Merge "Merge the POMBA code to ONAP AAI data router"
[aai/data-router.git] / src / test / java / org / onap / aai / datarouter / policy / ServiceIntegrityValidationPolicyTest.java
diff --git a/src/test/java/org/onap/aai/datarouter/policy/ServiceIntegrityValidationPolicyTest.java b/src/test/java/org/onap/aai/datarouter/policy/ServiceIntegrityValidationPolicyTest.java
new file mode 100644 (file)
index 0000000..0f0ee80
--- /dev/null
@@ -0,0 +1,112 @@
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright © 2017-2018 Amdocs\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *       http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+package org.onap.aai.datarouter.policy;\r
+\r
+import static org.junit.Assert.*;\r
+import static org.mockito.Matchers.anyObject;\r
+import static org.mockito.Matchers.anyString;\r
+\r
+import java.io.File;\r
+import java.io.FileInputStream;\r
+\r
+import org.apache.camel.Exchange;\r
+import org.apache.camel.Message;\r
+import org.apache.commons.io.IOUtils;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.onap.aai.datarouter.policy.EntityEventPolicy;\r
+import org.onap.aai.datarouter.policy.EntityEventPolicyConfig;\r
+import org.onap.aai.datarouter.util.NodeUtils;\r
+import org.onap.aai.datarouter.util.SearchServiceAgent;\r
+import org.powermock.api.mockito.PowerMockito;\r
+\r
+\r
+public class ServiceIntegrityValidationPolicyTest {\r
+    private ServiceIntegrityValidationPolicy policy;\r
+    private String eventJson;\r
+    private String validationJson;\r
+    private String violationjson;\r
+\r
+    private InMemorySearchDatastore searchDb;\r
+\r
+    @SuppressWarnings("unchecked")\r
+    @Before\r
+    public void init() throws Exception {\r
+\r
+        String searchCertPath = "";\r
+        String searchCertTruststore ="";\r
+        String searchCertPassword = "password";\r
+        String searchBaseURL = "";\r
+        String endpoint = "services/search-data-service/v1/search/indexes/";\r
+        String validationIndexName = "service-validations";\r
+        String violationIndexName = "service-violations";\r
+\r
+\r
+        searchDb = new InMemorySearchDatastore();\r
+        policy = new ServiceIntegrityValidationPolicyStubbed(searchCertPath, searchCertTruststore,\r
+                searchCertPassword, searchBaseURL, endpoint, validationIndexName, violationIndexName).withSearchDb(searchDb);\r
+\r
+        FileInputStream event = new FileInputStream( new File("src/test/resources/poa_audit_result.json"));\r
+        eventJson = IOUtils.toString(event, "UTF-8");\r
+\r
+        FileInputStream validation = new FileInputStream( new File("src/test/resources/poa_auditservice_validation.json"));\r
+        validationJson = IOUtils.toString(validation, "UTF-8");\r
+\r
+        FileInputStream violation = new FileInputStream( new File("src/test/resources/poa_auditservice_violation.json"));\r
+        violationjson = IOUtils.toString(violation, "UTF-8");\r
+\r
+\r
+    }\r
+\r
+    @Test\r
+    public void testProcess() throws Exception {\r
+\r
+        policy.process(getExchangeEvent(validationJson));\r
+        policy.process(getExchangeEvent(violationjson));\r
+\r
+        assertNotNull(searchDb.get("service-validations"));\r
+        assertNotNull(searchDb.get("service-violations"));\r
+\r
+    }\r
+\r
+\r
+\r
+    private Exchange getExchangeEvent(String outputJson){\r
+\r
+        Exchange exchange = PowerMockito.mock(Exchange.class);\r
+        Message inMessage = PowerMockito.mock(Message.class);\r
+        Message outMessage = PowerMockito.mock(Message.class);\r
+        PowerMockito.when(exchange.getIn()).thenReturn(inMessage);\r
+        PowerMockito.when(inMessage.getBody()).thenReturn(eventJson);\r
+\r
+        PowerMockito.when(exchange.getOut()).thenReturn(outMessage);\r
+        PowerMockito.when(outMessage.getBody()).thenReturn(outputJson);\r
+\r
+        PowerMockito.doNothing().when(outMessage).setBody(anyObject());\r
+        PowerMockito.doNothing().when(outMessage).setHeader(anyString(), anyObject());\r
+\r
+        return exchange;\r
+\r
+    }\r
+\r
+\r
+\r
+}\r