use of com.spectralogic.ds3autogen.net.utils.TestGenerateCode in project ds3_autogen by SpectraLogic.
the class NetCodeGenerator_ModelParsers_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, "PlaceHolderRequest", "./Ds3/Calls/", typeName);
codeGenerator.withIgnorableFiles(fileUtils, ImmutableList.of("./Ds3/Models/BulkObject.cs"));
codeGenerator.generateCode(fileUtils, "/input/types/jobChunkApiBean.xml");
final String typeParserCode = codeGenerator.getTypeParser();
CODE_LOGGER.logFile(typeParserCode, FileTypeToLog.MODEL_PARSERS);
assertTrue(typeParserCode.contains("public static Objects ParseObjects(XElement element)"));
assertTrue(typeParserCode.contains("public static Objects ParseNullableObjects(XElement element)"));
assertTrue(typeParserCode.contains("ChunkId = ParseGuid(element.AttributeText(\"ChunkId\"))"));
assertTrue(typeParserCode.contains("ChunkNumber = ParseInt(element.AttributeText(\"ChunkNumber\"))"));
assertTrue(typeParserCode.contains("NodeId = ParseNullableGuid(element.AttributeTextOrNull(\"NodeId\"))"));
assertTrue(typeParserCode.contains("ObjectsList = element.Elements(\"Object\").Select(ParseBulkObject).ToList()"));
}
use of com.spectralogic.ds3autogen.net.utils.TestGenerateCode in project ds3_autogen by SpectraLogic.
the class NetCodeGenerator_ModelParsers_Test method checksumType_Test.
@Test
public void checksumType_Test() throws IOException, TemplateModelException {
final String enumName = "ChecksumType";
final FileUtils fileUtils = mock(FileUtils.class);
final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, "PlaceHolderRequest", "./Ds3/Calls/", enumName);
codeGenerator.generateCode(fileUtils, "/input/modelparsing/modelParsingEnumType.xml");
final String typeParserCode = codeGenerator.getTypeParser();
CODE_LOGGER.logFile(typeParserCode, FileTypeToLog.MODEL_PARSERS);
assertFalse(typeParserCode.contains("AlgorithmName"));
assertFalse(typeParserCode.contains("HttpHeaderName"));
assertFalse(parseNullableEnumString(enumName, typeParserCode));
assertFalse(parseEnumString(enumName, typeParserCode));
assertFalse(parseNullableEnumElement(enumName, typeParserCode));
assertFalse(parseEnumElement(enumName, typeParserCode));
}
use of com.spectralogic.ds3autogen.net.utils.TestGenerateCode in project ds3_autogen by SpectraLogic.
the class NetCodeGenerator_ModelParsers_Test method getTapesWithFullDetails_Test.
@Test
public void getTapesWithFullDetails_Test() throws TemplateModelException, IOException {
final String typeName = "NamedDetailedTapeList";
final FileUtils fileUtils = mock(FileUtils.class);
final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, "GetTapesWithFullDetailsSpectraS3Request", "./Ds3/Calls/", typeName);
codeGenerator.generateCode(fileUtils, "/input/getTapesWithFullDetails.xml");
final String typeParserCode = codeGenerator.getTypeParser();
CODE_LOGGER.logFile(typeParserCode, FileTypeToLog.MODEL_PARSERS);
assertTrue(typeParserCode.contains("public static NamedDetailedTapeList ParseNamedDetailedTapeList(XElement element)"));
assertTrue(typeParserCode.contains("public static NamedDetailedTapeList ParseNullableNamedDetailedTapeList(XElement element)"));
assertTrue(typeParserCode.contains("NamedDetailedTapes = element.Elements(\"Tape\").Select(ParseNamedDetailedTape).ToList()"));
}
use of com.spectralogic.ds3autogen.net.utils.TestGenerateCode in project ds3_autogen by SpectraLogic.
the class NetCodeGenerator_Test method getObjectRequest_Test.
@Test
public void getObjectRequest_Test() 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/getObjectRequest.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("ObjectName", "string", requestCode));
assertTrue(TestHelper.hasRequiredParam("Job", "string", requestCode));
assertTrue(TestHelper.hasRequiredParam("Offset", "long", requestCode));
final ImmutableList<Arguments> constructorArgs = ImmutableList.of(new Arguments("String", "BucketName"), new Arguments("String", "ObjectName"), new Arguments("Stream", "DestinationStream"), new Arguments("UUID", "Job"), new Arguments("long", "Offset"));
assertTrue(TestHelper.hasConstructor(requestName, constructorArgs, requestCode));
assertTrue(TestHelper.hasConstructor(requestName, modifyType(constructorArgs, "Guid", "string"), requestCode));
assertTrue(requestCode.contains("QueryParams.Add(\"job\", job.ToString());"));
assertTrue(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(clientCode.contains("public GetObjectResponse GetObject(GetObjectRequest request)"));
assertTrue(clientCode.contains("return new GetObjectResponseParser(_netLayer.CopyBufferSize).Parse(request, _netLayer.Invoke(request));"));
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));
assertTrue(responseCode.contains("public GetObjectResponse(IDictionary<string, string> metadata)"));
//Generate Parser
final String parserCode = codeGenerator.getParserCode();
CODE_LOGGER.logFile(parserCode, FileTypeToLog.PARSER);
assertTrue(hasContent(parserCode));
}
use of com.spectralogic.ds3autogen.net.utils.TestGenerateCode in project ds3_autogen by SpectraLogic.
the class NetCodeGenerator_Test method verifyPhysicalPlacementForObjectsRequestHandler.
@Test
public void verifyPhysicalPlacementForObjectsRequestHandler() throws IOException, TemplateModelException {
final String requestName = "VerifyPhysicalPlacementForObjectsSpectraS3Request";
final FileUtils fileUtils = mock(FileUtils.class);
final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/", "PhysicalPlacement");
codeGenerator.generateCode(fileUtils, "/input/verifyPhysicalPlacementForObjects.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));
}
Aggregations