Search in sources :

Example 41 with Arguments

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

the class JavaFunctionalTests method replicatePutJobRequest.

@Test
public void replicatePutJobRequest() throws IOException, TemplateModelException {
    final String requestName = "ReplicatePutJobSpectraS3Request";
    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/replicatePutJobRequestHandler.xml");
    final String requestGeneratedCode = testGeneratedCode.getRequestGeneratedCode();
    CODE_LOGGER.logFile(requestGeneratedCode, FileTypeToLog.REQUEST);
    assertTrue(extendsClass(requestName, "AbstractRequest", requestGeneratedCode));
    assertTrue(isOptParamOfType("ConflictResolutionMode", "ReplicationConflictResolutionMode", requestName, requestGeneratedCode, false));
    assertTrue(isOptParamOfType("Priority", "Priority", requestName, requestGeneratedCode, true));
    assertTrue(isReqVariable("BucketName", "String", requestGeneratedCode));
    assertTrue(isReqVariable("RequestPayload", "String", requestGeneratedCode));
    assertFalse(isReqVariable("Replicate", "boolean", 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("com.spectralogic.ds3client.models.ReplicationConflictResolutionMode", requestGeneratedCode));
    assertTrue(hasImport("com.spectralogic.ds3client.models.Priority", requestGeneratedCode));
    assertTrue(hasImport("java.nio.charset.Charset", requestGeneratedCode));
    assertTrue(isOfPackage("com.spectralogic.ds3client.commands.spectrads3", requestGeneratedCode));
    assertFalse(requestGeneratedCode.contains("RestOperationType"));
    assertTrue(hasOperation(Operation.START_BULK_PUT, requestGeneratedCode));
    assertTrue(hasCopyright(requestGeneratedCode));
    final ImmutableList<Arguments> constructorArgs = ImmutableList.of(new Arguments("String", "BucketName"), new Arguments("String", "RequestPayload"));
    assertTrue(hasConstructor(requestName, constructorArgs, requestGeneratedCode));
    assertTrue(constructorHasVoidQueryParam("replicate", 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.models.MasterObjectList", responseGeneratedCode));
    assertTrue(hasImport("com.spectralogic.ds3client.commands.interfaces.AbstractResponse", responseGeneratedCode));
    assertTrue(isReqParamOfType("masterObjectListResult", "MasterObjectList", responseName, responseGeneratedCode, false));
    //Test the Ds3Client
    final String ds3ClientGeneratedCode = testGeneratedCode.getDs3ClientGeneratedCode();
    CODE_LOGGER.logFile(ds3ClientGeneratedCode, FileTypeToLog.CLIENT);
    testDs3Client(requestName, ds3ClientGeneratedCode);
    assertTrue(ds3ClientGeneratedCode.contains("@ResponsePayloadModel(\"MasterObjectList\")"));
    assertTrue(ds3ClientGeneratedCode.contains("@Action(\"MODIFY\")"));
    assertTrue(ds3ClientGeneratedCode.contains("@Resource(\"BUCKET\")"));
    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.models.MasterObjectList", 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));
    final BaseParseResponse expectedParsing = new BaseParseResponse(responseName, "MasterObjectList");
    assertTrue(responseParserCode.contains(expectedParsing.toJavaCode()));
    final NullParseResponse nullExpectedParsing = new NullParseResponse(responseName);
    assertTrue(responseParserCode.contains(nullExpectedParsing.toJavaCode()));
    assertTrue(responseParserCode.contains("private final int[] expectedStatusCodes = new int[]{200, 204};"));
}
Also used : TestGeneratedCode(com.spectralogic.ds3autogen.java.utils.TestGeneratedCode) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) Arguments(com.spectralogic.ds3autogen.api.models.Arguments) BaseParseResponse(com.spectralogic.ds3autogen.java.models.parseresponse.BaseParseResponse) NullParseResponse(com.spectralogic.ds3autogen.java.models.parseresponse.NullParseResponse) Test(org.junit.Test)

Example 42 with Arguments

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

the class JavaFunctionalTests method getPhysicalPlacementForObjectsRequestHandler_FullDetails.

@Test
public void getPhysicalPlacementForObjectsRequestHandler_FullDetails() throws IOException, TemplateModelException {
    final String requestName = "GetPhysicalPlacementForObjectsWithFullDetailsSpectraS3Request";
    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/getPhysicalPlacementFullDetailsRequest.xml");
    final String requestGeneratedCode = testGeneratedCode.getRequestGeneratedCode();
    CODE_LOGGER.logFile(requestGeneratedCode, FileTypeToLog.REQUEST);
    assertTrue(extendsClass(requestName, "AbstractRequest", requestGeneratedCode));
    assertTrue(isReqParamOfType("BucketName", "String", requestName, requestGeneratedCode, false));
    assertTrue(isReqParamOfType("Objects", "List<Ds3Object>", requestName, requestGeneratedCode, false));
    assertTrue(isOptParamOfType("StorageDomainId", "String", requestName, requestGeneratedCode, false));
    assertTrue(hasMethod("getStream", "InputStream", Scope.PUBLIC, requestGeneratedCode));
    assertTrue(requestGeneratedCode.contains("this.getQueryParams().put(\"full_details\", null)"));
    assertFalse(doesConstructorContainParam("FullDetails", "void", requestName, requestGeneratedCode));
    assertFalse(isReqVariable("FullDetails", "void", requestGeneratedCode));
    assertFalse(hasGetter("FullDetails", "void", requestGeneratedCode));
    assertFalse(doesConstructorContainParam("Test", "boolean", requestName, requestGeneratedCode));
    assertFalse(isReqVariable("Test", "boolean", requestGeneratedCode));
    assertFalse(hasGetter("Test", "boolean", requestGeneratedCode));
    assertTrue(hasImport("com.spectralogic.ds3client.networking.HttpVerb", requestGeneratedCode));
    assertTrue(hasImport("java.util.UUID", requestGeneratedCode));
    assertTrue(hasImport("com.spectralogic.ds3client.models.bulk.Ds3Object", requestGeneratedCode));
    assertTrue(hasImport("com.spectralogic.ds3client.models.bulk.Ds3ObjectList", requestGeneratedCode));
    assertTrue(hasImport("com.spectralogic.ds3client.serializer.XmlOutput", requestGeneratedCode));
    assertTrue(hasImport("java.io.ByteArrayInputStream", requestGeneratedCode));
    assertTrue(hasImport("java.io.InputStream", 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));
    assertFalse(requestGeneratedCode.contains("RestOperationType"));
    assertTrue(hasOperation(Operation.GET_PHYSICAL_PLACEMENT, requestGeneratedCode));
    assertTrue(hasCopyright(requestGeneratedCode));
    assertTrue(hasPath("\"/_rest_/bucket/\" + this.bucketName", requestGeneratedCode));
    final ImmutableList<Arguments> constructorArgs = ImmutableList.of(new Arguments("String", "BucketName"), new Arguments("List<Ds3Object>", "Objects"));
    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(hasImport("com.spectralogic.ds3client.models.BulkObjectList", responseGeneratedCode));
    assertTrue(isReqParamOfType("bulkObjectListResult", "BulkObjectList", responseName, responseGeneratedCode, false));
    //Test the Ds3Client
    final String ds3ClientGeneratedCode = testGeneratedCode.getDs3ClientGeneratedCode();
    CODE_LOGGER.logFile(ds3ClientGeneratedCode, FileTypeToLog.CLIENT);
    testDs3Client(requestName, ds3ClientGeneratedCode);
    assertTrue(ds3ClientGeneratedCode.contains("@ResponsePayloadModel(\"BulkObjectList\")"));
    assertTrue(ds3ClientGeneratedCode.contains("@Action(\"MODIFY\")"));
    assertTrue(ds3ClientGeneratedCode.contains("@Resource(\"BUCKET\")"));
    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.models.BulkObjectList", 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));
    final BaseParseResponse expectedParsing = new BaseParseResponse(responseName, "BulkObjectList");
    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) BaseParseResponse(com.spectralogic.ds3autogen.java.models.parseresponse.BaseParseResponse) Test(org.junit.Test)

Example 43 with Arguments

use of com.spectralogic.ds3autogen.api.models.Arguments 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)

Example 44 with Arguments

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

the class PaginationResponseGenerator method toConstructorParams.

/**
     * Retrieves the list of parameters need to create the response POJO and
     * adds the pagination parameters to the end of the list.
     */
@Override
public String toConstructorParams(final ImmutableList<Arguments> params) {
    final ImmutableList.Builder<Arguments> builder = ImmutableList.builder();
    if (hasContent(params)) {
        builder.addAll(params);
    }
    builder.add(new Arguments("Integer", "pagingTotalResultCount"));
    builder.add(new Arguments("Integer", "pagingTruncated"));
    return builder.build().stream().map(i -> "final " + i.getType() + " " + uncapFirst(i.getName())).collect(Collectors.joining(", "));
}
Also used : Arguments(com.spectralogic.ds3autogen.api.models.Arguments) ImmutableList(com.google.common.collect.ImmutableList) Helper.uncapFirst(com.spectralogic.ds3autogen.utils.Helper.uncapFirst) Collectors(java.util.stream.Collectors) ConverterUtil.hasContent(com.spectralogic.ds3autogen.utils.ConverterUtil.hasContent) ImmutableList(com.google.common.collect.ImmutableList) Arguments(com.spectralogic.ds3autogen.api.models.Arguments)

Example 45 with Arguments

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

the class CommonRequestGeneratorUtils method createInputStreamConstructor.

/**
     * Creates a constructor with the provided parameters in addition to
     * adding the required parameter Stream for parsing a request payload.
     */
public static RequestConstructor createInputStreamConstructor(final ImmutableList<Arguments> parameters, final ImmutableList<QueryParam> queryParams, final String requestName, final Ds3DocSpec docSpec) {
    final ImmutableList.Builder<Arguments> builder = ImmutableList.builder();
    if (hasContent(parameters)) {
        builder.addAll(parameters);
    }
    builder.add(new Arguments("InputStream", "Stream"));
    final ImmutableList<Arguments> updatedParameters = builder.build();
    final ImmutableList<String> argNames = updatedParameters.stream().map(Arguments::getName).collect(GuavaCollectors.immutableList());
    return new RequestConstructor(updatedParameters, updatedParameters, queryParams, toConstructorDocs(requestName, argNames, docSpec, 1));
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Arguments(com.spectralogic.ds3autogen.api.models.Arguments) RequestConstructor(com.spectralogic.ds3autogen.java.models.RequestConstructor)

Aggregations

Arguments (com.spectralogic.ds3autogen.api.models.Arguments)188 Test (org.junit.Test)144 FileUtils (com.spectralogic.ds3autogen.api.FileUtils)46 ImmutableList (com.google.common.collect.ImmutableList)40 RequestConstructor (com.spectralogic.ds3autogen.java.models.RequestConstructor)33 Ds3Request (com.spectralogic.ds3autogen.api.models.apispec.Ds3Request)25 Ds3DocSpecEmptyImpl (com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl)25 TestGeneratedCode (com.spectralogic.ds3autogen.java.utils.TestGeneratedCode)25 TestGenerateCode (com.spectralogic.ds3autogen.net.utils.TestGenerateCode)21 QueryParam (com.spectralogic.ds3autogen.java.models.QueryParam)19 Helper.removeVoidArguments (com.spectralogic.ds3autogen.utils.Helper.removeVoidArguments)15 BaseParseResponse (com.spectralogic.ds3autogen.java.models.parseresponse.BaseParseResponse)14 RequestGeneratorTestHelper.createSimpleTestDs3Request (com.spectralogic.ds3autogen.java.test.helpers.RequestGeneratorTestHelper.createSimpleTestDs3Request)13 Ds3Param (com.spectralogic.ds3autogen.api.models.apispec.Ds3Param)9 GuavaCollectors (com.spectralogic.ds3autogen.utils.collections.GuavaCollectors)8 CustomArgumentComparator (com.spectralogic.ds3autogen.utils.comparators.CustomArgumentComparator)8 ConstructorParam (com.spectralogic.ds3autogen.python.model.request.ConstructorParam)7 Helper.camelToUnderscore (com.spectralogic.ds3autogen.utils.Helper.camelToUnderscore)7 RequestConverterUtil.getNonVoidArgsFromParamList (com.spectralogic.ds3autogen.utils.RequestConverterUtil.getNonVoidArgsFromParamList)6 Ds3ResponseType (com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseType)5