blob: c97eba297bc32cef04d4acf35b691eb7a1d22de2 [file] [log] [blame]
Ray Milkeyff710202014-05-23 16:55:18 -07001package net.onrc.onos.api.rest;
2
3import org.junit.Test;
4
5import java.util.HashSet;
6import java.util.Map;
7import java.util.Set;
8
9import static org.hamcrest.MatcherAssert.assertThat;
10import static org.hamcrest.Matchers.hasItem;
11import static org.hamcrest.Matchers.not;
12
13/**
14 * Tests to make sure that the error catalog is consistent.
15 */
16public class RestErrorCatalogTest {
17
18 /**
19 * Make sure that there are no duplicate entries in the catalog.
20 */
21 @Test
22 public void testNoDuplicatesInCatalog() {
23 final Set<RestErrorCodes.RestErrorCode> entriesSeen = new HashSet<>();
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();
43 for (final RestErrorCodes.RestErrorCode code : RestErrorCodes.RestErrorCode.values()) {
44 // There should be a RestErrorCatalogEntry for every code.
45 assertThat(catalogEntryMap.keySet(), hasItem(code.ordinal()));
46 }
47 }
48}