Search in sources :

Example 71 with Resource

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

the class urn_perun_user_facility_attribute_def_virt_shellTest method setUp.

@Before
public void setUp() {
    classInstance = new urn_perun_user_facility_attribute_def_virt_shell();
    session = mock(PerunSessionImpl.class, RETURNS_DEEP_STUBS);
    preffered = new Attribute();
    defDefShell = new Attribute();
    facilityShell = new Attribute();
    resourceShell = new ArrayList();
    listOfMntPts = new ArrayList<String>();
    for (int i = 0; i < 5; i++) listOfMntPts.add("/mnt/bash" + i);
    preffered.setValue(new ArrayList(listOfMntPts));
    listOfMntPts.clear();
    listOfMntPts.add("/mnt/bash2");
    facilityShell.setValue(listOfMntPts);
    resourceShell.addAll(listOfMntPts);
    user = new User();
    facility = new Facility();
    resource = new Resource();
    resource.setName("myResource");
    resource.setDescription("desc");
    resource1 = new Resource();
    resource1.setId(1);
    resource1.setName("myResource");
    resource1.setDescription("desc");
    resourceList = new ArrayList<Resource>();
    resourceList.add(resource1);
}
Also used : User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) ArrayList(java.util.ArrayList) Resource(cz.metacentrum.perun.core.api.Resource) Facility(cz.metacentrum.perun.core.api.Facility) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) Before(org.junit.Before)

Example 72 with Resource

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

the class urn_perun_resource_attribute_def_def_shellsTest method testCheckAttributeValueWrongShellFormatShellIsDirectory.

@Test(expected = WrongAttributeValueException.class)
public void testCheckAttributeValueWrongShellFormatShellIsDirectory() throws Exception {
    System.out.println("testCheckAttributeValueWrongShellFormatShellIsDirectory()");
    Attribute attributeToCheck = new Attribute();
    attributeToCheck.setValue(new ArrayList<String>() {

        {
            add("/bin/bash/");
        }
    });
    when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSession.class), any(Facility.class), anyString())).thenReturn(listOfShells);
    classInstance.checkAttributeValue(session, new Resource(), attributeToCheck);
    fail("Shell attribute with inappropriate format was approved.");
}
Also used : PerunSession(cz.metacentrum.perun.core.api.PerunSession) Attribute(cz.metacentrum.perun.core.api.Attribute) Resource(cz.metacentrum.perun.core.api.Resource) Matchers.anyString(org.mockito.Matchers.anyString) Facility(cz.metacentrum.perun.core.api.Facility) Test(org.junit.Test)

Example 73 with Resource

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

the class urn_perun_member_resource_attribute_def_virt_isBannedTest method setUp.

@Before
public void setUp() throws Exception {
    classInstance = new urn_perun_member_resource_attribute_def_virt_isBanned();
    session = mock(PerunSessionImpl.class, RETURNS_DEEP_STUBS);
    facility = new Facility(1, "testFacility");
    resource = new Resource(1, "testResource", "desc", 1, 1);
    vo = new Vo(1, "testVo", "desc");
    user = new User(1, "name", "surname", "middlename", "title", "title");
    member = new Member(1, 1, 1, Status.VALID);
    banOnResource = new BanOnResource(1, new Date(), "test", 1, 1);
    banOnFacility = new BanOnFacility(1, new Date(), "test", 1, 1);
    isBanned = new Attribute(classInstance.getAttributeDefinition());
    isBanned.setValue(true);
    message1 = "Ban " + banOnResource.serializeToString() + " was set for memberId 1 on resourceId 1";
    message2 = "Ban " + banOnResource.serializeToString() + " was updated for memberId 1 on resourceId 1";
    message3 = "Ban " + banOnResource.serializeToString() + " was removed for memberId 1 on resourceId 1";
    message4 = "Ban " + banOnFacility.serializeToString() + " was set for userId 1 on facilityId 1";
    message5 = "Ban " + banOnFacility.serializeToString() + " was updated for userId 1 on facilityId 1";
    message6 = "Ban " + banOnFacility.serializeToString() + " was removed for userId 1 on facilityId 1";
    wrongMessage = "Ban " + banOnFacility.serializeToString() + " was destroyed for userId 1 on facilityId 1";
}
Also used : User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) Resource(cz.metacentrum.perun.core.api.Resource) Vo(cz.metacentrum.perun.core.api.Vo) Facility(cz.metacentrum.perun.core.api.Facility) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) Member(cz.metacentrum.perun.core.api.Member) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) Date(java.util.Date) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) Before(org.junit.Before)

Example 74 with Resource

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

the class urn_perun_resource_attribute_def_def_defaultShellTest method fillAttributeWhichNotExists.

@Test
public void fillAttributeWhichNotExists() throws Exception {
    System.out.println("fillAttributeWhichNotExists()");
    //testujeme scenar, kdy budeme hledat neexistujici atribut a proto ocekavame vyjimku AttrNotExists..
    when(ps.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSession.class), any(Resource.class), anyString())).thenThrow(new AttributeNotExistsException("neexistuje"));
    try {
        defShellAttr.fillAttribute(ps, new Resource(), new AttributeDefinition());
        fail();
    } catch (InternalErrorException ex) {
        assertTrue("Mela byt vyhozena vyjimka AttributeNotExistsException", (ex.getCause() instanceof AttributeNotExistsException));
    }
}
Also used : PerunSession(cz.metacentrum.perun.core.api.PerunSession) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) Resource(cz.metacentrum.perun.core.api.Resource) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Test(org.junit.Test)

Example 75 with Resource

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

the class urn_perun_resource_attribute_def_def_defaultShellTest method checkAttributeValueWhichNotExists.

@Test
public void checkAttributeValueWhichNotExists() throws Exception {
    System.out.println("checkAttributeValueWhichNotExists()");
    // hledame neexistujici atribut, proto ocekavame vyjimku
    when(ps.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSession.class), any(Resource.class), anyString())).thenThrow(new AttributeNotExistsException("neexistuje"));
    final Attribute attribute = new Attribute();
    attribute.setValue("mujShell");
    try {
        defShellAttr.checkAttributeValue(ps, new Resource(), attribute);
        fail();
    } catch (InternalErrorException ex) {
        assertTrue("Mela byt vyhozena vyjimka AttributeNotExistsException", (ex.getCause() instanceof AttributeNotExistsException));
    }
}
Also used : PerunSession(cz.metacentrum.perun.core.api.PerunSession) Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) Resource(cz.metacentrum.perun.core.api.Resource) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Test(org.junit.Test)

Aggregations

Resource (cz.metacentrum.perun.core.api.Resource)176 Test (org.junit.Test)110 Attribute (cz.metacentrum.perun.core.api.Attribute)82 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)79 Facility (cz.metacentrum.perun.core.api.Facility)56 User (cz.metacentrum.perun.core.api.User)55 Group (cz.metacentrum.perun.core.api.Group)49 ArrayList (java.util.ArrayList)41 Vo (cz.metacentrum.perun.core.api.Vo)31 Member (cz.metacentrum.perun.core.api.Member)29 PerunSession (cz.metacentrum.perun.core.api.PerunSession)29 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)26 RichResource (cz.metacentrum.perun.core.api.RichResource)25 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)20 RichUser (cz.metacentrum.perun.core.api.RichUser)18 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)18 ContactGroup (cz.metacentrum.perun.core.api.ContactGroup)17 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)17 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)15 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)14