Charles Chan | cab494d | 2016-11-11 16:31:49 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Charles Chan | cab494d | 2016-11-11 16:31:49 -0800 | [diff] [blame] | 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 | |
Ray Milkey | 69ec871 | 2017-08-08 13:00:43 -0700 | [diff] [blame] | 17 | package org.onosproject.routeservice; |
Charles Chan | cab494d | 2016-11-11 16:31:49 -0800 | [diff] [blame] | 18 | |
| 19 | import com.fasterxml.jackson.databind.JsonNode; |
| 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 21 | import com.google.common.collect.ImmutableSet; |
| 22 | import org.junit.Before; |
| 23 | import org.junit.Test; |
| 24 | import org.onlab.packet.IpAddress; |
| 25 | import org.onlab.packet.IpPrefix; |
| 26 | import org.onosproject.TestApplicationId; |
| 27 | import org.onosproject.core.ApplicationId; |
| 28 | import org.onosproject.net.config.Config; |
| 29 | import org.onosproject.net.config.ConfigApplyDelegate; |
| 30 | |
| 31 | import java.io.InputStream; |
| 32 | import java.util.Set; |
| 33 | |
| 34 | import static org.hamcrest.Matchers.is; |
| 35 | import static org.hamcrest.Matchers.not; |
| 36 | import static org.junit.Assert.*; |
| 37 | |
| 38 | /** |
| 39 | * Tests for class {@link RouteConfigTest}. |
| 40 | */ |
| 41 | public class RouteConfigTest { |
| 42 | private static final String KEY = "org.onosproject.routing"; |
| 43 | |
| 44 | private static final IpPrefix PREFIX1 = IpPrefix.valueOf("10.0.0.1/24"); |
| 45 | private static final IpPrefix PREFIX2 = IpPrefix.valueOf("20.0.0.1/24"); |
| 46 | private static final IpPrefix PREFIX3 = IpPrefix.valueOf("30.0.0.1/24"); |
| 47 | private static final IpAddress NEXTHOP1 = IpAddress.valueOf("192.168.1.1"); |
| 48 | private static final IpAddress NEXTHOP2 = IpAddress.valueOf("192.168.2.1"); |
| 49 | private static final Route ROUTE1 = new Route(Route.Source.STATIC, PREFIX1, NEXTHOP1); |
| 50 | private static final Route ROUTE2 = new Route(Route.Source.STATIC, PREFIX2, NEXTHOP1); |
| 51 | private static final Route ROUTE3 = new Route(Route.Source.STATIC, PREFIX3, NEXTHOP2); |
| 52 | private static final Set<Route> EXPECTED_ROUTES = ImmutableSet.of(ROUTE1, ROUTE2, ROUTE3); |
| 53 | private static final Set<Route> UNEXPECTED_ROUTES = ImmutableSet.of(ROUTE1, ROUTE2); |
| 54 | |
| 55 | private RouteConfig config; |
| 56 | |
| 57 | @Before |
| 58 | public void setUp() throws Exception { |
| 59 | InputStream jsonStream = RouteConfigTest.class |
| 60 | .getResourceAsStream("/route-config.json"); |
| 61 | ApplicationId subject = new TestApplicationId(KEY); |
| 62 | ObjectMapper mapper = new ObjectMapper(); |
| 63 | JsonNode jsonNode = mapper.readTree(jsonStream); |
| 64 | ConfigApplyDelegate delegate = new MockDelegate(); |
| 65 | |
| 66 | config = new RouteConfig(); |
| 67 | config.init(subject, KEY, jsonNode, mapper, delegate); |
| 68 | } |
| 69 | |
| 70 | @Test |
| 71 | public void getRoutes() throws Exception { |
| 72 | assertThat(config.getRoutes(), is(EXPECTED_ROUTES)); |
| 73 | assertThat(config.getRoutes(), not(UNEXPECTED_ROUTES)); |
| 74 | } |
| 75 | |
| 76 | private class MockDelegate implements ConfigApplyDelegate { |
| 77 | @Override |
| 78 | public void onApply(Config config) { |
| 79 | } |
| 80 | } |
Ray Milkey | 69ec871 | 2017-08-08 13:00:43 -0700 | [diff] [blame] | 81 | } |