f42eebb8ba375df5f7a3d7425d89fedaaccc8a6c
[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 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22 package org.onap.aai.rest;
23
24 import org.json.JSONObject;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.onap.aai.AAIJunitRunner;
29 import org.onap.aai.HttpTestUtil;
30 import org.onap.aai.PayloadUtil;
31 import org.skyscreamer.jsonassert.JSONAssert;
32
33 import javax.ws.rs.core.Response;
34 import java.util.HashMap;
35 import java.util.Map;
36
37 import static org.junit.Assert.assertEquals;
38
39 @RunWith(AAIJunitRunner.class)
40 public class GenericVnfLInterfaceTest {
41
42     private HttpTestUtil httpTestUtil;
43
44     @Before
45     public void setUp(){
46         httpTestUtil = new HttpTestUtil();
47     }
48
49     @Test
50     public void testPutTwoLInterfacesToGenericVnf() throws Exception {
51
52         Map<String, String> templateValueMap = new HashMap<>();
53         templateValueMap.put("ip-address", "ipv1");
54
55         String resource = PayloadUtil.getTemplatePayload("generic-vnf-with-lag-interface.json", templateValueMap);
56         Response response = httpTestUtil.doPut("/aai/v12/network/generic-vnfs/generic-vnf/vnf1", resource);
57         assertEquals("Expecting the generic vnf to be created", 201, response.getStatus());
58
59         response = httpTestUtil.doGet("/aai/v12/network/generic-vnfs/generic-vnf/vnf1");
60         assertEquals("Expecting the generic vnf to be updated", 200, response.getStatus());
61
62         resource = response.getEntity().toString().replaceAll("ipv1\",\"resource-version\":\"\\d+\"", "ipv2\"");
63         response = httpTestUtil.doPut("/aai/v12/network/generic-vnfs/generic-vnf/vnf1", resource);
64         assertEquals("Expecting the generic vnf to be updated", 200, response.getStatus());
65
66         response = httpTestUtil.doGet("/aai/v12/network/generic-vnfs/generic-vnf/vnf1");
67         assertEquals("Expecting the generic vnf to be updated", 200, response.getStatus());
68
69         String expected = PayloadUtil.getExpectedPayload("generic-vnf-with-lag-interface.json");
70         JSONAssert.assertEquals(expected, response.getEntity().toString(), false);
71
72         JSONObject jsonObject = new JSONObject(response.getEntity().toString());
73         String resourceVersion = (String) jsonObject.get("resource-version");
74
75         response = httpTestUtil.doDelete("/aai/v12/network/generic-vnfs/generic-vnf/vnf1", resourceVersion);
76         assertEquals("Expecting the generic vnf to be deleted", 204, response.getStatus());
77     }
78 }