1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- Class {
- #name : #ZnockClient,
- #superclass : #ZnClient,
- #instVars : [
- 'interceptor'
- ],
- #category : #Znock
- }
- { #category : #'instance creation' }
- ZnockClient class >> newWithInterceptor: aZnock [
- ^ self new
- interceptor: aZnock;
- yourself
- ]
- { #category : #'private protocol' }
- ZnockClient >> fakeDelay: aDuration [
- | localTimeout |
- localTimeout := self timeout seconds.
- localTimeout <= aDuration
- ifTrue: [ localTimeout asDelay wait. ConnectionTimedOut signal: 'Znock timeout' ]
- ifFalse: [ aDuration asDelay wait ]
- ]
- { #category : #'private protocol' }
- ZnockClient >> getConnectionAndExecute [
- | expectation |
- expectation := interceptor consumeExpectationFor: self.
- expectation ifNil: [ ^ super executeRequestResponse ].
- expectation customizeResponseFromRequest: request.
- expectation delay ifNotNil: [ :delay | self fakeDelay: delay ].
- response := expectation response.
- ^ response contents
- ]
- { #category : #accessing }
- ZnockClient >> interceptor: anObject [
- interceptor := anObject
- ]
- { #category : #comparing }
- ZnockClient >> matches: aZnockExpectation [
- | req exp |
- req := self request.
- exp := aZnockExpectation request.
- exp url scheme ifNotNil:
- [ :scheme | scheme = req url scheme ifFalse: [ ^ false ] ].
- exp url authority ifNotNil:
- [ :authority | authority = req url authority ifFalse: [ ^ false ] ].
- exp method ifNotNil:
- [ :method | method = req method ifFalse: [ ^ false ] ].
- (req url path beginsWith: exp url path) ifFalse: [ ^ false ].
- ^ true
- ]
|