2 * ================================================================================
3 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ============LICENSE_END=========================================================
20 package org.onap.dcae.analytics.tca.core;
22 import org.onap.dcae.analytics.model.cef.EventListener;
23 import org.onap.dcae.analytics.model.util.json.AnalyticsModelJsonConversion;
24 import org.onap.dcae.analytics.tca.core.domain.TestTcaAaiEnrichmentContext;
25 import org.onap.dcae.analytics.tca.core.domain.TestTcaAbatementContext;
26 import org.onap.dcae.analytics.tca.core.service.GenericTcaExecutionContext;
27 import org.onap.dcae.analytics.tca.core.service.GenericTcaExecutionContext.GenericTcaExecutionContextBuilder;
28 import org.onap.dcae.analytics.tca.core.service.GenericTcaProcessingContext;
29 import org.onap.dcae.analytics.tca.core.service.GenericTcaResultContext;
30 import org.onap.dcae.analytics.tca.core.service.TcaAbatementContext;
31 import org.onap.dcae.analytics.tca.core.service.TcaExecutionContext;
32 import org.onap.dcae.analytics.tca.core.service.TcaProcessingContext;
33 import org.onap.dcae.analytics.tca.core.service.TcaResultContext;
34 import org.onap.dcae.analytics.tca.model.policy.TcaPolicy;
35 import org.onap.dcae.analytics.tca.model.util.json.TcaModelJsonConversion;
36 import org.onap.dcae.analytics.test.BaseAnalyticsUnitTest;
39 * @author Rajiv Singla
41 public abstract class BaseTcaCoreTest extends BaseAnalyticsUnitTest {
44 protected static final String TEST_POLICY_JSON_STRING;
45 protected static final String TEST_CEF_EVENT_LISTENER_STRING;
46 protected static final String TEST_CEF_JSON_MESSAGE_WITH_VIOLATION_STRING;
47 protected static final String TEST_CEF_JSON_MESSAGE_WITH_ABATEMENT_STRING;
48 protected static final String TEST_CEF_JSON_MESSAGE_WITH_INAPPLICABLE_EVENT_NAME;
49 protected static final String TEST_REQUEST_ID = "testRequestId";
50 protected static final TcaPolicy TEST_TCA_POLICY;
54 TEST_POLICY_JSON_STRING = fromStream(TestFileLocation.TCA_POLICY_JSON);
55 TEST_CEF_EVENT_LISTENER_STRING = fromStream(TestFileLocation.CEF_JSON_MESSAGE);
56 TEST_CEF_JSON_MESSAGE_WITH_VIOLATION_STRING = fromStream(TestFileLocation.CEF_JSON_MESSAGE_WITH_VIOLATION);
57 TEST_CEF_JSON_MESSAGE_WITH_ABATEMENT_STRING = fromStream(TestFileLocation.CEF_JSON_MESSAGE_WITH_ABATEMENT);
58 TEST_CEF_JSON_MESSAGE_WITH_INAPPLICABLE_EVENT_NAME = fromStream(TestFileLocation
59 .CEF_JSON_MESSAGE_WITH_INAPPLICABLE_EVENT_NAME);
60 TEST_TCA_POLICY = TcaModelJsonConversion.TCA_POLICY_JSON_FUNCTION.apply(TEST_POLICY_JSON_STRING)
61 .orElseThrow(() -> new IllegalStateException("Unable to get Test TcaPolicy"));
65 * Provides Event Listener that can be used for testing purposes
67 * @return test Event Listener
69 protected EventListener getTestEventListener() {
70 return AnalyticsModelJsonConversion.EVENT_LISTENER_JSON_FUNCTION
71 .apply(TEST_CEF_EVENT_LISTENER_STRING)
72 .orElseThrow(() -> new IllegalStateException("Unable to get Test CEF Event Listener"));
76 * Provides Event Listener with violation that can be used for testing purposes
78 * @return test Event Listener with violation
80 protected EventListener getTestEventListenerWithViolation() {
81 return AnalyticsModelJsonConversion.EVENT_LISTENER_JSON_FUNCTION
82 .apply(TEST_CEF_JSON_MESSAGE_WITH_VIOLATION_STRING)
83 .orElseThrow(() -> new IllegalStateException("Unable to get Test CEF Event Listeners with violation"));
88 * Provides Event Listener with abatement that can be used for testing purposes
90 * @return test Event Listener with abatement
92 protected EventListener getTestEventListenerWithAbatement() {
93 return AnalyticsModelJsonConversion.EVENT_LISTENER_JSON_FUNCTION
94 .apply(TEST_CEF_JSON_MESSAGE_WITH_ABATEMENT_STRING)
95 .orElseThrow(() -> new IllegalStateException("Unable to get Test CEF Event Listeners with abatement"));
99 protected TcaExecutionContext getTestExecutionContext(final String cefMessage) {
100 final TestTcaAbatementContext testTcaAbatementContext = new TestTcaAbatementContext();
101 return getTestExecutionContextBuilder(cefMessage, TEST_TCA_POLICY, testTcaAbatementContext).build();
104 protected GenericTcaExecutionContextBuilder getTestExecutionContextBuilder(
105 final String cefMessage, final TcaPolicy tcaPolicy, final TcaAbatementContext tcaAbatementContext) {
107 final TcaProcessingContext tcaProcessingContext = new GenericTcaProcessingContext();
108 final TcaResultContext tcaResultContext = new GenericTcaResultContext();
109 final TestTcaAaiEnrichmentContext testTcaAaiEnrichmentContext = new TestTcaAaiEnrichmentContext();
111 return GenericTcaExecutionContext.builder()
112 .requestId(TEST_REQUEST_ID)
113 .cefMessage(cefMessage)
114 .tcaPolicy(tcaPolicy)
115 .tcaProcessingContext(tcaProcessingContext)
116 .tcaResultContext(tcaResultContext)
117 .tcaAbatementContext(tcaAbatementContext)
118 .tcaAaiEnrichmentContext(testTcaAaiEnrichmentContext);