Fix some security vulnerabilities
[vfc/nfvo/driver/vnfm/svnfm.git] / nokiav2 / driver / src / test / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / nokia / spring / TestConditions.java
1 /*
2  * Copyright 2016-2017, Nokia Corporation
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring;
18
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;
27
28 import static org.mockito.Mockito.when;
29
30 public class TestConditions {
31
32     @Mock
33     private ConditionContext conditionContext;
34     @Mock
35     private Environment environment;
36
37     private String[] activeProfiles = new String[]{"a", "b"};
38
39     @Before
40     public void init() {
41         MockitoAnnotations.initMocks(this);
42         when(conditionContext.getEnvironment()).thenReturn(environment);
43         when(environment.getActiveProfiles()).thenReturn(activeProfiles);
44     }
45
46     /**
47      * if direct integration is not specified VF-C based integration is used
48      */
49     @Test
50     public void testVfcBased() throws Exception {
51         //verify
52         TestCase.assertTrue(new Conditions.UseForVfc().matches(conditionContext, null));
53         TestCase.assertFalse(new Conditions.UseForDirect().matches(conditionContext, null));
54     }
55
56     /**
57      * if direct integration is not specified VF-C based integration is used
58      */
59     @Test
60     public void testDirectBased() throws Exception {
61         activeProfiles[1] = "direct";
62         //verify
63         TestCase.assertFalse(new Conditions.UseForVfc().matches(conditionContext, null));
64         TestCase.assertTrue(new Conditions.UseForDirect().matches(conditionContext, null));
65     }
66
67     /**
68      * use class in a static way
69      */
70     @Test
71     public void useStaticway() {
72         TestUtil.coveragePrivateConstructorForClassesWithStaticMethodsOnly(Conditions.class);
73     }
74
75 }