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