2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6 * file except in compliance with the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software distributed under the License
11 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12 * or implied. See the License for the specific language governing permissions and limitations under
15 * SPDX-License-Identifier: Apache-2.0
16 * ============LICENSE_END=========================================================
19 package org.onap.appc.data.services.db;
21 import static org.mockito.Matchers.anyObject;
22 import static org.mockito.Matchers.eq;
23 import java.util.HashMap;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.mockito.Mockito;
29 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
32 import org.powermock.api.mockito.PowerMockito;
33 import org.powermock.core.classloader.annotations.PrepareForTest;
34 import org.powermock.modules.junit4.PowerMockRunner;
36 @RunWith(PowerMockRunner.class)
37 @PrepareForTest(DGGeneralDBService.class)
38 public class TestGeneralDataService {
40 private GeneralDataService generalDataService;
41 private Map<String, String> inParams;
42 private SvcLogicContext ctx;
43 private DGGeneralDBService dGGeneralDBService;
46 public void setUp() throws SvcLogicException {
47 PowerMockito.mockStatic(DGGeneralDBService.class);
48 dGGeneralDBService = Mockito.mock(DGGeneralDBService.class);
49 ctx = new SvcLogicContext();
50 generalDataService = new GeneralDataService();
51 inParams = new HashMap<>();
52 inParams.put("message", "message");
53 PowerMockito.when(DGGeneralDBService.initialise()).thenReturn(dGGeneralDBService);
57 public void testSaveTransactionLog() throws SvcLogicException {
58 PowerMockito.when(dGGeneralDBService.saveConfigTransactionLog(anyObject(), eq("")))
59 .thenReturn(QueryStatus.SUCCESS);
60 generalDataService.saveTransactionLog(inParams, ctx);
63 @Test(expected = Exception.class)
64 public void testSaveTransactionLogFailure() throws SvcLogicException {
65 PowerMockito.when(dGGeneralDBService.saveConfigTransactionLog(anyObject(), eq("")))
66 .thenReturn(QueryStatus.FAILURE);
67 generalDataService.saveTransactionLog(inParams, ctx);
70 @Test(expected = Exception.class)
71 public void testSaveTransactionLogException() throws SvcLogicException {
72 generalDataService.saveTransactionLog(inParams, null);