Search in sources :

Example 86 with AttributeDefinition

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

the class AttributesManagerEntryIntegrationTest method getRichAttributesWithHoldersForAttributeDefinitionGetVosFromResource.

@Test
public void getRichAttributesWithHoldersForAttributeDefinitionGetVosFromResource() throws Exception {
    System.out.println(CLASS_NAME + "getRichAttributesWithHoldersForAttributeDefinitionGetVosFromResource");
    //Prepare attribute, create it and set it with testing value
    Attribute attribute = setAttributeInNamespace(AttributesManager.NS_VO_ATTR);
    perun.getAttributesManagerBl().setAttribute(sess, vo2, attribute);
    //Prepare richAttribute with holders (attribute is not needed but holders are needed)
    RichAttribute richAttr = new RichAttribute();
    richAttr.setPrimaryHolder(resource2InVo2);
    List<RichAttribute> listOfRichAttributes = perun.getAttributesManagerBl().getRichAttributesWithHoldersForAttributeDefinition(sess, new AttributeDefinition(attribute), richAttr);
    assertTrue("return only 1 vo", listOfRichAttributes.size() == 1);
    assertTrue("primary holder is type of vo", listOfRichAttributes.get(0).getPrimaryHolder() instanceof Vo);
    assertTrue("secondary holder is null", listOfRichAttributes.get(0).getSecondaryHolder() == null);
    assertTrue("the Vo is vo2", vo2.equals(listOfRichAttributes.get(0).getPrimaryHolder()));
    assertTrue("attribute in richAttribute is equals to our attribute", (listOfRichAttributes.get(0).getAttribute()).equals(attribute));
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) Vo(cz.metacentrum.perun.core.api.Vo) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 87 with AttributeDefinition

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

the class AttributesManagerEntryIntegrationTest method getRichAttributesWithHoldersForAttributeDefinitionGetVosFromHost.

@Test
public void getRichAttributesWithHoldersForAttributeDefinitionGetVosFromHost() throws Exception {
    System.out.println(CLASS_NAME + "getRichAttributesWithHoldersForAttributeDefinitionGetVosFromHost");
    //Prepare attribute, create it and set it with testing value
    Attribute attribute = setAttributeInNamespace(AttributesManager.NS_VO_ATTR);
    perun.getAttributesManagerBl().setAttribute(sess, vo2, attribute);
    perun.getAttributesManagerBl().setAttribute(sess, vo1, attribute);
    //Prepare richAttribute with holders (attribute is not needed but holders are needed)
    RichAttribute richAttr = new RichAttribute();
    richAttr.setPrimaryHolder(host1OnFacility2);
    List<RichAttribute> listOfRichAttributes = perun.getAttributesManagerBl().getRichAttributesWithHoldersForAttributeDefinition(sess, new AttributeDefinition(attribute), richAttr);
    //Return facilities Administrator too if exists
    assertTrue("return at least 2 vos", listOfRichAttributes.size() >= 2);
    assertTrue("return maximum of 3 vos", listOfRichAttributes.size() <= 3);
    assertTrue("primary holder is type of vo", listOfRichAttributes.get(0).getPrimaryHolder() instanceof Vo);
    assertTrue("secondary holder is null", listOfRichAttributes.get(0).getSecondaryHolder() == null);
    List<Vo> returnedVos = new ArrayList<Vo>();
    for (RichAttribute ra : listOfRichAttributes) {
        returnedVos.add((Vo) ra.getPrimaryHolder());
    }
    assertTrue("returned vos contains vo1", returnedVos.contains(vo1));
    assertTrue("returned vos contains vo2", returnedVos.contains(vo2));
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) Vo(cz.metacentrum.perun.core.api.Vo) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 88 with AttributeDefinition

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

the class AttributesManagerEntryIntegrationTest method checkNamespaceList.

