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
31 changes: 31 additions & 0 deletions source/HOP-Core-Tests/HOPRouteHanderWrapperTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,34 @@ HOPRouteHanderWrapperTest >> testRetryHandlerExceeded [
should: [ uriSpace asZincDelegate handleRequest: (ZnRequest get: #first) ]
raise: HOPMaximumRetriesExceeded
]

{ #category : 'tests' }
HOPRouteHanderWrapperTest >> testHandlerOfASegmentLeavesItsSiblingsAlone [
| other |
other := uriSpace /+ #other.
other @@ (#GET -> (HOPPluggableHandler new block: [ :req | Error signal ])).
(uriSpace / #first) addHandler: HOPExceptionHandlerWrapper new.
self
should: [ uriSpace asZincDelegate handleRequest: (ZnRequest get: #other) ]
raise: Error
]

{ #category : 'tests' }
HOPRouteHanderWrapperTest >> testHandlerOfASegmentWrapsItsChildren [
| response |
uriSpace / #first / #second @@ (#GET -> (HOPPluggableHandler new block: [ :req | Error signal ])).
(uriSpace / #first) addHandler: HOPExceptionHandlerWrapper new.
response := uriSpace asZincDelegate handleRequest: (ZnRequest get: '/first/second').
self assert: response status equals: 500
]

{ #category : 'tests' }
HOPRouteHanderWrapperTest >> testHandlerOfASegmentWrapsItsOwnMethod [
"a segment that carries handlers answers a method on its own path, it is not only a
prefix for the segments below it"
| response |
uriSpace / #first @@ (#GET -> (HOPPluggableHandler new block: [ :req | Error signal ])).
(uriSpace / #first) addHandler: HOPExceptionHandlerWrapper new.
response := uriSpace asZincDelegate handleRequest: (ZnRequest get: #first).
self assert: response status equals: 500
]
20 changes: 20 additions & 0 deletions source/HOP-Core-Tests/HOPUriBuilderTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,23 @@ HOPUriBuilderTest >> testBuildUriForResource [
uri := uriSpace buildUriForResource: object.
self assert: uri equals: '/api/objects/1/children/2'
]

{ #category : 'tests' }
HOPUriBuilderTest >> testBuildUriForResourceInAMountedUriSpace [
"a uri space mounted under a name is a named segment of the space it hangs in"
| uriSpace mounted objectSegment childSegment object uri |
objectSegment := HOPVariableSegment new
name: #objectId;
segmentNameSelector: #id.
childSegment := HOPVariableSegment new
name: #childId;
segmentNameSelector: #id.
mounted := HOPUriSpace new
name: #mounted;
yourself.
uriSpace := (HOPUriSpace /+ mounted) root.
mounted /+ #objects /+ objectSegment --> HOPUriBuildObject /+ #children /+ childSegment --> HOPUriBuildChildObject.
object := HOPUriBuildChildObject new container: HOPUriBuildObject new.
uri := uriSpace buildUriForResource: object.
self assert: uri equals: '/mounted/objects/1/children/2'
]
2 changes: 1 addition & 1 deletion source/HOP-Core/HOPCatchAllSegment.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ HOPCatchAllSegment >> matches: aString [
]

{ #category : 'testing' }
HOPCatchAllSegment >> matchesNode: aHOPSpaceZone [
HOPCatchAllSegment >> matchesNode: aHOPNode [
^ false
]

Expand Down
8 changes: 0 additions & 8 deletions source/HOP-Core/HOPNamedSegment.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ HOPNamedSegment >> acceptHOP: aHOPVisitor [
^ aHOPVisitor visitNamedSegment: self
]

{ #category : 'converting' }
HOPNamedSegment >> asHOPSpaceZone [
^ HOPSpaceZone new
name: name;
mergeNode: self root;
yourself
]

{ #category : 'as yet unclassified' }
HOPNamedSegment >> canonicalUriFor: aResource [
^ (super canonicalUriFor: aResource)
Expand Down
5 changes: 0 additions & 5 deletions source/HOP-Core/HOPNode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,6 @@ HOPNode >> isRoot [
^ parent isNil
]

{ #category : 'testing' }
HOPNode >> isSpaceZone [
^ false
]

{ #category : 'accessing' }
HOPNode >> label [
^ self name
Expand Down
3 changes: 1 addition & 2 deletions source/HOP-Core/HOPRouteMatcher.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ HOPRouteMatcher >> matchRoute [
currentSegment ifNil: [
currentSegment := self startSegment ].

currentSegment isSpaceZone ifTrue: [
self routeMatch addHandlers: currentSegment handlers ].
self routeMatch addHandlers: currentSegment handlers.

[ self atEnd ] whileFalse: [
currentSegment := currentSegment
Expand Down
27 changes: 24 additions & 3 deletions source/HOP-Core/HOPSegment.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ Class {
#name : 'HOPSegment',
#superclass : 'HOPNode',
#instVars : [
'methods'
'methods',
'handlers'
],
#category : 'HOP-Core',
#package : 'HOP-Core'
Expand All @@ -18,9 +19,18 @@ HOPSegment >> @@ anAssociation [
anAssociation addMethodsTo: self
]

{ #category : 'adding' }
HOPSegment >> addHandler: aHandler [
handlers add: aHandler
]

{ #category : 'services' }
HOPSegment >> addSegment: key routeMatch: routeMatch [
^ routeMatch addSegment: self
"the handlers of a segment wrap everything that is reached through it, the
methods of the segment itself included"
routeMatch
addSegment: self;
addHandlers: handlers
]

{ #category : 'adding' }
Expand Down Expand Up @@ -64,6 +74,16 @@ HOPSegment >> atMethod: aString put: anObject [
put: anObject
]

{ #category : 'accessing' }
HOPSegment >> handlers [
^ handlers
]

{ #category : 'testing' }
HOPSegment >> hasHandlers [
^ handlers notEmpty
]

{ #category : 'testing' }
HOPSegment >> hasMethods [
^ methods notEmpty
Expand All @@ -72,7 +92,8 @@ HOPSegment >> hasMethods [
{ #category : 'initialization' }
HOPSegment >> initialize [
super initialize.
methods := Dictionary new
methods := Dictionary new.
handlers := OrderedCollection new
]

{ #category : 'as yet unclassified' }
Expand Down
112 changes: 0 additions & 112 deletions source/HOP-Core/HOPSpaceZone.class.st

This file was deleted.

12 changes: 4 additions & 8 deletions source/HOP-Core/HOPUriBuilder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,12 @@ HOPUriBuilder >> visitSegment: aHOPSegment [
self visit: aHOPSegment parent ]
]

{ #category : 'visiting' }
HOPUriBuilder >> visitSpaceZone: aSpaceZone [
aSpaceZone hasParent ifTrue: [
segments add: aSpaceZone name ].
super visitSpaceZone: aSpaceZone
]

{ #category : 'visiting' }
HOPUriBuilder >> visitUriSpace: aUriSpace [

"the root is the empty path and adds nothing. A space mounted under a name is a
named segment of the space it is mounted in"
aUriSpace isRoot ifFalse: [
self visitNamedSegment: aUriSpace ]
]

{ #category : 'visiting' }
Expand Down
24 changes: 23 additions & 1 deletion source/HOP-Core/HOPUriSpace.class.st
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Class {
#name : 'HOPUriSpace',
#superclass : 'HOPSpaceZone',
#superclass : 'HOPNamedSegment',
#instVars : [
'operationSegments',
'behaviorSegments'
Expand All @@ -14,6 +14,14 @@ HOPUriSpace class >> /+ aSegment [
^ self new /+ aSegment
]

{ #category : 'converting' }
HOPUriSpace class >> asHOPSegment [
"a uri space class mounted under a name, as in #auth -> OIDCUriSpace"
^ self new
build;
asHOPSegment
]

{ #category : 'visiting' }
HOPUriSpace >> acceptHOP: aHOPVisitor [
^ aHOPVisitor visitUriSpace: self
Expand Down Expand Up @@ -79,6 +87,13 @@ HOPUriSpace >> buildUriForResource: anObject [
build
]

{ #category : 'as yet unclassified' }
HOPUriSpace >> canonicalUriFor: aResource [
"the root is the empty path and adds no segment, a mounted space adds its name"
self isRoot ifTrue: [ ^ OrderedCollection new ].
^ super canonicalUriFor: aResource
]

{ #category : 'as yet unclassified' }
HOPUriSpace >> canonicalUriForResource: resource [

Expand Down Expand Up @@ -203,6 +218,13 @@ HOPUriSpace >> uriBuilderClass [
^ HOPUriBuilder
]

{ #category : 'as yet unclassified' }
HOPUriSpace >> uriFor: aResource resourceRoute: resourceRoute [
"the root is the empty path and adds no segment, a mounted space adds its name"
self isRoot ifTrue: [ ^ OrderedCollection new ].
^ super uriFor: aResource resourceRoute: resourceRoute
]

{ #category : 'as yet unclassified' }
HOPUriSpace >> zincServerDelegate [
^ HOPServerDelegate new
Expand Down
7 changes: 1 addition & 6 deletions source/HOP-Core/HOPVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,9 @@ HOPVisitor >> visitSegment: aHOPSegment [

]

{ #category : 'visiting' }
HOPVisitor >> visitSpaceZone: aHOSpaceZone [
self visitSegment: aHOSpaceZone
]

{ #category : 'visiting' }
HOPVisitor >> visitUriSpace: aHOPUriSpace [
self visitSpaceZone: aHOPUriSpace
self visitNamedSegment: aHOPUriSpace
]

{ #category : 'visiting' }
Expand Down
Loading