minor updates to clean up code
[ccsdk/sli/adaptors.git] / aai-service / provider / src / test / java / org / onap / ccsdk / sli / adaptors / aai / EchoRequestTest.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
26 import java.io.UnsupportedEncodingException;
27 import java.net.MalformedURLException;
28 import java.net.URISyntaxException;
29 import java.net.URL;
30
31 import org.junit.AfterClass;
32 import org.junit.BeforeClass;
33 import org.junit.FixMethodOrder;
34 import org.junit.Test;
35 import org.junit.runners.MethodSorters;
36 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41
42 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
43 public class EchoRequestTest {
44
45     private static final Logger LOG = LoggerFactory.getLogger(EchoRequestTest.class);
46
47     private static EchoRequest request;
48     private static AAIService aaiService;
49
50     @BeforeClass
51     public static void setUp() throws Exception {
52         aaiService = new AAIService(
53                 AAIService.class.getResource(AAIService.AAICLIENT_PROPERTIES));
54         request = new EchoRequest();
55         LOG.info("\nEchoRequestTest.setUp\n");
56     }
57
58     @AfterClass
59     public static void tearDown() throws Exception {
60         request = null;
61         LOG.info("----------------------- EchoRequestTest.tearDown -----------------------");
62     }
63
64     @Test
65     public void runGetRequestUrlTest() {
66         LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
67
68         URL url;
69         try {
70             url = request.getRequestUrl("GET", null);
71             assertNotNull(url);
72         } catch (UnsupportedEncodingException | MalformedURLException exc) {
73             LOG.error("Failed test", exc);
74                 }
75
76     }
77
78     @Test
79     public void runToJSONStringTest() {
80         LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
81
82         try {
83             String json = request.toJSONString();
84             assertNotNull(json);
85         } catch (Exception exc) {
86             LOG.error("Failed test", exc);
87         }
88
89     }
90
91     @Test
92     public void runGetArgsListTest() {
93         LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
94
95         try {
96             String[] args = request.getArgsList();
97             assertNotNull(args);
98         } catch (Exception exc) {
99             LOG.error("Failed test", exc);
100         }
101
102     }
103
104     @Test
105     public void runGetModelTest() {
106         LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
107
108         try {
109             Class<?  extends AAIDatum> clazz = request.getModelClass();
110             assertNotNull(clazz);
111         } catch (Exception exc) {
112             LOG.error("Failed test", exc);
113         }
114
115     }
116     
117 //      @Test
118         public void EchoTest() {
119                 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
120                 try
121                 {
122                         SvcLogicContext ctx = new SvcLogicContext();
123                         
124                         QueryStatus resp = null;
125
126 //                 (String resource, boolean localOnly, String select, String key, String prefix, String orderBy, SvcLogicContext ctx)
127                         resp = aaiService.query("echo", false, null, "",        "aaidata", null, ctx);
128                         assert(resp == QueryStatus.SUCCESS);
129                 }
130                 catch (Throwable e)
131                 {
132                         LOG.error("Caught exception", e);
133 //                      fail("Caught exception");
134                 }
135         }
136 }