Search in sources :

Example 26 with Ds3Type

use of com.spectralogic.ds3autogen.api.models.apispec.Ds3Type in project ds3_autogen by SpectraLogic.

the class BaseResponseGenerator_Test method testTypeMap.

private static ImmutableMap<String, Ds3Type> testTypeMap() {
    final Ds3Type type1 = typeWithNameToMarshal();
    final Ds3Type type2 = typeWithoutNameToMarshal();
    final Ds3Type type3 = typeEmptyListBucketResult();
    final Ds3Type type4 = typeEmptyJobWithChunks();
    return ImmutableMap.of(type1.getName(), type1, type2.getName(), type2, type3.getName(), type3, type4.getName(), type4);
}
Also used : Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type)

Example 27 with Ds3Type

use of com.spectralogic.ds3autogen.api.models.apispec.Ds3Type in project ds3_autogen by SpectraLogic.

the class Ds3TypeClassificationUtil_Test method isCommonPrefixesType_Test.

@Test
public void isCommonPrefixesType_Test() {
    final ImmutableList<Ds3Element> elements = ImmutableList.of(new Ds3Element("CommonPrefixes", "array", "java.lang.String", true));
    final Ds3Type type = createDs3TypeTestData("TestType", elements);
    assertTrue(isCommonPrefixesType(type));
}
Also used : Ds3ModelPartialDataFixture.createEmptyDs3Type(com.spectralogic.ds3autogen.testutil.Ds3ModelPartialDataFixture.createEmptyDs3Type) Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type) Ds3Element(com.spectralogic.ds3autogen.api.models.apispec.Ds3Element) Test(org.junit.Test)

Example 28 with Ds3Type

use of com.spectralogic.ds3autogen.api.models.apispec.Ds3Type in project ds3_autogen by SpectraLogic.

the class StructHelper_Test method testGenerateStructMembers.

