@Test public void testGetDefaultDescription() throws Exception { UserInfo affectedUser = UserInfo.from(UserInfo.Username.valueOf("AffectedUser")).withUserId("AffectedUser").withFirstName("Aff").withLastName("Ected").build(); UserInfo invokingUser = UserInfo.from(UserInfo.Username.valueOf("InvokingUser")).withUserId("InvokingUser").withFirstName("Inv").withLastName("Oking").build(); AuthorizationChangeEvent event1 = new AuthorizationChangeEvent(invokingUser, Application.Name.valueOf("TestApp"), affectedUser, "", "ADMIN"); Assert.assertTrue("Description does not contain the application name, was:\n" + event1.getDefaultDescription(), event1.getDefaultDescription().contains("TestApp")); Assert.assertTrue("Description does not contain the username (affected user), was:\n" + event1.getDefaultDescription(), event1.getDefaultDescription().contains(affectedUser.getUsername().toString())); Assert.assertTrue("Description does not contain the username (invoking user), was:\n" + event1.getDefaultDescription(), event1.getDefaultDescription().contains(invokingUser.getUsername().toString())); Assert.assertTrue("Description does not contain the role change, was:\n" + event1.getDefaultDescription(), event1.getDefaultDescription().contains("ADMIN")); AuthorizationChangeEvent event2 = new AuthorizationChangeEvent(invokingUser, Application.Name.valueOf("TestApp"), affectedUser, "", ""); Assert.assertTrue("Description does not contain the application name, was:\n" + event1.getDefaultDescription(), event2.getDefaultDescription().contains("TestApp")); Assert.assertTrue("Description does not contain the username (affected user), was:\n" + event1.getDefaultDescription(), event2.getDefaultDescription().contains(affectedUser.getUsername().toString())); Assert.assertTrue("Description does not contain the username (invoking user), was:\n" + event1.getDefaultDescription(), event2.getDefaultDescription().contains(invokingUser.getUsername().toString())); Assert.assertTrue("Description does not contain the role deletion (\"removed\"), was:\n" + event1.getDefaultDescription(), event2.getDefaultDescription().contains("removed")); }
@Override public String getDefaultDescription() { if (!StringUtils.isBlank(getAfter())) { return getUser() + " changed the role of " + getPropertyName() + " in application " + getApplicationName() + " to " + getAfter(); } return getUser() + " removed the role of " + getPropertyName() + " from application " + getApplicationName(); }
AuthorizationChangeEvent extends AbstractChangeEvent implements ApplicationEvent { @Override public String getDefaultDescription() { if (!StringUtils.isBlank(getAfter())) { return getUser() + " changed the role of " + getPropertyName() + " in application " + getApplicationName() + " to " + getAfter(); } return getUser() + " removed the role of " + getPropertyName() + " from application " + getApplicationName(); } }
AuthorizationChangeEvent extends AbstractChangeEvent implements ApplicationEvent { @Override public String getDefaultDescription() { if (!StringUtils.isBlank(getAfter())) { return getUser() + " changed the role of " + getPropertyName() + " in application " + getApplicationName() + " to " + getAfter(); } return getUser() + " removed the role of " + getPropertyName() + " from application " + getApplicationName(); } AuthorizationChangeEvent(Application.Name applicationName, UserInfo user, String oldRole, String newRole);  AuthorizationChangeEvent(UserInfo admin, Application.Name applicationName, UserInfo user, String oldRole, String newRole); }
AuthorizationChangeEvent extends AbstractChangeEvent implements ApplicationEvent { @Override public String getDefaultDescription() { if (!StringUtils.isBlank(getAfter())) { return getUser() + " changed the role of " + getPropertyName() + " in application " + getApplicationName() + " to " + getAfter(); } return getUser() + " removed the role of " + getPropertyName() + " from application " + getApplicationName(); } AuthorizationChangeEvent(Application.Name applicationName, UserInfo user, String oldRole, String newRole);  AuthorizationChangeEvent(UserInfo admin, Application.Name applicationName, UserInfo user, String oldRole, String newRole); @Override String getDefaultDescription(); @Override Application.Name getApplicationName(); }
AuthorizationChangeEvent extends AbstractChangeEvent implements ApplicationEvent { @Override public String getDefaultDescription() { if (!StringUtils.isBlank(getAfter())) { return getUser() + " changed the role of " + getPropertyName() + " in application " + getApplicationName() + " to " + getAfter(); } return getUser() + " removed the role of " + getPropertyName() + " from application " + getApplicationName(); } AuthorizationChangeEvent(Application.Name applicationName, UserInfo user, String oldRole, String newRole);  AuthorizationChangeEvent(UserInfo admin, Application.Name applicationName, UserInfo user, String oldRole, String newRole); @Override String getDefaultDescription(); @Override Application.Name getApplicationName();  }