Search in sources :

Example 16 with ConfigurationException

use of org.wso2.carbon.config.ConfigurationException in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method init.

@BeforeClass
void init() {
    File temp = Files.createTempDir();
    temp.deleteOnExit();
    System.setProperty("gwHome", temp.getAbsolutePath());
    // Set the resource path, where contain composer test JS
    System.setProperty("carbon.home", new File("src/test/resources").getAbsolutePath());
    WorkflowExtensionsConfigBuilder.build(new ConfigProvider() {

        @Override
        public <T> T getConfigurationObject(Class<T> configClass) throws ConfigurationException {
            T workflowConfig = (T) new WorkflowConfig();
            return workflowConfig;
        }

        @Override
        public Object getConfigurationObject(String s) throws ConfigurationException {
            return null;
        }

        public <T> T getConfigurationObject(String s, Class<T> aClass) throws ConfigurationException {
            return null;
        }
    });
}
Also used : WorkflowConfig(org.wso2.carbon.apimgt.core.models.WorkflowConfig) ConfigProvider(org.wso2.carbon.config.provider.ConfigProvider) ConfigurationException(org.wso2.carbon.config.ConfigurationException) File(java.io.File) BeforeClass(org.testng.annotations.BeforeClass)

Example 17 with ConfigurationException

use of org.wso2.carbon.config.ConfigurationException in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method setup.

@BeforeTest
public void setup() throws Exception {
    WorkflowExtensionsConfigBuilder.build(new ConfigProvider() {

        @Override
        public <T> T getConfigurationObject(Class<T> configClass) throws ConfigurationException {
            T workflowConfig = (T) new WorkflowConfig();
            return workflowConfig;
        }

        @Override
        public Object getConfigurationObject(String s) throws ConfigurationException {
            return null;
        }

        public <T> T getConfigurationObject(String s, Class<T> aClass) throws ConfigurationException {
            return null;
        }
    });
    ConfigProvider configProvider = Mockito.mock(ConfigProvider.class);
    ServiceReferenceHolder.getInstance().setConfigProvider(configProvider);
}
Also used : WorkflowConfig(org.wso2.carbon.apimgt.core.models.WorkflowConfig) ConfigProvider(org.wso2.carbon.config.provider.ConfigProvider) ConfigurationException(org.wso2.carbon.config.ConfigurationException) BeforeTest(org.testng.annotations.BeforeTest)

Example 18 with ConfigurationException

use of org.wso2.carbon.config.ConfigurationException in project carbon-apimgt by wso2.

the class ServiceReferenceHolderTestCase method testGetAPIMAppConfiguration.

@Test
public void testGetAPIMAppConfiguration() throws ConfigurationException {
    // // Happy Path
    ServiceReferenceHolder instance = ServiceReferenceHolder.getInstance();
    ConfigProvider configProvider = Mockito.mock(ConfigProvider.class);
    instance.setConfigProvider(configProvider);
    APIMAppConfigurations expectedConfigs = new APIMAppConfigurations();
    expectedConfigs.setApimBaseUrl("https://localhost:9443/");
    Mockito.when(configProvider.getConfigurationObject(Mockito.any(Class.class))).thenReturn(expectedConfigs);
    APIMAppConfigurations actualConfigs = instance.getAPIMAppConfiguration();
    Assert.assertNotNull(actualConfigs);
    Assert.assertEquals(expectedConfigs.getApimBaseUrl(), actualConfigs.getApimBaseUrl());
    // // Error path
    // // ConfigurationException
    Mockito.when(configProvider.getConfigurationObject(Mockito.any(Class.class))).thenThrow(ConfigurationException.class);
    actualConfigs = instance.getAPIMAppConfiguration();
    Assert.assertNotNull(actualConfigs);
    // // config provider is null
    instance.setConfigProvider(null);
    actualConfigs = instance.getAPIMAppConfiguration();
    Assert.assertNotNull(actualConfigs);
}
Also used : ConfigProvider(org.wso2.carbon.config.provider.ConfigProvider) APIMAppConfigurations(org.wso2.carbon.apimgt.rest.api.authenticator.configuration.models.APIMAppConfigurations) Test(org.junit.Test)

Example 19 with ConfigurationException

use of org.wso2.carbon.config.ConfigurationException in project carbon-business-process by wso2.

the class AnalyticsPublisherExtensionOperation method evaluateXPathExpression.

