genCtx.get(module).addChoiceToCaseMapping(refChoiceType, caseTypeBuilder, caseNode);
final Iterable<DataSchemaNode> caseChildNodes = caseNode.getChildNodes();
if (caseChildNodes != null) {
- Object parentNode = null;
final SchemaPath nodeSp = choiceNode.getPath();
- parentNode = findDataSchemaNode(schemaContext, nodeSp.getParent());
+ final Object parentNode = findDataSchemaNode(schemaContext, nodeSp.getParent());
SchemaNode parent;
if (parentNode instanceof AugmentationSchema) {
final SchemaPath sp = choiceNode.getPath();
parent = findDataSchemaNode(schemaContext, sp.getParent());
}
- GeneratedTypeBuilder childOfType = findChildNodeByPath(parent.getPath());
- if (childOfType == null) {
- childOfType = findGroupingByPath(parent.getPath());
+ if (parent != null) {
+ GeneratedTypeBuilder childOfType = findChildNodeByPath(parent.getPath());
+ if (childOfType == null) {
+ childOfType = findGroupingByPath(parent.getPath());
+ }
+ resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType, caseChildNodes);
}
- resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType, caseChildNodes);
}
}
-
processUsesAugments(caseNode, module);
}
}
/**
* It is used only as ancestor for other <code>Type</code>s
- *
+ *
*/
public class AbstractBaseType implements Type {
/**
* Constructs the instance of this class with the concrete package name type
* name.
- *
+ *
* @param pkName
* string with the package name to which this <code>Type</code>
* belongs
if (obj == null) {
return false;
}
- if (false ==(obj instanceof Type)) {
+ if (!(obj instanceof Type)) {
return false;
}
Type other = (Type) obj;
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.binding.generator.util;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class AbstractBaseTypeTest {
+
+ @Rule
+ public ExpectedException expException = ExpectedException.none();
+
+ @Test
+ public void testgetFullyQualifiedName() {
+ AbstractBaseType baseType = new AbstractBaseType("", "");
+ assertTrue(baseType.getFullyQualifiedName().isEmpty());
+ }
+
+ @Test
+ public void testCreateAbstractBaseTypeWithNullPackagename() {
+ expException.expect(IllegalArgumentException.class);
+ expException.expectMessage("Package Name for Generated Type cannot be null!");
+ AbstractBaseType baseTypeNullpackagename = new AbstractBaseType(null, "Test");
+ }
+
+ @Test
+ public void testCreateAbstractBaseTypeWithNullTypeName() {
+ expException.expect(IllegalArgumentException.class);
+ expException.expectMessage("Name of Generated Type cannot be null!");
+ AbstractBaseType baseTypeNullTypeName = new AbstractBaseType("org.opendaylight.yangtools.test", null);
+ }
+
+ @Test
+ public void testHashCode() {
+ AbstractBaseType baseType1 = new AbstractBaseType("org.opendaylight.yangtools.test", "Test");
+ AbstractBaseType baseType2 = new AbstractBaseType("org.opendaylight.yangtools.test", "Test2");
+ assertNotEquals(baseType1.hashCode(), baseType2.hashCode());
+ }
+
+ @Test
+ public void testToString() {
+ AbstractBaseType baseType = new AbstractBaseType("org.opendaylight.yangtools.test", "Test");
+ assertTrue(baseType.toString().contains("org.opendaylight.yangtools.test.Test"));
+ baseType = new AbstractBaseType("", "Test");
+ assertTrue(baseType.toString().contains("Test"));
+ }
+
+ @Test
+ public void testEquals() {
+ AbstractBaseType baseType1 = new AbstractBaseType("org.opendaylight.yangtools.test", "Test");
+ AbstractBaseType baseType2 = new AbstractBaseType("org.opendaylight.yangtools.test", "Test2");
+ AbstractBaseType baseType3 = null;
+ AbstractBaseType baseType4 = new AbstractBaseType("org.opendaylight.yangtools.test", "Test");
+ AbstractBaseType baseType5 = new AbstractBaseType("org.opendaylight.yangtools.test1", "Test");
+
+ assertFalse(baseType1.equals(baseType2));
+ assertFalse(baseType1.equals(baseType3));
+ assertTrue(baseType1.equals(baseType4));
+ assertFalse(baseType1.equals(baseType5));
+ assertFalse(baseType1.equals(null));
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.binding.generator.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class ReferencedTypeImplTest {
+
+ @Test
+ public void testCreateNewReferencedType() {
+ ReferencedTypeImpl refType = new ReferencedTypeImpl("org.opendaylight.yangtools.test", "RefTypeTest");
+ assertEquals("RefTypeTest", refType.getName());
+ }
+
+ @Test
+ public void testToStringMethod() {
+ ReferencedTypeImpl refType = new ReferencedTypeImpl("org.opendaylight.yangtools.test", "RefTypeTest");
+ assertTrue(refType.toString().contains("RefTypeTest"));
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.binding.generator.util;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.sal.binding.model.api.ConcreteType;
+import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType;
+import org.opendaylight.yangtools.sal.binding.model.api.Type;
+import org.opendaylight.yangtools.sal.binding.model.api.WildcardType;
+
+public class TypesTest {
+
+ @Test
+ public void testVoidType() {
+ final ConcreteType voidType = Types.voidType();
+ assertEquals("Void", voidType.getName());
+ }
+
+ @Test
+ public void testPrimitiveType() {
+ final Type primitiveType = Types.primitiveType("newType", null);
+ assertEquals("newType", primitiveType.getName());
+ }
+
+ @Test
+ public void testMapTypeFor() {
+ final ParameterizedType mapType = Types.mapTypeFor(null, null);
+ assertEquals("Map", mapType.getName());
+ }
+
+ @Test
+ public void testSetTypeFor() {
+ final ParameterizedType setType = Types.setTypeFor(null);
+ assertEquals("Set", setType.getName());
+ }
+
+ @Test
+ public void testListTypeFor() {
+ final ParameterizedType listType = Types.listTypeFor(null);
+ assertEquals("List", listType.getName());
+ }
+
+ @Test
+ public void testWildcardTypeFor() {
+ final WildcardType wildcardType = Types.wildcardTypeFor("org.opendaylight.yangtools.test", "WildcardTypeTest");
+ assertEquals("WildcardTypeTest", wildcardType.getName());
+ }
+
+ @Test
+ public void testAugmentableTypeFor() {
+ ParameterizedType augmentableType = Types.augmentableTypeFor(null);
+ assertEquals("Augmentable", augmentableType.getName());
+ }
+
+ @Test
+ public void augmentationTypeFor() {
+ ParameterizedType augmentationType = Types.augmentationTypeFor(null);
+ assertEquals("Augmentation", augmentationType.getName());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.binding.generator.util.generated.type.builder;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature;
+
+public class AbstractTypeMemberTest {
+
+ @Test
+ public void testMethodsForAbstractTypeMemberBuilder() {
+ final MethodSignatureBuilderImpl methodSignatureBuilderImpl = new MethodSignatureBuilderImpl("TestProperty");
+ final GeneratedTypeBuilderImpl typeBuilderImpl = new GeneratedTypeBuilderImpl("org.opendaylight.yangtools.test", "TestType");
+ final GeneratedTypeBuilderImpl typeBuilderImpl2 = new GeneratedTypeBuilderImpl("org.opendaylight.yangtools.test", "TestType2");
+ methodSignatureBuilderImpl.setComment("test comment");
+ methodSignatureBuilderImpl.setFinal(true);
+ methodSignatureBuilderImpl.setStatic(true);
+
+ final MethodSignature genProperty = methodSignatureBuilderImpl.toInstance(typeBuilderImpl);
+ final MethodSignature genProperty2 = methodSignatureBuilderImpl.toInstance(typeBuilderImpl2);
+ assertEquals("test comment", genProperty.getComment());
+ assertTrue(genProperty.isFinal());
+ assertTrue(genProperty.isStatic());
+ assertEquals(genProperty.hashCode(), genProperty2.hashCode());
+ String pom = genProperty.toString();
+ assertTrue(genProperty.toString().contains("org.opendaylight.yangtools.test.TestType"));
+ assertTrue(genProperty.equals(genProperty2));
+ assertFalse(genProperty.equals(null));
+
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.binding.generator.util.generated.type.builder;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class ConstantImplTest {
+
+ @Test
+ public void testAllMethods() {
+ final GeneratedTypeBuilderImpl definingType = new GeneratedTypeBuilderImpl("org.opendaylight.yangtools.test",
+ "DefiningType");
+ final GeneratedTypeBuilderImpl type = new GeneratedTypeBuilderImpl("org.opendaylight.yangtools.test.v1",
+ "BaseType");
+ final ConstantImpl constImpl = new ConstantImpl(definingType, type, "IpAddress", "127.0.0.1");
+ final ConstantImpl constImpl2 = new ConstantImpl(definingType, type, "IpAddress", "127.0.0.1");
+ final ConstantImpl constImpl3 = new ConstantImpl(definingType, type, "IpAddress", "127.0.0.0");
+ final ConstantImpl constImpl4 = constImpl;
+ final ConstantImpl constImpl5 = new ConstantImpl(definingType, type, null, "127.0.0.0");
+ final ConstantImpl constImpl6 = new ConstantImpl(definingType, type, "IpAddress", null);
+
+ assertEquals("DefiningType", constImpl.getDefiningType().getName());
+ assertEquals("BaseType", constImpl.getType().getName());
+ assertEquals("IpAddress", constImpl.getName());
+ assertEquals("127.0.0.1", constImpl.getValue());
+ assertTrue(constImpl.toFormattedString().contains("GeneratedTransferObject"));
+ assertTrue(constImpl.toString().contains("GeneratedTransferObject"));
+ assertEquals(constImpl.hashCode(), constImpl2.hashCode());
+ assertFalse(constImpl.equals(null));
+ assertFalse(constImpl.equals("test"));
+
+ assertTrue(constImpl.equals(constImpl2));
+ assertFalse(constImpl.equals(constImpl3));
+ assertTrue(constImpl.equals(constImpl4));
+ assertFalse(constImpl5.equals(constImpl));
+ assertFalse(constImpl6.equals(constImpl));
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.binding.generator.util.generated.type.builder;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.sal.binding.model.api.AccessModifier;
+import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty;
+
+public class GeneratedPropertyTest {
+
+ @Test
+ public void testMethodsForGeneratedPropertyBuilderImpl() {
+ final GeneratedPropertyBuilderImpl propertyBuilderImpl = new GeneratedPropertyBuilderImpl("testProperty");
+
+ propertyBuilderImpl.setValue("new value");
+ propertyBuilderImpl.setReadOnly(true);
+
+ final GeneratedProperty genProperty = propertyBuilderImpl.toInstance(null);
+ assertNotNull(genProperty);
+
+ assertNotNull(propertyBuilderImpl.toString());
+ }
+
+ @Test
+ public void testMethodsForGeneratedPropertyImpl() {
+ final GeneratedPropertyImpl propertyImpl = new GeneratedPropertyImpl(null, "Test", null, "test property", AccessModifier.PRIVATE, null, true, true, true, "test value");
+
+ assertEquals("test value", propertyImpl.getValue());
+ assertTrue(propertyImpl.isReadOnly());
+ assertNotNull(propertyImpl.toString());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.binding.generator.util.generated.type.builder;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+import org.junit.Test;
+import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;
+import org.opendaylight.yangtools.sal.binding.model.api.Restrictions;
+import org.opendaylight.yangtools.sal.binding.model.api.type.builder.MethodSignatureBuilder;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
+
+public class GeneratedTOBuilderImplTest {
+
+ @Test
+ public void testCreateNewInstance() {
+ final GeneratedTOBuilderImpl genTOBuilder = new GeneratedTOBuilderImpl("org.opendaylight.yangtools.test", "Test");
+ assertNotNull(genTOBuilder);
+ }
+
+ @Test
+ public void testSetExtendsType() {
+ final GeneratedTOBuilderImpl genTOBuilder = new GeneratedTOBuilderImpl("org.opendaylight.yangtools.test", "Test");
+ final GeneratedTOBuilderImpl extendedTypeBuilder = new GeneratedTOBuilderImpl("org.opendaylight.yangtools.test", "ExtendedType");
+ final GeneratedTransferObject extendedType = extendedTypeBuilder.toInstance();
+ genTOBuilder.setExtendsType(extendedType);
+ final GeneratedTransferObject genTO = genTOBuilder.toInstance();
+
+ assertEquals("ExtendedType", genTO.getSuperType().getName());
+ }
+
+ @Test
+ public void testAddMethod() {
+ final GeneratedTOBuilderImpl genTOBuilder = new GeneratedTOBuilderImpl("org.opendaylight.yangtools.test", "Test");
+ final MethodSignatureBuilder methodSignatureBuilder = genTOBuilder.addMethod("testMethod");
+ assertEquals(methodSignatureBuilder, genTOBuilder.getMethodDefinitions().get(0));
+ assertEquals("testMethod", genTOBuilder.getMethodDefinitions().get(0).getName());
+ }
+
+ @Test
+ public void testAddEqualsIdentity() {
+ final GeneratedTOBuilderImpl genTOBuilder = new GeneratedTOBuilderImpl("org.opendaylight.yangtools.test", "Test");
+ final GeneratedPropertyBuilderImpl propertyBuilder = new GeneratedPropertyBuilderImpl("testProperty");
+ genTOBuilder.addEqualsIdentity(propertyBuilder);
+
+ final GeneratedTransferObject genTO = genTOBuilder.toInstance();
+ assertEquals(1, genTO.getEqualsIdentifiers().size());
+ assertEquals("testProperty", genTO.getEqualsIdentifiers().get(0).getName());
+ }
+
+ @Test
+ public void testAddHashIdentity() {
+ final GeneratedTOBuilderImpl genTOBuilder = new GeneratedTOBuilderImpl("org.opendaylight.yangtools.test", "Test");
+ final GeneratedPropertyBuilderImpl propertyBuilder = new GeneratedPropertyBuilderImpl("testProperty");
+ genTOBuilder.addHashIdentity(propertyBuilder);
+
+ final GeneratedTransferObject genTO = genTOBuilder.toInstance();
+ assertEquals(1, genTO.getHashCodeIdentifiers().size());
+ assertEquals("testProperty", genTO.getHashCodeIdentifiers().get(0).getName());
+ }
+
+ @Test
+ public void testAddToStringProperty() {
+ final GeneratedTOBuilderImpl genTOBuilder = new GeneratedTOBuilderImpl("org.opendaylight.yangtools.test", "Test");
+ final GeneratedPropertyBuilderImpl propertyBuilder = new GeneratedPropertyBuilderImpl("testProperty");
+ genTOBuilder.addToStringProperty(propertyBuilder);
+
+ final GeneratedTransferObject genTO = genTOBuilder.toInstance();
+ assertEquals(1, genTO.getToStringIdentifiers().size());
+ assertEquals("testProperty", genTO.getToStringIdentifiers().get(0).getName());
+ }
+
+ @Test
+ public void testSetRestrictions() {
+ final GeneratedTOBuilderImpl genTOBuilder = new GeneratedTOBuilderImpl("org.opendaylight.yangtools.test", "Test");
+ final Restrictions restrictions = new Restrictions() {
+
+ @Override
+ public boolean isEmpty() {
+ return false;
+ }
+
+ @Override
+ public List<RangeConstraint> getRangeConstraints() {
+ return null;
+ }
+
+ @Override
+ public List<PatternConstraint> getPatternConstraints() {
+ return null;
+ }
+
+ @Override
+ public List<LengthConstraint> getLengthConstraints() {
+ return null;
+ }
+ };
+ genTOBuilder.setRestrictions(restrictions);
+ final GeneratedTransferObject genTO = genTOBuilder.toInstance();
+
+ assertNotNull(genTO.getRestrictions());
+ }
+
+ @Test
+ public void testSetSUID() {
+ final GeneratedTOBuilderImpl genTOBuilder = new GeneratedTOBuilderImpl("org.opendaylight.yangtools.test", "Test");
+ final GeneratedPropertyBuilderImpl propertyBuilder = new GeneratedPropertyBuilderImpl("testProperty");
+ genTOBuilder.setSUID(propertyBuilder);
+
+ final GeneratedTransferObject genTO = genTOBuilder.toInstance();
+ assertEquals("testProperty", genTO.getSUID().getName());
+ }
+
+ @Test
+ public void testToStringMethod() {
+ final GeneratedTOBuilderImpl genTOBuilder = new GeneratedTOBuilderImpl("org.opendaylight.yangtools.test", "Test");
+ assertNotNull(genTOBuilder.toString());
+ }
+
+ @Test
+ public void testSetterMethods() {
+ final GeneratedTOBuilderImpl genTOBuilder = new GeneratedTOBuilderImpl("org.opendaylight.yangtools.test", "Test");
+ genTOBuilder.setTypedef(true);
+ genTOBuilder.setIsUnion(true);
+ genTOBuilder.setIsUnionBuilder(true);
+ genTOBuilder.setDescription("test description");
+ genTOBuilder.setModuleName("test-module");
+ genTOBuilder.setReference("http://tools.ietf.org/html/rfc6020");
+ genTOBuilder.setSchemaPath(SchemaPath.ROOT.getPathFromRoot());
+
+ final GeneratedTransferObject genTO = genTOBuilder.toInstance();
+
+ assertTrue(genTO.isTypedef());
+ assertTrue(genTO.isUnionType());
+ assertTrue(genTO.isUnionTypeBuilder());
+ assertEquals("test description", genTO.getDescription());
+ assertEquals("test-module", genTO.getModuleName());
+ assertEquals("http://tools.ietf.org/html/rfc6020", genTO.getReference());
+ assertEquals(SchemaPath.ROOT.getPathFromRoot(), genTO.getSchemaPath());
+ }
+
+ @Test
+ public void testMethodsOfGeneratedTransferObjectImpl() {
+ final GeneratedTOBuilderImpl genTOBuilder = new GeneratedTOBuilderImpl("org.opendaylight.yangtools.test", "Test");
+ final GeneratedTransferObject genTO = genTOBuilder.toInstance();
+
+ assertNotNull(genTO.toString());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.binding.generator.util.generated.type.builder;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature;
+
+public class MethodSignatureBuilderImplTest {
+
+ @Test
+ public void testCreateNewInstance() {
+ final MethodSignatureBuilderImpl signatureBuilderImpl = new MethodSignatureBuilderImpl("testMethod");
+ assertNotNull(signatureBuilderImpl);
+ }
+
+ @Test
+ public void testSetAbstractMethod() {
+ final MethodSignatureBuilderImpl signatureBuilderImpl = new MethodSignatureBuilderImpl("testMethod");
+ signatureBuilderImpl.setAbstract(true);
+ final MethodSignature methodSignature = signatureBuilderImpl.toInstance(null);
+ assertTrue(methodSignature.isAbstract());
+ }
+
+ @Test
+ public void testAddParameterMethod() {
+ final MethodSignatureBuilderImpl signatureBuilderImpl = new MethodSignatureBuilderImpl("testMethod");
+ final GeneratedTypeBuilderImpl ipAddressType = new GeneratedTypeBuilderImpl("org.opendaylight.yangtools.test", "IpAddress");
+ signatureBuilderImpl.addParameter(ipAddressType, "ipAddress");
+ final MethodSignature methodSignature = signatureBuilderImpl.toInstance(null);
+ assertEquals("ipAddress", methodSignature.getParameters().get(0).getName());
+ }
+
+ @Test
+ public void testHashCodeEqualsToStringMethods() {
+ final MethodSignatureBuilderImpl signatureBuilderImpl = new MethodSignatureBuilderImpl("testMethod");
+ final MethodSignatureBuilderImpl signatureBuilderImpl2 = new MethodSignatureBuilderImpl("testMethod");
+ final MethodSignatureBuilderImpl signatureBuilderImpl3 = new MethodSignatureBuilderImpl("testMethod2");
+ final MethodSignatureBuilderImpl signatureBuilderImpl4 = new MethodSignatureBuilderImpl(null);
+ final MethodSignatureBuilderImpl signatureBuilderImpl5 = signatureBuilderImpl;
+ final MethodSignatureBuilderImpl signatureBuilderImpl6 = new MethodSignatureBuilderImpl("testMethod");
+ final GeneratedTypeBuilderImpl returnType = new GeneratedTypeBuilderImpl("org.opendaylight.yangtools.test", "Address");
+ signatureBuilderImpl6.setReturnType(returnType);
+
+ assertEquals(signatureBuilderImpl.hashCode(), signatureBuilderImpl2.hashCode());
+
+ assertTrue(signatureBuilderImpl.equals(signatureBuilderImpl2));
+ assertFalse(signatureBuilderImpl.equals(signatureBuilderImpl3));
+ assertFalse(signatureBuilderImpl.equals(signatureBuilderImpl4));
+ assertFalse(signatureBuilderImpl4.equals(signatureBuilderImpl));
+ assertTrue(signatureBuilderImpl.equals(signatureBuilderImpl5));
+ assertFalse(signatureBuilderImpl4.equals("test"));
+ assertFalse(signatureBuilderImpl4.equals(signatureBuilderImpl));
+ assertFalse(signatureBuilderImpl6.equals(signatureBuilderImpl));
+ assertFalse(signatureBuilderImpl.equals(signatureBuilderImpl6));
+
+ assertNotNull(signatureBuilderImpl.toString());
+ }
+}
int i = 0;
return new «genTO.name»(
«FOR prop : allProperties SEPARATOR ","»
- properties.get(i++).equals(defaultValue) ? new «Boolean.importedName»("true") : null
+ properties.get(i++).equals(defaultValue) ? «Boolean.importedName».TRUE : null
«ENDFOR»
);
'''
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.sal.binding.yang.types;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.parser.builder.impl.GroupingBuilderImpl;
+
+public class GroupingDefinitionDependencySortTest {
+
+ @Rule
+ public ExpectedException expException = ExpectedException.none();
+
+ @Test
+ public void testSortMethod() {
+ GroupingDefinitionDependencySort groupingDefinitionDependencySort = new GroupingDefinitionDependencySort();
+ List<GroupingDefinition> unsortedGroupingDefs = new ArrayList<>();
+
+ GroupingBuilderImpl groupingBuilderImpl = new GroupingBuilderImpl("test-module", 111, QName.create("leaf1"), SchemaPath.create(false, QName.create("Cont1"), QName.create("Cont2")));
+ GroupingBuilderImpl groupingBuilderImpl2 = new GroupingBuilderImpl("test-module", 222, QName.create("leaf2"), SchemaPath.create(false, QName.create("Cont1")));
+ GroupingBuilderImpl groupingBuilderImpl3 = new GroupingBuilderImpl("test-module2", 111, QName.create("leaf3"), SchemaPath.create(false, QName.create("Cont1"), QName.create("Cont2")));
+ GroupingBuilderImpl groupingBuilderImpl4 = new GroupingBuilderImpl("test-module2", 222, QName.create("leaf4"), SchemaPath.create(false, QName.create("Cont1"), QName.create("Cont2"), QName.create("List1")));
+ GroupingBuilderImpl groupingBuilderImpl5 = new GroupingBuilderImpl("test-module2", 333, QName.create("leaf5"), SchemaPath.create(false, QName.create("Cont1")));
+
+ unsortedGroupingDefs.add(groupingBuilderImpl.build());
+ unsortedGroupingDefs.add(groupingBuilderImpl.build());
+ unsortedGroupingDefs.add(groupingBuilderImpl2.build());
+ unsortedGroupingDefs.add(groupingBuilderImpl3.build());
+ unsortedGroupingDefs.add(groupingBuilderImpl4.build());
+ unsortedGroupingDefs.add(groupingBuilderImpl5.build());
+
+ List<GroupingDefinition> sortedGroupingDefs = groupingDefinitionDependencySort.sort(unsortedGroupingDefs);
+ assertNotNull(sortedGroupingDefs);
+
+ expException.expect(IllegalArgumentException.class);
+ expException.expectMessage("Set of Type Definitions cannot be NULL!");
+ groupingDefinitionDependencySort.sort(null);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.sal.binding.yang.types;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import com.google.common.base.Optional;
+import java.io.File;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.NoSuchElementException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.opendaylight.yangtools.binding.generator.util.generated.type.builder.GeneratedTypeBuilderImpl;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
+import org.opendaylight.yangtools.yang.model.util.BinaryType;
+import org.opendaylight.yangtools.yang.model.util.BooleanType;
+import org.opendaylight.yangtools.yang.model.util.Decimal64;
+import org.opendaylight.yangtools.yang.model.util.EmptyType;
+import org.opendaylight.yangtools.yang.model.util.EnumerationType;
+import org.opendaylight.yangtools.yang.model.util.IdentityrefType;
+import org.opendaylight.yangtools.yang.model.util.StringType;
+import org.opendaylight.yangtools.yang.parser.builder.impl.IdentitySchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.impl.LeafSchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
+import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
+
+public class TypeProviderImplTest {
+
+ @Rule
+ public ExpectedException expException = ExpectedException.none();
+
+ @Test
+ public void testMethodsOfTypeProviderImpl() throws URISyntaxException {
+ final YangParserImpl yangParser = new YangParserImpl();
+ final File abstractTopology = new File(BaseYangTypes.class.getResource("/base-yang-types.yang")
+ .toURI());
+ final SchemaContext schemaContext = yangParser.parseFiles(Arrays.asList(abstractTopology));
+ final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext);
+
+ final SchemaPath refTypePath = SchemaPath.create(true, QName.create("cont1"), QName.create("list1"));
+ final GeneratedTypeBuilderImpl refType = new GeneratedTypeBuilderImpl("org.opendaylight.yangtools.test", "TestType");
+ typeProvider.putReferencedType(refTypePath, refType);
+ final StringType stringType = StringType.getInstance();
+ LeafSchemaNodeBuilder leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT);
+ leafSchemaNodeBuilder.setType(stringType);
+ LeafSchemaNode leafSchemaNode = leafSchemaNodeBuilder.build();
+
+ // test constructor
+ assertNotNull(typeProvider);
+
+ // test getAdditionalTypes() method
+ assertFalse(typeProvider.getAdditionalTypes().isEmpty());
+
+ // test getConstructorPropertyName() method
+ assertTrue(typeProvider.getConstructorPropertyName(null).isEmpty());
+ assertEquals("value", typeProvider.getConstructorPropertyName(stringType));
+
+ // test getParamNameFromType() method
+ assertEquals("string", typeProvider.getParamNameFromType(stringType));
+
+ // test getTypeDefaultConstruction() method for string type
+ assertEquals("\"default value\"", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "default value"));
+
+ // binary type
+ final BinaryType binaryType = BinaryType.getInstance();
+ leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT);
+ leafSchemaNodeBuilder.setType(binaryType);
+ leafSchemaNode = leafSchemaNodeBuilder.build();
+ assertEquals("new byte[] {-45}", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "01"));
+
+ // boolean type
+ final BooleanType booleanType = BooleanType.getInstance();
+ leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT);
+ leafSchemaNodeBuilder.setType(booleanType);
+ leafSchemaNode = leafSchemaNodeBuilder.build();
+ assertEquals("new java.lang.Boolean(\"false\")", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "false"));
+
+ // decimal type
+ final Decimal64 decimalType = Decimal64.create(refTypePath, 4);
+ leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT);
+ leafSchemaNodeBuilder.setType(decimalType);
+ leafSchemaNode = leafSchemaNodeBuilder.build();
+ assertEquals("new java.math.BigDecimal(\"111\")", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "111"));
+
+ // empty type
+ final EmptyType emptyType = EmptyType.getInstance();
+ leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT);
+ leafSchemaNodeBuilder.setType(emptyType);
+ leafSchemaNode = leafSchemaNodeBuilder.build();
+ assertEquals("new java.lang.Boolean(\"default value\")", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "default value"));
+
+ // enum type
+ expException.expect(NoSuchElementException.class);
+ final EnumerationType enumType = EnumerationType.create(refTypePath, new ArrayList<EnumTypeDefinition.EnumPair>(), Optional.<EnumPair> absent());
+ leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT);
+ leafSchemaNodeBuilder.setType(enumType);
+ leafSchemaNode = leafSchemaNodeBuilder.build();
+ assertEquals("\"default value\"", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "default value"));
+
+ // identityref type
+ expException.expect(UnsupportedOperationException.class);
+ expException.expectMessage("Cannot get default construction for identityref type");
+
+ final ModuleBuilder testModBuilder = new ModuleBuilder("test-module", "/test");
+ final IdentitySchemaNodeBuilder identityNodeBuilder = testModBuilder.addIdentity(QName.create("IdentityRefTest"), 111, SchemaPath.ROOT);
+ final IdentitySchemaNode identitySchemaNode = identityNodeBuilder.build();
+ final IdentityrefType identityRef = IdentityrefType.create(refTypePath, identitySchemaNode);
+ leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT);
+ leafSchemaNodeBuilder.setType(identityRef);
+
+ leafSchemaNodeBuilder.setParent(identityNodeBuilder);
+ leafSchemaNode = leafSchemaNodeBuilder.build();
+ assertEquals("\"default value\"", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "default value"));
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.sal.binding.yang.types;
+
+import static org.junit.Assert.assertNotNull;
+
+import com.google.common.base.Optional;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.ExtendedType;
+import org.opendaylight.yangtools.yang.model.util.StringType;
+
+public class UnionDependencySortTest {
+
+ @Rule
+ public ExpectedException expException = ExpectedException.none();
+
+ @Test
+ public void testSortMethod() {
+
+ final UnionDependencySort unionDependencySort = new UnionDependencySort();
+ final Set<TypeDefinition<?>> typeDefs = new HashSet<>();
+
+ final StringType stringType = StringType.getInstance();
+ final ExtendedType extendedType = ExtendedType.builder(QName.create("ExtendedType1"), stringType, Optional.<String> absent(), Optional.<String> absent(), SchemaPath.create(false, QName.create("Cont1"), QName.create("List1"))).build();
+
+ typeDefs.add(stringType);
+ typeDefs.add(extendedType);
+
+ final List<ExtendedType> sortedExtendedTypes = unionDependencySort.sort(typeDefs);
+ assertNotNull(sortedExtendedTypes);
+
+ expException.expect(IllegalArgumentException.class);
+ expException.expectMessage("Set of Type Definitions cannot be NULL!");
+ unionDependencySort.sort(null);
+ }
+}
import static org.opendaylight.yangtools.featuretest.Constants.ORG_OPENDAYLIGHT_FEATURETEST_FEATUREVERSION_PROP;
import static org.opendaylight.yangtools.featuretest.Constants.ORG_OPENDAYLIGHT_FEATURETEST_URI_PROP;
import static org.ops4j.pax.exam.CoreOptions.maven;
+import static org.ops4j.pax.exam.CoreOptions.vmOptions;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
//import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.debugConfiguration;
public Option[] config() throws IOException {
return new Option[] {
getKarafDistroOption(),
+ vmOptions("-Xmx2048m","-XX:MaxPermSize=512m"),
keepRuntimeFolder(),
configureConsole().ignoreLocalConsole(),
logLevel(LogLevel.WARN),
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.util;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class HashCodeBuilderTest {
+
+ @Test
+ public void testAllMethodsOfHashCodeBuilder() {
+ final HashCodeBuilder<String> hashCodeBuilder = new HashCodeBuilder<>();
+ assertEquals("Default hash code should be '1'.", 1, hashCodeBuilder.toInstance().intValue());
+
+ int nextHashCode = HashCodeBuilder.nextHashCode(1, "test");
+ assertEquals("Next hash code should be '3556529'.", 3556529, nextHashCode);
+
+ hashCodeBuilder.addArgument("another test");
+ assertEquals("Updated internal hash code should be '700442706'.", -700442706, hashCodeBuilder.toInstance().intValue());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.util;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Test;
+
+public class LazyCollectionsTest {
+
+ @Test
+ public void testLazyAddMethod() {
+ final List<Integer> list = new ArrayList<>();
+ List<Integer> anotherList = LazyCollections.lazyAdd(list, 5);
+ assertEquals(1, anotherList.size());
+
+ anotherList = LazyCollections.lazyAdd(anotherList, 4);
+ assertEquals(2, anotherList.size());
+
+ anotherList = LazyCollections.lazyAdd(anotherList, 3);
+ assertEquals(3, anotherList.size());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import com.google.common.collect.Iterables;
+import java.util.EventListener;
+import java.util.Iterator;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+
+public class ListenerRegistryTest {
+
+ private TestEventListener testEventListener;
+ private ExtendedTestEventListener extendedTestEventListener;
+ private ListenerRegistry<TestEventListener> listenerRegistry;
+
+ @Rule
+ public ExpectedException expException = ExpectedException.none();
+
+ @Before
+ public void init() {
+ testEventListener = new TestEventListener() {};
+ extendedTestEventListener = new ExtendedTestEventListener() {};
+ listenerRegistry = new ListenerRegistry<>();
+ }
+
+ @Test
+ public void testCreateNewInstance() {
+ assertNotNull("Intance of listener registry shouldn't be null.", listenerRegistry);
+ }
+
+ @Test
+ public void tetGetListenersMethod() {
+ assertTrue("Listener regisdtry should have any listeners.", Iterables.isEmpty(listenerRegistry.getListeners()));
+ }
+
+ @Test
+ public void testRegisterMethod() {
+
+ final ListenerRegistration<TestEventListener> listenerRegistration = listenerRegistry.register(testEventListener);
+ assertEquals("Listeners should be the same.", testEventListener, listenerRegistration.getInstance());
+
+ expException.expect(IllegalArgumentException.class);
+ expException.expectMessage("Listener should not be null.");
+ listenerRegistry.register(null);
+ }
+
+ @Test
+ public void testRegisterWithType() {
+ final ListenerRegistration<ExtendedTestEventListener> listenerRegistration = listenerRegistry.registerWithType(extendedTestEventListener);
+ assertEquals("Listeners should be the same.", extendedTestEventListener, listenerRegistration.getInstance());
+ }
+
+ @Test
+ public void testIteratorMethod() {
+ final Iterator<ListenerRegistration<TestEventListener>> listenerIterator = listenerRegistry.iterator();
+ assertNotNull("Listener iterator shouldn't be null.", listenerIterator);
+ }
+
+ @Test
+ public void testCreateMethod() {
+ final ListenerRegistry<EventListener> emptyListenerRegistry = ListenerRegistry.create();
+ assertTrue("List of listeners in listener registry should be empty.", Iterables.isEmpty(emptyListenerRegistry.getListeners()));
+ }
+
+ interface TestEventListener extends EventListener {
+
+ }
+
+ interface ExtendedTestEventListener extends TestEventListener {
+
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.util;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class PropertyUtilsTest {
+
+ @Test
+ public void testGetIntSystemProperty() {
+ final int testValue = PropertyUtils.getIntSystemProperty("file.separator", 1);
+ assertEquals("Property value should be '1'.", 1, testValue);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Maps;
+import com.romix.scala.collection.concurrent.TrieMap;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import org.junit.Test;
+
+public class ReadWriteTrieMapTest {
+
+ @Test
+ public void testMethodsOfReadWriteTrieMap() {
+ final TrieMap<String, String> trieMap = new TrieMap<>();
+ trieMap.put("0", "zero");
+ trieMap.put("1", "one");
+
+ final ReadWriteTrieMap<String, String> readWriteTrieMap = new ReadWriteTrieMap<String, String>(trieMap, 5);
+
+ assertNotNull("Object readOnlyTrieMap shouldn't be 'null'.", readWriteTrieMap);
+
+ assertEquals("Size of readOnlyTrieMap should be '5'.", 5, readWriteTrieMap.size());
+ assertFalse("Object readOnlyTrieMap shouldn't be empty.", readWriteTrieMap.isEmpty());
+
+ assertTrue("Object readOnlyTrieMap should have key '0'.", readWriteTrieMap.containsKey("0"));
+ assertTrue("Object readOnlyTrieMap should have value 'zero'.", readWriteTrieMap.containsValue("zero"));
+ assertEquals("Object readOnlyTrieMap should have value 'zero'.", "zero", readWriteTrieMap.get("0"));
+
+ final Map<String, String> rwMap = readWriteTrieMap;
+ rwMap.put("2", "two");
+ rwMap.put("3", "three");
+
+ assertEquals("Removed value from readOnlyTrieMap should be 'one'.", "one", rwMap.remove("1"));
+
+ final Set<String> trieMapKeySet = readWriteTrieMap.keySet();
+ assertEquals("Size of keySet should be '3'.", 3, Iterables.size(trieMapKeySet));
+
+ final Collection<String> trieMapValues = readWriteTrieMap.values();
+ assertEquals("Size of values should be '3'.", 3, Iterables.size(trieMapValues));
+
+ assertTrue("Entry set of readWriteTrieMap and trieMap should by equals.", convertSetEntryToMap(readWriteTrieMap.entrySet()).equals(trieMap));
+
+ trieMap.put("2", "two");
+ final ReadWriteTrieMap<String, String> readWriteTrieMap2 = new ReadWriteTrieMap<String, String>(trieMap, 4);
+
+ assertFalse("Objects readWriteTrieMap and readOnlyTrieMap2 should be different.", readWriteTrieMap.equals(readWriteTrieMap2));
+ assertFalse("Hash codes of object readWriteTrieMap and readOnelyTrieMap2 should be different.", readWriteTrieMap.hashCode() == readWriteTrieMap2.hashCode());
+
+ final Map<String, String> readOnlyTrieMap = readWriteTrieMap.toReadOnly();
+
+ readWriteTrieMap.clear();
+ assertEquals("Size of readOnlyTrieMap should be '0'.", 0, readWriteTrieMap.size());
+ }
+
+ public Map<String, String> convertSetEntryToMap(Set<Entry<String, String>> input) {
+ Map<String, String> resultMap = Maps.newHashMap();
+ for (Entry<String, String> entry : input) {
+ resultMap.put(entry.getKey(), entry.getValue());
+ }
+ return resultMap;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+
+public class SynchronizedDurationStatsTrackerTest {
+
+ @Test
+ public void testAllMethodsOfSynchronizedDurationStatsTracker() {
+ final SynchronizedDurationStatsTracker statsTracker = new SynchronizedDurationStatsTracker();
+ statsTracker.addDuration(1000);
+ statsTracker.addDuration(2000);
+ statsTracker.addDuration(3000);
+
+ assertEquals("Shortest recorded duration should be '1000'.", 1000, statsTracker.getShortest().getDuration());
+ assertEquals("Average recorded duration should be '2000'.", 2000, statsTracker.getAverageDuration(), 0.0001);
+ assertEquals("Longest recorded duration should be '3000'.", 3000, statsTracker.getLongest().getDuration());
+ assertEquals("Total recorded duration count should be '3'.", 3, statsTracker.getTotalDurations());
+
+ statsTracker.reset();
+
+ assertNull("Shortest recorded duration should be 'null'.", statsTracker.getShortest());
+ assertEquals("Average recorded duration should be '0'.", 0, statsTracker.getAverageDuration(), 0.0001);
+ assertNull("Longest recorded duration should be '0'.", statsTracker.getLongest());
+ assertEquals("Total recorded duration should be '0'.", 0, statsTracker.getTotalDurations());
+ }
+}
package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
import java.util.Map;
-
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
public DataContainerNodeBuilder<YangInstanceIdentifier.AugmentationIdentifier, AugmentationNode> withChild(
final DataContainerChild<?, ?> child) {
// Check nested augments
- DataValidationException.checkLegalData(child instanceof AugmentationNode == false,
+ DataValidationException.checkLegalData(!(child instanceof AugmentationNode),
"Unable to add: %s, as a child for: %s, Nested augmentations are not permitted", child.getNodeType(),
getNodeIdentifier() == null ? this : getNodeIdentifier());
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@Override
public DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> withChild(final DataContainerChild<?, ?> child) {
// Augmentation nodes cannot be keys, and do not have to be present in childrenQNamesToPaths map
- if(isAugment(child.getIdentifier()) == false) {
+ if(!isAugment(child.getIdentifier())) {
childrenQNamesToPaths.put(child.getNodeType(), child.getIdentifier());
}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid;
-import java.util.Set;
-
+import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;
+import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import com.google.common.base.Preconditions;
-
/**
* General validator for container like statements, e.g. container, list-entry, choice, augment
*/
for (DataSchemaNode childSchema : nodeContainer.getChildNodes()) {
if(childSchema instanceof ChoiceCaseNode) {
allChildNodes.addAll(getChildNodes((DataNodeContainer) childSchema));
- } else if (childSchema instanceof AugmentationSchema == false) {
+ } else if (!(childSchema instanceof AugmentationSchema)) {
allChildNodes.add(childSchema.getQName());
}
}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.LinkedListMultimap;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
-
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.LinkedListMultimap;
-
/**
* Abstract(base) Parser for DataContainerNodes e.g. ContainerNode, AugmentationNode.
*/
}
private void checkAtLeastOneNode(S schema, Iterable<E> childNodes) {
- Preconditions.checkArgument(Iterables.isEmpty(childNodes) == false,
+ Preconditions.checkArgument(!Iterables.isEmpty(childNodes),
"Node detected 0 times, should be at least 1, identified by: %s, found: %s", schema, childNodes);
}
}
@Override
public final DataContainerChild<?, ?> dispatchChildElement(Object schema, List<E> childNodes) {
- Preconditions.checkArgument(childNodes.isEmpty() == false);
+ Preconditions.checkArgument(!childNodes.isEmpty());
if (schema instanceof ContainerSchemaNode) {
return factory.getContainerNodeParser().parse(childNodes, (ContainerSchemaNode) schema);
*/
package org.opendaylight.yangtools.yang.data.operations;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
import java.util.List;
import java.util.Set;
-
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-
abstract class AbstractContainerNodeModification<S, N extends DataContainerNode<?>> implements Modification<S, N> {
@Override
private Optional<N> modifyContainer(S schema, Optional<N> actual, Optional<N> modification,
OperationStack operationStack) throws DataModificationException {
- if (actual.isPresent() == false) {
+ if (!actual.isPresent()) {
return modification;
}
- if (modification.isPresent() == false) {
+ if (!modification.isPresent()) {
return actual;
}
*/
package org.opendaylight.yangtools.yang.data.operations;
+import com.google.common.base.Optional;
+import com.google.common.collect.Sets;
import java.util.Set;
-
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.SchemaUtils;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
-import com.google.common.base.Optional;
-import com.google.common.collect.Sets;
-
final class ChoiceNodeModification extends
AbstractContainerNodeModification<ChoiceNode, org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode> {
Set<YangInstanceIdentifier.PathArgument> childrenToProcess = super.getChildrenToProcess(schema, actual,
modification);
- if (modification.isPresent() == false) {
+ if (!modification.isPresent()) {
return childrenToProcess;
}
for (DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> child : modification.get().getValue()) {
Optional<ChoiceCaseNode> detectedCaseForChild = SchemaUtils.detectCase(schema, child);
- if(detectedCaseForChild.isPresent() == false) {
+ if(!detectedCaseForChild.isPresent()) {
DataModificationException.IllegalChoiceValuesException.throwUnknownChild(schema.getQName(),
child.getNodeType());
}
- if (detectedCase != null && detectedCase.equals(detectedCaseForChild.get()) == false) {
+ if (detectedCase != null && (!detectedCase.equals(detectedCaseForChild.get()))) {
DataModificationException.IllegalChoiceValuesException.throwMultipleCasesReferenced(schema.getQName(),
modification.get(), detectedCase.getQName(), detectedCaseForChild.get().getQName());
}
for (YangInstanceIdentifier.PathArgument childToProcess : childrenToProcess) {
// child from other cases, skip
if (childToProcess instanceof YangInstanceIdentifier.AugmentationIdentifier
- && SchemaUtils.belongsToCaseAugment(detectedCase,
- (YangInstanceIdentifier.AugmentationIdentifier) childToProcess) == false) {
+ && (!SchemaUtils.belongsToCaseAugment(detectedCase,
+ (YangInstanceIdentifier.AugmentationIdentifier) childToProcess))) {
continue;
- } else if (belongsToCase(detectedCase, childToProcess) == false) {
+ } else if (!belongsToCase(detectedCase, childToProcess)) {
continue;
}
*/
package org.opendaylight.yangtools.yang.data.operations;
+import com.google.common.base.Optional;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
import java.util.List;
-
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-import com.google.common.base.Optional;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
final class LeafSetNodeModification implements Modification<LeafListSchemaNode, LeafSetNode<?>> {
@Override
DataModificationException.DataExistsException.check(schema.getQName(), actual, leafListModification);
}
case REPLACE: {
- if (contains(actual, leafListModification) == false) {
+ if (!contains(actual, leafListModification)) {
resultNodes.add(leafListModification);
}
break;
*/
package org.opendaylight.yangtools.yang.data.operations;
+import com.google.common.base.Optional;
+import com.google.common.collect.Maps;
import java.util.Map;
-
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import com.google.common.base.Optional;
-import com.google.common.collect.Maps;
-
public class MapNodeModification implements Modification<ListSchemaNode, MapNode> {
public static final MapEntryNodeModification MAP_ENTRY_NODE_MODIFICATION = new MapEntryNodeModification();
Optional<MapNode> modification, OperationStack operationStack) throws DataModificationException {
// Merge or None operation on parent, leaving actual if modification not present
- if (modification.isPresent() == false)
+ if (!modification.isPresent())
return actual;
Map<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> resultNodes = Maps.newLinkedHashMap();
*/
package org.opendaylight.yangtools.yang.data.operations;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
import java.net.URI;
import java.util.Deque;
import java.util.LinkedList;
-
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.AttributesContainer;
import org.opendaylight.yangtools.yang.data.api.ModifyAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-
/**
* Tracks netconf operations on nested nodes.
*/
}
public void enteringNode(Optional<? extends NormalizedNode<?, ?>> modificationNode) {
- if (modificationNode.isPresent() == false) {
+ if (!modificationNode.isPresent()) {
return;
}
}
private ModifyAction getOperation(NormalizedNode<?, ?> modificationNode) {
- if (modificationNode instanceof AttributesContainer == false)
+ if (!(modificationNode instanceof AttributesContainer))
return null;
String operationString = ((AttributesContainer) modificationNode).getAttributes().get(OPERATION_NAME);
}
public void exitingNode(Optional<? extends NormalizedNode<?, ?>> modificationNode) {
- if (modificationNode.isPresent() == false) {
+ if (!modificationNode.isPresent()) {
return;
}
checkSupportedRepresentation(representation);
- if(storageDirectory.exists() == false) {
+ if(!storageDirectory.exists()) {
Preconditions.checkArgument(storageDirectory.mkdirs(), "Unable to create cache directory at %s", storageDirectory);
}
Preconditions.checkArgument(storageDirectory.exists());
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.model.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+
+public class LeafrefTest {
+
+ @Test
+ public void testMethodsOfLeafrefTest() {
+ final SchemaPath schemaPath = SchemaPath.create(false, QName.create("Cont1"), QName.create("List1"));
+ final RevisionAwareXPathImpl revision = new RevisionAwareXPathImpl("/test:Cont1/test:List1", false);
+ final RevisionAwareXPathImpl revision2 = new RevisionAwareXPathImpl("/test:Cont1/test:List2", false);
+
+ final Leafref leafref = Leafref.create(schemaPath, revision);
+ final Leafref leafref2 = Leafref.create(schemaPath, revision2);
+ final Leafref leafref3 = Leafref.create(schemaPath, revision);
+ final Leafref leafref4 = leafref;
+
+ assertNotNull("Object 'leafref' shouldn't be null.", leafref);
+ assertNull("Base type of 'leafref' should be null.", leafref.getBaseType());
+ assertTrue("Units of 'leafref' should be empty.", leafref.getUnits().isEmpty());
+ assertEquals("Default value of 'leafref' is 'leafref' itself.", leafref, leafref.getDefaultValue());
+ assertEquals("QName of 'leafref' is value '(urn:ietf:params:xml:ns:yang:1)leafref'.",
+ BaseTypes.constructQName("leafref"), leafref.getQName());
+ assertEquals("SchemaPath of 'leafref' is '/Cont1/List1'.", schemaPath, leafref.getPath());
+ assertEquals("Description of 'leafref' is 'The leafref type is used to reference a particular leaf instance in the data tree.'",
+ "The leafref type is used to reference a particular leaf instance in the data tree.", leafref.getDescription());
+ assertEquals("Reference of 'leafref' is 'https://tools.ietf.org/html/rfc6020#section-9.9'.", "https://tools.ietf.org/html/rfc6020#section-9.9", leafref.getReference());
+ assertEquals("Status of 'leafref' is current.", Status.CURRENT, leafref.getStatus());
+ assertTrue("Object 'leafref' shouldn't have any unknown schema nodes.", leafref.getUnknownSchemaNodes().isEmpty());
+ assertEquals("Revision aware XPath of 'leafref' should be '/test:Cont1/test:List1'.", revision, leafref.getPathStatement());
+ assertNotNull("String representation of 'leafref' shouldn't be null.", leafref.toString());
+ assertNotEquals("Hash codes of two different object of type Leafref shouldn't be equal.", leafref.hashCode(), leafref2.hashCode());
+ assertTrue("Objects of type Leafref should be equal.", leafref.equals(leafref3));
+ assertTrue("Objects of type Leafref should be equal.", leafref.equals(leafref4));
+ assertFalse("Objects of type Leafref shouldn't be equal.", leafref.equals(leafref2));
+ assertFalse("Objects shouldn't be equal.", leafref.equals(null));
+ assertFalse("Objects shouldn't be equal.", leafref.equals("test"));
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.model.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import com.google.common.base.Optional;
+import org.junit.Test;
+
+public class PatternConstraintImplTest {
+
+ @Test
+ public void testMethodsOfPatternConstraintImpl() {
+ final String regexExp = "\\D";
+ final Optional<String> description = Optional.of("test description");
+ final Optional<String> reference = Optional.of("RFC 6020");
+ final PatternConstraintImpl patternConstraint = new PatternConstraintImpl(regexExp, description, reference);
+ final String regexExp2 = "\\s";
+ final Optional<String> description2 = Optional.of("test description2");
+ final Optional<String> reference2 = Optional.of("RFC 6020 http://tools.ietf.org/html/rfc6020#page-23");
+ final PatternConstraintImpl patternConstraint2 = new PatternConstraintImpl(regexExp2, description2, reference2);
+ final PatternConstraintImpl patternConstraint3 = patternConstraint;
+ final PatternConstraintImpl patternConstraint4 = new PatternConstraintImpl(regexExp, description2, reference);
+ final PatternConstraintImpl patternConstraint5 = new PatternConstraintImpl(regexExp2, description2, reference2);
+
+ assertNotNull("Object of PatternConstraintImpl shouldn't be null.", patternConstraint);
+ assertEquals("Description should be 'test description'.", "test description", patternConstraint.getDescription());
+ assertEquals("Error app tag shouldn't be null.", "invalid-regular-expression", patternConstraint.getErrorAppTag());
+ assertTrue("Error message should be empty.", patternConstraint.getErrorMessage().isEmpty());
+ assertEquals("Reference should be equals 'RFC 6020'.", "RFC 6020", patternConstraint.getReference());
+ assertEquals("Regular expression should be equls '\\D'.", "\\D", patternConstraint.getRegularExpression());
+ assertNotEquals("Hash codes shouldn't be equals.", patternConstraint.hashCode(), patternConstraint2.hashCode());
+ assertFalse("String representation shouldn't be empty.", patternConstraint.toString().isEmpty());
+
+ assertTrue("Objects should be equals.", patternConstraint.equals(patternConstraint3));
+ assertFalse("Objects shouldn't be equals.", patternConstraint.equals(patternConstraint2));
+ assertFalse("Objects shouldn't be equals.", patternConstraint4.equals(patternConstraint));
+ assertFalse("Objects shouldn't be equals.", patternConstraint5.equals(patternConstraint));
+ assertFalse("Objects shouldn't be equals.", patternConstraint.equals("test"));
+ assertFalse("Objects shouldn't be equals.", patternConstraint.equals(null));
+ }
+}
private static DataBean getdata(final SchemaNodeBuilder old, final Builder newParent, final boolean updateQName) {
final SchemaPath newSchemaPath;
+ // this check avoid NPE because if old is IdentityrefTypeBuilder, old.getQNname() return null
+ final boolean identityrefTypeCheck = old instanceof IdentityrefTypeBuilder ? false : updateQName;
+
QName newQName = null;
if (newParent instanceof ModuleBuilder) {
ModuleBuilder parent = (ModuleBuilder) newParent;
- if (updateQName) {
+ if (identityrefTypeCheck) {
newQName = QName.create(parent.getQNameModule(), parent.getPrefix(), old.getQName()
.getLocalName());
} else {
} else if (newParent instanceof AugmentationSchemaBuilder) {
AugmentationSchemaBuilder augment = (AugmentationSchemaBuilder) newParent;
ModuleBuilder parent = BuilderUtils.getParentModule(newParent);
- if (updateQName) {
+ if (identityrefTypeCheck) {
newQName = QName.create(parent.getQNameModule(), parent.getPrefix(), old.getQName()
.getLocalName());
} else {
} else if (newParent instanceof SchemaNodeBuilder) {
SchemaNodeBuilder parent = (SchemaNodeBuilder) newParent;
QName parentQName = parent.getQName();
- if (updateQName) {
+ if (identityrefTypeCheck) {
newQName = QName.create(parentQName, old.getQName().getLocalName());
} else {
newQName = old.getQName();
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Optional;
-
import java.net.URI;
import java.util.Date;
-
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
if (this == o) {
return true;
}
- if (o == null || (o instanceof ModuleIdentifier == false)) {
+ if (o == null || (!(o instanceof ModuleIdentifier))) {
return false;
}
}
}
- private void resolveIdentity(final ModuleBuilder module, final IdentitySchemaNodeBuilder identity) {
+ private void resolveIdentity(final ModuleBuilder module,
+ final IdentitySchemaNodeBuilder identity) {
final String baseIdentityName = identity.getBaseIdentityName();
if (baseIdentityName != null) {
IdentitySchemaNodeBuilder result = null;
final int line = identity.getLine();
String[] splittedBase = baseIdentityName.split(":");
if (splittedBase.length > 2) {
- throw new YangParseException(module.getName(), line, "Failed to parse identityref base: "
- + baseIdentityName);
+ throw new YangParseException(module.getName(), line,
+ "Failed to parse identityref base: "
+ + baseIdentityName);
}
String prefix = splittedBase[0];
String name = splittedBase[1];
- ModuleBuilder dependentModule = BuilderUtils.getModuleByPrefix(module, prefix);
- result = BuilderUtils.findIdentity(dependentModule.getAddedIdentities(), name);
+
+ if (prefix.equals(module.getPrefix())
+ && name.equals(identity.getQName().getLocalName())) {
+ throw new YangParseException(module.getName(),
+ identity.getLine(),
+ "Failed to parse base, identity name equals base identity name: "
+ + baseIdentityName);
+ }
+
+ ModuleBuilder dependentModule = BuilderUtils.getModuleByPrefix(
+ module, prefix);
+ result = BuilderUtils.findIdentity(
+ dependentModule.getAddedIdentities(), name);
} else {
- result = BuilderUtils.findIdentity(module.getAddedIdentities(), baseIdentityName);
+ if (baseIdentityName.equals(identity.getQName().getLocalName())) {
+ throw new YangParseException(module.getName(),
+ identity.getLine(),
+ "Failed to parse base, identity name equals base identity name: "
+ + baseIdentityName);
+ }
+ result = BuilderUtils.findIdentity(module.getAddedIdentities(),
+ baseIdentityName);
}
identity.setBaseIdentity(result);
}
final ASTSchemaSource astSchemaSource = input.get(i);
final SourceIdentifier realSId = astSchemaSource.getIdentifier();
- if (expectedSId.equals(realSId) == false) {
+ if (!expectedSId.equals(realSId)) {
LOG.warn("Source identifier mismatch for module \"{}\", requested as {} but actually is {}. Using actual id", expectedSId.getName(), expectedSId, realSId);
}
--- /dev/null
+package org.opendaylight.yangtools.yang.parser.builder.impl;
+
+import com.google.common.base.Optional;
+import java.net.URI;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import org.junit.Before;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.MustDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.util.MustDefinitionImpl;
+import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder;
+
+/**
+ * Created by lukas on 10/14/14.
+ */
+public abstract class AbstractBuilderTest {
+
+ protected final static String MODULE_NAMESPACE = "urn:opendaylight.rpc:def:test-model";
+ protected final static String REVISION = "2014-10-06";
+ protected final static String MODULE_NAME = "test-module";
+ protected final static DateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-mm-dd");
+ protected final static String MODULE_PATH = "test/module/path/test-module@" + REVISION + ".yang";
+
+ protected ModuleBuilder module;
+
+ @Before
+ public void setUp() throws Exception {
+ module = new ModuleBuilder(MODULE_NAME, MODULE_PATH);
+ final Date moduleRevision = SIMPLE_DATE_FORMAT.parse(REVISION);
+ module.setRevision(moduleRevision);
+ module.setNamespace(URI.create(MODULE_NAMESPACE));
+ module.setPrefix("mod");
+ }
+
+ protected MustDefinition provideMustDefinition() {
+ return MustDefinitionImpl.create("must-condition == value",
+ Optional.fromNullable("desc"), Optional.fromNullable("reference"), Optional.fromNullable("error-apptag"),
+ Optional.fromNullable("error-message"));
+ }
+
+ protected UnknownSchemaNodeBuilder provideUnknownNodeBuilder() {
+ final QName unknownType = QName.create(module.getNamespace(), module.getRevision(), "unknown-type");
+ final QName unknownNode = QName.create(module.getNamespace(), module.getRevision(), "unknown-ext-use");
+ final SchemaPath unknownNodePath = SchemaPath.create(true, unknownNode);
+ final UnknownSchemaNodeBuilder unknownNodeBuilder = new UnknownSchemaNodeBuilderImpl(module.getModuleName(),
+ 25, unknownNode, unknownNodePath);
+ unknownNodeBuilder.setNodeType(unknownType);
+ return unknownNodeBuilder;
+ }
+
+ protected UnknownSchemaNodeBuilder provideUnknownNodeBuilder(final QName innerPathSegment) {
+ final QName unknownType = QName.create(module.getNamespace(), module.getRevision(), "unknown-type");
+ final QName unknownNode = QName.create(module.getNamespace(), module.getRevision(), "unknown-ext-use");
+ final SchemaPath unknownNodePath = SchemaPath.create(true, innerPathSegment, unknownNode);
+ final UnknownSchemaNodeBuilder unknownNodeBuilder = new UnknownSchemaNodeBuilderImpl(module.getModuleName(),
+ 25, unknownNode, unknownNodePath);
+ unknownNodeBuilder.setNodeType(unknownType);
+ return unknownNodeBuilder;
+ }
+
+ protected ChoiceBuilder provideChoiceBuilder(String choiceLocalName) {
+ final QName choiceName = QName.create(module.getNamespace(), module.getRevision(), choiceLocalName);
+ final SchemaPath choicePath = SchemaPath.create(true, choiceName);
+ final ChoiceBuilder choiceBuilder = new ChoiceBuilder(module.getModuleName(), 22, choiceName, choicePath);
+
+ return choiceBuilder;
+ }
+
+ protected UsesNodeBuilder provideUsesNodeBuilder(final String usesGroupingName) {
+ final QName targetQName = QName.create(module.getNamespace(), module.getRevision(), usesGroupingName);
+ return new UsesNodeBuilderImpl(module.getModuleName(), 10, SchemaPath.create(true, targetQName));
+ }
+
+ protected ContainerSchemaNodeBuilder provideContainerBuilder(final String containerLocalName) {
+ final QName containerQName = QName.create(module.getNamespace(), module.getRevision(), containerLocalName);
+ SchemaPath containerPath = SchemaPath.create(true, containerQName);
+
+ return new ContainerSchemaNodeBuilder(module.getModuleName(), 10,
+ containerQName, containerPath);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.builder.impl;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
+
+import com.google.common.base.Optional;
+import java.net.URI;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.*;
+import org.opendaylight.yangtools.yang.model.util.Uint16;
+import org.opendaylight.yangtools.yang.parser.builder.api.*;
+import org.opendaylight.yangtools.yang.parser.util.YangParseException;
+
+/**
+ * Test suite for increasing of test coverage of BuilderUtils implementation.
+ *
+ * @see org.opendaylight.yangtools.yang.parser.builder.impl.BuilderUtils
+ *
+ * @author Lukas Sedlak <lsedlak@cisco.com>
+ */
+public class BuilderUtilsTest {
+
+ private final static String MASTER_MODULE_NAMESPACE = "urn:opendaylight.master-model";
+ private final static String MODULES_REVISION = "2014-10-06";
+ private final static String MASTER_MODULE = "master-module";
+ private final static String DEPENDENT_MODULE_NAMESPACE = "urn:opendaylight.secondary-model";
+ private final static String DEPENDENT_MODULE = "depend-module";
+ private final static String MASTER_MODULE_PATH = "test/module/path/master-module@" + MODULES_REVISION + ".yang";
+ private final static String DEPENDENT_MODULE_PATH = "test/module/path/depend-module@" + MODULES_REVISION + ".yang";
+ private final static String DEPENDENT_MODULE_PREFIX = "dep";
+
+ private final static DateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-mm-dd");
+
+ private ModuleBuilder masterModule;
+ private ModuleBuilder dependentModule;
+
+ @Before
+ public void setUp() throws Exception {
+ masterModule = new ModuleBuilder(MASTER_MODULE, MASTER_MODULE_PATH);
+ dependentModule = new ModuleBuilder(DEPENDENT_MODULE, DEPENDENT_MODULE_PATH);
+
+ final Date moduleRevision = SIMPLE_DATE_FORMAT.parse(MODULES_REVISION);
+ masterModule.setRevision(moduleRevision);
+ dependentModule.setRevision(moduleRevision);
+
+ masterModule.setNamespace(URI.create(MASTER_MODULE_NAMESPACE));
+ dependentModule.setNamespace(URI.create(DEPENDENT_MODULE_NAMESPACE));
+
+ masterModule.setNamespace(URI.create(MASTER_MODULE_NAMESPACE));
+ dependentModule.setNamespace(URI.create(DEPENDENT_MODULE_NAMESPACE));
+
+ masterModule.setPrefix("mod");
+ dependentModule.setPrefix("mod");
+ masterModule.addModuleImport(dependentModule.getModuleName(), dependentModule.getRevision(), DEPENDENT_MODULE_PREFIX);
+ }
+
+ @Test
+ public void testFindModuleFromBuildersWithNullPrefix() throws Exception {
+ final Map<String, TreeMap<Date, ModuleBuilder>> testModules = initModuleBuildersForTest();
+
+ ModuleBuilder result = BuilderUtils.findModuleFromBuilders(testModules, masterModule, null, 12);
+ assertEquals(masterModule, result);
+
+ result = BuilderUtils.findModuleFromBuilders(testModules, masterModule, masterModule.getPrefix(), 12);
+ assertEquals(masterModule, result);
+
+ result = BuilderUtils.findModuleFromBuilders(testModules, masterModule, DEPENDENT_MODULE_PREFIX, 12);
+ assertEquals(dependentModule, result);
+ }
+
+ private Map<String, TreeMap<Date, ModuleBuilder>> initModuleBuildersForTest() throws Exception {
+ final Map<String, TreeMap<Date, ModuleBuilder>> modules = new HashMap<>();
+ final String module3Name = "Module3";
+
+ ModuleBuilder module3 = new ModuleBuilder(module3Name, "test/module/path/module3.yang");
+ final Date moduleRevision = SIMPLE_DATE_FORMAT.parse(MODULES_REVISION);
+
+ module3.setRevision(moduleRevision);
+ module3.setNamespace(URI.create("urn:opendaylight.ternary-model"));
+ module3.setPrefix("mod");
+
+ dependentModule.addModuleImport(module3.getModuleName(), module3.getRevision(), "ter");
+
+ final TreeMap<Date, ModuleBuilder> module1Map = new TreeMap<>();
+ module1Map.put(masterModule.getRevision(), masterModule);
+
+ final TreeMap<Date, ModuleBuilder> module2Map = new TreeMap<>();
+ module2Map.put(dependentModule.getRevision(), dependentModule);
+
+ final TreeMap<Date, ModuleBuilder> module3Map = new TreeMap<>();
+ module3Map.put(module3.getRevision(), module3);
+
+ modules.put(masterModule.getName(), module1Map);
+ modules.put(dependentModule.getName(), module2Map);
+ modules.put(module3Name, module3Map);
+
+ return modules;
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testFindModuleFromBuildersWithNoImportedModule() throws Exception {
+ final Map<String, TreeMap<Date, ModuleBuilder>> testModules = initModuleBuildersForTest();
+
+ BuilderUtils.findModuleFromBuilders(testModules, masterModule, "eth", 12);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testFindModuleFromContextWithDependentModuleImportEqualsToNull() {
+ final SchemaContext mockContext = mock(SchemaContext.class);
+
+ BuilderUtils.findModuleFromContext(mockContext, masterModule, "inalid-prefix", 14);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testFindModuleFromContextWhereModuleIsNotPresent() {
+ final SchemaContext mockContext = mock(SchemaContext.class);
+
+ BuilderUtils.findModuleFromContext(mockContext, masterModule, DEPENDENT_MODULE_PREFIX, 14);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testFillAugmentTargetForInvalidTarget() {
+ AugmentationSchemaBuilder augBuilder = mock(AugmentationSchemaBuilder.class);
+ Builder invalidTarget = mock(Builder.class);
+ BuilderUtils.fillAugmentTarget(augBuilder, invalidTarget);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testFillAugmentTargetWithChoiceBuilderContainingInvalidUsesNodeBuilder() {
+ final QName usesQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "test-grouping");
+ final UsesNodeBuilder usesNodeBuilder = new UsesNodeBuilderImpl(masterModule.getModuleName(), 10, SchemaPath.create(true, usesQName));
+
+ final QName augTargetQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "target");
+ final AugmentationSchemaBuilder augBuilder = new AugmentationSchemaBuilderImpl(masterModule.getModuleName(), 12,
+ "/target", SchemaPath.create(true, augTargetQName), 1);
+
+ augBuilder.setParent(usesNodeBuilder);
+
+ final QName choiceQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "test-choice");
+ final ChoiceBuilder choiceBuilder = new ChoiceBuilder(masterModule.getModuleName(), 14, choiceQName,
+ SchemaPath.create(true, choiceQName));
+
+ augBuilder.addUsesNode(usesNodeBuilder);
+ BuilderUtils.fillAugmentTarget(augBuilder, choiceBuilder);
+ }
+
+ @Test
+ public void testFillAugmentTargetSetNodeAddedByUses() {
+ final QName augTargetQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "target");
+ final AugmentationSchemaBuilder augBuilder = new AugmentationSchemaBuilderImpl(masterModule.getModuleName(), 12,
+ "/target", SchemaPath.create(true, augTargetQName), 1);
+
+ final String containerLocalName = "top-level-container";
+ final QName containerQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), containerLocalName);
+ SchemaPath containerPath = SchemaPath.create(true, containerQName);
+ augBuilder.addChildNode(
+ new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 10, containerQName, containerPath));
+
+ final QName choiceQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "test-choice");
+ final ChoiceBuilder choiceBuilder = new ChoiceBuilder(masterModule.getModuleName(), 14, choiceQName,
+ SchemaPath.create(true, choiceQName));
+
+ BuilderUtils.fillAugmentTarget(augBuilder, choiceBuilder);
+
+ ChoiceCaseBuilder result = choiceBuilder.getCaseNodeByName(containerLocalName);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testFindUnknownNodeInDataNodeContainer() {
+ final String parentLocalName = "parent";
+ final QName containerQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), parentLocalName);
+ SchemaPath containerPath = SchemaPath.create(true, containerQName);
+
+ final ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 10,
+ containerQName, containerPath);
+
+ final String unknownLocalName = "unknown-ext-use";
+ final QName unknownNode = QName.create(masterModule.getNamespace(), masterModule.getRevision(), unknownLocalName);
+ SchemaPath unknownNodePath = SchemaPath.create(true, containerQName, unknownNode);
+ UnknownSchemaNodeBuilderImpl unknownNodeBuilder = new UnknownSchemaNodeBuilderImpl(masterModule.getModuleName(),
+ 22, unknownNode, unknownNodePath);
+ containerBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+ List<QName> path = new ArrayList<>(2);
+ path.add(unknownNode);
+
+ SchemaNodeBuilder result = BuilderUtils.findSchemaNode(path, containerBuilder);
+ assertNotNull(result);
+ assertEquals(unknownNodeBuilder, result);
+
+ path.add(QName.create(masterModule.getNamespace(), masterModule.getRevision(), "foo"));
+ assertNull(BuilderUtils.findSchemaNode(path, containerBuilder));
+
+ final QName choiceQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "select");
+ SchemaPath choicePath = SchemaPath.create(true, choiceQName);
+
+ final ChoiceBuilder choiceBuilder = new ChoiceBuilder(masterModule.getModuleName(), 33, choiceQName, choicePath);
+
+ final QName caseQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "simple-case");
+ SchemaPath casePath = SchemaPath.create(true, choiceQName, caseQName);
+
+ ChoiceCaseBuilder caseBuilder = new ChoiceCaseBuilder(masterModule.getModuleName(), 35, caseQName, casePath);
+ choiceBuilder.addCase(caseBuilder);
+
+ choiceBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+ path.clear();
+ path.add(caseQName);
+ result = BuilderUtils.findSchemaNode(path, choiceBuilder);
+ assertNotNull(result);
+ assertTrue(result instanceof ChoiceCaseBuilder);
+ assertEquals(caseBuilder, result);
+
+ path.clear();
+ path.add(unknownNode);
+ result = BuilderUtils.findSchemaNode(path, choiceBuilder);
+ assertNotNull(result);
+ assertEquals(unknownNodeBuilder, result);
+
+ path.add(QName.create(masterModule.getNamespace(), masterModule.getRevision(), "foo"));
+ result = BuilderUtils.findSchemaNode(path, choiceBuilder);
+ assertNull(result);
+
+ final QName rpcQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), parentLocalName);
+ SchemaPath rpcPath = SchemaPath.create(true, rpcQName);
+ final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(masterModule.getModuleName(), 45, rpcQName, rpcPath);
+
+ final QName inputQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "input");
+ final SchemaPath inputPath = SchemaPath.create(true, rpcQName, inputQName);
+
+ final QName outputQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "output");
+ final SchemaPath outputPath = SchemaPath.create(true, rpcQName, outputQName);
+
+ final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 46,
+ inputQName, inputPath);
+ final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 76,
+ outputQName, outputPath);
+
+ rpcBuilder.setInput(inputBuilder);
+ rpcBuilder.setOutput(outputBuilder);
+ rpcBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+ path.clear();
+ path.add(inputQName);
+ result = BuilderUtils.findSchemaNode(path, rpcBuilder);
+ assertNotNull(result);
+ assertEquals(inputBuilder, result);
+
+ path.clear();
+ path.add(outputQName);
+ result = BuilderUtils.findSchemaNode(path, rpcBuilder);
+ assertNotNull(result);
+ assertEquals(outputBuilder, result);
+
+ path.clear();
+ path.add(unknownNode);
+ result = BuilderUtils.findSchemaNode(path, rpcBuilder);
+ assertNotNull(result);
+ assertEquals(unknownNodeBuilder, result);
+
+ final QName leafQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "simple-leaf");
+ SchemaPath leafPath = SchemaPath.create(true, leafQName);
+
+ final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(masterModule.getModuleName(), 10, leafQName, leafPath);
+ leafBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+ path.clear();
+ path.add(unknownNode);
+ result = BuilderUtils.findSchemaNode(path, leafBuilder);
+ assertNotNull(result);
+ assertEquals(unknownNodeBuilder, result);
+ }
+
+ @Test
+ public void testFindUnknownSchemaNodeInModule() {
+ final String parentLocalName = "parent";
+ final QName containerQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), parentLocalName);
+ SchemaPath containerPath = SchemaPath.create(true, containerQName);
+
+ final ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 10,
+ containerQName, containerPath);
+
+ final String unknownLocalName = "unknown-ext-use";
+ final QName unknownNode = QName.create(masterModule.getNamespace(), masterModule.getRevision(), unknownLocalName);
+ final SchemaPath unknownNodePath = SchemaPath.create(true, containerQName, unknownNode);
+ UnknownSchemaNodeBuilderImpl unknownNodeBuilder = new UnknownSchemaNodeBuilderImpl(masterModule.getModuleName(),
+ 22, unknownNode, unknownNodePath);
+ containerBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+ masterModule.addChildNode(containerBuilder);
+
+ Optional<SchemaNodeBuilder> result = BuilderUtils.findSchemaNodeInModule(unknownNodePath, masterModule);
+
+ assertTrue(result.isPresent());
+ assertEquals(result.get(), unknownNodeBuilder);
+
+ final QName invalidUnknownNode = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "invalid-ext-use");
+ final SchemaPath invalidPath = SchemaPath.create(true, containerQName, invalidUnknownNode);
+
+ result = BuilderUtils.findSchemaNodeInModule(invalidPath, masterModule);
+ assertFalse(result.isPresent());
+ }
+
+ @Test
+ public void testFindContainerInRPC() {
+
+ final QName rpcQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "send-message");
+ SchemaPath rpcPath = SchemaPath.create(true, rpcQName);
+ final RpcDefinitionBuilder rpcBuilder = masterModule.addRpc(45, rpcQName, rpcPath);
+
+ final QName inputQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "input");
+ final SchemaPath inputPath = SchemaPath.create(true, rpcQName, inputQName);
+
+ final QName outputQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "output");
+ final SchemaPath outputPath = SchemaPath.create(true, rpcQName, outputQName);
+
+ Optional<SchemaNodeBuilder> requestResult = BuilderUtils.findSchemaNodeInModule(inputPath, masterModule);
+ assertTrue(requestResult.isPresent());
+
+ Optional<SchemaNodeBuilder> responseResult = BuilderUtils.findSchemaNodeInModule(outputPath, masterModule);
+ assertTrue(responseResult.isPresent());
+
+ final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 46,
+ inputQName, inputPath);
+ final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 76,
+ outputQName, outputPath);
+
+ final QName request = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "request");
+ final SchemaPath requestPath = SchemaPath.create(true, rpcQName, inputQName, request);
+
+ final QName response = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "response");
+ final SchemaPath responsePath = SchemaPath.create(true, rpcQName, outputQName, response);
+
+ final ContainerSchemaNodeBuilder requestBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 50,
+ request, requestPath);
+ final ContainerSchemaNodeBuilder responseBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 80,
+ response, responsePath);
+
+ inputBuilder.addChildNode(requestBuilder);
+ outputBuilder.addChildNode(responseBuilder);
+
+ rpcBuilder.setInput(inputBuilder);
+ rpcBuilder.setOutput(outputBuilder);
+
+ requestResult = BuilderUtils.findSchemaNodeInModule(requestPath, masterModule);
+ assertTrue(requestResult.isPresent());
+
+ responseResult = BuilderUtils.findSchemaNodeInModule(responsePath, masterModule);
+ assertTrue(responseResult.isPresent());
+
+ final SchemaPath invalidPath = SchemaPath.create(true, rpcQName, response);
+ Optional<SchemaNodeBuilder> invalidResult = BuilderUtils.findSchemaNodeInModule(invalidPath, masterModule);
+ assertFalse(invalidResult.isPresent());
+ }
+
+ @Test
+ public void testFindIdentity() {
+ assertNull(BuilderUtils.findIdentity(Collections.<IdentitySchemaNodeBuilder>emptySet(), "test-identity"));
+ }
+
+ @Test
+ public void testGetModuleByPrefix() {
+ assertEquals(BuilderUtils.getModuleByPrefix(masterModule, null), masterModule);
+ assertEquals(BuilderUtils.getModuleByPrefix(masterModule, ""), masterModule);
+ assertEquals(BuilderUtils.getModuleByPrefix(masterModule, masterModule.getPrefix()), masterModule);
+ }
+
+ @Test
+ public void testFindModule() {
+ final Map<URI, TreeMap<Date, ModuleBuilder>> modules = new HashMap<>(1);
+ final TreeMap<Date, ModuleBuilder> masterModuleMap = new TreeMap<>();
+ masterModuleMap.put(masterModule.getRevision(), masterModule);
+ modules.put(masterModule.getNamespace(), masterModuleMap);
+
+ assertNull(BuilderUtils.findModule(QName.create("test-urn:namespace", "2014-10-08", "impossible-module"), modules));
+
+ assertEquals(BuilderUtils.findModule(QName.create(masterModule.getNamespace(), null, masterModule.getName()), modules),
+ masterModule);
+ }
+
+ @Test
+ public void testFindBaseIdentity() {
+ assertNull(BuilderUtils.findBaseIdentity(masterModule, "prefix:ident", 27));
+
+ final QName identity = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "ident");
+ masterModule.addIdentity(identity, 22, SchemaPath.create(true, identity));
+
+ final IdentitySchemaNodeBuilder result = BuilderUtils
+ .findBaseIdentity(masterModule, masterModule.getPrefix() + ":ident", 22);
+ assertNotNull(result);
+ assertEquals(result.getQName(), identity);
+ }
+
+ @Test
+ public void testWrapChildNode() {
+ final QName leafQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "parent-leaf");
+ final SchemaPath leafPath = SchemaPath.create(true, leafQName);
+ final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(masterModule.getModuleName(),
+ 27, leafQName, leafPath);
+ leafListBuilder.setType(Uint16.getInstance());
+
+ final LeafListSchemaNode leafList = leafListBuilder.build();
+
+ DataSchemaNodeBuilder wrapedLeafList = BuilderUtils
+ .wrapChildNode(masterModule.getModuleName(), 72, leafList, leafPath, leafQName);
+
+ assertNotNull(wrapedLeafList);
+ assertEquals(wrapedLeafList.getQName(), leafList.getQName());
+ }
+
+ @Test(expected = YangParseException.class)
+ public void wrapChildNodeForUnknownNode() {
+ final QName qName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "name");
+ final SchemaPath path = SchemaPath.create(true, qName);
+
+ BuilderUtils
+ .wrapChildNode(masterModule.getModuleName(), 72, new NotExistingDataSchemaNodeImpl(), path, qName);
+ }
+
+ private static class NotExistingDataSchemaNodeImpl implements DataSchemaNode {
+
+ @Override public boolean isAugmenting() {
+ return false;
+ }
+
+ @Override public boolean isAddedByUses() {
+ return false;
+ }
+
+ @Override public boolean isConfiguration() {
+ return false;
+ }
+
+ @Override public ConstraintDefinition getConstraints() {
+ return null;
+ }
+
+ @Override public QName getQName() {
+ return null;
+ }
+
+ @Override public SchemaPath getPath() {
+ return null;
+ }
+
+ @Override public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ return null;
+ }
+
+ @Override public String getDescription() {
+ return null;
+ }
+
+ @Override public String getReference() {
+ return null;
+ }
+
+ @Override public Status getStatus() {
+ return null;
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.builder.impl;
+
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.util.ExtendedType;
+import org.opendaylight.yangtools.yang.model.util.IdentityrefType;
+import org.opendaylight.yangtools.yang.model.util.Uint16;
+import org.opendaylight.yangtools.yang.parser.builder.api.*;
+import org.opendaylight.yangtools.yang.parser.util.YangParseException;
+
+/**
+ * Test suite for increasing of test coverage of CopyUtils implementation.
+ *
+ * @see org.opendaylight.yangtools.yang.parser.builder.impl.CopyUtils
+ *
+ * @author Lukas Sedlak <lsedlak@cisco.com>
+ */
+public class CopyUtilsTest extends AbstractBuilderTest {
+
+ @Test(expected = YangParseException.class)
+ public void testCopyOfUnknownTypeOfDataSchemaNode() {
+ final String leafLocalName = "leaf-to-refine";
+ final QName leafName = QName.create(module.getNamespace(), module.getRevision(), leafLocalName);
+ final SchemaPath leafPath = SchemaPath.create(true, leafName);
+ final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(module.getModuleName(), 22, leafName, leafPath);
+
+ CopyUtils.copy(new InvalidDataSchemaNodeBuilder(), leafBuilder, false);
+ }
+
+ @Test
+ public void testCopyAnyxmlWithAnyxmlOriginalNodeAndUnknownNodes() {
+ final String parentAnyxmlLocalName = "original-anyxml";
+ final QName parentAnyxmlName = QName.create(module.getNamespace(), module.getRevision(), parentAnyxmlLocalName);
+ final SchemaPath parentAnyxmlPath = SchemaPath.create(true, parentAnyxmlName);
+ final AnyXmlBuilder parentAnyXmlBuilder = new AnyXmlBuilder(module.getModuleName(), 22, parentAnyxmlName, parentAnyxmlPath);
+
+ final String anyxmlLocalName = "anyxml";
+ final QName anyxmlName = QName.create(module.getNamespace(), module.getRevision(), anyxmlLocalName);
+ final SchemaPath anyxmlPath = SchemaPath.create(true, anyxmlName);
+ final AnyXmlBuilder anyXmlBuilder = new AnyXmlBuilder(module.getModuleName(), 22, anyxmlName, anyxmlPath);
+
+ anyXmlBuilder.setOriginal(parentAnyXmlBuilder);
+
+ final UnknownSchemaNodeBuilder unknownSchemaNodeBuilder = provideUnknownNodeBuilder(anyxmlName);
+ anyXmlBuilder.addUnknownNodeBuilder(unknownSchemaNodeBuilder);
+
+ final AnyXmlBuilder copy = (AnyXmlBuilder) CopyUtils.copy(anyXmlBuilder, anyXmlBuilder, false);
+ assertFalse(copy.getUnknownNodes().isEmpty());
+ assertNotNull(copy.getOriginal());
+ assertEquals(copy.getOriginal(), parentAnyXmlBuilder);
+ }
+
+ @Test
+ public void testCopyChoiceBuilderWithUnknownNodesAndAugmentation() {
+ final String originalChoiceLocalName = "original-choice-to-copy";
+ final ChoiceBuilder originalChoiceBuilder = provideChoiceBuilder(originalChoiceLocalName);
+
+ final String choiceLocalName = "choice-to-copy";
+ final ChoiceBuilder choiceBuilder = provideChoiceBuilder(choiceLocalName);
+ choiceBuilder.setOriginal(originalChoiceBuilder);
+
+ final UnknownSchemaNodeBuilder unknownSchemaNodeBuilder = provideUnknownNodeBuilder(choiceBuilder.getQName());
+ final SchemaPath augPath = SchemaPath.create(true, choiceBuilder.getQName());
+
+ final AugmentationSchemaBuilder augBuilder = new AugmentationSchemaBuilderImpl(module.getModuleName(), 22,
+ "/imaginary/path", augPath, 0);
+
+ final UsesNodeBuilder usesNodeBuilder = provideUsesNodeBuilder("test-grouping-use");
+ augBuilder.addUsesNode(usesNodeBuilder);
+ augBuilder.addUnknownNodeBuilder(unknownSchemaNodeBuilder);
+
+ choiceBuilder.addUnknownNodeBuilder(unknownSchemaNodeBuilder);
+ choiceBuilder.addAugmentation(augBuilder);
+
+ final ChoiceBuilder copy = (ChoiceBuilder)CopyUtils.copy(choiceBuilder, module, false);
+ List<AugmentationSchemaBuilder> augmentations = copy.getAugmentationBuilders();
+
+ assertFalse(copy.getUnknownNodes().isEmpty());
+
+ final UnknownSchemaNodeBuilder copyUnknownNode = copy.getUnknownNodes().get(0);
+ assertEquals(copyUnknownNode, unknownSchemaNodeBuilder);
+
+ assertFalse(augmentations.isEmpty());
+ final AugmentationSchemaBuilder copyAugBuilder = augmentations.get(0);
+
+ assertEquals(copyAugBuilder, augBuilder);
+ assertEquals(copyAugBuilder.getUnknownNodes().get(0), augBuilder.getUnknownNodes().get(0));
+ assertNotEquals(copyAugBuilder.getUsesNodeBuilders().get(0), augBuilder.getUsesNodeBuilders().get(0));
+ }
+
+ @Test
+ public void testCopyChoiceCaseBuilder() {
+ final String originalChoiceCaseLocalName = "original-choice-case";
+ final QName originalChoiceCaseQName = QName.create(module.getNamespace(), module.getRevision(),
+ originalChoiceCaseLocalName);
+ final SchemaPath originalChoiceCasePath = SchemaPath.create(true, originalChoiceCaseQName);
+ final ChoiceCaseBuilder originalChoiceCaseBuilder = new ChoiceCaseBuilder(module.getModuleName(), 10,
+ originalChoiceCaseQName, originalChoiceCasePath);
+
+ final String choiceCaseLocalName = "test-choice-case";
+ final QName choiceCaseQName = QName.create(module.getNamespace(), module.getRevision(), choiceCaseLocalName);
+ final SchemaPath choiceCasePath = SchemaPath.create(true, choiceCaseQName);
+ final ChoiceCaseBuilder choiceCaseBuilder = new ChoiceCaseBuilder(module.getModuleName(), 10, choiceCaseQName,
+ choiceCasePath);
+
+ choiceCaseBuilder.setOriginal(originalChoiceCaseBuilder);
+
+ final UsesNodeBuilder usesNodeBuilder = provideUsesNodeBuilder("test-grouping-use");
+
+ UnknownSchemaNodeBuilder unknownSchemaNodeBuilder = provideUnknownNodeBuilder(choiceCaseQName);
+
+ choiceCaseBuilder.addUsesNode(usesNodeBuilder);
+ choiceCaseBuilder.addUnknownNodeBuilder(unknownSchemaNodeBuilder);
+
+ ChoiceCaseBuilder copy = (ChoiceCaseBuilder) CopyUtils.copy(choiceCaseBuilder, module, true);
+
+ assertNotNull(copy);
+ assertEquals(copy.getUnknownNodes().get(0), choiceCaseBuilder.getUnknownNodes().get(0));
+ assertFalse(copy.getUsesNodeBuilders().isEmpty());
+ assertNotEquals(copy.getUsesNodeBuilders().get(0), choiceCaseBuilder.getUsesNodeBuilders().get(0));
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddGroupingIntoChoiceCaseBuilder() {
+ final String choiceCaseLocalName = "test-choice-case";
+ final QName choiceCaseQName = QName.create(module.getNamespace(), module.getRevision(), choiceCaseLocalName);
+ final SchemaPath choiceCasePath = SchemaPath.create(true, choiceCaseQName);
+ final ChoiceCaseBuilder choiceCaseBuilder = new ChoiceCaseBuilder(module.getModuleName(), 10, choiceCaseQName,
+ choiceCasePath);
+
+ final String groupLocalName = "test-group";
+ final QName testGroup = QName.create(module.getNamespace(), module.getRevision(), groupLocalName);
+ final SchemaPath groupPath = SchemaPath.create(true, choiceCaseQName, testGroup);
+ final GroupingBuilder grouping = module.addGrouping(12, testGroup, groupPath);
+ choiceCaseBuilder.addGrouping(grouping);
+ }
+
+ @Test
+ public void testCopyContainerSchemaNodeBuilder() {
+ final ContainerSchemaNodeBuilder containerBuilder = provideContainerBuilder("parent-container");
+
+ final String groupLocalName = "test-group";
+ final GroupingBuilder grouping = provideNestedGroupingDefinition(containerBuilder.getQName(), groupLocalName);
+
+ final String typedefLocalName = "test-type-definition";
+ final TypeDefinitionBuilder typedefBuilder = provideNestedTypedef(containerBuilder.getQName(), typedefLocalName);
+
+ final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder(containerBuilder.getQName());
+
+ containerBuilder.addGrouping(grouping);
+ containerBuilder.addTypedef(typedefBuilder);
+ containerBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+ final ContainerSchemaNodeBuilder copy = (ContainerSchemaNodeBuilder) CopyUtils.copy(containerBuilder, module, true);
+
+ assertNotNull(copy);
+
+ assertFalse(copy.getGroupingBuilders().isEmpty());
+ assertFalse(copy.getTypeDefinitionBuilders().isEmpty());
+ assertFalse(copy.getUnknownNodes().isEmpty());
+ }
+
+ private GroupingBuilder provideNestedGroupingDefinition(final QName parentName, final String groupLocalName) {
+ final QName testGroup = QName.create(module.getNamespace(), module.getRevision(), groupLocalName);
+ final SchemaPath groupPath = SchemaPath.create(true, parentName, testGroup);
+ final GroupingBuilder grouping = module.addGrouping(12, testGroup, groupPath);
+
+ return grouping;
+ }
+
+ private TypeDefinitionBuilder provideNestedTypedef(final QName parentName, final String typedefLocalName) {
+ final QName typedefQname = QName.create(module.getNamespace(), module.getRevision(), typedefLocalName);
+ final SchemaPath typedefPath = SchemaPath.create(true, parentName, typedefQname);
+ final TypeDefinitionBuilder typedefBuilder = new TypeDefinitionBuilderImpl(module.getModuleName(), 12,
+ typedefQname, typedefPath);
+ typedefBuilder.setType(Uint16.getInstance());
+
+ return typedefBuilder;
+ }
+
+ @Test
+ public void testCopyLeafSchemaNodeBuilder() {
+ final String leafLocalName = "original-leaf";
+ final QName leafName = QName.create(module.getNamespace(), module.getRevision(), leafLocalName);
+ final SchemaPath leafPath = SchemaPath.create(true, leafName);
+ final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(module.getModuleName(), 22, leafName, leafPath);
+ leafBuilder.setType(Uint16.getInstance());
+
+ final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder(leafName);
+ leafBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+ final LeafSchemaNodeBuilder copy = (LeafSchemaNodeBuilder)CopyUtils.copy(leafBuilder, module, true);
+
+ assertNotNull(copy);
+ assertFalse(leafBuilder.getUnknownNodes().isEmpty());
+ }
+
+ @Test
+ public void testCopyLeafListSchemaNodeBuilder() {
+ final String origLeafListLocalName = "original-list-to";
+ final QName origLeafListQName = QName.create(module.getNamespace(), module.getRevision(), origLeafListLocalName );
+ final SchemaPath origLeafListPath = SchemaPath.create(true, origLeafListQName);
+ final LeafListSchemaNodeBuilder origLeafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(),
+ 10, origLeafListQName, origLeafListPath);
+ origLeafListBuilder.setType(Uint16.getInstance());
+
+ final String leafListLocalName = "leaflist-copy";
+ final QName leafListQName = QName.create(module.getNamespace(), module.getRevision(), leafListLocalName);
+ final SchemaPath leafListPath = SchemaPath.create(true, leafListQName);
+ final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(),
+ 20, leafListQName, leafListPath);
+ leafListBuilder.setType(Uint16.getInstance());
+
+ leafListBuilder.setOriginal(origLeafListBuilder);
+ final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder(leafListQName);
+ leafListBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+ final LeafListSchemaNodeBuilder copy = (LeafListSchemaNodeBuilder)CopyUtils.copy(leafListBuilder, module, true);
+
+ assertNotNull(copy);
+ assertFalse(copy.getUnknownNodes().isEmpty());
+ assertNotNull(copy.getUnknownNodes().get(0));
+ }
+
+ @Test
+ public void testCopyListSchemaNodeBuilder() {
+ final String origListLocalName = "original-list";
+ final QName origListQName = QName.create(module.getNamespace(), module.getRevision(), origListLocalName);
+ final SchemaPath origListPath = SchemaPath.create(true, origListQName);
+ final ListSchemaNodeBuilder origListBuilder = new ListSchemaNodeBuilder(module.getModuleName(),
+ 10, origListQName, origListPath);
+
+ final String listLocalName = "copy-of-list";
+ final QName listQName = QName.create(module.getNamespace(), module.getRevision(), listLocalName);
+ final SchemaPath listPath = SchemaPath.create(true, listQName);
+ final ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder(module.getModuleName(),
+ 20, listQName, listPath);
+
+ listBuilder.setOriginal(origListBuilder);
+
+ final String groupLocalName = "test-group";
+ final GroupingBuilder grouping = provideNestedGroupingDefinition(listBuilder.getQName(), groupLocalName);
+ listBuilder.addGrouping(grouping);
+
+ final String typedefLocalName = "test-type-definition";
+ final TypeDefinitionBuilder typedefBuilder = provideNestedTypedef(listBuilder.getQName(), typedefLocalName);
+ listBuilder.addTypedef(typedefBuilder);
+
+ final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder(listBuilder.getQName());
+ listBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+ final UsesNodeBuilder usesNodeBuilder = provideUsesNodeBuilder("test-grouping-use");
+ listBuilder.addUsesNode(usesNodeBuilder);
+
+ final SchemaPath augPath = SchemaPath.create(true, listBuilder.getQName());
+ final AugmentationSchemaBuilder augBuilder = new AugmentationSchemaBuilderImpl(module.getModuleName(), 22,
+ "/imaginary/path", augPath, 0);
+ listBuilder.addAugmentation(augBuilder);
+
+ ListSchemaNodeBuilder copy = (ListSchemaNodeBuilder) CopyUtils.copy(listBuilder, module, true);
+ assertNotNull(copy);
+ assertFalse(copy.getGroupingBuilders().isEmpty());
+ assertFalse(copy.getTypeDefinitionBuilders().isEmpty());
+ assertFalse(copy.getUnknownNodes().isEmpty());
+ assertFalse(copy.getUsesNodeBuilders().isEmpty());
+ assertFalse(copy.getAugmentationBuilders().isEmpty());
+ }
+
+ @Test
+ public void testCopyGroupingBuilder() {
+ final String groupLocalName = "test-group";
+ final QName testGroup = QName.create(module.getNamespace(), module.getRevision(), groupLocalName);
+ final SchemaPath groupPath = SchemaPath.create(true, testGroup);
+ final GroupingBuilder grouping = module.addGrouping(12, testGroup, groupPath);
+
+ final String innerGroupLocalName = "inner-group";
+ final QName innerGroup = QName.create(module.getNamespace(), module.getRevision(), innerGroupLocalName);
+ final SchemaPath innerGroupPath = SchemaPath.create(true, testGroup, innerGroup);
+ final GroupingBuilder innerGrouping = module.addGrouping(12, innerGroup, innerGroupPath);
+
+ grouping.addGrouping(innerGrouping);
+
+ final String typedefLocalName = "test-type-definition";
+ final TypeDefinitionBuilder typedefBuilder = provideNestedTypedef(grouping.getQName(), typedefLocalName);
+ grouping.addTypedef(typedefBuilder);
+
+ final UsesNodeBuilder usesNodeBuilder = provideUsesNodeBuilder(innerGroupLocalName);
+ grouping.addUsesNode(usesNodeBuilder);
+
+ final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder(grouping.getQName());
+ grouping.addUnknownNodeBuilder(unknownNodeBuilder);
+
+ final GroupingBuilder copy = CopyUtils.copy(grouping, module, true);
+ assertNotNull(copy);
+ assertFalse(copy.getGroupingBuilders().isEmpty());
+ assertFalse(copy.getTypeDefinitionBuilders().isEmpty());
+ assertFalse(copy.getUsesNodeBuilders().isEmpty());
+ assertFalse(copy.getUnknownNodes().isEmpty());
+ }
+
+ @Ignore
+ @Test
+ public void testCopyIdentityrefTypeBuilder() {
+ final String typedefLocalName = "identity-ref-test-type";
+ final QName typedefQname = QName.create(module.getNamespace(), module.getRevision(), typedefLocalName);
+ final SchemaPath typedefPath = SchemaPath.create(true, typedefQname);
+ final IdentityrefTypeBuilder typeBuilder = new IdentityrefTypeBuilder(module.getModuleName(), 12,
+ "base:parent-identity", typedefPath);
+
+ //FIXME remove Ignore annotation once fix for bug 2219 will be resolved and merged
+ final TypeDefinitionBuilder copy = CopyUtils.copy(typeBuilder, module, true);
+ assertNotNull(copy);
+
+ //TODO: add additional asserts
+ }
+
+ @Ignore
+ @Test
+ public void testCopyTypeDefinitionBuilderWithUnknownNodes() {
+ final String typedefLocalName = "test-typedef-with-ext";
+ final QName typedefQname = QName.create(module.getNamespace(), module.getRevision(), typedefLocalName);
+ final SchemaPath typedefPath = SchemaPath.create(true, typedefQname);
+ final TypeDefinitionBuilder typedefBuilder = new TypeDefinitionBuilderImpl(module.getModuleName(), 12,
+ typedefQname, typedefPath);
+ typedefBuilder.setType(Uint16.getInstance());
+
+ typedefBuilder.addUnknownNodeBuilder(provideUnknownNodeBuilder());
+
+ TypeDefinitionBuilder copy = CopyUtils.copy(typedefBuilder, module, true);
+ //FIXME: remove @Ignore annotation once bug 2220 will be resolved and merged
+ assertNotNull(copy);
+ assertFalse(copy.getUnknownNodes().isEmpty());
+ }
+
+ private static final class InvalidDataSchemaNodeBuilder implements DataSchemaNodeBuilder {
+
+ @Override public SchemaNodeBuilder getOriginal() {
+ return null;
+ }
+
+ @Override public void setOriginal(SchemaNodeBuilder original) {
+
+ }
+
+ @Override public boolean isAugmenting() {
+ return false;
+ }
+
+ @Override public void setAugmenting(boolean augmenting) {
+
+ }
+
+ @Override public boolean isConfiguration() {
+ return false;
+ }
+
+ @Override public void setConfiguration(boolean config) {
+
+ }
+
+ @Override public ConstraintsBuilder getConstraints() {
+ return null;
+ }
+
+ @Override public QName getQName() {
+ return null;
+ }
+
+ @Override public SchemaPath getPath() {
+ return null;
+ }
+
+ @Override public void setPath(SchemaPath path) {
+
+ }
+
+ @Override public String getModuleName() {
+ return null;
+ }
+
+ @Override public void setModuleName(String moduleName) {
+
+ }
+
+ @Override public int getLine() {
+ return 0;
+ }
+
+ @Override public Builder getParent() {
+ return null;
+ }
+
+ @Override public void setParent(Builder parent) {
+
+ }
+
+ @Override public void addUnknownNodeBuilder(UnknownSchemaNodeBuilder unknownNode) {
+
+ }
+
+ @Override public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+ return null;
+ }
+
+ @Override public DataSchemaNode build() {
+ return null;
+ }
+
+ @Override public String getDescription() {
+ return null;
+ }
+
+ @Override public void setDescription(String description) {
+
+ }
+
+ @Override public String getReference() {
+ return null;
+ }
+
+ @Override public void setReference(String reference) {
+
+ }
+
+ @Override public Status getStatus() {
+ return null;
+ }
+
+ @Override public void setStatus(Status status) {
+
+ }
+
+ @Override public boolean isAddedByUses() {
+ return false;
+ }
+
+ @Override public void setAddedByUses(boolean addedByUses) {
+
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.builder.impl;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.util.Uint16;
+import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
+
+/**
+ * Test suite for increasing of test coverage of LeafListSchemaNodeBuilder implementation.
+ *
+ * @see org.opendaylight.yangtools.yang.parser.builder.impl.LeafListSchemaNodeBuilder
+ *
+ * @author Lukas Sedlak <lsedlak@cisco.com>
+ */
+public class LeafListSchemaNodeBuilderTest extends AbstractBuilderTest {
+
+ @Test
+ public void testLeafListSchemaNodeBuilderWithBaseLeafListSchemaNode() {
+ final String baseLeafListLocalName = "base-leaf-list";
+ final QName baseLeafListQName = QName.create(module.getNamespace(), module.getRevision(), baseLeafListLocalName);
+ final SchemaPath baseLeafListPath = SchemaPath.create(true, baseLeafListQName);
+ final LeafListSchemaNodeBuilder baseLeafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(),
+ 10, baseLeafListQName, baseLeafListPath);
+
+ final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder();
+
+ baseLeafListBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+ baseLeafListBuilder.setType(Uint16.getInstance());
+ final LeafListSchemaNode leafList = baseLeafListBuilder.build();
+
+ assertNotNull(leafList);
+ assertFalse(leafList.getUnknownSchemaNodes().isEmpty());
+ assertEquals(leafList.getUnknownSchemaNodes().size(), 1);
+
+ final String leafListLocalName = "extended-leaf-list";
+ final QName leafListQName = QName.create(module.getNamespace(), module.getRevision(), leafListLocalName);
+ final SchemaPath leafListPath = SchemaPath.create(true, leafListQName);
+ final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(),
+ 15, leafListQName, leafListPath, leafList);
+
+ final LeafListSchemaNode extendedLeafList = leafListBuilder.build();
+
+ assertNotNull(extendedLeafList);
+ assertFalse(extendedLeafList.getUnknownSchemaNodes().isEmpty());
+ assertEquals(extendedLeafList.getUnknownSchemaNodes().size(), 1);
+
+ assertNotEquals(leafList, extendedLeafList);
+
+ assertTrue(extendedLeafList instanceof DerivableSchemaNode);
+ assertTrue(((DerivableSchemaNode) extendedLeafList).getOriginal().isPresent());
+ assertEquals(leafList, ((DerivableSchemaNode) extendedLeafList).getOriginal().get());
+ }
+
+ @Test
+ public void testEquals() {
+ final String baseLeafListLocalName = "leaf-list1";
+ final QName baseLeafListQName = QName.create(module.getNamespace(), module.getRevision(), baseLeafListLocalName);
+ final SchemaPath baseLeafListPath = SchemaPath.create(true, baseLeafListQName);
+ final LeafListSchemaNodeBuilder baseLeafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(),
+ 10, baseLeafListQName, baseLeafListPath);
+
+ baseLeafListBuilder.setType(Uint16.getInstance());
+ final LeafListSchemaNode leafList = baseLeafListBuilder.build();
+
+ final String leafListLocalName = "leaf-list2";
+ final QName leafListQName2 = QName.create(module.getNamespace(), module.getRevision(), leafListLocalName);
+ final SchemaPath leafListPath2 = SchemaPath.create(true, leafListQName2);
+ final LeafListSchemaNodeBuilder leafListBuilder2 = new LeafListSchemaNodeBuilder(module.getModuleName(),
+ 10, leafListQName2, leafListPath2);
+
+ leafListBuilder2.setType(Uint16.getInstance());
+ final LeafListSchemaNode leafList2 = leafListBuilder2.build();
+
+ assertNotEquals(baseLeafListBuilder, null);
+ assertNotEquals(baseLeafListBuilder, leafListBuilder2);
+
+ assertNotEquals(leafList, null);
+ assertNotEquals(leafList, leafList2);
+
+ final QName containerQName = QName.create(module.getNamespace(), module.getRevision(), "parent-container");
+ final String leafListLocalName3 = "leaf-list2";
+ final QName leafListQName3 = QName.create(module.getNamespace(), module.getRevision(), leafListLocalName3);
+ final SchemaPath leafListPath3 = SchemaPath.create(true, containerQName, leafListQName3);
+ final LeafListSchemaNodeBuilder leafListBuilder3 = new LeafListSchemaNodeBuilder(module.getModuleName(),
+ 10, leafListQName3, leafListPath3);
+
+ baseLeafListBuilder.setType(Uint16.getInstance());
+ final LeafListSchemaNode leafList3 = baseLeafListBuilder.build();
+
+ assertNotEquals(leafListBuilder2, leafListBuilder3);
+ assertNotEquals(leafList3, leafList2);
+ }
+
+ @Test
+ public void testLeafListSchemaNodeImplProperties() {
+ final String descString = "my leaf list description";
+ final String leafListLocalName = "base-leaf-list";
+ final QName leafListQName = QName.create(module.getNamespace(), module.getRevision(), leafListLocalName);
+ final SchemaPath leafListPath = SchemaPath.create(true, leafListQName);
+ final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(),
+ 10, leafListQName, leafListPath);
+
+ leafListBuilder.setType(Uint16.getInstance());
+ leafListBuilder.setDescription(descString);
+ final LeafListSchemaNode leafList = leafListBuilder.build();
+
+ assertEquals(leafList.getQName(), leafListQName);
+ assertEquals(leafList.getDescription(), descString);
+ assertEquals(leafList.getStatus(), Status.CURRENT);
+ assertEquals(leafList.getPath(), leafListPath);
+ assertEquals(leafList.getType(), Uint16.getInstance());
+ assertNull(leafList.getReference());
+
+ assertEquals("LeafListSchemaNodeImpl[(urn:opendaylight.rpc:def:test-model?revision=2014-01-06)base-leaf-list]",
+ leafList.toString());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.builder.impl;
+
+import static org.junit.Assert.*;
+
+import java.net.URI;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.util.Uint16;
+import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
+import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.util.YangParseException;
+
+/**
+ * Test suite for increasing of test coverage of ModuleBuilder implementation.
+ *
+ * @see org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder
+ *
+ * @author Lukas Sedlak <lsedlak@cisco.com>
+ */
+public class ModuleBuilderTest {
+
+ private final static String TEST_MODULE_NAMESPACE = "urn:opendaylight.foo";
+ private final static String TEST_MODULE_REVISION = "2014-09-22";
+ private final static String MODULE_NAME = "TestModule";
+ private static final String TEST_MODULE_PATH = "/test/module/path";
+
+ private ModuleBuilder moduleBuilder;
+
+ @Before
+ public void setUp() throws Exception {
+ moduleBuilder = new ModuleBuilder(MODULE_NAME , TEST_MODULE_PATH);
+ }
+
+ @Test
+ public void testGetSetModuleBuilderMethods() throws Exception {
+ assertEquals("module", moduleBuilder.getStatementName());
+ assertEquals(TEST_MODULE_PATH, moduleBuilder.getModuleSourcePath());
+ assertNotNull(moduleBuilder.getAllLists());
+ final URI namespace = URI.create(TEST_MODULE_NAMESPACE + "?" + TEST_MODULE_REVISION);
+ moduleBuilder.setNamespace(namespace);
+ assertEquals(namespace, moduleBuilder.getNamespace());
+ moduleBuilder.setBelongsTo("TEST_SUBMODULE");
+ assertEquals("TEST_SUBMODULE", moduleBuilder.getBelongsTo());
+ final Date revision = new SimpleDateFormat("yyyy-dd-mm").parse(TEST_MODULE_REVISION);
+ moduleBuilder.setRevision(revision);
+ assertEquals(revision, moduleBuilder.getRevision());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testCheckPrefixFailOnPrefixNull() {
+ moduleBuilder.addModuleImport("TEST_MODULE", null, null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testCheckPrefixFailOnPrefixStringIsEmpty() {
+ moduleBuilder.addModuleImport("TEST_MODULE", null, "");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testCheckPrefixFailOnPrefixEqualsModuleBuilderPrefix() {
+ moduleBuilder.setPrefix("prefix");
+ moduleBuilder.addModuleImport("TEST_MODULE", null, "prefix");
+ }
+
+ @Test
+ public void testGetActualNodeNullResult() {
+ moduleBuilder.exitNode();
+ assertNull(moduleBuilder.getActualNode());
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testSetParent() throws Exception {
+ moduleBuilder.setParent(new Builder() {
+ @Override public String getModuleName() {
+ return null;
+ }
+
+ @Override public void setModuleName(String moduleName) {
+
+ }
+
+ @Override public int getLine() {
+ return 0;
+ }
+
+ @Override public Builder getParent() {
+ return null;
+ }
+
+ @Override public void setParent(Builder parent) {
+
+ }
+
+ @Override public void addUnknownNodeBuilder(UnknownSchemaNodeBuilder unknownNode) {
+
+ }
+
+ @Override public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+ return null;
+ }
+
+ @Override public Object build() {
+ return null;
+ }
+ });
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddExtensionWhereParentNodeIsNotModuleBuilder() throws Exception {
+ final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+ SchemaPath containerPath = SchemaPath.create(true, containerQName);
+ moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+ final QName extQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-ext");
+ SchemaPath extPath = SchemaPath.create(true, containerQName, extQName);
+ moduleBuilder.addExtension(extQName, 12, extPath);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddExtensionWhereNameOfExtensionCollides() throws Exception {
+ final QName extQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-ext");
+ SchemaPath extPath = SchemaPath.create(true, extQName);
+ moduleBuilder.addExtension(extQName, 12, extPath);
+
+ final QName extQName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-ext");
+ moduleBuilder.addExtension(extQName2, 22, extPath);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddDuplicateGroupingIntoModule() {
+ final QName testGroup1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group");
+ final SchemaPath groupPath1 = SchemaPath.create(true, testGroup1);
+
+ final QName testGroup2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group");
+ final SchemaPath groupPath2 = SchemaPath.create(true, testGroup2);
+
+ moduleBuilder.addGrouping(12, testGroup1, groupPath1);
+ moduleBuilder.addGrouping(12, testGroup2, groupPath2);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddDuplicateGroupingIntoDataNodeContainer() {
+ final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+ SchemaPath containerPath = SchemaPath.create(true, containerQName);
+ moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+ final QName testGroup1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group");
+ final SchemaPath groupPath1 = SchemaPath.create(true, containerQName, testGroup1);
+
+ final QName testGroup2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group");
+ final SchemaPath groupPath2 = SchemaPath.create(true, containerQName, testGroup2);
+
+ moduleBuilder.addGrouping(12, testGroup1, groupPath1);
+ moduleBuilder.addGrouping(22, testGroup2, groupPath2);
+ }
+
+ @Test
+ public void testAddTwoGroupingIntoDataNodeContainer() {
+ final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+ SchemaPath containerPath = SchemaPath.create(true, containerQName);
+ moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+ final QName testGroup1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group");
+ final SchemaPath groupPath1 = SchemaPath.create(true, containerQName, testGroup1);
+
+ final QName testGroup2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group2");
+ final SchemaPath groupPath2 = SchemaPath.create(true, containerQName, testGroup2);
+
+ GroupingBuilder grouping1 = moduleBuilder.addGrouping(12, testGroup1, groupPath1);
+ GroupingBuilder grouping2 = moduleBuilder.addGrouping(22, testGroup2, groupPath2);
+
+ assertNotNull(grouping1);
+ assertNotNull(grouping2);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddDuplicateGroupingIntoRpcDefinition() {
+ final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition");
+ SchemaPath rpcPath = SchemaPath.create(true, rpcDefName);
+ moduleBuilder.enterNode(new RpcDefinitionBuilder(MODULE_NAME, 10, rpcDefName, rpcPath));
+ final QName testGroup1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group");
+ final SchemaPath groupPath1 = SchemaPath.create(true, rpcDefName, testGroup1);
+
+ final QName testGroup2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group");
+ final SchemaPath groupPath2 = SchemaPath.create(true, rpcDefName, testGroup2);
+
+ moduleBuilder.addGrouping(12, testGroup1, groupPath1);
+ moduleBuilder.addGrouping(22, testGroup2, groupPath2);
+ }
+
+ @Test
+ public void testAddTwoGroupingsIntoRpcDefinition() {
+ final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition");
+ SchemaPath rpcPath = SchemaPath.create(true, rpcDefName);
+ moduleBuilder.enterNode(new RpcDefinitionBuilder(MODULE_NAME, 10, rpcDefName, rpcPath));
+ final QName testGroup1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group");
+ final SchemaPath groupPath1 = SchemaPath.create(true, rpcDefName, testGroup1);
+
+ final QName testGroup2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group2");
+ final SchemaPath groupPath2 = SchemaPath.create(true, rpcDefName, testGroup2);
+
+ GroupingBuilder grouping1 = moduleBuilder.addGrouping(12, testGroup1, groupPath1);
+ GroupingBuilder grouping2 = moduleBuilder.addGrouping(22, testGroup2, groupPath2);
+
+ assertNotNull(grouping1);
+ assertNotNull(grouping2);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddGroupingIntoNonValidStatementDefinition() {
+ final QName leafListDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-leaflist");
+ SchemaPath leaflistPath = SchemaPath.create(true, leafListDefName);
+ moduleBuilder.enterNode(new LeafListSchemaNodeBuilder(MODULE_NAME, 10, leafListDefName, leaflistPath));
+ final QName testGroup = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group");
+ final SchemaPath groupPath = SchemaPath.create(true, leafListDefName, testGroup);
+
+ moduleBuilder.addGrouping(12, testGroup, groupPath);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testInvalidAugmentPathTargetString() {
+ final QName targetSchemaName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "fictive-target-container");
+ moduleBuilder.addAugment(12, "something/something", SchemaPath.create(true, targetSchemaName), 0);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testInvalidAugmentPathTargetStringInUsesNode() {
+ final QName usesNode = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "fictive-uses-node");
+ SchemaPath targetPath = SchemaPath.create(true, usesNode);
+ moduleBuilder.enterNode(new UsesNodeBuilderImpl(MODULE_NAME, 10, targetPath));
+ final QName targetSchemaName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "fictive-target-container");
+ moduleBuilder.addAugment(12, "/something/something", SchemaPath.create(true, targetSchemaName), 0);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testInvalidAugmentDefinition() {
+ final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+ SchemaPath containerPath = SchemaPath.create(true, containerQName);
+ moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+ final QName targetSchemaName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "fictive-target-container");
+ moduleBuilder.addAugment(12, "/something/something", SchemaPath.create(true, targetSchemaName), 0);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testInvalidUsesNodeUse() {
+ final QName leafListDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-leaflist");
+ SchemaPath leaflistPath = SchemaPath.create(true, leafListDefName);
+ moduleBuilder.enterNode(new LeafListSchemaNodeBuilder(MODULE_NAME, 10, leafListDefName, leaflistPath));
+
+ final QName testGroup = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group");
+ final SchemaPath groupPath = SchemaPath.create(true, testGroup);
+
+ moduleBuilder.addUsesNode(17, groupPath);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddRefineToNonUsesNodeBuilder() throws Exception {
+ final QName leafListDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-leaflist");
+ SchemaPath leaflistPath = SchemaPath.create(true, leafListDefName);
+ moduleBuilder.enterNode(new LeafListSchemaNodeBuilder(MODULE_NAME, 10, leafListDefName, leaflistPath));
+
+ moduleBuilder.addRefine(new RefineHolderImpl(MODULE_NAME, 12, "testRefineName"));
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddRpcToNonModuleBuilder() throws Exception {
+ final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+ SchemaPath containerPath = SchemaPath.create(true, containerQName);
+ moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+ final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition");
+ SchemaPath rpcPath = SchemaPath.create(true, rpcDefName);
+
+ moduleBuilder.addRpc(17, rpcDefName, rpcPath);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddRpcWithSameNameAsAlreadyExistingDataNodeContainer() throws Exception {
+ final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "element-foo");
+ SchemaPath containerPath = SchemaPath.create(true, containerQName);
+ moduleBuilder.addContainerNode(10, containerQName, containerPath);
+
+ final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "element-foo");
+ SchemaPath rpcPath = SchemaPath.create(true, rpcDefName);
+ moduleBuilder.addRpc(17, rpcDefName, rpcPath);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddDuplicateRpc() throws Exception {
+ final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition");
+ SchemaPath rpcPath = SchemaPath.create(true, rpcDefName);
+ moduleBuilder.addRpc(17, rpcDefName, rpcPath);
+
+ final QName rpcDefName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition");
+ SchemaPath rpcPath2 = SchemaPath.create(true, rpcDefName2);
+ moduleBuilder.addRpc(23, rpcDefName2, rpcPath2);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddRpcWithSameNameAsAlreadyDefinedNotification() throws Exception {
+ final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition");
+ SchemaPath rpcPath = SchemaPath.create(true, rpcDefName);
+ moduleBuilder.addNotification(17, rpcDefName, rpcPath);
+
+ final QName rpcDefName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition");
+ SchemaPath rpcPath2 = SchemaPath.create(true, rpcDefName2);
+ moduleBuilder.addRpc(23, rpcDefName2, rpcPath2);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddRpcInputForInvalidParent() throws Exception {
+ final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition");
+ final QName rpcInput = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "input");
+ SchemaPath rpcInputPath = SchemaPath.create(true, rpcDefName, rpcInput);
+
+ moduleBuilder.addRpcInput(23, rpcInput, rpcInputPath);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddRpcOutputForInvalidParent() throws Exception {
+ final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition");
+ final QName rpcOutput = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "output");
+ SchemaPath rpcOutputPath = SchemaPath.create(true, rpcDefName, rpcOutput);
+
+ moduleBuilder.addRpcOutput(rpcOutputPath, rpcOutput, 23);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddNotificationForInvalidParent() throws Exception {
+ final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+ SchemaPath containerPath = SchemaPath.create(true, containerQName);
+ moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+ final QName notificationName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify-this");
+ SchemaPath notificationPath = SchemaPath.create(true, notificationName);
+
+ moduleBuilder.addNotification(12, notificationName, notificationPath);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddNotificationWithSameNameAsAlreadyExistingDataNodeContainer() throws Exception {
+ final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify");
+ SchemaPath containerPath = SchemaPath.create(true, containerQName);
+ moduleBuilder.addContainerNode(10, containerQName, containerPath);
+
+ final QName notificationName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify");
+ SchemaPath notificationPath = SchemaPath.create(true, notificationName);
+
+ moduleBuilder.addNotification(12, notificationName, notificationPath);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddDuplicateNotification() throws Exception {
+ final QName notificationName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify-this");
+ SchemaPath notificationPath = SchemaPath.create(true, notificationName);
+
+ moduleBuilder.addNotification(12, notificationName, notificationPath);
+
+ final QName notificationName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify-this");
+ SchemaPath notificationPath2 = SchemaPath.create(true, notificationName2);
+
+ moduleBuilder.addNotification(17, notificationName2, notificationPath2);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddNotificationWithSameNameAsAlreadyDefinedRpc() throws Exception {
+ final QName rpcDefName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify-this");
+ SchemaPath rpcPath2 = SchemaPath.create(true, rpcDefName2);
+ moduleBuilder.addRpc(17, rpcDefName2, rpcPath2);
+
+ final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify-this");
+ SchemaPath rpcPath = SchemaPath.create(true, rpcDefName);
+ moduleBuilder.addNotification(23, rpcDefName, rpcPath);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddFeatureIntoNonModuleBuilder() throws Exception {
+ final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+ SchemaPath containerPath = SchemaPath.create(true, containerQName);
+ moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+ final QName testFeature = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-feature");
+ SchemaPath featurePath = SchemaPath.create(true, testFeature);
+
+ moduleBuilder.addFeature(23, testFeature, featurePath);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddDuplicateFeature() throws Exception {
+ final QName testFeature = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-feature");
+ SchemaPath featurePath = SchemaPath.create(true, testFeature);
+
+ moduleBuilder.addFeature(23, testFeature, featurePath);
+
+ final QName testFeature2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-feature");
+ SchemaPath featurePath2 = SchemaPath.create(true, testFeature2);
+
+ moduleBuilder.addFeature(23, testFeature2, featurePath2);
+ }
+
+ @Test
+ public void testAddTwoFeatures() throws Exception {
+ final QName testFeature = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-feature");
+ SchemaPath featurePath = SchemaPath.create(true, testFeature);
+
+ final FeatureBuilder feature1 = moduleBuilder.addFeature(23, testFeature, featurePath);
+
+ final QName testFeature2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-feature2");
+ SchemaPath featurePath2 = SchemaPath.create(true, testFeature2);
+
+ final FeatureBuilder feature2 = moduleBuilder.addFeature(23, testFeature2, featurePath2);
+
+ assertNotNull(feature1);
+ assertNotNull(feature2);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddCaseWhenParentIsNull() throws Exception {
+ moduleBuilder.exitNode();
+ addTestCase();
+ }
+
+ private void addTestCase() {
+ final QName testCase = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-case");
+ SchemaPath testCasePath = SchemaPath.create(true, testCase);
+
+ moduleBuilder.addCase(72, testCase, testCasePath);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddCaseWhenParentIsModule() throws Exception {
+ addTestCase();
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddCaseWhenParentIsNotChoiceNorAugmentation() throws Exception {
+ final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+ SchemaPath containerPath = SchemaPath.create(true, containerQName);
+ moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+ addTestCase();
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddDuplicateTypedefIntoContainer() throws Exception {
+ final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+ SchemaPath containerPath = SchemaPath.create(true, containerQName);
+ moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+ tryToAddDuplicateTypedef();
+ }
+
+ private void tryToAddDuplicateTypedef() {
+ final QName testTypedef1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-type-definition");
+ SchemaPath testTypedefPath1 = SchemaPath.create(true, testTypedef1);
+
+ final QName testTypedef2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-type-definition");
+ SchemaPath testTypedefPath2 = SchemaPath.create(true, testTypedef2);
+
+ moduleBuilder.addTypedef(23, testTypedef1, testTypedefPath1);
+ moduleBuilder.addTypedef(44, testTypedef2, testTypedefPath2);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddDuplicateTypedefIntoRpcDefinition() throws Exception {
+ final QName rpcQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-rpc");
+ SchemaPath rpcPath = SchemaPath.create(true, rpcQName);
+ moduleBuilder.enterNode(new RpcDefinitionBuilder(MODULE_NAME, 10, rpcQName, rpcPath));
+
+ tryToAddDuplicateTypedef();
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddTypedefIntoNonValidStatement() throws Exception {
+ final QName leafName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-leaf");
+ SchemaPath leafPath = SchemaPath.create(true, leafName);
+ moduleBuilder.enterNode(new LeafSchemaNodeBuilder(MODULE_NAME, 10, leafName, leafPath));
+
+ final QName testRpc = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-type-definition");
+ SchemaPath testRpcPath = SchemaPath.create(true, testRpc);
+
+ moduleBuilder.addTypedef(23, testRpc, testRpcPath);
+ }
+
+ @Test
+ public void testAddTwoTypedefsIntoContainer() throws Exception {
+ final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+ SchemaPath containerPath = SchemaPath.create(true, containerQName);
+ moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+ tryToAddTwoTypedefs();
+ }
+
+ private void tryToAddTwoTypedefs() {
+ final QName testTypedef1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-type-definition");
+ SchemaPath testTypedefPath1 = SchemaPath.create(true, testTypedef1);
+
+ final QName testTypedef2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-type-definition2");
+ SchemaPath testTypedefPath2 = SchemaPath.create(true, testTypedef2);
+
+ final TypeDefinitionBuilderImpl typedef1 = moduleBuilder.addTypedef(23, testTypedef1, testTypedefPath1);
+ final TypeDefinitionBuilderImpl typedef2 = moduleBuilder.addTypedef(44, testTypedef2, testTypedefPath2);
+
+ assertNotNull(typedef1);
+ assertNotNull(typedef2);
+ }
+
+ @Test
+ public void testAddTwoTypedefsIntoRpcDefinition() throws Exception {
+ final QName rpcQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-rpc");
+ SchemaPath rpcPath = SchemaPath.create(true, rpcQName);
+ moduleBuilder.enterNode(new RpcDefinitionBuilder(MODULE_NAME, 10, rpcQName, rpcPath));
+
+ tryToAddTwoTypedefs();
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testSetType() throws Exception {
+ final Uint16 uint = Uint16.getInstance();
+ moduleBuilder.setType(uint);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddUnionTypeWhenParentIsNull() throws Exception {
+ moduleBuilder.exitNode();
+
+ tryToAddUnionType();
+ }
+
+ private void tryToAddUnionType() {
+ final QName unionQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "union-type-def");
+ moduleBuilder.addUnionType(25, QNameModule.create(unionQName.getNamespace(), unionQName.getRevision()));
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddUnionTypeWhenParentIsNotTypeAwareBuilder() throws Exception {
+ final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+ SchemaPath containerPath = SchemaPath.create(true, containerQName);
+ moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+ tryToAddUnionType();
+ }
+
+ @Test(expected = YangParseException.class)
+ public void addIdentityrefTypeWhenParentIsNull() throws Exception {
+ moduleBuilder.exitNode();
+ tryToAddIdentityrefType();
+ }
+
+ private void tryToAddIdentityrefType() {
+ final QName identityrefQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "identityref-type-def");
+ SchemaPath identityrefPath = SchemaPath.create(true, identityrefQName);
+ moduleBuilder.addIdentityrefType(25, identityrefPath, "simplebase");
+ }
+
+ @Test(expected = YangParseException.class)
+ public void addIdentityrefTypeWhenParentIsNotTypeAwareBuilder() throws Exception {
+ final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+ SchemaPath containerPath = SchemaPath.create(true, containerQName);
+ moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+ tryToAddIdentityrefType();
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddDeviationWhereParentIsNotModule() throws Exception {
+ final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+ SchemaPath containerPath = SchemaPath.create(true, containerQName);
+ moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+ final QName deviationQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-deviation-name");
+ SchemaPath deviationPath = SchemaPath.create(true, deviationQName);
+
+ moduleBuilder.addDeviation(78, deviationPath);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddIdentityWhereParentIsNotModule() throws Exception {
+ final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+ SchemaPath containerPath = SchemaPath.create(true, containerQName);
+ moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+ tryToAddIdentity();
+ }
+
+ private void tryToAddIdentity() {
+ final QName identityQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-identity-name");
+ SchemaPath identityPath = SchemaPath.create(true, identityQName);
+
+ moduleBuilder.addIdentity(identityQName, 78, identityPath);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddDuplicateIdentity() throws Exception {
+ tryToAddIdentity();
+ tryToAddIdentity();
+ }
+
+ @Test
+ public void testAddUnknownSchemaNodeDirectlyToParent() throws Exception {
+ final QName unknownQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "my-extension-use");
+ SchemaPath unknownPath = SchemaPath.create(true, unknownQName);
+ assertTrue(moduleBuilder.getUnknownNodes().isEmpty());
+ moduleBuilder.addUnknownSchemaNode(72, unknownQName, unknownPath);
+ assertFalse(moduleBuilder.getUnknownNodes().isEmpty());
+ }
+
+ @Test
+ public void testAddUnknownSchemaNodeIntoDataNodeContainer() throws Exception {
+ final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+ SchemaPath containerPath = SchemaPath.create(true, containerQName);
+ moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+ final QName unknownQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "my-extension-use");
+ SchemaPath unknownPath = SchemaPath.create(true, unknownQName);
+ assertTrue(moduleBuilder.getAllUnknownNodes().isEmpty());
+ moduleBuilder.addUnknownSchemaNode(72, unknownQName, unknownPath);
+ assertFalse(moduleBuilder.getAllUnknownNodes().isEmpty());
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddUnknownSchemaNodeIntoNonSchemaNode() throws Exception {
+ final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-non-schema-node");
+ SchemaPath containerPath = SchemaPath.create(true, containerQName);
+ moduleBuilder.enterNode(new NonSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+ final QName unknownQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "my-extension-use");
+ SchemaPath unknownPath = SchemaPath.create(true, unknownQName);
+ assertTrue(moduleBuilder.getUnknownNodes().isEmpty());
+ moduleBuilder.addUnknownSchemaNode(72, unknownQName, unknownPath);
+ assertFalse(moduleBuilder.getUnknownNodes().isEmpty());
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddContainerWithSameNameAsRpcDefintion() throws Exception {
+ final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "message");
+ SchemaPath rpcPath = SchemaPath.create(true, rpcDefName);
+ moduleBuilder.addRpc(70, rpcDefName, rpcPath);
+ tryToAddContainer();
+ }
+
+ private void tryToAddContainer() {
+ final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "message");
+ final SchemaPath containerPath = SchemaPath.create(true, containerQName);
+
+ moduleBuilder.addContainerNode(22, containerQName, containerPath);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddContainerWithSameNameAsNotificationDefintion() throws Exception {
+ final QName notificationName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "message");
+ SchemaPath notificationPath = SchemaPath.create(true, notificationName);
+ moduleBuilder.addNotification(70, notificationName, notificationPath);
+ tryToAddContainer();
+ }
+
+ @Test
+ public void testAddContainerWithAlreadyAddedRpcDefintion() throws Exception {
+ final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "send-message");
+ SchemaPath rpcPath = SchemaPath.create(true, rpcDefName);
+ moduleBuilder.addRpc(70, rpcDefName, rpcPath);
+ tryToAddContainer();
+
+ DataSchemaNodeBuilder addedContainer = moduleBuilder.getDataChildByName("message");
+ assertNotNull(addedContainer);
+ }
+
+ @Test
+ public void testAddContainerWithAlreadyAddedNotificationDefintion() throws Exception {
+ final QName notificationName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify-me");
+ SchemaPath notificationPath = SchemaPath.create(true, notificationName);
+ moduleBuilder.addNotification(70, notificationName, notificationPath);
+ tryToAddContainer();
+
+ DataSchemaNodeBuilder addedContainer = moduleBuilder.getDataChildByName("message");
+ assertNotNull(addedContainer);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddDuplicateSchemaNodeIntoSubnodeOfModule() throws Exception {
+ final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+ SchemaPath containerPath = SchemaPath.create(true, containerQName);
+ moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+ final QName leafQName1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-leaf");
+ SchemaPath leafPath1 = SchemaPath.create(true, containerQName, leafQName1);
+
+ final QName leafQName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-leaf");
+ SchemaPath leafPath2 = SchemaPath.create(true, containerQName, leafQName2);
+
+ moduleBuilder.addLeafNode(12, leafQName1, leafPath1);
+ moduleBuilder.addLeafNode(20, leafQName2, leafPath2);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddDuplicateCaseIntoChoiceCaseNode() throws Exception {
+ //FIXME: move this into ChoiceBuilderTest !!!
+ final QName choiceQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+ SchemaPath choicePath = SchemaPath.create(true, choiceQName);
+
+ moduleBuilder.enterNode(new ChoiceBuilder(MODULE_NAME, 10, choiceQName, choicePath));
+
+ final QName caseQName1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-case");
+ SchemaPath casePath1 = SchemaPath.create(true, choiceQName, caseQName1);
+
+ final QName caseQName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-case");
+ SchemaPath casePath2 = SchemaPath.create(true, choiceQName, caseQName2);
+
+ moduleBuilder.addCase(12, caseQName1, casePath1);
+ moduleBuilder.addCase(20, caseQName2, casePath2);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddChoiceWithSameNameAsCase() throws Exception {
+ final QName choiceQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "my-choice");
+ SchemaPath choicePath = SchemaPath.create(true, choiceQName);
+
+ final ChoiceBuilder choiceBuilder = moduleBuilder.addChoice(8, choiceQName, choicePath);
+ moduleBuilder.enterNode(choiceBuilder);
+
+ final QName caseQName1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-case");
+ SchemaPath casePath1 = SchemaPath.create(true, choiceQName, caseQName1);
+
+ final QName caseQName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-case");
+ SchemaPath casePath2 = SchemaPath.create(true, choiceQName, caseQName2);
+
+ moduleBuilder.addCase(12, caseQName1, casePath1);
+ moduleBuilder.addChoice(20, caseQName2, casePath2);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testAddChildToSubnodeForNonDataNodeContainerAndNonChoiceNode() {
+ final QName leafQName1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-leaf");
+ SchemaPath leafPath1 = SchemaPath.create(true, leafQName1);
+
+ final LeafSchemaNodeBuilder leafBuilder = moduleBuilder.addLeafNode(10, leafQName1, leafPath1);
+ moduleBuilder.enterNode(leafBuilder);
+
+ final QName leafQName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-leaf");
+ SchemaPath leafPath2 = SchemaPath.create(true, leafQName1, leafQName2);
+
+ moduleBuilder.addLeafNode(12, leafQName2, leafPath2);
+ }
+
+ private static class NonSchemaNodeBuilder implements Builder {
+
+ String moduleName;
+ final int line;
+ final QName name;
+ final SchemaPath path;
+
+ public NonSchemaNodeBuilder(final String moduleName, final int line, final QName name, final SchemaPath path) {
+ this.moduleName = moduleName;
+ this.line = line;
+ this.name = name;
+ this.path = path;
+ }
+
+ @Override public String getModuleName() {
+ return moduleName;
+ }
+
+ @Override public void setModuleName(String moduleName) {
+ this.moduleName = moduleName;
+ }
+
+ @Override public int getLine() {
+ return line;
+ }
+
+ @Override public Builder getParent() {
+ return null;
+ }
+
+ @Override public void setParent(Builder parent) {
+
+ }
+
+ @Override public void addUnknownNodeBuilder(UnknownSchemaNodeBuilder unknownNode) {
+
+ }
+
+ @Override public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+ return null;
+ }
+
+ @Override public Object build() {
+ return null;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.builder.impl;
+
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+import com.google.common.base.Optional;
+import java.net.URI;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.MustDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.util.MustDefinitionImpl;
+import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.util.YangParseException;
+
+/**
+ * Test suite for increasing of test coverage of RefineUtils implementation.
+ *
+ * @see org.opendaylight.yangtools.yang.parser.builder.impl.RefineUtils
+ *
+ * @author Lukas Sedlak <lsedlak@cisco.com>
+ */
+public class RefineUtilsTest extends AbstractBuilderTest {
+
+ @Test
+ public void testRefineLeafWithEmptyDefaultString() {
+ final String leafLocalName = "leaf-to-refine";
+ final QName leafName = QName.create(module.getNamespace(), module.getRevision(), leafLocalName);
+ final SchemaPath leafPath = SchemaPath.create(true, leafName);
+ final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(module.getModuleName(), 22, leafName, leafPath);
+
+ final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+leafLocalName);
+ refineBuilder.setDefaultStr("");
+
+ RefineUtils.performRefine(leafBuilder, refineBuilder);
+ assertNull(leafBuilder.getDefaultStr());
+ }
+
+ @Test
+ public void testRefineContainer() {
+ final String containerLocalName = "container-to-refine";
+ final QName containerName = QName.create(module.getNamespace(), module.getRevision(), containerLocalName);
+ final SchemaPath containerPath = SchemaPath.create(true, containerName);
+ final ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder(module.getModuleName(),
+ 10, containerName, containerPath);
+
+ final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+containerLocalName);
+ refineBuilder.setPresence(null);
+
+ final MustDefinition must = provideMustDefinition();
+ refineBuilder.setMust(must);
+
+ final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder();
+ refineBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+ RefineUtils.performRefine(containerBuilder, refineBuilder);
+
+ assertFalse(containerBuilder.getConstraints().getMustDefinitions().isEmpty());
+ assertEquals(containerBuilder.getConstraints().getMustDefinitions().size(), 1);
+ assertFalse(containerBuilder.getUnknownNodes().isEmpty());
+ assertEquals(containerBuilder.getUnknownNodes().get(0), unknownNodeBuilder);
+ }
+
+
+
+ @Test
+ public void testRefineList() {
+ final String listLocalName = "list-to-refine";
+ final QName listQName = QName.create(module.getNamespace(), module.getRevision(), listLocalName);
+ final SchemaPath listPath = SchemaPath.create(true, listQName);
+ final ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder(module.getModuleName(),
+ 10, listQName, listPath);
+
+ final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+listLocalName);
+
+ final MustDefinition must = provideMustDefinition();
+ refineBuilder.setMust(must);
+
+ final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder();
+ refineBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+ refineBuilder.setMinElements(null);
+ refineBuilder.setMaxElements(null);
+
+ RefineUtils.performRefine(listBuilder, refineBuilder);
+ assertFalse(listBuilder.getConstraints().getMustDefinitions().isEmpty());
+ assertEquals(listBuilder.getConstraints().getMustDefinitions().size(), 1);
+ assertNull(listBuilder.getConstraints().getMinElements());
+ assertNull(listBuilder.getConstraints().getMaxElements());
+ assertFalse(listBuilder.getUnknownNodes().isEmpty());
+ assertEquals(listBuilder.getUnknownNodes().get(0), unknownNodeBuilder);
+ }
+
+ @Test
+ public void testRefineLeafList() {
+ final String leafListLocalName = "list-to-refine";
+ final QName leafListQName = QName.create(module.getNamespace(), module.getRevision(), leafListLocalName);
+ final SchemaPath leafListPath = SchemaPath.create(true, leafListQName);
+ final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(),
+ 10, leafListQName, leafListPath);
+
+ final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+leafListLocalName);
+
+ final MustDefinition must = provideMustDefinition();
+ refineBuilder.setMust(null);
+
+ final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder();
+ refineBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+ refineBuilder.setMinElements(null);
+ refineBuilder.setMaxElements(null);
+
+ RefineUtils.performRefine(leafListBuilder, refineBuilder);
+ assertTrue(leafListBuilder.getConstraints().getMustDefinitions().isEmpty());
+ assertNull(leafListBuilder.getConstraints().getMinElements());
+ assertNull(leafListBuilder.getConstraints().getMaxElements());
+ assertFalse(leafListBuilder.getUnknownNodes().isEmpty());
+ assertEquals(leafListBuilder.getUnknownNodes().get(0), unknownNodeBuilder);
+
+ refineBuilder.setMinElements(Integer.MIN_VALUE);
+ refineBuilder.setMaxElements(Integer.MAX_VALUE);
+ refineBuilder.setMust(must);
+
+ RefineUtils.performRefine(leafListBuilder, refineBuilder);
+ assertFalse(leafListBuilder.getConstraints().getMustDefinitions().isEmpty());
+ assertEquals(leafListBuilder.getConstraints().getMustDefinitions().size(), 1);
+
+ assertNotNull(leafListBuilder.getConstraints().getMinElements());
+ assertNotNull(leafListBuilder.getConstraints().getMaxElements());
+ }
+
+ @Test
+ public void testRefineChoice() {
+ final String choiceLocalName = "choice-to-refine";
+ final ChoiceBuilder choiceBuilder = provideChoiceBuilder(choiceLocalName);
+
+ final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+choiceLocalName);
+ refineBuilder.setDefaultStr(null);
+ refineBuilder.setMandatory(null);
+
+ RefineUtils.performRefine(choiceBuilder, refineBuilder);
+ assertNull(choiceBuilder.getDefaultCase());
+ assertFalse(choiceBuilder.getConstraints().isMandatory());
+
+ final String defaultValue = "choice-default-case";
+ refineBuilder.setDefaultStr(defaultValue);
+ refineBuilder.setMandatory(true);
+ final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder();
+ refineBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+ RefineUtils.performRefine(choiceBuilder, refineBuilder);
+ assertNotNull(choiceBuilder.getDefaultCase());
+ assertNotNull(choiceBuilder.getConstraints().isMandatory());
+ assertFalse(choiceBuilder.getUnknownNodes().isEmpty());
+ assertEquals(choiceBuilder.getUnknownNodes().get(0), unknownNodeBuilder);
+ }
+
+ @Test
+ public void testRefineAnyxml() {
+ final String anyxmlLocalName = "anyxml-to-refine";
+ final QName anyxmlName = QName.create(module.getNamespace(), module.getRevision(), anyxmlLocalName);
+ final SchemaPath anyxmlPath = SchemaPath.create(true, anyxmlName);
+ final AnyXmlBuilder anyXmlBuilder = new AnyXmlBuilder(module.getModuleName(), 22, anyxmlName, anyxmlPath);
+
+ final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+anyxmlLocalName);
+ refineBuilder.setMandatory(null);
+ refineBuilder.setMust(null);
+
+ RefineUtils.performRefine(anyXmlBuilder, refineBuilder);
+ assertNull(refineBuilder.isMandatory());
+ assertNull(refineBuilder.getMust());
+
+ final MustDefinition must = provideMustDefinition();
+
+ refineBuilder.setMandatory(true);
+ refineBuilder.setMust(must);
+
+ final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder();
+ refineBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+ RefineUtils.performRefine(anyXmlBuilder, refineBuilder);
+ assertFalse(anyXmlBuilder.getConstraints().getMustDefinitions().isEmpty());
+ assertEquals(anyXmlBuilder.getConstraints().getMustDefinitions().size(), 1);
+ assertFalse(anyXmlBuilder.getUnknownNodes().isEmpty());
+ assertEquals(anyXmlBuilder.getUnknownNodes().get(0), unknownNodeBuilder);
+ assertTrue(anyXmlBuilder.getConstraints().isMandatory());
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testCheckRefineDefault() {
+ final String groupLocalName = "test-group";
+ final QName testGroup = QName.create(module.getNamespace(), module.getRevision(), groupLocalName);
+ final SchemaPath groupPath = SchemaPath.create(true, testGroup);
+ final GroupingBuilder grouping = module.addGrouping(12, testGroup, groupPath);
+
+ final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+groupLocalName);
+ refineBuilder.setDefaultStr("invalid-default-value");
+
+ RefineUtils.performRefine(grouping, refineBuilder);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testCheckRefineMandatory() {
+ final TypeDefinitionBuilderImpl typedef = initTypedef();
+ final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+typedef.getQName().getLocalName());
+ refineBuilder.setMandatory(true);
+ RefineUtils.performRefine(typedef, refineBuilder);
+ }
+
+ private TypeDefinitionBuilderImpl initTypedef() {
+ final String typedefLocalName = "test-type-definition";
+ final QName testTypedef = QName.create(module.getNamespace(), module.getRevision(), typedefLocalName);
+ SchemaPath testTypedefPath = SchemaPath.create(true, testTypedef);
+
+ return module.addTypedef(23, testTypedef, testTypedefPath);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testCheckRefineMust() {
+ final TypeDefinitionBuilderImpl typedef = initTypedef();
+ final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+typedef.getQName().getLocalName());
+
+ final MustDefinition must = provideMustDefinition();
+ refineBuilder.setMust(must);
+ RefineUtils.performRefine(typedef, refineBuilder);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testCheckRefineMin() {
+ final TypeDefinitionBuilderImpl typedef = initTypedef();
+ final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+typedef.getQName().getLocalName());
+
+ refineBuilder.setMinElements(Integer.MIN_VALUE);
+ RefineUtils.performRefine(typedef, refineBuilder);
+ }
+
+ @Test(expected = YangParseException.class)
+ public void testCheckRefineMax() {
+ final TypeDefinitionBuilderImpl typedef = initTypedef();
+ final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+typedef.getQName().getLocalName());
+
+ refineBuilder.setMaxElements(Integer.MAX_VALUE);
+ RefineUtils.performRefine(typedef, refineBuilder);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.builder.impl;
+
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+import java.net.URI;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.util.Uint16;
+import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
+
+/**
+ * Test suite for increasing of test coverage of RpcDefinitionBuilder implementation.
+ *
+ * @see org.opendaylight.yangtools.yang.parser.builder.impl.RpcDefinitionBuilder
+ *
+ * @author Lukas Sedlak <lsedlak@cisco.com>
+ */
+public class RpcDefinitionBuilderTest extends AbstractBuilderTest {
+
+ @Test
+ public void testBuild() {
+ final QName rpcQName = QName.create(module.getNamespace(), module.getRevision(), "send-message");
+ SchemaPath rpcPath = SchemaPath.create(true, rpcQName);
+ final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(module.getModuleName(), 10, rpcQName, rpcPath);
+
+ final QName testTypedef = QName.create(module.getNamespace(), module.getRevision(), "test-typedef");
+ final SchemaPath testTypedefPath = SchemaPath.create(true, rpcQName, testTypedef);
+ final TypeDefinitionBuilder typedefBuilder = new TypeDefinitionBuilderImpl(module.getModuleName(),
+ 12, testTypedef, testTypedefPath);
+ typedefBuilder.setType(Uint16.getInstance());
+
+ rpcBuilder.addTypedef(typedefBuilder);
+
+ final QName testGroup = QName.create(module.getNamespace(), module.getRevision(), "test-group");
+ final SchemaPath groupPath = SchemaPath.create(true, rpcQName, testGroup);
+ final GroupingBuilder groupBuilder = new GroupingBuilderImpl(module.getModuleName(), 15, testGroup, groupPath);
+
+ rpcBuilder.addGrouping(groupBuilder);
+
+ final QName unknownNode = QName.create(module.getNamespace(), module.getRevision(), "unknown-ext-use");
+ final SchemaPath unknownNodePath = SchemaPath.create(true, rpcQName, unknownNode);
+ final UnknownSchemaNodeBuilder unknownNodeBuilder = new UnknownSchemaNodeBuilderImpl(module.getModuleName(),
+ 25, unknownNode, unknownNodePath);
+
+ rpcBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+ final RpcDefinitionBuilder rpcBuilder2 = new RpcDefinitionBuilder(module.getModuleName(), 10, rpcQName, rpcPath);
+ final RpcDefinitionBuilder rpcBuilder3 = new RpcDefinitionBuilder(module.getModuleName(), 10, unknownNode, rpcPath);
+ final RpcDefinitionBuilder rpcBuilder4 = new RpcDefinitionBuilder(module.getModuleName(), 10, rpcQName, unknownNodePath);
+
+ assertEquals(rpcBuilder, rpcBuilder2);
+ assertNotEquals(rpcBuilder, null);
+ assertNotEquals(rpcBuilder, rpcBuilder3);
+ assertNotEquals(rpcBuilder, rpcBuilder4);
+
+ assertEquals(rpcBuilder.toString(), "rpc send-message");
+
+ final RpcDefinition instance = rpcBuilder.build();
+
+ assertNotNull(instance);
+
+ final RpcDefinition sameInstance = rpcBuilder.build();
+ assertTrue(sameInstance == instance);
+ assertEquals(sameInstance, instance);
+
+ assertEquals(instance.getPath(), rpcPath);
+ assertEquals(instance.getStatus(), Status.CURRENT);
+ assertNull(instance.getOutput());
+ assertFalse(instance.getTypeDefinitions().isEmpty());
+ assertFalse(instance.getGroupings().isEmpty());
+ assertFalse(instance.getUnknownSchemaNodes().isEmpty());
+
+ assertEquals(instance.getTypeDefinitions().size(), 1);
+ assertEquals(instance.getGroupings().size(), 1);
+ assertEquals(instance.getUnknownSchemaNodes().size(), 1);
+
+ RpcDefinition instance2 = rpcBuilder2.build();
+ RpcDefinition instance3 = rpcBuilder3.build();
+ RpcDefinition instance4 = rpcBuilder4.build();
+
+ assertEquals(instance, instance2);
+ assertNotEquals(instance, null);
+ assertNotEquals(instance, instance3);
+ assertNotEquals(instance, instance4);
+
+ assertEquals(instance.toString(), "RpcDefinitionImpl[qname=(urn:opendaylight.rpc:def:test-model?" +
+ "revision=2014-01-06)send-message, path=AbsoluteSchemaPath{path=[(urn:opendaylight.rpc:def:test-model?" +
+ "revision=2014-01-06)send-message]}, input=null, output=null]");
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.impl;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.impl.CopyUtils;
+import org.opendaylight.yangtools.yang.parser.builder.impl.IdentityrefTypeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
+
+/**
+ * NPE is rised during use of CopyUtils.copy operation for IdentityrefTypeBuilder.
+ * NPE occours in private getData method in CopyUtils.java during QName.create.
+ *
+ * The reason for exception is the old.getQName returns null since IdentityrefTypeBuilder.getQName()
+ * by implementation returns always null.
+ *
+ */
+public class Bug2219Test {
+
+ private ModuleBuilder moduleBuilder;
+
+ @Before
+ public void init() {
+ moduleBuilder = new ModuleBuilder("test-module", "somePath");
+ }
+
+ @Test
+ public void testCopyIdentityrefTypeBuilder() {
+ final String typedefLocalName = "identity-ref-test-type";
+ final QName typedefQname = QName.create(moduleBuilder.getNamespace(), moduleBuilder.getRevision(), typedefLocalName);
+ final SchemaPath typedefPath = SchemaPath.create(true, typedefQname);
+ final IdentityrefTypeBuilder typeBuilder = new IdentityrefTypeBuilder(moduleBuilder.getModuleName(), 12,
+ "base:parent-identity", typedefPath);
+
+ final TypeDefinitionBuilder copy = CopyUtils.copy(typeBuilder, moduleBuilder, true);
+ assertNotNull(copy);
+ }
+}
--- /dev/null
+package org.opendaylight.yangtools.yang.parser.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.util.Set;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.ModuleImport;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
+import org.opendaylight.yangtools.yang.parser.util.YangParseException;
+
+public class YangParserIdentityTest {
+
+ // base identity name equals identity name
+ @Test(expected = YangParseException.class)
+ public void testParsingIdentityTestModuleShouldThrowYangParseException()
+ throws IOException, URISyntaxException, YangSyntaxErrorException {
+ File yang = new File(getClass().getResource(
+ "/identity/identitytest.yang").toURI());
+ InputStream stream = new FileInputStream(yang);
+ TestUtils.loadModule(stream);
+ }
+
+ // same module prefixed base identity name equals identity name
+ @Test(expected = YangParseException.class)
+ public void testParsingPrefixIdentityTestModuleShouldThrowYangParseException()
+ throws URISyntaxException, IOException, YangSyntaxErrorException {
+ File yang = new File(getClass().getResource(
+ "/identity/prefixidentitytest.yang").toURI());
+ InputStream stream = new FileInputStream(yang);
+ TestUtils.loadModule(stream);
+ }
+
+ // imported module prefixed base identity name equals identity name, but
+ // prefix differs
+ @Test
+ public void testParsingImportPrefixIdentityTestModuleShouldThrowYangParseException()
+ throws URISyntaxException, IOException, YangSyntaxErrorException {
+ Set<Module> modules = TestUtils.loadModules(getClass().getResource(
+ "/identity/import").toURI());
+ Module module = TestUtils.findModule(modules,
+ "prefiximportidentitytest");
+ Set<ModuleImport> imports = module.getImports();
+ assertEquals(imports.size(), 1);
+ ModuleImport dummy = TestUtils.findImport(imports, "dummy");
+ assertNotEquals(dummy.getPrefix(), module.getPrefix());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.util;
+
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
+import org.opendaylight.yangtools.yang.model.util.Int32;
+import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
+import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
+import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.text.ParseException;
+import java.util.Collections;
+import java.util.Set;
+
+import static org.junit.Assert.*;
+
+public class SchemaContextUtilTest {
+ @Mock
+ private SchemaContext mockSchemaContext;
+ @Mock
+ private Module mockModule;
+
+ @Test
+ public void testFindDummyData() {
+ MockitoAnnotations.initMocks(this);
+
+ QName qName = QName.create("TestQName");
+ SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qName), true);
+ assertEquals("Should be null. Module TestQName not found", null,
+ SchemaContextUtil.findDataSchemaNode(mockSchemaContext, schemaPath));
+
+ RevisionAwareXPath xPath = new RevisionAwareXPathImpl("/bookstore/book/title", true);
+ assertEquals("Should be null. Module bookstore not found", null,
+ SchemaContextUtil.findDataSchemaNode(mockSchemaContext, mockModule, xPath));
+
+ SchemaNode schemaNode = Int32.getInstance();
+ RevisionAwareXPath xPathRelative = new RevisionAwareXPathImpl("../prefix", false);
+ assertEquals("Should be null, Module prefix not found", null,
+ SchemaContextUtil.findDataSchemaNodeForRelativeXPath(mockSchemaContext, mockModule, schemaNode,
+ xPathRelative));
+
+ assertEquals("Should be null. Module TestQName not found", null,
+ SchemaContextUtil.findNodeInSchemaContext(mockSchemaContext, Collections.singleton(qName)));
+
+ assertEquals("Should be null.", null, SchemaContextUtil.findParentModule(mockSchemaContext, schemaNode));
+ }
+
+ @Test
+ public void findNodeInSchemaContextTest() throws URISyntaxException, IOException, YangSyntaxErrorException,
+ ParseException {
+
+ File resourceFile = new File(getClass().getResource("/schema-context-util-test/my-module.yang").toURI());
+ File resourceDir = resourceFile.getParentFile();
+
+ YangParserImpl parser = YangParserImpl.getInstance();
+ SchemaContext context = parser.parseFile(resourceFile, resourceDir);
+
+ Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+ QName.parseRevision("2014-10-07"));
+
+ SchemaNode testNode = ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+ .getDataChildByName("my-leaf-in-container");
+
+ SchemaPath path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+ QName.create(myModule.getQNameModule(), "my-leaf-in-container"));
+ SchemaNode foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ Set<RpcDefinition> rpcs = myModule.getRpcs();
+ RpcDefinition rpc = rpcs.iterator().next();
+ testNode = rpc.getInput().getDataChildByName("my-input-leaf");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+ QName.create(myModule.getQNameModule(), "input"),
+ QName.create(myModule.getQNameModule(), "my-input-leaf"));
+
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ rpc = myModule.getRpcs().iterator().next();
+ testNode = rpc.getOutput().getDataChildByName("my-output-leaf");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+ QName.create(myModule.getQNameModule(), "output"),
+ QName.create(myModule.getQNameModule(), "my-output-leaf"));
+
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ NotificationDefinition notification = myModule.getNotifications().iterator().next();
+ testNode = notification.getDataChildByName("my-notification-leaf");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-notification"),
+ QName.create(myModule.getQNameModule(), "my-notification-leaf"));
+
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ GroupingDefinition grouping = myModule.getGroupings().iterator().next();
+ testNode = ((ContainerSchemaNode) grouping.getDataChildByName("my-container-in-grouping"))
+ .getDataChildByName("my-leaf-in-grouping");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-grouping"),
+ QName.create(myModule.getQNameModule(), "my-container-in-grouping"),
+ QName.create(myModule.getQNameModule(), "my-leaf-in-grouping"));
+
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ testNode = ((ChoiceNode) myModule.getDataChildByName("my-choice")).getCaseNodeByName("one").getDataChildByName(
+ "my-choice-leaf-one");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
+ QName.create(myModule.getQNameModule(), "one"),
+ QName.create(myModule.getQNameModule(), "my-choice-leaf-one"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ ListSchemaNode listNode = (ListSchemaNode) ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+ .getDataChildByName("my-list");
+
+ testNode = listNode.getDataChildByName("my-leaf-in-list");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+ QName.create(myModule.getQNameModule(), "my-list"),
+ QName.create(myModule.getQNameModule(), "my-leaf-in-list"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ listNode = (ListSchemaNode) ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+ .getDataChildByName("my-list");
+
+ testNode = listNode.getDataChildByName("my-leaf-list-in-list");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+ QName.create(myModule.getQNameModule(), "my-list"),
+ QName.create(myModule.getQNameModule(), "my-leaf-list-in-list"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ }
+
+ @Test
+ public void findNodeInSchemaContextTest2() throws URISyntaxException, IOException, YangSyntaxErrorException,
+ ParseException {
+
+ File resourceFile = new File(getClass().getResource("/schema-context-util-test/my-module.yang").toURI());
+ File resourceDir = resourceFile.getParentFile();
+
+ YangParserImpl parser = YangParserImpl.getInstance();
+ SchemaContext context = parser.parseFile(resourceFile, resourceDir);
+
+ Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+ QName.parseRevision("2014-10-07"));
+
+ SchemaNode testNode = ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+ .getDataChildByName("my-leaf-not-in-container");
+
+ SchemaPath path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+ QName.create(myModule.getQNameModule(), "my-leaf-not-in-container"));
+ SchemaNode foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNull(testNode);
+ assertNull(foundNode);
+
+ Set<RpcDefinition> rpcs = myModule.getRpcs();
+ RpcDefinition rpc = rpcs.iterator().next();
+ testNode = rpc.getInput().getDataChildByName("no-input-leaf");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+ QName.create(myModule.getQNameModule(), "input"),
+ QName.create(myModule.getQNameModule(), "no-input-leaf"));
+
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNull(testNode);
+ assertNull(foundNode);
+
+ NotificationDefinition notification = myModule.getNotifications().iterator().next();
+ testNode = notification.getDataChildByName("no-notification-leaf");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-notification"),
+ QName.create(myModule.getQNameModule(), "no-notification-leaf"));
+
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNull(testNode);
+ assertNull(foundNode);
+
+ GroupingDefinition grouping = myModule.getGroupings().iterator().next();
+ testNode = ((ContainerSchemaNode) grouping.getDataChildByName("my-container-in-grouping"))
+ .getDataChildByName("no-leaf-in-grouping");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-grouping"),
+ QName.create(myModule.getQNameModule(), "my-container-in-grouping"),
+ QName.create(myModule.getQNameModule(), "no-leaf-in-grouping"));
+
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNull(testNode);
+ assertNull(foundNode);
+
+ testNode = ((ChoiceNode) myModule.getDataChildByName("my-choice")).getCaseNodeByName("one").getDataChildByName(
+ "no-choice-leaf");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
+ QName.create(myModule.getQNameModule(), "one"),
+ QName.create(myModule.getQNameModule(), "no-choice-leaf"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNull(testNode);
+ assertNull(foundNode);
+
+ ListSchemaNode listNode = (ListSchemaNode) ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+ .getDataChildByName("my-list");
+
+ testNode = listNode.getDataChildByName("no-leaf-in-list");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+ QName.create(myModule.getQNameModule(), "my-list"),
+ QName.create(myModule.getQNameModule(), "no-leaf-in-list"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNull(testNode);
+ assertNull(foundNode);
+
+ listNode = (ListSchemaNode) ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+ .getDataChildByName("my-list");
+
+ testNode = listNode.getDataChildByName("no-leaf-list-in-list");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+ QName.create(myModule.getQNameModule(), "my-list"),
+ QName.create(myModule.getQNameModule(), "no-leaf-list-in-list"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNull(testNode);
+ assertNull(foundNode);
+
+ }
+
+ @Test
+ public void findNodeInSchemaContextTest3() throws URISyntaxException, IOException, YangSyntaxErrorException,
+ ParseException {
+
+ File resourceFile = new File(getClass().getResource("/schema-context-util-test/my-module.yang").toURI());
+ File resourceDir = resourceFile.getParentFile();
+
+ YangParserImpl parser = YangParserImpl.getInstance();
+ SchemaContext context = parser.parseFile(resourceFile, resourceDir);
+
+ Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+ QName.parseRevision("2014-10-07"));
+
+ SchemaNode testNode = myModule.getDataChildByName("my-container");
+
+ SchemaPath path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"));
+ SchemaNode foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ testNode = myModule.getRpcs().iterator().next();
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ testNode = myModule.getNotifications().iterator().next();
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-notification"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ testNode = myModule.getGroupings().iterator().next();
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-grouping"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ testNode = myModule.getDataChildByName("my-choice");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ testNode = ((ContainerSchemaNode) myModule.getDataChildByName("my-container")).getDataChildByName("my-list");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+ QName.create(myModule.getQNameModule(), "my-list"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ }
+
+ @Test
+ public void findParentModuleTest() throws URISyntaxException, IOException, YangSyntaxErrorException, ParseException {
+
+ File resourceFile = new File(getClass().getResource("/schema-context-util-test/my-module.yang").toURI());
+ File resourceDir = resourceFile.getParentFile();
+
+ YangParserImpl parser = YangParserImpl.getInstance();
+ SchemaContext context = parser.parseFile(resourceFile, resourceDir);
+
+ Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+ QName.parseRevision("2014-10-07"));
+
+ DataSchemaNode node = myModule.getDataChildByName("my-container");
+
+ Module foundModule = SchemaContextUtil.findParentModule(context, node);
+
+ assertEquals(myModule, foundModule);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void findParentModuleIllegalArgumentTest() {
+
+ SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+ SchemaContextUtil.findParentModule(mockContext, null);
+
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void findParentModuleIllegalArgumentTest2() {
+
+ SchemaNode mockSchemaNode = Mockito.mock(SchemaNode.class);
+ SchemaContextUtil.findParentModule(null, mockSchemaNode);
+
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void findParentModuleIllegalStateTest() {
+
+ SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+ SchemaNode mockSchemaNode = Mockito.mock(SchemaNode.class);
+ Mockito.when(mockSchemaNode.getPath()).thenReturn(null);
+ SchemaContextUtil.findParentModule(mockContext, mockSchemaNode);
+
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void findDataSchemaNodeIllegalArgumentTest() {
+
+ SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+ SchemaContextUtil.findDataSchemaNode(mockContext, null);
+
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void findDataSchemaNodeIllegalArgumentTest2() {
+
+ SchemaPath mockSchemaPath = Mockito.mock(SchemaPath.class);
+ SchemaContextUtil.findDataSchemaNode(null, mockSchemaPath);
+
+ }
+
+ @Test
+ public void findDataSchemaNodeTest() throws URISyntaxException, IOException, YangSyntaxErrorException {
+
+ File resourceFile = new File(getClass().getResource("/schema-context-util-test/my-module.yang").toURI());
+ File resourceDir = resourceFile.getParentFile();
+
+ YangParserImpl parser = YangParserImpl.getInstance();
+ SchemaContext context = parser.parseFile(resourceFile, resourceDir);
+
+ Module module = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+ QName.parseRevision("2014-10-07"));
+ Module importedModule = context.findModuleByNamespaceAndRevision(new URI("uri:imported-module"),
+ QName.parseRevision("2014-10-07"));
+
+ SchemaNode testNode = ((ContainerSchemaNode) importedModule.getDataChildByName("my-imported-container"))
+ .getDataChildByName("my-imported-leaf");
+
+ RevisionAwareXPath xpath = new RevisionAwareXPathImpl("imp:my-imported-container/imp:my-imported-leaf", true);
+
+ SchemaNode foundNode = SchemaContextUtil.findDataSchemaNode(context, module, xpath);
+
+ assertNotNull(foundNode);
+ assertNotNull(testNode);
+ assertEquals(testNode, foundNode);
+
+ }
+
+ @Test
+ public void findDataSchemaNodeTest2() throws URISyntaxException, IOException, YangSyntaxErrorException {
+ // findDataSchemaNode(final SchemaContext context, final Module module,
+ // final RevisionAwareXPath nonCondXPath) {
+
+ File resourceFile = new File(getClass().getResource("/schema-context-util-test/my-module.yang").toURI());
+ File resourceDir = resourceFile.getParentFile();
+
+ YangParserImpl parser = YangParserImpl.getInstance();
+ SchemaContext context = parser.parseFile(resourceFile, resourceDir);
+
+ Module module = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+ QName.parseRevision("2014-10-07"));
+
+ GroupingDefinition grouping = module.getGroupings().iterator().next();
+ SchemaNode testNode = grouping.getDataChildByName("my-leaf-in-gouping2");
+
+ RevisionAwareXPath xpath = new RevisionAwareXPathImpl("my:my-grouping/my:my-leaf-in-gouping2", true);
+
+ SchemaNode foundNode = SchemaContextUtil.findDataSchemaNode(context, module, xpath);
+
+ assertNotNull(foundNode);
+ assertNotNull(testNode);
+ assertEquals(testNode, foundNode);
+
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void findDataSchemaNodeFromXPathIllegalArgumentTest() {
+
+ SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+ Module module = Mockito.mock(Module.class);
+
+ SchemaContextUtil.findDataSchemaNode(mockContext, module, null);
+
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void findDataSchemaNodeFromXPathIllegalArgumentTest2() {
+
+ SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+ RevisionAwareXPath xpath = new RevisionAwareXPathImpl("my:my-grouping/my:my-leaf-in-gouping2", true);
+
+ SchemaContextUtil.findDataSchemaNode(mockContext, null, xpath);
+
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void findDataSchemaNodeFromXPathIllegalArgumentTest3() {
+
+ Module module = Mockito.mock(Module.class);
+ RevisionAwareXPath xpath = new RevisionAwareXPathImpl("my:my-grouping/my:my-leaf-in-gouping2", true);
+
+ SchemaContextUtil.findDataSchemaNode(null, module, xpath);
+
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void findDataSchemaNodeFromXPathIllegalArgumentTest4() {
+
+ SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+ Module module = Mockito.mock(Module.class);
+ RevisionAwareXPath xpath = new RevisionAwareXPathImpl("my:my-grouping[@con='NULL']/my:my-leaf-in-gouping2",
+ true);
+
+ SchemaContextUtil.findDataSchemaNode(mockContext, module, xpath);
+
+ }
+
+ @Test
+ public void findDataSchemaNodeFromXPathNullTest() {
+
+ SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+ Module module = Mockito.mock(Module.class);
+ RevisionAwareXPath xpath = Mockito.mock(RevisionAwareXPath.class);
+
+ Mockito.when(xpath.toString()).thenReturn(null);
+ assertNull(SchemaContextUtil.findDataSchemaNode(mockContext, module, xpath));
+
+ }
+
+ @Test
+ public void findDataSchemaNodeFromXPathNullTest2() {
+
+ SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+ Module module = Mockito.mock(Module.class);
+ RevisionAwareXPath xpath = new RevisionAwareXPathImpl("my:my-grouping/my:my-leaf-in-gouping2", false);
+
+ assertNull(SchemaContextUtil.findDataSchemaNode(mockContext, module, xpath));
+
+ }
+
+}
\ No newline at end of file
--- /dev/null
+module identitytest {
+ yang-version 1;
+ namespace "urn:test.identitytest";
+ prefix "idtest";
+
+ organization "opendaylight";
+ contact "http://www.opendaylight.org";
+
+ revision "2014-09-17" {
+ description "Initial import";
+ }
+
+ identity test {
+ base test;
+ }
+}
--- /dev/null
+module dummy {
+ yang-version 1;
+ namespace "urn:test.dummy";
+ prefix "dummy";
+
+ organization "opendaylight";
+ contact "http://www.opendaylight.org";
+
+ revision "2014-09-24" {
+ description "Initial import";
+ }
+
+ identity prefiximportidentitytest {
+ }
+}
--- /dev/null
+module prefiximportidentitytest {
+ yang-version 1;
+ namespace "urn:test.prefiximportidentitytest";
+ prefix "prefiximportidentitytest";
+
+ import dummy { prefix dummy; revision-date 2014-09-24; }
+
+ organization "opendaylight";
+ contact "http://www.opendaylight.org";
+
+ revision "2014-09-24" {
+ description "Initial import";
+ }
+
+ identity prefiximportidentitytest {
+ base dummy:prefiximportidentitytest;
+ }
+}
--- /dev/null
+module prefixidentitytest {
+ yang-version 1;
+ namespace "urn:test.prefixidentitytest";
+ prefix prefixtest;
+
+ organization "opendaylight";
+ contact "http://www.opendaylight.org";
+
+ revision "2014-09-24" {
+ description "Initial import";
+ }
+
+ identity prefixtest {
+ base prefixtest:prefixtest;
+ }
+}
--- /dev/null
+module imported-module {
+ yang-version 1;
+ namespace "uri:imported-module";
+ prefix imp;
+
+ revision 2014-10-07 {
+ description
+ "Imported yang model";
+ }
+
+ container my-imported-container {
+ leaf my-imported-leaf {
+ type string;
+ }
+ }
+}
--- /dev/null
+module my-module {
+ yang-version 1;
+ namespace "uri:my-module";
+ prefix my;
+
+ import imported-module { prefix imp; revision-date 2014-10-07; }
+
+ revision 2014-10-07 {
+ description
+ "My yang model";
+ }
+
+ grouping my-grouping {
+ container my-container-in-grouping {
+ leaf my-leaf-in-grouping {
+ type int16;
+ }
+ }
+ leaf my-leaf-in-gouping2 {
+ type string;
+ }
+ }
+
+ container my-container {
+ leaf my-leaf-in-container {
+ type int32;
+ }
+ uses my-grouping;
+ list my-list {
+ leaf my-leaf-in-list {
+ type string;
+ }
+ leaf-list my-leaf-list-in-list {
+ type int16;
+ }
+ }
+ }
+
+ rpc my-rpc {
+ input {
+ leaf my-input-leaf {
+ type string;
+ }
+ }
+
+ output {
+ leaf my-output-leaf {
+ type int16;
+ }
+ }
+ }
+
+ notification my-notification {
+ leaf my-notification-leaf {
+ type string;
+ }
+ }
+
+ choice my-choice {
+ case one {
+ leaf my-choice-leaf-one {
+ type string;
+ }
+ }
+ case two {
+ leaf my-choice-leaf-two {
+ type int16;
+ }
+ }
+ }
+}
+