Second part of onap rename
[appc.git] / appc-dg / appc-dg-shared / appc-dg-common / src / test / java / org / onap / appc / dg / common / impl / TestVNFConfiguratorImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.dg.common.impl;
26
27 import org.onap.appc.dg.common.VNFConfigurator;
28 import org.onap.appc.exceptions.APPCException;
29 import org.onap.appc.mdsal.MDSALStore;
30 import org.onap.appc.mdsal.impl.MDSALStoreFactory;
31 import org.onap.appc.mdsal.impl.MDSALStoreImpl;
32 import org.onap.appc.mdsal.objects.BundleInfo;
33 import com.att.eelf.configuration.EELFLogger;
34 import com.att.eelf.configuration.EELFManager;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39 import org.mockito.Matchers;
40 import org.powermock.api.mockito.PowerMockito;
41 import org.powermock.core.classloader.annotations.PrepareForTest;
42 import org.powermock.modules.junit4.PowerMockRunner;
43
44 import java.util.Date;
45 import java.util.HashMap;
46 import java.util.Map;
47
48 @RunWith(PowerMockRunner.class)
49 @PrepareForTest({MDSALStoreImpl.class,MDSALStoreFactory.class})
50 public class TestVNFConfiguratorImpl {
51
52     private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestVNFConfiguratorImpl.class);
53
54     @Before
55     public void setUp() {
56         logger.setLevel(EELFLogger.Level.DEBUG);
57     }
58
59     @Test(expected = APPCException.class)
60     public void testValidations() throws APPCException {
61         VNFConfigurator configurator = new VNFConfiguratorImpl();
62         Map<String,String> params = new HashMap<String, String>();
63         params.put("uniqueId","uniqueId");
64         params.put("yang","yang");
65         params.put("configJSON","configJSON");
66         configurator.storeConfig(params,new SvcLogicContext());
67     }
68
69     @Test
70     public void testYangPresentScenario() throws APPCException {
71
72         VNFConfigurator configurator = new VNFConfiguratorImpl();
73         PowerMockito.mockStatic(MDSALStoreFactory.class);
74         MDSALStore mdsalStore = PowerMockito.mock(MDSALStoreImpl.class);
75         PowerMockito.when(MDSALStoreFactory.createMDSALStore()).thenReturn(mdsalStore);
76         PowerMockito.when(mdsalStore.isModulePresent(Matchers.anyString(),(Date) Matchers.anyObject())).thenReturn(true);
77
78         Map<String,String> params = new HashMap<String, String>();
79         params.put("uniqueId","uniqueId");
80         params.put("yang","yang");
81         params.put("configJSON","configJSON");
82         params.put("requestId","requestId");
83         configurator.storeConfig(params,new SvcLogicContext());
84     }
85
86     @Test
87     public void testYangAbsentScenario() throws Exception {
88
89         VNFConfigurator configurator = new VNFConfiguratorImpl();
90         PowerMockito.mockStatic(MDSALStoreFactory.class);
91
92         MDSALStore mdsalStore = PowerMockito.mock(MDSALStoreImpl.class);
93
94         PowerMockito.when(MDSALStoreFactory.createMDSALStore()).thenReturn(mdsalStore);
95
96         PowerMockito.when(mdsalStore.isModulePresent(Matchers.anyString(),(Date) Matchers.anyObject())).thenReturn(false);
97
98         PowerMockito.doNothing().when(mdsalStore).storeYangModule(Matchers.anyString(),(BundleInfo)Matchers.anyObject());
99
100         Map<String,String> params = new HashMap<>();
101         params.put("uniqueId","uniqueId");
102         params.put("yang","yang");
103         params.put("configJSON","configJSON");
104         params.put("requestId","requestId");
105         configurator.storeConfig(params,new SvcLogicContext());
106
107     }
108 }