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