Ray Milkey | fbfd2da | 2014-05-09 17:30:14 -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.UtilityClassChecker.assertThatClassIsUtility; |
| 6 | import static org.hamcrest.MatcherAssert.assertThat; |
| 7 | import static org.hamcrest.Matchers.*; |
| 8 | |
| 9 | |
| 10 | /** |
| 11 | * Unit tests for REST error handling classes. |
| 12 | */ |
| 13 | public class RestErrorTest { |
| 14 | |
| 15 | /** |
| 16 | * Test the formatting of a REST error that contains a single |
| 17 | * positional parameter. |
| 18 | */ |
| 19 | @Test |
| 20 | public void testRestErrorFormatting1Parameter() { |
| 21 | final RestError restError = |
| 22 | RestErrorCatalog.getRestError(RestErrorCodes.RestErrorCode.INTENT_ALREADY_EXISTS); |
| 23 | assertThat(restError, is(notNullValue())); |
| 24 | |
| 25 | final String formattedError = |
| 26 | RestErrorFormatter.formatErrorMessage(restError, |
| 27 | "INTENT-ID"); |
| 28 | assertThat(formattedError, is(notNullValue())); |
| 29 | |
| 30 | final String expectedFormattedString = |
| 31 | "An intent with the identifier INTENT-ID could not be created " + |
| 32 | "because one already exists."; |
| 33 | assertThat(formattedError, is(equalTo(expectedFormattedString))); |
| 34 | |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Test the formatting of a REST error that contains two |
| 39 | * positional parameters. |
| 40 | */ |
| 41 | @Test |
| 42 | public void testRestErrorFormatting2Parameters() { |
| 43 | final RestError restError = |
| 44 | RestErrorCatalog.getRestError(RestErrorCodes.RestErrorCode.INTENT_NO_PATH); |
| 45 | assertThat(restError, is(notNullValue())); |
| 46 | |
| 47 | final String formattedError = |
| 48 | RestErrorFormatter.formatErrorMessage(restError, |
| 49 | "Switch1", "Switch2"); |
| 50 | assertThat(formattedError, is(notNullValue())); |
| 51 | |
| 52 | final String expectedFormattedString = |
| 53 | "No path found between Switch1 and Switch2"; |
| 54 | assertThat(formattedError, is(equalTo(expectedFormattedString))); |
| 55 | |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Make sure that the error formatter is a utility class. |
| 60 | */ |
| 61 | @Test |
| 62 | public void assureThatErrorFormatterIsUtility() { |
| 63 | assertThatClassIsUtility(RestErrorFormatter.class); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Make sure that the error catalog is a utility class. |
| 68 | */ |
| 69 | @Test |
| 70 | public void assureThatErrorCatalogIsUtility() { |
| 71 | assertThatClassIsUtility(RestErrorCatalog.class); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Make sure that the error codes is a utility class. |
| 76 | */ |
| 77 | @Test |
| 78 | public void assureThatErrorCodesIsUtility() { |
| 79 | assertThatClassIsUtility(RestErrorCodes.class); |
| 80 | } |
| 81 | } |