public void testUpdateNotification() { ISession session = null; try { // Se intenta modificar una notificacion con una sesion invalida Server.getInstance().modifyNotification(-15, not); fail("se esperaba NotLoggedException"); } catch (NotLoggedException e) { } catch (Exception e) { fail("se esperaba NotLoggedException"); } try { // Se intenta modificar una notificacion inexistente session = Server.getInstance().login("emp2", "emp2"); Server.getInstance().modifyNotification(session.getId(), not); fail("se esperaba NonExistentNotificationException"); } catch (NonExistentNotificationException e) { } catch (Exception e) { fail("se esperaba NonExistentNotificationException"); } try { // Se intenta cambiar el estado de la notificación sin estar logueado Server.getInstance().modifyNotificationState(-15, not); Server.getInstance().getNotificationsUser(session.getId()); fail("se esperaba NotLoggedException"); } catch (NotLoggedException e) { } catch (Exception e) { fail("se esperaba NotLoggedException"); } try { // Se intenta insertar una notificacion Server.getInstance().setCurrentProject(session.getId(), project.getId()); Server.getInstance().createNotification(session.getId(), not); List<Notification> nots = Server.getInstance().getNotificationsProject(session.getId()); assertTrue(nots.size() == 1); assertEquals(nots.get(0), not); // Se añade un usuario a la notificacion y se actualiza not.getUsers().add(chief); not.getUsers().add(employee); Server.getInstance().modifyNotification(session.getId(), not); nots = Server.getInstance().getNotificationsUser(session.getId()); assertTrue(nots.size() == 1); assertEquals(nots.get(0), not); // Se modifica el estado de la notificacion para este usuario not.setState("Read"); Server.getInstance().modifyNotificationState(session.getId(), not); nots = Server.getInstance().getNotificationsUser(session.getId()); assertTrue(nots.size() == 1); assertEquals(nots.get(0), not); // Se comprueba que no ha afectado al otro usuario el cambio de estado session = Server.getInstance().login("emp1", "emp1"); Server.getInstance().setCurrentProject(session.getId(), project.getId()); nots = Server.getInstance().getNotificationsUser(session.getId()); assertTrue(nots.size() == 1); assertFalse(nots.get(0).getState().startsWith("R")); } catch (Exception e) { fail(e.toString()); } }