diff options
author | 2019-02-22 12:36:50 +0000 | |
---|---|---|
committer | 2019-02-22 17:05:33 +0000 | |
commit | b9a571dbcf43810353c3f00a6839d80570ed1d6b (patch) | |
tree | e6ac2ccf971f910a99bd22139a67b4b51d885fdc /appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test | |
parent | 6fbff11fd9d6bcf0319aeb8951bcd9c4e80be8d9 (diff) |
Test coverage for RequestValidationPolicy
Added test cases for untested parts of code
Issue-ID: APPC-1482
Change-Id: I3dfa64b4eb1f69a08ca3346d75ae362affd55e0d
Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test')
-rw-r--r-- | appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/validationpolicy/RequestValidationPolicyTest.java | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/validationpolicy/RequestValidationPolicyTest.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/validationpolicy/RequestValidationPolicyTest.java new file mode 100644 index 000000000..b8e4da32a --- /dev/null +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/validationpolicy/RequestValidationPolicyTest.java @@ -0,0 +1,81 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 Ericsson + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.validationpolicy; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import java.sql.SQLException; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.Mockito; +import org.onap.ccsdk.sli.core.dblib.DbLibService; +import com.sun.rowset.CachedRowSetImpl; + +public class RequestValidationPolicyTest { + + private final String TEST_CONTENT = "TEST_CONTENT"; + private final String ARTIFACT_CONTENT = "ARTIFACT_CONTENT"; + private DbLibService db; + private RequestValidationPolicy policy; + private CachedRowSetImpl rowset; + + @Rule + public ExpectedException expectedEx = ExpectedException.none(); + + @Before + public void setup() throws SQLException { + db = Mockito.mock(DbLibService.class); + rowset = Mockito.mock(CachedRowSetImpl.class); + Mockito.when(rowset.next()).thenReturn(true); + Mockito.when(db.getData(Mockito.anyString(), Mockito.any(), Mockito.anyString())).thenReturn(rowset); + policy = new RequestValidationPolicy(); + policy.setDbLibService(db); + } + + @Test + public void testGetPolicyJson() throws SQLException { + Mockito.when(rowset.getString(ARTIFACT_CONTENT)).thenReturn(TEST_CONTENT); + assertEquals(TEST_CONTENT, policy.getPolicyJson()); + } + + @Test + public void testGetPolicyJsonBlank() throws SQLException { + Mockito.when(rowset.next()).thenThrow(new SQLException()); + expectedEx.expect(RuntimeException.class); + policy.getPolicyJson(); + } + + @Test + public void testGetPolicyJsonError() throws SQLException { + Mockito.when(rowset.getString(ARTIFACT_CONTENT)).thenReturn(""); + assertEquals("", policy.getPolicyJson()); + } + + @Test + public void testGetInProgressRuleExecutor() { + expectedEx.expect(RuntimeException.class); + expectedEx.expectMessage("Rule executor not available, initialization of RequestValidationPolicy failed"); + policy.getInProgressRuleExecutor(); + } +} |