Address more sonar issues in policy-models
[policy/models.git] / models-interactions / model-impl / guard / src / test / java / org / onap / policy / guard / OperationsHistoryTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3   * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END=========================================================
17  */
18
19 package org.onap.policy.guard;
20
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertNotEquals;
23 import static org.junit.Assert.assertTrue;
24
25 import java.util.Date;
26 import org.junit.Test;
27
28 public class OperationsHistoryTest {
29
30     @Test
31     public void test() {
32         OperationsHistory dao = new OperationsHistory();
33
34         dao.setActor("my-actor");
35         dao.setClosedLoopName("cl-name");
36         Date endDate = new Date();
37         dao.setEndtime(endDate);
38         dao.setId(100L);
39         dao.setMessage("my-message");
40         dao.setOperation("my-operation");
41         dao.setOutcome("my-outcome");
42         dao.setRequestId("my-request");
43         Date startDate = new Date(endDate.getTime() - 1);
44         dao.setStarttime(startDate);
45         dao.setSubrequestId("my-sub");
46         dao.setTarget("my-target");
47
48         assertEquals("my-actor", dao.getActor());
49         assertEquals("cl-name", dao.getClosedLoopName());
50         assertEquals(endDate, dao.getEndtime());
51         assertEquals(100L, dao.getId().longValue());
52         assertEquals("my-message", dao.getMessage());
53         assertEquals("my-operation", dao.getOperation());
54         assertEquals("my-outcome", dao.getOutcome());
55         assertEquals("my-request", dao.getRequestId());
56         assertEquals(startDate, dao.getStarttime());
57         assertEquals("my-sub", dao.getSubrequestId());
58         assertEquals("my-target", dao.getTarget());
59
60         assertTrue(dao.toString().startsWith("OperationsHistory"));
61
62         int hc = dao.hashCode();
63         dao.setId(101L);
64         assertNotEquals(hc, dao.hashCode());
65
66         assertEquals(dao, (Object) dao);
67         assertNotEquals(dao, new OperationsHistory());
68     }
69 }