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 = |
Ray Milkey | 6fdd91d | 2014-07-30 16:27:07 -0700 | [diff] [blame] | 25 | RestErrorCatalog.getRestError(RestErrorCode.INTENT_ALREADY_EXISTS); |
Ray Milkey | a8091b1 | 2014-05-16 14:42:47 -0700 | [diff] [blame] | 26 | assertThat(restErrorCatalogEntry, is(notNullValue())); |
| 27 | |
| 28 | final RestError formattedError = |
Ray Milkey | 6fdd91d | 2014-07-30 16:27:07 -0700 | [diff] [blame] | 29 | RestError.createRestError(RestErrorCode.INTENT_ALREADY_EXISTS, |
Ray Milkey | a8091b1 | 2014-05-16 14:42:47 -0700 | [diff] [blame] | 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 = |
Ray Milkey | 6fdd91d | 2014-07-30 16:27:07 -0700 | [diff] [blame] | 48 | RestErrorCatalog.getRestError(RestErrorCode.INTENT_NO_PATH); |
Ray Milkey | a8091b1 | 2014-05-16 14:42:47 -0700 | [diff] [blame] | 49 | assertThat(restErrorCatalogEntry, is(notNullValue())); |
| 50 | |
| 51 | final RestError formattedError = |
Ray Milkey | 6fdd91d | 2014-07-30 16:27:07 -0700 | [diff] [blame] | 52 | RestError.createRestError(RestErrorCode.INTENT_NO_PATH, |
Ray Milkey | a8091b1 | 2014-05-16 14:42:47 -0700 | [diff] [blame] | 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 | /** |
Ray Milkey | a8091b1 | 2014-05-16 14:42:47 -0700 | [diff] [blame] | 81 | * 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 | } |