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.util.function.calculation;
22 import static org.assertj.core.api.Assertions.assertThat;
24 import java.util.Collections;
25 import java.util.Date;
27 import org.junit.jupiter.api.DisplayName;
28 import org.junit.jupiter.api.Test;
29 import org.onap.dcae.analytics.tca.core.BaseTcaCoreTest;
30 import org.onap.dcae.analytics.tca.core.domain.TestTcaAbatementContext;
31 import org.onap.dcae.analytics.tca.core.domain.TestTcaAbatementEntity;
32 import org.onap.dcae.analytics.tca.core.domain.TestTcaAbatementRepository;
33 import org.onap.dcae.analytics.tca.core.service.TcaExecutionContext;
37 * @author Rajiv Singla
39 class TcaCalculatorTest extends BaseTcaCoreTest {
42 @DisplayName("Test TCA calculator with CEF Message without violation")
43 void testCEFMessageWithoutViolation() {
44 final TcaExecutionContext testExecutionContext =
45 getTestExecutionContext(TEST_CEF_EVENT_LISTENER_STRING);
46 final TcaExecutionContext result = new TcaCalculator().apply(testExecutionContext);
47 assertThat(result.getTcaProcessingContext().isContinueProcessing()).isFalse();
48 assertThat(result.getTcaProcessingContext().getErrorMessage()).isNull();
49 final String earlyTerminationMessage = result.getTcaProcessingContext().getEarlyTerminationMessage();
50 assertThat(earlyTerminationMessage).isNotNull();
51 logger.debug(earlyTerminationMessage);
52 assertThat(result.getTcaResultContext().isThresholdViolationsPresent()).isFalse();
56 @DisplayName("Test TCA calculator with CEF Message with violation")
57 void testCEFMessageWithViolation() {
58 final TcaExecutionContext testExecutionContext =
59 getTestExecutionContext(TEST_CEF_JSON_MESSAGE_WITH_VIOLATION_STRING);
60 final TcaExecutionContext result = new TcaCalculator().apply(testExecutionContext);
61 assertThat(result.getTcaProcessingContext().isContinueProcessing()).isTrue();
62 assertThat(result.getTcaResultContext().isThresholdViolationsPresent()).isTrue();
63 assertThat(result.getTcaResultContext().getTcaAlert().getRequestId()).isEqualTo(TEST_REQUEST_ID);
68 @DisplayName("Test TCA calculator with Abatement")
69 void testCEFMessageWithAbatement() {
70 final TestTcaAbatementContext testTcaAbatementContext = new TestTcaAbatementContext();
71 final TestTcaAbatementRepository testAbatementPersistenceContext =
72 (TestTcaAbatementRepository) testTcaAbatementContext.getTcaAbatementRepository();
73 final String previousRequestId = "previousRequestId";
74 final TestTcaAbatementEntity testTcaAbatementPersistenceEntity
75 = new TestTcaAbatementEntity(new Date(), "", previousRequestId, false);
76 testAbatementPersistenceContext.setTestLookupAbatementEntities(
77 Collections.singletonList(testTcaAbatementPersistenceEntity));
79 final TcaExecutionContext testExecutionContext =
80 getTestExecutionContextBuilder(TEST_CEF_JSON_MESSAGE_WITH_ABATEMENT_STRING,
81 TEST_TCA_POLICY, testTcaAbatementContext).build();
83 final TcaExecutionContext result = new TcaCalculator().apply(testExecutionContext);
84 assertThat(result.getTcaResultContext().getTcaAlert().getRequestId()).isEqualTo(previousRequestId);