use of com.spectralogic.ds3autogen.api.models.docspec.Ds3DocSpec in project ds3_autogen by SpectraLogic.
the class StructHelper_Test method testGenerateParserForTopLevelStruct.
@Test
public void testGenerateParserForTopLevelStruct() throws IOException, ParseException, TemplateModelException {
final String inputSpecFile = "/input/ResponseTypeGetSystemInfo.xml";
final TestFileUtilsImpl fileUtils = new TestFileUtilsImpl();
final Ds3SpecParser parser = new Ds3SpecParserImpl();
final Ds3ApiSpec spec = parser.getSpec(CCodeGenerator_Test.class.getResourceAsStream(inputSpecFile));
final Ds3DocSpecParser docSpecParser = new Ds3DocSpecParserImpl(new NameMapper());
final Ds3DocSpec docSpec = docSpecParser.getDocSpec(CCodeGenerator_Test.class.getResourceAsStream("/input/testCommandDocumentation.json"));
final ImmutableList<Request> allRequests = CCodeGenerator.getAllRequests(spec, docSpec);
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 Source source = SourceConverter.toSource(allEnums, allStructs, 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("static ds3_error* _parse_top_level_ds3_system_information_response(const ds3_client* client, const ds3_request* request, ds3_system_information_response** _response, GByteArray* xml_blob) {"));
assertTrue(output.contains(" xmlDocPtr doc;"));
assertTrue(output.contains(" xmlNodePtr root;"));
assertTrue(output.contains(" xmlNodePtr child_node;"));
assertTrue(output.contains(" ds3_system_information_response* response;"));
assertTrue(output.contains(" ds3_error* error;"));
assertTrue(output.contains(" error = _get_request_xml_nodes(xml_blob, &doc, &root, \"Data\");"));
assertTrue(output.contains(" if (error != NULL) {"));
assertTrue(output.contains(" return error;"));
assertTrue(output.contains(" }"));
assertTrue(output.contains(" response = g_new0(ds3_system_information_response, 1);"));
assertTrue(output.contains(" for (child_node = root->xmlChildrenNode; child_node != NULL; child_node = child_node->next) {"));
assertTrue(output.contains(" if (element_equal(child_node, \"ApiVersion\")) {"));
assertTrue(output.contains(" response->api_version = xml_get_string(doc, child_node);"));
assertTrue(output.contains(" } else if (element_equal(child_node, \"BackendActivated\")) {"));
assertTrue(output.contains(" response->backend_activated = xml_get_bool(client->log, doc, child_node);"));
assertTrue(output.contains(" } else if (element_equal(child_node, \"BuildInformation\")) {"));
assertTrue(output.contains(" error = _parse_ds3_build_information_response(client, doc, child_node, &response->build_information);"));
assertTrue(output.contains(" } else if (element_equal(child_node, \"InstanceId\")) {"));
assertTrue(output.contains(" response->instance_id = xml_get_string(doc, child_node);"));
assertTrue(output.contains(" } else if (element_equal(child_node, \"SerialNumber\")) {"));
assertTrue(output.contains(" response->serial_number = xml_get_string(doc, child_node);"));
assertTrue(output.contains(" } else {"));
assertTrue(output.contains(" ds3_log_message(client->log, DS3_ERROR, \"Unknown node[%s] of ds3_system_information_response [%s]\\n\", child_node->name, root->name);"));
assertTrue(output.contains(" }"));
assertTrue(output.contains(" if (error != NULL) {"));
assertTrue(output.contains(" break;"));
assertTrue(output.contains(" }"));
assertTrue(output.contains(" }"));
assertTrue(output.contains(" xmlFreeDoc(doc);"));
assertTrue(output.contains(" if (error == NULL) {"));
assertTrue(output.contains(" *_response = response;"));
assertTrue(output.contains(" } else {"));
assertTrue(output.contains(" ds3_system_information_response_free(response);"));
assertTrue(output.contains(" }"));
assertTrue(output.contains(" return error;"));
assertTrue(output.contains("}"));
}
use of com.spectralogic.ds3autogen.api.models.docspec.Ds3DocSpec in project ds3_autogen by SpectraLogic.
the class HeaderConverter_Test method testToHeader.
@Test
public void testToHeader() throws ParseException {
final Ds3DocSpec testDocSpec = new Ds3DocSpecEmptyImpl();
final ImmutableList<Request> allRequests = ImmutableList.of(RequestConverter.toRequest(Ds3ModelFixtures.createBucketRequest(), testDocSpec), RequestConverter.toRequest(Ds3ModelFixtures.deleteBucketRequest(), testDocSpec), RequestConverter.toRequest(Ds3ModelFixtures.getBucketsRequest(), testDocSpec));
final ImmutableList<Enum> allEnums = ImmutableList.of(new Enum("TestEnum", ImmutableList.of("TestEnumValue1", "TestEnumValue2")), new Enum("TestEnum2", ImmutableList.of("TestEnumValue3", "TestEnumValue4")));
final ImmutableList<Struct> allStructs = ImmutableList.of(new Struct("testStruct1", ImmutableList.of(new StructMember(new PrimitiveType("int", false), "structMember1"), new StructMember(new PrimitiveType("ds3_str", true), "structMember2"))), new Struct("testStruct2", "marshallStruct2", ImmutableList.of(new StructMember(new PrimitiveType("int", false), "structMember3")), false, true, false, false));
final Header testHeader = HeaderConverter.toHeader(allEnums, allStructs, allRequests);
assertEquals(testHeader.getEnums(), allEnums);
assertEquals(testHeader.getRequests(), allRequests);
assertEquals(testHeader.getStructs(), allStructs);
}
use of com.spectralogic.ds3autogen.api.models.docspec.Ds3DocSpec in project ds3_autogen by SpectraLogic.
the class RequestConverter_Test method testConvertDs3ParameterWithDocumentation.
@Test
public void testConvertDs3ParameterWithDocumentation() {
final Ds3DocSpec docSpec = getTestDocSpec();
final String paramName = "BucketName";
final Ds3Param testDs3Param = new Ds3Param(paramName, "Ds3Bucket", false);
final Parameter testParameter = ParameterConverter.toParameter(testDs3Param, true, RequestConverter.toParamDocs(paramName, docSpec));
assertEquals(testParameter.getDocumentation(), "This is how you use bucket name");
}
use of com.spectralogic.ds3autogen.api.models.docspec.Ds3DocSpec in project ds3_autogen by SpectraLogic.
the class BaseClientGenerator_Test method toDocumentation_Test.
@Test
public void toDocumentation_Test() {
final String expected = "'''\n" + " This is how you use test one request\n" + " '''\n";
final Ds3DocSpec docSpec = getTestDocSpec();
assertThat(toDocumentation("com.test.TestOneRequest", docSpec), is(expected));
assertThat(toDocumentation("TestOneRequest", docSpec), is(expected));
}
use of com.spectralogic.ds3autogen.api.models.docspec.Ds3DocSpec in project ds3_autogen by SpectraLogic.
the class PythonFunctionalDocs_Test method getBucketRequest_Test.
@Test
public void getBucketRequest_Test() throws IOException, TemplateModelException {
final String requestName = "GetBucketRequest";
final FileUtils fileUtils = mock(FileUtils.class);
final TestPythonGeneratedCode codeGenerator = new TestPythonGeneratedCode(fileUtils);
final Ds3DocSpec docSpec = new Ds3DocSpecImpl(ImmutableMap.of(requestName, "This is how you use the request"), ImmutableMap.of("Delimiter", "This is how you use delimiter", "Marker", "This is how you use marker", "MaxKeys", "This is how you use max keys", "Prefix", "This is how you use prefix", "BucketName", "This is how you use bucket name"));
codeGenerator.generateCode(fileUtils, "/input/requests/getBucketRequest.xml", docSpec);
//Test Request code
final String ds3Code = codeGenerator.getDs3Code();
CODE_LOGGER.logFile(ds3Code, FileTypeToLog.REQUEST);
final Pattern expectedConstructorDocs = Pattern.compile("'''\\s+" + "This is how you use the request\\s+" + "`bucket_name` This is how you use bucket name\\s+" + "`delimiter` This is how you use delimiter\\s+" + "`marker` This is how you use marker\\s+" + "`max_keys` This is how you use max keys\\s+" + "`prefix` This is how you use prefix\\s+" + "'''\\s+" + "def __init__\\(self, bucket_name, delimiter=None, marker=None, max_keys=None, prefix=None\\):", Pattern.MULTILINE | Pattern.UNIX_LINES);
assertTrue(expectedConstructorDocs.matcher(ds3Code).find());
//Test Client code
final Pattern expectedCommandDoc = Pattern.compile("'''\\s+" + "This is how you use the request\\s+" + "'''\\s+" + "def get_bucket\\(self, request\\):", Pattern.MULTILINE | Pattern.UNIX_LINES);
assertTrue(expectedCommandDoc.matcher(ds3Code).find());
}
Aggregations