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