blob: c435668953626fe995ad994855e73eb05d0f180d [file] [log] [blame]
Ray Milkeya8091b12014-05-16 14:42:47 -07001package net.onrc.onos.api.rest;
2
3import org.junit.Test;
4
5import static net.onrc.onos.core.util.ImmutableClassChecker.assertThatClassIsImmutable;
6import static net.onrc.onos.core.util.UtilityClassChecker.assertThatClassIsUtility;
7import static org.hamcrest.MatcherAssert.assertThat;
8import static org.hamcrest.Matchers.equalTo;
9import static org.hamcrest.Matchers.is;
10import static org.hamcrest.Matchers.notNullValue;
11
12
13/**
14 * Unit tests for REST error handling classes.
15 */
16public class RestErrorCatalogEntryTest {
17
18 /**
19 * Test the formatting of a REST error that contains a single
20 * positional parameter.
21 */
22 @Test
23 public void testRestErrorFormatting1Parameter() {
24 final RestErrorCatalogEntry restErrorCatalogEntry =
Ray Milkey6fdd91d2014-07-30 16:27:07 -070025 RestErrorCatalog.getRestError(RestErrorCode.INTENT_ALREADY_EXISTS);
Ray Milkeya8091b12014-05-16 14:42:47 -070026 assertThat(restErrorCatalogEntry, is(notNullValue()));
27
28 final RestError formattedError =
Ray Milkey6fdd91d2014-07-30 16:27:07 -070029 RestError.createRestError(RestErrorCode.INTENT_ALREADY_EXISTS,
Ray Milkeya8091b12014-05-16 14:42:47 -070030 "INTENT-ID");
31 final String formattedErrorString =
32 formattedError.getFormattedDescription();
33 assertThat(formattedErrorString, is(notNullValue()));
34
35 final String expectedFormattedString =
36 "An intent with the identifier INTENT-ID could not be created " +
37 "because one already exists.";
38 assertThat(formattedErrorString, is(equalTo(expectedFormattedString)));
39 }
40
41 /**
42 * Test the formatting of a REST error that contains two
43 * positional parameters.
44 */
45 @Test
46 public void testRestErrorFormatting2Parameters() {
47 final RestErrorCatalogEntry restErrorCatalogEntry =
Ray Milkey6fdd91d2014-07-30 16:27:07 -070048 RestErrorCatalog.getRestError(RestErrorCode.INTENT_NO_PATH);
Ray Milkeya8091b12014-05-16 14:42:47 -070049 assertThat(restErrorCatalogEntry, is(notNullValue()));
50
51 final RestError formattedError =
Ray Milkey6fdd91d2014-07-30 16:27:07 -070052 RestError.createRestError(RestErrorCode.INTENT_NO_PATH,
Ray Milkeya8091b12014-05-16 14:42:47 -070053 "Switch1", "Switch2");
54 final String formattedErrorString =
55 formattedError.getFormattedDescription();
56
57 assertThat(formattedErrorString, is(notNullValue()));
58
59 final String expectedFormattedString =
60 "No path found between Switch1 and Switch2";
61 assertThat(formattedErrorString, is(equalTo(expectedFormattedString)));
62 }
63
64 /**
65 * Make sure that the error formatter is a utility class.
66 */
67 @Test
68 public void assureThatErrorFormatterIsUtility() {
69 assertThatClassIsUtility(RestErrorFormatter.class);
70 }
71
72 /**
73 * Make sure that the error catalog is a utility class.
74 */
75 @Test
76 public void assureThatErrorCatalogIsUtility() {
77 assertThatClassIsUtility(RestErrorCatalog.class);
78 }
79
80 /**
Ray Milkeya8091b12014-05-16 14:42:47 -070081 * Make sure that the RestErrorCatalogEntry class is immutable.
82 */
83 @Test
84 public void assureThatRestErrorCatalogEntryIsImmutable() {
85 assertThatClassIsImmutable(RestErrorCatalogEntry.class);
86 }
87
88 /**
89 * Make sure that the RestErrorCatalogEntry class is immutable.
90 */
91 @Test
92 public void assureThatRestErrorIsImmutable() {
93 assertThatClassIsImmutable(RestError.class);
94 }
95}