Search in sources :

Example 51 with FileUtils

use of com.spectralogic.ds3autogen.api.FileUtils 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()"));
}
Also used : TestGenerateCode(com.spectralogic.ds3autogen.net.utils.TestGenerateCode) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) Test(org.junit.Test)

Example 52 with FileUtils

use of com.spectralogic.ds3autogen.api.FileUtils 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));
}
Also used : TestGenerateCode(com.spectralogic.ds3autogen.net.utils.TestGenerateCode) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) Test(org.junit.Test)

Example 53 with FileUtils

use of com.spectralogic.ds3autogen.api.FileUtils 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()"));
}
Also used : TestGenerateCode(com.spectralogic.ds3autogen.net.utils.TestGenerateCode) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) Test(org.junit.Test)

Example 54 with FileUtils

use of com.spectralogic.ds3autogen.api.FileUtils 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));
}
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 55 with FileUtils

use of com.spectralogic.ds3autogen.api.FileUtils 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));
}
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)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