Unit test cases for iaas impl package
[appc.git] / appc-adapters / appc-iaas-adapter / appc-iaas-adapter-bundle / src / test / java / org / onap / appc / adapter / iaas / impl / TestProviderOperation.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.appc.adapter.iaas.impl;
25
26 import static org.onap.appc.adapter.iaas.provider.operation.common.constants.Constants.MDC_SERVICE;
27 import java.lang.reflect.Field;
28 import java.util.Map;
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;
35 import org.slf4j.MDC;
36 import com.att.cdp.zones.model.ModelObject;
37
38 /**
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.
41  *
42  * @since Jan 20, 2016
43  * @version $Id$
44  */
45
46 public class TestProviderOperation extends ProviderOperation {
47
48     private static Class<?> providerAdapterImplClass;
49     private static Class<?> configurationFactoryClass;
50     private static Field providerCacheField;
51     private static Field configField;
52
53     /**
54      * Use reflection to locate fields and methods so that they can be manipulated during the test
55      * to change the internal state accordingly.
56      *
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
60      */
61     @SuppressWarnings("nls")
62     @BeforeClass
63     public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException {
64         providerAdapterImplClass = ProviderAdapterImpl.class;
65         configurationFactoryClass = ConfigurationFactory.class;
66
67         providerCacheField = providerAdapterImplClass.getDeclaredField("providerCache");
68         providerCacheField.setAccessible(true);
69
70         configField = configurationFactoryClass.getDeclaredField("config");
71         configField.setAccessible(true);
72     }
73
74     /**
75      * This test expects a failure because the value to be validated is a null URL
76      *
77      * @throws RequestFailedException Expected
78      */
79     @SuppressWarnings("nls")
80     @Test(expected = RequestFailedException.class)
81     public void testValidateParameterPatternExpectFailNullValue() throws RequestFailedException {
82         MDC.put(MDC_SERVICE, "junit");
83         String link = null;
84         validateVMURL(VMURL.parseURL(link));
85     }
86
87     /**
88      * This test expects a failure because the value to be validated is an empty URL
89      *
90      * @throws RequestFailedException Expected
91      */
92     @SuppressWarnings("nls")
93     @Test(expected = RequestFailedException.class)
94     public void testValidateParameterPatternExpectFailEmptyValue() throws RequestFailedException {
95         MDC.put(MDC_SERVICE, "junit");
96         String link = "";
97         validateVMURL(VMURL.parseURL(link));
98     }
99
100     /**
101      * This test expects a failure because the value to be validated is a blank URL
102      *
103      * @throws RequestFailedException Expected
104      */
105     @SuppressWarnings("nls")
106     @Test(expected = RequestFailedException.class)
107     public void testValidateParameterPatternExpectFailBlankValue() throws RequestFailedException {
108         MDC.put(MDC_SERVICE, "junit");
109         String link = " ";
110         validateVMURL(VMURL.parseURL(link));
111     }
112
113     /**
114      * This test expects a failure because the value to be validated is a bad URL
115      *
116      * @throws RequestFailedException Expected
117      */
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));
124     }
125
126     /**
127      * This test expects to pass
128      *
129      * @throws RequestFailedException Un-Expected
130      */
131     @SuppressWarnings("nls")
132     @Test
133     public void testValidateParameterPatternValidURL() throws RequestFailedException {
134         MDC.put(MDC_SERVICE, "junit");
135         String link =
136                 "http://some.host:1234/v2/01d82c08594a4b23a0f9260c94be0c4d/servers/f888f89f-096b-421e-ba36-34f714071551";
137         validateVMURL(VMURL.parseURL(link));
138     }
139
140     @Override
141     protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
142             throws APPCException {
143         return null;
144     }
145 }