org.wso2.carbon.registry.core.session.UserRegistry Java Examples

The following examples show how to use org.wso2.carbon.registry.core.session.UserRegistry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractAPIManagerTestCase.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test
    public void testGetSwaggerDefinitionTimeStamps() throws Exception {
        APIIdentifier identifier = getAPIIdentifier(SAMPLE_API_NAME, API_PROVIDER, SAMPLE_API_VERSION);
        UserRegistry registry = Mockito.mock(UserRegistry.class);
        Mockito.when(tenantManager.getTenantId(Mockito.anyString())).thenThrow(UserStoreException.class)
                .thenReturn(-1234);
        PowerMockito.mockStatic(OASParserUtil.class);
        Mockito.when(registryService.getGovernanceUserRegistry(Mockito.anyString(), Mockito.anyInt())).thenThrow
                (RegistryException.class).thenReturn(registry);
        AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(null, registryService,registry,
                tenantManager);
        Assert.assertNull(abstractAPIManager.getSwaggerDefinitionTimeStamps(identifier));
        Assert.assertNull(abstractAPIManager.getSwaggerDefinitionTimeStamps(identifier));
        abstractAPIManager.tenantDomain = SAMPLE_TENANT_DOMAIN_1;
        Map<String, String> result = new HashMap<String, String>();
        result.put("swagger1","scopes:apim_create,resources:{get:/*}");
        result.put("swagger2","scopes:apim_view,resources:{get:/menu}");
//        Mockito.when(apiDefinitionFromOpenAPISpec.getAPIOpenAPIDefinitionTimeStamps((APIIdentifier) Mockito.any(),
//                (org.wso2.carbon.registry.api.Registry) Mockito.any())).thenReturn(result);
//        Assert.assertEquals(abstractAPIManager.getSwaggerDefinitionTimeStamps(identifier).size(),2);
//        abstractAPIManager.tenantDomain = SAMPLE_TENANT_DOMAIN;
//        result.put("swagger3","");
//        Assert.assertEquals(abstractAPIManager.getSwaggerDefinitionTimeStamps(identifier).size(),3);

    }
 
Example #2
Source File: CloudServicesUtil.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
public static boolean isCloudServiceActive(String cloudServiceName,
                                           int tenantId, UserRegistry govRegistry)
                                                                                  throws Exception {
    // The cloud manager is always active
    if (StratosConstants.CLOUD_MANAGER_SERVICE.equals(cloudServiceName)) {
        return true;
    }

    String cloudServiceInfoPath = StratosConstants.CLOUD_SERVICE_INFO_STORE_PATH +
                                  RegistryConstants.PATH_SEPARATOR + tenantId +
                                  RegistryConstants.PATH_SEPARATOR + cloudServiceName;
    Resource cloudServiceInfoResource;
    if (govRegistry.resourceExists(cloudServiceInfoPath)) {
        cloudServiceInfoResource = govRegistry.get(cloudServiceInfoPath);
        String isActiveStr =
                             cloudServiceInfoResource.getProperty(
                                                     StratosConstants.CLOUD_SERVICE_IS_ACTIVE_PROP_KEY);
        return "true".equals(isActiveStr);
    }
    return false;
}
 
Example #3
Source File: SAMLValidatorUtil.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Get all SAML Issuers from configurations
 *
 * @return Issuer List
 * @throws IdentityException
 */
public static String[] getIssuersOfSAMLServiceProviders() throws IdentityException {
    try {
        IdentityPersistenceManager persistenceManager =
                IdentityPersistenceManager.getPersistanceManager();
        int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
        UserRegistry registry =
                SAMLSSOUtil.getRegistryService()
                        .getConfigSystemRegistry(tenantId);
        SAMLSSOServiceProviderDO[] serviceProviderDOs =
                persistenceManager.getServiceProviders(registry);
        if (serviceProviderDOs != null && serviceProviderDOs.length > 0) {
            List<String> issuers = new ArrayList<String>();
            for (SAMLSSOServiceProviderDO providerDO : serviceProviderDOs) {
                issuers.add(providerDO.getIssuer());
            }
            return issuers.toArray(new String[issuers.size()]);
        }
    } catch (Exception e) {
        throw IdentityException.error(
                SAMLValidatorConstants.ValidationMessage.ERROR_LOADING_SP_CONF,
                e);
    }
    return null;
}
 
Example #4
Source File: SequenceUtilsTestCase.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws UserStoreException, RegistryException {
    userRegistry = Mockito.mock(UserRegistry.class);
    serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    registryService = Mockito.mock(RegistryService.class);
    realmService = Mockito.mock(RealmService.class);
    tenantManager = Mockito.mock(TenantManager.class);
    PowerMockito.mockStatic(APIUtil.class);
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    PowerMockito.mockStatic(MultitenantUtils.class);
    PowerMockito.mockStatic(RegistryUtils.class);

    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
    Mockito.when(registryService.getGovernanceSystemRegistry(Mockito.anyInt())).thenReturn(userRegistry);
    Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
    Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
}
 
