Search in sources :

Example 21 with FileUtils

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

the class NetCodeGenerator_Test method simpleRequest.

@Test
public void simpleRequest() throws IOException, TemplateModelException {
    final String requestName = "GetObjectRequest";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/");
    codeGenerator.generateCode(fileUtils, "/input/singleRequestHandler.xml");
    final String requestCode = codeGenerator.getRequestCode();
    CODE_LOGGER.logFile(requestCode, FileTypeToLog.REQUEST);
    assertTrue(TestHelper.extendsClass("GetObjectRequest", "Ds3Request", requestCode));
    assertTrue(TestHelper.hasProperty("Verb", "HttpVerb", requestCode));
    assertTrue(TestHelper.hasProperty("Path", "string", requestCode));
    //Generate Parser
    final String parserCode = codeGenerator.getParserCode();
    CODE_LOGGER.logFile(parserCode, FileTypeToLog.PARSER);
    assertTrue(hasContent(parserCode));
}
Also used : TestGenerateCode(com.spectralogic.ds3autogen.net.utils.TestGenerateCode) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) Test(org.junit.Test)

Example 22 with FileUtils

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

the class NetCodeGenerator_Test method getJobsRequest_Test.

@Test
public void getJobsRequest_Test() throws IOException, TemplateModelException {
    final String requestName = "GetJobsSpectraS3Request";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/", "JobList");
    codeGenerator.generateCode(fileUtils, "/input/getJobsRequest.xml");
    //Generate Request code
    final String requestCode = codeGenerator.getRequestCode();
    CODE_LOGGER.logFile(requestCode, FileTypeToLog.REQUEST);
    assertTrue(TestHelper.extendsClass(requestName, "Ds3Request", requestCode));
    assertTrue(TestHelper.hasProperty("Verb", "HttpVerb", requestCode));
    assertTrue(TestHelper.hasProperty("Path", "string", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "BucketId", "Guid", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "FullDetails", "bool", requestCode));
    assertTrue(TestHelper.hasConstructor(requestName, ImmutableList.of(), requestCode));
    //Generate Client code
    final String commandName = requestName.replace("Request", "");
    final String clientCode = codeGenerator.getClientCode();
    CODE_LOGGER.logFile(clientCode, FileTypeToLog.CLIENT);
    assertTrue(TestHelper.hasPayloadCommand(commandName, clientCode));
    final String idsClientCode = codeGenerator.getIdsClientCode();
    CODE_LOGGER.logFile(idsClientCode, FileTypeToLog.CLIENT);
    assertTrue(TestHelper.hasIDsCommand(commandName, idsClientCode));
    //Generate Responses
    final String responseCode = codeGenerator.getResponseCode();
    CODE_LOGGER.logFile(responseCode, FileTypeToLog.RESPONSE);
    final String responseName = NormalizingContractNamesUtil.toResponseName(requestName);
    final String responsePayloadType = "JobList";
    assertTrue(TestHelper.hasConstructor(responseName, ImmutableList.of(new Arguments(responsePayloadType, "ResponsePayload")), responseCode));
    assertTrue(TestHelper.hasRequiredParam("ResponsePayload", responsePayloadType, responseCode));
    //Generate Parser
    final String parserCode = codeGenerator.getParserCode();
    CODE_LOGGER.logFile(parserCode, FileTypeToLog.PARSER);
    assertTrue(parserHasResponseCode(200, parserCode));
    assertTrue(parserHasPayload("JobList", "Jobs", parserCode));
}
Also used : TestGenerateCode(com.spectralogic.ds3autogen.net.utils.TestGenerateCode) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) Arguments(com.spectralogic.ds3autogen.api.models.Arguments) Test(org.junit.Test)

Example 23 with FileUtils

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

the class NetCodeGenerator_Test method getObjectsDetailsSpectraS3Request_Test.

