diff --git a/source/BaselineOfHOP/BaselineOfHOP.class.st b/source/BaselineOfHOP/BaselineOfHOP.class.st index 66f9977..868cbae 100644 --- a/source/BaselineOfHOP/BaselineOfHOP.class.st +++ b/source/BaselineOfHOP/BaselineOfHOP.class.st @@ -20,6 +20,8 @@ BaselineOfHOP >> baseline: spec [ spec requires: #('HOP-Core') ]; package: 'HOP-Extra' with: [ spec requires: #('HOP-Core') ]; + package: 'HOP-Extra-Tests' with: [ + spec requires: #('HOP-Extra') ]; package: 'HOP-Roassal' with: [ spec requires: #('HOP-Core') ] ] ] diff --git a/source/HOP-Extra-Tests/HOPTestZincHandler.class.st b/source/HOP-Extra-Tests/HOPTestZincHandler.class.st new file mode 100644 index 0000000..c76707a --- /dev/null +++ b/source/HOP-Extra-Tests/HOPTestZincHandler.class.st @@ -0,0 +1,26 @@ +Class { + #name : 'HOPTestZincHandler', + #superclass : 'Object', + #instVars : [ + 'answer', + 'seenRequest' + ], + #category : 'HOP-Extra-Tests', + #package : 'HOP-Extra-Tests' +} + +{ #category : 'accessing' } +HOPTestZincHandler >> answer: aString [ + answer := aString +] + +{ #category : 'public' } +HOPTestZincHandler >> handleRequest: aRequest [ + seenRequest := aRequest. + ^ ZnResponse ok: (ZnEntity text: answer) +] + +{ #category : 'accessing' } +HOPTestZincHandler >> seenRequest [ + ^ seenRequest +] diff --git a/source/HOP-Extra-Tests/HOPZincHandlerCallTest.class.st b/source/HOP-Extra-Tests/HOPZincHandlerCallTest.class.st new file mode 100644 index 0000000..8dc940b --- /dev/null +++ b/source/HOP-Extra-Tests/HOPZincHandlerCallTest.class.st @@ -0,0 +1,28 @@ +Class { + #name : 'HOPZincHandlerCallTest', + #superclass : 'TestCase', + #category : 'HOP-Extra-Tests', + #package : 'HOP-Extra-Tests' +} + +{ #category : 'tests' } +HOPZincHandlerCallTest >> testTheConfiguredHandlerIsTheOneThatAnswers [ + "The point of carrying the handler rather than its class: whoever builds the route can + prepare it, and that same prepared object answers the request." + | handler call request | + handler := HOPTestZincHandler new answer: 'prepared'; yourself. + call := HOPZincHandlerCall new handler: handler; yourself. + request := ZnRequest get: '/anything'. + self + assert: (call handleRoute: (HOPRouteMatch new request: request; yourself)) entity contents + equals: 'prepared'. + self assert: handler seenRequest identicalTo: request +] + +{ #category : 'tests' } +HOPZincHandlerCallTest >> testACallAnswersItselfAsRouteHandler [ + "A prepared instance goes into the route as it is - that is what makes it configurable." + | call | + call := HOPZincHandlerCall new. + self assert: call asHOPRouteHandler identicalTo: call +] diff --git a/source/HOP-Extra-Tests/package.st b/source/HOP-Extra-Tests/package.st new file mode 100644 index 0000000..43fff7a --- /dev/null +++ b/source/HOP-Extra-Tests/package.st @@ -0,0 +1 @@ +Package { #name : 'HOP-Extra-Tests' } diff --git a/source/HOP-Extra/HOPZincHandlerCall.class.st b/source/HOP-Extra/HOPZincHandlerCall.class.st new file mode 100644 index 0000000..1690514 --- /dev/null +++ b/source/HOP-Extra/HOPZincHandlerCall.class.st @@ -0,0 +1,23 @@ +Class { + #name : 'HOPZincHandlerCall', + #superclass : 'HOPCall', + #instVars : [ + 'handler' + ], + #category : 'HOP-Extra', + #package : 'HOP-Extra' +} + +{ #category : 'execution' } +HOPZincHandlerCall >> execute [ + ^ handler handleRequest: self request +] + +{ #category : 'accessing' } +HOPZincHandlerCall >> handler: anObject [ + "Anything that answers handleRequest: with a ZnResponse. Carrying the handler itself rather + than its class is the point: it can be configured where the route is built, which is where + the deployment knows what it wants. HOPZincHandlerAdaptor cannot - it says handlerClass new + and leaves nobody a moment to say anything about it." + handler := anObject +]