Search in sources :

Example 26 with TestGenerateCode

use of com.spectralogic.ds3autogen.net.utils.TestGenerateCode in project ds3_autogen by SpectraLogic.

the class NetCodeGenerator_Test method headObjectRequest.

@Test
public void headObjectRequest() throws IOException, TemplateModelException {
    final String requestName = "HeadObjectRequest";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/");
    codeGenerator.generateCode(fileUtils, "/input/headObjectRequest.xml");
    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.hasRequiredParam("BucketName", "string", requestCode));
    assertTrue(TestHelper.hasRequiredParam("ObjectName", "string", requestCode));
    final ImmutableList<Arguments> constructorArgs = ImmutableList.of(new Arguments("String", "BucketName"), new Arguments("String", "ObjectName"));
    assertTrue(TestHelper.hasConstructor(requestName, constructorArgs, requestCode));
    assertTrue(TestHelper.hasConstructor(requestName, modifyType(constructorArgs, "Guid", "string"), requestCode));
    //Generate Responses
    final String responseCode = codeGenerator.getResponseCode();
    CODE_LOGGER.logFile(responseCode, FileTypeToLog.RESPONSE);
    assertTrue(hasContent(responseCode));
    assertTrue(responseCode.contains("public HeadObjectResponse(long length, string eTag, IDictionary<string, string> metadata)"));
    //Generate Parser
    final String parserCode = codeGenerator.getParserCode();
    CODE_LOGGER.logFile(parserCode, FileTypeToLog.PARSER);
    assertTrue(hasContent(parserCode));
    //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));
}
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 27 with TestGenerateCode

use of com.spectralogic.ds3autogen.net.utils.TestGenerateCode in project ds3_autogen by SpectraLogic.

the class NetCodeGenerator_Test method getPhysicalPlacementForObjectsRequestHandler.

