2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.northbound.commons.exception;
10 import javax.ws.rs.core.Response;
12 import org.junit.Assert;
13 import org.junit.Test;
15 public class CommonsNorthboundExceptionTest {
18 public void testMethodNotAllowed() {
19 MethodNotAllowed mna = new MethodNotAllowed();
20 Assert.assertTrue(mna.getStatusCode() == 405);
21 Assert.assertTrue(mna.getReasonPhrase().equals("Method Not Allowed"));
22 Assert.assertTrue(mna.getFamily().equals(
23 Response.Status.Family.CLIENT_ERROR));
27 public void testInternalServerErrorException() {
29 throw new InternalServerErrorException("Internal Server Exception");
30 } catch (InternalServerErrorException e) {
31 Assert.assertTrue(e.getResponse().getEntity()
32 .equals("Internal Server Exception"));
37 public void testMethodNotAllowedException() {
39 throw new MethodNotAllowedException("Method Not Allowed Exception");
40 } catch (MethodNotAllowedException e) {
41 Assert.assertTrue(e.getResponse().getEntity()
42 .equals("Method Not Allowed Exception"));
47 public void testNotAcceptableException() {
49 throw new NotAcceptableException("Not Acceptable Exception");
50 } catch (NotAcceptableException e) {
51 Assert.assertTrue(e.getResponse().getEntity()
52 .equals("Not Acceptable Exception"));
57 public void testResourceConflictException() {
59 throw new ResourceConflictException("Resource Conflict Exception");
60 } catch (ResourceConflictException e) {
61 Assert.assertTrue(e.getResponse().getEntity()
62 .equals("Resource Conflict Exception"));
67 public void testResourceForbiddenException() {
69 throw new ResourceForbiddenException("Resource Forbidden Exception");
70 } catch (ResourceForbiddenException e) {
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.getResponse().getEntity()
82 .equals("Resource Gone Exception"));
87 public void testResourceNotFoundException() {
89 throw new ResourceNotFoundException("Resource Not Found Exception");
90 } catch (ResourceNotFoundException e) {
91 Assert.assertTrue(e.getResponse().getEntity()
92 .equals("Resource Not Found Exception"));
97 public void testServiceUnavailableException() {
99 throw new ServiceUnavailableException(
100 "Service Unavailable Exception");
101 } catch (ServiceUnavailableException e) {
102 Assert.assertTrue(e.getResponse().getEntity()
103 .equals("Service Unavailable Exception"));
108 public void testUnauthorizedException() {
110 throw new UnauthorizedException("Unauthorized Exception");
111 } catch (UnauthorizedException e) {
112 Assert.assertTrue(e.getResponse().getEntity()
113 .equals("Unauthorized Exception"));
118 public void testUnsupportedMediaTypeException() {
120 throw new UnsupportedMediaTypeException(
121 "Unsupported Media Type Exception");
122 } catch (UnsupportedMediaTypeException e) {
123 Assert.assertTrue(e.getResponse().getEntity()
124 .equals("Unsupported Media Type Exception"));