Search in sources :

Example 41 with APIManagerConfigurationService

use of org.wso2.carbon.apimgt.impl.APIManagerConfigurationService in project carbon-apimgt by wso2.

the class WSO2APIPublisherTestCase method init.

@Before
public void init() throws Exception {
    store = new APIStore();
    store.setDisplayName(storeName);
    store.setUsername(storeUserName);
    store.setPassword(storePassword);
    store.setEndpoint(storeEndpoint);
    identifier = new APIIdentifier(apiIdentifier);
    api = new API(identifier);
    defaultHttpClient = Mockito.mock(CloseableHttpClient.class);
    wso2APIPublisher = new WSO2APIPublisherWrapper(defaultHttpClient, username, Mockito.mock(APIProvider.class));
    CloseableHttpResponse httpResponse = Mockito.mock(CloseableHttpResponse.class);
    ServiceReferenceHolder serviceReferenceHolder = TestUtils.getServiceReferenceHolder();
    RealmService realmService = Mockito.mock(RealmService.class);
    tenantManager = Mockito.mock(TenantManager.class);
    Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
    Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
    HttpEntity entity = Mockito.mock(HttpEntity.class);
    statusLine = Mockito.mock(StatusLine.class);
    Mockito.doReturn(statusLine).when(httpResponse).getStatusLine();
    Mockito.doReturn(entity).when(httpResponse).getEntity();
    PowerMockito.mockStatic(EntityUtils.class);
    APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
    Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
    APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
    Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
    Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.EXTERNAL_API_STORES + "." + APIConstants.EXTERNAL_API_STORES_STORE_URL)).thenReturn(storeRedirectURL);
    HttpGet httpGet = Mockito.mock(HttpGet.class);
    HttpPost httpPost = Mockito.mock(HttpPost.class);
    HttpDelete httpDelete = Mockito.mock(HttpDelete.class);
    PowerMockito.whenNew(HttpGet.class).withAnyArguments().thenReturn(httpGet);
    PowerMockito.whenNew(HttpPost.class).withAnyArguments().thenReturn(httpPost);
    PowerMockito.whenNew(HttpDelete.class).withAnyArguments().thenReturn(httpDelete);
    Mockito.doReturn(httpResponse).when(defaultHttpClient).execute(httpPost);
    Mockito.doReturn(httpResponse).when(defaultHttpClient).execute(httpGet);
    Mockito.doReturn(httpResponse).when(defaultHttpClient).execute(httpDelete);
    MultipartEntityBuilder multipartEntityBuilder = Mockito.mock(MultipartEntityBuilder.class);
    PowerMockito.mockStatic(MultipartEntityBuilder.class);
    Mockito.when(MultipartEntityBuilder.create()).thenReturn(multipartEntityBuilder);
    Mockito.when(multipartEntityBuilder.build()).thenReturn(Mockito.mock(HttpEntity.class));
    Mockito.doNothing().when(httpPost).setEntity(Matchers.any());
    importExportAPI = Mockito.mock(ImportExportAPI.class);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) HttpPost(org.apache.http.client.methods.HttpPost) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) MultipartEntityBuilder(org.apache.http.entity.mime.MultipartEntityBuilder) HttpEntity(org.apache.http.HttpEntity) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpGet(org.apache.http.client.methods.HttpGet) StatusLine(org.apache.http.StatusLine) RealmService(org.wso2.carbon.user.core.service.RealmService) ImportExportAPI(org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) ImportExportAPI(org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI) API(org.wso2.carbon.apimgt.api.model.API) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) APIStore(org.wso2.carbon.apimgt.api.model.APIStore) Before(org.junit.Before)

Example 42 with APIManagerConfigurationService

use of org.wso2.carbon.apimgt.impl.APIManagerConfigurationService in project carbon-apimgt by wso2.

the class APIHandlerServiceComponent method setAPIManagerConfigurationService.

@Reference(name = "api.manager.config.service", service = org.wso2.carbon.apimgt.impl.APIManagerConfigurationService.class, cardinality = ReferenceCardinality.MANDATORY, policy = ReferencePolicy.DYNAMIC, unbind = "unsetAPIManagerConfigurationService")
protected void setAPIManagerConfigurationService(APIManagerConfigurationService amcService) {
    if (log.isDebugEnabled()) {
        log.debug("API manager configuration service bound to the API handlers");
    }
    ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(amcService);
    if (amcService.getAPIAnalyticsConfiguration().isAnalyticsEnabled()) {
        AnalyticsCommonConfiguration commonConfiguration = new AnalyticsCommonConfiguration(amcService.getAPIAnalyticsConfiguration().getReporterProperties());
        commonConfiguration.setResponseSchema(amcService.getAPIAnalyticsConfiguration().getResponseSchemaName());
        commonConfiguration.setFaultSchema(amcService.getAPIAnalyticsConfiguration().getFaultSchemaName());
        AnalyticsServiceReferenceHolder.getInstance().setConfigurations(commonConfiguration);
    }
}
Also used : AnalyticsCommonConfiguration(org.wso2.carbon.apimgt.common.analytics.AnalyticsCommonConfiguration) Reference(org.osgi.service.component.annotations.Reference)

