Changes for checkstyle 8.32
[policy/apex-pdp.git] / core / core-engine / src / test / java / org / onap / policy / apex / core / engine / engine / impl / DummySmExecutor.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2019 Nordix Foundation.
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.core.engine.engine.impl;
23
24 import java.util.Properties;
25 import org.onap.policy.apex.core.engine.event.EnEvent;
26 import org.onap.policy.apex.core.engine.executor.ExecutorFactory;
27 import org.onap.policy.apex.core.engine.executor.StateMachineExecutor;
28 import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
29 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
30
31 /**
32  * Dummy state machine executor for testing.
33  */
34 public class DummySmExecutor extends StateMachineExecutor {
35     private boolean cleanupWorks = false;
36     private boolean prepareWorks;
37
38     /**
39      * Constructor.
40      *
41      * @param executorFactory the factory for executors
42      * @param owner the owner key
43      */
44     public DummySmExecutor(ExecutorFactory executorFactory, AxArtifactKey owner) {
45         super(executorFactory, owner);
46     }
47
48     /**
49      * {@inheritDoc}.
50      */
51     @Override
52     public void prepare() throws StateMachineException {
53         if (prepareWorks) {
54             prepareWorks = false;
55         } else {
56             prepareWorks = true;
57             throw new StateMachineException("dummy state machine executor exception");
58         }
59     }
60
61     /**
62      * {@inheritDoc}.
63      */
64     @Override
65     public EnEvent execute(final long executionId, final Properties executionProperties, final EnEvent incomingEvent) {
66         return incomingEvent;
67     }
68
69     /**
70      * {@inheritDoc}.
71      */
72     @Override
73     public void cleanUp() throws StateMachineException {
74         if (cleanupWorks) {
75             cleanupWorks = false;
76         } else {
77             cleanupWorks = true;
78             throw new StateMachineException("dummy state machine executor exception");
79         }
80     }
81 }