2  * ============LICENSE_START=======================================================
 
   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
 
  13  *      http://www.apache.org/licenses/LICENSE-2.0
 
  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.
 
  21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
 
  22  * ============LICENSE_END=========================================================
 
  25 package org.openecomp.appc.adapter.iaas.impl;
 
  27 import java.lang.reflect.Field;
 
  30 import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderOperation;
 
  31 import org.openecomp.appc.exceptions.APPCException;
 
  32 import com.att.cdp.zones.model.ModelObject;
 
  33 import org.junit.Before;
 
  34 import org.junit.BeforeClass;
 
  35 import org.junit.Test;
 
  38 import org.openecomp.appc.configuration.ConfigurationFactory;
 
  39 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 
  41 import static org.openecomp.appc.adapter.iaas.provider.operation.common.constants.Constants.MDC_SERVICE;
 
  44  * This class is used to test methods and functions of the adapter implementation that do not require and do not set up
 
  45  * connections to any providers.
 
  51 public class TestProviderOperation extends ProviderOperation{
 
  53     private static Class<?> providerAdapterImplClass;
 
  54     private static Class<?> configurationFactoryClass;
 
  55     private static Field providerCacheField;
 
  56     private static Field configField;
 
  59      * Use reflection to locate fields and methods so that they can be manipulated during the test to change the
 
  60      * internal state accordingly.
 
  62      * @throws NoSuchFieldException
 
  63      *             if the field(s) dont exist
 
  64      * @throws SecurityException
 
  65      *             if reflective access is not allowed
 
  66      * @throws NoSuchMethodException
 
  67      *             If the method(s) dont exist
 
  69     @SuppressWarnings("nls")
 
  71     public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException {
 
  72         providerAdapterImplClass = ProviderAdapterImpl.class;
 
  73         configurationFactoryClass = ConfigurationFactory.class;
 
  75         providerCacheField = providerAdapterImplClass.getDeclaredField("providerCache");
 
  76         providerCacheField.setAccessible(true);
 
  78         configField = configurationFactoryClass.getDeclaredField("config");
 
  79         configField.setAccessible(true);
 
  83      * This test expects a failure because the value to be validated is a null URL
 
  85      * @throws RequestFailedException
 
  88     @SuppressWarnings("nls")
 
  89     @Test(expected = RequestFailedException.class)
 
  90     public void testValidateParameterPatternExpectFailNullValue() throws RequestFailedException {
 
  91         MDC.put(MDC_SERVICE, "junit");
 
  92         SvcLogicContext svcContext = new SvcLogicContext();
 
  93         RequestContext rc = new RequestContext(svcContext);
 
  96         validateVMURL(VMURL.parseURL(link));
 
 100      * This test expects a failure because the value to be validated is an empty URL
 
 102      * @throws RequestFailedException
 
 105     @SuppressWarnings("nls")
 
 106     @Test(expected = RequestFailedException.class)
 
 107     public void testValidateParameterPatternExpectFailEmptyValue() throws RequestFailedException {
 
 108         MDC.put(MDC_SERVICE, "junit");
 
 109         SvcLogicContext svcContext = new SvcLogicContext();
 
 110         RequestContext rc = new RequestContext(svcContext);
 
 113         validateVMURL(VMURL.parseURL(link));
 
 117      * This test expects a failure because the value to be validated is a blank URL
 
 119      * @throws RequestFailedException
 
 122     @SuppressWarnings("nls")
 
 123     @Test(expected = RequestFailedException.class)
 
 124     public void testValidateParameterPatternExpectFailBlankValue() throws RequestFailedException {
 
 125         MDC.put(MDC_SERVICE, "junit");
 
 126         SvcLogicContext svcContext = new SvcLogicContext();
 
 127         RequestContext rc = new RequestContext(svcContext);
 
 130         validateVMURL(VMURL.parseURL(link));
 
 134      * This test expects a failure because the value to be validated is a bad URL
 
 136      * @throws RequestFailedException
 
 139     @SuppressWarnings("nls")
 
 140     @Test(expected = RequestFailedException.class)
 
 141     public void testValidateParameterPatternExpectFailBadURL() throws RequestFailedException {
 
 142         MDC.put(MDC_SERVICE, "junit");
 
 143         SvcLogicContext svcContext = new SvcLogicContext();
 
 144         RequestContext rc = new RequestContext(svcContext);
 
 145         String link = "http://some.host:1234/01d82c08594a4b23a0f9260c94be0c4d/";
 
 147         validateVMURL(VMURL.parseURL(link));
 
 151      * This test expects to pass
 
 153      * @throws RequestFailedException
 
 156     @SuppressWarnings("nls")
 
 158     public void testValidateParameterPatternValidURL() throws RequestFailedException {
 
 159         MDC.put(MDC_SERVICE, "junit");
 
 160         SvcLogicContext svcContext = new SvcLogicContext();
 
 161         RequestContext rc = new RequestContext(svcContext);
 
 163             "http://some.host:1234/v2/01d82c08594a4b23a0f9260c94be0c4d/servers/f888f89f-096b-421e-ba36-34f714071551";
 
 165         validateVMURL(VMURL.parseURL(link));
 
 169     protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context) throws APPCException {