Ray Milkey | ff71020 | 2014-05-23 16:55:18 -0700 | [diff] [blame] | 1 | package net.onrc.onos.api.rest; |
| 2 | |
| 3 | import org.junit.Test; |
| 4 | |
| 5 | import java.util.HashSet; |
| 6 | import java.util.Map; |
| 7 | import java.util.Set; |
| 8 | |
| 9 | import static org.hamcrest.MatcherAssert.assertThat; |
| 10 | import static org.hamcrest.Matchers.hasItem; |
| 11 | import static org.hamcrest.Matchers.not; |
| 12 | |
| 13 | /** |
| 14 | * Tests to make sure that the error catalog is consistent. |
| 15 | */ |
| 16 | public class RestErrorCatalogTest { |
| 17 | |
| 18 | /** |
| 19 | * Make sure that there are no duplicate entries in the catalog. |
| 20 | */ |
| 21 | @Test |
| 22 | public void testNoDuplicatesInCatalog() { |
Ray Milkey | 6fdd91d | 2014-07-30 16:27:07 -0700 | [diff] [blame] | 23 | final Set<RestErrorCode> entriesSeen = new HashSet<>(); |
Ray Milkey | ff71020 | 2014-05-23 16:55:18 -0700 | [diff] [blame] | 24 | final RestErrorCatalogEntry[] rawEntries = RestErrorCatalog.getCatalogEntries(); |
| 25 | |
| 26 | for (final RestErrorCatalogEntry entry : rawEntries) { |
| 27 | // There should only be one entry for this code, if we have seen it |
| 28 | // before that's an error. |
| 29 | assertThat(entriesSeen, not(hasItem(entry.getCode()))); |
| 30 | |
| 31 | entriesSeen.add(entry.getCode()); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Make sure that each REST error code has an entry in the catalog. |
| 37 | */ |
| 38 | @Test |
| 39 | public void testAllCodesInCatalog() { |
| 40 | |
| 41 | final Map<Integer, RestErrorCatalogEntry> catalogEntryMap = |
| 42 | RestErrorCatalog.getRestErrorMap(); |
Ray Milkey | 6fdd91d | 2014-07-30 16:27:07 -0700 | [diff] [blame] | 43 | for (final RestErrorCode code : RestErrorCode.values()) { |
Ray Milkey | ff71020 | 2014-05-23 16:55:18 -0700 | [diff] [blame] | 44 | // There should be a RestErrorCatalogEntry for every code. |
| 45 | assertThat(catalogEntryMap.keySet(), hasItem(code.ordinal())); |
| 46 | } |
| 47 | } |
| 48 | } |