private String evaluateXPathExpression(ExtensionContext context, String xpath, Element element) throws FaultException {
    String result = "";
    QName qnVariableData = new QName(Namespaces.BPEL11_NS, "getVariableData");
    QName qnGetVariableProperty = new QName(Namespaces.BPEL11_NS, "getVariableProperty");
    QName qnGetLinkStatus = new QName(Namespaces.BPEL11_NS, "getLinkStatus");
    QName qnDoXslTransform = new QName(Namespaces.BPEL11_NS, "getDoXslTransform");
    OXPath20ExpressionBPEL20 oexpr = new OXPath20ExpressionBPEL20(context.getInternalInstance().getProcessModel().getOwner(), qnVariableData, qnGetVariableProperty, qnGetLinkStatus, qnDoXslTransform, false);
    OExpressionLanguage oExpressionLanguage = new OExpressionLanguage(context.getProcessModel().getOwner(), null);
    oExpressionLanguage.expressionLanguageUri = "urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0";
    oexpr.expressionLanguage = oExpressionLanguage;
    oExpressionLanguage.properties.put("runtime-class", "org.apache.ode.bpel.elang.xpath20.runtime.XPath20ExpressionRuntime");
    try {
        context.getInternalInstance().getExpLangRuntime().registerRuntime(oExpressionLanguage);
    } catch (ConfigurationException ex) {
        String errMsg = "Error when trying to register xpath runtime";
        log.error(errMsg, ex);
        handleException(errMsg, ex);
    }
    oexpr.insertMissingData = true;
    ScopeFrame scopeFrame = ((ExtensionContextImpl) context).getScopeFrame();
    ExprEvaluationContextImpl exprEvaluationContext = new ExprEvaluationContextImpl(scopeFrame, context.getInternalInstance());
    oexpr.vars = (HashMap) context.getVisibleVariables();
    oexpr.namespaceCtx = context.getProcessModel().namespaceContext;
    try {
        oexpr.xpath = xpath;
        List resultList = context.getInternalInstance().getExpLangRuntime().evaluate(oexpr, exprEvaluationContext);
        if (result != null) {
            Iterator iterator = resultList.iterator();
            /**
             * for analytics publishing to work, there should only be a single node here
             */
            while (iterator.hasNext()) {
                Node node = ((Node) iterator.next());
                if (node.getNodeType() == Node.ELEMENT_NODE) {
                    result += node.getTextContent();
                } else if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
                    result += node.getNodeValue();
                }
            }
        }
    } catch (EvaluationException e) {
        String errMsg = "Xpath evaluation failed";
        log.error(errMsg);
        handleException(errMsg, e);
    }
    return result;
}
Also used : DataEndpointConfigurationException(org.wso2.carbon.databridge.agent.exception.DataEndpointConfigurationException) ConfigurationException(org.apache.ode.bpel.explang.ConfigurationException) DataEndpointAgentConfigurationException(org.wso2.carbon.databridge.agent.exception.DataEndpointAgentConfigurationException) ScopeFrame(org.apache.ode.bpel.runtime.ScopeFrame) QName(javax.xml.namespace.QName) OXPath20ExpressionBPEL20(org.apache.ode.bpel.elang.xpath20.o.OXPath20ExpressionBPEL20) Node(org.w3c.dom.Node) Iterator(java.util.Iterator) ExtensionContextImpl(org.apache.ode.bpel.runtime.ExtensionContextImpl) NodeList(org.w3c.dom.NodeList) List(java.util.List) EvaluationException(org.apache.ode.bpel.explang.EvaluationException) ExprEvaluationContextImpl(org.apache.ode.bpel.runtime.ExprEvaluationContextImpl) OExpressionLanguage(org.apache.ode.bpel.o.OExpressionLanguage)

Aggregations

ConfigProvider (org.wso2.carbon.config.provider.ConfigProvider)12 ConfigurationException (org.wso2.carbon.config.ConfigurationException)9 Test (org.junit.Test)5 HashMap (java.util.HashMap)3 Test (org.testng.annotations.Test)3 WorkflowConfig (org.wso2.carbon.apimgt.core.models.WorkflowConfig)3 Feature (org.wso2.carbon.apimgt.rest.api.configurations.models.Feature)3 Path (java.nio.file.Path)2 Map (java.util.Map)2 BeforeTest (org.testng.annotations.BeforeTest)2 BrokerConfigProvider (org.wso2.broker.common.BrokerConfigProvider)2 ContainerBasedGatewayConfiguration (org.wso2.carbon.apimgt.core.configuration.models.ContainerBasedGatewayConfiguration)2 APIMAppConfigurations (org.wso2.carbon.apimgt.rest.api.authenticator.configuration.models.APIMAppConfigurations)2 APIMUIConfigurations (org.wso2.carbon.apimgt.rest.api.configurations.models.APIMUIConfigurations)2 File (java.io.File)1 Iterator (java.util.Iterator)1 List (java.util.List)1 QName (javax.xml.namespace.QName)1 OXPath20ExpressionBPEL20 (org.apache.ode.bpel.elang.xpath20.o.OXPath20ExpressionBPEL20)1 ConfigurationException (org.apache.ode.bpel.explang.ConfigurationException)1