Example #5
Source File: Utils.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * gets no of verified user challenges
 *
 * @param userDTO bean class that contains user and tenant Information
 * @return no of verified challenges
 * @throws IdentityException if fails
 */
public static int getVerifiedChallenges(UserDTO userDTO) throws IdentityException {

    int noOfChallenges = 0;

    try {
        UserRegistry registry = IdentityMgtServiceComponent.getRegistryService().
                getConfigSystemRegistry(MultitenantConstants.SUPER_TENANT_ID);
        String identityKeyMgtPath = IdentityMgtConstants.IDENTITY_MANAGEMENT_CHALLENGES +
                RegistryConstants.PATH_SEPARATOR + userDTO.getUserId() +
                RegistryConstants.PATH_SEPARATOR + userDTO.getUserId();

        Resource resource;
        if (registry.resourceExists(identityKeyMgtPath)) {
            resource = registry.get(identityKeyMgtPath);
            String property = resource.getProperty(IdentityMgtConstants.VERIFIED_CHALLENGES);
            if (property != null) {
                return Integer.parseInt(property);
            }
        }
    } catch (RegistryException e) {
        log.error("Error while processing userKey", e);
    }

    return noOfChallenges;
}
 
Example #6
Source File: Utils.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * gets no of verified user challenges
 *
 * @param userDTO bean class that contains user and tenant Information
 * @return no of verified challenges
 * @throws IdentityException if fails
 */
public static int getVerifiedChallenges(UserDTO userDTO) throws IdentityException {

    int noOfChallenges = 0;

    try {
        UserRegistry registry = IdentityMgtServiceComponent.getRegistryService().
                getConfigSystemRegistry(MultitenantConstants.SUPER_TENANT_ID);
        String identityKeyMgtPath = IdentityMgtConstants.IDENTITY_MANAGEMENT_CHALLENGES +
                RegistryConstants.PATH_SEPARATOR + userDTO.getUserId() +
                RegistryConstants.PATH_SEPARATOR + userDTO.getUserId();

        Resource resource;
        if (registry.resourceExists(identityKeyMgtPath)) {
            resource = registry.get(identityKeyMgtPath);
            String property = resource.getProperty(IdentityMgtConstants.VERIFIED_CHALLENGES);
            if (property != null) {
                return Integer.parseInt(property);
            }
        }
    } catch (RegistryException e) {
        log.error("Error while processing userKey", e);
    }

    return noOfChallenges;
}
 
Example #7
Source File: SAMLValidatorUtil.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Load Service Provider Configurations
 *
 * @param issuer
 * @return SAMLSSOServiceProviderDO
 * @throws IdentityException
 */
public static SAMLSSOServiceProviderDO getServiceProviderConfig(String issuer)
        throws IdentityException {
    try {
        SSOServiceProviderConfigManager idPConfigManager =
                SSOServiceProviderConfigManager.getInstance();
        SAMLSSOServiceProviderDO ssoIdpConfigs = idPConfigManager.getServiceProvider(issuer);
        if (ssoIdpConfigs == null) {
            IdentityPersistenceManager persistenceManager =
                    IdentityPersistenceManager.getPersistanceManager();
            int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
            UserRegistry registry =
                    SAMLSSOUtil.getRegistryService()
                            .getConfigSystemRegistry(tenantId);
            ssoIdpConfigs = persistenceManager.getServiceProvider(registry, issuer);
        }
        return ssoIdpConfigs;
    } catch (Exception e) {
        throw IdentityException.error(
                SAMLValidatorConstants.ValidationMessage.ERROR_LOADING_SP_CONF,
                e);
    }
}
 
Example #8
Source File: GatewayUtils.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * Delete the given registry property from the given tenant registry path
 *
 * @param propertyName property name
 * @param path         resource path
 * @param tenantDomain
 * @throws AxisFault
 */
