2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
\r
6 * Copyright © 2017-2018 Amdocs
\r
7 * ================================================================================
\r
8 * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * you may not use this file except in compliance with the License.
\r
10 * You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing, software
\r
15 * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * See the License for the specific language governing permissions and
\r
18 * limitations under the License.
\r
19 * ============LICENSE_END=========================================================
\r
21 package org.onap.aai.datarouter.policy;
\r
23 import static org.junit.Assert.*;
\r
24 import static org.mockito.Matchers.anyObject;
\r
25 import static org.mockito.Matchers.anyString;
\r
27 import java.io.File;
\r
28 import java.io.FileInputStream;
\r
30 import org.apache.camel.Exchange;
\r
31 import org.apache.camel.Message;
\r
32 import org.apache.commons.io.IOUtils;
\r
33 import org.junit.Before;
\r
34 import org.junit.Test;
\r
35 import org.onap.aai.datarouter.policy.EntityEventPolicy;
\r
36 import org.onap.aai.datarouter.policy.EntityEventPolicyConfig;
\r
37 import org.onap.aai.datarouter.util.NodeUtils;
\r
38 import org.onap.aai.datarouter.util.SearchServiceAgent;
\r
39 import org.powermock.api.mockito.PowerMockito;
\r
42 public class ServiceIntegrityValidationPolicyTest {
\r
43 private ServiceIntegrityValidationPolicy policy;
\r
44 private String eventJson;
\r
45 private String validationJson;
\r
46 private String violationjson;
\r
48 private InMemorySearchDatastore searchDb;
\r
50 @SuppressWarnings("unchecked")
\r
52 public void init() throws Exception {
\r
54 String searchCertPath = "";
\r
55 String searchCertTruststore ="";
\r
56 String searchCertPassword = "password";
\r
57 String searchBaseURL = "";
\r
58 String endpoint = "services/search-data-service/v1/search/indexes/";
\r
59 String validationIndexName = "service-validations";
\r
60 String violationIndexName = "service-violations";
\r
63 searchDb = new InMemorySearchDatastore();
\r
64 policy = new ServiceIntegrityValidationPolicyStubbed(searchCertPath, searchCertTruststore,
\r
65 searchCertPassword, searchBaseURL, endpoint, validationIndexName, violationIndexName).withSearchDb(searchDb);
\r
67 FileInputStream event = new FileInputStream( new File("src/test/resources/poa_audit_result.json"));
\r
68 eventJson = IOUtils.toString(event, "UTF-8");
\r
70 FileInputStream validation = new FileInputStream( new File("src/test/resources/poa_auditservice_validation.json"));
\r
71 validationJson = IOUtils.toString(validation, "UTF-8");
\r
73 FileInputStream violation = new FileInputStream( new File("src/test/resources/poa_auditservice_violation.json"));
\r
74 violationjson = IOUtils.toString(violation, "UTF-8");
\r
80 public void testProcess() throws Exception {
\r
82 policy.process(getExchangeEvent(validationJson));
\r
83 policy.process(getExchangeEvent(violationjson));
\r
85 assertNotNull(searchDb.get("service-validations"));
\r
86 assertNotNull(searchDb.get("service-violations"));
\r
92 private Exchange getExchangeEvent(String outputJson){
\r
94 Exchange exchange = PowerMockito.mock(Exchange.class);
\r
95 Message inMessage = PowerMockito.mock(Message.class);
\r
96 Message outMessage = PowerMockito.mock(Message.class);
\r
97 PowerMockito.when(exchange.getIn()).thenReturn(inMessage);
\r
98 PowerMockito.when(inMessage.getBody()).thenReturn(eventJson);
\r
100 PowerMockito.when(exchange.getOut()).thenReturn(outMessage);
\r
101 PowerMockito.when(outMessage.getBody()).thenReturn(outputJson);
\r
103 PowerMockito.doNothing().when(outMessage).setBody(anyObject());
\r
104 PowerMockito.doNothing().when(outMessage).setHeader(anyString(), anyObject());
\r