2 * ==========LICENSE_START=========================================================
3 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4 * Copyright (c) 2022 Wipro Limited Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
21 package org.onap.dcae.analytics.tca.core;
23 import java.util.List;
25 import org.onap.dcae.analytics.model.cef.EventListener;
26 import org.onap.dcae.analytics.model.util.json.AnalyticsModelJsonConversion;
27 import org.onap.dcae.analytics.tca.core.domain.TestTcaAaiEnrichmentContext;
28 import org.onap.dcae.analytics.tca.core.domain.TestTcaAbatementContext;
29 import org.onap.dcae.analytics.tca.core.service.GenericTcaExecutionContext;
30 import org.onap.dcae.analytics.tca.core.service.GenericTcaExecutionContext.GenericTcaExecutionContextBuilder;
31 import org.onap.dcae.analytics.tca.core.service.GenericTcaProcessingContext;
32 import org.onap.dcae.analytics.tca.core.service.GenericTcaResultContext;
33 import org.onap.dcae.analytics.tca.core.service.TcaAbatementContext;
34 import org.onap.dcae.analytics.tca.core.service.TcaExecutionContext;
35 import org.onap.dcae.analytics.tca.core.service.TcaProcessingContext;
36 import org.onap.dcae.analytics.tca.core.service.TcaResultContext;
37 import org.onap.dcae.analytics.tca.model.policy.TcaPolicy;
38 import org.onap.dcae.analytics.tca.model.util.json.TcaModelJsonConversion;
39 import org.onap.dcae.analytics.test.BaseAnalyticsUnitTest;
42 * @author Rajiv Singla
44 public abstract class BaseTcaCoreTest extends BaseAnalyticsUnitTest {
47 protected static final String TEST_POLICY_JSON_STRING;
48 protected static final String TEST_CEF_EVENT_LISTENER_STRING;
49 protected static final String TEST_CEF_JSON_MESSAGE_WITH_VIOLATION_STRING;
50 protected static final String TEST_CEF_JSON_MESSAGE_WITH_ABATEMENT_STRING;
51 protected static final String TEST_CEF_JSON_MESSAGE_WITH_INAPPLICABLE_EVENT_NAME;
52 protected static final String TEST_REQUEST_ID = "testRequestId";
53 protected static final List<TcaPolicy> TEST_TCA_POLICY;
57 TEST_POLICY_JSON_STRING = fromStream(TestFileLocation.TCA_POLICY_JSON);
58 TEST_CEF_EVENT_LISTENER_STRING = fromStream(TestFileLocation.CEF_JSON_MESSAGE);
59 TEST_CEF_JSON_MESSAGE_WITH_VIOLATION_STRING = fromStream(TestFileLocation.CEF_JSON_MESSAGE_WITH_VIOLATION);
60 TEST_CEF_JSON_MESSAGE_WITH_ABATEMENT_STRING = fromStream(TestFileLocation.CEF_JSON_MESSAGE_WITH_ABATEMENT);
61 TEST_CEF_JSON_MESSAGE_WITH_INAPPLICABLE_EVENT_NAME = fromStream(TestFileLocation
62 .CEF_JSON_MESSAGE_WITH_INAPPLICABLE_EVENT_NAME);
63 TEST_TCA_POLICY = TcaModelJsonConversion.TCA_POLICY_JSON_FUNCTION.apply(TEST_POLICY_JSON_STRING)
64 .orElseThrow(() -> new IllegalStateException("Unable to get Test TcaPolicy"));
68 * Provides Event Listener that can be used for testing purposes
70 * @return test Event Listener
72 protected EventListener getTestEventListener() {
73 return AnalyticsModelJsonConversion.EVENT_LISTENER_JSON_FUNCTION
74 .apply(TEST_CEF_EVENT_LISTENER_STRING)
75 .orElseThrow(() -> new IllegalStateException("Unable to get Test CEF Event Listener"));
79 * Provides Event Listener with violation that can be used for testing purposes
81 * @return test Event Listener with violation
83 protected EventListener getTestEventListenerWithViolation() {
84 return AnalyticsModelJsonConversion.EVENT_LISTENER_JSON_FUNCTION
85 .apply(TEST_CEF_JSON_MESSAGE_WITH_VIOLATION_STRING)
86 .orElseThrow(() -> new IllegalStateException("Unable to get Test CEF Event Listeners with violation"));
91 * Provides Event Listener with abatement that can be used for testing purposes
93 * @return test Event Listener with abatement
95 protected EventListener getTestEventListenerWithAbatement() {
96 return AnalyticsModelJsonConversion.EVENT_LISTENER_JSON_FUNCTION
97 .apply(TEST_CEF_JSON_MESSAGE_WITH_ABATEMENT_STRING)
98 .orElseThrow(() -> new IllegalStateException("Unable to get Test CEF Event Listeners with abatement"));
102 protected TcaExecutionContext getTestExecutionContext(final String cefMessage) {
103 final TestTcaAbatementContext testTcaAbatementContext = new TestTcaAbatementContext();
104 return getTestExecutionContextBuilder(cefMessage, TEST_TCA_POLICY, testTcaAbatementContext).build();
107 protected GenericTcaExecutionContextBuilder getTestExecutionContextBuilder(
108 final String cefMessage, final List<TcaPolicy> tcaPolicy, final TcaAbatementContext tcaAbatementContext) {
110 final TcaProcessingContext tcaProcessingContext = new GenericTcaProcessingContext();
111 final TcaResultContext tcaResultContext = new GenericTcaResultContext();
112 final TestTcaAaiEnrichmentContext testTcaAaiEnrichmentContext = new TestTcaAaiEnrichmentContext();
114 return GenericTcaExecutionContext.builder()
115 .requestId(TEST_REQUEST_ID)
116 .cefMessage(cefMessage)
117 .tcaPolicy(tcaPolicy)
118 .tcaProcessingContext(tcaProcessingContext)
119 .tcaResultContext(tcaResultContext)
120 .tcaAbatementContext(tcaAbatementContext)
121 .tcaAaiEnrichmentContext(testTcaAaiEnrichmentContext);