Example 43 with APIManagerConfigurationService

use of org.wso2.carbon.apimgt.impl.APIManagerConfigurationService in project carbon-apimgt by wso2.

the class RestAPIStoreUtilsTest method mockStaticInitializer.

@BeforeClass
public static void mockStaticInitializer() {
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
    Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
    APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
    Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
    Mockito.when(apiManagerConfiguration.getFirstProperty(Mockito.anyString())).thenReturn("true");
    mocklog = Mockito.mock(Log.class);
    PowerMockito.mockStatic(LogFactory.class);
    Mockito.when(LogFactory.getLog(Mockito.any(Class.class))).thenReturn(mocklog);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) Log(org.apache.commons.logging.Log) BeforeClass(org.junit.BeforeClass) BeforeClass(org.junit.BeforeClass)

Example 44 with APIManagerConfigurationService

use of org.wso2.carbon.apimgt.impl.APIManagerConfigurationService in project carbon-apimgt by wso2.

the class RestAPIStoreUtilsTest method testIsUserOwnerOfApplicationlowerCase.

@Test
public void testIsUserOwnerOfApplicationlowerCase() {
    String username = "William Black";
    String lowerCaseUsername = "william black";
    PowerMockito.mockStatic(RestApiCommonUtil.class);
    Mockito.when(RestApiCommonUtil.getLoggedInUsername()).thenReturn(username);
    PowerMockito.mockStatic(Application.class);
    Application mockApplication = Mockito.mock(Application.class);
    Subscriber subscriber = Mockito.mock(Subscriber.class);
    Mockito.when(mockApplication.getSubscriber()).thenReturn(subscriber);
    Mockito.when(subscriber.getName()).thenReturn(lowerCaseUsername);
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
    Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
    APIManagerConfiguration configuration = Mockito.mock(APIManagerConfiguration.class);
    Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(configuration);
    Mockito.when(configuration.getFirstProperty(APIConstants.API_STORE_FORCE_CI_COMPARISIONS)).thenReturn("true");
    Assert.assertEquals(true, RestAPIStoreUtils.isUserOwnerOfApplication(mockApplication));
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) Application(org.wso2.carbon.apimgt.api.model.Application) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 45 with APIManagerConfigurationService

use of org.wso2.carbon.apimgt.impl.APIManagerConfigurationService in project carbon-apimgt by wso2.

the class WebSubConfigContextTest method testWithSecretConfigContextForAPI.

@Test
public void testWithSecretConfigContextForAPI() 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(true, "9207975e1fef9c41fab41645f81dbf0f", "SHA1", "x-hub-signature");
    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.assertTrue("The websub velocity template is not updated correctly", updatedTemplate.contains("generated_signature"));
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) APIManagerConfigurationServiceImpl(org.wso2.carbon.apimgt.impl.APIManagerConfigurationServiceImpl) Environment(org.wso2.carbon.apimgt.api.model.Environment) API(org.wso2.carbon.apimgt.api.model.API) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) WebsubSubscriptionConfiguration(org.wso2.carbon.apimgt.api.model.WebsubSubscriptionConfiguration) APITemplateBuilderImpl(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APITemplateBuilderImpl) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)58 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)55 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)49 APIManagerConfigurationService (org.wso2.carbon.apimgt.impl.APIManagerConfigurationService)39 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)33 RealmService (org.wso2.carbon.user.core.service.RealmService)24 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)22 TenantManager (org.wso2.carbon.user.core.tenant.TenantManager)21 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)20 ThrottleProperties (org.wso2.carbon.apimgt.impl.dto.ThrottleProperties)18 API (org.wso2.carbon.apimgt.api.model.API)17 HashMap (java.util.HashMap)16 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)15 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)15 ArrayList (java.util.ArrayList)14 Registry (org.wso2.carbon.registry.core.Registry)14 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)13 Resource (org.wso2.carbon.registry.core.Resource)13 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)12 Before (org.junit.Before)11