Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions source/BaselineOfHOP/BaselineOfHOP.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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') ] ]
]
Expand Down
26 changes: 26 additions & 0 deletions source/HOP-Extra-Tests/HOPTestZincHandler.class.st
Original file line number Diff line number Diff line change
@@ -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
]
28 changes: 28 additions & 0 deletions source/HOP-Extra-Tests/HOPZincHandlerCallTest.class.st
Original file line number Diff line number Diff line change
@@ -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
]
1 change: 1 addition & 0 deletions source/HOP-Extra-Tests/package.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : 'HOP-Extra-Tests' }
23 changes: 23 additions & 0 deletions source/HOP-Extra/HOPZincHandlerCall.class.st
Original file line number Diff line number Diff line change
@@ -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
]
Loading