Search in sources :

Example 1 with LogManager

use of org.apache.axis2.transport.testkit.util.LogManager in project wso2-axis2-transports by wso2.

the class AxisTestEndpoint method setUp.

@Setup
@SuppressWarnings("unused")
private void setUp(LogManager logManager, AxisTestEndpointContext context, Channel channel, AxisServiceConfigurator[] configurators) throws Exception {
    this.context = context;
    TransportListener listener = context.getTransportListener();
    if (listener instanceof TransportErrorSource) {
        transportErrorSource = (TransportErrorSource) listener;
        errorListener = new TransportErrorListener() {

            public void error(TransportError error) {
                AxisService s = error.getService();
                if (s == null || s == service) {
                    onTransportError(error.getException());
                }
            }
        };
        transportErrorSource.addErrorListener(errorListener);
    } else {
        transportErrorSource = null;
    }
    String path;
    try {
        path = new URI(channel.getEndpointReference().getAddress()).getPath();
    } catch (URISyntaxException ex) {
        path = null;
    }
    String serviceName;
    if (path != null && path.startsWith(Channel.CONTEXT_PATH + "/")) {
        serviceName = path.substring(Channel.CONTEXT_PATH.length() + 1);
    } else {
        serviceName = "TestService-" + UUID.randomUUID();
    }
    service = new AxisService(serviceName);
    service.addOperation(createOperation());
    if (configurators != null) {
        for (AxisServiceConfigurator configurator : configurators) {
            configurator.setupService(service, false);
        }
    }
    // Output service parameters to log file
    // FIXME: This actually doesn't give the expected result because the AxisTestEndpoint might be reused
    // by several test cases and in that case the log file is only produced once
    List<Parameter> params = (List<Parameter>) service.getParameters();
    if (!params.isEmpty()) {
        PrintWriter log = new PrintWriter(logManager.createLog("service-parameters"), false);
        try {
            for (Parameter param : params) {
                log.print(param.getName());
                log.print("=");
                log.println(param.getValue());
            }
        } finally {
            log.close();
        }
    }
    // We want to receive all messages through the same operation:
    service.addParameter(AxisService.SUPPORT_SINGLE_OP, true);
    context.getAxisConfiguration().addService(service);
    // The transport may disable the service. In that case, fail directly.
    if (!BaseUtils.isUsingTransport(service, context.getTransportName())) {
        Assert.fail("The service has been disabled by the transport");
    }
}
Also used : TransportError(org.apache.axis2.transport.base.event.TransportError) AxisServiceConfigurator(org.apache.axis2.transport.testkit.axis2.AxisServiceConfigurator) AxisService(org.apache.axis2.description.AxisService) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) TransportErrorSource(org.apache.axis2.transport.base.event.TransportErrorSource) TransportListener(org.apache.axis2.transport.TransportListener) TransportErrorListener(org.apache.axis2.transport.base.event.TransportErrorListener) Parameter(org.apache.axis2.description.Parameter) List(java.util.List) PrintWriter(java.io.PrintWriter) Setup(org.apache.axis2.transport.testkit.tests.Setup)

Example 2 with LogManager

use of org.apache.axis2.transport.testkit.util.LogManager in project wso2-axis2-transports by wso2.

the class ManagedTestSuite method run.