public static void deleteRegistryProperty(String propertyName, String path, String tenantDomain)
        throws AxisFault {

    try {
        UserRegistry registry = getRegistry(tenantDomain);
        PrivilegedCarbonContext.startTenantFlow();
        if (tenantDomain != null && StringUtils.isNotEmpty(tenantDomain)) {
            PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
        } else {
            PrivilegedCarbonContext.getThreadLocalCarbonContext()
                    .setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
        }
        Resource resource = registry.get(path);
        if (resource != null && resource.getProperty(propertyName) != null) {
            resource.removeProperty(propertyName);
            registry.put(resource.getPath(), resource);
            resource.discard();
        }
    } catch (RegistryException | APIManagementException e) {
        String msg = "Failed to delete secure endpoint password alias " + e.getMessage();
        throw new AxisFault(msg, e);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
Example #9
Source File: MediationSecurityAdminServiceProxy.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
public boolean isAliasExist(String alias) throws APIManagementException {

        UserRegistry registry = GatewayUtils.getRegistry(tenantDomain);
        PrivilegedCarbonContext.startTenantFlow();
        if (tenantDomain != null && StringUtils.isNotEmpty(tenantDomain)) {
            PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
        } else {
            PrivilegedCarbonContext.getThreadLocalCarbonContext()
                    .setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
        }
        try {
            if (registry.resourceExists(APIConstants.API_SYSTEM_CONFIG_SECURE_VAULT_LOCATION)) {
                Resource resource = registry.get(APIConstants.API_SYSTEM_CONFIG_SECURE_VAULT_LOCATION);
                if (resource.getProperty(alias) != null) {
                    return true;
                }
            }
            return false;
        } catch (RegistryException e) {
            throw new APIManagementException("Error while reading registry resource "
                    + APIConstants.API_SYSTEM_CONFIG_SECURE_VAULT_LOCATION + " for tenant " + tenantDomain);
        } finally {
            PrivilegedCarbonContext.endTenantFlow();
        }
    }
 
Example #10
Source File: RegistryTopicManager.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public TopicNode getTopicTree() throws EventBrokerException {
    try {
        UserRegistry userRegistry =
                this.registryService.getGovernanceSystemRegistry(EventBrokerHolder.getInstance().getTenantId());
        if (!userRegistry.resourceExists(topicStoragePath)) {
            userRegistry.put(topicStoragePath, userRegistry.newCollection());
        }
        Resource root = userRegistry.get(this.topicStoragePath);
        TopicNode rootTopic = new TopicNode("/", "/");
        buildTopicTree(rootTopic, (Collection) root, userRegistry);
        return rootTopic;
    } catch (RegistryException e) {
        throw new EventBrokerException(e.getMessage(), e);
    }
}
 
Example #11
Source File: StratosApiV41Utils.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
private static void clearMetadata(String applicationId) throws RestAPIException {

        PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
        ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);

        String resourcePath = METADATA_REG_PATH + applicationId;
        Registry registry = (UserRegistry) PrivilegedCarbonContext.getThreadLocalCarbonContext()
                .getRegistry(RegistryType.SYSTEM_GOVERNANCE);
        try {
            registry.beginTransaction();
            if (registry.resourceExists(resourcePath)) {
                registry.delete(resourcePath);
                log.info(String.format("Application metadata removed: [application-id] %s", applicationId));
            }
            registry.commitTransaction();
        } catch (RegistryException e) {
            try {
                registry.rollbackTransaction();
            } catch (RegistryException e1) {
                log.error("Could not rollback transaction", e1);
            }
            throw new RestAPIException(
                    String.format("Application metadata removed: [application-id] %s", applicationId), e);
        }
    }
 
Example #12
Source File: CommonUtil.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
/**
 * validates domain from the successkey
 *
 * @param governanceSystemRegistry - The governance system registry
 * @param domain                   - tenant domain
 * @param successKey               - successkey
 * @return true, if successfully validated
 * @throws RegistryException, if validation failed
 */
public static boolean validateDomainFromSuccessKey(UserRegistry governanceSystemRegistry,
                                                   String domain, String successKey)
        throws RegistryException {
    String domainValidatorInfoPath =
            StratosConstants.DOMAIN_VALIDATOR_INFO_PATH + RegistryConstants.PATH_SEPARATOR +
                    domain + RegistryConstants.PATH_SEPARATOR +
                    StratosConstants.VALIDATION_KEY_RESOURCE_NAME;
    if (governanceSystemRegistry.resourceExists(domainValidatorInfoPath)) {
        Resource resource = governanceSystemRegistry.get(domainValidatorInfoPath);
        String actualSuccessKey = resource.getProperty("successKey");
        if (actualSuccessKey != null && successKey != null &&
                actualSuccessKey.trim().equals(successKey.trim())) {
            // the domain is correct
            return true;
        }
    }
    return false;
}
 
Example #13
Source File: APIConsumerImplTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetPublishedAPIsByProvider() throws APIManagementException, RegistryException {
    Registry userRegistry = Mockito.mock(Registry.class);
    APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(userRegistry, apiMgtDAO);
    PowerMockito.when(APIUtil.isAllowDisplayMultipleVersions()).thenReturn(true, false);
    PowerMockito.when(APIUtil.isAllowDisplayAPIsWithMultipleStatus()).thenReturn(true, false);
    GenericArtifactManager artifactManager = Mockito.mock(GenericArtifactManager.class);
    PowerMockito.when(APIUtil.getArtifactManager((UserRegistry)(Mockito.anyObject()), Mockito.anyString())).
            thenReturn(artifactManager);
    Association association = Mockito.mock(Association.class);
    Association[] associations = new Association[]{association};
    Mockito.when(userRegistry.getAssociations(Mockito.anyString(), Mockito.anyString())).thenReturn(associations);
    Mockito.when(association.getDestinationPath()).thenReturn("testPath");
    Resource resource = Mockito.mock(Resource.class);
    Mockito.when(userRegistry.get("testPath")).thenReturn(resource);
    Mockito.when(resource.getUUID()).thenReturn("testID");
    GenericArtifact genericArtifact = Mockito.mock(GenericArtifact.class);
    Mockito.when(artifactManager.getGenericArtifact(Mockito.anyString())).thenReturn(genericArtifact);
    Mockito.when(genericArtifact.getAttribute("overview_status")).thenReturn("PUBLISHED");
    APIIdentifier apiId1 = new APIIdentifier("admin", "API1", "1.0.0");
    API api = new API(apiId1);
    Mockito.when(APIUtil.getAPI(genericArtifact)).thenReturn(api);
    assertNotNull(apiConsumer.getPublishedAPIsByProvider("testID", 10));
    assertNotNull(apiConsumer.getPublishedAPIsByProvider("testID", 10));
}
 
Example #14
Source File: CustomAPIIndexerTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * This method checks the indexer's behaviour for APIs which does not have the relevant custom properties.
 *
 * @throws RegistryException Registry Exception.
 * @throws APIManagementException API Management Exception.
 */
@Test
public void testIndexingCustomProperties() throws RegistryException, APIManagementException {
    Resource resource = new ResourceImpl();
    PowerMockito.mockStatic(APIUtil.class);
    Mockito.doReturn(resource).when(userRegistry).get(Mockito.anyString());
    GenericArtifactManager artifactManager = Mockito.mock(GenericArtifactManager.class);
    GenericArtifact genericArtifact = Mockito.mock(GenericArtifact.class);
    PowerMockito.when(APIUtil.getArtifactManager((UserRegistry)(Mockito.anyObject()), Mockito.anyString())).
            thenReturn(artifactManager);
    Mockito.when(artifactManager.getGenericArtifact(Mockito.anyString())).thenReturn(genericArtifact);
    Mockito.when(genericArtifact.getAttribute(APIConstants.API_OVERVIEW_VISIBILITY)).thenReturn("public");
    PowerMockito.when(APIUtil.getAPI(genericArtifact, userRegistry))
            .thenReturn(Mockito.mock(API.class));
    resource.setProperty(APIConstants.API_RELATED_CUSTOM_PROPERTIES_PREFIX + APIConstants.
            CUSTOM_API_INDEXER_PROPERTY, APIConstants.CUSTOM_API_INDEXER_PROPERTY);
    Assert.assertEquals(APIConstants.OVERVIEW_PREFIX + APIConstants.API_RELATED_CUSTOM_PROPERTIES_PREFIX +
            APIConstants.CUSTOM_API_INDEXER_PROPERTY, indexer.getIndexedDocument(file2Index).getFields().keySet().
            toArray()[0].toString());
}
 
Example #15
Source File: CustomAPIIndexerTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * This method checks the indexer's behaviour for new APIs which does not have the relevant properties.
 *
 * @throws RegistryException Registry Exception.
 * @throws APIManagementException API Management Exception.
 */
@Test
public void testIndexDocumentForNewAPI() throws APIManagementException, RegistryException {
    Resource resource = new ResourceImpl();
    PowerMockito.mockStatic(APIUtil.class);
    GenericArtifactManager artifactManager = Mockito.mock(GenericArtifactManager.class);
    PowerMockito.when(APIUtil.getArtifactManager((UserRegistry)(Mockito.anyObject()), Mockito.anyString())).
            thenReturn(artifactManager);
    GenericArtifact genericArtifact = Mockito.mock(GenericArtifact.class);
    Mockito.when(artifactManager.getGenericArtifact(Mockito.anyString())).thenReturn(genericArtifact);
    Mockito.when(genericArtifact.getAttribute(APIConstants.API_OVERVIEW_VISIBILITY)).thenReturn("public");
    PowerMockito.when(APIUtil.getAPI(genericArtifact, userRegistry))
            .thenReturn(Mockito.mock(API.class));
    resource.setProperty(APIConstants.ACCESS_CONTROL, APIConstants.NO_ACCESS_CONTROL);
    resource.setProperty(APIConstants.PUBLISHER_ROLES, APIConstants.NULL_USER_ROLE_LIST);
    resource.setProperty(APIConstants.STORE_VIEW_ROLES, APIConstants.NULL_USER_ROLE_LIST);
    Mockito.doReturn(resource).when(userRegistry).get(Mockito.anyString());
    indexer.getIndexedDocument(file2Index);
    Assert.assertNull(APIConstants.CUSTOM_API_INDEXER_PROPERTY + " property was set for the API which does not "
            + "require migration", resource.getProperty(APIConstants.CUSTOM_API_INDEXER_PROPERTY));
}
 
Example #16
Source File: APIUtilTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test
public void testIsPerAPISequenceResourceMissing() throws Exception {
    APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class);

    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    RegistryService registryService = Mockito.mock(RegistryService.class);
    UserRegistry registry = Mockito.mock(UserRegistry.class);

    String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR +
            apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR +
            apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion();
    String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "in" + RegistryConstants.PATH_SEPARATOR;

    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
    Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry);
    Mockito.when(registry.resourceExists(eq(path))).thenReturn(false);

    boolean isPerAPiSequence = APIUtil.isPerAPISequence("sample", 1, apiIdentifier, "in");

    Assert.assertFalse(isPerAPiSequence);
}
 