@Test
public void getObjectsDetailsSpectraS3Request_Test() throws IOException, TemplateModelException {
    final String requestName = "GetObjectsDetailsSpectraS3Request";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/", "S3ObjectList");
    codeGenerator.generateCode(fileUtils, "/input/getObjectsDetailsRequest.xml");
    //Generate Request code
    final String requestCode = codeGenerator.getRequestCode();
    CODE_LOGGER.logFile(requestCode, FileTypeToLog.REQUEST);
    assertTrue(TestHelper.extendsClass(requestName, "Ds3Request", requestCode));
    assertTrue(TestHelper.hasProperty("Verb", "HttpVerb", requestCode));
    assertTrue(TestHelper.hasProperty("Path", "string", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "BucketId", "string", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "Folder", "string", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "LastPage", "bool?", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "Latest", "bool?", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "Name", "string", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "PageLength", "int?", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "PageOffset", "int?", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "PageStartMarker", "string", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "Type", "S3ObjectType", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "Version", "long?", requestCode));
    assertTrue(TestHelper.hasConstructor(requestName, ImmutableList.of(), requestCode));
    //Generate Client code
    final String commandName = requestName.replace("Request", "");
    final String clientCode = codeGenerator.getClientCode();
    CODE_LOGGER.logFile(clientCode, FileTypeToLog.CLIENT);
    assertTrue(TestHelper.hasPayloadCommand(commandName, clientCode));
    final String idsClientCode = codeGenerator.getIdsClientCode();
    CODE_LOGGER.logFile(idsClientCode, FileTypeToLog.CLIENT);
    assertTrue(TestHelper.hasIDsCommand(commandName, idsClientCode));
    //Generate Responses
    final String responseCode = codeGenerator.getResponseCode();
    CODE_LOGGER.logFile(responseCode, FileTypeToLog.RESPONSE);
    assertTrue(responseCode.contains("public GetObjectsDetailsSpectraS3Response(S3ObjectList responsePayload, int? pagingTruncated, int? pagingTotalResultCount)"));
    //Generate Parser
    final String parserCode = codeGenerator.getParserCode();
    CODE_LOGGER.logFile(parserCode, FileTypeToLog.PARSER);
    assertTrue(parserHasResponseCode(200, parserCode));
    assertTrue(parserHasPayload("S3ObjectList", "Data", parserCode));
}
Also used : TestGenerateCode(com.spectralogic.ds3autogen.net.utils.TestGenerateCode) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) Test(org.junit.Test)

Example 24 with FileUtils

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

the class JavaFunctionalTests method getObjectsDetailsRequest_Test.

@Test
public void getObjectsDetailsRequest_Test() throws IOException, TemplateModelException {
    final String requestName = "GetObjectsDetailsSpectraS3Request";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGeneratedComponentResponseCode testGeneratedCode = new TestGeneratedComponentResponseCode(fileUtils, requestName, "./ds3-sdk/src/main/java/com/spectralogic/ds3client/commands/spectrads3/", "./ds3-sdk/src/main/java/com/spectralogic/ds3client/models/S3ObjectList.java");
    testGeneratedCode.generateCode(fileUtils, "/input/getObjectsDetailsRequestHandler.xml");
    final String requestGeneratedCode = testGeneratedCode.getRequestGeneratedCode();
    CODE_LOGGER.logFile(requestGeneratedCode, FileTypeToLog.REQUEST);
    //Verify that name mapped from GetObjects to GetObjectsDetailsSpectraS3
    assertTrue(extendsClass(requestName, "AbstractPaginationRequest", 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, "AbstractPaginationResponse", responseGeneratedCode));
    assertTrue(hasImport("com.spectralogic.ds3client.commands.interfaces.AbstractPaginationResponse", responseGeneratedCode));
    assertTrue(isReqParamOfType("s3ObjectListResult", "S3ObjectList", responseName, responseGeneratedCode, false));
    assertTrue(isReqParamOfType("pagingTotalResultCount", "Integer", responseName, responseGeneratedCode, true));
    assertTrue(isReqParamOfType("pagingTruncated", "Integer", responseName, responseGeneratedCode, true));
    //Test the Ds3Client
    final String ds3ClientGeneratedCode = testGeneratedCode.getDs3ClientGeneratedCode();
    CODE_LOGGER.logFile(ds3ClientGeneratedCode, FileTypeToLog.CLIENT);
    testDs3Client(requestName, ds3ClientGeneratedCode);
    assertTrue(ds3ClientGeneratedCode.contains("@ResponsePayloadModel(\"S3ObjectList\")"));
    assertTrue(ds3ClientGeneratedCode.contains("@Action(\"LIST\")"));
    assertTrue(ds3ClientGeneratedCode.contains("@Resource(\"OBJECT\")"));
    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.S3ObjectList", 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, "S3ObjectList", true);
    assertTrue(responseParserCode.contains(expectedParsing.toJavaCode()));
    assertTrue(responseParserCode.contains("private final int[] expectedStatusCodes = new int[]{200};"));
}
Also used : TestGeneratedComponentResponseCode(com.spectralogic.ds3autogen.java.utils.TestGeneratedComponentResponseCode) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) BaseParseResponse(com.spectralogic.ds3autogen.java.models.parseresponse.BaseParseResponse) Test(org.junit.Test)

Example 25 with FileUtils

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

the class JavaFunctionalTests method getJobChunksReadyForClientProcessingRequest.

