use of com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseType in project ds3_autogen by SpectraLogic.
the class BaseResponseParserGenerator method toParseResponse.
/**
* Converts a Ds3ResponseCode into a Parse Response model which can be used to
* generate the java code for parsing a response payload
* @param responseName Name of the response handler
*/
protected static ParseResponse toParseResponse(final Ds3ResponseCode ds3ResponseCode, final String responseName, final boolean hasResponsePayload, final boolean hasPaginationHeaders) {
if (isEmpty(ds3ResponseCode.getDs3ResponseTypes())) {
throw new IllegalArgumentException("Response code does not contain any response types: " + ds3ResponseCode.getCode());
}
final Ds3ResponseType ds3ResponseType = ds3ResponseCode.getDs3ResponseTypes().get(0);
final String responseModelName = getResponseModelName(ds3ResponseType);
if (responseModelName.equalsIgnoreCase("null") && !hasResponsePayload) {
return new EmptyParseResponse(responseName, hasPaginationHeaders);
}
if (responseModelName.equalsIgnoreCase("null") && hasResponsePayload) {
return new NullParseResponse(responseName, hasPaginationHeaders);
}
if (responseModelName.equalsIgnoreCase("string")) {
return new StringParseResponse(responseName, hasPaginationHeaders);
}
return new BaseParseResponse(responseName, responseModelName, hasPaginationHeaders);
}
use of com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseType in project ds3_autogen by SpectraLogic.
the class BaseResponseGenerator_Test method toParam_SimpleType_Test.
@Test
public void toParam_SimpleType_Test() {
final Ds3ResponseCode responseCode = new Ds3ResponseCode(200, ImmutableList.of(new Ds3ResponseType("com.test.TestType", null)));
final Optional<Arguments> result = toParam(responseCode);
assertTrue(result.isPresent());
assertThat(result.get().getName(), is("testTypeResult"));
assertThat(result.get().getType(), is("TestType"));
}
use of com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseType in project ds3_autogen by SpectraLogic.
the class BaseResponseGenerator_Test method toParamList_FullList_Test.
@Test
public void toParamList_FullList_Test() {
final ImmutableList<Ds3ResponseCode> responseCodes = ImmutableList.of(new Ds3ResponseCode(200, ImmutableList.of(new Ds3ResponseType("com.test.TestTypeB", null))), new Ds3ResponseCode(201, ImmutableList.of(new Ds3ResponseType("null", null))), new Ds3ResponseCode(203, ImmutableList.of(new Ds3ResponseType("com.test.TestTypeA", null))), new Ds3ResponseCode(400, ImmutableList.of(new Ds3ResponseType("com.test.TestTypeC", null))));
final ImmutableList<Arguments> result = generator.toParamList(responseCodes);
assertThat(result.size(), is(2));
assertThat(result.get(0).getName(), is("testTypeAResult"));
assertThat(result.get(1).getName(), is("testTypeBResult"));
}
use of com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseType in project ds3_autogen by SpectraLogic.
the class BaseResponseGenerator_Test method toParam_NullPayload_Test.
@Test
public void toParam_NullPayload_Test() {
final Ds3ResponseCode responseCode = new Ds3ResponseCode(200, ImmutableList.of(new Ds3ResponseType("null", null)));
final Optional<Arguments> result = toParam(responseCode);
assertFalse(result.isPresent());
}
use of com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseType in project ds3_autogen by SpectraLogic.
the class BaseResponseGenerator_Test method toParam_ComponentType_Test.
@Test
public void toParam_ComponentType_Test() {
final Ds3ResponseCode responseCode = new Ds3ResponseCode(200, ImmutableList.of(new Ds3ResponseType("array", "com.test.ComponentType")));
final Optional<Arguments> result = toParam(responseCode);
assertTrue(result.isPresent());
assertThat(result.get().getName(), is("componentTypeListResult"));
assertThat(result.get().getType(), is("List<ComponentType>"));
}
Aggregations