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