Example #17
Source File: APIUtilTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test
public void testIsPerAPISequenceSequenceMissing() throws Exception {
    APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class);

    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    RegistryService registryService = Mockito.mock(RegistryService.class);
    UserRegistry registry = Mockito.mock(UserRegistry.class);

    String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR +
            apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR +
            apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion();
    String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "in" + RegistryConstants.PATH_SEPARATOR;

    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
    Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry);
    Mockito.when(registry.resourceExists(eq(path))).thenReturn(true);
    Mockito.when(registry.get(eq(path))).thenReturn(null);

    boolean isPerAPiSequence = APIUtil.isPerAPISequence("sample", 1, apiIdentifier, "in");

    Assert.assertFalse(isPerAPiSequence);
}
 
Example #18
Source File: APIUtilTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetOAuthConfigurationFromTenantRegistry () throws Exception{
    final int tenantId = -1234;
    final String property = "AuthorizationHeader";

    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    RegistryService registryService = Mockito.mock(RegistryService.class);
    UserRegistry userRegistry = Mockito.mock(UserRegistry.class);
    Resource resource = Mockito.mock(Resource.class);
    Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
    Mockito.when(registryService.getConfigSystemRegistry(tenantId)).thenReturn(userRegistry);
    Mockito.when(userRegistry.resourceExists(APIConstants.API_TENANT_CONF_LOCATION)).thenReturn(true);
    Mockito.when(userRegistry.get(APIConstants.API_TENANT_CONF_LOCATION)).thenReturn(resource);
    File siteConfFile = new File(Thread.currentThread().getContextClassLoader().
            getResource("tenant-conf.json").getFile());
    String tenantConfValue = FileUtils.readFileToString(siteConfFile);
    Mockito.when(resource.getContent()).thenReturn(tenantConfValue.getBytes());
    JSONParser parser = new JSONParser();
    JSONObject json = (JSONObject) parser.parse(tenantConfValue);
    String authorizationHeader = (String)json.get(property);
    String authHeader = getOAuthConfigurationFromTenantRegistry(tenantId,property);
    Assert.assertEquals(authorizationHeader, authHeader);
}
 
