Search in sources :

Example 91 with FileUtils

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

the class JavaFunctionalModels_Test method bucketAclType.

@Test
public void bucketAclType() throws IOException, TemplateModelException {
    final String modelName = "BucketAcl";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGeneratedModelCode testGeneratedModelCode = new TestGeneratedModelCode(fileUtils, modelName, "./ds3-sdk/src/main/java/com/spectralogic/ds3client/models/");
    testGeneratedModelCode.generateCode(fileUtils, "/input/BucketAclType.xml");
    final String modelGeneratedCode = testGeneratedModelCode.getModelGeneratedCode();
    CODE_LOGGER.logFile(modelGeneratedCode, FileTypeToLog.MODEL);
    assertTrue(hasCopyright(modelGeneratedCode));
    assertTrue(isOfPackage("com.spectralogic.ds3client.models", modelGeneratedCode));
    assertTrue(hasModelVariable("BucketId", "UUID", modelGeneratedCode));
    assertTrue(hasModelVariable("GroupId", "UUID", modelGeneratedCode));
    assertTrue(hasModelVariable("Id", "UUID", modelGeneratedCode));
    assertTrue(hasModelVariable("Permission", "BucketAclPermission", modelGeneratedCode));
    assertTrue(hasModelVariable("UserId", "UUID", modelGeneratedCode));
    assertTrue(hasImport("com.fasterxml.jackson.annotation.JsonProperty", modelGeneratedCode));
    assertTrue(hasImport("java.util.UUID", modelGeneratedCode));
    assertFalse(hasImport("com.spectralogic.ds3client.models.BucketAclPermission", modelGeneratedCode));
    assertFalse(hasImport("java.util.List", modelGeneratedCode));
    final ImmutableList<Element> constructorArgs = ImmutableList.of(new Element("BucketId", "UUID", ""), new Element("GroupId", "UUID", ""), new Element("Id", "UUID", ""), new Element("Permission", "BucketAclPermission", ""), new Element("UserId", "UUID", ""));
    assertFalse(hasModelConstructor(modelName, constructorArgs, modelGeneratedCode));
    assertTrue(hasModelConstructor(modelName, ImmutableList.<Element>of(), modelGeneratedCode));
}
Also used : FileUtils(com.spectralogic.ds3autogen.api.FileUtils) TestGeneratedModelCode(com.spectralogic.ds3autogen.java.utils.TestGeneratedModelCode) Element(com.spectralogic.ds3autogen.java.models.Element) Test(org.junit.Test)

Example 92 with FileUtils

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

the class JavaFunctionalModels_Test method checksumType.

@Test
public void checksumType() throws IOException, TemplateModelException {
    final String modelName = "ChecksumType";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGeneratedModelCode testGeneratedModelCode = new TestGeneratedModelCode(fileUtils, modelName, "./ds3-sdk/src/main/java/com/spectralogic/ds3client/models/");
    testGeneratedModelCode.generateCode(fileUtils, "/input/checksumType.xml");
    final String modelGeneratedCode = testGeneratedModelCode.getModelGeneratedCode();
    CODE_LOGGER.logFile(modelGeneratedCode, FileTypeToLog.MODEL);
    assertTrue(hasCopyright(modelGeneratedCode));
    assertTrue(isOfPackage("com.spectralogic.ds3client.models", modelGeneratedCode));
    assertTrue(modelGeneratedCode.contains("public abstract class " + modelName + " {"));
    assertTrue(hasImport("org.apache.commons.codec.binary.Base64", modelGeneratedCode));
    assertTrue(hasImport("org.apache.commons.codec.binary.Base64", modelGeneratedCode));
    assertTrue(TestHelper.enumContainsValue("CRC_32", modelGeneratedCode));
    assertTrue(TestHelper.enumContainsValue("CRC_32C", modelGeneratedCode));
    assertTrue(TestHelper.enumContainsValue("MD5", modelGeneratedCode));
    assertTrue(TestHelper.enumContainsValue("SHA_256", modelGeneratedCode));
    assertTrue(TestHelper.enumContainsValue("SHA_512", modelGeneratedCode));
    assertTrue(TestHelper.enumContainsValue("NONE", modelGeneratedCode));
}
Also used : FileUtils(com.spectralogic.ds3autogen.api.FileUtils) TestGeneratedModelCode(com.spectralogic.ds3autogen.java.utils.TestGeneratedModelCode) Test(org.junit.Test)

Example 93 with FileUtils

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

the class Python3FunctionalTests method simpleRequest.

@Test
public void simpleRequest() throws IOException, TemplateModelException {
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestPython3GeneratedCode codeGenerator = new TestPython3GeneratedCode(fileUtils);
    codeGenerator.generateCode(fileUtils, "/input/requests/simpleRequest.xml");
    final String ds3Code = codeGenerator.getDs3Code();
    assertThat(ds3Code, is(notNullValue()));
    CODE_LOGGER.logFile(ds3Code, FileTypeToLog.REQUEST);
    //test template imports from python 2 module
    assertTrue(ds3Code.contains("def createClientFromEnv():"));
    //test imports
    assertTrue(ds3Code.contains("from .ds3network import *"));
    assertFalse(ds3Code.contains("from ds3network import *"));
    //test abstract request
    assertTrue(ds3Code.contains("class AbstractRequest(object, metaclass=ABCMeta):"));
    assertFalse(ds3Code.contains("class AbstractRequest(object):"));
    //test abstract response
    assertTrue(ds3Code.contains("class AbstractResponse(object, metaclass=ABCMeta):"));
    assertFalse(ds3Code.contains("class AbstractResponse(object):"));
    assertTrue(ds3Code.contains("if header[0].lower() == key.lower():"));
    assertFalse(ds3Code.contains("if header[0] == key:"));
}
Also used : FileUtils(com.spectralogic.ds3autogen.api.FileUtils) TestPython3GeneratedCode(com.spectralogic.ds3autogen.python3.utils.TestPython3GeneratedCode) Test(org.junit.Test)

