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.onap.appc.adapter.iaas.impl;
27 import java.lang.reflect.Field;
29 import org.onap.appc.adapter.iaas.provider.operation.impl.base.ProviderOperation;
30 import org.onap.appc.exceptions.APPCException;
31 import com.att.cdp.zones.model.ModelObject;
32 import org.junit.Before;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
36 import org.onap.appc.configuration.ConfigurationFactory;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
38 import static org.onap.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
42 * require and do not set up 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
57 * to change the internal state accordingly.
59 * @throws NoSuchFieldException if the field(s) dont exist
60 * @throws SecurityException if reflective access is not allowed
61 * @throws NoSuchMethodException If the method(s) dont exist
63 @SuppressWarnings("nls")
65 public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException {
66 providerAdapterImplClass = ProviderAdapterImpl.class;
67 configurationFactoryClass = ConfigurationFactory.class;
69 providerCacheField = providerAdapterImplClass.getDeclaredField("providerCache");
70 providerCacheField.setAccessible(true);
72 configField = configurationFactoryClass.getDeclaredField("config");
73 configField.setAccessible(true);
77 * This test expects a failure because the value to be validated is a null URL
79 * @throws RequestFailedException Expected
81 @SuppressWarnings("nls")
82 @Test(expected = RequestFailedException.class)
83 public void testValidateParameterPatternExpectFailNullValue() throws RequestFailedException {
84 MDC.put(MDC_SERVICE, "junit");
85 SvcLogicContext svcContext = new SvcLogicContext();
86 RequestContext rc = new RequestContext(svcContext);
89 validateVMURL(VMURL.parseURL(link));
93 * This test expects a failure because the value to be validated is an empty URL
95 * @throws RequestFailedException Expected
97 @SuppressWarnings("nls")
98 @Test(expected = RequestFailedException.class)
99 public void testValidateParameterPatternExpectFailEmptyValue() throws RequestFailedException {
100 MDC.put(MDC_SERVICE, "junit");
101 SvcLogicContext svcContext = new SvcLogicContext();
102 RequestContext rc = new RequestContext(svcContext);
105 validateVMURL(VMURL.parseURL(link));
109 * This test expects a failure because the value to be validated is a blank URL
111 * @throws RequestFailedException Expected
113 @SuppressWarnings("nls")
114 @Test(expected = RequestFailedException.class)
115 public void testValidateParameterPatternExpectFailBlankValue() throws RequestFailedException {
116 MDC.put(MDC_SERVICE, "junit");
117 SvcLogicContext svcContext = new SvcLogicContext();
118 RequestContext rc = new RequestContext(svcContext);
121 validateVMURL(VMURL.parseURL(link));
125 * This test expects a failure because the value to be validated is a bad URL
127 * @throws RequestFailedException Expected
129 @SuppressWarnings("nls")
130 @Test(expected = RequestFailedException.class)
131 public void testValidateParameterPatternExpectFailBadURL() throws RequestFailedException {
132 MDC.put(MDC_SERVICE, "junit");
133 SvcLogicContext svcContext = new SvcLogicContext();
134 RequestContext rc = new RequestContext(svcContext);
135 String link = "http://some.host:1234/01d82c08594a4b23a0f9260c94be0c4d/";
137 validateVMURL(VMURL.parseURL(link));
141 * This test expects to pass
143 * @throws RequestFailedException Un-Expected
145 @SuppressWarnings("nls")
147 public void testValidateParameterPatternValidURL() throws RequestFailedException {
148 MDC.put(MDC_SERVICE, "junit");
149 SvcLogicContext svcContext = new SvcLogicContext();
150 RequestContext rc = new RequestContext(svcContext);
152 "http://some.host:1234/v2/01d82c08594a4b23a0f9260c94be0c4d/servers/f888f89f-096b-421e-ba36-34f714071551";
154 validateVMURL(VMURL.parseURL(link));
158 protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
159 throws APPCException {