Search in sources :

Example 66 with FileUtils

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

the class JavaFunctionalTests method deleteBucket_Test.

@Test
public void deleteBucket_Test() throws IOException, TemplateModelException {
    final String requestName = "DeleteBucketSpectraS3Request";
    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/deleteBucket.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(isOptParamOfType("Replicate", "boolean", requestName, requestGeneratedCode, false));
    assertTrue(isOptParamOfType("Force", "boolean", requestName, requestGeneratedCode, false));
    //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));
    //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.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.DeleteBucketSpectraS3Response", responseParserCode));
    assertTrue(hasImport("com.spectralogic.ds3client.commands.parsers.utils.ResponseParserUtils", responseParserCode));
    final EmptyParseResponse expectedParsing = new EmptyParseResponse(responseName);
    assertTrue(responseParserCode.contains(expectedParsing.toJavaCode()));
    assertTrue(responseParserCode.contains("private final int[] expectedStatusCodes = new int[]{204};"));
}
Also used : TestGeneratedCode(com.spectralogic.ds3autogen.java.utils.TestGeneratedCode) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) EmptyParseResponse(com.spectralogic.ds3autogen.java.models.parseresponse.EmptyParseResponse) Test(org.junit.Test)

Example 67 with FileUtils

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

the class JavaFunctionalTests method deleteJobCreatedNotificationRegistrationRequestHandler.

@Test
public void deleteJobCreatedNotificationRegistrationRequestHandler() throws IOException, TemplateModelException {
    final String requestName = "DeleteJobCreatedNotificationRegistrationSpectraS3Request";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGeneratedCode testGeneratedCode = new TestGeneratedCode(fileUtils, requestName, "./ds3-sdk/src/main/java/com/spectralogic/ds3client/commands/spectrads3/notifications/");
    testGeneratedCode.generateCode(fileUtils, "/input/deleteJobCreatedNotificationRegistrationRequestHandler.xml");
    final String requestGeneratedCode = testGeneratedCode.getRequestGeneratedCode();
    CODE_LOGGER.logFile(requestGeneratedCode, FileTypeToLog.REQUEST);
    assertTrue(extendsClass(requestName, "AbstractDeleteNotificationRequest", requestGeneratedCode));
    assertTrue(hasPath("\"/_rest_/job_created_notification_registration/\" + this.getNotificationId().toString()", requestGeneratedCode));
    assertTrue(isOfPackage("com.spectralogic.ds3client.commands.spectrads3.notifications", requestGeneratedCode));
    assertTrue(hasImport("java.util.UUID", requestGeneratedCode));
    assertTrue(hasCopyright(requestGeneratedCode));
    assertTrue(hasImport("com.spectralogic.ds3client.commands.interfaces.AbstractDeleteNotificationRequest", requestGeneratedCode));
    final ImmutableList<Arguments> constructorArgs = ImmutableList.of(new Arguments("UUID", "NotificationId"));
    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.notifications", responseGeneratedCode));
    assertTrue(hasImport("com.spectralogic.ds3client.commands.interfaces.AbstractResponse", responseGeneratedCode));
    //Test the Ds3Client
    final String ds3ClientGeneratedCode = testGeneratedCode.getDs3ClientGeneratedCode();
    CODE_LOGGER.logFile(ds3ClientGeneratedCode, FileTypeToLog.CLIENT);
    testDs3Client(requestName, ds3ClientGeneratedCode);
    assertTrue(ds3ClientGeneratedCode.contains("@Action(\"DELETE\")"));
    assertTrue(ds3ClientGeneratedCode.contains("@Resource(\"JOB_CREATED_NOTIFICATION_REGISTRATION\")"));
    assertFalse(ds3ClientGeneratedCode.contains("@ResponsePayloadModel("));
    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.notifications." + responseName, 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.parsers.utils.ResponseParserUtils", responseParserCode));
    final EmptyParseResponse expectedParsing = new EmptyParseResponse(responseName);
    assertTrue(responseParserCode.contains(expectedParsing.toJavaCode()));
    assertTrue(responseParserCode.contains("private final int[] expectedStatusCodes = new int[]{204};"));
}
Also used : TestGeneratedCode(com.spectralogic.ds3autogen.java.utils.TestGeneratedCode) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) Arguments(com.spectralogic.ds3autogen.api.models.Arguments) EmptyParseResponse(com.spectralogic.ds3autogen.java.models.parseresponse.EmptyParseResponse) Test(org.junit.Test)

