2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.appc.adapter.rest.impl;
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;
32 import java.io.IOException;
33 import java.lang.reflect.Field;
34 import java.util.HashMap;
35 import java.util.List;
37 import java.util.Properties;
40 import org.junit.Before;
41 import org.junit.BeforeClass;
42 import org.junit.Ignore;
43 import org.junit.Test;
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;
61 * Test the ProviderAdapter implementation.
65 public class TestRestAdapterImpl {
67 @SuppressWarnings("nls")
68 private static final String PROVIDER_NAME = "APPC";
70 @SuppressWarnings("nls")
71 private static final String PROVIDER_TYPE = "OpenStackProvider";
73 private static String IDENTITY_URL;
75 private static String PRINCIPAL;
77 private static String CREDENTIAL;
79 private static String TENANT_NAME;
81 private static String TENANT_ID;
83 private static String USER_ID;
85 private static String REGION_NAME;
87 private static String SERVER_URL;
89 private static Class<?> providerAdapterImplClass;
90 private static Class<?> configurationFactoryClass;
91 private static Field providerCacheField;
92 private static Field configField;
94 private RestAdapterImpl adapter;
97 @SuppressWarnings("nls")
99 public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException {
104 public void setup() throws IllegalArgumentException, IllegalAccessException {
106 adapter = new RestAdapterImpl();
110 public void testCommonGet() throws IOException, IllegalStateException, IllegalArgumentException,
111 ZoneException, APPCException {
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);
123 public void testCommonPost() throws IOException, IllegalStateException, IllegalArgumentException,
124 ZoneException, APPCException {
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);
137 public void testCommonPut() throws IOException, IllegalStateException, IllegalArgumentException,
138 ZoneException, APPCException {
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);
151 public void testCommonDelete() throws IOException, IllegalStateException, IllegalArgumentException,
152 ZoneException, APPCException {
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);