Add plugin to check coverage
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / rest / GenericVnfLInterfaceTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.aai.rest;
21
22 import org.json.JSONObject;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.junit.runners.Parameterized;
27 import org.onap.aai.AAIJunitRunner;
28 import org.onap.aai.AAISetup;
29 import org.onap.aai.HttpTestUtil;
30 import org.onap.aai.PayloadUtil;
31 import org.onap.aai.serialization.engines.QueryStyle;
32 import org.skyscreamer.jsonassert.JSONAssert;
33
34 import javax.ws.rs.core.Response;
35 import java.util.Arrays;
36 import java.util.Collection;
37 import java.util.HashMap;
38 import java.util.Map;
39
40 import static org.junit.Assert.assertEquals;
41
42 @RunWith(value = AAIJunitRunner.class)
43 public class GenericVnfLInterfaceTest extends AAISetup {
44
45     private HttpTestUtil httpTestUtil;
46
47     @Parameterized.Parameter(value = 0)
48     public QueryStyle queryStyle;
49
50     @Parameterized.Parameters(name = "QueryStyle.{0}")
51     public static Collection<Object[]> data() {
52         return Arrays.asList(new Object[][]{
53                 {QueryStyle.TRAVERSAL}
54         });
55     }
56
57     @Before
58     public void setUp(){
59         httpTestUtil = new HttpTestUtil(queryStyle);
60     }
61
62     @Test
63     public void testPutTwoLInterfacesToGenericVnf() throws Exception {
64
65         Map<String, String> templateValueMap = new HashMap<>();
66         templateValueMap.put("ip-address", "ipv1");
67
68         String resource = PayloadUtil.getTemplatePayload("generic-vnf-with-lag-interface.json", templateValueMap);
69         Response response = httpTestUtil.doPut("/aai/v12/network/generic-vnfs/generic-vnf/vnf1", resource);
70         assertEquals("Expecting the generic vnf to be created", 201, response.getStatus());
71
72         response = httpTestUtil.doGet("/aai/v12/network/generic-vnfs/generic-vnf/vnf1");
73         assertEquals("Expecting the generic vnf to be updated", 200, response.getStatus());
74
75         resource = response.getEntity().toString();
76         resource = resource.replaceAll("ipv1\",\"resource-version\":\"\\d+\"", "ipv2\"");
77         response = httpTestUtil.doPut("/aai/v12/network/generic-vnfs/generic-vnf/vnf1", resource);
78         assertEquals("Expecting the generic vnf to be updated", 200, response.getStatus());
79
80         response = httpTestUtil.doGet("/aai/v12/network/generic-vnfs/generic-vnf/vnf1");
81         assertEquals("Expecting the generic vnf to be updated", 200, response.getStatus());
82
83         String expected = PayloadUtil.getExpectedPayload("generic-vnf-with-lag-interface.json");
84         JSONAssert.assertEquals(expected, response.getEntity().toString(), false);
85
86         JSONObject jsonObject = new JSONObject(response.getEntity().toString());
87         String resourceVersion = (String) jsonObject.get("resource-version");
88
89         response = httpTestUtil.doDelete("/aai/v12/network/generic-vnfs/generic-vnf/vnf1", resourceVersion);
90         assertEquals("Expecting the generic vnf to be deleted", 204, response.getStatus());
91     }
92 }