0594ca9a7091fcd7a6b1667c27e5a1b045796c21
[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  * APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22
23 package org.openecomp.appc.adapter.iaas.impl;
24
25 import java.lang.reflect.Field;
26 import java.util.Map;
27
28 import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderOperation;
29 import org.openecomp.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
36 import org.openecomp.appc.configuration.ConfigurationFactory;
37 import org.openecomp.sdnc.sli.SvcLogicContext;
38
39 import static org.openecomp.appc.adapter.iaas.provider.operation.common.constants.Constants.MDC_SERVICE;
40
41 /**
42  * This class is used to test methods and functions of the adapter implementation that do not require and do not set up
43  * connections to any providers.
44  *
45  * @since Jan 20, 2016
46  * @version $Id$
47  */
48
49 public class TestProviderOperation extends ProviderOperation{
50
51     private static Class<?> providerAdapterImplClass;
52     private static Class<?> configurationFactoryClass;
53     private static Field providerCacheField;
54     private static Field configField;
55
56     /**
57      * Use reflection to locate fields and methods so that they can be manipulated during the test to change the
58      * internal state accordingly.
59      *
60      * @throws NoSuchFieldException
61      *             if the field(s) dont exist
62      * @throws SecurityException
63      *             if reflective access is not allowed
64      * @throws NoSuchMethodException
65      *             If the method(s) dont exist
66      */
67     @SuppressWarnings("nls")
68     @BeforeClass
69     public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException {
70         providerAdapterImplClass = ProviderAdapterImpl.class;
71         configurationFactoryClass = ConfigurationFactory.class;
72
73         providerCacheField = providerAdapterImplClass.getDeclaredField("providerCache");
74         providerCacheField.setAccessible(true);
75
76         configField = configurationFactoryClass.getDeclaredField("config");
77         configField.setAccessible(true);
78     }
79
80     /**
81      * This test expects a failure because the value to be validated is a null URL
82      *
83      * @throws RequestFailedException
84      *             Expected
85      */
86     @SuppressWarnings("nls")
87     @Test(expected = RequestFailedException.class)
88     public void testValidateParameterPatternExpectFailNullValue() throws RequestFailedException {
89         MDC.put(MDC_SERVICE, "junit");
90         SvcLogicContext svcContext = new SvcLogicContext();
91         RequestContext rc = new RequestContext(svcContext);
92         String link = null;
93
94         validateVMURL(VMURL.parseURL(link));
95     }
96
97     /**
98      * This test expects a failure because the value to be validated is an empty URL
99      *
100      * @throws RequestFailedException
101      *             Expected
102      */
103     @SuppressWarnings("nls")
104     @Test(expected = RequestFailedException.class)
105     public void testValidateParameterPatternExpectFailEmptyValue() throws RequestFailedException {
106         MDC.put(MDC_SERVICE, "junit");
107         SvcLogicContext svcContext = new SvcLogicContext();
108         RequestContext rc = new RequestContext(svcContext);
109         String link = "";
110
111         validateVMURL(VMURL.parseURL(link));
112     }
113
114     /**
115      * This test expects a failure because the value to be validated is a blank URL
116      *
117      * @throws RequestFailedException
118      *             Expected
119      */
120     @SuppressWarnings("nls")
121     @Test(expected = RequestFailedException.class)
122     public void testValidateParameterPatternExpectFailBlankValue() throws RequestFailedException {
123         MDC.put(MDC_SERVICE, "junit");
124         SvcLogicContext svcContext = new SvcLogicContext();
125         RequestContext rc = new RequestContext(svcContext);
126         String link = " ";
127
128         validateVMURL(VMURL.parseURL(link));
129     }
130
131     /**
132      * This test expects a failure because the value to be validated is a bad URL
133      *
134      * @throws RequestFailedException
135      *             Expected
136      */
137     @SuppressWarnings("nls")
138     @Test(expected = RequestFailedException.class)
139     public void testValidateParameterPatternExpectFailBadURL() throws RequestFailedException {
140         MDC.put(MDC_SERVICE, "junit");
141         SvcLogicContext svcContext = new SvcLogicContext();
142         RequestContext rc = new RequestContext(svcContext);
143         String link = "http://some.host:1234/01d82c08594a4b23a0f9260c94be0c4d/";
144
145         validateVMURL(VMURL.parseURL(link));
146     }
147
148     /**
149      * This test expects to pass
150      *
151      * @throws RequestFailedException
152      *             Un-Expected
153      */
154     @SuppressWarnings("nls")
155     @Test
156     public void testValidateParameterPatternValidURL() throws RequestFailedException {
157         MDC.put(MDC_SERVICE, "junit");
158         SvcLogicContext svcContext = new SvcLogicContext();
159         RequestContext rc = new RequestContext(svcContext);
160         String link =
161             "http://some.host:1234/v2/01d82c08594a4b23a0f9260c94be0c4d/servers/f888f89f-096b-421e-ba36-34f714071551";
162
163         validateVMURL(VMURL.parseURL(link));
164     }
165
166     @Override
167     protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context) throws APPCException {
168         return null;
169     }
170 }