Search in sources :

Example 1 with StringParseResponse

use of com.spectralogic.ds3autogen.java.models.parseresponse.StringParseResponse in project ds3_autogen by SpectraLogic.

the class JavaFunctionalTests method GetBlobPersistenceRequest_Test.

@Test
public void GetBlobPersistenceRequest_Test() throws IOException, TemplateModelException {
    final String requestName = "GetBlobPersistenceSpectraS3Request";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGeneratedCode testGeneratedCode = new TestGeneratedCode(fileUtils, requestName, "./ds3-sdk/src/main/java/com/spectralogic/ds3client/commands/spectrads3/");
    testGeneratedCode.generateCode(fileUtils, "/input/getBlobPersistenceRequest.xml");
    final String requestGeneratedCode = testGeneratedCode.getRequestGeneratedCode();
    CODE_LOGGER.logFile(requestGeneratedCode, FileTypeToLog.REQUEST);
    assertTrue(extendsClass(requestName, "AbstractRequest", requestGeneratedCode));
    assertTrue(isReqVariable("RequestPayload", "String", requestGeneratedCode));
    assertTrue(hasImport("com.spectralogic.ds3client.networking.HttpVerb", requestGeneratedCode));
    assertTrue(hasImport("java.io.ByteArrayInputStream", requestGeneratedCode));
    assertTrue(hasImport("java.io.InputStream", requestGeneratedCode));
    assertTrue(hasImport("com.spectralogic.ds3client.utils.Guard", requestGeneratedCode));
    assertTrue(hasImport("com.spectralogic.ds3client.commands.interfaces.AbstractRequest", requestGeneratedCode));
    assertTrue(hasImport("java.nio.charset.Charset", requestGeneratedCode));
    assertTrue(isOfPackage("com.spectralogic.ds3client.commands.spectrads3", requestGeneratedCode));
    assertTrue(hasCopyright(requestGeneratedCode));
    final ImmutableList<Arguments> constructorArgs = ImmutableList.of(new Arguments("String", "RequestPayload"));
    assertTrue(hasConstructor(requestName, constructorArgs, requestGeneratedCode));
    //Test the generated response
    final String responseGeneratedCode = testGeneratedCode.getResponseGeneratedCode();
    CODE_LOGGER.logFile(responseGeneratedCode, FileTypeToLog.RESPONSE);
    final String responseName = requestName.replace("Request", "Response");
    assertTrue(extendsClass(responseName, "AbstractResponse", responseGeneratedCode));
    assertTrue(isOfPackage("com.spectralogic.ds3client.commands.spectrads3", responseGeneratedCode));
    assertTrue(hasImport("com.spectralogic.ds3client.commands.interfaces.AbstractResponse", responseGeneratedCode));
    assertTrue(isReqParamOfType("stringResult", "String", responseName, responseGeneratedCode, false));
    //Test the Ds3Client
    final String ds3ClientGeneratedCode = testGeneratedCode.getDs3ClientGeneratedCode();
    CODE_LOGGER.logFile(ds3ClientGeneratedCode, FileTypeToLog.CLIENT);
    testDs3Client(requestName, ds3ClientGeneratedCode);
    final String ds3ClientImplGeneratedCode = testGeneratedCode.getDs3ClientImplGeneratedCode();
    CODE_LOGGER.logFile(ds3ClientImplGeneratedCode, FileTypeToLog.CLIENT);
    testDs3ClientImpl(requestName, ds3ClientImplGeneratedCode);
    //Test the response parser
    final String responseParserCode = testGeneratedCode.getResponseParserGeneratedCode();
    CODE_LOGGER.logFile(responseParserCode, FileTypeToLog.PARSER);
    assertTrue(isOfPackage("com.spectralogic.ds3client.commands.parsers", responseParserCode));
    assertTrue(hasImport("com.spectralogic.ds3client.commands.spectrads3." + responseName, responseParserCode));
    assertTrue(hasImport("com.spectralogic.ds3client.commands.parsers.interfaces.AbstractResponseParser", responseParserCode));
    assertTrue(hasImport("com.spectralogic.ds3client.networking.WebResponse", responseParserCode));
    assertTrue(hasImport("com.spectralogic.ds3client.serializer.XmlOutput", responseParserCode));
    assertTrue(hasImport("java.io.IOException", responseParserCode));
    assertTrue(hasImport("java.io.InputStream", responseParserCode));
    assertTrue(hasImport("com.spectralogic.ds3client.commands.parsers.utils.ResponseParserUtils", responseParserCode));
    assertTrue(hasImport("org.apache.commons.io.IOUtils", responseParserCode));
    assertTrue(hasImport("java.nio.charset.StandardCharsets", responseParserCode));
    final StringParseResponse expectedParsing = new StringParseResponse(responseName);
    assertTrue(responseParserCode.contains(expectedParsing.toJavaCode()));
    assertTrue(responseParserCode.contains("private final int[] expectedStatusCodes = new int[]{200};"));
}
Also used : TestGeneratedCode(com.spectralogic.ds3autogen.java.utils.TestGeneratedCode) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) Arguments(com.spectralogic.ds3autogen.api.models.Arguments) StringParseResponse(com.spectralogic.ds3autogen.java.models.parseresponse.StringParseResponse) Test(org.junit.Test)

Aggregations

FileUtils (com.spectralogic.ds3autogen.api.FileUtils)1 Arguments (com.spectralogic.ds3autogen.api.models.Arguments)1 StringParseResponse (com.spectralogic.ds3autogen.java.models.parseresponse.StringParseResponse)1 TestGeneratedCode (com.spectralogic.ds3autogen.java.utils.TestGeneratedCode)1 Test (org.junit.Test)1