JUnit tests for commons.northbound 89/89/1
authorKalvin Hom <kahom@cisco.com>
Fri, 29 Mar 2013 00:28:44 +0000 (17:28 -0700)
committerKalvin Hom <kahom@cisco.com>
Fri, 29 Mar 2013 00:28:44 +0000 (17:28 -0700)
Change-Id: Ie450b2b8227809dac2dde5bed5c5b15dfc7cd260
Signed-off-by: Kalvin Hom <kahom@cisco.com>
opendaylight/northbound/commons/src/test/java/org/opendaylight/controller/northbound/commons/CommonsNorthboundTest.java [new file with mode: 0644]
opendaylight/northbound/commons/src/test/java/org/opendaylight/controller/northbound/commons/exception/CommonsNorthboundExceptionTest.java [new file with mode: 0644]

diff --git a/opendaylight/northbound/commons/src/test/java/org/opendaylight/controller/northbound/commons/CommonsNorthboundTest.java b/opendaylight/northbound/commons/src/test/java/org/opendaylight/controller/northbound/commons/CommonsNorthboundTest.java
new file mode 100644 (file)
index 0000000..9dba530
--- /dev/null
@@ -0,0 +1,19 @@
+package org.opendaylight.controller.northbound.commons;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import junit.framework.TestCase;
+
+public class CommonsNorthboundTest extends TestCase {
+
+    @Test
+    public void testRestMessages() {
+        Assert.assertTrue(RestMessages.SUCCESS.toString().equals("Success"));
+        Assert.assertTrue(RestMessages.INTERNALERROR.toString().equals(
+                "Internal Error"));
+        Assert.assertTrue(RestMessages.INVALIDDATA.toString().equals(
+                "Data is invalid or conflicts with URI"));
+    }
+
+}
diff --git a/opendaylight/northbound/commons/src/test/java/org/opendaylight/controller/northbound/commons/exception/CommonsNorthboundExceptionTest.java b/opendaylight/northbound/commons/src/test/java/org/opendaylight/controller/northbound/commons/exception/CommonsNorthboundExceptionTest.java
new file mode 100644 (file)
index 0000000..65790ad
--- /dev/null
@@ -0,0 +1,133 @@
+package org.opendaylight.controller.northbound.commons.exception;
+
+import javax.ws.rs.core.Response;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import junit.framework.TestCase;
+
+public class CommonsNorthboundExceptionTest extends TestCase {
+
+    @Test
+    public void testMethodNotAllowed() {
+        MethodNotAllowed mna = new MethodNotAllowed();
+        Assert.assertTrue(mna.getStatusCode() == 405);
+        Assert.assertTrue(mna.getReasonPhrase().equals("Method Not Allowed"));
+        Assert.assertTrue(mna.getFamily().equals(
+                Response.Status.Family.CLIENT_ERROR));
+    }
+
+    @Test
+    public void testInternalServerErrorException() {
+        try {
+            throw new InternalServerErrorException("Internal Server Exception");
+        } catch (InternalServerErrorException e) {
+            Assert.assertTrue(e instanceof InternalServerErrorException);
+            Assert.assertTrue(e.getResponse().getEntity()
+                    .equals("Internal Server Exception"));
+        }
+    }
+
+    @Test
+    public void testMethodNotAllowedException() {
+        try {
+            throw new MethodNotAllowedException("Method Not Allowed Exception");
+        } catch (MethodNotAllowedException e) {
+            Assert.assertTrue(e instanceof MethodNotAllowedException);
+            Assert.assertTrue(e.getResponse().getEntity()
+                    .equals("Method Not Allowed Exception"));
+        }
+    }
+
+    @Test
+    public void testNotAcceptableException() {
+        try {
+            throw new NotAcceptableException("Not Acceptable Exception");
+        } catch (NotAcceptableException e) {
+            Assert.assertTrue(e instanceof NotAcceptableException);
+            Assert.assertTrue(e.getResponse().getEntity()
+                    .equals("Not Acceptable Exception"));
+        }
+    }
+
+    @Test
+    public void testResourceConflictException() {
+        try {
+            throw new ResourceConflictException("Resource Conflict Exception");
+        } catch (ResourceConflictException e) {
+            Assert.assertTrue(e instanceof ResourceConflictException);
+            Assert.assertTrue(e.getResponse().getEntity()
+                    .equals("Resource Conflict Exception"));
+        }
+    }
+
+    @Test
+    public void testResourceForbiddenException() {
+        try {
+            throw new ResourceForbiddenException("Resource Forbidden Exception");
+        } catch (ResourceForbiddenException e) {
+            Assert.assertTrue(e instanceof ResourceForbiddenException);
+            Assert.assertTrue(e.getResponse().getEntity()
+                    .equals("Resource Forbidden Exception"));
+        }
+    }
+
+    @Test
+    public void testResourceGoneException() {
+        try {
+            throw new ResourceGoneException("Resource Gone Exception");
+        } catch (ResourceGoneException e) {
+            Assert.assertTrue(e instanceof ResourceGoneException);
+            Assert.assertTrue(e.getResponse().getEntity()
+                    .equals("Resource Gone Exception"));
+        }
+    }
+
+    @Test
+    public void testResourceNotFoundException() {
+        try {
+            throw new ResourceNotFoundException("Resource Not Found Exception");
+        } catch (ResourceNotFoundException e) {
+            Assert.assertTrue(e instanceof ResourceNotFoundException);
+            Assert.assertTrue(e.getResponse().getEntity()
+                    .equals("Resource Not Found Exception"));
+        }
+    }
+
+    @Test
+    public void testServiceUnavailableException() {
+        try {
+            throw new ServiceUnavailableException(
+                    "Service Unavailable Exception");
+        } catch (ServiceUnavailableException e) {
+            Assert.assertTrue(e instanceof ServiceUnavailableException);
+            Assert.assertTrue(e.getResponse().getEntity()
+                    .equals("Service Unavailable Exception"));
+        }
+    }
+
+    @Test
+    public void testUnauthorizedException() {
+        try {
+            throw new UnauthorizedException("Unauthorized Exception");
+        } catch (UnauthorizedException e) {
+            Assert.assertTrue(e instanceof UnauthorizedException);
+            Assert.assertTrue(e.getResponse().getEntity()
+                    .equals("Unauthorized Exception"));
+        }
+    }
+
+    @Test
+    public void testUnsupportedMediaTypeException() {
+        try {
+            throw new UnsupportedMediaTypeException(
+                    "Unsupported Media Type Exception");
+        } catch (UnsupportedMediaTypeException e) {
+            Assert.assertTrue(e instanceof UnsupportedMediaTypeException);
+            Assert.assertTrue(e.getResponse().getEntity()
+                    .equals("Unsupported Media Type Exception"));
+        }
+    }
+
+}