Ray Milkey | a8091b1 | 2014-05-16 14:42:47 -0700 | [diff] [blame] | 1 | package net.onrc.onos.api.rest; |
| 2 | |
| 3 | import org.junit.Test; |
| 4 | |
| 5 | import static net.onrc.onos.core.util.ImmutableClassChecker.assertThatClassIsImmutable; |
| 6 | import static net.onrc.onos.core.util.UtilityClassChecker.assertThatClassIsUtility; |
| 7 | import static org.hamcrest.MatcherAssert.assertThat; |
| 8 | import static org.hamcrest.Matchers.equalTo; |
| 9 | import static org.hamcrest.Matchers.is; |
| 10 | import static org.hamcrest.Matchers.notNullValue; |
| 11 | |
| 12 | |
| 13 | /** |
| 14 | * Unit tests for REST error handling classes. |
| 15 | */ |
| 16 | public 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 = |
| 25 | RestErrorCatalog.getRestError(RestErrorCodes.RestErrorCode.INTENT_ALREADY_EXISTS); |
| 26 | assertThat(restErrorCatalogEntry, is(notNullValue())); |
| 27 | |
| 28 | final RestError formattedError = |
| 29 | RestError.createRestError(RestErrorCodes.RestErrorCode.INTENT_ALREADY_EXISTS, |
| 30 | "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 = |
| 48 | RestErrorCatalog.getRestError(RestErrorCodes.RestErrorCode.INTENT_NO_PATH); |
| 49 | assertThat(restErrorCatalogEntry, is(notNullValue())); |
| 50 | |
| 51 | final RestError formattedError = |
| 52 | RestError.createRestError(RestErrorCodes.RestErrorCode.INTENT_NO_PATH, |
| 53 | "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 | /** |
| 81 | * Make sure that the error codes is a utility class. |
| 82 | */ |
| 83 | @Test |
| 84 | public void assureThatErrorCodesIsUtility() { |
| 85 | assertThatClassIsUtility(RestErrorCodes.class); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Make sure that the RestErrorCatalogEntry class is immutable. |
| 90 | */ |
| 91 | @Test |
| 92 | public void assureThatRestErrorCatalogEntryIsImmutable() { |
| 93 | assertThatClassIsImmutable(RestErrorCatalogEntry.class); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Make sure that the RestErrorCatalogEntry class is immutable. |
| 98 | */ |
| 99 | @Test |
| 100 | public void assureThatRestErrorIsImmutable() { |
| 101 | assertThatClassIsImmutable(RestError.class); |
| 102 | } |
| 103 | } |