2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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 * ============LICENSE_END=========================================================
24 package org.onap.appc.adapter.iaas.impl;
26 import java.lang.reflect.Field;
28 import org.onap.appc.adapter.iaas.provider.operation.impl.base.ProviderOperation;
29 import org.onap.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;
35 import org.onap.appc.configuration.ConfigurationFactory;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
37 import static org.onap.appc.adapter.iaas.provider.operation.common.constants.Constants.MDC_SERVICE;
40 * This class is used to test methods and functions of the adapter implementation that do not
41 * require and do not set up connections to any providers.
47 public class TestProviderOperation extends ProviderOperation {
49 private static Class<?> providerAdapterImplClass;
50 private static Class<?> configurationFactoryClass;
51 private static Field providerCacheField;
52 private static Field configField;
55 * Use reflection to locate fields and methods so that they can be manipulated during the test
56 * to change the internal state accordingly.
58 * @throws NoSuchFieldException if the field(s) dont exist
59 * @throws SecurityException if reflective access is not allowed
60 * @throws NoSuchMethodException If the method(s) dont exist
62 @SuppressWarnings("nls")
64 public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException {
65 providerAdapterImplClass = ProviderAdapterImpl.class;
66 configurationFactoryClass = ConfigurationFactory.class;
68 providerCacheField = providerAdapterImplClass.getDeclaredField("providerCache");
69 providerCacheField.setAccessible(true);
71 configField = configurationFactoryClass.getDeclaredField("config");
72 configField.setAccessible(true);
76 * This test expects a failure because the value to be validated is a null URL
78 * @throws RequestFailedException Expected
80 @SuppressWarnings("nls")
81 @Test(expected = RequestFailedException.class)
82 public void testValidateParameterPatternExpectFailNullValue() throws RequestFailedException {
83 MDC.put(MDC_SERVICE, "junit");
84 SvcLogicContext svcContext = new SvcLogicContext();
85 RequestContext rc = new RequestContext(svcContext);
88 validateVMURL(VMURL.parseURL(link));
92 * This test expects a failure because the value to be validated is an empty URL
94 * @throws RequestFailedException Expected
96 @SuppressWarnings("nls")
97 @Test(expected = RequestFailedException.class)
98 public void testValidateParameterPatternExpectFailEmptyValue() throws RequestFailedException {
99 MDC.put(MDC_SERVICE, "junit");
100 SvcLogicContext svcContext = new SvcLogicContext();
101 RequestContext rc = new RequestContext(svcContext);
104 validateVMURL(VMURL.parseURL(link));
108 * This test expects a failure because the value to be validated is a blank URL
110 * @throws RequestFailedException Expected
112 @SuppressWarnings("nls")
113 @Test(expected = RequestFailedException.class)
114 public void testValidateParameterPatternExpectFailBlankValue() throws RequestFailedException {
115 MDC.put(MDC_SERVICE, "junit");
116 SvcLogicContext svcContext = new SvcLogicContext();
117 RequestContext rc = new RequestContext(svcContext);
120 validateVMURL(VMURL.parseURL(link));
124 * This test expects a failure because the value to be validated is a bad URL
126 * @throws RequestFailedException Expected
128 @SuppressWarnings("nls")
129 @Test(expected = RequestFailedException.class)
130 public void testValidateParameterPatternExpectFailBadURL() throws RequestFailedException {
131 MDC.put(MDC_SERVICE, "junit");
132 SvcLogicContext svcContext = new SvcLogicContext();
133 RequestContext rc = new RequestContext(svcContext);
134 String link = "http://some.host:1234/01d82c08594a4b23a0f9260c94be0c4d/";
136 validateVMURL(VMURL.parseURL(link));
140 * This test expects to pass
142 * @throws RequestFailedException Un-Expected
144 @SuppressWarnings("nls")
146 public void testValidateParameterPatternValidURL() throws RequestFailedException {
147 MDC.put(MDC_SERVICE, "junit");
148 SvcLogicContext svcContext = new SvcLogicContext();
149 RequestContext rc = new RequestContext(svcContext);
151 "http://some.host:1234/v2/01d82c08594a4b23a0f9260c94be0c4d/servers/f888f89f-096b-421e-ba36-34f714071551";
153 validateVMURL(VMURL.parseURL(link));
157 protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
158 throws APPCException {