@Test
public void testGenerateStructMembers() throws ParseException {
    final Ds3Element testElement1 = new Ds3Element("boolElement", "boolean", null, false);
    final Ds3Element testElement2 = new Ds3Element("beanElement", "com.spectralogic.s3.server.domain.UserApiBean", null, false);
    final ImmutableList<Ds3Element> elementsList = ImmutableList.of(testElement1, testElement2);
    final Ds3Type ds3Type = new Ds3Type("testDs3Type", elementsList);
    final ImmutableSet.Builder<String> enumNames = ImmutableSet.builder();
    final Struct testStruct = StructConverter.toStruct(ds3Type, enumNames.build(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of());
    final String output = StructMemberHelper.generateStructMembers(testStruct.getStructMembers());
    assertTrue(output.contains("ds3_bool bool_element;"));
    assertTrue(output.contains("ds3_user_api_bean_response* bean_element;"));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type) Ds3Element(com.spectralogic.ds3autogen.api.models.apispec.Ds3Element) Test(org.junit.Test)

Example 29 with Ds3Type

use of com.spectralogic.ds3autogen.api.models.apispec.Ds3Type in project ds3_autogen by SpectraLogic.

the class StructHelper_Test method testGenerateResponseParser.

@Test
public void testGenerateResponseParser() throws ParseException {
    final Ds3Element testElement1 = new Ds3Element("BoolElement", "boolean", null, false);
    final Ds3Element testElement2 = new Ds3Element("BeanElement", "com.spectralogic.s3.server.domain.UserApiBean", null, false);
    final ImmutableList<Ds3Element> elementsList = ImmutableList.of(testElement1, testElement2);
    final Ds3Type ds3Type = new Ds3Type("testDs3Type", elementsList);
    final ImmutableSet.Builder<String> enumNames = ImmutableSet.builder();
    final Struct testStruct = StructConverter.toStruct(ds3Type, enumNames.build(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of());
    final String output = StructHelper.generateResponseParser(testStruct.getName(), testStruct.getStructMembers());
    assertTrue(output.contains("    if (element_equal(child_node, \"BoolElement\")) {"));
    assertTrue(output.contains("        response->bool_element = xml_get_bool(client->log, doc, child_node);"));
    assertTrue(output.contains("    } else if (element_equal(child_node, \"BeanElement\")) {"));
    assertTrue(output.contains("        error = _parse_ds3_user_api_bean_response(client, doc, child_node, &response->bean_element);"));
    assertTrue(output.contains("    } else {"));
    assertTrue(output.contains("        ds3_log_message(client->log, DS3_ERROR, \"Unknown node[%s] of ds3_test_ds3_type_response [%s]\\n\", child_node->name, root->name);"));
    assertTrue(output.contains("    }"));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type) Ds3Element(com.spectralogic.ds3autogen.api.models.apispec.Ds3Element) Test(org.junit.Test)

Example 30 with Ds3Type

use of com.spectralogic.ds3autogen.api.models.apispec.Ds3Type in project ds3_autogen by SpectraLogic.

the class GoCodeGenerator method generateType.

/**
     * Generates the response model represented by the specified {@link Ds3Type}
     */
private void generateType(final Ds3Type ds3Type) throws IOException, TemplateException {
    final Template tmpl = getTypeTemplate(ds3Type);
    final TypeModelGenerator<?> generator = getTypeGenerator(ds3Type);
    final Type type = generator.generate(ds3Type);
    final Path path = destDir.resolve(BASE_PROJECT_PATH.resolve(Paths.get(COMMANDS_NAMESPACE.replace(".", "/") + "/" + uncapitalize(type.getName()) + ".go")));
    LOG.info("Getting OutputStream for file: {}", path.toString());
    try (final OutputStream outputStream = fileUtils.getOutputFile(path);
        final Writer writer = new OutputStreamWriter(outputStream)) {
        tmpl.process(type, writer);
    }
}
Also used : Path(java.nio.file.Path) Type(com.spectralogic.ds3autogen.go.models.type.Type) Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type) OutputStream(java.io.OutputStream) OutputStreamWriter(java.io.OutputStreamWriter) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer)

Aggregations

Ds3Type (com.spectralogic.ds3autogen.api.models.apispec.Ds3Type)44 Test (org.junit.Test)37 Ds3Element (com.spectralogic.ds3autogen.api.models.apispec.Ds3Element)22 Ds3EnumConstant (com.spectralogic.ds3autogen.api.models.apispec.Ds3EnumConstant)9 Enum (com.spectralogic.ds3autogen.c.models.Enum)6 Ds3ApiSpec (com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec)5 Ds3ModelPartialDataFixture.createEmptyDs3Type (com.spectralogic.ds3autogen.testutil.Ds3ModelPartialDataFixture.createEmptyDs3Type)5 ImmutableSet (com.google.common.collect.ImmutableSet)4 Ds3SpecParser (com.spectralogic.ds3autogen.api.Ds3SpecParser)4 Struct (com.spectralogic.ds3autogen.c.models.Struct)4 TestFileUtilsImpl (com.spectralogic.ds3autogen.utils.TestFileUtilsImpl)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 ImmutableList (com.google.common.collect.ImmutableList)3 Ds3SpecParserImpl (com.spectralogic.ds3autogen.Ds3SpecParserImpl)2 NameMapper (com.spectralogic.ds3autogen.NameMapper)2 Ds3DocSpecParser (com.spectralogic.ds3autogen.api.Ds3DocSpecParser)2 Ds3DocSpec (com.spectralogic.ds3autogen.api.models.docspec.Ds3DocSpec)2 SourceConverter (com.spectralogic.ds3autogen.c.converters.SourceConverter)2 StructConverter (com.spectralogic.ds3autogen.c.converters.StructConverter)2 EnumHelper (com.spectralogic.ds3autogen.c.helpers.EnumHelper)2