1 package org.opendaylight.controller.northbound.commons.exception;
3 import javax.ws.rs.core.Response;
5 import org.junit.Assert;
8 import junit.framework.TestCase;
10 public class CommonsNorthboundExceptionTest extends TestCase {
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));
22 public void testInternalServerErrorException() {
24 throw new InternalServerErrorException("Internal Server Exception");
25 } catch (InternalServerErrorException e) {
26 Assert.assertTrue(e.getResponse().getEntity()
27 .equals("Internal Server Exception"));
32 public void testMethodNotAllowedException() {
34 throw new MethodNotAllowedException("Method Not Allowed Exception");
35 } catch (MethodNotAllowedException e) {
36 Assert.assertTrue(e.getResponse().getEntity()
37 .equals("Method Not Allowed Exception"));
42 public void testNotAcceptableException() {
44 throw new NotAcceptableException("Not Acceptable Exception");
45 } catch (NotAcceptableException e) {
46 Assert.assertTrue(e.getResponse().getEntity()
47 .equals("Not Acceptable Exception"));
52 public void testResourceConflictException() {
54 throw new ResourceConflictException("Resource Conflict Exception");
55 } catch (ResourceConflictException e) {
56 Assert.assertTrue(e.getResponse().getEntity()
57 .equals("Resource Conflict Exception"));
62 public void testResourceForbiddenException() {
64 throw new ResourceForbiddenException("Resource Forbidden Exception");
65 } catch (ResourceForbiddenException e) {
66 Assert.assertTrue(e.getResponse().getEntity()
67 .equals("Resource Forbidden Exception"));
72 public void testResourceGoneException() {
74 throw new ResourceGoneException("Resource Gone Exception");
75 } catch (ResourceGoneException e) {
76 Assert.assertTrue(e.getResponse().getEntity()
77 .equals("Resource Gone Exception"));
82 public void testResourceNotFoundException() {
84 throw new ResourceNotFoundException("Resource Not Found Exception");
85 } catch (ResourceNotFoundException e) {
86 Assert.assertTrue(e.getResponse().getEntity()
87 .equals("Resource Not Found Exception"));
92 public void testServiceUnavailableException() {
94 throw new ServiceUnavailableException(
95 "Service Unavailable Exception");
96 } catch (ServiceUnavailableException e) {
97 Assert.assertTrue(e.getResponse().getEntity()
98 .equals("Service Unavailable Exception"));
103 public void testUnauthorizedException() {
105 throw new UnauthorizedException("Unauthorized Exception");
106 } catch (UnauthorizedException e) {
107 Assert.assertTrue(e.getResponse().getEntity()
108 .equals("Unauthorized Exception"));
113 public void testUnsupportedMediaTypeException() {
115 throw new UnsupportedMediaTypeException(
116 "Unsupported Media Type Exception");
117 } catch (UnsupportedMediaTypeException e) {
118 Assert.assertTrue(e.getResponse().getEntity()
119 .equals("Unsupported Media Type Exception"));