Search in sources :

Example 26 with UserExtSource

use of cz.metacentrum.perun.core.api.UserExtSource in project perun by CESNET.

the class AttributesManagerEntryIntegrationTest method setUpWorld.

/**
	 * How the world look: "->" means "have a binding, connection with"
	 *
	 * vo1 -> member1OfUser1, member2OfUser2, member1OfUser3 && group1InVo1, group2InVo1, membersGroupOfVo1 && resource1InVo1, resource2InVo1
	 * vo2 -> member2OfUser1, member1OfUser2, member2OfUser3 && group1InVo2, group2InVo2, membersGroupOfVo2 && resource1InVo2, resource2InVo2
	 *
	 * user1 -> member1OfUser1, member2OfUser1 && userExtSource1
	 * user2 -> member1OfUser2, member2OfUser2 && userExtSource2
	 * user3 -> member1OfUser3, member2OfUser3 && userExtSource3
	 *
	 * member1OfUser1 IS allowed
	 * member2OfUser1 IS disallowed
	 * member1OfUser2 IS allowed
	 * member2OfUser2 IS disallowed
	 * member1OfUser3 IS allowed
	 * member2OfUser3 IS allowed
	 *
	 * group1InVo1 -> member1OfUser1, member2OfUser2, member1OfUser3
	 * group2InVo1 -> member1OfUser1, member2OfUser2
	 * group1InVo2 -> member2OfUser1, member1OfUser2
	 * group2InVo2 -> member2OfUser1, member1OfUser2, member2OfUser3
	 *
	 * facility1 -> host1OnFacility1, host2OnFacility1
	 * facility2 -> host1OnFacility2, host2OnFacility2
	 * facility3 -> host1OnFacility3, host2OnFacility3
	 *
	 * resource1InVo1 ->  facility1 && group1InVo1, group2InVo1
	 * resource2InVo1 ->  facility2 && group2InVo1
	 * resource1InVo2 ->  facility2 && group1InVo2, group2InVo2
	 * resource2InVo2 ->  facility3 && group2InVo2
	 */