@Test
public void getPhysicalPlacementForObjectsRequestHandler() throws IOException, TemplateModelException {
    final String requestName = "GetPhysicalPlacementForObjectsSpectraS3Request";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/", "PhysicalPlacement");
    codeGenerator.generateCode(fileUtils, "/input/getPhysicalPlacementForObjects.xml");
    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.hasRequiredParam("BucketName", "string", requestCode));
    assertTrue(TestHelper.hasRequiredParam("Objects", "IEnumerable<Ds3Object>", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "StorageDomainId", "Guid", requestCode));
    final ImmutableList<Arguments> constructorArgs = ImmutableList.of(new Arguments("string", "BucketName"), new Arguments("IEnumerable<Ds3Object>", "Objects"));
    assertTrue(TestHelper.hasConstructor(requestName, constructorArgs, 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 = "PhysicalPlacement";
    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(hasContent(parserCode));
    assertTrue(parserHasResponseCode(200, parserCode));
    assertTrue(parserHasPayload("PhysicalPlacement", "Data", 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 28 with TestGenerateCode

use of com.spectralogic.ds3autogen.net.utils.TestGenerateCode in project ds3_autogen by SpectraLogic.

the class NetCodeGenerator_Test method getObjectSpectraS3Request_Test.

@Test
public void getObjectSpectraS3Request_Test() throws IOException, TemplateModelException {
    final String requestName = "GetObjectDetailsSpectraS3Request";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/", "S3Object");
    codeGenerator.generateCode(fileUtils, "/input/getObjectRequestSpectraS3.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.hasRequiredParam("ObjectName", "string", requestCode));
    assertTrue(TestHelper.hasRequiredParam("BucketId", "string", requestCode));
    final ImmutableList<Arguments> constructorArgs = ImmutableList.of(new Arguments("String", "ObjectName"), new Arguments("UUID", "BucketId"));
    assertTrue(TestHelper.hasConstructor(requestName, constructorArgs, requestCode));
    assertTrue(TestHelper.hasConstructor(requestName, modifyType(constructorArgs, "Guid", "string"), requestCode));
    assertFalse(requestCode.contains("QueryParams.Add(\"job\", job.ToString());"));
    assertFalse(requestCode.contains("QueryParams.Add(\"offset\", offset.ToString());"));
    //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 = "S3Object";
    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("S3Object", "Data", 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 29 with TestGenerateCode

use of com.spectralogic.ds3autogen.net.utils.TestGenerateCode in project ds3_autogen by SpectraLogic.

the class NetCodeGenerator_Test method ejectStorageDomainBlobsRequestHandler.

@Test
public void ejectStorageDomainBlobsRequestHandler() throws IOException, TemplateModelException {
    final String requestName = "EjectStorageDomainBlobsSpectraS3Request";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/");
    codeGenerator.generateCode(fileUtils, "/input/ejectStorageDomainBlobsRequest.xml");
    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));
    assertFalse(TestHelper.hasRequiredParam("Blobs", "bool", requestCode));
    assertTrue(TestHelper.hasRequiredParam("BucketId", "string", requestCode));
    assertTrue(TestHelper.hasRequiredParam("StorageDomainId", "string", requestCode));
    assertTrue(TestHelper.hasRequiredParam("Objects", "IEnumerable<Ds3Object>", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "EjectLabel", "string", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "EjectLocation", "string", requestCode));
    final ImmutableList<Arguments> constructorArgs = ImmutableList.of(new Arguments("Guid", "BucketId"), new Arguments("Guid", "StorageDomainId"), new Arguments("IEnumerable<Ds3Object>", "Objects"));
    assertTrue(TestHelper.hasConstructor(requestName, constructorArgs, requestCode));
    assertTrue(TestHelper.hasConstructor(requestName, modifyType(constructorArgs, "Guid", "string"), requestCode));
    //Generate Client code
    final String commandName = requestName.replace("Request", "");
    final String clientCode = codeGenerator.getClientCode();
    CODE_LOGGER.logFile(clientCode, FileTypeToLog.CLIENT);
    assertTrue(TestHelper.hasVoidCommand(commandName, clientCode));
    final String idsClientCode = codeGenerator.getIdsClientCode();
    CODE_LOGGER.logFile(idsClientCode, FileTypeToLog.CLIENT);
    assertTrue(TestHelper.hasIDsCommand(commandName, idsClientCode));
    //Generate Responses (should be empty due to no response payload)
    final String responseCode = codeGenerator.getResponseCode();
    assertTrue(isEmpty(responseCode));
    //Generate Parser
    final String parserCode = codeGenerator.getParserCode();
    CODE_LOGGER.logFile(parserCode, FileTypeToLog.PARSER);
    assertTrue(isEmpty(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 30 with TestGenerateCode

use of com.spectralogic.ds3autogen.net.utils.TestGenerateCode in project ds3_autogen by SpectraLogic.

the class NetCodeGenerator_Test method getBucketRequest_Test.

@Test
public void getBucketRequest_Test() throws IOException, TemplateModelException {
    final String requestName = "GetBucketRequest";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/", "ListBucketResult");
    codeGenerator.generateCode(fileUtils, "/input/getBucketRequest.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.hasRequiredParam("BucketName", "string", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "Delimiter", "string", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "MaxKeys", "int", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "Prefix", "string", requestCode));
    final ImmutableList<Arguments> constructorArgs = ImmutableList.of(new Arguments("String", "BucketName"));
    assertTrue(TestHelper.hasConstructor(requestName, constructorArgs, 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 = "ListBucketResult";
    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("ListBucketResult", "ListBucketResult", 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)

Aggregations

FileUtils (com.spectralogic.ds3autogen.api.FileUtils)34 TestGenerateCode (com.spectralogic.ds3autogen.net.utils.TestGenerateCode)34 Test (org.junit.Test)34 Arguments (com.spectralogic.ds3autogen.api.models.Arguments)21 ImmutableList (com.google.common.collect.ImmutableList)1 Ds3DocSpec (com.spectralogic.ds3autogen.api.models.docspec.Ds3DocSpec)1 Ds3DocSpecImpl (com.spectralogic.ds3autogen.docspec.Ds3DocSpecImpl)1