2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.openecomp.appc.dg.common.impl;
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;
41 import java.util.Date;
42 import java.util.HashMap;
45 @RunWith(PowerMockRunner.class)
46 @PrepareForTest({MDSALStoreImpl.class,MDSALStoreFactory.class})
47 public class TestVNFConfiguratorImpl {
49 private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestVNFConfiguratorImpl.class);
53 logger.setLevel(EELFLogger.Level.DEBUG);
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());
67 public void testYangPresentScenario() throws APPCException {
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);
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());
84 public void testYangAbsentScenario() throws Exception {
86 VNFConfigurator configurator = new VNFConfiguratorImpl();
87 PowerMockito.mockStatic(MDSALStoreFactory.class);
89 MDSALStore mdsalStore = PowerMockito.mock(MDSALStoreImpl.class);
91 PowerMockito.when(MDSALStoreFactory.createMDSALStore()).thenReturn(mdsalStore);
93 PowerMockito.when(mdsalStore.isModulePresent(Matchers.anyString(),(Date) Matchers.anyObject())).thenReturn(false);
95 PowerMockito.doNothing().when(mdsalStore).storeYangModule(Matchers.anyString(),(BundleInfo)Matchers.anyObject());
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());