use of com.spectralogic.ds3autogen.net.utils.TestGenerateCode in project ds3_autogen by SpectraLogic.
the class NetCodeGenerator_Test method verifyPhysicalPlacementForObjectsWithFullDetailsRequestHandler.
@Test
public void verifyPhysicalPlacementForObjectsWithFullDetailsRequestHandler() throws IOException, TemplateModelException {
final String requestName = "VerifyPhysicalPlacementForObjectsWithFullDetailsSpectraS3Request";
final FileUtils fileUtils = mock(FileUtils.class);
final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/", "BulkObjectList");
codeGenerator.generateCode(fileUtils, "/input/verifyPhysicalPlacementForObjectsFullDetails.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));
assertFalse(TestHelper.hasRequiredParam("FullDetails", "bool", 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 = "BulkObjectList";
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("BulkObjectList", "Data", parserCode));
}
use of com.spectralogic.ds3autogen.net.utils.TestGenerateCode in project ds3_autogen by SpectraLogic.
the class NetCodeGenerator_Test method DeleteObjectsRequestHandler.
@Test
public void DeleteObjectsRequestHandler() throws IOException, TemplateModelException {
final String requestName = "DeleteObjectsRequest";
final FileUtils fileUtils = mock(FileUtils.class);
final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/", "DeleteResult");
codeGenerator.generateCode(fileUtils, "/input/deleteObjectsRequest.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, "RollBack", "bool", 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 = "DeleteResult";
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("DeleteResult", "DeleteResult", parserCode));
}
use of com.spectralogic.ds3autogen.net.utils.TestGenerateCode in project ds3_autogen by SpectraLogic.
the class NetCodeGenerator_Test method createGetJobRequest_Test.
@Test
public void createGetJobRequest_Test() throws IOException, TemplateModelException {
final String requestName = "GetBulkJobSpectraS3Request";
final FileUtils fileUtils = mock(FileUtils.class);
final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/", "MasterObjectList");
codeGenerator.generateCode(fileUtils, "/input/createGetJobRequest.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.hasRequiredParam("FullObjects", "IEnumerable<string>", requestCode));
assertTrue(TestHelper.hasRequiredParam("PartialObjects", "IEnumerable<Ds3PartialObject>", requestCode));
assertTrue(TestHelper.hasOptionalParam(requestName, "ChunkClientProcessingOrderGuarantee?", "JobChunkClientProcessingOrderGuarantee?", requestCode));
assertTrue(TestHelper.hasOptionalParam(requestName, "Aggregating", "bool?", requestCode));
assertTrue(TestHelper.hasOptionalParam(requestName, "Name", "string", requestCode));
assertTrue(TestHelper.hasOptionalParam(requestName, "Priority", "Priority?", requestCode));
final ImmutableList<Arguments> constructorArgs = ImmutableList.of(new Arguments("String", "BucketName"), new Arguments("IEnumerable<string>", "FullObjects"), new Arguments("IEnumerable<Ds3PartialObject>", "PartialObjects"));
assertTrue(TestHelper.hasConstructor(requestName, constructorArgs, requestCode));
final ImmutableList<Arguments> secondConstructorArgs = ImmutableList.of(new Arguments("String", "BucketName"), new Arguments("List<Ds3Object>", "Objects"));
assertTrue(TestHelper.hasConstructor(requestName, secondConstructorArgs, requestCode));
assertTrue(requestCode.contains("this.QueryParams.Add(\"operation\", \"start_bulk_get\");"));
assertTrue(requestCode.contains("internal override Stream GetContentStream()"));
assertTrue(requestCode.contains("private static string BuildChunkOrderingEnumString(JobChunkClientProcessingOrderGuarantee chunkClientProcessingOrderGuarantee)"));
//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 = "MasterObjectList";
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(parserCode.contains("ResponseParseUtilities.HandleStatusCode(response, (HttpStatusCode)200, HttpStatusCode.ServiceUnavailable)"));
assertTrue(parserHasPayload("MasterObjectList", "MasterObjectList", parserCode));
}
use of com.spectralogic.ds3autogen.net.utils.TestGenerateCode in project ds3_autogen by SpectraLogic.
the class NetCodeGenerator_Types_Test method jobChunkApiBean_Test.
@Test
public void jobChunkApiBean_Test() throws TemplateModelException, IOException {
final String typeName = "Objects";
final FileUtils fileUtils = mock(FileUtils.class);
final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, PLACEHOLDER_REQUEST_NAME, "./Ds3/Calls/", typeName);
codeGenerator.withIgnorableFiles(fileUtils, ImmutableList.of("./Ds3/Models/BulkObject.cs"));
codeGenerator.generateCode(fileUtils, "/input/types/jobChunkApiBean.xml");
final String typeCode = codeGenerator.getTypeCode();
LOG.info("Generated code:\n" + typeCode);
assertTrue(typeCode.contains("public Guid ChunkId { get; set; }"));
assertTrue(typeCode.contains("public int ChunkNumber { get; set; }"));
assertTrue(typeCode.contains("public Guid? NodeId { get; set; }"));
assertTrue(typeCode.contains("public IEnumerable<BulkObject> ObjectsList { get; set; }"));
}
Aggregations