migrate model-impl from drools-applications
[policy/models.git] / models-interactions / model-impl / events / src / test / java / org / onap / policy / controlloop / ControlLoopOperationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * controlloop
4  * ================================================================================
5  * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019 Nordix Foundation.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.controlloop;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotEquals;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertTrue;
28
29 import java.time.Instant;
30 import org.junit.Test;
31
32 public class ControlLoopOperationTest {
33
34     @Test
35     public void test() {
36         ControlLoopOperation operation = new ControlLoopOperation();
37
38         assertEquals(operation, operation);
39         assertNotEquals(operation, new String());
40         assertNotEquals(operation, null);
41
42         assertTrue(operation.hashCode() != 0);
43         assertTrue(operation.toString().startsWith("ControlLoopOperation"));
44
45         assertNotNull(operation);
46
47         operation.setActor("actor");
48         assertEquals("actor", operation.getActor());
49
50         operation.setOperation("operation");
51         assertEquals("operation", operation.getOperation());
52
53         Instant now = Instant.now();
54         operation.setStart(now);
55         assertEquals(now, operation.getStart());
56         operation.setEnd(now);
57         assertEquals(now, operation.getEnd());
58
59         operation.setMessage("message");
60         assertEquals("message", operation.getMessage());
61
62         operation.setOutcome("outcome");
63         assertEquals("outcome", operation.getOutcome());
64
65         operation.setSubRequestId("1");
66         assertEquals("1", operation.getSubRequestId());
67
68         operation.setTarget("target");
69         assertEquals("target", operation.getTarget());
70
71         assertTrue(operation.hashCode() != 0);
72
73         ControlLoopOperation operation2 = new ControlLoopOperation(operation);
74         assertEquals(now, operation2.getEnd());
75
76         assertEquals(operation, operation2);
77
78         operation2.setActor("foo");
79         assertNotEquals(operation, operation2);
80
81         operation = new ControlLoopOperation(null);
82         assertNotNull(operation.getStart());
83
84         assertNotEquals(operation, operation2);
85
86         assertTrue(operation.toMessage().startsWith("actor="));
87         assertTrue(operation.toHistory().startsWith("actor="));
88
89     }
90 }