Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [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 | package org.onosproject.vtnweb.resources; |
| 17 | |
Ray Milkey | 094a135 | 2018-01-22 14:03:54 -0800 | [diff] [blame^] | 18 | import com.eclipsesource.json.Json; |
| 19 | import com.eclipsesource.json.JsonObject; |
| 20 | import com.google.common.collect.Lists; |
| 21 | import org.junit.After; |
| 22 | import org.junit.Before; |
| 23 | import org.junit.Test; |
| 24 | import org.onlab.osgi.ServiceDirectory; |
| 25 | import org.onlab.osgi.TestServiceDirectory; |
| 26 | import org.onosproject.codec.CodecService; |
| 27 | import org.onosproject.vtnrsc.PortPairId; |
| 28 | import org.onosproject.vtnrsc.ServiceFunctionGroup; |
| 29 | import org.onosproject.vtnrsc.portchainsfmap.PortChainSfMapService; |
| 30 | import org.onosproject.vtnweb.web.SfcCodecContext; |
| 31 | |
| 32 | import javax.ws.rs.client.WebTarget; |
| 33 | import java.util.List; |
| 34 | import java.util.Map; |
| 35 | import java.util.concurrent.ConcurrentHashMap; |
| 36 | |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 37 | import static org.easymock.EasyMock.anyObject; |
| 38 | import static org.easymock.EasyMock.createMock; |
| 39 | import static org.easymock.EasyMock.expect; |
| 40 | import static org.easymock.EasyMock.replay; |
| 41 | import static org.hamcrest.Matchers.is; |
| 42 | import static org.hamcrest.Matchers.notNullValue; |
| 43 | import static org.junit.Assert.assertThat; |
| 44 | |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 45 | /** |
| 46 | * Unit tests for port chain sf map REST APIs. |
| 47 | */ |
| 48 | public 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 Milkey | 094a135 | 2018-01-22 14:03:54 -0800 | [diff] [blame^] | 68 | setServiceDirectory(testDirectory); |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 69 | } |
| 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 | } |