JUnit/SONAR/Checkstyle in ONAP-REST
[policy/engine.git] / ONAP-REST / src / test / java / org / onap / policy / rest / jpa / ActionBodyEntityTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-REST
4  * ================================================================================
5  * Copyright (C) 2018 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.rest.jpa;
23
24 import static org.hamcrest.CoreMatchers.is;
25 import static org.hamcrest.CoreMatchers.not;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNull;
28 import static org.junit.Assert.assertThat;
29
30 import java.util.Date;
31
32 import org.junit.Test;
33
34 public class ActionBodyEntityTest {
35     @Test
36     public void testEntity() {
37         // Set up test data
38         String value = "testVal";
39         ActionBodyEntity entity = new ActionBodyEntity();
40         entity.prePersist();
41
42         // Test set and get
43         ActionBodyEntity entity0 = new ActionBodyEntity();
44         entity0.preUpdate();
45         entity0.setActionBody(value);
46         assertEquals(value, entity0.getActionBody());
47         entity0.setActionBodyName(value);
48         assertEquals(value, entity0.getActionBodyName());
49         entity0.setCreatedBy(value);
50         assertEquals(value, entity0.getCreatedBy());
51         entity0.setModifiedBy(value);
52         assertEquals(value, entity0.getModifiedBy());
53
54         Date date = new Date();
55         entity0.setModifiedDate(date);
56         assertEquals(date, entity0.getModifiedDate());
57         assertEquals(0, entity0.getVersion());
58         assertNull(entity0.getCreatedDate());
59         entity0.setDeleted(true);
60         assertEquals(true, entity0.isDeleted());
61         assertEquals(0, entity0.getActionBodyId());
62
63         // Test equals method combinations
64         assertEquals(false, entity.equals(null));
65         assertEquals(true, entity.equals(entity));
66         assertEquals(false, entity.equals((Object) value));
67         ActionBodyEntity entity1 = new ActionBodyEntity();
68         assertEquals(false, entity.equals(entity1));
69         assertThat(entity.hashCode(), is(not(0)));
70     }
71 }