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