More iaas adapter license header changes
[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 java.lang.reflect.Field;
27 import java.util.Map;
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;
34 import org.slf4j.MDC;
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;
38
39 /**
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.
42  *
43  * @since Jan 20, 2016
44  * @version $Id$
45  */
46
47 public class TestProviderOperation extends ProviderOperation {
48
49     private static Class<?> providerAdapterImplClass;
50     private static Class<?> configurationFactoryClass;
51     private static Field providerCacheField;
52     private static Field configField;
53
54     /**
55      * Use reflection to locate fields and methods so that they can be manipulated during the test
56      * to change the internal state accordingly.
57      *
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
61      */
62     @SuppressWarnings("nls")
63     @BeforeClass
64     public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException {
65         providerAdapterImplClass = ProviderAdapterImpl.class;
66         configurationFactoryClass = ConfigurationFactory.class;
67
68         providerCacheField = providerAdapterImplClass.getDeclaredField("providerCache");
69         providerCacheField.setAccessible(true);
70
71         configField = configurationFactoryClass.getDeclaredField("config");
72         configField.setAccessible(true);
73     }
74
75     /**
76      * This test expects a failure because the value to be validated is a null URL
77      *
78      * @throws RequestFailedException Expected
79      */
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);
86         String link = null;
87
88         validateVMURL(VMURL.parseURL(link));
89     }
90
91     /**
92      * This test expects a failure because the value to be validated is an empty URL
93      *
94      * @throws RequestFailedException Expected
95      */
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);
102         String link = "";
103
104         validateVMURL(VMURL.parseURL(link));
105     }
106
107     /**
108      * This test expects a failure because the value to be validated is a blank URL
109      *
110      * @throws RequestFailedException Expected
111      */
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);
118         String link = " ";
119
120         validateVMURL(VMURL.parseURL(link));
121     }
122
123     /**
124      * This test expects a failure because the value to be validated is a bad URL
125      *
126      * @throws RequestFailedException Expected
127      */
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/";
135
136         validateVMURL(VMURL.parseURL(link));
137     }
138
139     /**
140      * This test expects to pass
141      *
142      * @throws RequestFailedException Un-Expected
143      */
144     @SuppressWarnings("nls")
145     @Test
146     public void testValidateParameterPatternValidURL() throws RequestFailedException {
147         MDC.put(MDC_SERVICE, "junit");
148         SvcLogicContext svcContext = new SvcLogicContext();
149         RequestContext rc = new RequestContext(svcContext);
150         String link =
151                 "http://some.host:1234/v2/01d82c08594a4b23a0f9260c94be0c4d/servers/f888f89f-096b-421e-ba36-34f714071551";
152
153         validateVMURL(VMURL.parseURL(link));
154     }
155
156     @Override
157     protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
158             throws APPCException {
159         return null;
160     }
161 }