Search in sources :

Example 6 with ConfigurationContextService

use of org.wso2.carbon.utils.ConfigurationContextService in project carbon-apimgt by wso2.

the class TestUtils method getServiceReferenceHolder.

public static ServiceReferenceHolder getServiceReferenceHolder() throws XMLStreamException {
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    ServiceReferenceHolder sh = PowerMockito.mock(ServiceReferenceHolder.class);
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(sh);
    ConfigurationContextService configurationContextService = initConfigurationContextService(false);
    PowerMockito.when(ServiceReferenceHolder.getContextService()).thenReturn(configurationContextService);
    return sh;
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) ConfigurationContextService(org.wso2.carbon.utils.ConfigurationContextService)

Example 7 with ConfigurationContextService

use of org.wso2.carbon.utils.ConfigurationContextService in project carbon-apimgt by wso2.

the class ServiceReferenceHolderTestCase method testServiceReferenceHolder.

@Test
public void testServiceReferenceHolder() {
    ServiceReferenceHolder serviceReferenceHolder = ServiceReferenceHolder.getInstance();
    Assert.assertTrue(serviceReferenceHolder instanceof ServiceReferenceHolder);
    serviceReferenceHolder.getThrottleDataHolder();
    ThrottleDataHolder throttleDataHolder = Mockito.mock(ThrottleDataHolder.class);
    serviceReferenceHolder.setThrottleDataHolder(throttleDataHolder);
    ConfigurationContextService cfgCtxService = Mockito.mock(ConfigurationContextService.class);
    serviceReferenceHolder.setConfigurationContextService(cfgCtxService);
    cfgCtxService = serviceReferenceHolder.getConfigurationContextService();
    Assert.assertNotNull(cfgCtxService);
    APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
    serviceReferenceHolder.setAPIManagerConfigurationService(apiManagerConfigurationService);
    apiManagerConfigurationService = serviceReferenceHolder.getApiManagerConfigurationService();
    Assert.assertNotNull(apiManagerConfigurationService);
    Assert.assertNull(serviceReferenceHolder.getAPIManagerConfiguration());
    Assert.assertNull(serviceReferenceHolder.getServerConfigurationContext());
    ThrottleProperties throttleProperties = Mockito.mock(ThrottleProperties.class);
    serviceReferenceHolder.setThrottleProperties(throttleProperties);
    Assert.assertNotNull(serviceReferenceHolder.getThrottleProperties());
}
Also used : ThrottleDataHolder(org.wso2.carbon.apimgt.gateway.throttling.ThrottleDataHolder) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) ConfigurationContextService(org.wso2.carbon.utils.ConfigurationContextService) ThrottleProperties(org.wso2.carbon.apimgt.impl.dto.ThrottleProperties) Test(org.junit.Test)

Example 8 with ConfigurationContextService

use of org.wso2.carbon.utils.ConfigurationContextService in project carbon-apimgt by wso2.

the class ApplicationRegistrationWSWorkflowExecutorTest method init.

@Before
public void init() throws Exception {
    ServiceReferenceHolder serviceReferenceHolder = TestUtils.getServiceReferenceHolder();
    ConfigurationContextService configurationContextService = Mockito.mock(ConfigurationContextService.class);
    configurationContext = Mockito.mock(ConfigurationContext.class);
    PowerMockito.when(serviceReferenceHolder.getContextService()).thenReturn(configurationContextService);
    PowerMockito.when(configurationContextService.getClientConfigContext()).thenReturn(configurationContext);
    serviceClient = Mockito.mock(ServiceClient.class);
    PowerMockito.whenNew(ServiceClient.class).withAnyArguments().thenReturn(serviceClient);
    applicationRegistrationWSWorkflowExecutor = new ApplicationRegistrationWSWorkflowExecutor();
    apiMgtDAO = TestUtils.getApiMgtDAO();
    application = new Application("test", new Subscriber("testUser"));
    application.setCallbackUrl(callBaclURL);
    application.setTier("Unlimited");
    PowerMockito.mockStatic(KeyManagerHolder.class);
    keyManager = Mockito.mock(KeyManager.class);
    KeyManagerConfiguration keyManagerConfiguration = new KeyManagerConfiguration();
    Mockito.when(keyManager.getKeyManagerConfiguration()).thenReturn(keyManagerConfiguration);
    PowerMockito.when(KeyManagerHolder.getKeyManagerInstance("carbon.super", "default")).thenReturn(keyManager);
    OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo();
    PowerMockito.when(keyManager.createApplication((OAuthAppRequest) Mockito.anyObject())).thenReturn(oAuthApplicationInfo);
    OAuthAppRequest oAuthAppRequest = new OAuthAppRequest();
    oAuthAppRequest.setOAuthApplicationInfo(oAuthApplicationInfo);
    workflowDTO = new ApplicationRegistrationWorkflowDTO();
    workflowDTO.setWorkflowReference("1");
    workflowDTO.setApplication(application);
    workflowDTO.setCallbackUrl(callBaclURL);
    workflowDTO.setTenantDomain("carbon.super");
    workflowDTO.setUserName("testUser");
    workflowDTO.setExternalWorkflowReference("testUser");
    workflowDTO.setKeyType("PRODUCTION");
    workflowDTO.setAppInfoDTO(oAuthAppRequest);
    KeyManagerConfigurationDTO kmConfigDTO = new KeyManagerConfigurationDTO();
    kmConfigDTO.setOrganization("carbon.super");
    kmConfigDTO.setName("default");
    PowerMockito.when(apiMgtDAO.getKeyManagerConfigurationByUUID("default")).thenReturn(kmConfigDTO);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) ApplicationRegistrationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO) ConfigurationContextService(org.wso2.carbon.utils.ConfigurationContextService) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) OAuthAppRequest(org.wso2.carbon.apimgt.api.model.OAuthAppRequest) ServiceClient(org.apache.axis2.client.ServiceClient) OAuthApplicationInfo(org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo) Application(org.wso2.carbon.apimgt.api.model.Application) KeyManager(org.wso2.carbon.apimgt.api.model.KeyManager) KeyManagerConfiguration(org.wso2.carbon.apimgt.api.model.KeyManagerConfiguration) Before(org.junit.Before)

