Fix some sonars in policy-models
[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-2020 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         /*
39          * Disabling sonar to test equals().
40          */
41         assertEquals(operation, operation);         // NOSONAR
42         assertNotEquals(operation, "");             // NOSONAR
43         assertNotEquals(operation, null);
44
45         assertNotEquals(0, operation.hashCode());
46         assertTrue(operation.toString().startsWith("ControlLoopOperation"));
47
48         assertNotNull(operation);
49
50         operation.setActor("actor");
51         assertEquals("actor", operation.getActor());
52
53         operation.setOperation("operation");
54         assertEquals("operation", operation.getOperation());
55
56         Instant now = Instant.now();
57         operation.setStart(now);
58         assertEquals(now, operation.getStart());
59         operation.setEnd(now);
60         assertEquals(now, operation.getEnd());
61
62         operation.setMessage("message");
63         assertEquals("message", operation.getMessage());
64
65         operation.setOutcome("outcome");
66         assertEquals("outcome", operation.getOutcome());
67
68         operation.setSubRequestId("1");
69         assertEquals("1", operation.getSubRequestId());
70
71         operation.setTarget("target");
72         assertEquals("target", operation.getTarget());
73
74         assertNotEquals(0, operation.hashCode());
75
76         ControlLoopOperation operation2 = new ControlLoopOperation(operation);
77         assertEquals(now, operation2.getEnd());
78
79         assertEquals(operation, operation2);
80
81         operation2.setActor("foo");
82         assertNotEquals(operation, operation2);
83
84         operation = new ControlLoopOperation(null);
85         assertNotNull(operation.getStart());
86
87         assertNotEquals(operation, operation2);
88
89         assertTrue(operation.toMessage().startsWith("actor="));
90         assertTrue(operation.toHistory().startsWith("actor="));
91
92     }
93 }