Merge "remove nexus function from entrypoint"
[policy/drools-applications.git] / controlloop / m2 / base / src / test / java / org / onap / policy / m2 / base / ActorOperationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * m2/base
4  * ================================================================================
5  * Copyright (C) 2020 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  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.m2.base;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
26
27 import org.junit.Test;
28 import org.onap.policy.controlloop.ControlLoopEvent;
29 import org.onap.policy.controlloop.ControlLoopException;
30 import org.onap.policy.controlloop.policy.Policy;
31 import org.onap.policy.controlloop.policy.PolicyResult;
32
33 public class ActorOperationTest {
34
35     public static final String ACTOR_NAME = "test";
36     public static final String STATE = "COMPLETE";
37
38     public static class TestOperation implements Operation {
39         private static final long serialVersionUID = 1L;
40
41         @Override
42         public Object getRequest() throws ControlLoopException {
43             return "request";
44         }
45
46         @Override
47         public Policy getPolicy() {
48             return null;
49         }
50
51         @Override
52         public String getState() {
53             return STATE;
54         }
55
56         @Override
57         public int getAttempt() {
58             return 0;
59         }
60
61         @Override
62         public PolicyResult getResult() {
63             return PolicyResult.SUCCESS;
64         }
65
66         @Override
67         public String getMessage() {
68             return "success";
69         }
70
71         @Override
72         public void incomingMessage(Object object) {
73             return;
74         }
75
76         @Override
77         public void timeout() {
78             return;
79         }
80
81     }
82
83     public static class TestActor implements Actor {
84
85         @Override
86         public String getName() {
87             return ACTOR_NAME;
88         }
89
90         @Override
91         public Operation createOperation(Transaction transaction, Policy policy, ControlLoopEvent onset, int attempt) {
92             return new TestOperation();
93         }
94
95     }
96
97     @Test
98     public void getNameTest() {
99         Actor actor = new TestActor();
100         assertEquals(ACTOR_NAME, actor.getName());
101     }
102
103     @Test
104     public void testOperation() throws ControlLoopException {
105         Actor actor = new TestActor();
106         Operation operation = actor.createOperation(null, null, null, 0);
107         assertNotNull(operation);
108         assertEquals("request", operation.getRequest());
109         assertNull(operation.getPolicy());
110         assertEquals(STATE, operation.getState());
111         assertEquals(0, operation.getAttempt());
112         assertEquals(PolicyResult.SUCCESS, operation.getResult());
113         assertEquals("success", operation.getMessage());
114     }
115
116 }