import static org.junit.Assert.*;
+import java.io.FileNotFoundException;
import java.net.URI;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import org.opendaylight.controller.yang.model.api.ChoiceNode;
import org.opendaylight.controller.yang.model.api.ConstraintDefinition;
import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.controller.yang.model.api.DataSchemaNode;
import org.opendaylight.controller.yang.model.api.Deviation;
import org.opendaylight.controller.yang.model.api.Deviation.Deviate;
import org.opendaylight.controller.yang.model.api.ExtensionDefinition;
import org.opendaylight.controller.yang.model.api.FeatureDefinition;
+import org.opendaylight.controller.yang.model.api.GroupingDefinition;
+import org.opendaylight.controller.yang.model.api.LeafListSchemaNode;
import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
import org.opendaylight.controller.yang.model.api.ListSchemaNode;
import org.opendaylight.controller.yang.model.api.Module;
import org.opendaylight.controller.yang.model.util.ExtendedType;
import org.opendaylight.controller.yang.model.util.Int16;
import org.opendaylight.controller.yang.model.util.Int32;
+import org.opendaylight.controller.yang.model.util.Leafref;
import org.opendaylight.controller.yang.model.util.StringType;
import org.opendaylight.controller.yang.model.util.Uint32;
import org.opendaylight.controller.yang.model.util.UnionType;
private Set<Module> modules;
@Before
- public void init() {
+ public void init() throws FileNotFoundException {
modules = TestUtils.loadModules("src/test/resources/model");
assertEquals(3, modules.size());
}
assertNull(constraints.getWhenCondition());
assertEquals(0, constraints.getMustConstraints().size());
assertFalse(constraints.isMandatory());
- assertNull(constraints.getMinElements());
- assertNull(constraints.getMaxElements());
+ assertEquals(1, (int) constraints.getMinElements());
+ assertEquals(11, (int) constraints.getMaxElements());
// test AugmentationTarget args
Set<AugmentationSchema> availableAugmentations = ifEntry
.getAvailableAugmentations();
.getDataChildByName("ifEntry");
ContainerSchemaNode augmentedContainer = (ContainerSchemaNode) ifEntry
.getDataChildByName("augment-holder");
- // Set<AugmentationSchema> augmentedContainerAugments =
- // augmentedContainer
- // .getAvailableAugmentations();
+
+ // augmentation defined in testfile1 and augmentation returned from
+ // augmented container have to be same
+ Set<AugmentationSchema> augmentedContainerAugments = augmentedContainer
+ .getAvailableAugmentations();
+ AugmentationSchema augmentDefinition = augmentedContainerAugments
+ .iterator().next();
+ assertEquals(augment1, augmentDefinition);
+
LeafSchemaNode augmentedLeaf = (LeafSchemaNode) augmentedContainer
.getDataChildByName("ds0ChannelNumber");
assertTrue(augmentedLeaf.isAugmenting());
Set<AugmentationSchema> module3Augmentations = module3
.getAugmentations();
assertEquals(2, module3Augmentations.size());
- // AugmentationSchema augment3 = module3Augmentations.iterator().next();
- // ContainerSchemaNode augmentedContainerDefinition =
- // (ContainerSchemaNode) augment3
- // .getDataChildByName("augment-holder");
- // assertTrue(augmentedContainerDefinition.isAugmenting());
- //
- // // check
- // assertEquals(augmentedContainer, augmentedContainerDefinition);
- // assertEquals(augmentedContainerAugments.iterator().next(), augment1);
- //
- // assertEquals(augmentedLeaf, augmentedLeafDefinition);
- // assertEquals(ifEntryAugments.iterator().next(), augment3);
+ AugmentationSchema augment3 = null;
+ for (AugmentationSchema as : module3Augmentations) {
+ if ("if:ifType='ds0'".equals(as.getWhenCondition().toString())) {
+ augment3 = as;
+ }
+ }
+ ContainerSchemaNode augmentedContainerDefinition = (ContainerSchemaNode) augment3
+ .getDataChildByName("augment-holder");
+ assertTrue(augmentedContainerDefinition.isAugmenting());
+
+ // check
+ assertEquals(augmentedContainer, augmentedContainerDefinition);
+ assertEquals(augmentedLeaf, augmentedLeafDefinition);
}
@Test
.getAvailableAugmentations();
assertEquals(2, augmentations.size());
- // AugmentationSchema augment = augmentations.iterator().next();
-
- // ContainerSchemaNode augmentHolder = (ContainerSchemaNode) augment
- // .getDataChildByName("augment-holder");
- // assertNotNull(augmentHolder);
- // assertTrue(augmentHolder.isAugmenting());
- // QName augmentHolderQName = augmentHolder.getQName();
- // assertEquals("augment-holder", augmentHolderQName.getLocalName());
- // assertEquals("t3", augmentHolderQName.getPrefix());
- // assertEquals("Description for augment holder",
- // augmentHolder.getDescription());
+ AugmentationSchema augment = null;
+ for (AugmentationSchema as : augmentations) {
+ if ("if:ifType='ds0'".equals(as.getWhenCondition().toString())) {
+ augment = as;
+ }
+ }
+ ContainerSchemaNode augmentHolder = (ContainerSchemaNode) augment
+ .getDataChildByName("augment-holder");
+ assertNotNull(augmentHolder);
+ assertTrue(augmentHolder.isAugmenting());
+ QName augmentHolderQName = augmentHolder.getQName();
+ assertEquals("augment-holder", augmentHolderQName.getLocalName());
+ assertEquals("t3", augmentHolderQName.getPrefix());
+ assertEquals("Description for augment holder",
+ augmentHolder.getDescription());
}
@Test
List<RangeConstraint> ranges = leafType.getRanges();
assertEquals(1, ranges.size());
RangeConstraint range = ranges.get(0);
- assertEquals(11L, range.getMin());
+ assertEquals(3L, range.getMin());
assertEquals(20L, range.getMax());
}
assertEquals(1, usesNodes.size());
UsesNode usesNode = usesNodes.iterator().next();
Map<SchemaPath, SchemaNode> refines = usesNode.getRefines();
- assertEquals(2, refines.size());
+ assertEquals(5, refines.size());
+ LeafSchemaNode refineLeaf = null;
+ ContainerSchemaNode refineContainer = null;
+ ListSchemaNode refineList = null;
+ GroupingDefinition refineGrouping = null;
+ TypeDefinition<?> typedef = null;
for (Map.Entry<SchemaPath, SchemaNode> entry : refines.entrySet()) {
SchemaNode value = entry.getValue();
-
if (value instanceof LeafSchemaNode) {
- LeafSchemaNode refineLeaf = (LeafSchemaNode) value;
- assertNotNull(refineLeaf);
- } else {
- ContainerSchemaNode refineContainer = (ContainerSchemaNode) value;
- Set<MustDefinition> mustConstraints = refineContainer
- .getConstraints().getMustConstraints();
- assertEquals(1, mustConstraints.size());
- MustDefinition must = mustConstraints.iterator().next();
- assertEquals("must-condition", must.toString());
- assertEquals("An error message test", must.getErrorMessage());
- assertEquals(("An error app tag test"), must.getErrorAppTag());
+ refineLeaf = (LeafSchemaNode) value;
+ } else if (value instanceof ContainerSchemaNode) {
+ refineContainer = (ContainerSchemaNode) value;
+ } else if (value instanceof ListSchemaNode) {
+ refineList = (ListSchemaNode) value;
+ } else if (value instanceof GroupingDefinition) {
+ refineGrouping = (GroupingDefinition) value;
+ } else if (value instanceof TypeDefinition<?>) {
+ typedef = (TypeDefinition<?>) value;
}
}
+
+ // leaf address
+ assertNotNull(refineLeaf);
+ assertEquals("address", refineLeaf.getQName().getLocalName());
+ assertEquals("description of address defined by refine",
+ refineLeaf.getDescription());
+ assertEquals("address reference added by refine",
+ refineLeaf.getReference());
+ assertFalse(refineLeaf.isConfiguration());
+ assertTrue(refineLeaf.getConstraints().isMandatory());
+ Set<MustDefinition> leafMustConstraints = refineLeaf.getConstraints()
+ .getMustConstraints();
+ assertEquals(1, leafMustConstraints.size());
+ MustDefinition leafMust = leafMustConstraints.iterator().next();
+ assertEquals(
+ "\"ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)\"",
+ leafMust.toString());
+
+ // container port
+ assertNotNull(refineContainer);
+ Set<MustDefinition> mustConstraints = refineContainer.getConstraints()
+ .getMustConstraints();
+ assertTrue(mustConstraints.isEmpty());
+ assertEquals("description of port defined by refine",
+ refineContainer.getDescription());
+ assertEquals("port reference added by refine",
+ refineContainer.getReference());
+ assertFalse(refineContainer.isConfiguration());
+ assertTrue(refineContainer.isPresenceContainer());
+
+ // list addresses
+ assertNotNull(refineList);
+ assertEquals("description of addresses defined by refine",
+ refineList.getDescription());
+ assertEquals("addresses reference added by refine",
+ refineList.getReference());
+ assertFalse(refineList.isConfiguration());
+ assertEquals(2, (int) refineList.getConstraints().getMinElements());
+ assertEquals(12, (int) refineList.getConstraints().getMaxElements());
+
+ // grouping target-inner
+ assertNotNull(refineGrouping);
+ Set<DataSchemaNode> refineGroupingChildren = refineGrouping
+ .getChildNodes();
+ assertEquals(1, refineGroupingChildren.size());
+ LeafSchemaNode refineGroupingLeaf = (LeafSchemaNode) refineGroupingChildren
+ .iterator().next();
+ assertEquals("inner-grouping-id", refineGroupingLeaf.getQName()
+ .getLocalName());
+ assertEquals("new target-inner grouping description",
+ refineGrouping.getDescription());
+
+ // typedef group-type
+ assertNotNull(typedef);
+ assertEquals("new group-type description", typedef.getDescription());
+ assertEquals("new group-type reference", typedef.getReference());
+ assertTrue(typedef.getBaseType() instanceof ExtendedType);
}
@Test
assertNotNull(output.getDataChildByName("data"));
}
+ @Test
+ public void testGrouping() {
+ Module testModule = TestUtils.findModule(modules, "types2");
+ Set<GroupingDefinition> groupings = testModule.getGroupings();
+ assertEquals(1, groupings.size());
+ GroupingDefinition grouping = groupings.iterator().next();
+ Set<DataSchemaNode> children = grouping.getChildNodes();
+ assertEquals(5, children.size());
+ }
+
+ @Test
+ public void testAugmentNodesTypesSchemaPath() throws Exception {
+ final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ Module testModule = TestUtils.findModule(modules, "types1");
+ Set<AugmentationSchema> augments = testModule.getAugmentations();
+ assertEquals(1, augments.size());
+ AugmentationSchema augment = augments.iterator().next();
+
+ LeafSchemaNode ifcId = (LeafSchemaNode) augment
+ .getDataChildByName("interface-id");
+ Leafref ifcIdType = (Leafref) ifcId.getType();
+ SchemaPath ifcIdTypeSchemaPath = ifcIdType.getPath();
+ List<QName> ifcIdTypePath = ifcIdTypeSchemaPath.getPath();
+ QName q0 = new QName(new URI("urn:simple.types.data.demo"),
+ simpleDateFormat.parse("2013-02-27"), "data", "interfaces");
+ QName q1 = new QName(new URI("urn:simple.types.data.demo"),
+ simpleDateFormat.parse("2013-02-27"), "data", "ifEntry");
+ QName q2 = new QName(new URI("urn:simple.container.demo.test"),
+ simpleDateFormat.parse("2013-02-27"), "data", "augment-holder");
+ QName q3 = new QName(new URI("urn:simple.container.demo"),
+ simpleDateFormat.parse("2013-02-27"), "data", "interface-id");
+ assertEquals(q0, ifcIdTypePath.get(0));
+ assertEquals(q1, ifcIdTypePath.get(1));
+ assertEquals(q2, ifcIdTypePath.get(2));
+ assertEquals(q3, ifcIdTypePath.get(3));
+
+ LeafListSchemaNode higherLayer = (LeafListSchemaNode) augment
+ .getDataChildByName("higher-layer-if");
+ Leafref higherLayerType = (Leafref) higherLayer.getType();
+ SchemaPath higherLayerTypeSchemaPath = higherLayerType.getPath();
+ List<QName> higherLayerTypePath = higherLayerTypeSchemaPath.getPath();
+ assertEquals(q0, higherLayerTypePath.get(0));
+ assertEquals(q1, higherLayerTypePath.get(1));
+ assertEquals(q2, higherLayerTypePath.get(2));
+ q3 = new QName(new URI("urn:simple.container.demo"),
+ simpleDateFormat.parse("2013-02-27"), "data", "higher-layer-if");
+ assertEquals(q3, higherLayerTypePath.get(3));
+ }
+
}