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