Search in sources :

Example 16 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.

the class AuthenticatorAPIFactory method getService.

/**
 * Get an instance of AuthenticatorService
 *
 * @return AuthenticatorService
 * @throws APIMgtDAOException     if failed to initialize SystemApplicationDao
 * @throws IdentityProviderException if failed to initialize IdentityProvider
 */
public synchronized AuthenticatorService getService() throws APIMgtDAOException, IdentityProviderException {
    if (service == null) {
        IdentityProvider identityProvider = APIManagerFactory.getInstance().getIdentityProvider();
        SystemApplicationDao systemApplicationDao = DAOFactory.getSystemApplicationDao();
        APIMConfigurationService apimConfigurationService = APIMConfigurationService.getInstance();
        APIMAppConfigurationService apimAppConfigurationService = APIMAppConfigurationService.getInstance();
        service = new AuthenticatorService(identityProvider, systemApplicationDao, apimConfigurationService, apimAppConfigurationService);
    }
    return service;
}
Also used : AuthenticatorService(org.wso2.carbon.apimgt.rest.api.authenticator.AuthenticatorService) SystemApplicationDao(org.wso2.carbon.apimgt.core.dao.SystemApplicationDao) IdentityProvider(org.wso2.carbon.apimgt.core.api.IdentityProvider) APIMAppConfigurationService(org.wso2.carbon.apimgt.rest.api.authenticator.configuration.APIMAppConfigurationService) APIMConfigurationService(org.wso2.carbon.apimgt.core.configuration.APIMConfigurationService)

Example 17 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.

the class ServiceReferenceHolderTestCase method testGetRestAPIConfigurationMap.

@Test
public void testGetRestAPIConfigurationMap() throws ConfigurationException {
    // // Happy Path
    ServiceReferenceHolder instance = ServiceReferenceHolder.getInstance();
    ConfigProvider configProvider = Mockito.mock(ConfigProvider.class);
    instance.setConfigProvider(configProvider);
    Map<String, String> expectedConfigMap = new HashMap<>();
    expectedConfigMap.put("apimBaseUrl", "https://localhost:9443/");
    Mockito.when(configProvider.getConfigurationObject("xxx-namespace-xxx")).thenReturn(expectedConfigMap);
    Map<String, String> actualConfigMap = instance.getRestAPIConfigurationMap("xxx-namespace-xxx");
    Assert.assertEquals(expectedConfigMap, actualConfigMap);
    // // Error path
    // // ConfigurationException
    Mockito.when(configProvider.getConfigurationObject("xxx-namespace-xxx")).thenThrow(ConfigurationException.class);
    actualConfigMap = instance.getRestAPIConfigurationMap("xxx-namespace-xxx");
    Assert.assertNull(actualConfigMap);
    // // config provider is null
    instance.setConfigProvider(null);
    actualConfigMap = instance.getRestAPIConfigurationMap("xxx-namespace-xxx");
    Assert.assertNull(actualConfigMap);
}
Also used : ConfigProvider(org.wso2.carbon.config.provider.ConfigProvider) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 18 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.

the class AnalyzerHolder method getAnalyzer.

/**
 * Borrows an object from pools (xml or json) for threat analysis
 *
 * @param contentType Content-Type of the payload
 * @param policyId ID of the API
 * @return Instance of APIMThreatAnalyzer based on content type
 */
