2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Ericsson
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.appc.validationpolicy;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNull;
26 import java.sql.SQLException;
27 import org.junit.Before;
28 import org.junit.Rule;
29 import org.junit.Test;
30 import org.junit.rules.ExpectedException;
31 import org.mockito.Mockito;
32 import org.onap.ccsdk.sli.core.dblib.DbLibService;
33 import com.sun.rowset.CachedRowSetImpl;
35 public class RequestValidationPolicyTest {
37 private final String TEST_CONTENT = "TEST_CONTENT";
38 private final String ARTIFACT_CONTENT = "ARTIFACT_CONTENT";
39 private DbLibService db;
40 private RequestValidationPolicy policy;
41 private CachedRowSetImpl rowset;
44 public ExpectedException expectedEx = ExpectedException.none();
47 public void setup() throws SQLException {
48 db = Mockito.mock(DbLibService.class);
49 rowset = Mockito.mock(CachedRowSetImpl.class);
50 Mockito.when(rowset.next()).thenReturn(true);
51 Mockito.when(db.getData(Mockito.anyString(), Mockito.any(), Mockito.anyString())).thenReturn(rowset);
52 policy = new RequestValidationPolicy();
53 policy.setDbLibService(db);
57 public void testGetPolicyJson() throws SQLException {
58 Mockito.when(rowset.getString(ARTIFACT_CONTENT)).thenReturn(TEST_CONTENT);
59 assertEquals(TEST_CONTENT, policy.getPolicyJson());
63 public void testGetPolicyJsonBlank() throws SQLException {
64 Mockito.when(rowset.next()).thenThrow(new SQLException());
65 expectedEx.expect(RuntimeException.class);
66 policy.getPolicyJson();
70 public void testGetPolicyJsonError() throws SQLException {
71 Mockito.when(rowset.getString(ARTIFACT_CONTENT)).thenReturn("");
72 assertEquals("", policy.getPolicyJson());
76 public void testGetInProgressRuleExecutor() {
77 expectedEx.expect(RuntimeException.class);
78 expectedEx.expectMessage("Rule executor not available, initialization of RequestValidationPolicy failed");
79 policy.getInProgressRuleExecutor();