use of cz.metacentrum.perun.core.api.Resource in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getResourceRequiredHostAttributes.
@Test
public void getResourceRequiredHostAttributes() throws Exception {
System.out.println(CLASS_NAME + "getResourceRequiredHostAttributes");
vo = setUpVo();
// also creates Facility
host = setUpHost().get(0);
// create resource
Resource resource = new Resource();
resource.setName("AttrTestResource");
perun.getResourcesManager().createResource(sess, resource, vo, facility);
service = setUpService();
attributes = setUpRequiredAttributes();
perun.getResourcesManager().assignService(sess, resource, service);
List<Attribute> reqAttr = attributesManager.getResourceRequiredAttributes(sess, resource, host);
assertNotNull("Unable to get host required attributes for resource", reqAttr);
assertTrue("There should be only one required attribute", reqAttr.size() == 1);
}
use of cz.metacentrum.perun.core.api.Resource in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getResourceRequiredHostAttributesWhenFakeResource.
@Test
public void getResourceRequiredHostAttributesWhenFakeResource() throws Exception {
System.out.println(CLASS_NAME + "getResourceRequiredHostAttributesWhenFakeResource");
// also creates cluster type facility
host = setUpHost().get(0);
vo = setUpVo();
// without service
Resource fakeResource = setUpResource();
List<Attribute> reqAttr = attributesManager.getResourceRequiredAttributes(sess, fakeResource, host);
assertNotNull("unable to get required host attributes for resource", reqAttr);
assertTrue("Shouldn't return attribute, when there is no service on resource", reqAttr.size() == 0);
}
use of cz.metacentrum.perun.core.api.Resource 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);
}
use of cz.metacentrum.perun.core.api.Resource in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getResourceRequiredMemberResourceAttributesWorkWithUserWhenFakeResource.
@Test
public void getResourceRequiredMemberResourceAttributesWorkWithUserWhenFakeResource() throws Exception {
System.out.println(CLASS_NAME + "getResourceRequiredMemberResourceAttributesWorkWithUserWhenFakeResource");
vo = setUpVo();
member = setUpMember();
facility = setUpFacility();
resource = setUpResource();
service = setUpService();
attributes = setUpRequiredAttributes();
perun.getResourcesManager().assignService(sess, resource, service);
Resource fakeResource = new Resource();
fakeResource.setName("AttrManTestResource2");
fakeResource.setDescription("fake resource");
perun.getResourcesManager().createResource(sess, fakeResource, vo, facility);
List<Attribute> reqAttr = attributesManager.getResourceRequiredAttributes(sess, fakeResource, resource, member, true);
assertNotNull("unable to get required member resource attributes for its services", reqAttr);
assertTrue("Shouldn't return attribute, when there is no service on resource", reqAttr.size() == 0);
reqAttr = attributesManager.getResourceRequiredAttributes(sess, fakeResource, fakeResource, member, true);
assertNotNull("unable to get required member resource attributes for its services", reqAttr);
assertTrue("Shouldn't return attribute, when there is no service on resource and no value set", reqAttr.size() == 0);
reqAttr = attributesManager.getResourceRequiredAttributes(sess, resource, fakeResource, member, true);
assertNotNull("unable to get required member resource attributes for its services", reqAttr);
assertTrue("Should return 4 attributes (but with no value)", reqAttr.size() == 4);
// member_resource, user_facility, user, member
}
use of cz.metacentrum.perun.core.api.Resource in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getMemberResourceAttributeByIdWhenResourceNotExists.
@Test(expected = ResourceNotExistsException.class)
public void getMemberResourceAttributeByIdWhenResourceNotExists() throws Exception {
System.out.println(CLASS_NAME + "getMemberResourceAttributeByIdWhenResourceNotExists");
vo = setUpVo();
member = setUpMember();
attributes = setUpMemberResourceAttribute();
int id = attributes.get(0).getId();
attributesManager.getAttributeById(sess, new Resource(), member, id);
// shouldn't find resource
}
Aggregations