2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
5 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.apex.testsuites.integration.uservice.executionproperties;
26 import java.io.FileInputStream;
27 import java.io.IOException;
28 import java.util.EnumMap;
30 import java.util.Properties;
32 import org.onap.policy.apex.service.engine.event.ApexEventConsumer;
33 import org.onap.policy.apex.service.engine.event.ApexEventException;
34 import org.onap.policy.apex.service.engine.event.ApexEventReceiver;
35 import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
36 import org.onap.policy.apex.service.engine.event.PeeredReference;
37 import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
38 import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
43 * Dummy Apex event consumer for testing event properties.
45 * @author Liam Fallon (liam.fallon@est.tech)
47 public class DummyApexEventConsumer implements ApexEventConsumer {
48 // Get a reference to the logger
49 private static final Logger LOGGER = LoggerFactory.getLogger(DummyApexEventConsumer.class);
51 // The event receiver that will receive events from this consumer
52 private ApexEventReceiver eventReceiver;
54 // The name for this consumer
56 private String name = null;
58 // The peer references for this event handler
59 private Map<EventHandlerPeeredMode, PeeredReference> peerReferenceMap = new EnumMap<>(EventHandlerPeeredMode.class);
61 private DummyCarrierTechnologyParameters dummyConsumerProperties = null;
64 public void init(final String consumerName, final EventHandlerParameters consumerParameters,
65 final ApexEventReceiver incomingEventReceiver) throws ApexEventException {
66 this.eventReceiver = incomingEventReceiver;
67 this.name = consumerName;
69 // Check and get the properties
70 if (!(consumerParameters.getCarrierTechnologyParameters() instanceof DummyCarrierTechnologyParameters)) {
71 String message = "specified consumer properties of type \""
72 + consumerParameters.getCarrierTechnologyParameters().getClass().getName()
73 + "\" are not applicable to a dummy consumer";
75 throw new ApexEventException(message);
78 dummyConsumerProperties = (DummyCarrierTechnologyParameters) consumerParameters
79 .getCarrierTechnologyParameters();
84 new Thread(new RunTestEventSender()).start();
91 public PeeredReference getPeeredReference(final EventHandlerPeeredMode peeredMode) {
92 return peerReferenceMap.get(peeredMode);
99 public void setPeeredReference(final EventHandlerPeeredMode peeredMode, final PeeredReference peeredReference) {
100 peerReferenceMap.put(peeredMode, peeredReference);
107 private class RunTestEventSender implements Runnable {
110 Properties executionProperties = new Properties();
112 executionProperties.load(new FileInputStream(new File(dummyConsumerProperties.getPropertyFileName())));
113 } catch (IOException e1) {
114 String message = "reading of executor properties for testing failed from file: "
115 + dummyConsumerProperties.getPropertyFileName();
116 LOGGER.warn(message);
117 throw new ApexEventRuntimeException(message);
120 RunTestEvent event = new RunTestEvent();
121 event.setTestToRun(dummyConsumerProperties.getTestToRun());
123 eventReceiver.receiveEvent(1, executionProperties, event.toJson());
124 } catch (Exception e) {
125 String message = "event processing for executor properties testing failed: " + e.getMessage();
126 LOGGER.warn(message, e);
127 throw new ApexEventRuntimeException(message, e);