2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.sli.adaptors.aai;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
26 import static org.junit.Assert.fail;
29 import java.io.IOException;
31 import java.nio.charset.StandardCharsets;
32 import java.nio.file.Files;
33 import java.nio.file.Paths;
34 import java.util.ArrayList;
35 import java.util.HashMap;
36 import java.util.List;
38 import java.util.Properties;
39 import java.util.UUID;
41 import org.apache.commons.lang.StringUtils;
42 import org.junit.AfterClass;
43 import org.junit.BeforeClass;
44 import org.junit.FixMethodOrder;
45 import org.junit.Test;
46 import org.junit.runners.MethodSorters;
47 import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
48 import org.onap.ccsdk.sli.adaptors.aai.AAIRequest;
49 import org.onap.ccsdk.sli.adaptors.aai.AAIService;
50 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
51 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
52 import org.onap.aai.inventory.v14.GenericVnf;
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
56 import com.fasterxml.jackson.databind.ObjectMapper;
58 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
59 public class GenericVnfTest {
61 private static final Logger LOG = LoggerFactory.getLogger(GenericVnfTest.class);
63 protected static AAIClient client;
66 public static void setUp() throws Exception {
67 Properties properties = new Properties();
68 properties.setProperty("org.onap.ccsdk.sli.adaptors.aai.host.certificate.ignore", "true");
69 properties.setProperty("org.onap.ccsdk.sli.adaptors.aai.client.name", "SDNC");
70 properties.setProperty("org.onap.ccsdk.sli.adaptors.aai.client.psswd", "SDNC");
71 properties.setProperty("org.onap.ccsdk.sli.adaptors.aai.application", "CCSDK");
72 properties.setProperty("org.onap.ccsdk.sli.adaptors.aai.uri", "http://localhost:8181");
73 properties.setProperty("connection.timeout", "60000");
74 properties.setProperty("read.timeout", "60000");
75 client = new AAIService(properties);
76 ((AAIService)client).setExecutor(new TestExecutor());
77 LOG.info("\nTaicAAIResourceTest.setUp\n");
81 public static void tearDown() throws Exception {
83 LOG.info("----------------------- GenericVnfTest.tearDown -----------------------");
88 public void test01SaveGenericVnf() {
89 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
92 SvcLogicContext ctx = new SvcLogicContext();
94 String uuid = UUID.randomUUID().toString();
95 Map<String, String> data = new HashMap<String, String>();
96 data.put("vnf-id", uuid);
97 data.put("vnf-name" , "Demo-vmtn5scpx01");
98 data.put("vnf-type", "asc_heat-int");
99 data.put("service-id", "SDN-MOBILITY");
100 data.put("equipment-role", "vSCP");
101 data.put("orchestration-status", "active");
102 data.put("heat-stack-id", "Devmtn5scpx04/" + data.get("vnf-id"));
103 data.put("in-maint", "false");
104 data.put("is-closed-loop-disabled", "false");
105 data.put("encrypted-access-flag","true");
107 QueryStatus resp = client.save("generic-vnf", false, false, "generic-vnf.vnf-id = '"+uuid+"'", data, "aaidata", ctx);
117 public void test02QueryGenericVnf()
119 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
123 List<String> keys = new ArrayList<String>();
124 keys.add("vnf-id = 'ec14a84d-7b43-45ad-bb04-c12b74083648'");
125 keys.add("depth = 'all'");
127 SvcLogicContext ctx = new SvcLogicContext();
128 QueryStatus response = client.query("generic-vnf", false, null, StringUtils.join(keys, " AND "), "aaiTest", null, ctx);
130 assertTrue(response == QueryStatus.SUCCESS);
131 LOG.info("AAIResponse: " + response.toString());
135 LOG.error("Caught exception", e);
136 fail("Caught exception");
141 public void test03UpdateGenericVnf() {
142 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
145 SvcLogicContext ctx = new SvcLogicContext();
147 String uuid = UUID.randomUUID().toString();
148 Map<String, String> data = new HashMap<String, String>();
149 data.put("service-id", "SDN-MOBILITY");
150 data.put("equipment-role", "vSCP");
151 data.put("orchestration-status", "active");
152 data.put("heat-stack-id", "Devmtn5scpx04/" + data.get("vnf-id"));
153 data.put("in-maint", "false");
154 data.put("is-closed-loop-disabled", "false");
155 data.put("encrypted-access-flag","true");
157 QueryStatus resp = client.update("generic-vnf", "generic-vnf.vnf-id = '"+uuid+"'", data, "aaidata", ctx);
167 public void test04DeleteGenericVnf()
169 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
173 SvcLogicContext ctx = new SvcLogicContext();
175 List<String> keys = new ArrayList<String>();
176 keys.add("generic-vnf.vnf-id = 'VNF-S7'");
178 QueryStatus response = client.delete("generic-vnf", StringUtils.join(keys, " AND "), ctx);
180 assertTrue(response == QueryStatus.SUCCESS);
181 LOG.info("AAIResponse: " + response.toString());
185 LOG.error("Caught exception", e);
186 fail("Caught exception");
191 public void test05GetResource()
193 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
197 SvcLogicContext ctx = new SvcLogicContext();
198 GenericVnf response = ((AAIService)client).getResource("/network/generic-vnfs/generic-vnf/ec14a84d-7b43-45ad-bb04-c12b74083648", GenericVnf.class);
200 assertNotNull(response);
208 static class TestExecutor implements AAIExecutorInterface {
209 private String data = "{\"vnf-id\":\"7324200933\",\"vnf-name\":\"vnfinst1m001\",\"vnf-type\":\"TestVnf\",\"service-id\":\"9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb\",\"equipment-role\":\"vTEST\",\"orchestration-status\":\"active\",\"in-maint\":false,\"is-closed-loop-disabled\":false,\"resource-version\":\"1520720941585\"}";
212 public String get(AAIRequest request) throws AAIServiceException {
217 public String post(AAIRequest request) throws AAIServiceException {
222 public Boolean delete(AAIRequest request, String resourceVersion) throws AAIServiceException {
227 public Object query(AAIRequest request, Class clas) throws AAIServiceException {
228 ObjectMapper mapper = AAIService.getObjectMapper();
230 return mapper.readValue(data, GenericVnf.class);
231 } catch (IOException e) {
232 return new GenericVnf();
237 public Boolean patch(AAIRequest request, String resourceVersion) throws AAIServiceException {