Merge "More JUnit additions for PAP-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  * ================================================================================
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.rest.jpa;
22
23 import static org.hamcrest.CoreMatchers.is;
24 import static org.hamcrest.CoreMatchers.not;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.assertThat;
28 import java.util.Date;
29 import org.junit.Test;
30
31 public class ActionBodyEntityTest {
32   @Test
33   public void testEntity() {
34     // Set up test data
35     String value = "testVal";
36     Date date = new Date();
37     ActionBodyEntity entity = new ActionBodyEntity();
38     entity.prePersist();
39     ActionBodyEntity entity2 = new ActionBodyEntity();
40     ActionBodyEntity entity3 = new ActionBodyEntity();
41
42     // Test set and get
43     entity3.preUpdate();
44     entity3.setActionBody(value);
45     assertEquals(value, entity3.getActionBody());
46     entity3.setActionBodyName(value);
47     assertEquals(value, entity3.getActionBodyName());
48     entity3.setCreatedBy(value);
49     assertEquals(value, entity3.getCreatedBy());
50     entity3.setModifiedBy(value);
51     assertEquals(value, entity3.getModifiedBy());
52     entity3.setModifiedDate(date);
53     assertEquals(date, entity3.getModifiedDate());
54     assertEquals(0, entity3.getVersion());
55     assertNull(entity3.getCreatedDate());
56     entity3.setDeleted(true);
57     assertEquals(true, entity3.isDeleted());
58     assertEquals(0, entity3.getActionBodyId());
59
60     // Test equals method combinations
61     assertEquals(false, entity.equals(null));
62     assertEquals(true, entity.equals(entity));
63     assertEquals(false, entity.equals(value));
64     assertEquals(false, entity.equals(entity2));
65     assertThat(entity.hashCode(), is(not(0)));
66   }
67 }