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