Change to CCSDK and ODL Carbon
[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  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.openecomp.appc.adapter.rest.impl;
26
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertNotNull;
29 import static org.junit.Assert.assertTrue;
30 import static org.junit.Assert.fail;
31
32 import java.io.IOException;
33 import java.lang.reflect.Field;
34 import java.util.HashMap;
35 import java.util.List;
36 import java.util.Map;
37 import java.util.Properties;
38 import java.util.Set;
39
40 import org.junit.Before;
41 import org.junit.BeforeClass;
42 import org.junit.Ignore;
43 import org.junit.Test;
44 import org.slf4j.MDC;
45
46 import org.openecomp.appc.Constants;
47 import org.openecomp.appc.adapter.rest.RestAdapter;
48 import org.openecomp.appc.configuration.ConfigurationFactory;
49 import org.openecomp.appc.exceptions.APPCException;
50 import org.openecomp.appc.exceptions.UnknownProviderException;
51 import com.att.cdp.exceptions.ZoneException;
52 import com.att.cdp.zones.ComputeService;
53 import com.att.cdp.zones.Context;
54 import com.att.cdp.zones.ContextFactory;
55 import com.att.cdp.zones.model.Server;
56 import com.att.cdp.zones.model.Server.Status;
57 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
58
59
60 /**
61  * Test the ProviderAdapter implementation.
62  */
63
64 @Ignore
65 public class TestRestAdapterImpl {
66
67     @SuppressWarnings("nls")
68     private static final String PROVIDER_NAME = "APPC";
69
70     @SuppressWarnings("nls")
71     private static final String PROVIDER_TYPE = "OpenStackProvider";
72
73     private static String IDENTITY_URL;
74
75     private static String PRINCIPAL;
76
77     private static String CREDENTIAL;
78
79     private static String TENANT_NAME;
80
81     private static String TENANT_ID;
82
83     private static String USER_ID;
84
85     private static String REGION_NAME;
86
87     private static String SERVER_URL;
88
89     private static Class<?> providerAdapterImplClass;
90     private static Class<?> configurationFactoryClass;
91     private static Field providerCacheField;
92     private static Field configField;
93
94     private RestAdapterImpl adapter;
95
96
97     @SuppressWarnings("nls")
98     @BeforeClass
99     public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException {
100
101     }
102
103     @Before
104     public void setup() throws IllegalArgumentException, IllegalAccessException {
105
106         adapter = new RestAdapterImpl();
107     }
108     
109     @Test
110     public void testCommonGet() throws IOException, IllegalStateException, IllegalArgumentException,
111         ZoneException, APPCException {    
112          
113             Map<String, String> params = new HashMap<>();
114             params.put("org.openecomp.appc.instance.URI", "http://example.com:8080/about/health");
115             params.put("org.openecomp.appc.instance.haveHeader","false");
116             SvcLogicContext svcContext = new SvcLogicContext();          
117             adapter.commonGet(params, svcContext);
118             String statusCode=svcContext.getAttribute("org.openecomp.rest.agent.result.code");
119             assertEquals("200",statusCode);
120     }
121     
122     @Test
123     public void testCommonPost() throws IOException, IllegalStateException, IllegalArgumentException,
124         ZoneException, APPCException {    
125          
126             Map<String, String> params = new HashMap<>();
127             params.put("org.openecomp.appc.instance.URI", "http://example.com:8081/posttest");
128             params.put("org.openecomp.appc.instance.haveHeader","false");
129             params.put("org.openecomp.appc.instance.requestBody", "{\"name\":\"MyNode\", \"width\":200, \"height\":100}");
130             SvcLogicContext svcContext = new SvcLogicContext();          
131             adapter.commonPost(params, svcContext);
132             String statusCode=svcContext.getAttribute("org.openecomp.rest.agent.result.code");
133             assertEquals("200",statusCode);
134     }
135     
136     @Test
137     public void testCommonPut() throws IOException, IllegalStateException, IllegalArgumentException,
138         ZoneException, APPCException {    
139          
140             Map<String, String> params = new HashMap<>();
141             params.put("org.openecomp.appc.instance.URI", "http://example.com:8081/puttest");
142             params.put("org.openecomp.appc.instance.haveHeader","false");
143             params.put("org.openecomp.appc.instance.requestBody", "{\"name\":\"MyNode2\", \"width\":300, \"height\":300}");
144             SvcLogicContext svcContext = new SvcLogicContext();          
145             adapter.commonPut(params, svcContext);
146             String statusCode=svcContext.getAttribute("org.openecomp.rest.agent.result.code");
147             assertEquals("200",statusCode);
148     }
149     
150     @Test
151     public void testCommonDelete() throws IOException, IllegalStateException, IllegalArgumentException,
152         ZoneException, APPCException {    
153          
154             Map<String, String> params = new HashMap<>();
155             params.put("org.openecomp.appc.instance.URI", "http://example.com:8081/deletetest");
156             params.put("org.openecomp.appc.instance.haveHeader","false");
157             SvcLogicContext svcContext = new SvcLogicContext();          
158             adapter.commonDelete(params, svcContext);
159             String statusCode=svcContext.getAttribute("org.openecomp.rest.agent.result.code");
160             assertEquals("200",statusCode);
161     }
162
163
164 }