use of com.spectralogic.ds3autogen.c.models.Struct in project ds3_autogen by SpectraLogic.
the class CCodeGeneratorAmazonS3Requests_Test method testGenerateAmazonS3GetBucketsRequest.
@Test
public void testGenerateAmazonS3GetBucketsRequest() throws IOException, ParseException, TemplateModelException {
final String inputSpecFile = "/input/AmazonS3GetBucketsRequest_WithResponsePayload.xml";
final TestFileUtilsImpl fileUtils = new TestFileUtilsImpl();
final Ds3SpecParser parser = new Ds3SpecParserImpl();
final Ds3ApiSpec spec = parser.getSpec(CCodeGenerator_Test.class.getResourceAsStream(inputSpecFile));
final ImmutableList<Request> allRequests = CCodeGenerator.getAllRequests(spec, new Ds3DocSpecEmptyImpl());
final ImmutableList<Enum> allEnums = CCodeGenerator.getAllEnums(spec);
final ImmutableSet<String> enumNames = EnumHelper.getEnumNamesSet(allEnums);
final ImmutableSet<String> arrayMemberTypes = CCodeGenerator.getArrayMemberTypes(spec, enumNames);
final ImmutableSet<String> responseTypes = RequestHelper.getResponseTypes(allRequests);
final ImmutableList<Struct> allStructs = CCodeGenerator.getAllStructs(spec, enumNames, responseTypes, arrayMemberTypes, ImmutableSet.of(), ImmutableSet.of());
final ImmutableList<Struct> allOrderedStructs = StructHelper.getStructsOrderedList(allStructs, enumNames);
final Source source = SourceConverter.toSource(allEnums, allOrderedStructs, allRequests);
final CCodeGenerator codeGenerator = new CCodeGenerator();
codeGenerator.processTemplate(source, "source-templates/ds3_c.ftl", fileUtils.getOutputStream());
final ByteArrayOutputStream bstream = (ByteArrayOutputStream) fileUtils.getOutputStream();
final String output = new String(bstream.toByteArray());
assertTrue(output.contains("ds3_error* ds3_get_service_request(const ds3_client* client, const ds3_request* request, ds3_list_all_my_buckets_result_response** response) {"));
assertTrue(output.contains(" return _parse_top_level_ds3_list_all_my_buckets_result_response(client, request, response, xml_blob);"));
assertTrue(output.contains("}"));
}
use of com.spectralogic.ds3autogen.c.models.Struct in project ds3_autogen by SpectraLogic.
the class StructConverter_Test method testConvertNameToMarshallJobsListSpecialCase.
@Test
public void testConvertNameToMarshallJobsListSpecialCase() 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("ds3JobList", "overrideMarshallName", elementsList, ImmutableList.of());
final Struct testStruct = StructConverter.toStruct(ds3Type, ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of());
assertThat(testStruct.getNameToMarshall(), is("Jobs"));
}
use of com.spectralogic.ds3autogen.c.models.Struct in project ds3_autogen by SpectraLogic.
the class StructConverter_Test method testConvertNameToMarshallCommonPrefixSpecialCase.
@Test
public void testConvertNameToMarshallCommonPrefixSpecialCase() throws ParseException {
final Ds3Element testElement1 = new Ds3Element("CommonPrefixes", "array", "java.lang.String", false);
final ImmutableList<Ds3Element> elementsList = ImmutableList.of(testElement1);
final Ds3Type ds3Type = new Ds3Type("com.spectralogic.s3.server.domain.BucketObjectsApiBean", "ListBucketResult", elementsList, ImmutableList.of());
final Struct testStruct = StructConverter.toStruct(ds3Type, ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of());
assertThat(testStruct.getNameToMarshall(), is("ListBucketResult"));
assertThat(testStruct.getStructMembers().get(0).getNameToMarshall(), is("CommonPrefixes"));
}
use of com.spectralogic.ds3autogen.c.models.Struct in project ds3_autogen by SpectraLogic.
the class StructHelper method getStructsOrderedList.
/**
* Return Structs which contain only primitive types first, and then cascade for Complex Structs that contain other Structs
*
* @throws java.text.ParseException
*/
public static ImmutableList<Struct> getStructsOrderedList(final ImmutableList<Struct> allStructs, final ImmutableSet<String> enumNames) throws ParseException {
final Queue<Struct> structsQueue = new LinkedList<>(allStructs);
final Set<String> existingStructs = new HashSet<>();
final ImmutableList.Builder<Struct> orderedStructsBuilder = ImmutableList.builder();
int skippedStructsCount = 0;
while (!structsQueue.isEmpty()) {
final int structsQueueSize = structsQueue.size();
final Struct structEntry = structsQueue.remove();
if (!StructHelper.requiresNewCustomParser(structEntry, existingStructs, enumNames)) {
existingStructs.add(structEntry.getName());
LOG.info(structEntry.toString());
orderedStructsBuilder.add(structEntry);
} else {
// move to end to come back to
structsQueue.add(structEntry);
}
if (structsQueueSize == structsQueue.size()) {
skippedStructsCount++;
if (skippedStructsCount == structsQueueSize) {
LOG.warn("Unable to progress on remaining structs, aborting!");
LOG.warn(" Remaining structs[" + structsQueue.size() + "]");
for (final Struct struct : allStructs) {
LOG.warn(" " + struct.toString() + "\n");
}
throw new ParseException("Unable to Order provided structs.", 0);
}
} else {
skippedStructsCount = 0;
}
}
return orderedStructsBuilder.build();
}
use of com.spectralogic.ds3autogen.c.models.Struct 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"));
}
Aggregations