public void setUpWorld() throws Exception {
    //Create VO
    vo1 = perun.getVosManagerBl().createVo(sess, new Vo(0, "vo1Test", "v1T"));
    vo2 = perun.getVosManagerBl().createVo(sess, new Vo(0, "vo2Test", "v2T"));
    //Create Groups(members groups in vos), Members and Users from Candidates
    Candidate can1 = new Candidate();
    can1.setFirstName("user1");
    can1.setId(0);
    can1.setMiddleName("");
    can1.setLastName("Test");
    can1.setTitleBefore("");
    can1.setTitleAfter("");
    UserExtSource userExtSource1 = new UserExtSource(new ExtSource(0, "testExtSource", "cz.metacentrum.perun.core.impl.ExtSourceInternal"), "user1TestLogin");
    UserExtSource userExtSource2 = new UserExtSource(new ExtSource(0, "testExtSource", "cz.metacentrum.perun.core.impl.ExtSourceInternal"), "user2TestLogin");
    UserExtSource userExtSource3 = new UserExtSource(new ExtSource(0, "testExtSource", "cz.metacentrum.perun.core.impl.ExtSourceInternal"), "user3TestLogin");
    can1.setUserExtSource(userExtSource1);
    can1.setAttributes(new HashMap<String, String>());
    member1OfUser1 = perun.getMembersManagerBl().createMemberSync(sess, vo1, can1);
    user1 = perun.getUsersManagerBl().getUserByMember(sess, member1OfUser1);
    member2OfUser1 = perun.getMembersManagerBl().createMember(sess, vo2, user1);
    can1.setFirstName("user2");
    can1.setUserExtSource(userExtSource2);
    member1OfUser2 = perun.getMembersManagerBl().createMemberSync(sess, vo2, can1);
    user2 = perun.getUsersManagerBl().getUserByMember(sess, member1OfUser2);
    member2OfUser2 = perun.getMembersManagerBl().createMember(sess, vo1, user2);
    can1.setFirstName("user3");
    can1.setUserExtSource(userExtSource3);
    member1OfUser3 = perun.getMembersManagerBl().createMemberSync(sess, vo1, can1);
    user3 = perun.getUsersManagerBl().getUserByMember(sess, member1OfUser3);
    member2OfUser3 = perun.getMembersManagerBl().createMember(sess, vo2, user3);
    //Validate members
    member1OfUser1 = perun.getMembersManagerBl().validateMember(sess, member1OfUser1);
    member2OfUser1 = perun.getMembersManagerBl().validateMember(sess, member2OfUser1);
    member1OfUser2 = perun.getMembersManagerBl().validateMember(sess, member1OfUser2);
    member2OfUser2 = perun.getMembersManagerBl().validateMember(sess, member2OfUser2);
    member1OfUser3 = perun.getMembersManagerBl().validateMember(sess, member1OfUser3);
    member2OfUser3 = perun.getMembersManagerBl().validateMember(sess, member2OfUser3);
    //Invalidate some members to Disallowed them
    perun.getMembersManagerBl().invalidateMember(sess, member2OfUser1);
    perun.getMembersManagerBl().invalidateMember(sess, member2OfUser2);
    //Create groups and add members to them
    membersGroupOfVo1 = perun.getGroupsManagerBl().getGroupByName(sess, vo1, VosManager.MEMBERS_GROUP);
    membersGroupOfVo2 = perun.getGroupsManagerBl().getGroupByName(sess, vo2, VosManager.MEMBERS_GROUP);
    group1InVo1 = perun.getGroupsManagerBl().createGroup(sess, vo1, new Group("testGroup1InVo1", ""));
    group2InVo1 = perun.getGroupsManagerBl().createGroup(sess, vo1, new Group("testGroup2InVo1", ""));
    group1InVo2 = perun.getGroupsManagerBl().createGroup(sess, vo2, new Group("testGroup1InVo2", ""));
    group2InVo2 = perun.getGroupsManagerBl().createGroup(sess, vo2, new Group("testGroup2InVo2", ""));
    perun.getGroupsManagerBl().addMember(sess, group1InVo1, member1OfUser1);
    perun.getGroupsManagerBl().addMember(sess, group2InVo1, member1OfUser1);
    perun.getGroupsManagerBl().addMember(sess, group1InVo1, member2OfUser2);
    perun.getGroupsManagerBl().addMember(sess, group2InVo1, member2OfUser2);
    perun.getGroupsManagerBl().addMember(sess, group1InVo2, member2OfUser1);
    perun.getGroupsManagerBl().addMember(sess, group2InVo2, member2OfUser1);
    perun.getGroupsManagerBl().addMember(sess, group1InVo2, member1OfUser2);
    perun.getGroupsManagerBl().addMember(sess, group2InVo2, member1OfUser2);
    perun.getGroupsManagerBl().addMember(sess, group1InVo1, member1OfUser3);
    perun.getGroupsManagerBl().addMember(sess, group2InVo2, member2OfUser3);
    //Create Facility
    facility1 = perun.getFacilitiesManagerBl().createFacility(sess, new Facility(0, "testFacility1"));
    facility2 = perun.getFacilitiesManagerBl().createFacility(sess, new Facility(0, "testFacility2"));
    facility3 = perun.getFacilitiesManagerBl().createFacility(sess, new Facility(0, "testFacility3"));
    //Create Host on Facilities
    host1OnFacility1 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "testHost1OnFacility1"), facility1);
    host2OnFacility1 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "testHost2OnFacility1"), facility1);
    host1OnFacility2 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "testHost1OnFacility2"), facility2);
    host2OnFacility2 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "testHost2OnFacility2"), facility2);
    host1OnFacility3 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "testHost1OnFacility3"), facility3);
    host2OnFacility3 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "testHost2OnFacility3"), facility3);
    //Create resources and assing group to them
    resource1InVo1 = perun.getResourcesManagerBl().createResource(sess, new Resource(0, "testResource1InVo1", "", facility1.getId(), vo1.getId()), vo1, facility1);
    resource2InVo1 = perun.getResourcesManagerBl().createResource(sess, new Resource(0, "testResource2InVo1", "", facility2.getId(), vo1.getId()), vo1, facility2);
    resource1InVo2 = perun.getResourcesManagerBl().createResource(sess, new Resource(0, "testResource1InVo2", "", facility2.getId(), vo2.getId()), vo2, facility2);
    resource2InVo2 = perun.getResourcesManagerBl().createResource(sess, new Resource(0, "testResource2InVo2", "", facility3.getId(), vo2.getId()), vo2, facility3);
    perun.getResourcesManagerBl().assignGroupToResource(sess, group1InVo1, resource1InVo1);
    perun.getResourcesManagerBl().assignGroupToResource(sess, group2InVo1, resource1InVo1);
    perun.getResourcesManagerBl().assignGroupToResource(sess, group2InVo1, resource2InVo1);
    perun.getResourcesManagerBl().assignGroupToResource(sess, group1InVo2, resource1InVo2);
    perun.getResourcesManagerBl().assignGroupToResource(sess, group2InVo2, resource1InVo2);
    perun.getResourcesManagerBl().assignGroupToResource(sess, group2InVo2, resource2InVo2);
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) Group(cz.metacentrum.perun.core.api.Group) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) Resource(cz.metacentrum.perun.core.api.Resource) Vo(cz.metacentrum.perun.core.api.Vo) Host(cz.metacentrum.perun.core.api.Host) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) Facility(cz.metacentrum.perun.core.api.Facility)

