33f88bf2dc2587f374702d38ea7e3282f81dad03
[policy/apex-pdp.git] / testsuites / integration / integration-common / src / main / java / org / onap / policy / apex / testsuites / integration / common / model / java / DefaultTaskLogic.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2020 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.testsuites.integration.common.model.java;
23
24 import java.util.Random;
25
26 import org.onap.policy.apex.core.engine.executor.context.TaskExecutionContext;
27
28 /**
29  * The Class DefaultTask_Logic is default task logic in Java.
30  */
31 public class DefaultTaskLogic {
32     private static final int BOUND_FOR_RANDOM_INT = 4;
33     private static final Random rand = new Random();
34
35     /**
36      * Gets the event.
37      *
38      * @param executor the executor
39      * @return the event
40      */
41     public boolean getEvent(final TaskExecutionContext executor) {
42         String idString = executor.subject.getId();
43         executor.logger.debug(idString);
44
45         String albumNameString = executor.getContextAlbum("GlobalContextAlbum").getName();
46         executor.logger.debug(albumNameString);
47
48         String inFieldsString = executor.inFields.toString();
49         executor.logger.debug(inFieldsString);
50         if (executor.inFields.containsKey("TestDecideCaseSelected")) {
51             executor.outFields.put("TestActCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
52             executor.outFields.put("TestActStateTime", System.nanoTime());
53         } else if (executor.inFields.containsKey("TestEstablishCaseSelected")) {
54             executor.outFields.put("TestDecideCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
55             executor.outFields.put("TestDecideStateTime", System.nanoTime());
56         } else if (executor.inFields.containsKey("TestMatchCaseSelected")) {
57             executor.outFields.put("TestEstablishCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
58             executor.outFields.put("TestEstablishStateTime", System.nanoTime());
59         } else {
60             executor.outFields.put("TestMatchCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
61             executor.outFields.put("TestMatchStateTime", System.nanoTime());
62         }
63         return true;
64     }
65 }