Example 68 with FileUtils

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

the class JavaFunctionalTests method createGetJobRequestHandler.

@Test
public void createGetJobRequestHandler() throws IOException, TemplateModelException {
    final String requestName = "GetBulkJobSpectraS3Request";
    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/createGetJobRequestHandler.xml");
    final String requestGeneratedCode = testGeneratedCode.getRequestGeneratedCode();
    CODE_LOGGER.logFile(requestGeneratedCode, FileTypeToLog.REQUEST);
    assertTrue(extendsClass(requestName, "BulkRequest", requestGeneratedCode));
    assertTrue(hasMethod("getCommand", "BulkCommand", Scope.PUBLIC, requestGeneratedCode));
    assertTrue(isOptParamOfType("ChunkClientProcessingOrderGuarantee", "JobChunkClientProcessingOrderGuarantee", requestName, requestGeneratedCode, true));
    assertTrue(isOptParamOfType("Priority", "Priority", requestName, requestGeneratedCode, true));
    assertFalse(isReqVariable("BucketName", "String", requestGeneratedCode));
    assertTrue(hasImport("com.spectralogic.ds3client.models.JobChunkClientProcessingOrderGuarantee", requestGeneratedCode));
    assertTrue(hasImport("com.spectralogic.ds3client.BulkCommand", requestGeneratedCode));
    assertTrue(hasImport("com.spectralogic.ds3client.models.bulk.Ds3Object", requestGeneratedCode));
    assertTrue(hasImport("com.spectralogic.ds3client.models.Priority", requestGeneratedCode));
    assertTrue(hasImport("com.spectralogic.ds3client.commands.interfaces.BulkRequest", requestGeneratedCode));
    assertFalse(hasImport("java.util.List", requestGeneratedCode));
    assertFalse(hasImport("com.spectralogic.ds3client.serializer.XmlProcessingException", requestGeneratedCode));
    assertFalse(requestGeneratedCode.contains("XmlProcessingException"));
    assertTrue(isOfPackage("com.spectralogic.ds3client.commands.spectrads3", requestGeneratedCode));
    assertFalse(requestGeneratedCode.contains("RestOperationType"));
    assertTrue(hasOperation(Operation.START_BULK_GET, requestGeneratedCode));
    assertTrue(hasCopyright(requestGeneratedCode));
    final ImmutableList<Arguments> constructorArgs = ImmutableList.of(new Arguments("String", "BucketName"), new Arguments("Iterable<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, "BulkResponse", responseGeneratedCode));
    assertTrue(isOfPackage("com.spectralogic.ds3client.commands.spectrads3", responseGeneratedCode));
    assertTrue(hasImport("com.spectralogic.ds3client.commands.interfaces.BulkResponse", responseGeneratedCode));
    final ImmutableList<Arguments> responseConstructorArg = ImmutableList.of(new Arguments("MasterObjectList", "masterObjectListResult"), new Arguments("String", "checksum"), new Arguments("ChecksumType.Type", "checksumType"));
    assertTrue(hasUnsortedConstructor(responseName, responseConstructorArg, responseGeneratedCode));
    //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);
    checkBulkResponseParserCode(responseName, responseParserCode);
    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)

Example 69 with FileUtils

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

the class JavaFunctionalTests method initiateMultiPartUploadRequest.

@Test
public void initiateMultiPartUploadRequest() throws IOException, TemplateModelException {
    final String requestName = "InitiateMultiPartUploadRequest";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGeneratedCode testGeneratedCode = new TestGeneratedCode(fileUtils, requestName, "./ds3-sdk/src/main/java/com/spectralogic/ds3client/commands/");
    testGeneratedCode.generateCode(fileUtils, "/input/initiateMultiPartUploadRequestHandler.xml");
    final String requestGeneratedCode = testGeneratedCode.getRequestGeneratedCode();
    CODE_LOGGER.logFile(requestGeneratedCode, FileTypeToLog.REQUEST);
    assertTrue(extendsClass(requestName, "AbstractRequest", requestGeneratedCode));
    assertFalse(doesConstructorContainParam("Uploads", "boolean", requestName, requestGeneratedCode));
    assertFalse(isReqVariable("Uploads", "boolean", requestGeneratedCode));
    assertFalse(hasGetter("Uploads", "boolean", requestGeneratedCode));
    assertTrue(hasImport("com.spectralogic.ds3client.networking.HttpVerb", requestGeneratedCode));
    assertFalse(hasImport("com.spectralogic.ds3client.commands.AbstractRequest", requestGeneratedCode));
    assertTrue(isOfPackage("com.spectralogic.ds3client.commands", requestGeneratedCode));
    assertTrue(doesNotHaveOperation(requestGeneratedCode));
    assertTrue(hasCopyright(requestGeneratedCode));
    assertTrue(hasPath("\"/\" + this.bucketName + \"/\" + this.objectName", requestGeneratedCode));
    final ImmutableList<Arguments> constructorArgs = ImmutableList.of(new Arguments("String", "BucketName"), new Arguments("String", "ObjectName"));
    assertTrue(hasConstructor(requestName, constructorArgs, requestGeneratedCode));
    assertTrue(constructorHasVoidQueryParam("uploads", requestGeneratedCode));
    assertFalse(constructorHasVarAssignment("uploads", 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", responseGeneratedCode));
    assertFalse(hasImport("com.spectralogic.ds3client.commands.AbstractResponse", responseGeneratedCode));
    assertTrue(hasImport("com.spectralogic.ds3client.models.InitiateMultipartUploadResult", responseGeneratedCode));
    assertTrue(isReqParamOfType("initiateMultipartUploadResult", "InitiateMultipartUploadResult", 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." + responseName, responseParserCode));
    assertTrue(hasImport("com.spectralogic.ds3client.commands.parsers.interfaces.AbstractResponseParser", responseParserCode));
    assertTrue(hasImport("com.spectralogic.ds3client.models.InitiateMultipartUploadResult", 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, "InitiateMultipartUploadResult");
    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 70 with FileUtils

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

the class JavaFunctionalDocs_Test method getBucketRequest_Test.

@Test
public void getBucketRequest_Test() throws IOException, TemplateModelException {
    final String requestName = "GetBucketRequest";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGeneratedCode codeGenerator = new TestGeneratedCode(fileUtils, requestName, "./ds3-sdk/src/main/java/com/spectralogic/ds3client/commands/");
    final Ds3DocSpec docSpec = new Ds3DocSpecImpl(ImmutableMap.of(requestName, "This is how you use the request"), ImmutableMap.of("Delimiter", "This is how you use delimiter", "Marker", "This is how you use marker", "MaxKeys", "This is how you use max keys", "Prefix", "This is how you use prefix", "BucketName", "This is how you use bucket name"));
    codeGenerator.generateCode(fileUtils, "/input/getBucketRequestHandler.xml", docSpec);
    //Generate Request code
    final String requestCode = codeGenerator.getRequestGeneratedCode();
    CODE_LOGGER.logFile(requestCode, FileTypeToLog.REQUEST);
    assertTrue(requestCode.contains(toConstructorDocs(requestName, ImmutableList.of("Delimiter"), docSpec, 1)));
    assertTrue(requestCode.contains(toConstructorDocs(requestName, ImmutableList.of("Marker"), docSpec, 1)));
    assertTrue(requestCode.contains(toConstructorDocs(requestName, ImmutableList.of("MaxKeys"), docSpec, 1)));
    assertTrue(requestCode.contains(toConstructorDocs(requestName, ImmutableList.of("Prefix"), docSpec, 1)));
    assertTrue(requestCode.contains(toConstructorDocs(requestName, ImmutableList.of("BucketName"), docSpec, 1)));
    //Generate Client code
    final String ds3ClientCode = codeGenerator.getDs3ClientGeneratedCode();
    CODE_LOGGER.logFile(ds3ClientCode, FileTypeToLog.CLIENT);
    final Pattern expectedCommandDoc = Pattern.compile("\\s+/\\*\\*" + "\\s+\\* This is how you use the request" + "\\s+\\*/" + "\\s+GetBucketResponse getBucket\\(final GetBucketRequest request\\)", Pattern.MULTILINE | Pattern.UNIX_LINES);
    assertTrue(expectedCommandDoc.matcher(ds3ClientCode).find());
}
Also used : Pattern(java.util.regex.Pattern) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) Ds3DocSpec(com.spectralogic.ds3autogen.api.models.docspec.Ds3DocSpec) Ds3DocSpecImpl(com.spectralogic.ds3autogen.docspec.Ds3DocSpecImpl) 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