OrganizationMembershipServiceImpl extends BaseServiceImpl<OrganizationMembership> implements OrganizationMembershipService { @Override public List<OrganizationMembership> getMembershipsForPersona(Persona persona) { return getList(stmtGetByPersonaInstance.get().setUUID("member", persona.getIdAsUUID())); }  @Override OrganizationMembership create(Organization organization, Persona persona, Role role); @Override List<OrganizationMembership> getMembershipsForPersona(Persona persona); @Override List<OrganizationMembership> getMembershipsForOrganization(Organization organization); @Override List<OrganizationMembership> getPersonaMembershipsForOrganization(Persona persona,
                                                                                       Organization organization); @Override OrganizationMembership getMembershipById(String id); @Override OrganizationMembership getById(UUID id); @Override OrganizationMembership changeRole(OrganizationMembership membership, Role role); @Override void remove(OrganizationMembership organizationMembership); @Override void remove(UUID id);  }
@Test public void listMembershipsForUserNotBelongingToAnyOrganization() { HawkularUser jdoe = userService.getOrCreateById(UUID.randomUUID().toString()); List<OrganizationMembership> memberships = membershipService.getMembershipsForPersona(jdoe); assertEquals("The persona should not belong to any organizations", 0, memberships.size()); }
@Test public void listMembershipsForUserBelongingToOrganization() { HawkularUser jdoe = userService.getOrCreateById(UUID.randomUUID().toString()); organizationService.createOrganization(UUID.randomUUID().toString(), "", jdoe); List<OrganizationMembership> memberships = membershipService.getMembershipsForPersona(jdoe); assertEquals("There should be one membership for this persona", 1, memberships.size()); }
@Test public void listMembershipsForSoleOrganization() { HawkularUser jdoe = userService.getOrCreateById(UUID.randomUUID().toString()); Organization acme = organizationService.createOrganization(UUID.randomUUID().toString(), "", jdoe); List<OrganizationMembership> memberships = membershipService.getMembershipsForPersona(acme); assertEquals("There should be no memberships for this organization", 0, memberships.size()); }
@Test public void listMembershipsForOrganizationBelongingToOrganization() { HawkularUser jdoe = userService.getOrCreateById(UUID.randomUUID().toString()); Organization acme = organizationService.createOrganization(UUID.randomUUID().toString(), "", jdoe); Organization itDepartment = organizationService.createOrganization(UUID.randomUUID().toString(), "", acme); List<OrganizationMembership> memberships = membershipService.getMembershipsForPersona(acme); assertEquals("Acme is super persona of IT department", 1, memberships.size()); }