Merge of new rebased code
[appc.git] / appc-dg / appc-dg-shared / appc-dg-common / src / test / java / org / openecomp / appc / dg / common / impl / TestVNFConfiguratorImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.openecomp.appc.dg.common.impl;
23
24 import org.openecomp.appc.dg.common.VNFConfigurator;
25 import org.openecomp.appc.exceptions.APPCException;
26 import org.openecomp.appc.mdsal.MDSALStore;
27 import org.openecomp.appc.mdsal.impl.MDSALStoreFactory;
28 import org.openecomp.appc.mdsal.impl.MDSALStoreImpl;
29 import org.openecomp.appc.mdsal.objects.BundleInfo;
30 import com.att.eelf.configuration.EELFLogger;
31 import com.att.eelf.configuration.EELFManager;
32 import org.openecomp.sdnc.sli.SvcLogicContext;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.Matchers;
37 import org.powermock.api.mockito.PowerMockito;
38 import org.powermock.core.classloader.annotations.PrepareForTest;
39 import org.powermock.modules.junit4.PowerMockRunner;
40
41 import java.util.Date;
42 import java.util.HashMap;
43 import java.util.Map;
44
45 @RunWith(PowerMockRunner.class)
46 @PrepareForTest({MDSALStoreImpl.class,MDSALStoreFactory.class})
47 public class TestVNFConfiguratorImpl {
48
49     private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestVNFConfiguratorImpl.class);
50
51     @Before
52     public void setUp() {
53         logger.setLevel(EELFLogger.Level.DEBUG);
54     }
55
56     @Test(expected = APPCException.class)
57     public void testValidations() throws APPCException {
58         VNFConfigurator configurator = new VNFConfiguratorImpl();
59         Map<String,String> params = new HashMap<String, String>();
60         params.put("uniqueId","uniqueId");
61         params.put("yang","yang");
62         params.put("configJSON","configJSON");
63         configurator.storeConfig(params,new SvcLogicContext());
64     }
65
66     @Test
67     public void testYangPresentScenario() throws APPCException {
68
69         VNFConfigurator configurator = new VNFConfiguratorImpl();
70         PowerMockito.mockStatic(MDSALStoreFactory.class);
71         MDSALStore mdsalStore = PowerMockito.mock(MDSALStoreImpl.class);
72         PowerMockito.when(MDSALStoreFactory.createMDSALStore()).thenReturn(mdsalStore);
73         PowerMockito.when(mdsalStore.isModulePresent(Matchers.anyString(),(Date) Matchers.anyObject())).thenReturn(true);
74
75         Map<String,String> params = new HashMap<String, String>();
76         params.put("uniqueId","uniqueId");
77         params.put("yang","yang");
78         params.put("configJSON","configJSON");
79         params.put("requestId","requestId");
80         configurator.storeConfig(params,new SvcLogicContext());
81     }
82
83     @Test
84     public void testYangAbsentScenario() throws Exception {
85
86         VNFConfigurator configurator = new VNFConfiguratorImpl();
87         PowerMockito.mockStatic(MDSALStoreFactory.class);
88
89         MDSALStore mdsalStore = PowerMockito.mock(MDSALStoreImpl.class);
90
91         PowerMockito.when(MDSALStoreFactory.createMDSALStore()).thenReturn(mdsalStore);
92
93         PowerMockito.when(mdsalStore.isModulePresent(Matchers.anyString(),(Date) Matchers.anyObject())).thenReturn(false);
94
95         PowerMockito.doNothing().when(mdsalStore).storeYangModule(Matchers.anyString(),(BundleInfo)Matchers.anyObject());
96
97         Map<String,String> params = new HashMap<>();
98         params.put("uniqueId","uniqueId");
99         params.put("yang","yang");
100         params.put("configJSON","configJSON");
101         params.put("requestId","requestId");
102         configurator.storeConfig(params,new SvcLogicContext());
103
104     }
105 }