Bug-730: Added concepts tests. 54/10754/1
authorMilos Fabian <milfabia@cisco.com>
Wed, 3 Sep 2014 14:21:27 +0000 (16:21 +0200)
committerMilos Fabian <milfabia@cisco.com>
Thu, 4 Sep 2014 07:27:46 +0000 (09:27 +0200)
Change-Id: I221fe2c100de1ce4ae703f4bc1a2237ffdce6ff8
Signed-off-by: Milos Fabian <milfabia@cisco.com>
concepts/pom.xml
concepts/src/test/java/org/opendaylight/protocol/concepts/DefaultInstanceReferenceTest.java [new file with mode: 0644]
concepts/src/test/java/org/opendaylight/protocol/concepts/HandlerRegistryTest.java [new file with mode: 0644]

index cf099432717b5867501ec60b82c3c5eca57e5f99..2f2c824cfe3d340e1134652a2fd0fcdc02c8abb1 100644 (file)
             <artifactId>netty-buffer</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools.model</groupId>
+            <artifactId>ietf-topology</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/concepts/src/test/java/org/opendaylight/protocol/concepts/DefaultInstanceReferenceTest.java b/concepts/src/test/java/org/opendaylight/protocol/concepts/DefaultInstanceReferenceTest.java
new file mode 100644 (file)
index 0000000..2a79514
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * 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.protocol.concepts;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class DefaultInstanceReferenceTest {
+
+    private static final InstanceIdentifier<NetworkTopology> IID = InstanceIdentifier.builder(NetworkTopology.class).toInstance();
+
+    @Test
+    public void testDefaultInstanceReference() {
+        final DefaultInstanceReference<NetworkTopology> defaultIID = new DefaultInstanceReference<>(IID);
+        Assert.assertEquals(IID, defaultIID.getInstanceIdentifier());
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testNullReference() {
+        new DefaultInstanceReference<>(null);
+    }
+
+}
diff --git a/concepts/src/test/java/org/opendaylight/protocol/concepts/HandlerRegistryTest.java b/concepts/src/test/java/org/opendaylight/protocol/concepts/HandlerRegistryTest.java
new file mode 100644 (file)
index 0000000..9efbbd1
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * 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.protocol.concepts;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class HandlerRegistryTest {
+
+    private static final String PARSER = "parser";
+    private static final String SERIALIZER = "serializer";
+    private static final int TYPE = 1;
+
+    @Test
+    public void testHandlerRegistry() {
+        final HandlerRegistry<Object, String, String> registry = new HandlerRegistry<>();
+        final AbstractRegistration parserReg = registry.registerParser(TYPE, PARSER);
+        final AbstractRegistration serializerReg = registry.registerSerializer(Object.class, SERIALIZER);
+
+        Assert.assertNotNull(parserReg);
+        Assert.assertNotNull(serializerReg);
+        Assert.assertEquals(SERIALIZER, registry.getSerializer(Object.class));
+        Assert.assertEquals(SERIALIZER, registry.getAllSerializers().iterator().next());
+        Assert.assertEquals(PARSER, registry.getParser(TYPE));
+        Assert.assertNull(registry.getParser(0));
+        Assert.assertNull(registry.getSerializer(String.class));
+
+        parserReg.close();
+        serializerReg.close();
+        Assert.assertNull(registry.getParser(TYPE));
+        Assert.assertNull(registry.getSerializer(Object.class));
+    }
+
+}