e897e4fe92ecb4ede4a1580093ff3ce48532683f
[ccsdk/apps.git] / ms / neng / src / test / java / org / onap / ccsdk / apps / ms / neng / core / policy / PolicyParametersImplTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK.apps
4  * ================================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.ccsdk.apps.ms.neng.core.policy;
22
23 import static org.junit.Assert.assertEquals;
24
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.mockito.InjectMocks;
28 import org.mockito.Mock;
29 import org.mockito.Mockito;
30 import org.mockito.runners.MockitoJUnitRunner;
31 import org.onap.ccsdk.apps.ms.neng.persistence.entity.IdentifierMap;
32 import org.onap.ccsdk.apps.ms.neng.persistence.entity.ServiceParameter;
33 import org.onap.ccsdk.apps.ms.neng.persistence.repository.IdentifierMapRespository;
34 import org.onap.ccsdk.apps.ms.neng.persistence.repository.ServiceParameterRepository;
35
36 @RunWith(MockitoJUnitRunner.class)
37 public class PolicyParametersImplTest {
38     @Mock
39     IdentifierMapRespository identifierMapRepository;
40     @Mock
41     ServiceParameterRepository serviceParameterRepository;
42     @Mock
43     IdentifierMap identifierMap;
44     @InjectMocks
45     PolicyParametersImpl policyParametersImpl;
46     @Mock
47     ServiceParameter sp;
48     
49     static final String RECIPE_SEPERATOR_PARAM = "recipe_separator";
50     static final String MAX_GEN_ATTEMPT_PARAM = "max_gen_attempt";
51
52     @Test
53     public void policyParameterTest() throws Exception {
54         Mockito.when(serviceParameterRepository.findByName(RECIPE_SEPERATOR_PARAM)).thenReturn(sp);
55         Mockito.when(sp.getValue()).thenReturn("value");
56         assertEquals("value", policyParametersImpl.getRecipeSeparator());
57
58         Mockito.when(identifierMapRepository.findByPolicyFnName("name")).thenReturn(identifierMap);
59         Mockito.when(identifierMap.getJsFnName()).thenReturn("jsFnName");
60         assertEquals("jsFnName", policyParametersImpl.mapFunction("name"));
61
62         Mockito.when(sp.getValue()).thenReturn("1");
63         Mockito.when(serviceParameterRepository.findByName(MAX_GEN_ATTEMPT_PARAM)).thenReturn(sp);
64         assertEquals(1, policyParametersImpl.getMaxGenAttempt());
65     }
66 }