blob: 1e48420f7f9f468513232504f9a712f2cf2cf9cc [file] [log] [blame]
Charles Chancab494d2016-11-11 16:31:49 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Charles Chancab494d2016-11-11 16:31:49 -08003 *
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 Milkey69ec8712017-08-08 13:00:43 -070017package org.onosproject.routeservice;
Charles Chancab494d2016-11-11 16:31:49 -080018
19import com.fasterxml.jackson.databind.JsonNode;
20import com.fasterxml.jackson.databind.ObjectMapper;
21import com.google.common.collect.ImmutableSet;
22import org.junit.Before;
23import org.junit.Test;
24import org.onlab.packet.IpAddress;
25import org.onlab.packet.IpPrefix;
26import org.onosproject.TestApplicationId;
27import org.onosproject.core.ApplicationId;
28import org.onosproject.net.config.Config;
29import org.onosproject.net.config.ConfigApplyDelegate;
30
31import java.io.InputStream;
32import java.util.Set;
33
34import static org.hamcrest.Matchers.is;
35import static org.hamcrest.Matchers.not;
36import static org.junit.Assert.*;
37
38/**
39 * Tests for class {@link RouteConfigTest}.
40 */
41public 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 Milkey69ec8712017-08-08 13:00:43 -070081}