public static APIMThreatAnalyzer getAnalyzer(String contentType, String policyId) {
    APIMThreatAnalyzer analyzer = null;
    if (T_TEXT_XML.equalsIgnoreCase(contentType) || T_APPLICATION_XML.equalsIgnoreCase(contentType)) {
        try {
            analyzer = xmlAnalyzerAnalyzerPool.borrowObject();
            // configure per api
            XMLConfig xmlConfig = ConfigurationHolder.getXmlConfig(policyId);
            if (xmlConfig == null) {
                xmlConfig = ConfigurationHolder.getXmlConfig("GLOBAL-XML");
            }
            if (xmlConfig == null) {
                return null;
            }
            analyzer.configure(xmlConfig);
        } catch (Exception e) {
            logger.error("Threat Protection: Failed to create XMLAnalyzer, " + e.getMessage());
        }
    } else if (T_TEXT_JSON.equalsIgnoreCase(contentType) || T_APPLICATION_JSON.equalsIgnoreCase(contentType)) {
        try {
            analyzer = jsonAnalyzerAnalyzerPool.borrowObject();
            // configure per api
            JSONConfig jsonConfig = ConfigurationHolder.getJsonConfig(policyId);
            if (jsonConfig == null) {
                jsonConfig = ConfigurationHolder.getJsonConfig("GLOBAL-JSON");
            }
            if (jsonConfig == null) {
                return null;
            }
            analyzer.configure(jsonConfig);
        } catch (Exception e) {
            logger.error("Threat Protection: Failed to create JSONAnalyzer, " + e.getMessage());
        }
    }
    return analyzer;
}
Also used : XMLConfig(org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.XMLConfig) JSONConfig(org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.JSONConfig) APIMThreatAnalyzer(org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.APIMThreatAnalyzer)

Example 19 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.

the class ApiStoreSdkGenerationManagerTestCase method testGenerateSdkForApi.

@Test
public void testGenerateSdkForApi() throws APIManagementException, ApiStoreSdkGenerationException {
    String apiId = UUID.randomUUID().toString();
    APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
    PowerMockito.mockStatic(APIManagerFactory.class);
    PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
    APIStore apiStore = Mockito.mock(APIStoreImpl.class);
    Mockito.when(instance.getAPIConsumer(USER)).thenReturn(apiStore);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    Mockito.when(apiStore.getAPIbyUUID(apiId)).thenReturn(api);
    Mockito.when(apiStore.getApiSwaggerDefinition(apiId)).thenReturn(swaggerPetStore);
    ApiStoreSdkGenerationManager sdkGenerationManager = new ApiStoreSdkGenerationManager();
    String pathToZip = sdkGenerationManager.generateSdkForApi(apiId, LANGUAGE, USER);
    File sdkZipFile = new File(pathToZip);
    Assert.assertTrue(sdkZipFile.exists() && sdkZipFile.length() > MIN_SDK_SIZE);
}
Also used : API(org.wso2.carbon.apimgt.core.models.API) File(java.io.File) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 20 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.

the class ApiStoreSdkGenerationManagerTestCase method testGenerateSdkForApiIncorrectSwagger.

@Test(expected = NullPointerException.class)
public void testGenerateSdkForApiIncorrectSwagger() throws APIManagementException, ApiStoreSdkGenerationException {
    String apiId = UUID.randomUUID().toString();
    APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
    PowerMockito.mockStatic(APIManagerFactory.class);
    PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
    APIStore apiStore = Mockito.mock(APIStoreImpl.class);
    Mockito.when(instance.getAPIConsumer(USER)).thenReturn(apiStore);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    Mockito.when(apiStore.getAPIbyUUID(apiId)).thenReturn(api);
    Mockito.when(apiStore.getApiSwaggerDefinition(apiId)).thenReturn(null);
    ApiStoreSdkGenerationManager sdkGenerationManager = new ApiStoreSdkGenerationManager();
    sdkGenerationManager.generateSdkForApi(apiId, LANGUAGE, USER);
}
Also used : API(org.wso2.carbon.apimgt.core.models.API) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ArrayList (java.util.ArrayList)28 Test (org.junit.Test)23 Response (javax.ws.rs.core.Response)22 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)21 APIManagerFactory (org.wso2.carbon.apimgt.core.impl.APIManagerFactory)20 HashMap (java.util.HashMap)15 Path (javax.ws.rs.Path)15 RuntimeService (org.activiti.engine.RuntimeService)15 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)15 InstanceManagementException (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException)14 Produces (javax.ws.rs.Produces)13 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)13 IOException (java.io.IOException)12 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)12 GET (javax.ws.rs.GET)11 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)11 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)10 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)9 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8