2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.fail;
28 import java.io.UnsupportedEncodingException;
29 import java.net.MalformedURLException;
30 import java.net.URISyntaxException;
32 import java.util.HashMap;
35 import org.junit.AfterClass;
36 import org.junit.BeforeClass;
37 import org.junit.FixMethodOrder;
38 import org.junit.Test;
39 import org.junit.runners.MethodSorters;
40 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
41 import org.openecomp.aai.inventory.v13.LInterface;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
45 import com.fasterxml.jackson.databind.ObjectMapper;
48 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
49 public class GenericRequestTest {
51 private static final Logger LOG = LoggerFactory.getLogger(GenericRequestTest.class);
53 protected static AAIClient client;
54 protected static AAIRequest request;
57 public static void setUp() throws Exception {
58 URL url = AAIService.class.getResource(AAIService.AAICLIENT_PROPERTIES);
59 client = new AAIService(url);
60 request = AAIRequest.createRequest("generic-vnf", new HashMap<String, String>());
61 LOG.info("\nTaicAAIResourceTest.setUp\n");
65 public static void tearDown() throws Exception {
67 LOG.info("----------------------- AAIResourceTest.tearDown -----------------------");
73 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
77 Map<String, String> key = new HashMap<String, String>();
78 AAIRequest request = AAIRequest.createRequest("vserver", key);
79 key.put("vserver.vserver_id", "e8faf166-2402-4ae2-be45-067954c63aed");
80 key.put("tenant.tenant_id", "1863027683132547");
81 request.processRequestPathValues(key);
82 String uri = request.getTargetUri();
89 LOG.error("Caught exception", e);
90 fail("Caught exception");
95 public void test002() {
96 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
99 URL resource = this.getClass().getResource("json/linterfaceJson.txt");
101 LOG.info("Resource is " + resource.getFile());
102 File requestFile = new File(resource.getFile());
103 if(!requestFile.exists()) {
104 fail("Test file does not exist");
107 ObjectMapper mapper = AAIService.getObjectMapper();
108 LInterface request = mapper.readValue(requestFile, LInterface.class);
109 String vnf_id = request.getInterfaceName();
115 LOG.error("Caught exception", e);
120 // public void test003() {
121 // LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
124 // String vnf_id = "4718302b-7884-4959-a499-f470c62418ff";
126 // GenericVnf genericVnf = client.requestGenericVnfData(vnf_id);
128 // client.deleteGenericVnfData(vnf_id, genericVnf.getResourceVersion());
131 // catch (Throwable e)
133 // LOG.error("Caught exception", e);
139 public void test004() {
140 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
144 url = request.getRequestUrl("GET", null);
146 } catch (UnsupportedEncodingException | MalformedURLException | URISyntaxException exc) {
147 LOG.error("Failed test", exc);
153 public void runToJSONStringTest() {
154 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
157 String json = request.toJSONString();
159 } catch (Exception exc) {
160 LOG.error("Failed test", exc);
166 public void runGetArgsListTest() {
167 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
170 String[] args = request.getArgsList();
172 } catch (Exception exc) {
173 LOG.error("Failed test", exc);
179 public void runGetModelTest() {
180 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
183 Class<? extends AAIDatum> clazz = request.getModelClass();
184 assertNotNull(clazz);
185 } catch (Exception exc) {
186 LOG.error("Failed test", exc);