Search in sources :

Example 16 with Ds3Type

use of com.spectralogic.ds3autogen.api.models.apispec.Ds3Type 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"));
}
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 17 with Ds3Type

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

the class NetNullableVariableUtils_Test method getTestTypeMap.

/**
     * Creates a type map with testing values
     */
private static ImmutableMap<String, Ds3Type> getTestTypeMap() {
    final Ds3Type enumType = new Ds3Type("TestEnumType", "", ImmutableList.of(), ImmutableList.of(new Ds3EnumConstant("ONE", null)));
    final Ds3Type elementType = new Ds3Type("TestElementType", ImmutableList.of(new Ds3Element("Element", "int", null, false)));
    return ImmutableMap.of(enumType.getName(), enumType, elementType.getName(), elementType);
}
Also used : Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type) Ds3EnumConstant(com.spectralogic.ds3autogen.api.models.apispec.Ds3EnumConstant) Ds3Element(com.spectralogic.ds3autogen.api.models.apispec.Ds3Element)

Example 18 with Ds3Type

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

the class BaseRequestGenerator_Test method toNullableArgument_NullableEnumType_Test.

@Test
public void toNullableArgument_NullableEnumType_Test() {
    final Ds3Type testType = new Ds3Type("com.spectra.TestType", "", null, createEmptyDs3EnumConstantList());
    final ImmutableMap<String, Ds3Type> testTypeMap = ImmutableMap.of(testType.getName(), testType);
    final Ds3Param param = new Ds3Param("MyParam", testType.getName(), true);
    final NetNullableVariable result = toNullableArgument(param, testTypeMap);
    assertThat(result.getNetType(), is("TestType?"));
}
Also used : Ds3Param(com.spectralogic.ds3autogen.api.models.apispec.Ds3Param) NetNullableVariable(com.spectralogic.ds3autogen.net.model.common.NetNullableVariable) Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type) Test(org.junit.Test)

Example 19 with Ds3Type

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

the class Ds3SpecParserImpl_Test method blobApiBean.

@Test
public void blobApiBean() throws IOException {
    final Ds3SpecParser parser = new Ds3SpecParserImpl();
    final Ds3ApiSpec spec = parser.getSpec(Ds3SpecParserImpl_Test.class.getResourceAsStream("/specs/blobApiBean.xml"));
    assertThat(spec.getTypes().size(), is(1));
    final Ds3Type blobApiBean = spec.getTypes().get("com.spectralogic.s3.common.platform.domain.BulkObject");
    assertThat(blobApiBean, is(notNullValue()));
    final ImmutableList<Ds3Element> elements = blobApiBean.getElements();
    assertThat(elements.size(), is(7));
    assertThat(elements.get(0).getName(), is("InCache"));
    assertThat(elements.get(0).getNullable(), is(true));
    assertThat(elements.get(1).getName(), is("Latest"));
    assertThat(elements.get(1).getNullable(), is(false));
    assertThat(elements.get(2).getName(), is("Length"));
    assertThat(elements.get(2).getNullable(), is(false));
    assertThat(elements.get(3).getName(), is("Name"));
    assertThat(elements.get(3).getNullable(), is(true));
    assertThat(elements.get(4).getName(), is("Offset"));
    assertThat(elements.get(4).getNullable(), is(false));
    assertThat(elements.get(5).getName(), is("PhysicalPlacement"));
    assertThat(elements.get(5).getNullable(), is(true));
    assertThat(elements.get(6).getName(), is("Version"));
    assertThat(elements.get(6).getNullable(), is(false));
}
Also used : Ds3SpecParser(com.spectralogic.ds3autogen.api.Ds3SpecParser) Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type) Ds3ApiSpec(com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec) Ds3Element(com.spectralogic.ds3autogen.api.models.apispec.Ds3Element) Test(org.junit.Test)

Example 20 with Ds3Type

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

the class CCodeGenerator_Test method testGenerateSingleTypeEnumConstantMatcher.

@Test
public void testGenerateSingleTypeEnumConstantMatcher() throws IOException, TemplateModelException {
    final TestFileUtilsImpl fileUtils = new TestFileUtilsImpl();
    final Map<String, Object> testMap = new HashMap<>();
    final Ds3EnumConstant inProgress = new Ds3EnumConstant("IN_PROGRESS", null);
    final Ds3EnumConstant completed = new Ds3EnumConstant("COMPLETED", null);
    final Ds3EnumConstant canceled = new Ds3EnumConstant("CANCELED", null);
    final ImmutableList<Ds3EnumConstant> enumConstants = ImmutableList.of(inProgress, completed, canceled);
    final Enum enumEntry = EnumConverter.toEnum(new Ds3Type("JobStatus", null, null, enumConstants));
    testMap.put("enumEntry", enumEntry);
    final CCodeGenerator codeGenerator = new CCodeGenerator();
    codeGenerator.processTemplate(testMap, "source-templates/TypedefEnumMatcher.ftl", fileUtils.getOutputStream());
    final ByteArrayOutputStream bstream = (ByteArrayOutputStream) fileUtils.getOutputStream();
    final String output = new String(bstream.toByteArray());
    final String expectedOutput = "static ds3_job_status _match_ds3_job_status(const ds3_log* log, const xmlChar* text) {" + "\n" + "    if (xmlStrcmp(text, (const xmlChar*) \"IN_PROGRESS\") == 0) {" + "\n" + "        return DS3_JOB_STATUS_IN_PROGRESS;" + "\n" + "    } else if (xmlStrcmp(text, (const xmlChar*) \"COMPLETED\") == 0) {" + "\n" + "        return DS3_JOB_STATUS_COMPLETED;" + "\n" + "    } else if (xmlStrcmp(text, (const xmlChar*) \"CANCELED\") == 0) {" + "\n" + "        return DS3_JOB_STATUS_CANCELED;" + "\n" + "    } else {" + "\n" + "        ds3_log_message(log, DS3_ERROR, \"ERROR: Unknown value of '%s'.  Returning DS3_JOB_STATUS_IN_PROGRESS for safety.\", text);" + "\n" + "        return DS3_JOB_STATUS_IN_PROGRESS;" + "\n" + "    }" + "\n" + "}" + "\n";
    assertThat(expectedOutput, is(output));
}
Also used : Enum(com.spectralogic.ds3autogen.c.models.Enum) TestFileUtilsImpl(com.spectralogic.ds3autogen.utils.TestFileUtilsImpl) HashMap(java.util.HashMap) Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type) Ds3EnumConstant(com.spectralogic.ds3autogen.api.models.apispec.Ds3EnumConstant) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

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