Example 94 with FileUtils

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

the class Python3FunctionalTests method putObjectRequestTest.

@Test
public void putObjectRequestTest() throws IOException, TemplateModelException {
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestPython3GeneratedCode codeGenerator = new TestPython3GeneratedCode(fileUtils);
    codeGenerator.generateCode(fileUtils, "/input/requests/putObject.xml");
    final String ds3Code = codeGenerator.getDs3Code();
    assertThat(ds3Code, is(notNullValue()));
    CODE_LOGGER.logFile(ds3Code, FileTypeToLog.REQUEST);
    assertTrue(ds3Code.contains("for key, val in headers.items():"));
    assertFalse(ds3Code.contains("for key, val in headers.iteritems():"));
}
Also used : FileUtils(com.spectralogic.ds3autogen.api.FileUtils) TestPython3GeneratedCode(com.spectralogic.ds3autogen.python3.utils.TestPython3GeneratedCode) Test(org.junit.Test)

Example 95 with FileUtils

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

the class Main method run.

public void run() throws Exception {
    final Ds3SpecParser parser = new Ds3SpecParserImpl();
    System.out.println("Generating " + args.getType().toString() + " ds3 sdk code for the spec " + args.getInputSpec());
    //TODO make the input file also accept a url that we can read from
    final Ds3ApiSpec spec = parser.getSpec(Files.newInputStream(Paths.get(args.getInputSpec())), args.generateInternal());
    final CodeGenerator generator;
    switch(args.getType()) {
        case C:
            generator = new CCodeGenerator();
            break;
        case JAVA:
            generator = new JavaCodeGenerator();
            break;
        case NET:
            generator = new NetCodeGenerator();
            break;
        case PYTHON:
            generator = new PythonCodeGenerator();
            break;
        case PYTHON3:
            generator = new Python3CodeGenerator();
            break;
        case GO:
            generator = new GoCodeGenerator();
            break;
        default:
            throw new IllegalArgumentException("Unknown generator typeName " + args.getType().toString());
    }
    final FileUtils fileUtils = new FileUtilsImpl();
    final Ds3DocSpec docSpec;
    if (args.isNoDoc()) {
        docSpec = new Ds3DocSpecEmptyImpl();
    } else {
        final Ds3DocSpecParser docSpecParser = new Ds3DocSpecParserImpl(new NameMapper());
        docSpec = docSpecParser.getDocSpec();
    }
    generator.generate(spec, fileUtils, Paths.get(args.getTargetDir()), docSpec);
}
Also used : PythonCodeGenerator(com.spectralogic.ds3autogen.python.PythonCodeGenerator) FileUtilsImpl(com.spectralogic.ds3autogen.utils.FileUtilsImpl) Ds3SpecParser(com.spectralogic.ds3autogen.api.Ds3SpecParser) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) NetCodeGenerator(com.spectralogic.ds3autogen.net.NetCodeGenerator) Ds3DocSpecParserImpl(com.spectralogic.ds3autogen.docspec.Ds3DocSpecParserImpl) Ds3DocSpec(com.spectralogic.ds3autogen.api.models.docspec.Ds3DocSpec) Ds3SpecParserImpl(com.spectralogic.ds3autogen.Ds3SpecParserImpl) JavaCodeGenerator(com.spectralogic.ds3autogen.java.JavaCodeGenerator) Python3CodeGenerator(com.spectralogic.ds3autogen.python3.Python3CodeGenerator) PythonCodeGenerator(com.spectralogic.ds3autogen.python.PythonCodeGenerator) CodeGenerator(com.spectralogic.ds3autogen.api.CodeGenerator) NetCodeGenerator(com.spectralogic.ds3autogen.net.NetCodeGenerator) CCodeGenerator(com.spectralogic.ds3autogen.c.CCodeGenerator) GoCodeGenerator(com.spectralogic.ds3autogen.go.GoCodeGenerator) GoCodeGenerator(com.spectralogic.ds3autogen.go.GoCodeGenerator) Ds3ApiSpec(com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec) Python3CodeGenerator(com.spectralogic.ds3autogen.python3.Python3CodeGenerator) NameMapper(com.spectralogic.ds3autogen.NameMapper) Ds3DocSpecEmptyImpl(com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl) CCodeGenerator(com.spectralogic.ds3autogen.c.CCodeGenerator) Ds3DocSpecParser(com.spectralogic.ds3autogen.api.Ds3DocSpecParser) JavaCodeGenerator(com.spectralogic.ds3autogen.java.JavaCodeGenerator)

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