use of org.wso2.carbon.apimgt.impl.APIManagerConfigurationService in project carbon-apimgt by wso2.
the class WebSubConfigContextTest method testWithoutSecretConfigContextForAPI.
@Test
public void testWithoutSecretConfigContextForAPI() throws Exception {
API api = new API(new APIIdentifier("admin", "websubAPI", "1.0.0"));
api.setStatus(APIConstants.CREATED);
api.setContextTemplate("/websub");
api.setTransports(Constants.TRANSPORT_HTTP);
api.setEndpointSecured(false);
api.setUriTemplates(setAPIUriTemplates());
api.setType(APIConstants.APITransportType.WEBSUB.toString());
WebsubSubscriptionConfiguration webSubConfig = new WebsubSubscriptionConfiguration(false, "", "", "");
api.setWebsubSubscriptionConfiguration(webSubConfig);
Environment environment = new Environment();
environment.setType("production");
config = Mockito.mock(APIManagerConfiguration.class);
APIManagerConfigurationService apiManagerConfigurationService = new APIManagerConfigurationServiceImpl(config);
ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(apiManagerConfigurationService);
String templatePath = System.getProperty("user.dir") + File.separator + "src" + File.separator + "test" + File.separator + "resources" + File.separator;
System.setProperty("carbon.home", templatePath);
APITemplateBuilderImpl apiTemplateBuilder = new APITemplateBuilderImpl(api, null, null);
String updatedTemplate = apiTemplateBuilder.getConfigStringForTemplate(environment);
Assert.assertFalse("The websub velocity template is not updated correctly", updatedTemplate.contains("generated_signature"));
}
use of org.wso2.carbon.apimgt.impl.APIManagerConfigurationService in project carbon-apimgt by wso2.
the class KeyMgtRegistrationService method registerDefaultKeyManager.
public static void registerDefaultKeyManager(String organization) throws APIManagementException {
synchronized (KeyMgtRegistrationService.class.getName().concat(organization)) {
ApiMgtDAO instance = ApiMgtDAO.getInstance();
if (instance.getKeyManagerConfigurationByName(organization, APIConstants.KeyManager.DEFAULT_KEY_MANAGER) == null) {
APIManagerConfigurationService apiManagerConfigurationService = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService();
KeyManagerConfigurationDTO keyManagerConfigurationDTO = new KeyManagerConfigurationDTO();
keyManagerConfigurationDTO.setName(APIConstants.KeyManager.DEFAULT_KEY_MANAGER);
keyManagerConfigurationDTO.setEnabled(true);
keyManagerConfigurationDTO.setUuid(UUID.randomUUID().toString());
keyManagerConfigurationDTO.setOrganization(organization);
keyManagerConfigurationDTO.setDescription(APIConstants.KeyManager.DEFAULT_KEY_MANAGER_DESCRIPTION);
keyManagerConfigurationDTO.setTokenType(KeyManagerConfiguration.TokenType.DIRECT.toString());
if (apiManagerConfigurationService != null && apiManagerConfigurationService.getAPIManagerConfiguration() != null) {
String defaultKeyManagerType = apiManagerConfigurationService.getAPIManagerConfiguration().getFirstProperty(APIConstants.DEFAULT_KEY_MANAGER_TYPE);
if (StringUtils.isNotEmpty(defaultKeyManagerType)) {
keyManagerConfigurationDTO.setType(defaultKeyManagerType);
} else {
keyManagerConfigurationDTO.setType(APIConstants.KeyManager.DEFAULT_KEY_MANAGER_TYPE);
}
}
TokenHandlingDto tokenHandlingDto = new TokenHandlingDto();
tokenHandlingDto.setEnable(true);
tokenHandlingDto.setType(TokenHandlingDto.TypeEnum.REFERENCE);
tokenHandlingDto.setValue(APIConstants.KeyManager.UUID_REGEX);
keyManagerConfigurationDTO.addProperty(APIConstants.KeyManager.TOKEN_FORMAT_STRING, new Gson().toJson(Arrays.asList(tokenHandlingDto)));
instance.addKeyManagerConfiguration(keyManagerConfigurationDTO);
}
}
}
use of org.wso2.carbon.apimgt.impl.APIManagerConfigurationService in project carbon-apimgt by wso2.
the class AbstractAPIManagerTestCase method testGetPoliciesIncludeUnlimitedThrottletier.
@Test
public void testGetPoliciesIncludeUnlimitedThrottletier() throws APIManagementException, org.wso2.carbon.user.api.UserStoreException, RegistryException, XMLStreamException {
SubscriptionPolicy[] policies3 = { new SubscriptionPolicy("policy4"), new SubscriptionPolicy("policy5"), new SubscriptionPolicy("policy6") };
PowerMockito.mockStatic(APIUtil.class);
BDDMockito.when(APIUtil.getTenantId(Mockito.anyString())).thenReturn(-1234);
PowerMockito.when(APIUtil.replaceSystemProperty(Mockito.anyString())).thenAnswer((Answer<String>) invocation -> {
Object[] args = invocation.getArguments();
return (String) args[0];
});
AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(apiMgtDAO);
Mockito.when(apiMgtDAO.getSubscriptionPolicies(Mockito.anyInt())).thenReturn(policies3);
ServiceReferenceHolder sh = mockRegistryAndUserRealm(-1234);
APIManagerConfigurationService amConfigService = Mockito.mock(APIManagerConfigurationService.class);
APIManagerConfiguration amConfig = Mockito.mock(APIManagerConfiguration.class);
ThrottleProperties throttleProperties = Mockito.mock(ThrottleProperties.class, Mockito.RETURNS_MOCKS);
PowerMockito.when(sh.getAPIManagerConfigurationService()).thenReturn(amConfigService);
PowerMockito.when(amConfigService.getAPIManagerConfiguration()).thenReturn(amConfig);
PowerMockito.when(amConfig.getThrottleProperties()).thenReturn(throttleProperties);
PowerMockito.when(throttleProperties.isEnableUnlimitedTier()).thenReturn(true);
Assert.assertEquals(3, abstractAPIManager.getPolicies(API_PROVIDER, PolicyConstants.POLICY_LEVEL_SUB).length);
}
use of org.wso2.carbon.apimgt.impl.APIManagerConfigurationService in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetAllPaginatedAPIsByStatusSet.
@Test
public void testGetAllPaginatedAPIsByStatusSet() throws Exception {
Registry userRegistry = Mockito.mock(Registry.class);
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(userRegistry, apiMgtDAO);
PowerMockito.mockStatic(GovernanceUtils.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("10", "20");
PowerMockito.doNothing().when(APIUtil.class, "loadTenantRegistry", Mockito.anyInt());
GenericArtifactManager artifactManager = Mockito.mock(GenericArtifactManager.class);
PowerMockito.when(APIUtil.isAllowDisplayMultipleVersions()).thenReturn(false, true);
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).thenReturn(artifactManager);
List<GovernanceArtifact> governanceArtifacts = new ArrayList<GovernanceArtifact>();
GenericArtifact artifact = Mockito.mock(GenericArtifact.class);
governanceArtifacts.add(artifact);
Mockito.when(GovernanceUtils.findGovernanceArtifacts(Mockito.anyString(), (UserRegistry) Mockito.anyObject(), Mockito.anyString())).thenReturn(governanceArtifacts);
APIIdentifier apiId1 = new APIIdentifier("admin", "API1", "1.0.0");
API api = new API(apiId1);
Mockito.when(APIUtil.getAPI(artifact)).thenReturn(api);
String artifactPath = "artifact/path";
PowerMockito.when(GovernanceUtils.getArtifactPath(userRegistry, artifact.getId())).thenReturn(artifactPath);
Tag tag = new Tag();
Tag[] tags = new Tag[] { tag };
Mockito.when(userRegistry.getTags(artifactPath)).thenReturn(tags);
assertNotNull(apiConsumer.getAllPaginatedAPIsByStatus(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10, new String[] { "testStatus" }, false));
assertNotNull(apiConsumer.getAllPaginatedAPIsByStatus(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10, new String[] { "testStatus" }, true));
// artifact manager null path
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).thenReturn(null);
assertNotNull(apiConsumer.getAllPaginatedAPIsByStatus(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10, new String[] { "testStatus" }, true));
// generic artifact null path
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).thenReturn(artifactManager);
Mockito.when(GovernanceUtils.findGovernanceArtifacts(Mockito.anyString(), (UserRegistry) Mockito.anyObject(), Mockito.anyString())).thenReturn(null);
assertNotNull(apiConsumer.getAllPaginatedAPIsByStatus(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10, new String[] { "testStatus" }, true));
}
use of org.wso2.carbon.apimgt.impl.APIManagerConfigurationService in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetRecentlyAddedAPIs.
@Test
public void testGetRecentlyAddedAPIs() throws Exception {
Registry userRegistry = Mockito.mock(Registry.class);
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(userRegistry, apiMgtDAO);
UserRegistry userRegistry1 = 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");
API api = Mockito.mock(API.class);
Set<API> recentlyAddedAPI = new HashSet<API>();
recentlyAddedAPI.add(api);
PowerMockito.mockStatic(Caching.class);
CacheManager cacheManager = Mockito.mock(CacheManager.class);
Cache<Object, Object> cache = Mockito.mock(Cache.class);
Mockito.when(Caching.getCacheManager(Mockito.anyString())).thenReturn(cacheManager);
Mockito.when(cacheManager.getCache(Mockito.anyString())).thenReturn(cache);
Mockito.when(cache.get(Mockito.anyObject())).thenReturn(recentlyAddedAPI);
Resource resource = new ResourceImpl();
resource.setProperty("overview_status", "overview_status");
resource.setProperty("store_view_roles", "store_view_roles");
String path = "testPath";
Mockito.when(APIUtil.getAPIPath((APIIdentifier) Mockito.anyObject())).thenReturn(path);
Mockito.when(userRegistry1.get(Mockito.anyString())).thenReturn(resource);
PowerMockito.mockStatic(GovernanceUtils.class);
PowerMockito.doNothing().when(APIUtil.class, "loadTenantRegistry", Mockito.anyInt());
PowerMockito.when(APIUtil.isAllowDisplayMultipleVersions()).thenReturn(true, false);
System.setProperty(CARBON_HOME, "");
Mockito.when(registryService.getGovernanceUserRegistry(Mockito.anyString(), Mockito.anyInt())).thenReturn(userRegistry1);
Mockito.when(registryService.getGovernanceSystemRegistry(Mockito.anyInt())).thenReturn(userRegistry1);
GenericArtifactManager artifactManager = Mockito.mock(GenericArtifactManager.class);
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).thenReturn(artifactManager);
GenericArtifact artifact = Mockito.mock(GenericArtifact.class);
GenericArtifact[] genericArtifacts = new GenericArtifact[] { artifact };
Mockito.when(artifactManager.findGovernanceArtifacts(Mockito.anyString())).thenReturn(genericArtifacts);
APIIdentifier apiId1 = new APIIdentifier("admin", "API1", "1.0.0");
API api1 = new API(apiId1);
Mockito.when(APIUtil.getAPI(artifact)).thenReturn(api1);
// set isAllowDisplayMultipleVersions true
assertNotNull(apiConsumer.getRecentlyAddedAPIs(10, "testDomain"));
// set isAllowDisplayMultipleVersions false
assertNotNull(apiConsumer.getRecentlyAddedAPIs(10, "testDomain"));
}
Aggregations