6c6a83e8522fa95944055f9d3c1403f6a235a66d
[policy/drools-applications.git] / controlloop / common / model-impl / events / src / test / java / org / onap / policy / controlloop / ControlLoopOperationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * controlloop
4  * ================================================================================
5  * Copyright (C) 2018 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.controlloop;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
27
28 import java.time.Instant;
29 import org.junit.Test;
30
31 public class ControlLoopOperationTest {
32
33     @Test
34     public void test() {
35         ControlLoopOperation operation = new ControlLoopOperation();
36         
37         assertEquals(operation, operation);
38         assertNotEquals(operation, new String());
39         assertNotEquals(operation, null);
40         
41         assertTrue(operation.hashCode() != 0);
42         assertTrue(operation.toString().startsWith("ControlLoopOperation"));
43         
44         assertNotNull(operation);
45         
46         operation.setActor("actor");
47         assertEquals("actor", operation.getActor());
48         
49         operation.setOperation("operation");
50         assertEquals("operation", operation.getOperation());
51         
52         Instant now = Instant.now();
53         operation.setStart(now);
54         assertEquals(now, operation.getStart());
55         operation.setEnd(now);
56         assertEquals(now, operation.getEnd());
57         
58         operation.setMessage("message");
59         assertEquals("message", operation.getMessage());
60         
61         operation.setOutcome("outcome");
62         assertEquals("outcome", operation.getOutcome());
63         
64         operation.setSubRequestId("1");
65         assertEquals("1", operation.getSubRequestId());
66         
67         operation.setTarget("target");
68         assertEquals("target", operation.getTarget());
69         
70         assertTrue(operation.hashCode() != 0);
71
72         ControlLoopOperation operation2 = new ControlLoopOperation(operation);
73         assertEquals(now, operation2.getEnd());
74         
75         assertEquals(operation, operation2);
76         
77         operation2.setActor("foo");
78         assertNotEquals(operation, operation2);
79         
80         operation = new ControlLoopOperation(null);
81         assertNotNull(operation.getStart());
82         
83         assertNotEquals(operation, operation2);
84         
85         assertTrue(operation.toMessage().startsWith("actor="));
86         assertTrue(operation.toHistory().startsWith("actor="));
87         
88     }
89 }