@Test public void shouldNotAllowUserToBecomeApprover() throws Exception { final B2BUnitModel unit = modelService.create(B2BUnitModel.class); unit.setUid("aUnit"); final B2BCustomerModel customer = modelService.create(B2BCustomerModel.class); customer.setUid("test"); customer.setName("test"); customer.setEmail("*****@*****.**"); final Set<PrincipalGroupModel> groups = new HashSet<PrincipalGroupModel>(customer.getGroups()); groups.add(unit); customer.setGroups(groups); final Set<B2BCustomerModel> approvers = new HashSet<B2BCustomerModel>(); approvers.add(customer); unit.setApprovers(approvers); try { modelService.save(unit); } catch (final ModelSavingException e) { Assert.assertTrue( e.getMessage().contains("error.b2bunit.approverNotMemberOfB2BApproverGroup")); } }
@Test public void shouldAllowUserToBecomeApprover() throws Exception { final B2BUnitModel unit = modelService.create(B2BUnitModel.class); unit.setUid("aUnit"); final B2BCustomerModel customer = modelService.create(B2BCustomerModel.class); customer.setUid("test"); customer.setName("test"); customer.setEmail("*****@*****.**"); final Set<PrincipalGroupModel> groups = new HashSet<PrincipalGroupModel>(customer.getGroups()); final UserGroupModel b2bApproverGroup = userService.getUserGroupForUID("b2bapprovergroup"); groups.add(unit); groups.add(b2bApproverGroup); customer.setGroups(groups); final Set<B2BCustomerModel> approvers = new HashSet<B2BCustomerModel>(); approvers.add(customer); unit.setApprovers(approvers); modelService.save(unit); Assert.assertFalse(modelService.isNew(unit)); modelService.remove(unit); }