c080cf9538136056d820933eabcc4544cc66a6fc
[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.onap.appc.adapter.iaas.impl;
26
27 import java.lang.reflect.Field;
28 import java.util.Map;
29 import org.onap.appc.adapter.iaas.provider.operation.impl.base.ProviderOperation;
30 import org.onap.appc.exceptions.APPCException;
31 import com.att.cdp.zones.model.ModelObject;
32 import org.junit.Before;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35 import org.slf4j.MDC;
36 import org.onap.appc.configuration.ConfigurationFactory;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
38 import static org.onap.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
42  * require and do not set up 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
57      * to change the internal state accordingly.
58      *
59      * @throws NoSuchFieldException if the field(s) dont exist
60      * @throws SecurityException if reflective access is not allowed
61      * @throws NoSuchMethodException If the method(s) dont exist
62      */
63     @SuppressWarnings("nls")
64     @BeforeClass
65     public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException {
66         providerAdapterImplClass = ProviderAdapterImpl.class;
67         configurationFactoryClass = ConfigurationFactory.class;
68
69         providerCacheField = providerAdapterImplClass.getDeclaredField("providerCache");
70         providerCacheField.setAccessible(true);
71
72         configField = configurationFactoryClass.getDeclaredField("config");
73         configField.setAccessible(true);
74     }
75
76     /**
77      * This test expects a failure because the value to be validated is a null URL
78      *
79      * @throws RequestFailedException Expected
80      */
81     @SuppressWarnings("nls")
82     @Test(expected = RequestFailedException.class)
83     public void testValidateParameterPatternExpectFailNullValue() throws RequestFailedException {
84         MDC.put(MDC_SERVICE, "junit");
85         SvcLogicContext svcContext = new SvcLogicContext();
86         RequestContext rc = new RequestContext(svcContext);
87         String link = null;
88
89         validateVMURL(VMURL.parseURL(link));
90     }
91
92     /**
93      * This test expects a failure because the value to be validated is an empty URL
94      *
95      * @throws RequestFailedException Expected
96      */
97     @SuppressWarnings("nls")
98     @Test(expected = RequestFailedException.class)
99     public void testValidateParameterPatternExpectFailEmptyValue() throws RequestFailedException {
100         MDC.put(MDC_SERVICE, "junit");
101         SvcLogicContext svcContext = new SvcLogicContext();
102         RequestContext rc = new RequestContext(svcContext);
103         String link = "";
104
105         validateVMURL(VMURL.parseURL(link));
106     }
107
108     /**
109      * This test expects a failure because the value to be validated is a blank URL
110      *
111      * @throws RequestFailedException Expected
112      */
113     @SuppressWarnings("nls")
114     @Test(expected = RequestFailedException.class)
115     public void testValidateParameterPatternExpectFailBlankValue() throws RequestFailedException {
116         MDC.put(MDC_SERVICE, "junit");
117         SvcLogicContext svcContext = new SvcLogicContext();
118         RequestContext rc = new RequestContext(svcContext);
119         String link = " ";
120
121         validateVMURL(VMURL.parseURL(link));
122     }
123
124     /**
125      * This test expects a failure because the value to be validated is a bad URL
126      *
127      * @throws RequestFailedException Expected
128      */
129     @SuppressWarnings("nls")
130     @Test(expected = RequestFailedException.class)
131     public void testValidateParameterPatternExpectFailBadURL() throws RequestFailedException {
132         MDC.put(MDC_SERVICE, "junit");
133         SvcLogicContext svcContext = new SvcLogicContext();
134         RequestContext rc = new RequestContext(svcContext);
135         String link = "http://some.host:1234/01d82c08594a4b23a0f9260c94be0c4d/";
136
137         validateVMURL(VMURL.parseURL(link));
138     }
139
140     /**
141      * This test expects to pass
142      *
143      * @throws RequestFailedException Un-Expected
144      */
145     @SuppressWarnings("nls")
146     @Test
147     public void testValidateParameterPatternValidURL() throws RequestFailedException {
148         MDC.put(MDC_SERVICE, "junit");
149         SvcLogicContext svcContext = new SvcLogicContext();
150         RequestContext rc = new RequestContext(svcContext);
151         String link =
152                 "http://some.host:1234/v2/01d82c08594a4b23a0f9260c94be0c4d/servers/f888f89f-096b-421e-ba36-34f714071551";
153
154         validateVMURL(VMURL.parseURL(link));
155     }
156
157     @Override
158     protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
159             throws APPCException {
160         return null;
161     }
162 }