use of com.spectralogic.ds3autogen.api.FileUtils in project ds3_autogen by SpectraLogic.
the class NetCodeGenerator_Test method CreatePutJobRequest_Test.
@Test
public void CreatePutJobRequest_Test() throws IOException, TemplateModelException {
final String requestName = "PutBulkJobSpectraS3Request";
final FileUtils fileUtils = mock(FileUtils.class);
final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/", "MasterObjectList");
codeGenerator.generateCode(fileUtils, "/input/createPutJobRequest.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("Objects", "IEnumerable<Ds3Object>", requestCode));
assertTrue(TestHelper.hasRequiredParam("MaxUploadSize", "long?", requestCode));
final ImmutableList<Arguments> constructorArgs = ImmutableList.of(new Arguments("String", "BucketName"), new Arguments("IEnumerable<Ds3Object>", "Objects"));
assertTrue(TestHelper.hasConstructor(requestName, constructorArgs, requestCode));
assertTrue(requestCode.contains("this.QueryParams.Add(\"operation\", \"start_bulk_put\");"));
//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.api.FileUtils in project ds3_autogen by SpectraLogic.
the class NetCodeGenerator_Test method ReplicatePutJobRequest.
@Test
public void ReplicatePutJobRequest() throws IOException, TemplateModelException {
final String requestName = "ReplicatePutJobSpectraS3Request";
final FileUtils fileUtils = mock(FileUtils.class);
final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/", "MasterObjectList");
codeGenerator.generateCode(fileUtils, "/input/replicatePutJobRequest.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("RequestPayload", "string", requestCode));
assertTrue(TestHelper.hasOptionalParam(requestName, "ConflictResolutionMode", "ReplicationConflictResolutionMode", requestCode));
assertTrue(TestHelper.hasOptionalParam(requestName, "Priority", "Priority", requestCode));
final ImmutableList<Arguments> constructorArgs = ImmutableList.of(new Arguments("string", "BucketName"), new Arguments("string", "RequestPayload"));
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 = "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(hasContent(parserCode));
assertTrue(parserCode.contains("ResponseParseUtilities.HandleStatusCode(response, (HttpStatusCode)200, HttpStatusCode.ServiceUnavailable)"));
assertTrue(parserHasPayload("MasterObjectList", "MasterObjectList", parserCode));
}
use of com.spectralogic.ds3autogen.api.FileUtils in project ds3_autogen by SpectraLogic.
the class NetCodeGenerator_Test method getTapesWithFullDetails_Test.
@Test
public void getTapesWithFullDetails_Test() throws TemplateModelException, IOException {
final String requestName = "GetTapesWithFullDetailsSpectraS3Request";
final FileUtils fileUtils = mock(FileUtils.class);
final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/", "NamedDetailedTapeList");
codeGenerator.generateCode(fileUtils, "/input/getTapesWithFullDetails.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.hasOptionalParam(requestName, "AssignedToStorageDomain", "bool", requestCode));
assertTrue(TestHelper.hasOptionalParam(requestName, "BarCode", "string", requestCode));
assertTrue(TestHelper.hasOptionalParam(requestName, "BucketId", "Guid", requestCode));
assertTrue(TestHelper.hasOptionalParam(requestName, "EjectLabel", "string", requestCode));
assertTrue(TestHelper.hasOptionalParam(requestName, "EjectLocation", "string", requestCode));
assertTrue(TestHelper.hasOptionalParam(requestName, "FullOfData", "bool", requestCode));
assertTrue(TestHelper.hasOptionalParam(requestName, "LastPage", "bool", requestCode));
assertTrue(TestHelper.hasOptionalParam(requestName, "PageLength", "int", requestCode));
assertTrue(TestHelper.hasOptionalParam(requestName, "PageOffset", "int", requestCode));
assertTrue(TestHelper.hasOptionalParam(requestName, "PageStartMarker", "Guid", requestCode));
assertTrue(TestHelper.hasOptionalParam(requestName, "PartitionId", "Guid", requestCode));
assertTrue(TestHelper.hasOptionalParam(requestName, "PreviousState", "TapeState", requestCode));
assertTrue(TestHelper.hasOptionalParam(requestName, "SerialNumber", "string", requestCode));
assertTrue(TestHelper.hasOptionalParam(requestName, "State", "TapeState", requestCode));
assertTrue(TestHelper.hasOptionalParam(requestName, "StorageDomainId", "Guid", requestCode));
assertTrue(TestHelper.hasOptionalParam(requestName, "Type", "TapeType", requestCode));
assertTrue(TestHelper.hasOptionalParam(requestName, "WriteProtected", "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 responsePayloadType = "NamedDetailedTapeList";
assertTrue(responseCode.contains("public GetTapesWithFullDetailsSpectraS3Response(NamedDetailedTapeList responsePayload, int? pagingTruncated, int? pagingTotalResultCount)"));
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("NamedDetailedTapeList", "Data", parserCode));
}
use of com.spectralogic.ds3autogen.api.FileUtils in project ds3_autogen by SpectraLogic.
the class NetCodeGenerator_Test method headBucketRequest_Test.
@Test
public void headBucketRequest_Test() throws IOException, TemplateModelException {
final String requestName = "HeadBucketRequest";
final FileUtils fileUtils = mock(FileUtils.class);
final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/");
codeGenerator.generateCode(fileUtils, "/input/headBucketRequest.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));
final ImmutableList<Arguments> constructorArgs = ImmutableList.of(new Arguments("String", "BucketName"));
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.hasPayloadCommand(commandName, clientCode));
assertFalse(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();
CODE_LOGGER.logFile(responseCode, FileTypeToLog.RESPONSE);
assertTrue(hasContent(responseCode));
final String responseName = NormalizingContractNamesUtil.toResponseName(requestName);
final String responsePayloadType = "StatusType";
assertTrue(TestHelper.hasConstructor(responseName, ImmutableList.of(new Arguments(responsePayloadType, "status")), responseCode));
assertTrue(TestHelper.hasRequiredParam("Status", responsePayloadType, responseCode));
assertTrue(responseCode.contains("public enum " + responsePayloadType));
//Generate Parser
final String parserCode = codeGenerator.getParserCode();
CODE_LOGGER.logFile(parserCode, FileTypeToLog.PARSER);
assertTrue(hasContent(parserCode));
assertTrue(parserCode.contains("ResponseParseUtilities.HandleStatusCode(response, HttpStatusCode.OK, HttpStatusCode.Forbidden, HttpStatusCode.NotFound)"));
}
use of com.spectralogic.ds3autogen.api.FileUtils in project ds3_autogen by SpectraLogic.
the class NetCodeGenerator_Test method createMultiPartUploadPartRequest.
@Test
public void createMultiPartUploadPartRequest() throws IOException, TemplateModelException {
final String requestName = "PutMultiPartUploadPartRequest";
final FileUtils fileUtils = mock(FileUtils.class);
final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/");
codeGenerator.generateCode(fileUtils, "/input/createMultiPartUploadPartRequest.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));
assertTrue(requestCode.contains("private readonly Stream RequestPayload;"));
assertTrue(requestCode.contains("internal override Stream GetContentStream()"));
assertFalse(hasOptionalChecksum(requestName, requestCode));
assertFalse(hasOptionalMetadata(requestName, requestCode));
final ImmutableList<Arguments> constructorArgs = ImmutableList.of(new Arguments("String", "BucketName"), new Arguments("String", "ObjectName"), new Arguments("Stream", "RequestPayload"), new Arguments("Guid", "UploadId"), new Arguments("int", "PartNumber"));
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.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));
}
Aggregations