--- /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());
+ }
+}
--- /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);
+ }
+}
--- /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());
+ }
+}
--- /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));
+ }
+}