2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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=========================================================
22 package org.openecomp.appc.adapter.rest.impl;
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;
29 import java.io.IOException;
30 import java.lang.reflect.Field;
31 import java.util.HashMap;
32 import java.util.List;
34 import java.util.Properties;
37 import org.junit.Before;
38 import org.junit.BeforeClass;
39 import org.junit.Ignore;
40 import org.junit.Test;
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;
58 * Test the ProviderAdapter implementation.
62 public class TestRestAdapterImpl {
64 @SuppressWarnings("nls")
65 private static final String PROVIDER_NAME = "APPC";
67 @SuppressWarnings("nls")
68 private static final String PROVIDER_TYPE = "OpenStackProvider";
70 private static String IDENTITY_URL;
72 private static String PRINCIPAL;
74 private static String CREDENTIAL;
76 private static String TENANT_NAME;
78 private static String TENANT_ID;
80 private static String USER_ID;
82 private static String REGION_NAME;
84 private static String SERVER_URL;
86 private static Class<?> providerAdapterImplClass;
87 private static Class<?> configurationFactoryClass;
88 private static Field providerCacheField;
89 private static Field configField;
91 private RestAdapterImpl adapter;
94 @SuppressWarnings("nls")
96 public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException {
101 public void setup() throws IllegalArgumentException, IllegalAccessException {
103 adapter = new RestAdapterImpl();
107 public void testCommonGet() throws IOException, IllegalStateException, IllegalArgumentException,
108 ZoneException, APPCException {
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);
120 public void testCommonPost() throws IOException, IllegalStateException, IllegalArgumentException,
121 ZoneException, APPCException {
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);
134 public void testCommonPut() throws IOException, IllegalStateException, IllegalArgumentException,
135 ZoneException, APPCException {
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);
148 public void testCommonDelete() throws IOException, IllegalStateException, IllegalArgumentException,
149 ZoneException, APPCException {
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);