diff --git a/source/Stargate-Examples-Tests/PetsRESTfulControllerTest.class.st b/source/Stargate-Examples-Tests/PetsRESTfulControllerTest.class.st index f9dce30..9f4b2db 100644 --- a/source/Stargate-Examples-Tests/PetsRESTfulControllerTest.class.st +++ b/source/Stargate-Examples-Tests/PetsRESTfulControllerTest.class.st @@ -137,6 +137,34 @@ PetsRESTfulControllerTest >> testCantDeleteInvalidPet [ withExceptionDo: [ :signal | self assert: signal code equals: 404 ] ] +{ #category : #'tests - get individual' } +PetsRESTfulControllerTest >> testCantGetPetSpecifyingLanguageRange [ + + self + assert: ( resourceController + createPetBasedOn: ( self requestToCreatePetFrom: '{"name":"Firulais","type":"dog"}' ) + within: self newHttpRequestContext ) isSuccess; + assert: petRepository count equals: 1. + + self + should: [ + resourceController + getPetBasedOn: ( self + requestToGETResourceIdentifiedBy: 1 + acceptingContentMatching: self defaultPetMediaType + inAnyOf: '*' ) + within: self newHttpRequestContext + ] + raise: HTTPNotAcceptable + withExceptionDo: [ :error | + self + assert: error messageText + equals: 'Cannot generate a response entity with acceptable characteristics.'; + assert: error code equals: 406; + assert: error allowedLanguageTags isEmpty + ] +] + { #category : #'tests - update' } PetsRESTfulControllerTest >> testCantUpdatePetIfMissingETag [ diff --git a/source/Stargate-Examples-Tests/SouthAmericanCurrenciesRESTfulControllerTest.class.st b/source/Stargate-Examples-Tests/SouthAmericanCurrenciesRESTfulControllerTest.class.st index 895ce6e..5128c83 100644 --- a/source/Stargate-Examples-Tests/SouthAmericanCurrenciesRESTfulControllerTest.class.st +++ b/source/Stargate-Examples-Tests/SouthAmericanCurrenciesRESTfulControllerTest.class.st @@ -7,6 +7,12 @@ Class { #category : #'Stargate-Examples-Tests-Currencies' } +{ #category : #'private - language ranges' } +SouthAmericanCurrenciesRESTfulControllerTest >> argentineSpanish [ + + ^ 'es-AR' asLanguageTag +] + { #category : #'private - support' } SouthAmericanCurrenciesRESTfulControllerTest >> assertThereAreNoLinksIn: json [ @@ -19,21 +25,67 @@ SouthAmericanCurrenciesRESTfulControllerTest >> baseUrl [ ^ 'https://currencies.example.com' asUrl ] +{ #category : #'private - language ranges' } +SouthAmericanCurrenciesRESTfulControllerTest >> english [ + + ^ 'en' asLanguageTag +] + +{ #category : #'private - language ranges' } +SouthAmericanCurrenciesRESTfulControllerTest >> languageRange [ + + ^ 'de,en;q=0.5,es;q=0.6' +] + { #category : #running } SouthAmericanCurrenciesRESTfulControllerTest >> setUpResourceController [ resourceController := SouthAmericanCurrenciesRESTfulController new ] +{ #category : #'private - language ranges' } +SouthAmericanCurrenciesRESTfulControllerTest >> spanish [ + + ^ 'es' asLanguageTag +] + +{ #category : #'private - language ranges' } +SouthAmericanCurrenciesRESTfulControllerTest >> supportedLanguages [ + + ^ Array with: self argentineSpanish with: self unitedStatesEnglish +] + +{ #category : #tests } +SouthAmericanCurrenciesRESTfulControllerTest >> testCantGetArgentinePesoAskingForAnEmptyLanguage [ + + | request | + + request := self + requestToGETResourceIdentifiedBy: 'ARS' + acceptingContentMatching: resourceController currencyVersion1dot0dot0MediaType + inAnyOf: ''. + + self + should: [ resourceController currencyBasedOn: request within: self newHttpRequestContext ] + raise: HTTPNotAcceptable + withExceptionDo: [ :error | + self + assert: error messageText + equals: 'Cannot generate a response entity with acceptable characteristics.'; + assert: error code equals: 406; + assertCollection: error allowedLanguageTags hasSameElements: self supportedLanguages + ] +] + { #category : #tests } SouthAmericanCurrenciesRESTfulControllerTest >> testCantGetArgentinePesoAskingForUnsupportedLanguage [ | request | request := self - requestToGETResourceIdentifiedBy: 'ARS' - accepting: resourceController currencyVersion1dot0dot0MediaType. - request setAcceptLanguage: 'de'. + requestToGETResourceIdentifiedBy: 'ARS' + acceptingContentMatching: resourceController currencyVersion1dot0dot0MediaType + inAnyOf: self unsupportedLanguage. self should: [ resourceController currencyBasedOn: request within: self newHttpRequestContext ] @@ -41,11 +93,9 @@ SouthAmericanCurrenciesRESTfulControllerTest >> testCantGetArgentinePesoAskingFo withExceptionDo: [ :error | self assert: error messageText - equals: 'Cannot generate a response entity with acceptable characteristics.'; + equals: 'Cannot generate a response entity with acceptable characteristics.'; assert: error code equals: 406; - assert: error allowedLanguageTags size equals: 2; - assert: error allowedLanguageTags includes: 'en-US' asLanguageTag; - assert: error allowedLanguageTags includes: 'es-AR' asLanguageTag + assertCollection: error allowedLanguageTags hasSameElements: self supportedLanguages ] ] @@ -69,7 +119,7 @@ SouthAmericanCurrenciesRESTfulControllerTest >> testGetArgentinePeso [ deny: response varyHeaderNames includes: 'Accept-Language'; assert: response varyHeaderNames includes: 'Accept'; assert: response entityTag equals: '"5dd07a40a75ea23fa44e641a92a6dd1ec7999a36"' asEntityTag; - assertCachingDirectivesFor: response with: #('immutable' 'public'). + assertCachingDirectivesFor: response with: #( 'immutable' 'public' ). self withJsonFromContentsIn: response do: [ :json | self @@ -86,38 +136,36 @@ SouthAmericanCurrenciesRESTfulControllerTest >> testGetArgentinePesoBanknotes [ | response | response := resourceController - currencyBanknotesBasedOn: - ( self - requestToGETSubresource: 'banknotes' - identifiedBy: 'ARS' - accepting: ZnMimeType applicationJson ) - within: self newHttpRequestContext. + currencyBanknotesBasedOn: ( self + requestToGETSubresource: 'banknotes' + identifiedBy: 'ARS' + accepting: ZnMimeType applicationJson ) + within: self newHttpRequestContext. self assert: response isSuccess; assert: response status equals: 200; assert: response contentType asMediaType equals: ZnMimeType applicationJson. self assertExpiresHeaderFor: response with: 365000000 seconds. - self assertCachingDirectivesFor: response with: #('immutable' 'public' 'Max-Age=365000000'). + self assertCachingDirectivesFor: response with: #( 'immutable' 'public' 'Max-Age=365000000' ). self withJsonFromContentsIn: response - do: [ :banknotes | self assertCollection: banknotes hasSameElements: #(5 10 20 50 100 200 500 1000) ] + do: [ :banknotes | + self assertCollection: banknotes hasSameElements: #( 5 10 20 50 100 200 500 1000 ) ] ] { #category : #tests } SouthAmericanCurrenciesRESTfulControllerTest >> testGetArgentinePesoInEnglish [ | response request | + request := self requestToGETResourceIdentifiedBy: 'ARS' - accepting: - resourceController currencyVersion1dot0dot0MediaType. - request setAcceptLanguage: 'en'. + acceptingContentMatching: resourceController currencyVersion1dot0dot0MediaType + inAnyOf: self english. - response := resourceController - currencyBasedOn: request - within: self newHttpRequestContext. + response := resourceController currencyBasedOn: request within: self newHttpRequestContext. self assert: response isSuccess; @@ -125,33 +173,95 @@ SouthAmericanCurrenciesRESTfulControllerTest >> testGetArgentinePesoInEnglish [ assert: response contentType asMediaType equals: resourceController currencyVersion1dot0dot0MediaType; withTheOnlyOneIn: response contentLanguageTags - do: [ :tag | self assert: tag equals: 'en-US' asLanguageTag ]; + do: [ :tag | self assert: tag equals: self unitedStatesEnglish ]; assert: response varyHeaderNames includes: 'Accept-Language'; assert: response varyHeaderNames includes: 'Accept'; - assert: response entityTag - equals: '"5dd07a40a75ea23fa44e641a92a6dd1ec7999a36"' asEntityTag. + assert: response entityTag equals: '"5dd07a40a75ea23fa44e641a92a6dd1ec7999a36"' asEntityTag. self withJsonFromContentsIn: response do: [ :json | self assert: json name equals: 'Argentine peso'; assert: json symbol equals: '$'; assert: json isoCode equals: 'ARS'; - assertThereAreNoLinksIn: json ] + assertThereAreNoLinksIn: json + ] +] + +{ #category : #tests } +SouthAmericanCurrenciesRESTfulControllerTest >> testGetArgentinePesoInEnglishBasedOnAnyLanguageWildcard [ + + | response request | + + request := self + requestToGETResourceIdentifiedBy: 'ARS' + acceptingContentMatching: resourceController currencyVersion1dot0dot0MediaType + inAnyOf: '*'. + + response := resourceController currencyBasedOn: request within: self newHttpRequestContext. + + self + assert: response isSuccess; + assert: response status equals: 200; + assert: response contentType asMediaType + equals: resourceController currencyVersion1dot0dot0MediaType; + withTheOnlyOneIn: response contentLanguageTags + do: [ :tag | self assert: tag equals: self unitedStatesEnglish ]; + assert: response varyHeaderNames includes: 'Accept-Language'; + assert: response varyHeaderNames includes: 'Accept'; + assert: response entityTag equals: '"5dd07a40a75ea23fa44e641a92a6dd1ec7999a36"' asEntityTag. + + self withJsonFromContentsIn: response do: [ :json | + self + assert: json name equals: 'Argentine peso'; + assert: json symbol equals: '$'; + assert: json isoCode equals: 'ARS'; + assertThereAreNoLinksIn: json + ] ] { #category : #tests } SouthAmericanCurrenciesRESTfulControllerTest >> testGetArgentinePesoInSpanish [ | response request | + request := self requestToGETResourceIdentifiedBy: 'ARS' - accepting: - resourceController currencyVersion1dot0dot0MediaType. - request setAcceptLanguage: 'es'. + acceptingContentMatching: resourceController currencyVersion1dot0dot0MediaType + inAnyOf: self spanish. - response := resourceController - currencyBasedOn: request - within: self newHttpRequestContext. + response := resourceController currencyBasedOn: request within: self newHttpRequestContext. + + self + assert: response isSuccess; + assert: response status equals: 200; + assert: response contentType asMediaType + equals: resourceController currencyVersion1dot0dot0MediaType; + withTheOnlyOneIn: response contentLanguageTags + do: [ :tag | self assert: tag equals: self argentineSpanish ]; + assert: response varyHeaderNames includes: 'Accept-Language'; + assert: response varyHeaderNames includes: 'Accept'; + assert: response entityTag equals: '"fd65007599711248b85d86917bd24c5aa29e610b"' asEntityTag. + + self withJsonFromContentsIn: response do: [ :json | + self + assert: json name equals: 'Peso'; + assert: json symbol equals: '$'; + assert: json isoCode equals: 'ARS'; + assertThereAreNoLinksIn: json + ] +] + +{ #category : #tests } +SouthAmericanCurrenciesRESTfulControllerTest >> testGetArgentinePesoInSpanishBasedOnLanguagePriorityList [ + + | response request | + + request := self + requestToGETResourceIdentifiedBy: 'ARS' + acceptingContentMatching: resourceController currencyVersion1dot0dot0MediaType + inAnyOf: self languageRange. + + response := resourceController currencyBasedOn: request within: self newHttpRequestContext. self assert: response isSuccess; @@ -159,29 +269,29 @@ SouthAmericanCurrenciesRESTfulControllerTest >> testGetArgentinePesoInSpanish [ assert: response contentType asMediaType equals: resourceController currencyVersion1dot0dot0MediaType; withTheOnlyOneIn: response contentLanguageTags - do: [ :tag | self assert: tag equals: 'es-AR' asLanguageTag ]; + do: [ :tag | self assert: tag equals: self argentineSpanish ]; assert: response varyHeaderNames includes: 'Accept-Language'; assert: response varyHeaderNames includes: 'Accept'; - assert: response entityTag - equals: '"fd65007599711248b85d86917bd24c5aa29e610b"' asEntityTag. + assert: response entityTag equals: '"fd65007599711248b85d86917bd24c5aa29e610b"' asEntityTag. self withJsonFromContentsIn: response do: [ :json | self assert: json name equals: 'Peso'; assert: json symbol equals: '$'; assert: json isoCode equals: 'ARS'; - assertThereAreNoLinksIn: json ] + assertThereAreNoLinksIn: json + ] ] { #category : #tests } SouthAmericanCurrenciesRESTfulControllerTest >> testGetBrazilianReal [ | response | + response := resourceController - currencyBasedOn: (self - requestToGETResourceIdentifiedBy: 'BRL' - accepting: - resourceController currencyVersion1dot0dot0MediaType) + currencyBasedOn: ( self + requestToGETResourceIdentifiedBy: 'BRL' + accepting: resourceController currencyVersion1dot0dot0MediaType ) within: self newHttpRequestContext. self @@ -191,31 +301,30 @@ SouthAmericanCurrenciesRESTfulControllerTest >> testGetBrazilianReal [ equals: resourceController currencyVersion1dot0dot0MediaType; assert: response contentLanguageTags isEmpty; assert: response varyHeaderNames includes: 'Accept'; - assert: response entityTag - equals: '"13bd1a73c317563852cbb2858e39a0af77699f60"' asEntityTag; - assertCachingDirectivesFor: response with: #('immutable'). + assert: response entityTag equals: '"13bd1a73c317563852cbb2858e39a0af77699f60"' asEntityTag; + assertCachingDirectivesFor: response with: #( 'immutable' ). self withJsonFromContentsIn: response do: [ :json | self assert: json name equals: 'Brazilian real'; assert: json symbol equals: 'R$'; assert: json isoCode equals: 'BRL'; - assertThereAreNoLinksIn: json ] + assertThereAreNoLinksIn: json + ] ] { #category : #tests } SouthAmericanCurrenciesRESTfulControllerTest >> testGetBrazilianRealInEnglish [ | response request | + request := self requestToGETResourceIdentifiedBy: 'BRL' - accepting: - resourceController currencyVersion1dot0dot0MediaType. - request setAcceptLanguage: 'en'. + acceptingContentMatching: resourceController currencyVersion1dot0dot0MediaType + inAnyOf: self english. - response := resourceController - currencyBasedOn: request - within: self newHttpRequestContext. + + response := resourceController currencyBasedOn: request within: self newHttpRequestContext. self assert: response isSuccess; @@ -223,33 +332,31 @@ SouthAmericanCurrenciesRESTfulControllerTest >> testGetBrazilianRealInEnglish [ assert: response contentType asMediaType equals: resourceController currencyVersion1dot0dot0MediaType; withTheOnlyOneIn: response contentLanguageTags - do: [ :tag | self assert: tag equals: 'en-US' asLanguageTag ]; + do: [ :tag | self assert: tag equals: self unitedStatesEnglish ]; assert: response varyHeaderNames includes: 'Accept-Language'; assert: response varyHeaderNames includes: 'Accept'; - assert: response entityTag - equals: '"13bd1a73c317563852cbb2858e39a0af77699f60"' asEntityTag. + assert: response entityTag equals: '"13bd1a73c317563852cbb2858e39a0af77699f60"' asEntityTag. self withJsonFromContentsIn: response do: [ :json | self assert: json name equals: 'Brazilian real'; assert: json symbol equals: 'R$'; assert: json isoCode equals: 'BRL'; - assertThereAreNoLinksIn: json ] + assertThereAreNoLinksIn: json + ] ] { #category : #tests } SouthAmericanCurrenciesRESTfulControllerTest >> testGetBrazilianRealInSpanish [ | response request | + request := self requestToGETResourceIdentifiedBy: 'BRL' - accepting: - resourceController currencyVersion1dot0dot0MediaType. - request setAcceptLanguage: 'es' asLanguageTag. + acceptingContentMatching: resourceController currencyVersion1dot0dot0MediaType + inAnyOf: self spanish. - response := resourceController - currencyBasedOn: request - within: self newHttpRequestContext. + response := resourceController currencyBasedOn: request within: self newHttpRequestContext. self assert: response isSuccess; @@ -257,18 +364,18 @@ SouthAmericanCurrenciesRESTfulControllerTest >> testGetBrazilianRealInSpanish [ assert: response contentType asMediaType equals: resourceController currencyVersion1dot0dot0MediaType; withTheOnlyOneIn: response contentLanguageTags - do: [ :tag | self assert: tag equals: 'es-AR' asLanguageTag ]; + do: [ :tag | self assert: tag equals: self argentineSpanish ]; assert: response varyHeaderNames includes: 'Accept-Language'; assert: response varyHeaderNames includes: 'Accept'; - assert: response entityTag - equals: '"f74a6f30f3c09515114aa5aa2a47253dfcd59d49"' asEntityTag. + assert: response entityTag equals: '"f74a6f30f3c09515114aa5aa2a47253dfcd59d49"' asEntityTag. self withJsonFromContentsIn: response do: [ :json | self assert: json name equals: 'Real brasileño'; assert: json symbol equals: 'R$'; assert: json isoCode equals: 'BRL'; - assertThereAreNoLinksIn: json ] + assertThereAreNoLinksIn: json + ] ] { #category : #tests } @@ -277,30 +384,27 @@ SouthAmericanCurrenciesRESTfulControllerTest >> testGetCurrencies [ | response | response := resourceController - currenciesBasedOn: - ( self - requestToGET: self resourceUrl - accepting: resourceController currencyVersion1dot0dot0MediaType ) - within: self newHttpRequestContext. + currenciesBasedOn: ( self + requestToGET: self resourceUrl + accepting: resourceController currencyVersion1dot0dot0MediaType ) + within: self newHttpRequestContext. self assert: response isSuccess; assert: response status equals: 200; assert: response contentType asMediaType - equals: resourceController currencyVersion1dot0dot0MediaType; + equals: resourceController currencyVersion1dot0dot0MediaType; assert: response contentLanguageTags isEmpty; deny: response varyHeaderNames includes: 'Accept-Language'; assert: response varyHeaderNames includes: 'Accept'. - self assertCachingDirectivesFor: response with: #('immutable' 'Max-Age=86400'). + self assertCachingDirectivesFor: response with: #( 'immutable' 'Max-Age=86400' ). - self - withJsonFromContentsIn: response - do: [ :currencies | - self - assert: currencies size equals: 11; - assert: ( currencies collect: #isoCode ) - equals: #('ARS' 'BOB' 'BRL' 'CLP' 'COP' 'GYD' 'PYG' 'PEN' 'SRD' 'UYU' 'VES') - ] + self withJsonFromContentsIn: response do: [ :currencies | + self + assert: currencies size equals: 11; + assert: ( currencies collect: #isoCode ) + equals: #( 'ARS' 'BOB' 'BRL' 'CLP' 'COP' 'GYD' 'PYG' 'PEN' 'SRD' 'UYU' 'VES' ) + ] ] { #category : #tests } @@ -308,10 +412,11 @@ SouthAmericanCurrenciesRESTfulControllerTest >> testGetCurrenciesInSpanish [ | response request | - request := self - requestToGET: self resourceUrl - accepting: resourceController currencyVersion1dot0dot0MediaType. - request setAcceptLanguage: 'es'. + request := self requestToGET: self resourceUrl applying: [ :requestConfig | + requestConfig + setAccept: resourceController currencyVersion1dot0dot0MediaType; + setAcceptLanguage: self spanish + ]. response := resourceController currenciesBasedOn: request within: self newHttpRequestContext. @@ -319,29 +424,28 @@ SouthAmericanCurrenciesRESTfulControllerTest >> testGetCurrenciesInSpanish [ assert: response isSuccess; assert: response status equals: 200; assert: response contentType asMediaType - equals: resourceController currencyVersion1dot0dot0MediaType; + equals: resourceController currencyVersion1dot0dot0MediaType; withTheOnlyOneIn: response contentLanguageTags - do: [ :tag | self assert: tag equals: 'es-AR' asLanguageTag ]; + do: [ :tag | self assert: tag equals: self argentineSpanish ]; assert: response varyHeaderNames includes: 'Accept-Language'; assert: response varyHeaderNames includes: 'Accept'. - self assertCachingDirectivesFor: response with: #('immutable' 'Max-Age=86400'). + self assertCachingDirectivesFor: response with: #( 'immutable' 'Max-Age=86400' ). - self - withJsonFromContentsIn: response - do: [ :currencies | - self - assert: currencies size equals: 11; - assert: ( currencies collect: #isoCode ) - equals: #('ARS' 'BOB' 'BRL' 'CLP' 'COP' 'GYD' 'PYG' 'PEN' 'SRD' 'UYU' 'VES'); - assert: ( currencies anySatisfy: [ :currency | currency name = 'Real brasileño' ] ) - ] + self withJsonFromContentsIn: response do: [ :currencies | + self + assert: currencies size equals: 11; + assert: ( currencies collect: #isoCode ) + equals: #( 'ARS' 'BOB' 'BRL' 'CLP' 'COP' 'GYD' 'PYG' 'PEN' 'SRD' 'UYU' 'VES' ); + assert: ( currencies anySatisfy: [ :currency | currency name = 'Real brasileño' ] ) + ] ] { #category : #tests } SouthAmericanCurrenciesRESTfulControllerTest >> testGetCurrencyNotFoundShouldFail [ self - should: [ resourceController + should: [ + resourceController currencyBasedOn: ( self requestToGETResourceIdentifiedBy: 'ZZZ' accepting: '*/*' ) within: self newHttpRequestContext ] @@ -353,30 +457,27 @@ SouthAmericanCurrenciesRESTfulControllerTest >> testGetCurrencyNotFoundShouldFai SouthAmericanCurrenciesRESTfulControllerTest >> testGetNotModifiedWhenValidETag [ | response | + response := resourceController - currencyBasedOn: (self - requestToGETResourceIdentifiedBy: 'ARS' - accepting: - resourceController currencyVersion1dot0dot0MediaType) + currencyBasedOn: ( self + requestToGETResourceIdentifiedBy: 'ARS' + accepting: resourceController currencyVersion1dot0dot0MediaType ) within: self newHttpRequestContext. self assert: response isSuccess; - assert: response entityTag - equals: '"5dd07a40a75ea23fa44e641a92a6dd1ec7999a36"' asEntityTag. + assert: response entityTag equals: '"5dd07a40a75ea23fa44e641a92a6dd1ec7999a36"' asEntityTag. response := resourceController - currencyBasedOn: (self - requestToGETResourceIdentifiedBy: 'ARS' - accepting: - resourceController currencyVersion1dot0dot0MediaType - conditionalTo: response entityTag) + currencyBasedOn: ( self + requestToGETResourceIdentifiedBy: 'ARS' + accepting: resourceController currencyVersion1dot0dot0MediaType + conditionalTo: response entityTag ) within: self newHttpRequestContext. self assert: response code equals: 304; - assert: response entityTag - equals: '"5dd07a40a75ea23fa44e641a92a6dd1ec7999a36"' asEntityTag; + assert: response entityTag equals: '"5dd07a40a75ea23fa44e641a92a6dd1ec7999a36"' asEntityTag; assert: response varyHeaderNames includes: 'Accept' ] @@ -389,7 +490,20 @@ SouthAmericanCurrenciesRESTfulControllerTest >> testTemplates [ self assertCollection: ( routes collect: #urlTemplate ) - hasSameElements: #('/currencies' '/currencies/' '/currencies//banknotes'). + hasSameElements: + #( '/currencies' '/currencies/' '/currencies//banknotes' ). routes do: [ :route | self assert: route httpMethod equals: #GET ] ] + +{ #category : #'private - language ranges' } +SouthAmericanCurrenciesRESTfulControllerTest >> unitedStatesEnglish [ + + ^ 'en-US' asLanguageTag +] + +{ #category : #'private - language ranges' } +SouthAmericanCurrenciesRESTfulControllerTest >> unsupportedLanguage [ + + ^ 'de' asLanguageTag +] diff --git a/source/Stargate-SUnit-Model/SingleResourceRESTfulControllerTest.class.st b/source/Stargate-SUnit-Model/SingleResourceRESTfulControllerTest.class.st index 1ae5d35..fb9a4e4 100644 --- a/source/Stargate-SUnit-Model/SingleResourceRESTfulControllerTest.class.st +++ b/source/Stargate-SUnit-Model/SingleResourceRESTfulControllerTest.class.st @@ -36,58 +36,103 @@ SingleResourceRESTfulControllerTest >> requestToDELETEResourceIdentifiedBy: anId ] { #category : #'private - HTTP requests' } -SingleResourceRESTfulControllerTest >> requestToGET: aUrl accepting: anAcceptHeader [ +SingleResourceRESTfulControllerTest >> requestToGET: aUrl accepting: aMediaRange [ - ^ TeaRequest - fromZnRequest: - ((ZnRequest get: aUrl) - setAccept: anAcceptHeader; - yourself) + ^ self + requestToGET: aUrl + applying: [ :request | request setAccept: aMediaRange ] ] { #category : #'private - HTTP requests' } -SingleResourceRESTfulControllerTest >> requestToGETResourceIdentifiedBy: anIdentifier accepting: anAcceptHeader [ +SingleResourceRESTfulControllerTest >> requestToGET: aUrl applying: aConfiguration [ + + ^ self + requestToGET: aUrl + withPathParams: Dictionary new + applying: aConfiguration +] +{ #category : #'private - HTTP requests' } +SingleResourceRESTfulControllerTest >> requestToGET: aUrl withPathParams: aDictionary applying: aConfiguration [ + + | request | + + request := ZnRequest get: aUrl. + + aConfiguration value: request. + ^ TeaRequest - fromZnRequest: - ( ( ZnRequest get: ( self urlForResourceIdentifiedBy: anIdentifier ) ) - setAccept: anAcceptHeader; - yourself ) - pathParams: ( self parametersWith: anIdentifier ) + fromZnRequest: request + pathParams: aDictionary. ] { #category : #'private - HTTP requests' } -SingleResourceRESTfulControllerTest >> requestToGETResourceIdentifiedBy: anIdentifier accepting: anAcceptHeader conditionalTo: anETag [ +SingleResourceRESTfulControllerTest >> requestToGETResourceFrom: aLocation identifiedBy: anIdentifier applying: aConfiguration [ - ^ TeaRequest - fromZnRequest: - ( ( ZnRequest get: ( self urlForResourceIdentifiedBy: anIdentifier ) ) - setAccept: anAcceptHeader; - setIfNoneMatchTo: anETag; - yourself ) - pathParams: ( self parametersWith: anIdentifier ) + ^ self + requestToGET: aLocation + withPathParams: (self parametersWith: anIdentifier) + applying: aConfiguration ] { #category : #'private - HTTP requests' } -SingleResourceRESTfulControllerTest >> requestToGETSubresource: aSubresourceUrl identifiedBy: anIdentifier accepting: anAcceptHeader [ +SingleResourceRESTfulControllerTest >> requestToGETResourceIdentifiedBy: anIdentifier accepting: aMediaRange [ - ^ TeaRequest - fromZnRequest: - ( ( ZnRequest get: aSubresourceUrl ) - setAccept: anAcceptHeader; - yourself ) - pathParams: ( self parametersWith: anIdentifier ) + ^ self + requestToGETResourceIdentifiedBy: anIdentifier + applying: [ :request | request setAccept: aMediaRange ] +] + +{ #category : #'private - HTTP requests' } +SingleResourceRESTfulControllerTest >> requestToGETResourceIdentifiedBy: anIdentifier accepting: aMediaRange conditionalTo: anETag [ + + ^ self + requestToGETResourceIdentifiedBy: anIdentifier + applying: [ :request | + request + setAccept: aMediaRange; + setIfNoneMatchTo: anETag ] +] + +{ #category : #'private - HTTP requests' } +SingleResourceRESTfulControllerTest >> requestToGETResourceIdentifiedBy: anIdentifier acceptingContentMatching: aMediaRange inAnyOf: aLanguageRange [ + + ^ self + requestToGETResourceIdentifiedBy: anIdentifier + applying: [ :request | + request + setAccept: aMediaRange; + setAcceptLanguage: aLanguageRange ] +] + +{ #category : #'private - HTTP requests' } +SingleResourceRESTfulControllerTest >> requestToGETResourceIdentifiedBy: anIdentifier applying: aConfiguration [ + + ^ self + requestToGETResourceFrom: + (self urlForResourceIdentifiedBy: anIdentifier) + identifiedBy: anIdentifier + applying: aConfiguration +] + +{ #category : #'private - HTTP requests' } +SingleResourceRESTfulControllerTest >> requestToGETSubresource: aSubresourceUrl identifiedBy: anIdentifier accepting: aMediaRange [ + + ^ self + requestToGET: aSubresourceUrl + withPathParams: (self parametersWith: anIdentifier) + applying: [ :request | request setAccept: aMediaRange ] ] { #category : #'private - HTTP requests' } -SingleResourceRESTfulControllerTest >> requestToPATCHResourceIdentifiedBy: anIdentifier with: aRequestBody accepting: anAcceptHeader conditionalTo: anETag [ +SingleResourceRESTfulControllerTest >> requestToPATCHResourceIdentifiedBy: anIdentifier with: aRequestBody accepting: aMediaRange conditionalTo: anETag [ ^ TeaRequest fromZnRequest: ( ( ZnRequest patch: ( self urlForResourceIdentifiedBy: anIdentifier ) ) - setAccept: anAcceptHeader; + setAccept: aMediaRange; setIfMatchTo: anETag; - entity: ( ZnEntity with: aRequestBody type: anAcceptHeader ); + entity: ( ZnEntity with: aRequestBody type: aMediaRange ); yourself ) pathParams: ( self parametersWith: anIdentifier ) ]