-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FeignMethodRepresentationExtractor minor refactoring and added tests
- Loading branch information
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...ovy/com/hltech/pact/gen/domain/client/feign/FeignMethodRepresentationExtractorSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.hltech.pact.gen.domain.client.feign | ||
|
||
import com.hltech.pact.gen.domain.client.feign.sample.ResponseHeadersFeignClient | ||
import com.hltech.pact.gen.domain.client.model.ClientMethodRepresentation | ||
import com.hltech.pact.gen.domain.client.model.RequestRepresentation | ||
import com.hltech.pact.gen.domain.client.model.ResponseRepresentation | ||
import org.springframework.http.HttpMethod | ||
import org.springframework.http.HttpStatus | ||
import spock.lang.Specification | ||
import spock.lang.Subject | ||
|
||
import java.lang.reflect.Method | ||
|
||
class FeignMethodRepresentationExtractorSpec extends Specification { | ||
|
||
@Subject | ||
FeignMethodRepresentationExtractor extractor = new FeignMethodRepresentationExtractor() | ||
|
||
def "Should correctly extract feign method representation"() { | ||
given: | ||
Method method = ResponseHeadersFeignClient.getMethod('getTestObject', null) | ||
|
||
when: | ||
ClientMethodRepresentation representation = extractor.extractClientMethodRepresentation(method) | ||
|
||
then: | ||
verifyRequestRepresentation(representation.getRequestRepresentation()) | ||
|
||
representation.getResponseRepresentationList().size() == 1 | ||
verifyResponseRepresentation(representation.getResponseRepresentationList().get(0)) | ||
} | ||
|
||
def verifyRequestRepresentation(RequestRepresentation representation) { | ||
representation.getHttpMethod() == HttpMethod.GET | ||
representation.getPath() == '/' | ||
representation.getHeaders().isEmpty() | ||
!representation.getBody().getType() | ||
!representation.getBody().getGenericArgumentTypes() | ||
!representation.getRequestParameters() | ||
!representation.getPathParameters() | ||
} | ||
|
||
def verifyResponseRepresentation(ResponseRepresentation representation) { | ||
representation.getStatus() == HttpStatus.OK | ||
representation.getHeaders().any { param -> | ||
param.name == 'key1' | ||
!param.type | ||
!param.genericArgumentType | ||
param.defaultValue == 'val1' | ||
} | ||
representation.getHeaders().any { param -> | ||
param.name == 'key2' | ||
!param.type | ||
!param.genericArgumentType | ||
param.defaultValue == 'val2' | ||
} | ||
representation.getBody().type == Void.TYPE | ||
representation.getBody().genericArgumentTypes.size() == 0 | ||
!representation.getDescription() | ||
} | ||
} |