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));
}
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));
}
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:"));
}
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():"));
}
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);
}
Aggregations