You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2003/11/25 08:01:06 UTC
cvs commit: incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector BootstrapContextTest.java MockTransaction.java MockWorkManager.java MockXATerminator.java TxUtilsTest.java
djencks 2003/11/24 23:01:06
Added: modules/core/src/test/org/apache/geronimo/connector
BootstrapContextTest.java MockTransaction.java
MockWorkManager.java MockXATerminator.java
TxUtilsTest.java
Log:
Connector tests by Jesse Beaumont, JIRA GERONIMO-118. Many thanks
Revision Changes Path
1.1 incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/BootstrapContextTest.java
Index: BootstrapContextTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.connector;
import java.util.Timer;
import javax.resource.spi.XATerminator;
import javax.resource.spi.work.WorkManager;
import junit.framework.TestCase;
import org.apache.geronimo.connector.BootstrapContext;
import org.apache.geronimo.kernel.service.GeronimoMBeanEndpoint;
import org.apache.geronimo.kernel.service.GeronimoMBeanInfo;
/**
* Unit tests for {@link BootstrapContext}
* @version $Revision: 1.1 $ $Date: 2003/11/25 07:01:06 $
*/
public class BootstrapContextTest extends TestCase {
/**
* Creates a new instance of BootstrapContextTest
* @param name the name of the test
*/
public BootstrapContextTest(String name) {
super(name);
}
/**
* Tests get and set work manager
*/
public void testGetSetWorkManager() {
BootstrapContext context = new BootstrapContext();
MockWorkManager manager = new MockWorkManager("testGetSetWorkManager");
context.setWorkManager(manager);
WorkManager wm = context.getWorkManager();
assertTrue("Make sure it is the same object", manager.equals(wm));
}
/**
* Tests get and set XATerminator
*/
public void testGetSetXATerminator() {
BootstrapContext context = new BootstrapContext();
MockXATerminator t = new MockXATerminator("testGetSetXATerminator");
context.setXATerminator(t);
XATerminator xat = context.getXATerminator();
assertTrue("Make sure it is the same object", t.equals(xat));
}
/**
* Tests getTimer
*/
public void testGetTimer() throws Exception {
BootstrapContext context = new BootstrapContext();
Timer t = context.createTimer();
assertNotNull("Object is not null", t);
}
/**
* Tests getGeronimoMBeanInfo
*/
public void testGetGeronimoMBeanInfo() throws Exception {
BootstrapContext context = new BootstrapContext();
GeronimoMBeanInfo info = context.getGeronimoMBeanInfo();
assertNotNull("Object is not null", info);
assertTrue("Correct target",
info.getTargetClass().equals(BootstrapContext.class.getName()));
GeronimoMBeanEndpoint[] endpoints = info.getEndpoints();
assertNotNull("Endpoinds are not null", endpoints);
assertTrue("Endpoints has 2 elements", endpoints.length == 2);
assertTrue("First endpoint is WorkManager endpoint",
hasEndpoint("WorkManager", endpoints));
assertTrue("Second endpoint is XATerminator endpoint",
hasEndpoint("XATerminator", endpoints));
}
private boolean hasEndpoint(String name, GeronimoMBeanEndpoint[] endpoints) {
for(int i = 0; i < endpoints.length; i++) {
if(name.equals(endpoints[i].getName())) {
return true;
}
}
return false;
}
}
1.1 incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/MockTransaction.java
Index: MockTransaction.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.connector;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.RollbackException;
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.xa.XAResource;
/**
* Dummy implementation of Transaction interface for use in
* {@link TxUtilsTest}
* @version $Revision: 1.1 $ $Date: 2003/11/25 07:01:06 $
*/
public class MockTransaction implements Transaction {
private int status = -1;
/** Creates a new instance of MockWorkManager */
public MockTransaction() {
}
public void commit() throws HeuristicMixedException,
HeuristicRollbackException,
RollbackException,
SecurityException,
SystemException {
}
public boolean delistResource(XAResource xaRes, int flag)
throws IllegalStateException, SystemException {
return false;
}
public boolean enlistResource(XAResource xaRes)
throws IllegalStateException,
RollbackException,
SystemException {
return false;
}
public int getStatus() throws SystemException {
return status;
}
public void registerSynchronization(Synchronization synch)
throws IllegalStateException,
RollbackException,
SystemException {
}
public void rollback() throws IllegalStateException, SystemException {
}
public void setRollbackOnly()
throws IllegalStateException,
SystemException {
}
public void setStatus(int status) {
this.status = status;
}
}
1.1 incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/MockWorkManager.java
Index: MockWorkManager.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.connector;
import javax.resource.spi.work.ExecutionContext;
import javax.resource.spi.work.Work;
import javax.resource.spi.work.WorkException;
import javax.resource.spi.work.WorkListener;
import javax.resource.spi.work.WorkManager;
/**
* Dummy implementation of WorkManager interface for use in
* {@link BootstrapContextTest}
* @version $Revision: 1.1 $ $Date: 2003/11/25 07:01:06 $
*/
public class MockWorkManager
implements WorkManager {
private String id = null;
/** Creates a new instance of MockWorkManager */
public MockWorkManager(String id) {
this.id = id;
}
public void doWork(Work work) throws WorkException {
}
public void doWork(Work work,
long startTimeout,
ExecutionContext execContext,
WorkListener workListener)
throws WorkException {
}
public void scheduleWork(Work work) throws WorkException {
}
public void scheduleWork(Work work,
long startTimeout,
ExecutionContext execContext,
WorkListener workListener)
throws WorkException {
}
public long startWork(Work work) throws WorkException {
return -1;
}
public long startWork(Work work,
long startTimeout,
ExecutionContext execContext,
WorkListener workListener)
throws WorkException {
return -1;
}
public String getId() {
return id;
}
public boolean equals(WorkManager wm) {
if(! (wm instanceof MockWorkManager)) {
return false;
}
return ((MockWorkManager) wm).getId() != null &&
((MockWorkManager) wm).getId().equals(getId());
}
}
1.1 incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/MockXATerminator.java
Index: MockXATerminator.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.connector;
import javax.resource.spi.XATerminator;
import javax.transaction.xa.XAException;
import javax.transaction.xa.Xid;
/**
* Dummy implementation of XATerminator interface for use in
* {@link BootstrapContextTest}
* @version $Revision: 1.1 $ $Date: 2003/11/25 07:01:06 $
*/
public class MockXATerminator implements XATerminator {
private String id = null;
/** Creates a new instance of MockWorkManager */
public MockXATerminator(String id) {
this.id = id;
}
public String getId() {
return id;
}
public boolean equals(MockXATerminator xat) {
if(! (xat instanceof MockXATerminator)) {
return false;
}
return ((MockXATerminator) xat).getId() != null &&
((MockXATerminator) xat).getId().equals(getId());
}
public void commit(Xid xid, boolean onePhase) throws XAException {
}
public void forget(Xid xid) throws XAException {
}
public int prepare(Xid xid) throws XAException {
return -1;
}
public Xid[] recover(int flag) throws XAException {
return null;
}
public void rollback(Xid xid) throws XAException {
}
}
1.1 incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/TxUtilsTest.java
Index: TxUtilsTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.connector;
import javax.transaction.Status;
import junit.framework.TestCase;
import org.apache.geronimo.connector.TxUtils;
/**
* Unit tests for {@link TxUtils}
* @version $Revision: 1.1 $ $Date: 2003/11/25 07:01:06 $
*/
public class TxUtilsTest extends TestCase {
/**
* Creates a new instance of TxUtilsTest
* @param name the name of the test
*/
public TxUtilsTest(String name) {
super(name);
}
/**
* Tests isActive with a null transaction
*/
public void testIsActiveNull() throws Exception {
assertFalse("Null transaction returns false",
TxUtils.isActive(null));
}
/**
* Tests isActive with a committed transaction
*/
public void testIsActiveCommitted() throws Exception {
MockTransaction mt = new MockTransaction();
mt.setStatus(Status.STATUS_COMMITTED);
assertFalse("Committed transaction returns false",
TxUtils.isActive(mt));
}
/**
* Tests isActive with an active transaction
*/
public void testIsActiveActive() throws Exception {
MockTransaction mt = new MockTransaction();
mt.setStatus(Status.STATUS_ACTIVE);
assertTrue("Active transaction returns true",
TxUtils.isActive(mt));
}
/**
* Tests isActive with a marked rollback transaction
*/
public void testIsActiveMarkedRollback() throws Exception {
MockTransaction mt = new MockTransaction();
mt.setStatus(Status.STATUS_MARKED_ROLLBACK);
assertTrue("Marked rollback transaction returns true",
TxUtils.isActive(mt));
}
}