Skip to content

Commit

Permalink
Improvements to test framework to detect specific validation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
terrypacker committed Mar 12, 2020
1 parent c4b0169 commit 6a76028
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -140,4 +141,34 @@ public void testAddEditRoleUserDoesNotHave() {

//TODO Test Add/Remove/Use Toggle Permission

@Override
String getReadRolesContextKey() {
return "toggleRoles";
}

@Override
String getEditRolesContextKey() {
return "toggleRoles";
}

@Test
@Override
public void testAddReadRoleUserDoesNotHave() {
runTest(() -> {
MaintenanceEventVO vo = newVO(readUser);
setReadRoles(Collections.singleton(roleService.getUserRole()), vo);
setEditRoles(Collections.singleton(roleService.getUserRole()), vo);
getService().permissionService.runAsSystemAdmin(() -> {
service.insert(vo);
});
getService().permissionService.runAs(readUser, () -> {
MaintenanceEventVO fromDb = service.get(vo.getId());
assertVoEqual(vo, fromDb);
vo.setToggleRoles(Collections.singleton(roleService.getSuperadminRole()));
service.update(fromDb.getId(), fromDb);
});

}, getReadRolesContextKey(), getReadRolesContextKey());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -129,4 +130,38 @@ public void testCreatePrivilegeFails() {
service.insert(vo);
});
}

@Override
@Test
public void testAddReadRoleUserDoesNotHave() {
runTest(() -> {
WatchListVO vo = newVO(readUser);

//Change Owner
vo.setUserId(this.allUser.getId());

setReadRoles(Collections.singleton(roleService.getUserRole()), vo);
setEditRoles(Collections.singleton(roleService.getUserRole()), vo);
getService().permissionService.runAsSystemAdmin(() -> {
service.insert(vo);
});
getService().permissionService.runAs(readUser, () -> {
WatchListVO fromDb = service.get(vo.getId());
assertVoEqual(vo, fromDb);
setReadRoles(Collections.singleton(roleService.getSuperadminRole()), fromDb);
service.update(fromDb.getId(), fromDb);
});

}, getReadRolesContextKey(), getReadRolesContextKey());
}

@Override
String getReadRolesContextKey() {
return "readRoles";
}

@Override
String getEditRolesContextKey() {
return "editRoles";
}
}

0 comments on commit 6a76028

Please sign in to comment.