⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bpeltestabstract.java

📁 bpel执行引擎用来执行bpel业务流程
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements.  See the NOTICE file * distributed with this work for additional information * regarding copyright ownership.  The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License.  You may obtain a copy of the License at * *    http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied.  See the License for the * specific language governing permissions and limitations * under the License. */package org.apache.ode.test;import org.apache.ode.bpel.common.evt.DebugBpelEventListener;import org.apache.ode.bpel.dao.BpelDAOConnectionFactory;import org.apache.ode.bpel.engine.BpelServerImpl;import org.apache.ode.bpel.iapi.Message;import org.apache.ode.bpel.iapi.MessageExchange;import org.apache.ode.bpel.iapi.MessageExchange.Status;import org.apache.ode.bpel.iapi.MyRoleMessageExchange;import org.apache.ode.bpel.iapi.MyRoleMessageExchange.CorrelationStatus;import org.apache.ode.bpel.iapi.ProcessStore;import org.apache.ode.bpel.iapi.ProcessStoreEvent;import org.apache.ode.bpel.iapi.ProcessStoreListener;import org.apache.ode.bpel.memdao.BpelDAOConnectionFactoryImpl;import org.apache.ode.dao.jpa.BPELDAOConnectionFactoryImpl;import org.apache.ode.il.MockScheduler;import org.apache.ode.il.config.OdeConfigProperties;import org.apache.ode.store.ProcessConfImpl;import org.apache.ode.store.ProcessStoreImpl;import org.apache.ode.utils.DOMUtils;import org.apache.ode.utils.GUID;import org.junit.After;import org.junit.Assert;import org.junit.Before;import org.w3c.dom.Element;import javax.persistence.EntityManager;import javax.persistence.EntityManagerFactory;import javax.persistence.Persistence;import javax.xml.namespace.QName;import java.io.File;import java.io.FileInputStream;import java.io.InputStream;import java.net.URISyntaxException;import java.net.URL;import java.util.ArrayList;import java.util.Collection;import java.util.List;import java.util.Properties;import java.util.concurrent.CopyOnWriteArrayList;import java.util.concurrent.Future;import java.util.concurrent.TimeUnit;import java.util.regex.Matcher;import java.util.regex.Pattern;public abstract class BPELTestAbstract {	private static final String SHOW_EVENTS_ON_CONSOLE = "no";    protected BpelServerImpl _server;    protected ProcessStore store;    protected MessageExchangeContextImpl mexContext;    protected EntityManager em;    protected EntityManagerFactory emf;    protected MockScheduler scheduler;    protected BpelDAOConnectionFactory _cf;    /** Failures that have been detected. */    protected List<Failure> _failures;    /** The things we'd like to deploy. */    protected List<Deployment> _deployments;    /** The things we'd like to invoke. */    protected List<Invocation> _invocations;    /** What's actually been deployed. */    private List<Deployment> _deployed;    @Before    public void setUp() throws Exception {        _failures = new CopyOnWriteArrayList<Failure>();        _server = new BpelServerImpl();        mexContext = new MessageExchangeContextImpl();        _deployments = new ArrayList<Deployment>();        _invocations = new ArrayList<Invocation>();        _deployed = new ArrayList<Deployment>();        if (Boolean.getBoolean("org.apache.ode.test.persistent")) {            emf = Persistence.createEntityManagerFactory("ode-unit-test-embedded");            em = emf.createEntityManager();            _cf = new BPELDAOConnectionFactoryImpl();            _server.setDaoConnectionFactory(_cf);            scheduler = new MockScheduler() {                @Override                public void begin() {                    super.begin();                    em.getTransaction().begin();                }                @Override                public void commit() {                    super.commit();                    em.getTransaction().commit();                }                @Override                public void rollback() {                    super.rollback();                    em.getTransaction().rollback();                }            };        } else {            scheduler = new MockScheduler();            _cf = new BpelDAOConnectionFactoryImpl(scheduler);            _server.setDaoConnectionFactory(_cf);        }        _server.setInMemDaoConnectionFactory(new BpelDAOConnectionFactoryImpl(scheduler));        _server.setScheduler(scheduler);        _server.setBindingContext(new BindingContextImpl());        _server.setMessageExchangeContext(mexContext);        scheduler.setJobProcessor(_server);        store = new ProcessStoreImpl(null, null, "jpa", new OdeConfigProperties(new Properties(), ""), true);        store.registerListener(new ProcessStoreListener() {            public void onProcessStoreEvent(ProcessStoreEvent event) {                // bounce the process                _server.unregister(event.pid);                if (event.type != ProcessStoreEvent.Type.UNDEPLOYED) {                    ProcessConfImpl conf = (ProcessConfImpl) store.getProcessConfiguration(event.pid);                    // Test processes always run with in-mem DAOs                    conf.setTransient(true);                    _server.register(conf);                }            }        });        _server.setConfigProperties(getConfigProperties());        _server.registerBpelEventListener(new DebugBpelEventListener());        _server.init();        _server.start();    }    @After    public void tearDown() throws Exception {        for (Deployment d : _deployed) {            try {                store.undeploy(d.deployDir);            } catch (Exception ex) {                ex.printStackTrace();                System.err.println("Error undeploying " + d);            }        }        if (em != null) em.close();        if (emf != null) emf.close();        _server.stop();        _failures = null;        _deployed = null;        _deployments = null;        _invocations = null;    }    protected void negative(String deployDir) throws Throwable {        try {            go(new File(deployDir));        } catch (junit.framework.AssertionFailedError ex) {            return;        }        Assert.fail("Expecting test to fail");    }    protected void go(String deployDir) throws Exception {        go(makeDeployDir(deployDir));    }    protected Deployment addDeployment(String deployDir) {        return addDeployment(makeDeployDir(deployDir));    }    protected Deployment addDeployment(File deployDir) {        Deployment deployment = new Deployment(deployDir);        _deployments.add(deployment);        return deployment;    }    protected void go(File deployDir) throws Exception {        setup(deployDir);        go();    }    protected void setup(File deployDir) throws Exception {        addDeployment(deployDir);        int propsFileCnt = 0;        File testPropsFile = new File(deployDir, "test.properties");        if (!testPropsFile.exists()) {            propsFileCnt++;            testPropsFile = new File(deployDir, "test" + propsFileCnt + ".properties");            if (!testPropsFile.exists()) {                System.err.println("can't find " + testPropsFile);            }        }        if (!testPropsFile.exists()) {            Assert.fail("Test property file not found in " + deployDir);        }        while (testPropsFile.exists()) {            Properties testProps = new Properties();            InputStream is = new FileInputStream(testPropsFile);            try {                testProps.load(is);            } finally {                is.close();            }            final QName serviceId = new QName(testProps.getProperty("namespace"), testProps.getProperty("service"));            final String operation = testProps.getProperty("operation");            for (int i = 1; testProps.getProperty("request" + i) != null; i++) {                final String in = testProps.getProperty("request" + i);                final String responsePattern = testProps.getProperty("response" + i);                addInvoke(testPropsFile + "#" + i, serviceId, operation, in, responsePattern);            }            propsFileCnt++;            testPropsFile = new File(deployDir, "test" + propsFileCnt + ".properties");        }    }    protected Invocation addInvoke(String id, QName target, String operation, String request, String responsePattern) throws Exception {        Invocation inv = new Invocation(id);        inv.target = target;        inv.operation = operation;        inv.request = DOMUtils.stringToDOM(request);        inv.expectedStatus = null;        if (responsePattern != null) {            inv.expectedFinalStatus = MessageExchange.Status.RESPONSE;            inv.expectedResponsePattern = Pattern.compile(responsePattern, Pattern.DOTALL);        }        _invocations.add(inv);        return inv;    }    protected void go() throws Exception {        try {            doDeployments();            doInvokes();        } finally {            checkFailure();        }    }    protected void checkFailure() {        StringBuffer sb = new StringBuffer("Failure report:\n");        for (Failure failure : _failures) {            sb.append(failure);            sb.append('\n');        }        if (_failures.size() != 0) {            System.err.println(sb.toString());            Assert.fail(sb.toString());        }    }    protected Deployment deploy(String location) {        Deployment deployment = new Deployment(makeDeployDir(location));        doDeployment(deployment);        return deployment;    }    protected void doDeployments() {        for (Deployment d : _deployments)            doDeployment(d);    }    /**     * Do all the registered deployments.     *     * @param d     */    protected void doDeployment(Deployment d) {        Collection<QName> procs;        try {            procs = store.deploy(d.deployDir);            _deployed.add(d);        } catch (Exception ex) {            if (d.expectedException == null) {                ex.printStackTrace();                failure(d, "DEPLOY: Unexpected exception: " + ex, ex);            } else if (!d.expectedException.isAssignableFrom(ex.getClass())) {                ex.printStackTrace();                failure(d, "DEPLOY: Wrong exception; expected " + d.expectedException + " but got " + ex.getClass(), ex);            }            return;        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -