--- /dev/null
+/*
+ * ================================================================================
+ * Copyright (c) 2020 ChinaMobile. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ */
+
+package org.onap.dcae.analytics.tca.web;
+
+import org.onap.dcae.analytics.test.BaseAnalyticsUnitTest;
+
+/**
+ * @author Kai Lu
+ */
+public class BaseTcaWebTest extends BaseAnalyticsUnitTest {
+}
--- /dev/null
+/*
+ * ================================================================================
+ * Copyright (c) 2020 ChinaMobile. All rights reserved.
+ * ================================================================================
+ * Copyright Copyright (c) 2019 IBM
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ */
+package org.onap.dcae.analytics.tca.web;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.onap.dcae.analytics.model.AnalyticsProfile;
+import org.onap.dcae.analytics.test.BaseAnalyticsSpringBootIT;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.test.context.ActiveProfiles;
+
+@ActiveProfiles({AnalyticsProfile.DEV_PROFILE_NAME})
+public class TcaAppPropertiesTest extends BaseAnalyticsSpringBootIT{
+
+ @Autowired
+ Environment environment;
+
+ @Test
+ void TestTcaAppProperties() {
+ TcaAppProperties properties = new TcaAppProperties(environment);
+ Assertions.assertNotNull(properties.getTca());
+ Assertions.assertNotNull(properties.getStreamsPublishes());
+ Assertions.assertNotNull(properties.getStreamsSubscribes());
+ Assertions.assertNotNull(properties.getTca().getAai());
+ Assertions.assertEquals(true, properties.getTca().getEnableAbatement());
+ Assertions.assertEquals(false, properties.isConfigBindingServiceProfileActive());
+ }
+}
--- /dev/null
+/*
+ * ================================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ */
+
+package org.onap.dcae.analytics.tca.web.domain;
+
+import lombok.Data;
+
+import org.onap.dcae.analytics.tca.core.service.TcaAaiEnrichmentContext;
+import org.onap.dcae.analytics.tca.core.service.TcaAaiEnrichmentService;
+
+/**
+ * @author Rajiv Singla
+ */
+@Data
+public class TestTcaAaiEnrichmentContext implements TcaAaiEnrichmentContext {
+
+ private boolean isAaiEnrichmentEnabled = true;
+ private TcaAaiEnrichmentService aaiEnrichmentService = new TestTcaAaiEnrichmentService();
+
+}
--- /dev/null
+/*
+ * ================================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ */
+
+package org.onap.dcae.analytics.tca.web.domain;
+
+import lombok.Data;
+
+import org.onap.dcae.analytics.tca.core.service.TcaAaiEnrichmentService;
+import org.onap.dcae.analytics.tca.core.service.TcaExecutionContext;
+import org.onap.dcae.analytics.tca.model.facade.TcaAlert;
+
+/**
+ * @author Rajiv Singla
+ */
+@Data
+public class TestTcaAaiEnrichmentService implements TcaAaiEnrichmentService {
+
+ private TcaAlert enrichedTcaAlert;
+
+ @Override
+ public TcaAlert doAaiEnrichment(final TcaExecutionContext tcaExecutionContext) {
+ final TcaAlert tcaAlert = tcaExecutionContext.getTcaResultContext().getTcaAlert();
+ return enrichedTcaAlert == null ? tcaAlert : enrichedTcaAlert;
+ }
+}
--- /dev/null
+/*
+ * ================================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ */
+
+package org.onap.dcae.analytics.tca.web.domain;
+
+import lombok.Data;
+
+import java.util.Date;
+
+import org.onap.dcae.analytics.tca.core.service.TcaAbatementContext;
+import org.onap.dcae.analytics.tca.core.service.TcaAbatementEntity;
+import org.onap.dcae.analytics.tca.core.service.TcaAbatementRepository;
+
+/**
+ * @author Rajiv Singla
+ */
+@Data
+public class TestTcaAbatementContext implements TcaAbatementContext {
+
+ private boolean isAbatementEnabled = true;
+ private TcaAbatementRepository tcaAbatementRepository = new TestTcaAbatementRepository();
+
+
+ @Override
+ public TcaAbatementEntity create(
+ final String lookupKey, final String requestId, final boolean isAbatementAlertSent) {
+ return new TestTcaAbatementEntity(new Date(), lookupKey, requestId, isAbatementAlertSent);
+ }
+
+}
--- /dev/null
+/*
+ * ================================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ */
+
+package org.onap.dcae.analytics.tca.web.domain;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+import java.util.Date;
+
+import org.onap.dcae.analytics.tca.core.service.TcaAbatementEntity;
+
+/**
+ * @author Rajiv Singla
+ */
+@Data
+@AllArgsConstructor
+public class TestTcaAbatementEntity implements TcaAbatementEntity {
+
+ private Date lastModificationDate;
+ private String lookupKey;
+ private String requestId;
+ private boolean isAbatementAlertSent;
+
+}
--- /dev/null
+/*
+ * ================================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ */
+
+package org.onap.dcae.analytics.tca.web.domain;
+
+import lombok.Data;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.onap.dcae.analytics.tca.core.service.TcaAbatementEntity;
+import org.onap.dcae.analytics.tca.core.service.TcaAbatementRepository;
+
+/**
+ * @author Rajiv Singla
+ */
+@Data
+public class TestTcaAbatementRepository implements TcaAbatementRepository {
+
+ private List<TcaAbatementEntity> testLookupAbatementEntities = new LinkedList<>();
+
+ @Override
+ public void save(final TcaAbatementEntity tcaAbatementEntity) {
+ // do nothing
+ }
+
+ @Override
+ public List<TcaAbatementEntity> findByLookupKey(final String lookUpKey) {
+ return testLookupAbatementEntities;
+ }
+
+}
--- /dev/null
+/*
+ * ================================================================================
+ * Copyright (c) 2020 ChinaMobile. All rights reserved.
+ * ================================================================================
+ * Copyright Copyright (c) 2019 IBM
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ */
+package org.onap.dcae.analytics.tca.web.integration;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.onap.dcae.analytics.model.AnalyticsHttpConstants;
+import org.onap.dcae.analytics.tca.core.service.GenericTcaExecutionContext;
+import org.onap.dcae.analytics.tca.core.service.GenericTcaExecutionContext.GenericTcaExecutionContextBuilder;
+import org.onap.dcae.analytics.tca.core.service.GenericTcaProcessingContext;
+import org.onap.dcae.analytics.tca.core.service.GenericTcaResultContext;
+import org.onap.dcae.analytics.tca.core.service.TcaAbatementContext;
+import org.onap.dcae.analytics.tca.core.service.TcaExecutionContext;
+import org.onap.dcae.analytics.tca.core.service.TcaProcessingContext;
+import org.onap.dcae.analytics.tca.core.service.TcaResultContext;
+import org.onap.dcae.analytics.tca.model.policy.TcaPolicy;
+import org.onap.dcae.analytics.tca.model.util.json.TcaModelJsonConversion;
+import org.onap.dcae.analytics.tca.web.BaseTcaWebTest;
+import org.onap.dcae.analytics.tca.web.TcaAppProperties;
+import org.onap.dcae.analytics.tca.web.domain.TestTcaAaiEnrichmentContext;
+import org.onap.dcae.analytics.tca.web.domain.TestTcaAbatementContext;
+import org.onap.dcae.analytics.test.BaseAnalyticsSpringBootIT;
+import org.onap.dcae.analytics.web.util.AnalyticsHttpUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.messaging.Message;
+import org.springframework.messaging.MessageHeaders;
+
+public class TcaAlertTransformerTest extends BaseAnalyticsSpringBootIT {
+
+ @Autowired
+ Environment environment;
+
+ protected static final String TEST_POLICY_JSON_STRING;
+ protected static final String TEST_REQUEST_ID = "testRequestId";
+ protected static final TcaPolicy TEST_TCA_POLICY;
+
+ static {
+
+ TEST_POLICY_JSON_STRING = fromStream(TestFileLocation.TCA_POLICY_JSON);
+ TEST_TCA_POLICY = TcaModelJsonConversion.TCA_POLICY_JSON_FUNCTION.apply(TEST_POLICY_JSON_STRING)
+ .orElseThrow(() -> new IllegalStateException("Unable to get Test TcaPolicy"));
+ }
+
+ @Test
+ void TestTcaAppPropertiesValidator() throws Exception {
+ TcaAppProperties properties = new TcaAppProperties(environment);
+
+ final Message message = Mockito.mock(Message.class);
+ MessageHeaders header = Mockito.mock(MessageHeaders.class);
+
+
+ final TcaExecutionContext testExecutionContext =
+ getTestExecutionContext(BaseTcaWebTest.fromStream("data/json/cef/cef_message.json"));
+
+ List<TcaExecutionContext> messagePayload = new ArrayList<TcaExecutionContext>();
+ messagePayload.add(testExecutionContext);
+
+ Mockito.when(message.getPayload()).thenReturn(messagePayload);
+ Mockito.when(message.getHeaders()).thenReturn(header);
+ Mockito.when(AnalyticsHttpUtils.getRequestId(header)).thenReturn("resuestId-1");
+ Mockito.when(AnalyticsHttpUtils.getTransactionId(header)).thenReturn("transactionId-1");
+ Mockito.when(header.get(AnalyticsHttpConstants.REQUEST_BEGIN_TS_HEADER_KEY)).thenReturn(null);
+
+ TcaAlertTransformer tcaAlertTransformer = new TcaAlertTransformer(properties);
+ tcaAlertTransformer.doTransform(message);
+
+ }
+
+ protected TcaExecutionContext getTestExecutionContext(final String cefMessage) {
+ final TestTcaAbatementContext testTcaAbatementContext = new TestTcaAbatementContext();
+ return getTestExecutionContextBuilder(cefMessage, TEST_TCA_POLICY, testTcaAbatementContext).build();
+ }
+
+ protected GenericTcaExecutionContextBuilder getTestExecutionContextBuilder(
+ final String cefMessage, final TcaPolicy tcaPolicy, final TcaAbatementContext tcaAbatementContext) {
+
+ final TcaProcessingContext tcaProcessingContext = new GenericTcaProcessingContext();
+ final TcaResultContext tcaResultContext = new GenericTcaResultContext();
+ final TestTcaAaiEnrichmentContext testTcaAaiEnrichmentContext = new TestTcaAaiEnrichmentContext();
+
+ return GenericTcaExecutionContext.builder()
+ .requestId(TEST_REQUEST_ID)
+ .cefMessage(cefMessage)
+ .tcaPolicy(tcaPolicy)
+ .tcaProcessingContext(tcaProcessingContext)
+ .tcaResultContext(tcaResultContext)
+ .tcaAbatementContext(tcaAbatementContext)
+ .tcaAaiEnrichmentContext(testTcaAaiEnrichmentContext);
+ }
+
+}
--- /dev/null
+/*
+ * ================================================================================
+ * Copyright (c) 2020 ChinaMobile. All rights reserved.
+ * ================================================================================
+ * Copyright Copyright (c) 2019 IBM
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ */
+package org.onap.dcae.analytics.tca.web.validation;
+
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.onap.dcae.analytics.model.AnalyticsProfile;
+import org.onap.dcae.analytics.tca.web.TcaAppProperties;
+import org.onap.dcae.analytics.test.BaseAnalyticsSpringBootIT;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.validation.Errors;
+
+@ActiveProfiles({AnalyticsProfile.DEV_PROFILE_NAME})
+public class TcaAppPropertiesValidatorTest extends BaseAnalyticsSpringBootIT {
+
+ @Autowired
+ Environment environment;
+
+ @Test
+ void TestTcaAppPropertiesValidator() {
+ TcaAppProperties properties = new TcaAppProperties(environment);
+ TcaAppPropertiesValidator validate = new TcaAppPropertiesValidator();
+ Errors errors = Mockito.mock(Errors.class);
+ validate.validate(properties, errors);
+ }
+
+}
--- /dev/null
+/*
+ * ================================================================================
+ * Copyright (c) 2020 ChinaMobile. All rights reserved.
+ * ================================================================================
+ * Copyright Copyright (c) 2019 IBM
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ */
+package org.onap.dcae.analytics.tca.web.validation;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.onap.dcae.analytics.model.AnalyticsProfile;
+import org.onap.dcae.analytics.tca.model.policy.TcaPolicy;
+import org.onap.dcae.analytics.tca.web.TcaAppProperties;
+import org.onap.dcae.analytics.tca.web.domain.TcaPolicyWrapper;
+import org.onap.dcae.analytics.test.BaseAnalyticsSpringBootIT;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.validation.Errors;
+
+@ActiveProfiles({AnalyticsProfile.DEV_PROFILE_NAME})
+public class TcaPolicyValidateTest extends BaseAnalyticsSpringBootIT {
+
+ @Autowired
+ Environment environment;
+
+ @Test
+ void TestTcaAppPropertiesValidator() {
+ TcaAppProperties properties = new TcaAppProperties(environment);
+ TcaPolicyValidator validate = new TcaPolicyValidator();
+ Errors errors = Mockito.mock(Errors.class);
+ TcaPolicyWrapper tcaPolicyWrapper = new TcaPolicyWrapper(properties);
+ tcaPolicyWrapper.getConfigSource();
+ TcaPolicy tcaPolicy = tcaPolicyWrapper.getTcaPolicy();
+ validate.validate(tcaPolicy, errors);
+ validate.apply(tcaPolicy);
+ Assertions.assertEquals("version-0", tcaPolicyWrapper.getPolicyVersion());
+ }
+}
--- /dev/null
+/*
+ * ================================================================================
+ * Copyright (c) 2020 ChinaMobile. All rights reserved.
+ * ================================================================================
+ * Copyright Copyright (c) 2019 IBM
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ */
+package org.onap.dcae.analytics.web.dmaap;
+
+import java.net.URL;
+import java.util.Arrays;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.springframework.http.HttpHeaders;
+
+public class MrTriggerMessageProviderTest {
+
+ @Test
+ void getMrTriggerMessageProviderTest() throws Exception {
+ URL proxyURL = new URL("http://localhost");
+ MrSubscriberPollingPreferences pollingPreferences = Mockito.mock(MrSubscriberPollingPreferences.class);
+ HttpHeaders headers = Mockito.mock(HttpHeaders.class);
+ MrSubscriberPreferences subscriberPreferences =
+ new MrSubscriberPreferences("http://localhost:8080",
+ "TestClientId", headers,
+ "TestUserName", "TestPassword",
+ proxyURL, true, false, "TestGroup",
+ Arrays.asList("TestId1", "TestId2"),
+ new Integer(4), new Integer(3), pollingPreferences);
+ Assertions.assertNotNull(new MrTriggerMessageProvider(subscriberPreferences).getTriggerMessage());
+ }
+}