@Override
public void run(TestResult result) {
    LogManager logManager = LogManager.INSTANCE;
    if (!reuseResources) {
        super.run(result);
    } else {
        TestResourceSet resourceSet = null;
        for (Enumeration<?> e = tests(); e.hasMoreElements(); ) {
            Test test = (Test) e.nextElement();
            if (test instanceof ManagedTestCase) {
                ManagedTestCase ttest = (ManagedTestCase) test;
                TestResourceSet newResourceSet = ttest.getResourceSet();
                try {
                    if (resourceSet == null) {
                        logManager.setTestCase(ttest);
                        newResourceSet.setUp();
                    } else {
                        TestResourceSetTransition transition = new TestResourceSetTransition(resourceSet, newResourceSet);
                        transition.tearDown();
                        logManager.setTestCase(ttest);
                        transition.setUp();
                    }
                } catch (Throwable t) {
                    result.addError(this, t);
                    return;
                }
                resourceSet = newResourceSet;
            }
            runTest(test, result);
        }
        if (resourceSet != null) {
            try {
                resourceSet.tearDown();
                logManager.setTestCase(null);
            } catch (Throwable t) {
                result.addError(this, t);
                return;
            }
        }
    }
}
Also used : ManagedTestCase(org.apache.axis2.transport.testkit.tests.ManagedTestCase) Test(junit.framework.Test) TestResourceSet(org.apache.axis2.transport.testkit.tests.TestResourceSet) TestResourceSetTransition(org.apache.axis2.transport.testkit.tests.TestResourceSetTransition) LogManager(org.apache.axis2.transport.testkit.util.LogManager)

Example 3 with LogManager

use of org.apache.axis2.transport.testkit.util.LogManager in project wso2-axis2-transports by wso2.

the class GreenMailTestEnvironment method setUp.

@Setup
@SuppressWarnings("unused")
private void setUp(LogManager logManager, PortAllocator portAllocator) throws Exception {
    this.logManager = logManager;
    this.portAllocator = portAllocator;
    smtpServerSetup = new ServerSetup(portAllocator.allocatePort(), "127.0.0.1", ServerSetup.PROTOCOL_SMTP);
    storeServerSetup = new ServerSetup(portAllocator.allocatePort(), "127.0.0.1", protocol);
    greenMail = new GreenMail(new ServerSetup[] { smtpServerSetup, storeServerSetup });
    greenMail.start();
    smtpTunnel = new Tunnel(new InetSocketAddress("127.0.0.1", smtpServerSetup.getPort()));
    smtpTunnel.start();
    unallocatedAccounts = new LinkedList<Account>();
    ServerUtil.waitForServer(smtpServerSetup.getPort());
    ServerUtil.waitForServer(storeServerSetup.getPort());
}
Also used : Tunnel(org.apache.axis2.transport.testkit.util.tcpmon.Tunnel) InetSocketAddress(java.net.InetSocketAddress) ServerSetup(com.icegreen.greenmail.util.ServerSetup) GreenMail(com.icegreen.greenmail.util.GreenMail) ServerSetup(com.icegreen.greenmail.util.ServerSetup) Setup(org.apache.axis2.transport.testkit.tests.Setup)

Aggregations

Setup (org.apache.axis2.transport.testkit.tests.Setup)2 GreenMail (com.icegreen.greenmail.util.GreenMail)1 ServerSetup (com.icegreen.greenmail.util.ServerSetup)1 PrintWriter (java.io.PrintWriter)1 InetSocketAddress (java.net.InetSocketAddress)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 List (java.util.List)1 Test (junit.framework.Test)1 AxisService (org.apache.axis2.description.AxisService)1 Parameter (org.apache.axis2.description.Parameter)1 TransportListener (org.apache.axis2.transport.TransportListener)1 TransportError (org.apache.axis2.transport.base.event.TransportError)1 TransportErrorListener (org.apache.axis2.transport.base.event.TransportErrorListener)1 TransportErrorSource (org.apache.axis2.transport.base.event.TransportErrorSource)1 AxisServiceConfigurator (org.apache.axis2.transport.testkit.axis2.AxisServiceConfigurator)1 ManagedTestCase (org.apache.axis2.transport.testkit.tests.ManagedTestCase)1 TestResourceSet (org.apache.axis2.transport.testkit.tests.TestResourceSet)1 TestResourceSetTransition (org.apache.axis2.transport.testkit.tests.TestResourceSetTransition)1 LogManager (org.apache.axis2.transport.testkit.util.LogManager)1