Example 9 with ConfigurationContextService

use of org.wso2.carbon.utils.ConfigurationContextService in project carbon-apimgt by wso2.

the class UserSignUpWSWorkflowExecutorTest method init.

@Before
public void init() throws Exception {
    ServiceReferenceHolder serviceReferenceHolder = TestUtils.getServiceReferenceHolder();
    ConfigurationContextService configurationContextService = Mockito.mock(ConfigurationContextService.class);
    ConfigurationContext configurationContext = Mockito.mock(ConfigurationContext.class);
    RealmService realmService = Mockito.mock(RealmService.class);
    UserRealm userRealm = Mockito.mock(UserRealm.class);
    userStoreManager = Mockito.mock(UserStoreManager.class);
    TenantManager tenantManager = Mockito.mock(TenantManager.class);
    apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
    serviceClient = Mockito.mock(ServiceClient.class);
    APIManagerConfigurationService apiManagerConfigurationService = new APIManagerConfigurationServiceImpl(apiManagerConfiguration);
    PowerMockito.mockStatic(SelfSignUpUtil.class);
    PowerMockito.mockStatic(CarbonUtils.class);
    PowerMockito.mockStatic(APIUtil.class);
    PowerMockito.when(APIUtil.isAnalyticsEnabled()).thenReturn(true);
    PowerMockito.doNothing().when(CarbonUtils.class, "setBasicAccessSecurityHeaders", Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.any());
    PowerMockito.when(serviceReferenceHolder.getContextService()).thenReturn(configurationContextService);
    PowerMockito.when(configurationContextService.getClientConfigContext()).thenReturn(configurationContext);
    PowerMockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
    PowerMockito.whenNew(ServiceClient.class).withAnyArguments().thenReturn(serviceClient);
    Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
    Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
    Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(tenantID);
    Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(tenantID);
    Mockito.when(realmService.getTenantUserRealm(tenantID)).thenReturn(userRealm);
    Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
    apiMgtDAO = TestUtils.getApiMgtDAO();
    userSignUpWSWorkflowExecutor = new UserSignUpWSWorkflowExecutor();
    workflowDTO = new WorkflowDTO();
    workflowDTO.setCallbackUrl(callBackURL);
    workflowDTO.setTenantDomain(tenantDomain);
    workflowDTO.setExternalWorkflowReference(externalWFReference);
    workflowDTO.setWorkflowReference(testUsername + "@carbon.super");
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) ConfigurationContextService(org.wso2.carbon.utils.ConfigurationContextService) UserRealm(org.wso2.carbon.user.core.UserRealm) APIManagerConfigurationServiceImpl(org.wso2.carbon.apimgt.impl.APIManagerConfigurationServiceImpl) RealmService(org.wso2.carbon.user.core.service.RealmService) ServiceClient(org.apache.axis2.client.ServiceClient) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) Before(org.junit.Before)

Aggregations

ConfigurationContextService (org.wso2.carbon.utils.ConfigurationContextService)9 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)5 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)4 Before (org.junit.Before)3 ServiceClient (org.apache.axis2.client.ServiceClient)2 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)2 Test (org.junit.Test)2 APIManagerConfigurationService (org.wso2.carbon.apimgt.impl.APIManagerConfigurationService)2 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)2 RealmService (org.wso2.carbon.user.core.service.RealmService)2 TenantManager (org.wso2.carbon.user.core.tenant.TenantManager)2 ClusteringAgent (org.apache.axis2.clustering.ClusteringAgent)1 Parameter (org.apache.axis2.description.Parameter)1 TransportInDescription (org.apache.axis2.description.TransportInDescription)1 TransportOutDescription (org.apache.axis2.description.TransportOutDescription)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 KeyManagerConfigurationDTO (org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO)1 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)1 Application (org.wso2.carbon.apimgt.api.model.Application)1 KeyManager (org.wso2.carbon.apimgt.api.model.KeyManager)1