Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.net.config.basics; |
| 18 | |
| 19 | import com.fasterxml.jackson.databind.JsonNode; |
| 20 | import com.google.common.collect.ImmutableSet; |
| 21 | import org.junit.Before; |
| 22 | import org.junit.Test; |
| 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.region.Region; |
| 25 | |
| 26 | import java.util.List; |
| 27 | import java.util.Set; |
| 28 | |
| 29 | import static org.junit.Assert.assertEquals; |
| 30 | import static org.junit.Assert.assertTrue; |
| 31 | import static org.onosproject.net.region.RegionId.regionId; |
| 32 | |
| 33 | /** |
| 34 | * Test class for {@link BasicRegionConfig}. |
| 35 | */ |
| 36 | public class BasicRegionConfigTest extends AbstractConfigTest { |
| 37 | |
| 38 | private static final String REGION_JSON = "configs.regions.1.json"; |
| 39 | private static final String R1 = "r1"; |
| 40 | private static final String R2 = "r2"; |
| 41 | private static final String R3 = "r3"; |
| 42 | |
| 43 | private static final Set<DeviceId> R1_DEVS = |
| 44 | ImmutableSet.of(dstr("01"), dstr("02"), dstr("03")); |
| 45 | private static final Set<DeviceId> R2_DEVS = |
| 46 | ImmutableSet.of(dstr("04"), dstr("05"), dstr("06")); |
| 47 | private static final Set<DeviceId> R3_DEVS = |
| 48 | ImmutableSet.of(dstr("07"), dstr("08"), dstr("09")); |
| 49 | |
| 50 | |
| 51 | private JsonNode data; |
| 52 | |
| 53 | @Before |
| 54 | public void setUp() { |
| 55 | data = getTestJson(REGION_JSON); |
| 56 | } |
| 57 | |
| 58 | private JsonNode getR(String key) { |
| 59 | return data.get("regions").get(key).get("basic"); |
| 60 | } |
| 61 | |
| 62 | private void checkRegion(String rid, Region.Type expT, Set<DeviceId> expD) { |
| 63 | JsonNode r1json = getR(rid); |
| 64 | print(r1json); |
| 65 | |
| 66 | BasicRegionConfig brc = new BasicRegionConfig(); |
| 67 | brc.init(regionId(rid), rid, r1json, mapper, delegate); |
| 68 | |
| 69 | Region.Type type = brc.getType(); |
| 70 | assertEquals("wrong type", expT, type); |
| 71 | |
| 72 | List<DeviceId> devs = brc.getDevices(); |
| 73 | assertEquals("wr.size", expD.size(), devs.size()); |
| 74 | for (DeviceId d : expD) { |
| 75 | assertTrue("missing dev: " + d, devs.contains(d)); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | @Test |
| 80 | public void region1Config() { |
| 81 | checkRegion(R1, Region.Type.CONTINENT, R1_DEVS); |
| 82 | } |
| 83 | |
| 84 | @Test |
| 85 | public void region2Config() { |
| 86 | checkRegion(R2, Region.Type.METRO, R2_DEVS); |
| 87 | } |
| 88 | |
| 89 | @Test |
| 90 | public void region3Config() { |
| 91 | checkRegion(R3, null, R3_DEVS); |
| 92 | } |
| 93 | |
| 94 | } |