aboutsummaryrefslogtreecommitdiffstats
path: root/appc-dispatcher
diff options
context:
space:
mode:
Diffstat (limited to 'appc-dispatcher')
-rw-r--r--appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/validationpolicy/RequestValidationPolicy.java16
-rw-r--r--appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/validationpolicy/RequestValidationPolicyTest.java81
2 files changed, 90 insertions, 7 deletions
diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/validationpolicy/RequestValidationPolicy.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/validationpolicy/RequestValidationPolicy.java
index 5d676654f..af6dc314b 100644
--- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/validationpolicy/RequestValidationPolicy.java
+++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/validationpolicy/RequestValidationPolicy.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications 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.
@@ -85,12 +87,12 @@ public class RequestValidationPolicy {
Set<VNFOperation> exclusionSet = null;
if (ruleDTO.getInclusionList() != null && !ruleDTO.getInclusionList().isEmpty()) {
inclusionSet = ruleDTO.getInclusionList().stream()
- .map(VNFOperation::findByString).filter(operation -> operation!=null)
+ .map(VNFOperation::findByString).filter(operation -> operation != null)
.collect(Collectors.toSet());
}
if (ruleDTO.getExclusionList() != null && !ruleDTO.getExclusionList().isEmpty()) {
exclusionSet = ruleDTO.getExclusionList().stream()
- .map(VNFOperation::findByString).filter(operation -> operation!=null)
+ .map(VNFOperation::findByString).filter(operation -> operation != null)
.collect(Collectors.toSet());
}
org.onap.appc.validationpolicy.rules.Rule rule = RuleFactory
@@ -100,7 +102,7 @@ public class RequestValidationPolicy {
actionInProgressRuleExecutor = new ActionInProgressRuleExecutor(Collections.unmodifiableMap(rules));
});
} catch (Exception e) {
- logger.error("Error reading request validation policies",e);
+ logger.error("Error reading request validation policies", e);
}
}
@@ -112,9 +114,9 @@ public class RequestValidationPolicy {
"GROUP BY ARTIFACT_NAME";
ArrayList<String> arguments = new ArrayList<>();
arguments.add("request_validation_policy");
- String jsonContent =null;
+ String jsonContent = null;
try{
- CachedRowSet rowSet = dbLibService.getData(query,arguments,schema);
+ CachedRowSet rowSet = dbLibService.getData(query, arguments, schema);
if(rowSet.next()){
jsonContent = rowSet.getString("ARTIFACT_CONTENT");
}
@@ -126,14 +128,14 @@ public class RequestValidationPolicy {
}
}
catch(SQLException e){
- logger.error("Error accessing database",e);
+ logger.error("Error accessing database", e);
throw new RuntimeException(e);
}
return jsonContent;
}
public RuleExecutor getInProgressRuleExecutor(){
- if(actionInProgressRuleExecutor ==null){
+ if(actionInProgressRuleExecutor == null){
throw new RuntimeException("Rule executor not available, initialization of RequestValidationPolicy failed");
}
return actionInProgressRuleExecutor;
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();
+ }
+}