2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.aai.rest;
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;
42 import static org.junit.Assert.assertEquals;
44 @RunWith(value = Parameterized.class)
45 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
46 public class GenericVnfLInterfaceTest extends AAISetup {
48 private HttpTestUtil httpTestUtil;
51 @Parameterized.Parameter(value = 0)
52 public QueryStyle queryStyle;
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}
64 httpTestUtil = new HttpTestUtil(queryStyle);
68 public void testPutTwoLInterfacesToGenericVnf() throws Exception {
70 Map<String, String> templateValueMap = new HashMap<>();
71 templateValueMap.put("ip-address", "ipv1");
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());
77 response = httpTestUtil.doGet("/aai/v12/network/generic-vnfs/generic-vnf/vnf1");
78 assertEquals("Expecting the generic vnf to be updated", 200, response.getStatus());
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());
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());
92 String expected = PayloadUtil.getExpectedPayload("generic-vnf-with-lag-interface.json");
93 JSONAssert.assertEquals(expected, response.getEntity().toString(), false);
95 JSONObject jsonObject = new JSONObject(response.getEntity().toString());
96 String resourceVersion = (String) jsonObject.get("resource-version");
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());