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.iaas.impl;
25 import java.lang.reflect.Field;
28 import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderOperation;
29 import org.openecomp.appc.exceptions.APPCException;
30 import com.att.cdp.zones.model.ModelObject;
31 import org.junit.Before;
32 import org.junit.BeforeClass;
33 import org.junit.Test;
36 import org.openecomp.appc.configuration.ConfigurationFactory;
37 import org.openecomp.sdnc.sli.SvcLogicContext;
39 import static org.openecomp.appc.adapter.iaas.provider.operation.common.constants.Constants.MDC_SERVICE;
42 * This class is used to test methods and functions of the adapter implementation that do not require and do not set up
43 * connections to any providers.
49 public class TestProviderOperation extends ProviderOperation{
51 private static Class<?> providerAdapterImplClass;
52 private static Class<?> configurationFactoryClass;
53 private static Field providerCacheField;
54 private static Field configField;
57 * Use reflection to locate fields and methods so that they can be manipulated during the test to change the
58 * internal state accordingly.
60 * @throws NoSuchFieldException
61 * if the field(s) dont exist
62 * @throws SecurityException
63 * if reflective access is not allowed
64 * @throws NoSuchMethodException
65 * If the method(s) dont exist
67 @SuppressWarnings("nls")
69 public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException {
70 providerAdapterImplClass = ProviderAdapterImpl.class;
71 configurationFactoryClass = ConfigurationFactory.class;
73 providerCacheField = providerAdapterImplClass.getDeclaredField("providerCache");
74 providerCacheField.setAccessible(true);
76 configField = configurationFactoryClass.getDeclaredField("config");
77 configField.setAccessible(true);
81 * This test expects a failure because the value to be validated is a null URL
83 * @throws RequestFailedException
86 @SuppressWarnings("nls")
87 @Test(expected = RequestFailedException.class)
88 public void testValidateParameterPatternExpectFailNullValue() throws RequestFailedException {
89 MDC.put(MDC_SERVICE, "junit");
90 SvcLogicContext svcContext = new SvcLogicContext();
91 RequestContext rc = new RequestContext(svcContext);
94 validateVMURL(VMURL.parseURL(link));
98 * This test expects a failure because the value to be validated is an empty URL
100 * @throws RequestFailedException
103 @SuppressWarnings("nls")
104 @Test(expected = RequestFailedException.class)
105 public void testValidateParameterPatternExpectFailEmptyValue() throws RequestFailedException {
106 MDC.put(MDC_SERVICE, "junit");
107 SvcLogicContext svcContext = new SvcLogicContext();
108 RequestContext rc = new RequestContext(svcContext);
111 validateVMURL(VMURL.parseURL(link));
115 * This test expects a failure because the value to be validated is a blank URL
117 * @throws RequestFailedException
120 @SuppressWarnings("nls")
121 @Test(expected = RequestFailedException.class)
122 public void testValidateParameterPatternExpectFailBlankValue() throws RequestFailedException {
123 MDC.put(MDC_SERVICE, "junit");
124 SvcLogicContext svcContext = new SvcLogicContext();
125 RequestContext rc = new RequestContext(svcContext);
128 validateVMURL(VMURL.parseURL(link));
132 * This test expects a failure because the value to be validated is a bad URL
134 * @throws RequestFailedException
137 @SuppressWarnings("nls")
138 @Test(expected = RequestFailedException.class)
139 public void testValidateParameterPatternExpectFailBadURL() throws RequestFailedException {
140 MDC.put(MDC_SERVICE, "junit");
141 SvcLogicContext svcContext = new SvcLogicContext();
142 RequestContext rc = new RequestContext(svcContext);
143 String link = "http://some.host:1234/01d82c08594a4b23a0f9260c94be0c4d/";
145 validateVMURL(VMURL.parseURL(link));
149 * This test expects to pass
151 * @throws RequestFailedException
154 @SuppressWarnings("nls")
156 public void testValidateParameterPatternValidURL() throws RequestFailedException {
157 MDC.put(MDC_SERVICE, "junit");
158 SvcLogicContext svcContext = new SvcLogicContext();
159 RequestContext rc = new RequestContext(svcContext);
161 "http://some.host:1234/v2/01d82c08594a4b23a0f9260c94be0c4d/servers/f888f89f-096b-421e-ba36-34f714071551";
163 validateVMURL(VMURL.parseURL(link));
167 protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context) throws APPCException {