Example #19
Source File: APIUtilTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetMediationSequenceUuidCustomSequence() throws Exception {
    APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class);

    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    RegistryService registryService = Mockito.mock(RegistryService.class);
    UserRegistry registry = Mockito.mock(UserRegistry.class);

    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
    Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry);

    Collection collection = Mockito.mock(Collection.class);
    String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR +
            apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR +
            apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion();
    String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "custom" + RegistryConstants.PATH_SEPARATOR;

    Mockito.when(registry.get(eq(path))).thenReturn(collection);

    String[] childPaths = {"test"};
    Mockito.when(collection.getChildren()).thenReturn(childPaths);

    String expectedUUID = UUID.randomUUID().toString();

    InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader().
            getResource("sampleSequence.xml").getFile());

    Resource resource = Mockito.mock(Resource.class);
    Mockito.when(registry.get(eq("test"))).thenReturn(resource);
    Mockito.when(resource.getContentStream()).thenReturn(sampleSequence);
    Mockito.when(resource.getUUID()).thenReturn(expectedUUID);


    String actualUUID = APIUtil.getMediationSequenceUuid("sample", 1, "custom", apiIdentifier);

    Assert.assertEquals(expectedUUID, actualUUID);
    sampleSequence.close();
}
 
Example #20
Source File: CustomAPIIndexerTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws RegistryException {
    PowerMockito.mockStatic(GovernanceUtils.class);
    PowerMockito.mockStatic(IndexingManager.class);
    IndexingManager indexingManager = Mockito.mock(IndexingManager.class);
    PowerMockito.when(IndexingManager.getInstance()).thenReturn(indexingManager);
    userRegistry = Mockito.mock(UserRegistry.class);
    Mockito.doReturn(userRegistry).when(indexingManager).getRegistry(Mockito.anyInt());
    Mockito.doReturn(true).when(userRegistry).resourceExists(Mockito.anyString());
    PowerMockito.when(GovernanceUtils.getGovernanceSystemRegistry(userRegistry)).thenReturn(userRegistry);
    String path = RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + "/api";
    file2Index = new AsyncIndexer.File2Index("".getBytes(), null, path, -1234, "");
    indexer = new CustomAPIIndexer();
}
 
