Change nexus values to properties
[appc.git] / appc-adapters / appc-rest-adapter / appc-rest-adapter-bundle / src / test / java / org / openecomp / appc / adapter / rest / impl / TestRestAdapterImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-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.openecomp.appc.adapter.rest.impl;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
27 import static org.junit.Assert.fail;
28
29 import java.io.IOException;
30 import java.lang.reflect.Field;
31 import java.util.HashMap;
32 import java.util.List;
33 import java.util.Map;
34 import java.util.Properties;
35 import java.util.Set;
36
37 import org.junit.Before;
38 import org.junit.BeforeClass;
39 import org.junit.Ignore;
40 import org.junit.Test;
41 import org.slf4j.MDC;
42
43 import org.openecomp.appc.Constants;
44 import org.openecomp.appc.adapter.rest.RestAdapter;
45 import org.openecomp.appc.configuration.ConfigurationFactory;
46 import org.openecomp.appc.exceptions.APPCException;
47 import org.openecomp.appc.exceptions.UnknownProviderException;
48 import com.att.cdp.exceptions.ZoneException;
49 import com.att.cdp.zones.ComputeService;
50 import com.att.cdp.zones.Context;
51 import com.att.cdp.zones.ContextFactory;
52 import com.att.cdp.zones.model.Server;
53 import com.att.cdp.zones.model.Server.Status;
54 import org.openecomp.sdnc.sli.SvcLogicContext;
55
56
57 /**
58  * Test the ProviderAdapter implementation.
59  */
60
61 @Ignore
62 public class TestRestAdapterImpl {
63
64     @SuppressWarnings("nls")
65     private static final String PROVIDER_NAME = "APPC";
66
67     @SuppressWarnings("nls")
68     private static final String PROVIDER_TYPE = "OpenStackProvider";
69
70     private static String IDENTITY_URL;
71
72     private static String PRINCIPAL;
73
74     private static String CREDENTIAL;
75
76     private static String TENANT_NAME;
77
78     private static String TENANT_ID;
79
80     private static String USER_ID;
81
82     private static String REGION_NAME;
83
84     private static String SERVER_URL;
85
86     private static Class<?> providerAdapterImplClass;
87     private static Class<?> configurationFactoryClass;
88     private static Field providerCacheField;
89     private static Field configField;
90
91     private RestAdapterImpl adapter;
92
93
94     @SuppressWarnings("nls")
95     @BeforeClass
96     public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException {
97
98     }
99
100     @Before
101     public void setup() throws IllegalArgumentException, IllegalAccessException {
102
103         adapter = new RestAdapterImpl();
104     }
105     
106     @Test
107     public void testCommonGet() throws IOException, IllegalStateException, IllegalArgumentException,
108         ZoneException, APPCException {    
109          
110             Map<String, String> params = new HashMap<>();
111             params.put("org.openecomp.appc.instance.URI", "http://example.com:8080/about/health");
112             params.put("org.openecomp.appc.instance.haveHeader","false");
113             SvcLogicContext svcContext = new SvcLogicContext();          
114             adapter.commonGet(params, svcContext);
115             String statusCode=svcContext.getAttribute("org.openecomp.rest.agent.result.code");
116             assertEquals("200",statusCode);
117     }
118     
119     @Test
120     public void testCommonPost() throws IOException, IllegalStateException, IllegalArgumentException,
121         ZoneException, APPCException {    
122          
123             Map<String, String> params = new HashMap<>();
124             params.put("org.openecomp.appc.instance.URI", "http://example.com:8081/posttest");
125             params.put("org.openecomp.appc.instance.haveHeader","false");
126             params.put("org.openecomp.appc.instance.requestBody", "{\"name\":\"MyNode\", \"width\":200, \"height\":100}");
127             SvcLogicContext svcContext = new SvcLogicContext();          
128             adapter.commonPost(params, svcContext);
129             String statusCode=svcContext.getAttribute("org.openecomp.rest.agent.result.code");
130             assertEquals("200",statusCode);
131     }
132     
133     @Test
134     public void testCommonPut() throws IOException, IllegalStateException, IllegalArgumentException,
135         ZoneException, APPCException {    
136          
137             Map<String, String> params = new HashMap<>();
138             params.put("org.openecomp.appc.instance.URI", "http://example.com:8081/puttest");
139             params.put("org.openecomp.appc.instance.haveHeader","false");
140             params.put("org.openecomp.appc.instance.requestBody", "{\"name\":\"MyNode2\", \"width\":300, \"height\":300}");
141             SvcLogicContext svcContext = new SvcLogicContext();          
142             adapter.commonPut(params, svcContext);
143             String statusCode=svcContext.getAttribute("org.openecomp.rest.agent.result.code");
144             assertEquals("200",statusCode);
145     }
146     
147     @Test
148     public void testCommonDelete() throws IOException, IllegalStateException, IllegalArgumentException,
149         ZoneException, APPCException {    
150          
151             Map<String, String> params = new HashMap<>();
152             params.put("org.openecomp.appc.instance.URI", "http://example.com:8081/deletetest");
153             params.put("org.openecomp.appc.instance.haveHeader","false");
154             SvcLogicContext svcContext = new SvcLogicContext();          
155             adapter.commonDelete(params, svcContext);
156             String statusCode=svcContext.getAttribute("org.openecomp.rest.agent.result.code");
157             assertEquals("200",statusCode);
158     }
159
160
161 }