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 static org.onap.appc.adapter.iaas.provider.operation.common.constants.Constants.MDC_SERVICE;
27 import java.lang.reflect.Field;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31 import org.onap.appc.adapter.iaas.provider.operation.impl.base.ProviderOperation;
32 import org.onap.appc.configuration.ConfigurationFactory;
33 import org.onap.appc.exceptions.APPCException;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
36 import com.att.cdp.zones.model.ModelObject;
39 * This class is used to test methods and functions of the adapter implementation that do not
40 * require and do not set up connections to any providers.
46 public class TestProviderOperation extends ProviderOperation {
48 private static Class<?> providerAdapterImplClass;
49 private static Class<?> configurationFactoryClass;
50 private static Field providerCacheField;
51 private static Field configField;
54 * Use reflection to locate fields and methods so that they can be manipulated during the test
55 * to change the internal state accordingly.
57 * @throws NoSuchFieldException if the field(s) dont exist
58 * @throws SecurityException if reflective access is not allowed
59 * @throws NoSuchMethodException If the method(s) dont exist
61 @SuppressWarnings("nls")
63 public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException {
64 providerAdapterImplClass = ProviderAdapterImpl.class;
65 configurationFactoryClass = ConfigurationFactory.class;
67 providerCacheField = providerAdapterImplClass.getDeclaredField("providerCache");
68 providerCacheField.setAccessible(true);
70 configField = configurationFactoryClass.getDeclaredField("config");
71 configField.setAccessible(true);
75 * This test expects a failure because the value to be validated is a null URL
77 * @throws RequestFailedException Expected
79 @SuppressWarnings("nls")
80 @Test(expected = RequestFailedException.class)
81 public void testValidateParameterPatternExpectFailNullValue() throws RequestFailedException {
82 MDC.put(MDC_SERVICE, "junit");
84 validateVMURL(VMURL.parseURL(link));
88 * This test expects a failure because the value to be validated is an empty URL
90 * @throws RequestFailedException Expected
92 @SuppressWarnings("nls")
93 @Test(expected = RequestFailedException.class)
94 public void testValidateParameterPatternExpectFailEmptyValue() throws RequestFailedException {
95 MDC.put(MDC_SERVICE, "junit");
97 validateVMURL(VMURL.parseURL(link));
101 * This test expects a failure because the value to be validated is a blank URL
103 * @throws RequestFailedException Expected
105 @SuppressWarnings("nls")
106 @Test(expected = RequestFailedException.class)
107 public void testValidateParameterPatternExpectFailBlankValue() throws RequestFailedException {
108 MDC.put(MDC_SERVICE, "junit");
110 validateVMURL(VMURL.parseURL(link));
114 * This test expects a failure because the value to be validated is a bad URL
116 * @throws RequestFailedException Expected
118 @SuppressWarnings("nls")
119 @Test(expected = RequestFailedException.class)
120 public void testValidateParameterPatternExpectFailBadURL() throws RequestFailedException {
121 MDC.put(MDC_SERVICE, "junit");
122 String link = "http://some.host:1234/01d82c08594a4b23a0f9260c94be0c4d/";
123 validateVMURL(VMURL.parseURL(link));
127 * This test expects to pass
129 * @throws RequestFailedException Un-Expected
131 @SuppressWarnings("nls")
133 public void testValidateParameterPatternValidURL() throws RequestFailedException {
134 MDC.put(MDC_SERVICE, "junit");
136 "http://some.host:1234/v2/01d82c08594a4b23a0f9260c94be0c4d/servers/f888f89f-096b-421e-ba36-34f714071551";
137 validateVMURL(VMURL.parseURL(link));
141 protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
142 throws APPCException {