01c24d6de99b0be9bc6caca6ea55b1c0eb83942d
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2020 Nordix Foundation.
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.apex.examples.myfirstpolicy;
24
25 import static org.awaitility.Awaitility.await;
26
27 import java.util.ArrayList;
28 import java.util.List;
29 import java.util.concurrent.TimeUnit;
30 import lombok.AllArgsConstructor;
31 import lombok.Getter;
32 import org.onap.policy.apex.core.engine.engine.EnEventListener;
33 import org.onap.policy.apex.core.engine.event.EnEvent;
34
35 /**
36  * The listener interface for receiving SaleAuth events. The class that is interested in processing a SaleAuth event
37  * implements this interface, and the object created with that class is registered with a component using the
38  * component's <code>addTestApexActionListener</code> method. When the testApexAction event occurs, that object's
39  * appropriate method is invoked.
40  *
41  * @author Liam Fallon (liam.fallon@ericsson.com)
42  */
43 @AllArgsConstructor
44 public class TestSaleAuthListener implements EnEventListener {
45     // CHECKSTYLE:OFF: MagicNumber
46
47     private final List<EnEvent> resultEvents = new ArrayList<>();
48
49     @Getter
50     private final String id;
51
52     /**
53      * Gets the result.
54      *
55      * @return the result
56      */
57     public EnEvent getResult() {
58         await().atMost(200, TimeUnit.MILLISECONDS).until(() -> !resultEvents.isEmpty());
59         return resultEvents.remove(0);
60     }
61
62     /**
63      * {@inheritDoc}.
64      */
65     @Override
66     public void onEnEvent(final EnEvent saleauthEvent) {
67         if (saleauthEvent != null) {
68             System.out.println("SaleAuth event from engine:" + saleauthEvent.getName());
69             resultEvents.add(saleauthEvent);
70         }
71     }
72 }