Search in sources :

Example 11 with Ds3EnumConstant

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

the class BaseTypeGenerator_Test method toEnumConstantList_FullList_Test.

@Test
public void toEnumConstantList_FullList_Test() {
    final ImmutableList<Ds3EnumConstant> ds3EnumConstants = ImmutableList.of(new Ds3EnumConstant("Name1", null), new Ds3EnumConstant("Name2", null));
    final ImmutableList<EnumConstant> result = generator.toEnumConstantList(ds3EnumConstants);
    assertThat(result.size(), is(2));
    assertThat(result.get(0).getName(), is("Name1"));
    assertThat(result.get(1).getName(), is("Name2"));
}
Also used : Ds3EnumConstant(com.spectralogic.ds3autogen.api.models.apispec.Ds3EnumConstant) EnumConstant(com.spectralogic.ds3autogen.java.models.EnumConstant) Ds3EnumConstant(com.spectralogic.ds3autogen.api.models.apispec.Ds3EnumConstant) Test(org.junit.Test)

Example 12 with Ds3EnumConstant

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

the class BaseTypeGenerator_Test method toEnumConstant_Test.

@Test
public void toEnumConstant_Test() {
    final Ds3EnumConstant ds3EnumConstant = new Ds3EnumConstant("Name", null);
    final EnumConstant result = toEnumConstant(ds3EnumConstant);
    assertThat(result.getName(), is("Name"));
}
Also used : Ds3EnumConstant(com.spectralogic.ds3autogen.api.models.apispec.Ds3EnumConstant) EnumConstant(com.spectralogic.ds3autogen.java.models.EnumConstant) Ds3EnumConstant(com.spectralogic.ds3autogen.api.models.apispec.Ds3EnumConstant) Test(org.junit.Test)

Example 13 with Ds3EnumConstant

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

the class ChecksumTypeGenerator_Test method toEnumConstantList_FullList_Test.

@Test
public void toEnumConstantList_FullList_Test() {
    final ImmutableList<Ds3EnumConstant> enumConstants = ImmutableList.of(new Ds3EnumConstant("CRC_32", null), new Ds3EnumConstant("CRC_32C", null), new Ds3EnumConstant("MD5", null), new Ds3EnumConstant("SHA_256", null), new Ds3EnumConstant("SHA_512", null));
    final ImmutableList<EnumConstant> result = generator.toEnumConstantList(enumConstants);
    assertThat(result.size(), is(6));
    assertThat(result.get(0).getName(), is("CRC_32"));
    assertThat(result.get(1).getName(), is("CRC_32C"));
    assertThat(result.get(2).getName(), is("MD5"));
    assertThat(result.get(3).getName(), is("SHA_256"));
    assertThat(result.get(4).getName(), is("SHA_512"));
    assertThat(result.get(5).getName(), is("NONE"));
}
Also used : Ds3EnumConstant(com.spectralogic.ds3autogen.api.models.apispec.Ds3EnumConstant) EnumConstant(com.spectralogic.ds3autogen.java.models.EnumConstant) Ds3EnumConstant(com.spectralogic.ds3autogen.api.models.apispec.Ds3EnumConstant) Test(org.junit.Test)

Example 14 with Ds3EnumConstant

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

the class ChecksumTypeGenerator method toEnumConstantList.

/**
     * Converts a list of Ds3EnumConstants into a list of EnumConstant models
     * @param ds3EnumConstants A list of Ds3EnumConstants
     * @return A list of EnumConstant models
     */
@Override
public ImmutableList<EnumConstant> toEnumConstantList(final ImmutableList<Ds3EnumConstant> ds3EnumConstants) {
    if (isEmpty(ds3EnumConstants)) {
        return ImmutableList.of();
    }
    final ImmutableList.Builder<EnumConstant> builder = ImmutableList.builder();
    for (final Ds3EnumConstant ds3EnumConstant : ds3EnumConstants) {
        builder.add(toEnumConstant(ds3EnumConstant));
    }
    builder.add(new EnumConstant("NONE"));
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) EnumConstant(com.spectralogic.ds3autogen.java.models.EnumConstant) Ds3EnumConstant(com.spectralogic.ds3autogen.api.models.apispec.Ds3EnumConstant) Ds3EnumConstant(com.spectralogic.ds3autogen.api.models.apispec.Ds3EnumConstant)

Example 15 with Ds3EnumConstant

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

Ds3EnumConstant (com.spectralogic.ds3autogen.api.models.apispec.Ds3EnumConstant)18 Test (org.junit.Test)14 Ds3Type (com.spectralogic.ds3autogen.api.models.apispec.Ds3Type)9 Enum (com.spectralogic.ds3autogen.c.models.Enum)4 EnumConstant (com.spectralogic.ds3autogen.java.models.EnumConstant)4 EnumConstant (com.spectralogic.ds3autogen.net.model.type.EnumConstant)4 Ds3Element (com.spectralogic.ds3autogen.api.models.apispec.Ds3Element)3 ImmutableList (com.google.common.collect.ImmutableList)2 Ds3ModelPartialDataFixture.createEmptyDs3Type (com.spectralogic.ds3autogen.testutil.Ds3ModelPartialDataFixture.createEmptyDs3Type)1 TestFileUtilsImpl (com.spectralogic.ds3autogen.utils.TestFileUtilsImpl)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 HashMap (java.util.HashMap)1