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;
}
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");
}
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");
}
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());
}
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");
}
Aggregations