@Test
public void checkNamespaceList() throws Exception {
    System.out.println(CLASS_NAME + "checkNamespaceList");
    AttributeDefinition attrDef = new AttributeDefinition();
    attrDef.setFriendlyName("attr-manager-test-attribute");
    attrDef.setNamespace("urn:perun:facility:attribute-def:opt");
    attrDef.setType(String.class.getName());
    attrDef.setDescription("AttributesManagerTest");
    Attribute attribute = new Attribute(attrDef);
    List<Attribute> attributes = new ArrayList<Attribute>();
    attributes.add(attribute);
    attributesManager.checkNamespace(sess, attributes, "urn:perun:facility:attribute-def:opt");
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 89 with AttributeDefinition

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

the class AttributesManagerEntryIntegrationTest method getRichAttributesWithHoldersForAttributeDefinitionGetVosFromKey.

@Test
public void getRichAttributesWithHoldersForAttributeDefinitionGetVosFromKey() throws Exception {
    System.out.println(CLASS_NAME + "getRichAttributesWithHoldersForAttributeDefinitionGetVosFromKey");
    //Prepare attribute, create it and set it with testing value
    Attribute attribute = setAttributeInNamespace(AttributesManager.NS_VO_ATTR);
    perun.getAttributesManagerBl().setAttribute(sess, vo2, attribute);
    //Prepare richAttribute with holders (attribute is not needed but holders are needed)
    RichAttribute richAttr = new RichAttribute();
    richAttr.setPrimaryHolder("String");
    List<RichAttribute> listOfRichAttributes = perun.getAttributesManagerBl().getRichAttributesWithHoldersForAttributeDefinition(sess, new AttributeDefinition(attribute), richAttr);
    //Return facilities Administrator too if exists
    assertTrue("return at least 2 vos", listOfRichAttributes.size() > 1);
    assertTrue("primary holder is type of vo", listOfRichAttributes.get(0).getPrimaryHolder() instanceof Vo);
    assertTrue("secondary holder is null", listOfRichAttributes.get(0).getSecondaryHolder() == null);
    List<Vo> returnedVos = new ArrayList<Vo>();
    for (RichAttribute ra : listOfRichAttributes) {
        returnedVos.add((Vo) ra.getPrimaryHolder());
    }
    assertTrue("returned vos contains vo2", returnedVos.contains(vo2));
    assertTrue("returned vos contains vo1", returnedVos.contains(vo1));
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) Vo(cz.metacentrum.perun.core.api.Vo) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 90 with AttributeDefinition

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

the class AttributesManagerEntryIntegrationTest method deleteAttributeForce.

// FIXME - deleteAttributeForce - not yet implemented
@Ignore
@Test(expected = AttributeNotExistsException.class)
public void deleteAttributeForce() throws Exception {
    System.out.println(CLASS_NAME + "deleteAttributeForce");
    AttributeDefinition attrDef = new AttributeDefinition();
    attrDef.setFriendlyName("attr-def-facility-tests-attr");
    attrDef.setNamespace("urn:perun:facility:attribute-def:opt");
    attrDef.setDescription("poznamka");
    attrDef.setType(String.class.getName());
    //
    attributesManager.createAttribute(sess, attrDef);
    assertNotNull("unable to create attribute before deletion", attributesManager.createAttribute(sess, attrDef));
    attributesManager.deleteAttribute(sess, attrDef, true);
    attributesManager.getAttributeDefinition(sess, "urn:perun:facility:attribute-def:opt:attr-def-facility-tests-attr");
// shouldn't find attribute definition in db
}
Also used : AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) Ignore(org.junit.Ignore) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)396 Attribute (cz.metacentrum.perun.core.api.Attribute)157 ArrayList (java.util.ArrayList)46 Test (org.junit.Test)38 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)33 User (cz.metacentrum.perun.core.api.User)24 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)22 Vo (cz.metacentrum.perun.core.api.Vo)15 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)14 Facility (cz.metacentrum.perun.core.api.Facility)12 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)12 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)12 Resource (cz.metacentrum.perun.core.api.Resource)10 LinkedHashMap (java.util.LinkedHashMap)10 Group (cz.metacentrum.perun.core.api.Group)8 Member (cz.metacentrum.perun.core.api.Member)8 PerunSession (cz.metacentrum.perun.core.api.PerunSession)7 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)6 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)5 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)5