JUnits for coverage
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / portal / transport / EpNotificationItemTest.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */package org.onap.portalapp.portal.transport;
38
39 import static org.junit.Assert.assertEquals;
40 import static org.junit.Assert.assertFalse;
41 import static org.junit.Assert.assertNotEquals;
42 import static org.junit.Assert.assertNotNull;
43 import static org.junit.Assert.assertTrue;
44
45 import java.util.Date;
46 import java.util.HashSet;
47 import java.util.List;
48 import java.util.Set;
49 import java.util.stream.Collectors;
50
51 import org.junit.Test;
52
53 public class EpNotificationItemTest {
54         
55         private static final String TEST="test";
56         private static Date date=new Date();
57         
58         public EpNotificationItem mockEpNotificationItem(){
59                 EpNotificationItem epNotificationItem = new EpNotificationItem();
60                 Set<EpRoleNotificationItem> list=new HashSet<>();
61                 EpRoleNotificationItem item=new EpRoleNotificationItem();
62                 item.setRoleId(3);
63                 item.setId(1l);
64                 list.add(item);
65         List<Long> roleIds=     list.stream().map(e->e.getId()).collect(Collectors.toList());
66                 epNotificationItem.setNotificationId((long)1);
67                 epNotificationItem.setIsForOnlineUsers(TEST);
68                 epNotificationItem.setIsForAllRoles(TEST);
69                 epNotificationItem.setActiveYn(TEST);
70                 epNotificationItem.setMsgHeader(TEST);
71                 epNotificationItem.setMsgDescription(TEST);
72                 epNotificationItem.setMsgSource(TEST);
73                 
74                 epNotificationItem.setPriority((long)1);
75                 epNotificationItem.setCreatedId((long)1);
76                 epNotificationItem.setNotificationHyperlink(TEST);
77                 epNotificationItem.setStartTime(date);
78                 epNotificationItem.setEndTime(date);
79                 epNotificationItem.setCreatedDate(date);
80                 epNotificationItem.setCreatorId(1l);
81                 epNotificationItem.setRoles(list);
82                 epNotificationItem.setRoleIds(roleIds);
83                 
84                 
85                 return epNotificationItem;
86         }
87         
88         
89         
90         @Test
91         public void epNotificationItemTest(){
92                 EpNotificationItem epNotificationItem1 = mockEpNotificationItem();
93                 
94                 EpNotificationItem epNotificationItem = new EpNotificationItem();       
95                 epNotificationItem.setNotificationId(epNotificationItem1.getNotificationId());
96                 epNotificationItem.setIsForOnlineUsers(epNotificationItem1.getIsForOnlineUsers());
97                 epNotificationItem.setIsForAllRoles(epNotificationItem1.getIsForAllRoles());
98                 epNotificationItem.setActiveYn(epNotificationItem1.getActiveYn());
99                 epNotificationItem.setMsgHeader(epNotificationItem1.getMsgHeader());
100                 epNotificationItem.setMsgDescription(epNotificationItem1.getMsgDescription());
101                 epNotificationItem.setMsgSource(epNotificationItem1.getMsgSource());
102
103                 epNotificationItem.setPriority((long)1);
104                 epNotificationItem.setCreatedId(epNotificationItem1.getCreatedId());
105                 epNotificationItem.setNotificationHyperlink(epNotificationItem1.getNotificationHyperlink());
106                 epNotificationItem.setStartTime(new Date());
107                 epNotificationItem.setEndTime(epNotificationItem1.getEndTime());
108                 epNotificationItem.setCreatedDate(epNotificationItem1.getCreatedDate());
109                 epNotificationItem.setCreatorId(epNotificationItem1.getCreatorId());
110                 epNotificationItem.setRoles(epNotificationItem1.getRoles());
111                 epNotificationItem.setRoleIds(epNotificationItem1.getRoleIds());
112                 epNotificationItem.setStartTime(epNotificationItem1.getStartTime());
113                 assertNotNull(epNotificationItem.toString());
114                 //assertNotEquals(epNotificationItem.toString(), "EpNotificationItem [notificationId=1, isForOnlineUsers=test, isForAllRoles=test, activeYn=test, msgHeader=test, msgDescription=test, msgSource=test, startTime=null, endTime=null, priority=1, creatorId=null, createdDate=null, roles=null, roleIds=null]");
115                 assertEquals(epNotificationItem.hashCode(), epNotificationItem1.hashCode());
116                 EpNotificationItem epNotificationItem2 =epNotificationItem;
117                 assertTrue(epNotificationItem.equals(epNotificationItem2));
118                 assertTrue(epNotificationItem.equals(epNotificationItem1));
119                                         
120                 assertTrue(epNotificationItem.equals(epNotificationItem1));
121                 assertFalse(epNotificationItem.equals(null));
122                 epNotificationItem.setStartTime(null);
123                 assertFalse(epNotificationItem.equals(epNotificationItem1));
124                 epNotificationItem.setRoles(null);
125                 assertFalse(epNotificationItem.equals(epNotificationItem1));
126                 epNotificationItem.setRoleIds(null);
127                 assertFalse(epNotificationItem.equals(epNotificationItem1));
128                 epNotificationItem.setPriority(null);
129                 assertFalse(epNotificationItem.equals(epNotificationItem1));
130                 epNotificationItem.setNotificationId(null);
131                 assertFalse(epNotificationItem.equals(epNotificationItem1));
132                 epNotificationItem.setMsgSource(null);
133                 assertFalse(epNotificationItem.equals(epNotificationItem1));
134                 epNotificationItem.setMsgHeader(null);
135                 assertFalse(epNotificationItem.equals(epNotificationItem1));
136                 epNotificationItem.setMsgDescription(null);
137                 assertFalse(epNotificationItem.equals(epNotificationItem1));
138                 epNotificationItem.setIsForOnlineUsers(null);
139                 assertFalse(epNotificationItem.equals(epNotificationItem1));
140                 epNotificationItem.setIsForAllRoles(null);
141                 assertFalse(epNotificationItem.equals(epNotificationItem1));
142                 epNotificationItem.setEndTime(null);
143                 assertFalse(epNotificationItem.equals(epNotificationItem1));
144                 epNotificationItem.setCreatedId(null);
145                 assertFalse(epNotificationItem.equals(epNotificationItem1));
146                 epNotificationItem.setCreatedDate(null);
147                 assertFalse(epNotificationItem.equals(epNotificationItem1));
148                 epNotificationItem.setActiveYn(null);
149                 assertFalse(epNotificationItem.equals(epNotificationItem1));
150                 
151                 
152         }
153
154 }
155
156