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 instanceof InternalServerErrorException);
27 Assert.assertTrue(e.getResponse().getEntity()
28 .equals("Internal Server Exception"));
33 public void testMethodNotAllowedException() {
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"));
44 public void testNotAcceptableException() {
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"));
55 public void testResourceConflictException() {
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"));
66 public void testResourceForbiddenException() {
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"));
77 public void testResourceGoneException() {
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"));
88 public void testResourceNotFoundException() {
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"));
99 public void testServiceUnavailableException() {
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"));
111 public void testUnauthorizedException() {
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"));
122 public void testUnsupportedMediaTypeException() {
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"));