2 * Copyright 2016-2017, Nokia Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring;
19 import junit.framework.TestCase;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.mockito.Mock;
23 import org.mockito.MockitoAnnotations;
24 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil;
25 import org.springframework.context.annotation.ConditionContext;
26 import org.springframework.core.env.Environment;
28 import static org.mockito.Mockito.when;
30 public class TestConditions {
33 private ConditionContext conditionContext;
35 private Environment environment;
37 private String[] activeProfiles = new String[]{"a", "b"};
41 MockitoAnnotations.initMocks(this);
42 when(conditionContext.getEnvironment()).thenReturn(environment);
43 when(environment.getActiveProfiles()).thenReturn(activeProfiles);
47 * if direct integration is not specified VF-C based integration is used
50 public void testVfcBased() throws Exception {
52 TestCase.assertTrue(new Conditions.UseForVfc().matches(conditionContext, null));
53 TestCase.assertFalse(new Conditions.UseForDirect().matches(conditionContext, null));
57 * if direct integration is not specified VF-C based integration is used
60 public void testDirectBased() throws Exception {
61 activeProfiles[1] = "direct";
63 TestCase.assertFalse(new Conditions.UseForVfc().matches(conditionContext, null));
64 TestCase.assertTrue(new Conditions.UseForDirect().matches(conditionContext, null));
68 * use class in a static way
71 public void useStaticway() {
72 TestUtil.coveragePrivateConstructorForClassesWithStaticMethodsOnly(Conditions.class);