@Test
public void getJobChunksReadyForClientProcessingRequest() throws IOException, TemplateModelException {
    final String requestName = "GetJobChunksReadyForClientProcessingSpectraS3Request";
    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/getJobChunksReadyForClientProcessingRequest.xml");
    final String requestGeneratedCode = testGeneratedCode.getRequestGeneratedCode();
    CODE_LOGGER.logFile(requestGeneratedCode, FileTypeToLog.REQUEST);
    assertTrue(extendsClass(requestName, "AbstractRequest", requestGeneratedCode));
    assertTrue(isOfPackage("com.spectralogic.ds3client.commands.spectrads3", requestGeneratedCode));
    assertTrue(hasCopyright(requestGeneratedCode));
    assertTrue(isReqParamOfType("Job", "String", requestName, requestGeneratedCode, false));
    assertTrue(hasImport("com.spectralogic.ds3client.commands.interfaces.AbstractRequest", requestGeneratedCode));
    assertTrue(hasImport("com.spectralogic.ds3client.networking.HttpVerb", requestGeneratedCode));
    assertTrue(hasImport("java.util.UUID", requestGeneratedCode));
    assertTrue(doesNotHaveOperation(requestGeneratedCode));
    assertTrue(hasPath("\"/_rest_/job_chunk\"", requestGeneratedCode));
    final ImmutableList<Arguments> constructorArgs = ImmutableList.of(new Arguments("UUID", "Job"));
    assertTrue(hasConstructor(requestName, constructorArgs, requestGeneratedCode));
    assertTrue(hasConstructor(requestName, modifyType(constructorArgs, "UUID", "String"), 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.MasterObjectList", responseGeneratedCode));
    assertTrue(isReqParamOfType("masterObjectListResult", "MasterObjectList", responseName, responseGeneratedCode, false));
    assertTrue(isReqParamOfType("retryAfterSeconds", "int", responseName, responseGeneratedCode, false));
    assertTrue(isReqParamOfType("status", "Status", responseName, responseGeneratedCode, false));
    assertTrue(responseGeneratedCode.contains("public enum Status { AVAILABLE, RETRYLATER }"));
    //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(\"LIST\")"));
    assertTrue(ds3ClientGeneratedCode.contains("@Resource(\"JOB_CHUNK\")"));
    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.parsers.interfaces.AbstractResponseParser", responseParserCode));
    assertTrue(hasImport("com.spectralogic.ds3client.networking.WebResponse", responseParserCode));
    assertTrue(hasImport("java.io.IOException", responseParserCode));
    assertTrue(hasImport("com.spectralogic.ds3client.commands.spectrads3." + responseName, responseParserCode));
    assertTrue(hasImport("com.spectralogic.ds3client.commands.parsers.utils.ResponseParserUtils", responseParserCode));
    assertTrue(hasImport("com.spectralogic.ds3client.exceptions.RetryAfterExpectedException", responseParserCode));
    assertTrue(hasImport("com.spectralogic.ds3client.models.MasterObjectList", responseParserCode));
    assertTrue(hasImport("com.spectralogic.ds3client.serializer.XmlOutput", responseParserCode));
    assertTrue(hasImport("java.io.InputStream", responseParserCode));
    assertTrue(responseParserCode.contains("import static com.spectralogic.ds3client.utils.Guard.isNullOrEmpty"));
    assertTrue(responseParserCode.contains("return new GetJobChunksReadyForClientProcessingSpectraS3Response(result, parseRetryAfter(response), GetJobChunksReadyForClientProcessingSpectraS3Response.Status.RETRYLATER, this.getChecksum(), this.getChecksumType());"));
    assertTrue(responseParserCode.contains("return new GetJobChunksReadyForClientProcessingSpectraS3Response(result, 0, GetJobChunksReadyForClientProcessingSpectraS3Response.Status.AVAILABLE, this.getChecksum(), this.getChecksumType());"));
    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) Test(org.junit.Test)

Aggregations

FileUtils (com.spectralogic.ds3autogen.api.FileUtils)113 Test (org.junit.Test)112 Arguments (com.spectralogic.ds3autogen.api.models.Arguments)46 TestGenerateCode (com.spectralogic.ds3autogen.net.utils.TestGenerateCode)34 TestGeneratedCode (com.spectralogic.ds3autogen.java.utils.TestGeneratedCode)30 GoTestCodeUtil (com.spectralogic.ds3autogen.go.utils.GoTestCodeUtil)19 BaseParseResponse (com.spectralogic.ds3autogen.java.models.parseresponse.BaseParseResponse)18 TestGeneratedModelCode (com.spectralogic.ds3autogen.java.utils.TestGeneratedModelCode)11 TestPythonGeneratedCode (com.spectralogic.ds3autogen.python.utils.TestPythonGeneratedCode)10 EmptyParseResponse (com.spectralogic.ds3autogen.java.models.parseresponse.EmptyParseResponse)5 TypeContent (com.spectralogic.ds3autogen.python.model.type.TypeContent)5 TypeElementList (com.spectralogic.ds3autogen.python.model.type.TypeElementList)5 ImmutableList (com.google.common.collect.ImmutableList)4 Ds3DocSpec (com.spectralogic.ds3autogen.api.models.docspec.Ds3DocSpec)4 Element (com.spectralogic.ds3autogen.java.models.Element)4 TestGeneratedComponentResponseCode (com.spectralogic.ds3autogen.java.utils.TestGeneratedComponentResponseCode)4 Ds3DocSpecImpl (com.spectralogic.ds3autogen.docspec.Ds3DocSpecImpl)3 TypeElement (com.spectralogic.ds3autogen.python.model.type.TypeElement)3 Ds3SpecParserImpl (com.spectralogic.ds3autogen.Ds3SpecParserImpl)2 CodeGenerator (com.spectralogic.ds3autogen.api.CodeGenerator)2