Example #21
Source File: APIConsumerImplTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetDeniedTiers() throws APIManagementException, org.wso2.carbon.user.core.UserStoreException {
    UserRegistry userRegistry = Mockito.mock(UserRegistry.class);
    APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
    APIManagerConfigurationService apiManagerConfigurationService = Mockito.
            mock(APIManagerConfigurationService.class);
    Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
    Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
    Mockito.when(apiManagerConfiguration.getFirstProperty(Mockito.anyString())).thenReturn("true", "false");
    APIConsumerImpl apiConsumer = new UserAwareAPIConsumerWrapper(userRegistry, apiMgtDAO);
    Mockito.when(userRegistry.getUserRealm()).thenReturn(userRealm);
    Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
    Mockito.when(userStoreManager.getRoleListOfUser(Mockito.anyString())).thenThrow(UserStoreException.class).
            thenReturn(new String[] { "role1", "role2" });
    Assert.assertEquals(apiConsumer.getDeniedTiers().size(), 0);
    PowerMockito.when(APIUtil.isAdvanceThrottlingEnabled()).thenReturn(true, false);
    TierPermissionDTO tierPermissionDTO = new TierPermissionDTO();
    TierPermissionDTO tierPermissionDTO1 = new TierPermissionDTO();
    tierPermissionDTO.setRoles(new String[] { "role1" });
    Set<TierPermissionDTO> tierPermissionDTOs = new HashSet<TierPermissionDTO>();
    tierPermissionDTOs.add(tierPermissionDTO);
    Mockito.when(apiMgtDAO.getThrottleTierPermissions(Mockito.anyInt())).thenReturn(tierPermissionDTOs);
    Assert.assertEquals(apiConsumer.getDeniedTiers().size(), 1);
    tierPermissionDTO.setRoles(new String[] { "role3" });
    Assert.assertEquals(apiConsumer.getDeniedTiers().size(), 0);
    Mockito.when(apiMgtDAO.getTierPermissions(Mockito.anyInt())).thenReturn(tierPermissionDTOs);
    Assert.assertEquals(apiConsumer.getDeniedTiers().size(), 0);
    tierPermissionDTO.setPermissionType(APIConstants.TIER_PERMISSION_ALLOW);
    Mockito.when(userStoreManager.getRoleListOfUser(Mockito.anyString())).thenReturn(new String[0]);
    tierPermissionDTOs.add(tierPermissionDTO1);
    tierPermissionDTO1.setRoles(new String[] { "role4" });
    Assert.assertEquals(apiConsumer.getDeniedTiers().size(), 1);
    Mockito.when(userStoreManager.getRoleListOfUser(Mockito.anyString()))
            .thenReturn(new String[] { "role1", "role2" });
    tierPermissionDTO1.setRoles(new String[] { "role2" });
    tierPermissionDTO1.setTierName("Silver");
    Assert.assertEquals(apiConsumer.getDeniedTiers().size(), 2);
}
 
Example #22
Source File: APIConsumerImplTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsTierDenied() throws APIManagementException, org.wso2.carbon.user.core.UserStoreException {
    UserRegistry userRegistry = Mockito.mock(UserRegistry.class);
    APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
    APIManagerConfigurationService apiManagerConfigurationService = Mockito.
            mock(APIManagerConfigurationService.class);
    Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
    Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
    Mockito.when(apiManagerConfiguration.getFirstProperty(Mockito.anyString())).thenReturn("true", "false");
    APIConsumerImpl apiConsumer = new UserAwareAPIConsumerWrapper(userRegistry, apiMgtDAO);
    Mockito.when(userRegistry.getUserRealm()).thenReturn(userRealm);
    Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
    Mockito.when(userStoreManager.getRoleListOfUser(Mockito.anyString())).thenThrow(UserStoreException.class).
            thenReturn(new String[] { "role1", "role2" });
    Assert.assertFalse(apiConsumer.isTierDeneid("tier1"));
    PowerMockito.when(APIUtil.isAdvanceThrottlingEnabled()).thenReturn(true, false);
    TierPermissionDTO tierPermissionDTO = new TierPermissionDTO();
    tierPermissionDTO.setRoles(new String[] { "role1" });
    Mockito.when(apiMgtDAO.getThrottleTierPermission(Mockito.anyString(), Mockito.anyInt()))
            .thenReturn(tierPermissionDTO);
    Assert.assertTrue(apiConsumer.isTierDeneid("tier1"));
    tierPermissionDTO.setRoles(new String[] { "role3" });
    Assert.assertFalse(apiConsumer.isTierDeneid("tier1"));
    Mockito.when(apiMgtDAO.getTierPermission(Mockito.anyString(), Mockito.anyInt())).thenReturn(tierPermissionDTO);
    Assert.assertFalse(apiConsumer.isTierDeneid("tier1"));
    tierPermissionDTO.setPermissionType(APIConstants.TIER_PERMISSION_ALLOW);
    Mockito.when(userStoreManager.getRoleListOfUser(Mockito.anyString())).thenReturn(new String[0]);
    Assert.assertTrue(apiConsumer.isTierDeneid("tier1"));

}
 
