Search in sources :

Example 46 with Ds3Element

use of com.spectralogic.ds3autogen.api.models.apispec.Ds3Element 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 47 with Ds3Element

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

the class StructConverter_Test method testConvertNameToMarshallEmpty.

@Test
public void testConvertNameToMarshallEmpty() 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 Struct testStruct = StructConverter.toStruct(ds3Type, ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of());
    assertThat(testStruct.getNameToMarshall(), is("Data"));
}
Also used : Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type) Ds3Element(com.spectralogic.ds3autogen.api.models.apispec.Ds3Element) Struct(com.spectralogic.ds3autogen.c.models.Struct) Test(org.junit.Test)

Example 48 with Ds3Element

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

the class StructConverter_Test method testConvertNameToMarshallSetValid.

@Test
public void testConvertNameToMarshallSetValid() 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", "testDs3TypeMarshallName", elementsList, ImmutableList.of());
    final Struct testStruct = StructConverter.toStruct(ds3Type, ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of());
    assertThat(testStruct.getNameToMarshall(), is("testDs3TypeMarshallName"));
}
Also used : Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type) Ds3Element(com.spectralogic.ds3autogen.api.models.apispec.Ds3Element) Struct(com.spectralogic.ds3autogen.c.models.Struct) Test(org.junit.Test)

Example 49 with Ds3Element

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

the class CCodeGenerator_Test method testEmbeddedTypesSet.

@Test
public void testEmbeddedTypesSet() {
    final Ds3Type type1 = new Ds3Type("Ds3Bucket", ImmutableList.of(new Ds3Element("ChecksumType", "Ds3ChecksumType", null, true), new Ds3Element("Size", "Ds3Size", null, true)));
    final Ds3Type type2 = new Ds3Type("Ds3Object", ImmutableList.of(new Ds3Element("Name", "java.lang.String", null, true), new Ds3Element("Size", "Ds3Size", null, true)));
    final Ds3ApiSpec embeddedTypesSet = new Ds3ApiSpec(ImmutableList.of(), ImmutableMap.of(type1.getName(), type1, type2.getName(), type2));
    final ImmutableSet<String> embeddedTypes = CCodeGenerator.getEmbeddedTypes(embeddedTypesSet, ImmutableSet.of());
    assertEquals(embeddedTypes.size(), 2);
    assertTrue(embeddedTypes.contains("ds3_size_response"));
}
Also used : Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type) Ds3Element(com.spectralogic.ds3autogen.api.models.apispec.Ds3Element) Ds3ApiSpec(com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec) Test(org.junit.Test)

Example 50 with Ds3Element

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

the class CCodeGenerator_Test method testGenerateComplexTypedefStruct.

@Test
public void testGenerateComplexTypedefStruct() throws IOException, ParseException, TemplateModelException {
    final TestFileUtilsImpl fileUtils = new TestFileUtilsImpl();
    final Map<String, Object> testMap = new HashMap<>();
    final Struct structEntry = StructConverter.toStruct(new Ds3Type("ListAllMyBucketsResult", ImmutableList.of(new Ds3Element("Buckets", "array", "Bucket", false), new Ds3Element("Owner", "User", null, false))), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of());
    testMap.put("structEntry", structEntry);
    final CCodeGenerator codeGenerator = new CCodeGenerator();
    codeGenerator.processTemplate(testMap, "header-templates/TypedefStruct.ftl", fileUtils.getOutputStream());
    final ByteArrayOutputStream bstream = (ByteArrayOutputStream) fileUtils.getOutputStream();
    final String output = new String(bstream.toByteArray());
    final String expectedOutput = "typedef struct {" + "\n" + "    ds3_bucket_response** buckets;" + "\n" + "    size_t num_buckets;" + // Verify that the number of array elements is added to the model
    "\n" + "    ds3_user_response* owner;" + "\n" + "}ds3_list_all_my_buckets_result_response;" + "\n";
    assertThat(expectedOutput, is(output));
}
Also used : TestFileUtilsImpl(com.spectralogic.ds3autogen.utils.TestFileUtilsImpl) HashMap(java.util.HashMap) Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Ds3Element(com.spectralogic.ds3autogen.api.models.apispec.Ds3Element) Test(org.junit.Test)

Aggregations

Ds3Element (com.spectralogic.ds3autogen.api.models.apispec.Ds3Element)54 Test (org.junit.Test)48 Ds3Type (com.spectralogic.ds3autogen.api.models.apispec.Ds3Type)22 C_Type (com.spectralogic.ds3autogen.c.models.C_Type)10 Ds3Annotation (com.spectralogic.ds3autogen.api.models.apispec.Ds3Annotation)9 Element (com.spectralogic.ds3autogen.java.models.Element)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 Ds3AnnotationElement (com.spectralogic.ds3autogen.api.models.apispec.Ds3AnnotationElement)5 ImmutableList (com.google.common.collect.ImmutableList)4 Ds3ApiSpec (com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec)4 Struct (com.spectralogic.ds3autogen.c.models.Struct)4 NetNullableVariable (com.spectralogic.ds3autogen.net.model.common.NetNullableVariable)4 Ds3ModelPartialDataFixture.createEmptyDs3Type (com.spectralogic.ds3autogen.testutil.Ds3ModelPartialDataFixture.createEmptyDs3Type)4 Ds3SpecParser (com.spectralogic.ds3autogen.api.Ds3SpecParser)3 Ds3EnumConstant (com.spectralogic.ds3autogen.api.models.apispec.Ds3EnumConstant)3 TestFileUtilsImpl (com.spectralogic.ds3autogen.utils.TestFileUtilsImpl)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Ds3SpecParserImpl (com.spectralogic.ds3autogen.Ds3SpecParserImpl)2 NameMapper (com.spectralogic.ds3autogen.NameMapper)2 Ds3DocSpecParser (com.spectralogic.ds3autogen.api.Ds3DocSpecParser)2