use of org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject in project mdsal by opendaylight.
the class UnionTypeCodec method extractUnionProperties.
private static List<String> extractUnionProperties(final Type type) {
verify(type instanceof GeneratedTransferObject, "Unexpected runtime type %s", type);
GeneratedTransferObject gto = (GeneratedTransferObject) type;
while (true) {
if (gto instanceof RuntimeGeneratedUnion) {
return ((RuntimeGeneratedUnion) gto).typePropertyNames();
}
gto = verifyNotNull(gto.getSuperType(), "Cannot find union type information for %s", type);
}
}
use of org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject in project mdsal by opendaylight.
the class TypeUtilsTest method getBaseYangTypeWithExceptionTest.
@Test(expected = IllegalArgumentException.class)
public void getBaseYangTypeWithExceptionTest() throws Exception {
final GeneratedTransferObject rootType = mock(GeneratedTransferObject.class);
final GeneratedTransferObject innerType = mock(GeneratedTransferObject.class);
final GeneratedProperty property = mock(GeneratedProperty.class);
doReturn("test").when(property).getName();
doReturn(rootType).when(innerType).getSuperType();
doReturn(ImmutableList.of(property)).when(rootType).getProperties();
TypeUtils.getBaseYangType(innerType);
}
use of org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject in project mdsal by opendaylight.
the class AnnotationBuilderTest method generatedPropertyAnnotationTest.
@Test
public void generatedPropertyAnnotationTest() {
final GeneratedTOBuilder genTOBuilder = new CodegenGeneratedTOBuilder(JavaTypeName.create("org.opendaylight.controller", "AnnotInterface"));
final GeneratedPropertyBuilder propertyBuilder = genTOBuilder.addProperty("simpleProperty");
propertyBuilder.setReturnType(Types.typeForClass(Integer.class));
final AnnotationTypeBuilder annotManAttr = propertyBuilder.addAnnotation("org.springframework.jmx.export.annotation", "ManagedAttribute");
annotManAttr.addParameter("description", "\"The Name Attribute\"");
annotManAttr.addParameter("currencyTimeLimit", "20");
annotManAttr.addParameter("defaultValue", "\"bar\"");
annotManAttr.addParameter("persistPolicy", "\"OnUpdate\"");
final AnnotationTypeBuilder annotManProp = propertyBuilder.addAnnotation("org.springframework.jmx.export.annotation", "ManagedOperation");
final List<String> typeValues = new ArrayList<>();
typeValues.add("\"val1\"");
typeValues.add("\"val2\"");
typeValues.add("\"val3\"");
annotManProp.addParameters("types", typeValues);
final GeneratedTransferObject genTransObj = genTOBuilder.build();
assertNotNull(genTransObj);
assertNotNull(genTransObj.getAnnotations());
assertNotNull(genTransObj.getProperties());
assertNotNull(genTransObj.getProperties().get(0));
assertNotNull(genTransObj.getProperties().get(0).getAnnotations());
final List<AnnotationType> annotations = genTransObj.getProperties().get(0).getAnnotations();
assertEquals(2, annotations.size());
int annotCount = 0;
for (final AnnotationType annotation : annotations) {
if (annotation.getPackageName().equals("org.springframework.jmx.export.annotation") && annotation.getName().equals("ManagedAttribute")) {
annotCount++;
assertEquals(4, annotation.getParameters().size());
assertNotNull(annotation.getParameter("description"));
assertNotNull(annotation.getParameter("currencyTimeLimit"));
assertNotNull(annotation.getParameter("defaultValue"));
assertNotNull(annotation.getParameter("persistPolicy"));
assertEquals("\"The Name Attribute\"", annotation.getParameter("description").getValue());
assertEquals("20", annotation.getParameter("currencyTimeLimit").getValue());
assertEquals("\"bar\"", annotation.getParameter("defaultValue").getValue());
assertEquals("\"OnUpdate\"", annotation.getParameter("persistPolicy").getValue());
}
if (annotation.getPackageName().equals("org.springframework.jmx.export.annotation") && annotation.getName().equals("ManagedOperation")) {
annotCount++;
assertEquals(1, annotation.getParameters().size());
assertNotNull(annotation.getParameter("types"));
assertEquals(3, annotation.getParameter("types").getValues().size());
}
}
assertEquals(2, annotCount);
}
use of org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject in project mdsal by opendaylight.
the class GeneratedTOBuilderImplTest method testSetRestrictions.
@Test
public void testSetRestrictions() {
final CodegenGeneratedTOBuilder genTOBuilder = new CodegenGeneratedTOBuilder(JavaTypeName.create("org.opendaylight.yangtools.test", "Test"));
final Restrictions restrictions = new Restrictions() {
@Override
public boolean isEmpty() {
return false;
}
@Override
public Optional<? extends RangeConstraint<?>> getRangeConstraint() {
return Optional.empty();
}
@Override
public List<PatternConstraint> getPatternConstraints() {
return null;
}
@Override
public Optional<LengthConstraint> getLengthConstraint() {
return Optional.empty();
}
};
genTOBuilder.setRestrictions(restrictions);
final GeneratedTransferObject genTO = genTOBuilder.build();
assertNotNull(genTO.getRestrictions());
}
use of org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject in project mdsal by opendaylight.
the class GeneratedTOBuilderImplTest method testAddEqualsIdentity.
@Test
public void testAddEqualsIdentity() {
final CodegenGeneratedTOBuilder genTOBuilder = new CodegenGeneratedTOBuilder(JavaTypeName.create("org.opendaylight.yangtools.test", "Test"));
final GeneratedPropertyBuilderImpl propertyBuilder = new GeneratedPropertyBuilderImpl("testProperty");
genTOBuilder.addEqualsIdentity(propertyBuilder);
final GeneratedTransferObject genTO = genTOBuilder.build();
assertEquals(1, genTO.getEqualsIdentifiers().size());
assertEquals("testProperty", genTO.getEqualsIdentifiers().get(0).getName());
}
Aggregations