Search in sources :

Example 16 with FileUtils

use of com.spectralogic.ds3autogen.api.FileUtils in project ds3_autogen by SpectraLogic.

the class NetCodeGenerator_Types_Test method testElementsType.

@Test
public void testElementsType() throws IOException, TemplateModelException {
    final String typeName = "TestElementsType";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, PLACEHOLDER_REQUEST_NAME, "./Ds3/Calls/", typeName);
    final ImmutableList<String> ignorableFiles = ImmutableList.of("./Ds3/Models/ChecksumType.cs");
    codeGenerator.withIgnorableFiles(fileUtils, ignorableFiles);
    codeGenerator.generateCode(fileUtils, "/input/types/testElementsType.xml");
    final String typeCode = codeGenerator.getTypeCode();
    LOG.info("Generated code:\n" + typeCode);
    assertTrue(typeCode.contains("public class " + typeName));
    assertTrue(typeCode.contains("public IEnumerable<Pool> Pools { get; set; }"));
    assertTrue(typeCode.contains("public long ByteOffset { get; set; }"));
    assertTrue(typeCode.contains("public string Checksum { get; set; }"));
    assertTrue(typeCode.contains("public ChecksumType.Type? ChecksumType { get; set; }"));
    assertTrue(typeCode.contains("public Guid Id { get; set; }"));
    assertTrue(typeCode.contains("public long Length { get; set; }"));
    assertTrue(typeCode.contains("public Guid ObjectId { get; set; }"));
}
Also used : TestGenerateCode(com.spectralogic.ds3autogen.net.utils.TestGenerateCode) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) Test(org.junit.Test)

Example 17 with FileUtils

use of com.spectralogic.ds3autogen.api.FileUtils in project ds3_autogen by SpectraLogic.

the class NetCodeGenerator_Types_Test method bucket_Test.

@Test
public void bucket_Test() throws TemplateModelException, IOException {
    final String typeName = "Bucket";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, PLACEHOLDER_REQUEST_NAME, "./Ds3/Calls/", typeName);
    codeGenerator.generateCode(fileUtils, "/input/types/bucket.xml");
    final String typeCode = codeGenerator.getTypeCode();
    LOG.info("Generated code:\n" + typeCode);
    assertTrue(typeCode.contains("public DateTime CreationDate { get; set; }"));
    assertTrue(typeCode.contains("public Guid DataPolicyId { get; set; }"));
    assertTrue(typeCode.contains("public Guid Id { get; set; }"));
    assertTrue(typeCode.contains("public long? LastPreferredChunkSizeInBytes { get; set; }"));
    assertTrue(typeCode.contains("public long? LogicalUsedCapacity { get; set; }"));
    assertTrue(typeCode.contains("public string Name { get; set; }"));
    assertTrue(typeCode.contains("public Guid UserId { get; set; }"));
}
Also used : TestGenerateCode(com.spectralogic.ds3autogen.net.utils.TestGenerateCode) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) Test(org.junit.Test)

Example 18 with FileUtils

use of com.spectralogic.ds3autogen.api.FileUtils in project ds3_autogen by SpectraLogic.

the class NetCodeGenerator_Types_Test method databasePhysicalSpaceState.

@Test
public void databasePhysicalSpaceState() throws IOException, TemplateModelException {
    final String typeName = "DatabasePhysicalSpaceState";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, PLACEHOLDER_REQUEST_NAME, "./Ds3/Calls/", typeName);
    codeGenerator.generateCode(fileUtils, "/input/types/databasePhysicalSpaceState.xml");
    final String typeCode = codeGenerator.getTypeCode();
    LOG.info("Generated code:\n" + typeCode);
    assertTrue(typeCode.contains("public enum " + typeName));
    assertTrue(typeCode.contains("CRITICAL,"));
    assertTrue(typeCode.contains("LOW,"));
    assertTrue(typeCode.contains("NEAR_LOW,"));
    assertTrue(typeCode.contains("NORMAL"));
}
Also used : TestGenerateCode(com.spectralogic.ds3autogen.net.utils.TestGenerateCode) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) Test(org.junit.Test)

Example 19 with FileUtils

use of com.spectralogic.ds3autogen.api.FileUtils in project ds3_autogen by SpectraLogic.

the class NetCodeGenerator_Types_Test method checksumType.

@Test
public void checksumType() throws IOException, TemplateModelException {
    final String typeName = "ChecksumType";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, PLACEHOLDER_REQUEST_NAME, "./Ds3/Calls/", typeName);
    codeGenerator.generateCode(fileUtils, "/input/types/checksumType.xml");
    final String typeCode = codeGenerator.getTypeCode();
    LOG.info("Generated code:\n" + typeCode);
    assertTrue(typeCode.contains("public abstract class " + typeName));
    assertTrue(typeCode.contains("CRC_32,"));
    assertTrue(typeCode.contains("CRC_32C,"));
    assertTrue(typeCode.contains("MD5,"));
    assertTrue(typeCode.contains("SHA_256,"));
    assertTrue(typeCode.contains("SHA_512,"));
    assertTrue(typeCode.contains("NONE"));
}
Also used : TestGenerateCode(com.spectralogic.ds3autogen.net.utils.TestGenerateCode) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) Test(org.junit.Test)

Example 20 with FileUtils

use of com.spectralogic.ds3autogen.api.FileUtils in project ds3_autogen by SpectraLogic.

the class NetCodeGenerator_Test method createObjectRequest.

@Test
public void createObjectRequest() throws IOException, TemplateModelException {
    final String requestName = "PutObjectRequest";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/");
    codeGenerator.generateCode(fileUtils, "/input/createObjectRequest.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(TestHelper.hasOptionalParam(requestName, "Job", "Guid", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "Offset", "long", requestCode));
    assertTrue(requestCode.contains("private readonly Stream RequestPayload;"));
    assertTrue(requestCode.contains("internal override Stream GetContentStream()"));
    assertTrue(hasOptionalChecksum(requestName, requestCode));
    assertTrue(hasOptionalMetadata(requestName, requestCode));
    final ImmutableList.Builder<Arguments> constructorArgs = ImmutableList.builder();
    constructorArgs.add(new Arguments("String", "BucketName"));
    constructorArgs.add(new Arguments("String", "ObjectName"));
    constructorArgs.add(new Arguments("Stream", "RequestPayload"));
    assertTrue(TestHelper.hasConstructor(requestName, constructorArgs.build(), requestCode));
    constructorArgs.add(new Arguments("long", "Length"));
    assertTrue(TestHelper.hasConstructor(requestName, constructorArgs.build(), 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) ImmutableList(com.google.common.collect.ImmutableList) 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