2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 package org.openecomp.appc.adapter.rest.impl;
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;
30 import java.io.IOException;
31 import java.lang.reflect.Field;
32 import java.util.HashMap;
33 import java.util.List;
35 import java.util.Properties;
38 import org.junit.Before;
39 import org.junit.BeforeClass;
40 import org.junit.Ignore;
41 import org.junit.Test;
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;
59 * Test the ProviderAdapter implementation.
63 public class TestRestAdapterImpl {
65 @SuppressWarnings("nls")
66 private static final String PROVIDER_NAME = "APPC";
68 @SuppressWarnings("nls")
69 private static final String PROVIDER_TYPE = "OpenStackProvider";
71 private static String IDENTITY_URL;
73 private static String PRINCIPAL;
75 private static String CREDENTIAL;
77 private static String TENANT_NAME;
79 private static String TENANT_ID;
81 private static String USER_ID;
83 private static String REGION_NAME;
85 private static String SERVER_URL;
87 private static Class<?> providerAdapterImplClass;
88 private static Class<?> configurationFactoryClass;
89 private static Field providerCacheField;
90 private static Field configField;
92 private RestAdapterImpl adapter;
95 @SuppressWarnings("nls")
97 public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException {
102 public void setup() throws IllegalArgumentException, IllegalAccessException {
104 adapter = new RestAdapterImpl();
108 public void testCommonGet() throws IOException, IllegalStateException, IllegalArgumentException,
109 ZoneException, APPCException {
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);
121 public void testCommonPost() throws IOException, IllegalStateException, IllegalArgumentException,
122 ZoneException, APPCException {
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);
135 public void testCommonPut() throws IOException, IllegalStateException, IllegalArgumentException,
136 ZoneException, APPCException {
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);
149 public void testCommonDelete() throws IOException, IllegalStateException, IllegalArgumentException,
150 ZoneException, APPCException {
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);