Example #23
Source File: APIUtilTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetCustomOutSequence() throws Exception {
    APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class);

    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    RegistryService registryService = Mockito.mock(RegistryService.class);
    UserRegistry registry = Mockito.mock(UserRegistry.class);

    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
    Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry);

    Collection collection = Mockito.mock(Collection.class);
    String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR +
            apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR +
            apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion();
    String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "out" + RegistryConstants.PATH_SEPARATOR;

    Mockito.when(registry.get(eq(path))).thenReturn(collection);

    String[] childPaths = {"test"};
    Mockito.when(collection.getChildren()).thenReturn(childPaths);

    InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader().
            getResource("sampleSequence.xml").getFile());

    Resource resource = Mockito.mock(Resource.class);
    Mockito.when(registry.get(eq("test"))).thenReturn(resource);
    Mockito.when(resource.getContentStream()).thenReturn(sampleSequence);


    OMElement customSequence = APIUtil.getCustomSequence("sample", 1, "out", apiIdentifier);

    Assert.assertNotNull(customSequence);
    sampleSequence.close();
}
 
Example #24
Source File: APIUtilTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetMediationSequenceUuidInSequence() throws Exception {
    APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class);

    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    RegistryService registryService = Mockito.mock(RegistryService.class);
    UserRegistry registry = Mockito.mock(UserRegistry.class);

    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
    Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry);

    Collection collection = Mockito.mock(Collection.class);
    String path = APIConstants.API_CUSTOM_SEQUENCE_LOCATION + File.separator + APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN;
    Mockito.when(registry.get(eq(path))).thenReturn(collection);

    String[] childPaths = {"test"};
    Mockito.when(collection.getChildren()).thenReturn(childPaths);

    String expectedUUID = UUID.randomUUID().toString();

    InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader().
            getResource("sampleSequence.xml").getFile());

    Resource resource = Mockito.mock(Resource.class);
    Mockito.when(registry.get(eq("test"))).thenReturn(resource);
    Mockito.when(resource.getContentStream()).thenReturn(sampleSequence);
    Mockito.when(resource.getUUID()).thenReturn(expectedUUID);


    String actualUUID = APIUtil.getMediationSequenceUuid("sample", 1, "in", apiIdentifier);

    Assert.assertEquals(expectedUUID, actualUUID);
    sampleSequence.close();
}
 
Example #25
Source File: APIUtilTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetMediationSequenceUuidCustomSequenceNotFound() throws Exception {
    APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class);

    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    RegistryService registryService = Mockito.mock(RegistryService.class);
    UserRegistry registry = Mockito.mock(UserRegistry.class);

    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
    Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry);

    Collection collection = Mockito.mock(Collection.class);
    String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR +
            apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR +
            apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion();
    String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "custom" + RegistryConstants.PATH_SEPARATOR;

    Mockito.when(registry.get(eq(path))).thenReturn(null, collection);

    String[] childPaths = {"test"};
    Mockito.when(collection.getChildren()).thenReturn(childPaths);

    String expectedUUID = UUID.randomUUID().toString();

    InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader().
            getResource("sampleSequence.xml").getFile());

    Resource resource = Mockito.mock(Resource.class);
    Mockito.when(registry.get(eq("test"))).thenReturn(resource);
    Mockito.when(resource.getContentStream()).thenReturn(sampleSequence);
    Mockito.when(resource.getUUID()).thenReturn(expectedUUID);


    String actualUUID = APIUtil.getMediationSequenceUuid("sample", 1, "custom", apiIdentifier);

    Assert.assertEquals(expectedUUID, actualUUID);
    sampleSequence.close();
}
 
Example #26
Source File: APIUtilTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsPerAPISequence() throws Exception {
    APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class);

    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    RegistryService registryService = Mockito.mock(RegistryService.class);
    UserRegistry registry = Mockito.mock(UserRegistry.class);

    String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR +
            apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR +
            apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion();
    String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "in" + RegistryConstants.PATH_SEPARATOR;

    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
    Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry);
    Mockito.when(registry.resourceExists(eq(path))).thenReturn(true);

    Collection collection = Mockito.mock(Collection.class);
    Mockito.when(registry.get(eq(path))).thenReturn(collection);

    String[] childPaths = {"test"};
    Mockito.when(collection.getChildren()).thenReturn(childPaths);

    InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader().
                    getResource("sampleSequence.xml").getFile());
    Resource resource = Mockito.mock(Resource.class);
    Mockito.when(registry.get(eq("test"))).thenReturn(resource);
    Mockito.when(resource.getContentStream()).thenReturn(sampleSequence);

    boolean isPerAPiSequence = APIUtil.isPerAPISequence("sample", 1, apiIdentifier, "in");

    Assert.assertTrue(isPerAPiSequence);
}
 
