- @Test
- public void testRefine() {
- Module testModule = TestUtils.findModule(modules, "types2");
-
- ContainerSchemaNode peer = (ContainerSchemaNode) testModule
- .getDataChildByName("peer");
- ContainerSchemaNode destination = (ContainerSchemaNode) peer
- .getDataChildByName("destination");
- Set<UsesNode> usesNodes = destination.getUses();
- assertEquals(1, usesNodes.size());
- UsesNode usesNode = usesNodes.iterator().next();
- Map<SchemaPath, SchemaNode> refines = usesNode.getRefines();
- 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) {
- 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);
- }
-