Search in sources :

Example 6 with Ds3ResponseCode

use of com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseCode in project ds3_autogen by SpectraLogic.

the class RequestConverter method getResponseType.

public static String getResponseType(final ImmutableList<Ds3ResponseCode> responseCodes) {
    if (isEmpty(responseCodes))
        return "";
    String responseTypeName = "";
    for (final Ds3ResponseCode responseCode : responseCodes) {
        final int rc = responseCode.getCode();
        if (rc < 200 || rc >= 300)
            continue;
        for (final Ds3ResponseType responseType : responseCode.getDs3ResponseTypes()) {
            if (ConverterUtil.hasContent(responseType.getType()) && !responseType.getType().contentEquals("null")) {
                responseTypeName = responseType.getType();
            } else if (ConverterUtil.hasContent(responseType.getComponentType()) && !responseType.getComponentType().contentEquals("null")) {
                responseTypeName = responseType.getComponentType();
            }
        }
    }
    LOG.debug("\tResponse Type: " + responseTypeName);
    if (responseTypeName.equalsIgnoreCase("java.lang.String")) {
        return "ds3_str";
    } else if (!responseTypeName.isEmpty()) {
        return StructHelper.getResponseTypeName(responseTypeName);
    }
    return "";
}
Also used : Ds3ResponseCode(com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseCode) Ds3ResponseType(com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseType)

Example 7 with Ds3ResponseCode

use of com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseCode in project ds3_autogen by SpectraLogic.

the class BaseResponseGenerator_Test method toResponseCodeList_Test.

@Test
public void toResponseCodeList_Test() {
    final ImmutableList<ResponseCode> expectedCodes = ImmutableList.of(new ResponseCode(200, "var body ResponseName\n" + "        if err := readResponseBody(webResponse, &body.TypeName); err != nil {\n" + "            return nil, err\n" + "        }\n" + "        return &body, nil"), new ResponseCode(204, "return &ResponseName{}, nil"));
    final ImmutableList<Ds3ResponseCode> responseCodes = ImmutableList.of(new Ds3ResponseCode(200, ImmutableList.of(new Ds3ResponseType("com.test.TypeName", ""))), new Ds3ResponseCode(204, ImmutableList.of(new Ds3ResponseType("null", ""))));
    final ImmutableList<ResponseCode> result = generator.toResponseCodeList(responseCodes, "ResponseName");
    expectedCodes.forEach(expected -> assertThat(result, hasItem(expected)));
}
Also used : ResponseCode(com.spectralogic.ds3autogen.go.models.response.ResponseCode) Ds3ResponseCode(com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseCode) Ds3ResponseCode(com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseCode) Ds3ResponseType(com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseType) Test(org.junit.Test)

Example 8 with Ds3ResponseCode

use of com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseCode in project ds3_autogen by SpectraLogic.

the class BaseResponseGenerator_Test method toResponsePayloadStruct_StringPayload_Test.

@Test
public void toResponsePayloadStruct_StringPayload_Test() {
    final String expected = "Content string";
    final ImmutableList<Ds3ResponseCode> responseCodes = ImmutableList.of(new Ds3ResponseCode(200, ImmutableList.of(new Ds3ResponseType("java.lang.String", ""))), new Ds3ResponseCode(204, ImmutableList.of(new Ds3ResponseType("null", ""))));
    final String result = generator.toResponsePayloadStruct(responseCodes);
    assertThat(result, is(expected));
}
Also used : Ds3ResponseCode(com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseCode) Ds3ResponseType(com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseType) Test(org.junit.Test)

Example 9 with Ds3ResponseCode

use of com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseCode in project ds3_autogen by SpectraLogic.

the class GetObjectResponseGenerator_Test method toResponseCode_200_Test.

@Test
public void toResponseCode_200_Test() {
    final ResponseCode expected = new ResponseCode(200, "return &GetObjectResponse{ Content: webResponse.Body() }, nil");
    final Ds3ResponseCode code = new Ds3ResponseCode(200, ImmutableList.of(new Ds3ResponseType("null", null)));
    final ResponseCode result = generator.toResponseCode(code, "GetObjectResponse");
    assertThat(result, is(expected));
}
Also used : ResponseCode(com.spectralogic.ds3autogen.go.models.response.ResponseCode) Ds3ResponseCode(com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseCode) Ds3ResponseCode(com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseCode) Ds3ResponseType(com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseType) Test(org.junit.Test)

Example 10 with Ds3ResponseCode

use of com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseCode in project ds3_autogen by SpectraLogic.

the class BaseResponseGenerator_Test method toResponseCode_Exception_Test.

@Test(expected = IllegalArgumentException.class)
public void toResponseCode_Exception_Test() {
    final Ds3ResponseCode responseCode = new Ds3ResponseCode(200, ImmutableList.of());
    generator.toResponseCode(responseCode, "ResponseName");
}
Also used : Ds3ResponseCode(com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseCode) Test(org.junit.Test)

Aggregations

Ds3ResponseCode (com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseCode)52 Test (org.junit.Test)43 Ds3ResponseType (com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseType)30 ResponseCode (com.spectralogic.ds3autogen.java.models.ResponseCode)8 ResponseCode (com.spectralogic.ds3autogen.go.models.response.ResponseCode)6 Arguments (com.spectralogic.ds3autogen.api.models.Arguments)4 ImmutableList (com.google.common.collect.ImmutableList)3 CaseFormat (com.google.common.base.CaseFormat)1 com.spectralogic.ds3autogen.api.models (com.spectralogic.ds3autogen.api.models)1 Action (com.spectralogic.ds3autogen.api.models.enums.Action)1 HttpVerb (com.spectralogic.ds3autogen.api.models.enums.HttpVerb)1 Operation (com.spectralogic.ds3autogen.api.models.enums.Operation)1 Ds3ResponseCodeFixtureTestHelper.createPopulatedErrorResponseCode (com.spectralogic.ds3autogen.java.test.helpers.Ds3ResponseCodeFixtureTestHelper.createPopulatedErrorResponseCode)1 Ds3ResponseCodeFixtureTestHelper.createPopulatedResponseCode (com.spectralogic.ds3autogen.java.test.helpers.Ds3ResponseCodeFixtureTestHelper.createPopulatedResponseCode)1 ResponseAndParserUtils.getDs3ResponseCode (com.spectralogic.ds3autogen.java.utils.ResponseAndParserUtils.getDs3ResponseCode)1 ConverterUtil.isEmpty (com.spectralogic.ds3autogen.utils.ConverterUtil.isEmpty)1 CustomArgumentComparator (com.spectralogic.ds3autogen.utils.comparators.CustomArgumentComparator)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1