2 * ============LICENSE_START=======================================================
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
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=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.appc.dg.common.impl;
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;
42 import java.util.Date;
43 import java.util.HashMap;
46 @RunWith(PowerMockRunner.class)
47 @PrepareForTest({MDSALStoreImpl.class,MDSALStoreFactory.class})
48 public class TestVNFConfiguratorImpl {
50 private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestVNFConfiguratorImpl.class);
54 logger.setLevel(EELFLogger.Level.DEBUG);
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());
68 public void testYangPresentScenario() throws APPCException {
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);
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());
85 public void testYangAbsentScenario() throws Exception {
87 VNFConfigurator configurator = new VNFConfiguratorImpl();
88 PowerMockito.mockStatic(MDSALStoreFactory.class);
90 MDSALStore mdsalStore = PowerMockito.mock(MDSALStoreImpl.class);
92 PowerMockito.when(MDSALStoreFactory.createMDSALStore()).thenReturn(mdsalStore);
94 PowerMockito.when(mdsalStore.isModulePresent(Matchers.anyString(),(Date) Matchers.anyObject())).thenReturn(false);
96 PowerMockito.doNothing().when(mdsalStore).storeYangModule(Matchers.anyString(),(BundleInfo)Matchers.anyObject());
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());