2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
 
   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
 
  12  *      http://www.apache.org/licenses/LICENSE-2.0
 
  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=========================================================
 
  24 package org.openecomp.appc.adapter.iaas.impl;
 
  26 import java.lang.reflect.Field;
 
  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;
 
  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.
 
  44 public class TestProviderAdapterImplNoConnection {
 
  46     private static Class<?> providerAdapterImplClass;
 
  47     private static Class<?> configurationFactoryClass;
 
  48     private static Field providerCacheField;
 
  49     private static Field configField;
 
  51     private ProviderAdapterImpl adapter;
 
  54      * Use reflection to locate fields and methods so that they can be manipulated during the test to change the
 
  55      * internal state accordingly.
 
  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
 
  64     @SuppressWarnings("nls")
 
  66     public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException {
 
  67         providerAdapterImplClass = ProviderAdapterImpl.class;
 
  68         configurationFactoryClass = ConfigurationFactory.class;
 
  70         providerCacheField = providerAdapterImplClass.getDeclaredField("providerCache");
 
  71         providerCacheField.setAccessible(true);
 
  73         configField = configurationFactoryClass.getDeclaredField("config");
 
  74         configField.setAccessible(true);
 
  78      * initialize the test cases
 
  82         adapter = new ProviderAdapterImpl(false);
 
  86      * This test expects a failure because the value to be validated is a null URL
 
  88      * @throws RequestFailedException
 
  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);
 
  99         adapter.validateVMURL(VMURL.parseURL(link));
 
 103      * This test expects a failure because the value to be validated is an empty URL
 
 105      * @throws RequestFailedException
 
 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);
 
 116         adapter.validateVMURL(VMURL.parseURL(link));
 
 120      * This test expects a failure because the value to be validated is a blank URL
 
 122      * @throws RequestFailedException
 
 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);
 
 133         adapter.validateVMURL(VMURL.parseURL(link));
 
 137      * This test expects a failure because the value to be validated is a bad URL
 
 139      * @throws RequestFailedException
 
 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/";
 
 150         adapter.validateVMURL(VMURL.parseURL(link));
 
 154      * This test expects to pass
 
 156      * @throws RequestFailedException
 
 159     @SuppressWarnings("nls")
 
 161     public void testValidateParameterPatternValidURL() throws RequestFailedException {
 
 162         MDC.put(ProviderAdapterImpl.MDC_SERVICE, "junit");
 
 163         SvcLogicContext svcContext = new SvcLogicContext();
 
 164         RequestContext rc = new RequestContext(svcContext);
 
 166             "http://some.host:1234/v2/01d82c08594a4b23a0f9260c94be0c4d/servers/f888f89f-096b-421e-ba36-34f714071551";
 
 168         adapter.validateVMURL(VMURL.parseURL(link));