Search in sources :

Example 1 with ConfigurationContextFactory

use of org.apache.axis2.context.ConfigurationContextFactory in project carbon-apimgt by wso2.

the class CEPPolicyManagementServiceClientTest method testShouldInitializeServiceClient.

@Test
public void testShouldInitializeServiceClient() throws AxisFault {
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    PowerMockito.mockStatic(ConfigurationContextFactory.class);
    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    APIManagerConfiguration config = Mockito.mock(APIManagerConfiguration.class);
    APIManagerConfigurationService configService = Mockito.mock(APIManagerConfigurationService.class);
    ConfigurationContextFactory configFactory = Mockito.mock(ConfigurationContextFactory.class);
    ConfigurationContext configurationContext = Mockito.mock(ConfigurationContext.class);
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(configService);
    Mockito.when(configService.getAPIManagerConfiguration()).thenReturn(config);
    Mockito.when(config.getFirstProperty(Mockito.anyString())).thenReturn("").thenReturn(USER_NAME).thenReturn("").thenReturn(USER_NAME).thenReturn(null).thenReturn(USER_NAME);
    Mockito.when(configFactory.createConfigurationContextFromFileSystem(null, null)).thenReturn(configurationContext).thenThrow(AxisFault.class).thenReturn(configurationContext);
    try {
        new CEPPolicyManagementServiceClient();
    } catch (APIManagementException e) {
        Assert.fail("Should not throw an exception");
    }
    try {
        // should throw exception this time
        new CEPPolicyManagementServiceClient();
        Assert.fail("Should throw an exception");
    } catch (APIManagementException e) {
    }
    try {
        // should throw exception this time
        new CEPPolicyManagementServiceClient();
        Assert.fail("Should throw an exception");
    } catch (APIManagementException e) {
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ConfigurationContextFactory(org.apache.axis2.context.ConfigurationContextFactory) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

AxisFault (org.apache.axis2.AxisFault)1 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)1 ConfigurationContextFactory (org.apache.axis2.context.ConfigurationContextFactory)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)1 APIManagerConfigurationService (org.wso2.carbon.apimgt.impl.APIManagerConfigurationService)1 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)1