added assert statements in 4 jUnits
[appc.git] / appc-config / appc-data-services / provider / src / test / java / org / onap / appc / data / services / db / TestGeneralDataService.java
1 /*-
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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
13  * the License.
14  *
15  * SPDX-License-Identifier: Apache-2.0
16  * ============LICENSE_END=========================================================
17  */
18
19 package org.onap.appc.data.services.db;
20
21 import static org.mockito.Matchers.anyObject;
22 import static org.mockito.Matchers.eq;
23 import java.util.HashMap;
24 import java.util.Map;
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;
35 import static org.junit.Assert.assertEquals;
36 import static org.junit.Assert.assertNotNull;
37
38 @RunWith(PowerMockRunner.class)
39 @PrepareForTest(DGGeneralDBService.class)
40 public class TestGeneralDataService {
41
42   private GeneralDataService generalDataService;
43   private Map<String, String> inParams;
44   private SvcLogicContext ctx;
45   private DGGeneralDBService dGGeneralDBService;
46
47   @Before
48   public void setUp() throws SvcLogicException {
49     PowerMockito.mockStatic(DGGeneralDBService.class);
50     dGGeneralDBService = Mockito.mock(DGGeneralDBService.class);
51     ctx = new SvcLogicContext();
52     generalDataService = new GeneralDataService();
53     inParams = new HashMap<>();
54     inParams.put("message", "message");
55     PowerMockito.when(DGGeneralDBService.initialise()).thenReturn(dGGeneralDBService);
56   }
57
58   @Test
59   public void testSaveTransactionLog() throws SvcLogicException {
60     PowerMockito.when(dGGeneralDBService.saveConfigTransactionLog(anyObject(), eq("")))
61         .thenReturn(QueryStatus.SUCCESS);
62     generalDataService.saveTransactionLog(inParams, ctx);
63     assertNotNull(dGGeneralDBService);
64   }
65
66   @Test(expected = Exception.class)
67   public void testSaveTransactionLogFailure() throws SvcLogicException {
68     PowerMockito.when(dGGeneralDBService.saveConfigTransactionLog(anyObject(), eq("")))
69         .thenReturn(QueryStatus.FAILURE);
70     generalDataService.saveTransactionLog(inParams, ctx);
71   }
72
73   @Test(expected = Exception.class)
74   public void testSaveTransactionLogException() throws SvcLogicException {
75     generalDataService.saveTransactionLog(inParams, null);
76   }
77
78 }