2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.dg.common.impl;
26 import java.util.Date;
27 import java.util.HashMap;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.Matchers;
33 import org.onap.appc.dg.common.VNFConfigurator;
34 import org.onap.appc.exceptions.APPCException;
35 import org.onap.appc.mdsal.MDSALStore;
36 import org.onap.appc.mdsal.impl.MDSALStoreFactory;
37 import org.onap.appc.mdsal.impl.MDSALStoreImpl;
38 import org.onap.appc.mdsal.objects.BundleInfo;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
40 import org.powermock.api.mockito.PowerMockito;
41 import org.powermock.core.classloader.annotations.PrepareForTest;
42 import org.powermock.modules.junit4.PowerMockRunner;
43 import com.att.eelf.configuration.EELFLogger;
44 import com.att.eelf.configuration.EELFManager;
45 import static org.junit.Assert.assertNotNull;
47 @RunWith(PowerMockRunner.class)
48 @PrepareForTest({MDSALStoreImpl.class, MDSALStoreFactory.class})
49 public class TestVNFConfiguratorImpl {
51 private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestVNFConfiguratorImpl.class);
55 logger.setLevel(EELFLogger.Level.DEBUG);
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());
69 public void testYangPresentScenario() throws APPCException {
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()))
78 Map<String, String> params = new HashMap<String, String>();
79 params.put("uniqueId", "uniqueId");
80 params.put("yang", "yang");
81 params.put("configJSON", "configJSON");
82 params.put("requestId", "requestId");
83 configurator.storeConfig(params, new SvcLogicContext());
84 assertNotNull(configurator);
88 public void testYangAbsentScenario() throws Exception {
90 VNFConfigurator configurator = new VNFConfiguratorImpl();
91 PowerMockito.mockStatic(MDSALStoreFactory.class);
93 MDSALStore mdsalStore = PowerMockito.mock(MDSALStoreImpl.class);
95 PowerMockito.when(MDSALStoreFactory.createMDSALStore()).thenReturn(mdsalStore);
97 PowerMockito.when(mdsalStore.isModulePresent(Matchers.anyString(), (Date) Matchers.anyObject()))
100 PowerMockito.doNothing()
101 .when(mdsalStore).storeYangModule(Matchers.anyString(), (BundleInfo) Matchers.anyObject());
103 Map<String, String> params = new HashMap<String, String>();
104 params.put("uniqueId", "uniqueId");
105 params.put("yang", "yang");
106 params.put("configJSON", "configJSON");
107 params.put("requestId", "requestId");
108 configurator.storeConfig(params, new SvcLogicContext());
109 assertNotNull(configurator);