Example 27 with UserExtSource

use of cz.metacentrum.perun.core.api.UserExtSource in project perun by CESNET.

the class AttributesManagerEntryIntegrationTest method removeUserExtSourceAttributesWhenWrongAttrAssignment.

@Test(expected = WrongAttributeAssignmentException.class)
public void removeUserExtSourceAttributesWhenWrongAttrAssignment() throws Exception {
    System.out.println(CLASS_NAME + "removeUserExtSourceAttributesWhenWrongAttrAssignment");
    UserExtSource ues = setUpUserExtSourceTest();
    attributes = setUpFacilityAttribute();
    attributesManager.removeAttributes(sess, ues, attributes);
// shouldn't find facility attribute on user external source
}
Also used : UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 28 with UserExtSource

use of cz.metacentrum.perun.core.api.UserExtSource in project perun by CESNET.

the class AttributesManagerEntryIntegrationTest method getUserExtSourceAttributeWhenAttributeNotExists.

@Test(expected = AttributeNotExistsException.class)
public void getUserExtSourceAttributeWhenAttributeNotExists() throws Exception {
    System.out.println(CLASS_NAME + "getUserExtSourceAttributeWhenAttributeNotExists");
    UserExtSource ues = setUpUserExtSourceTest();
    attributesManager.getAttribute(sess, ues, "urn:perun:ues:attribute-def:opt:nesmysl");
// shouldn't find opt attribute "nesmysl"
}
Also used : UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 29 with UserExtSource

use of cz.metacentrum.perun.core.api.UserExtSource in project perun by CESNET.

the class AttributesManagerEntryIntegrationTest method setUserExtSourceAttributes.

@Test
public void setUserExtSourceAttributes() throws Exception {
    System.out.println(CLASS_NAME + "setUserExtSourceAttributes");
    UserExtSource ues = setUpUserExtSourceTest();
    attributes = setUpUserExtSourceAttribute();
    attributesManager.setAttributes(sess, ues, attributes);
    List<Attribute> retAttr = attributesManager.getAttributes(sess, ues);
    assertTrue("unable to set/or return userExtSource attribute we created", retAttr.contains(attributes.get(0)));
}
Also used : UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 30 with UserExtSource

use of cz.metacentrum.perun.core.api.UserExtSource in project perun by CESNET.

the class AttributesManagerEntryIntegrationTest method removeUserExtSourceAttribute.

@Test
public void removeUserExtSourceAttribute() throws Exception {
    System.out.println(CLASS_NAME + "removeUserExtSourceAttribute");
    UserExtSource ues = setUpUserExtSourceTest();
    attributes = setUpUserExtSourceAttribute();
    attributesManager.setAttribute(sess, ues, attributes.get(0));
    // create user external source and set attribute with value
    attributesManager.removeAttribute(sess, ues, attributes.get(0));
    // remove attribute from user external source (definition or attribute)
    List<Attribute> retAttr = attributesManager.getAttributes(sess, ues);
    assertFalse("our user external source shouldn't have set our attribute", retAttr.contains(attributes.get(0)));
}
Also used : UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)79 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)34 Test (org.junit.Test)34 ExtSource (cz.metacentrum.perun.core.api.ExtSource)28 Attribute (cz.metacentrum.perun.core.api.Attribute)19 Candidate (cz.metacentrum.perun.core.api.Candidate)18 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)14 User (cz.metacentrum.perun.core.api.User)12 Member (cz.metacentrum.perun.core.api.Member)11 ArrayList (java.util.ArrayList)11 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)8 Group (cz.metacentrum.perun.core.api.Group)7 ExtSourceNotExistsException (cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException)6 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)5 HashMap (java.util.HashMap)5 RichUser (cz.metacentrum.perun.core.api.RichUser)4 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)4 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)4 Matcher (java.util.regex.Matcher)4 RichMember (cz.metacentrum.perun.core.api.RichMember)3