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
45 changes: 45 additions & 0 deletions source/HOP-Core-Tests/HOPSnapshotRouteHandlerTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Class {
#name : 'HOPSnapshotRouteHandlerTest',
#superclass : 'TestCase',
#instVars : [
'uriSpace',
'directory'
],
#category : 'HOP-Core-Tests-Tests',
#package : 'HOP-Core-Tests',
#tag : 'Tests'
}

{ #category : 'running' }
HOPSnapshotRouteHandlerTest >> setUp [
super setUp.
directory := (FileLocator temp / ('hop-snapshot-', UUID new asString36)) ensureCreateDirectory.
uriSpace := (HOPUriSpace /+ #scim) root.
uriSpace / #scim @@ (#POST -> (HOPPluggableHandler new block: [ :req | #ok ])).
uriSpace addHandler: (HOPTestSnapshotRouteHandler new path: directory; yourself)
]

{ #category : 'running' }
HOPSnapshotRouteHandlerTest >> tearDown [
directory ifNotNil: [ directory ensureDeleteAll ].
super tearDown
]

{ #category : 'tests' }
HOPSnapshotRouteHandlerTest >> testSnapshotKeepsTheBytesOnTheWire [
"Der Mitschnitt gibt die Bytes des Requests unveraendert wieder. Auf einem
Zeichen-Strom kodiert der UTF-8-Encoder jedes Byte ueber 127 ein zweites
Mal - aus C3 9F wird C3 83 C2 9F, und der Rumpf enthaelt dann nicht mehr,
was der Client geschickt hat."
| body request snapshot |
body := '{"familyName":"Faaßen"}'.
request := (ZnRequest post: #scim)
entity: (ZnEntity with: body type: ZnMimeType applicationJson);
yourself.
uriSpace asZincDelegate handleRequest: request.
snapshot := ZnCharacterEncoder utf8 decodeBytes:
(directory files detect: [ :each | each basename beginsWith: 'SCIM-' ]) binaryReadStream upToEnd.
self
assert: (snapshot includesSubstring: body)
description: 'Der Mitschnitt gibt den Rumpf nicht Byte fuer Byte wieder'
]
21 changes: 21 additions & 0 deletions source/HOP-Core-Tests/HOPTestSnapshotRouteHandler.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Class {
#name : 'HOPTestSnapshotRouteHandler',
#superclass : 'HOPSnapshotRouteHandler',
#instVars : [
'testPath'
],
#category : 'HOP-Core-Tests-Tests',
#package : 'HOP-Core-Tests',
#tag : 'Tests'
}

{ #category : 'accessing' }
HOPTestSnapshotRouteHandler >> path [
"Statt /data/logs, damit ein Test den Mitschnitt wieder einlesen kann."
^ testPath
]

{ #category : 'accessing' }
HOPTestSnapshotRouteHandler >> path: aFileReference [
testPath := aFileReference
]
13 changes: 9 additions & 4 deletions source/HOP-Core/HOPSnapshotRouteHandler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ HOPSnapshotRouteHandler >> handleRoute: aRoute [
| response |
(self loggingEnabled: aRoute) ifFalse: [ ^ super handleRoute: aRoute ].

self withStreamDo: [ :stream |.
self withStreamDo: [ :stream |
aRoute request writeOn: stream.
stream
nextPutAll: String crlf;
nextPutAll: String crlf utf8Encoded;
flush.
[
[
Expand All @@ -30,7 +30,8 @@ HOPSnapshotRouteHandler >> handleRoute: aRoute [
]
on: Error
do: [ :error |
error signalerContext printDebugStackOn: stream.
stream nextPutAll: (String streamContents: [ :out |
error signalerContext printDebugStackOn: out ]) utf8Encoded.
stream flush.
error pass ]
]
Expand All @@ -54,8 +55,12 @@ HOPSnapshotRouteHandler >> path [

{ #category : 'as yet unclassified' }
HOPSnapshotRouteHandler >> withStreamDo: aBlock [
"Ein Byte-Strom, denn ZnMessage>>writeOn: schreibt Bytes. Auf einem
Zeichen-Strom kodiert der UTF-8-Encoder jedes Byte ueber 127 ein zweites
Mal: aus C3 9F wird C3 83 C2 9F, aus 'Faassen' wird 'FaaAYen'. Der
Mitschnitt wuerde dann laenger als sein eigenes Content-Length."
| stream |
stream := self filename writeStream.
stream := self filename binaryWriteStream.
[ aBlock value: stream ]
ensure: [
stream
Expand Down
Loading