Example #27
Source File: RegistryTopicManager.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Building the topic tree
 *
 * @param topicNode    node of the topic
 * @param resource     the resource that holds child topics
 * @param userRegistry user registry
 * @throws EventBrokerException
 */
private void buildTopicTree(TopicNode topicNode, Collection resource, UserRegistry userRegistry)
        throws EventBrokerException {
    try {
        String[] children = resource.getChildren();
        if (children != null) {
            List<TopicNode> nodes = new ArrayList<TopicNode>();
            for (String childTopic : children) {
                Resource childResource = userRegistry.get(childTopic);
                if (childResource instanceof Collection) {
                    if (childTopic.endsWith("/")) {
                        childTopic = childTopic.substring(0, childTopic.length() - 2);
                    }
                    String nodeName = childTopic.substring(childTopic.lastIndexOf("/") + 1);
                    if (!nodeName.equals(EventBrokerConstants.EB_CONF_WS_SUBSCRIPTION_COLLECTION_NAME) &&
                        !nodeName.equals(EventBrokerConstants.EB_CONF_JMS_SUBSCRIPTION_COLLECTION_NAME)) {
                        childTopic =
                                childTopic.substring(childTopic.indexOf(this.topicStoragePath)
                                                     + this.topicStoragePath.length() + 1);
                        TopicNode childNode = new TopicNode(nodeName, childTopic);
                        nodes.add(childNode);
                        buildTopicTree(childNode, (Collection) childResource, userRegistry);
                    }
                }
            }
            topicNode.setChildren(nodes.toArray(new TopicNode[nodes.size()]));
        }
    } catch (RegistryException e) {
        throw new EventBrokerException(e.getMessage(), e);
    }
}
 
Example #28
Source File: CaptchaUtil.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
public static void setAnonAccessToCaptchaImages() throws Exception {
    UserRegistry systemTenantRegistry = CaptchaMgtServiceComponent.getConfigSystemRegistry(
            MultitenantConstants.SUPER_TENANT_ID);
    setAnonAuthorization(RegistryConstants.CONFIG_REGISTRY_BASE_PATH +
                    CaptchaMgtConstants.CAPTCHA_IMAGES_PATH,
            systemTenantRegistry.getUserRealm());
}
 
Example #29
Source File: APIUtilTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsPerAPISequenceNoPathsInCollection() throws Exception {
    APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class);

    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    RegistryService registryService = Mockito.mock(RegistryService.class);
    UserRegistry registry = Mockito.mock(UserRegistry.class);

    String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR +
            apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR +
            apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion();
    String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "in" + RegistryConstants.PATH_SEPARATOR;

    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
    Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry);
    Mockito.when(registry.resourceExists(eq(path))).thenReturn(false);

    Collection collection = Mockito.mock(Collection.class);
    Mockito.when(registry.get(eq(path))).thenReturn(collection);

    String[] childPaths = {};
    Mockito.when(collection.getChildren()).thenReturn(childPaths);

    boolean isPerAPiSequence = APIUtil.isPerAPISequence("sample", 1, apiIdentifier, "in");

    Assert.assertFalse(isPerAPiSequence);
}
 
Example #30
Source File: APIUtilTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetMediationSequenceUuidOutSequence() throws Exception {
    APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class);

    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    RegistryService registryService = Mockito.mock(RegistryService.class);
    UserRegistry registry = Mockito.mock(UserRegistry.class);

    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
    Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry);

    Collection collection = Mockito.mock(Collection.class);
    String path = APIConstants.API_CUSTOM_SEQUENCE_LOCATION + File.separator + APIConstants.API_CUSTOM_SEQUENCE_TYPE_OUT;
    Mockito.when(registry.get(eq(path))).thenReturn(collection);

    String[] childPaths = {"test"};
    Mockito.when(collection.getChildren()).thenReturn(childPaths);

    String expectedUUID = UUID.randomUUID().toString();

    InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader().
            getResource("sampleSequence.xml").getFile());

    Resource resource = Mockito.mock(Resource.class);
    Mockito.when(registry.get(eq("test"))).thenReturn(resource);
    Mockito.when(resource.getContentStream()).thenReturn(sampleSequence);
    Mockito.when(resource.getUUID()).thenReturn(expectedUUID);


    String actualUUID = APIUtil.getMediationSequenceUuid("sample", 1, "out", apiIdentifier);

    Assert.assertEquals(expectedUUID, actualUUID);
    sampleSequence.close();
}