Skip to content

Commit

Permalink
FeignMethodRepresentationExtractor minor refactoring and added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe444 committed Nov 14, 2018
1 parent e67a88d commit a848f6d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private static List<ResponseRepresentation> extractResponseProperties(Method fei
annotation.description()))
.collect(Collectors.toList());

return results.size() > 0 ? results :
return !results.isEmpty() ? results :
Lists.newArrayList(populateResponse(HttpStatus.OK, Lists.newArrayList(), feignClientMethod, ""));
}

Expand Down
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()
}
}

0 comments on commit a848f6d

Please sign in to comment.