Search in sources :

Example 6 with Resource

use of org.wso2.carbon.identity.configuration.mgt.core.model.Resource in project product-microgateway by wso2.

the class HashUtils method detectChanges.

/**
 * Generate hashes for the specified apis, subscription and application policies, then compare with the previously
 * generated hashes and detect if there are changes with them.
 *
 * @param apis                 APIs list
 * @param subscriptionPolicies Subscription Policies list
 * @param appPolicies          Application policies list
 * @param projectName          Name of the project
 * @return true if there are changes detected vs the previous check
 * @throws HashingException error while change detection
 */
public static boolean detectChanges(List<ExtendedAPI> apis, List<SubscriptionThrottlePolicyDTO> subscriptionPolicies, List<ApplicationThrottlePolicyDTO> appPolicies, String projectName) throws HashingException {
    boolean hasChanges = true;
    Map<String, String> allHashesMap = new HashMap<>();
    Map<String, String> apiHashesMap = getMapOfHashes(apis);
    Map<String, String> appPolicyHashesMap = getMapOfHashes(appPolicies);
    Map<String, String> subsPolicyHashesMap = getMapOfHashes(subscriptionPolicies);
    logger.debug("API calculated hashes {}", apiHashesMap);
    logger.debug("App policy calculated hashes {}", appPolicyHashesMap);
    logger.debug("Subscription policy calculated hashes {}", subsPolicyHashesMap);
    allHashesMap.putAll(apiHashesMap);
    allHashesMap.putAll(appPolicyHashesMap);
    allHashesMap.putAll(subsPolicyHashesMap);
    try {
        Map<String, String> storedHashes = loadStoredResourceHashes(projectName);
        if (equalMaps(storedHashes, allHashesMap)) {
            logger.debug("No changes detected after calculating hashes.");
            hasChanges = false;
        } else {
            logger.debug("Storing calculated resource hashes.");
            storeResourceHashes(allHashesMap, projectName);
            logger.debug("Storing calculated resource hashes success.");
        }
    } catch (IOException e) {
        throw new HashingException("Error while resource change detection", e);
    }
    return hasChanges;
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) HashingException(org.wso2.apimgt.gateway.cli.exception.HashingException)

Example 7 with Resource

use of org.wso2.carbon.identity.configuration.mgt.core.model.Resource 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 8 with Resource

use of org.wso2.carbon.identity.configuration.mgt.core.model.Resource 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 9 with Resource

use of org.wso2.carbon.identity.configuration.mgt.core.model.Resource 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)

Example 10 with Resource

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

the class ConfigurationManagerTest method testAddAttribute.

@Test(priority = 17)
public void testAddAttribute() throws Exception {
    ResourceType resourceType = configurationManager.addResourceType(getSampleResourceTypeAdd());
    Resource resource = configurationManager.addResource(resourceType.getName(), getSampleResource1Add());
    Attribute attribute = getSampleAttribute3();
    Attribute retrievedAttribute = configurationManager.addAttribute(resourceType.getName(), resource.getResourceName(), attribute);
    assertNotNull(retrievedAttribute.getAttributeId(), "Created resource type 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)

Aggregations

Resource (org.wso2.carbon.registry.core.Resource)341 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)267 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)224 HashMap (java.util.HashMap)196 ArrayList (java.util.ArrayList)164 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)153 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)142 Test (org.testng.annotations.Test)130 Registry (org.wso2.carbon.registry.core.Registry)125 Test (org.junit.Test)115 IOException (java.io.IOException)113 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)111 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)109 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)90 Map (java.util.Map)86 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)86 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)79 InputStream (java.io.InputStream)78 Collection (org.wso2.carbon.registry.core.Collection)77 API (org.wso2.carbon.apimgt.api.model.API)73