60519b1a0a0fe280d1d748b9b027aee089adf226
[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.After;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.junit.runners.Parameterized;
28 import org.onap.aai.AAISetup;
29 import org.onap.aai.HttpTestUtil;
30 import org.onap.aai.PayloadUtil;
31 import org.onap.aai.exceptions.AAIException;
32 import org.onap.aai.serialization.engines.QueryStyle;
33 import org.skyscreamer.jsonassert.JSONAssert;
34 import org.springframework.test.annotation.DirtiesContext;
35 import javax.ws.rs.core.Response;
36 import java.io.IOException;
37 import java.util.Arrays;
38 import java.util.Collection;
39 import java.util.HashMap;
40 import java.util.Map;
41
42 import static org.junit.Assert.assertEquals;
43
44 @RunWith(value = Parameterized.class)
45 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
46 public class GenericVnfLInterfaceTest extends AAISetup {
47
48     private HttpTestUtil httpTestUtil;
49    
50
51     @Parameterized.Parameter(value = 0)
52     public QueryStyle queryStyle;
53
54     @Parameterized.Parameters(name = "QueryStyle.{0}")
55     public static Collection<Object[]> data() {
56         return Arrays.asList(new Object[][]{
57                 {QueryStyle.TRAVERSAL},
58                 {QueryStyle.TRAVERSAL_URI}
59         });
60     }
61
62     @Before
63     public void setUp(){
64         httpTestUtil = new HttpTestUtil(queryStyle);
65     }
66
67     @Test
68     public void testPutTwoLInterfacesToGenericVnf() throws Exception {
69
70         Map<String, String> templateValueMap = new HashMap<>();
71         templateValueMap.put("ip-address", "ipv1");
72
73         String resource = PayloadUtil.getTemplatePayload("generic-vnf-with-lag-interface.json", templateValueMap);
74         Response response = httpTestUtil.doPut("/aai/v12/network/generic-vnfs/generic-vnf/vnf1", resource);
75         assertEquals("Expecting the generic vnf to be created", 201, response.getStatus());
76
77         response = httpTestUtil.doGet("/aai/v12/network/generic-vnfs/generic-vnf/vnf1");
78         assertEquals("Expecting the generic vnf to be updated", 200, response.getStatus());
79
80         resource = response.getEntity().toString();
81         resource = resource.replaceAll("ipv1\",\"resource-version\":\"\\d+\"", "ipv2\"");
82         response = httpTestUtil.doPut("/aai/v12/network/generic-vnfs/generic-vnf/vnf1", resource);
83         assertEquals("Expecting the generic vnf to be updated", 200, response.getStatus());
84
85     }
86
87     @After
88     public void tearDown() throws IOException, AAIException {
89         Response response = httpTestUtil.doGet("/aai/v12/network/generic-vnfs/generic-vnf/vnf1");
90         assertEquals("Expecting the generic vnf to be updated", 200, response.getStatus());
91
92         String expected = PayloadUtil.getExpectedPayload("generic-vnf-with-lag-interface.json");
93         JSONAssert.assertEquals(expected, response.getEntity().toString(), false);
94
95         JSONObject jsonObject = new JSONObject(response.getEntity().toString());
96         String resourceVersion = (String) jsonObject.get("resource-version");
97
98         response = httpTestUtil.doDelete("/aai/v12/network/generic-vnfs/generic-vnf/vnf1", resourceVersion);
99         assertEquals("Expecting the generic vnf to be deleted", 204, response.getStatus());
100     }
101 }