+ @Test
+ public void publishNotificationTest_EmptyAppHeader() throws Exception {
+ // input
+ EpNotificationItem notificationItem = new EpNotificationItem();
+ List<Long> roleList = new ArrayList<Long>();
+ Long role1 = 1L;
+ roleList.add(role1);
+ notificationItem.setRoleIds(roleList);
+ notificationItem.setPriority(1L);
+ notificationItem.setMsgHeader("testHeader");
+ notificationItem.setMsgDescription("Test Description");
+ Date currentDate = new Date();
+ Calendar c = Calendar.getInstance();
+ c.setTime(currentDate);
+ c.add(Calendar.DATE, 1);
+ Date currentDatePlusOne = c.getTime();
+ notificationItem.setStartTime(currentDate);
+ notificationItem.setEndTime(currentDatePlusOne);
+
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(null);
+ final Map<String, String> params = new HashMap<>();
+ params.put("appKey", null);
+ Mockito.when(DataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", params, null))
+ .thenThrow(NullPointerException.class);
+
+ PortalAPIResponse response = externalAppsRestfulController.publishNotification(mockedRequest, notificationItem);
+ assertNotNull(response);
+ assertEquals("ok", response.getStatus());
+ assertEquals("success", response.getMessage());
+ ArgumentCaptor<EpNotificationItem> capture = ArgumentCaptor.forClass(EpNotificationItem.class);
+ Mockito.verify(userNotificationService).saveNotification(capture.capture());
+ assertNotNull(capture.getValue());
+ EpNotificationItem createdNofification = capture.getValue();
+ assertNotNull(createdNofification.getRoleIds());
+ assertEquals(0, createdNofification.getRoleIds().size());
+ }
+
+ @Test
+ public void publishNotificationTest_ErrorResponse() throws Exception {
+ // input
+ EpNotificationItem notificationItem = new EpNotificationItem();
+ List<Long> roleList = new ArrayList<Long>();
+ Long role1 = 1L;
+ roleList.add(role1);
+ notificationItem.setRoleIds(roleList);
+ notificationItem.setPriority(1L);
+ notificationItem.setMsgHeader("testHeader");
+ notificationItem.setMsgDescription("Test Description");
+ Date currentDate = new Date();
+ Calendar c = Calendar.getInstance();
+ c.setTime(currentDate);
+ c.add(Calendar.DATE, 1);
+ Date currentDatePlusOne = c.getTime();
+ notificationItem.setStartTime(currentDate);
+ notificationItem.setEndTime(currentDatePlusOne);
+
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(null);
+ final Map<String, String> params = new HashMap<>();
+ params.put("appKey", null);
+ Mockito.when(DataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", params, null))
+ .thenThrow(NullPointerException.class);
+ Mockito.when(userNotificationService.saveNotification(any(EpNotificationItem.class))).
+ thenThrow(new NullPointerException("expected message"));
+
+ PortalAPIResponse response = externalAppsRestfulController.publishNotification(mockedRequest, notificationItem);
+ assertNotNull(response);
+ assertEquals("error", response.getStatus());
+ assertEquals("expected message", response.getMessage());
+ }