Merge "Refactoring SubnetConfig: -Use NetUtils IP validation methods instead of own...
[controller.git] / opendaylight / northbound / commons / src / test / java / org / opendaylight / controller / northbound / commons / exception / CommonsNorthboundExceptionTest.java
1 package org.opendaylight.controller.northbound.commons.exception;
2
3 import javax.ws.rs.core.Response;
4
5 import org.junit.Assert;
6 import org.junit.Test;
7
8 import junit.framework.TestCase;
9
10 public class CommonsNorthboundExceptionTest extends TestCase {
11
12     @Test
13     public void testMethodNotAllowed() {
14         MethodNotAllowed mna = new MethodNotAllowed();
15         Assert.assertTrue(mna.getStatusCode() == 405);
16         Assert.assertTrue(mna.getReasonPhrase().equals("Method Not Allowed"));
17         Assert.assertTrue(mna.getFamily().equals(
18                 Response.Status.Family.CLIENT_ERROR));
19     }
20
21     @Test
22     public void testInternalServerErrorException() {
23         try {
24             throw new InternalServerErrorException("Internal Server Exception");
25         } catch (InternalServerErrorException e) {
26             Assert.assertTrue(e instanceof InternalServerErrorException);
27             Assert.assertTrue(e.getResponse().getEntity()
28                     .equals("Internal Server Exception"));
29         }
30     }
31
32     @Test
33     public void testMethodNotAllowedException() {
34         try {
35             throw new MethodNotAllowedException("Method Not Allowed Exception");
36         } catch (MethodNotAllowedException e) {
37             Assert.assertTrue(e instanceof MethodNotAllowedException);
38             Assert.assertTrue(e.getResponse().getEntity()
39                     .equals("Method Not Allowed Exception"));
40         }
41     }
42
43     @Test
44     public void testNotAcceptableException() {
45         try {
46             throw new NotAcceptableException("Not Acceptable Exception");
47         } catch (NotAcceptableException e) {
48             Assert.assertTrue(e instanceof NotAcceptableException);
49             Assert.assertTrue(e.getResponse().getEntity()
50                     .equals("Not Acceptable Exception"));
51         }
52     }
53
54     @Test
55     public void testResourceConflictException() {
56         try {
57             throw new ResourceConflictException("Resource Conflict Exception");
58         } catch (ResourceConflictException e) {
59             Assert.assertTrue(e instanceof ResourceConflictException);
60             Assert.assertTrue(e.getResponse().getEntity()
61                     .equals("Resource Conflict Exception"));
62         }
63     }
64
65     @Test
66     public void testResourceForbiddenException() {
67         try {
68             throw new ResourceForbiddenException("Resource Forbidden Exception");
69         } catch (ResourceForbiddenException e) {
70             Assert.assertTrue(e instanceof ResourceForbiddenException);
71             Assert.assertTrue(e.getResponse().getEntity()
72                     .equals("Resource Forbidden Exception"));
73         }
74     }
75
76     @Test
77     public void testResourceGoneException() {
78         try {
79             throw new ResourceGoneException("Resource Gone Exception");
80         } catch (ResourceGoneException e) {
81             Assert.assertTrue(e instanceof ResourceGoneException);
82             Assert.assertTrue(e.getResponse().getEntity()
83                     .equals("Resource Gone Exception"));
84         }
85     }
86
87     @Test
88     public void testResourceNotFoundException() {
89         try {
90             throw new ResourceNotFoundException("Resource Not Found Exception");
91         } catch (ResourceNotFoundException e) {
92             Assert.assertTrue(e instanceof ResourceNotFoundException);
93             Assert.assertTrue(e.getResponse().getEntity()
94                     .equals("Resource Not Found Exception"));
95         }
96     }
97
98     @Test
99     public void testServiceUnavailableException() {
100         try {
101             throw new ServiceUnavailableException(
102                     "Service Unavailable Exception");
103         } catch (ServiceUnavailableException e) {
104             Assert.assertTrue(e instanceof ServiceUnavailableException);
105             Assert.assertTrue(e.getResponse().getEntity()
106                     .equals("Service Unavailable Exception"));
107         }
108     }
109
110     @Test
111     public void testUnauthorizedException() {
112         try {
113             throw new UnauthorizedException("Unauthorized Exception");
114         } catch (UnauthorizedException e) {
115             Assert.assertTrue(e instanceof UnauthorizedException);
116             Assert.assertTrue(e.getResponse().getEntity()
117                     .equals("Unauthorized Exception"));
118         }
119     }
120
121     @Test
122     public void testUnsupportedMediaTypeException() {
123         try {
124             throw new UnsupportedMediaTypeException(
125                     "Unsupported Media Type Exception");
126         } catch (UnsupportedMediaTypeException e) {
127             Assert.assertTrue(e instanceof UnsupportedMediaTypeException);
128             Assert.assertTrue(e.getResponse().getEntity()
129                     .equals("Unsupported Media Type Exception"));
130         }
131     }
132
133 }