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