blob: e3866ce04ab069174b8a8f714869faed44eb3149 [file] [log] [blame]
Phaneendra Manda8db7d092016-06-04 00:17:24 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Phaneendra Manda8db7d092016-06-04 00:17:24 +05303 *
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 */
16package org.onosproject.vtnweb.resources;
17
Ray Milkey094a1352018-01-22 14:03:54 -080018import com.eclipsesource.json.Json;
19import com.eclipsesource.json.JsonObject;
20import com.google.common.collect.Lists;
21import org.junit.After;
22import org.junit.Before;
23import org.junit.Test;
24import org.onlab.osgi.ServiceDirectory;
25import org.onlab.osgi.TestServiceDirectory;
26import org.onosproject.codec.CodecService;
27import org.onosproject.vtnrsc.PortPairId;
28import org.onosproject.vtnrsc.ServiceFunctionGroup;
29import org.onosproject.vtnrsc.portchainsfmap.PortChainSfMapService;
30import org.onosproject.vtnweb.web.SfcCodecContext;
31
32import javax.ws.rs.client.WebTarget;
33import java.util.List;
34import java.util.Map;
35import java.util.concurrent.ConcurrentHashMap;
36
Phaneendra Manda8db7d092016-06-04 00:17:24 +053037import static org.easymock.EasyMock.anyObject;
38import static org.easymock.EasyMock.createMock;
39import static org.easymock.EasyMock.expect;
40import static org.easymock.EasyMock.replay;
41import static org.hamcrest.Matchers.is;
42import static org.hamcrest.Matchers.notNullValue;
43import static org.junit.Assert.assertThat;
44
Phaneendra Manda8db7d092016-06-04 00:17:24 +053045/**
46 * Unit tests for port chain sf map REST APIs.
47 */
48public class PortChainSfMapResourceTest extends VtnResourceTest {
49
50 final PortChainSfMapService portChainSfMapService = createMock(PortChainSfMapService.class);
51
52 String name1 = "Firewall";
53 String description1 = "Firewall service function";
54 Map<PortPairId, Integer> portPairLoadMap1 = new ConcurrentHashMap<>();
55
56 ServiceFunctionGroup serviceFunction1 = new ServiceFunctionGroup(name1, description1,
57 portPairLoadMap1);
58
59 /**
60 * Sets up the global values for all the tests.
61 */
62 @Before
63 public void setUpTest() {
64 SfcCodecContext context = new SfcCodecContext();
65 ServiceDirectory testDirectory = new TestServiceDirectory()
66 .add(PortChainSfMapService.class, portChainSfMapService)
67 .add(CodecService.class, context.codecManager());
Ray Milkey094a1352018-01-22 14:03:54 -080068 setServiceDirectory(testDirectory);
Phaneendra Manda8db7d092016-06-04 00:17:24 +053069 }
70
71 /**
72 * Cleans up.
73 */
74 @After
75 public void tearDownTest() {
76 }
77
78 /**
79 * Tests the result of a rest api GET for port chain id.
80 */
81 @Test
82 public void testGetPortChainId() {
83
84 final List<ServiceFunctionGroup> serviceFunctions = Lists.newArrayList();
85 serviceFunctions.add(serviceFunction1);
86
87 expect(portChainSfMapService.getServiceFunctions(anyObject())).andReturn(serviceFunctions).anyTimes();
88 replay(portChainSfMapService);
89
90 final WebTarget wt = target();
91 final String response = wt.path("portChainSfMap/1278dcd4-459f-62ed-754b-87fc5e4a6751").request()
92 .get(String.class);
93 final JsonObject result = Json.parse(response).asObject();
94 assertThat(result, notNullValue());
95 assertThat(result.names().get(0), is("portChainSfMap"));
96 }
97}