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.iaas.impl;
24 import java.lang.reflect.Field;
27 import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderOperation;
28 import org.openecomp.appc.exceptions.APPCException;
29 import com.att.cdp.zones.model.ModelObject;
30 import org.junit.Before;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
35 import org.openecomp.appc.configuration.ConfigurationFactory;
36 import org.openecomp.sdnc.sli.SvcLogicContext;
38 import static org.openecomp.appc.adapter.iaas.provider.operation.common.constants.Constants.MDC_SERVICE;
41 * This class is used to test methods and functions of the adapter implementation that do not require and do not set up
42 * connections to any providers.
48 public class TestProviderOperation extends ProviderOperation{
50 private static Class<?> providerAdapterImplClass;
51 private static Class<?> configurationFactoryClass;
52 private static Field providerCacheField;
53 private static Field configField;
56 * Use reflection to locate fields and methods so that they can be manipulated during the test to change the
57 * internal state accordingly.
59 * @throws NoSuchFieldException
60 * if the field(s) dont exist
61 * @throws SecurityException
62 * if reflective access is not allowed
63 * @throws NoSuchMethodException
64 * If the method(s) dont exist
66 @SuppressWarnings("nls")
68 public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException {
69 providerAdapterImplClass = ProviderAdapterImpl.class;
70 configurationFactoryClass = ConfigurationFactory.class;
72 providerCacheField = providerAdapterImplClass.getDeclaredField("providerCache");
73 providerCacheField.setAccessible(true);
75 configField = configurationFactoryClass.getDeclaredField("config");
76 configField.setAccessible(true);
80 * This test expects a failure because the value to be validated is a null URL
82 * @throws RequestFailedException
85 @SuppressWarnings("nls")
86 @Test(expected = RequestFailedException.class)
87 public void testValidateParameterPatternExpectFailNullValue() throws RequestFailedException {
88 MDC.put(MDC_SERVICE, "junit");
89 SvcLogicContext svcContext = new SvcLogicContext();
90 RequestContext rc = new RequestContext(svcContext);
93 validateVMURL(VMURL.parseURL(link));
97 * This test expects a failure because the value to be validated is an empty URL
99 * @throws RequestFailedException
102 @SuppressWarnings("nls")
103 @Test(expected = RequestFailedException.class)
104 public void testValidateParameterPatternExpectFailEmptyValue() throws RequestFailedException {
105 MDC.put(MDC_SERVICE, "junit");
106 SvcLogicContext svcContext = new SvcLogicContext();
107 RequestContext rc = new RequestContext(svcContext);
110 validateVMURL(VMURL.parseURL(link));
114 * This test expects a failure because the value to be validated is a blank URL
116 * @throws RequestFailedException
119 @SuppressWarnings("nls")
120 @Test(expected = RequestFailedException.class)
121 public void testValidateParameterPatternExpectFailBlankValue() throws RequestFailedException {
122 MDC.put(MDC_SERVICE, "junit");
123 SvcLogicContext svcContext = new SvcLogicContext();
124 RequestContext rc = new RequestContext(svcContext);
127 validateVMURL(VMURL.parseURL(link));
131 * This test expects a failure because the value to be validated is a bad URL
133 * @throws RequestFailedException
136 @SuppressWarnings("nls")
137 @Test(expected = RequestFailedException.class)
138 public void testValidateParameterPatternExpectFailBadURL() throws RequestFailedException {
139 MDC.put(MDC_SERVICE, "junit");
140 SvcLogicContext svcContext = new SvcLogicContext();
141 RequestContext rc = new RequestContext(svcContext);
142 String link = "http://some.host:1234/01d82c08594a4b23a0f9260c94be0c4d/";
144 validateVMURL(VMURL.parseURL(link));
148 * This test expects to pass
150 * @throws RequestFailedException
153 @SuppressWarnings("nls")
155 public void testValidateParameterPatternValidURL() throws RequestFailedException {
156 MDC.put(MDC_SERVICE, "junit");
157 SvcLogicContext svcContext = new SvcLogicContext();
158 RequestContext rc = new RequestContext(svcContext);
160 "http://some.host:1234/v2/01d82c08594a4b23a0f9260c94be0c4d/servers/f888f89f-096b-421e-ba36-34f714071551";
162 validateVMURL(VMURL.parseURL(link));
166 protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context) throws APPCException {