Change to CCSDK and ODL Carbon
[appc.git] / appc-adapters / appc-iaas-adapter / appc-iaas-adapter-bundle / src / test / java / org / openecomp / appc / adapter / iaas / impl / TestProviderOperation.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.openecomp.appc.adapter.iaas.impl;
26
27 import java.lang.reflect.Field;
28 import java.util.Map;
29
30 import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderOperation;
31 import org.openecomp.appc.exceptions.APPCException;
32 import com.att.cdp.zones.model.ModelObject;
33 import org.junit.Before;
34 import org.junit.BeforeClass;
35 import org.junit.Test;
36 import org.slf4j.MDC;
37
38 import org.openecomp.appc.configuration.ConfigurationFactory;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
40
41 import static org.openecomp.appc.adapter.iaas.provider.operation.common.constants.Constants.MDC_SERVICE;
42
43 /**
44  * This class is used to test methods and functions of the adapter implementation that do not require and do not set up
45  * connections to any providers.
46  *
47  * @since Jan 20, 2016
48  * @version $Id$
49  */
50
51 public class TestProviderOperation extends ProviderOperation{
52
53     private static Class<?> providerAdapterImplClass;
54     private static Class<?> configurationFactoryClass;
55     private static Field providerCacheField;
56     private static Field configField;
57
58     /**
59      * Use reflection to locate fields and methods so that they can be manipulated during the test to change the
60      * internal state accordingly.
61      *
62      * @throws NoSuchFieldException
63      *             if the field(s) dont exist
64      * @throws SecurityException
65      *             if reflective access is not allowed
66      * @throws NoSuchMethodException
67      *             If the method(s) dont exist
68      */
69     @SuppressWarnings("nls")
70     @BeforeClass
71     public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException {
72         providerAdapterImplClass = ProviderAdapterImpl.class;
73         configurationFactoryClass = ConfigurationFactory.class;
74
75         providerCacheField = providerAdapterImplClass.getDeclaredField("providerCache");
76         providerCacheField.setAccessible(true);
77
78         configField = configurationFactoryClass.getDeclaredField("config");
79         configField.setAccessible(true);
80     }
81
82     /**
83      * This test expects a failure because the value to be validated is a null URL
84      *
85      * @throws RequestFailedException
86      *             Expected
87      */
88     @SuppressWarnings("nls")
89     @Test(expected = RequestFailedException.class)
90     public void testValidateParameterPatternExpectFailNullValue() throws RequestFailedException {
91         MDC.put(MDC_SERVICE, "junit");
92         SvcLogicContext svcContext = new SvcLogicContext();
93         RequestContext rc = new RequestContext(svcContext);
94         String link = null;
95
96         validateVMURL(VMURL.parseURL(link));
97     }
98
99     /**
100      * This test expects a failure because the value to be validated is an empty URL
101      *
102      * @throws RequestFailedException
103      *             Expected
104      */
105     @SuppressWarnings("nls")
106     @Test(expected = RequestFailedException.class)
107     public void testValidateParameterPatternExpectFailEmptyValue() throws RequestFailedException {
108         MDC.put(MDC_SERVICE, "junit");
109         SvcLogicContext svcContext = new SvcLogicContext();
110         RequestContext rc = new RequestContext(svcContext);
111         String link = "";
112
113         validateVMURL(VMURL.parseURL(link));
114     }
115
116     /**
117      * This test expects a failure because the value to be validated is a blank URL
118      *
119      * @throws RequestFailedException
120      *             Expected
121      */
122     @SuppressWarnings("nls")
123     @Test(expected = RequestFailedException.class)
124     public void testValidateParameterPatternExpectFailBlankValue() throws RequestFailedException {
125         MDC.put(MDC_SERVICE, "junit");
126         SvcLogicContext svcContext = new SvcLogicContext();
127         RequestContext rc = new RequestContext(svcContext);
128         String link = " ";
129
130         validateVMURL(VMURL.parseURL(link));
131     }
132
133     /**
134      * This test expects a failure because the value to be validated is a bad URL
135      *
136      * @throws RequestFailedException
137      *             Expected
138      */
139     @SuppressWarnings("nls")
140     @Test(expected = RequestFailedException.class)
141     public void testValidateParameterPatternExpectFailBadURL() throws RequestFailedException {
142         MDC.put(MDC_SERVICE, "junit");
143         SvcLogicContext svcContext = new SvcLogicContext();
144         RequestContext rc = new RequestContext(svcContext);
145         String link = "http://some.host:1234/01d82c08594a4b23a0f9260c94be0c4d/";
146
147         validateVMURL(VMURL.parseURL(link));
148     }
149
150     /**
151      * This test expects to pass
152      *
153      * @throws RequestFailedException
154      *             Un-Expected
155      */
156     @SuppressWarnings("nls")
157     @Test
158     public void testValidateParameterPatternValidURL() throws RequestFailedException {
159         MDC.put(MDC_SERVICE, "junit");
160         SvcLogicContext svcContext = new SvcLogicContext();
161         RequestContext rc = new RequestContext(svcContext);
162         String link =
163             "http://some.host:1234/v2/01d82c08594a4b23a0f9260c94be0c4d/servers/f888f89f-096b-421e-ba36-34f714071551";
164
165         validateVMURL(VMURL.parseURL(link));
166     }
167
168     @Override
169     protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context) throws APPCException {
170         return null;
171     }
172 }