Search in sources :

Example 6 with ResourceType

use of org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType in project charon by wso2.

the class AbstractSCIMObject method setResourceType.

/**
 * set the resourceType of the meta attribute
 *
 * @param resourceType
 */
public void setResourceType(String resourceType) throws BadRequestException, CharonException {
    // create the resourceType attribute as defined in schema.
    SimpleAttribute resourceTypeAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.RESOURCE_TYPE, new SimpleAttribute(SCIMConstants.CommonSchemaConstants.RESOURCE_TYPE, resourceType));
    // check meta complex attribute already exist.
    if (getMetaAttribute() != null) {
        ComplexAttribute metaAttribute = getMetaAttribute();
        // check version attribute already exist
        if (metaAttribute.isSubAttributeExist(resourceTypeAttribute.getName())) {
            String error = "Read only attribute is tried to modify";
            throw new CharonException(error);
        } else {
            metaAttribute.setSubAttribute(resourceTypeAttribute);
        }
    } else {
        // create meta attribute and set the sub attribute.
        createMetaAttribute();
        getMetaAttribute().setSubAttribute(resourceTypeAttribute);
    }
}
Also used : SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) CharonException(org.wso2.charon3.core.exceptions.CharonException)

Example 7 with ResourceType

use of org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType in project charon by wso2.

the class ScimAttributeAware method replaceResourceType.

/**
 * sets or overrides the resource type attribute of the given {@link #getResource()} object
 *
 * @param resourceType the resource type attribute to write
 */
public void replaceResourceType(String resourceType) {
    SCIMAttributeSchema metaDefinition = SCIMSchemaDefinitions.META;
    SCIMAttributeSchema resourceTypeDefinition = SCIMSchemaDefinitions.RESOURCE_TYPE;
    ComplexAttribute meta = getOrCrateComplexAttribute(metaDefinition);
    getSetSubAttributeConsumer(meta).accept(resourceTypeDefinition, () -> resourceType);
}
Also used : SCIMAttributeSchema(org.wso2.charon3.core.schema.SCIMAttributeSchema) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute)

Example 8 with ResourceType

use of org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType in project carbon-identity-framework by wso2.

the class ConfigurationManagerTest method testReplaceNonExistingAttribute.

@Test(priority = 19)
public void testReplaceNonExistingAttribute() throws Exception {
    ResourceType resourceType = configurationManager.addResourceType(getSampleResourceTypeAdd());
    Resource resource = configurationManager.addResource(resourceType.getName(), getSampleResource1Add());
    Attribute attribute = getSampleAttribute3();
    Attribute retrievedAttribute = configurationManager.replaceAttribute(resourceType.getName(), resource.getResourceName(), attribute);
    assertNotNull(retrievedAttribute.getAttributeId(), "Created resource id cannot be null");
}
Also used : Attribute(org.wso2.carbon.identity.configuration.mgt.core.model.Attribute) Resource(org.wso2.carbon.identity.configuration.mgt.core.model.Resource) ResourceType(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with ResourceType

use of org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType in project carbon-identity-framework by wso2.

the class ConfigurationManagerTest method testAddResource.

@Test(priority = 9)
public void testAddResource() throws Exception {
    ResourceType resourceType = configurationManager.addResourceType(getSampleResourceTypeAdd());
    ResourceAdd resourceTypeAdd = getSampleResource1Add();
    Resource resource = configurationManager.addResource(resourceType.getName(), resourceTypeAdd);
    assertNotNull(resource.getResourceId(), "Created resource type id cannot be null");
}
Also used : Resource(org.wso2.carbon.identity.configuration.mgt.core.model.Resource) ResourceType(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType) ResourceAdd(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceAdd) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 10 with ResourceType

use of org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType in project carbon-identity-framework by wso2.

the class ConfigurationManagerTest method testGetResourcesByType.

@Test(priority = 31)
public void testGetResourcesByType() throws Exception {
    ResourceType resourceType = configurationManager.addResourceType(getSampleResourceType2Add());
    Resource resource1 = configurationManager.addResource(resourceType.getName(), getSampleResource1Add());
    Resource resource2 = configurationManager.addResource(resourceType.getName(), getSampleResource2Add());
    Resources resourcesByType = configurationManager.getResourcesByType(resourceType.getName());
    Assert.assertTrue("Retrieved resource count should be equal to the added value", resourcesByType.getResources().size() == 2);
    Assert.assertEquals("Created resource name should be equal to the retrieved resource name", resource1.getResourceName(), resourcesByType.getResources().get(0).getResourceName());
    Assert.assertEquals("Created resource name should be equal to the retrieved resource name", resource2.getResourceName(), resourcesByType.getResources().get(1).getResourceName());
}
Also used : Resource(org.wso2.carbon.identity.configuration.mgt.core.model.Resource) ResourceType(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType) Resources(org.wso2.carbon.identity.configuration.mgt.core.model.Resources) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ResourceType (org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType)36 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)27 Test (org.testng.annotations.Test)27 Resource (org.wso2.carbon.identity.configuration.mgt.core.model.Resource)22 Attribute (org.wso2.carbon.identity.configuration.mgt.core.model.Attribute)9 InputStream (java.io.InputStream)7 ResourceFile (org.wso2.carbon.identity.configuration.mgt.core.model.ResourceFile)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 QName (javax.xml.namespace.QName)6 XMLStreamException (javax.xml.stream.XMLStreamException)6 OMAttribute (org.apache.axiom.om.OMAttribute)6 OMElement (org.apache.axiom.om.OMElement)6 Resources (org.wso2.carbon.identity.configuration.mgt.core.model.Resources)6 Resource (org.wso2.carbon.registry.core.Resource)6 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)6 File (java.io.File)5 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)4 Mediation (org.wso2.carbon.apimgt.api.model.Mediation)4 JdbcTemplate (org.wso2.carbon.database.utils.jdbc.JdbcTemplate)4