Isolate deprecated code in CCSDK aai-service
[ccsdk/sli/adaptors.git] / aai-service / provider / src / test / java / org / onap / ccsdk / sli / adaptors / aai / GenericRequestTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.ccsdk.sli.adaptors.aai;
23
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.fail;
26
27 import java.io.File;
28 import java.io.UnsupportedEncodingException;
29 import java.net.MalformedURLException;
30 import java.net.URISyntaxException;
31 import java.net.URL;
32 import java.util.HashMap;
33 import java.util.Map;
34
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.v11.LInterface;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44
45 import com.fasterxml.jackson.databind.ObjectMapper;
46
47
48 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
49 public class GenericRequestTest {
50
51         private static final Logger LOG = LoggerFactory.getLogger(GenericRequestTest.class);
52
53         protected static AAIClient client;
54         protected static AAIRequest request;
55
56         @BeforeClass
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");
62         }
63
64         @AfterClass
65         public static void tearDown() throws Exception {
66                 client = null;
67                 LOG.info("----------------------- AAIResourceTest.tearDown -----------------------");
68         }
69
70         @Test
71         public void test001()
72         {
73                 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
74
75                 try
76                 {
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();
83
84                         assertNotNull(uri);
85
86                 }
87                 catch (Exception e)
88                 {
89                         LOG.error("Caught exception", e);
90                         fail("Caught exception");
91                 }
92         }
93
94         @Test
95         public void test002() {
96                 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
97                 try
98                 {
99                         URL resource = this.getClass().getResource("json/linterfaceJson.txt");
100
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");
105                         }
106
107                     ObjectMapper mapper = AAIService.getObjectMapper();
108                     LInterface request = mapper.readValue(requestFile, LInterface.class);
109                     String vnf_id = request.getInterfaceName();
110                     LOG.info(vnf_id);
111
112                 }
113                 catch (Exception e)
114                 {
115                         LOG.error("Caught exception", e);
116                 }
117         }
118
119 //    @Test
120 //      public void test003() {
121 //              LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
122 //              try
123 //              {
124 //                  String vnf_id = "4718302b-7884-4959-a499-f470c62418ff";
125 //
126 //                  GenericVnf genericVnf = client.requestGenericVnfData(vnf_id);
127 //
128 //                  client.deleteGenericVnfData(vnf_id, genericVnf.getResourceVersion());
129 //
130 //              }
131 //              catch (Throwable e)
132 //              {
133 //                      LOG.error("Caught exception", e);
134 //              }
135 //      }
136
137
138         @Test
139         public void test004() {
140                 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
141
142                 URL url;
143                 try {
144                         url = request.getRequestUrl("GET", null);
145                         assertNotNull(url);
146                 } catch (UnsupportedEncodingException | MalformedURLException | URISyntaxException exc) {
147                         LOG.error("Failed test", exc);
148                 }
149
150         }
151
152         @Test
153         public void runToJSONStringTest() {
154                 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
155
156                 try {
157                         String json = request.toJSONString();
158                         assertNotNull(json);
159                 } catch (Exception exc) {
160                         LOG.error("Failed test", exc);
161                 }
162
163         }
164
165         @Test
166         public void runGetArgsListTest() {
167                 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
168
169                 try {
170                         String[] args = request.getArgsList();
171                         assertNotNull(args);
172                 } catch (Exception exc) {
173                         LOG.error("Failed test", exc);
174                 }
175
176         }
177
178         @Test
179         public void runGetModelTest() {
180                 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
181
182                 try {
183                         Class<?  extends AAIDatum> clazz = request.getModelClass();
184                         assertNotNull(clazz);
185                 } catch (Exception exc) {
186                         LOG.error("Failed test", exc);
187                 }
188
189         }
190 }