blob: cc1ac0d60de5626c0313881efc6399cbea31e1d6 [file] [log] [blame]
/*
* Copyright 2004-2005 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed 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.jackrabbit.jca.test;
import org.apache.jackrabbit.jca.JCAConnectionRequestInfo;
import org.apache.jackrabbit.jca.JCARepositoryHandle;
import org.apache.jackrabbit.jca.JCASessionHandle;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.naming.Referenceable;
import javax.resource.spi.ManagedConnection;
import java.io.Serializable;
import java.util.HashSet;
/**
* This case executes tests on the connection factory.
*/
public final class ConnectionFactoryTest
extends AbstractTestCase {
/**
* Test the connection factory allocation.
*/
public void testAllocation()
throws Exception {
// Create the connection factory
Object cf = mcf.createConnectionFactory();
assertTrue(cf instanceof JCARepositoryHandle);
Repository repository = (Repository) cf;
// Open a new session
Session session = repository.login(JCR_SUPERUSER);
assertTrue(session != null);
assertTrue(session instanceof JCASessionHandle);
// Logout session
session.logout();
}
/**
* Test the connection matching.
*/
public void testMatching()
throws Exception {
// Create connection request infos
JCAConnectionRequestInfo cri1 = new JCAConnectionRequestInfo(JCR_SUPERUSER, JCR_WORKSPACE);
JCAConnectionRequestInfo cri2 = new JCAConnectionRequestInfo(JCR_ANONUSER, JCR_WORKSPACE);
// Check if not same
assertNotSame(cri1, cri2);
// Allocate connections
ManagedConnection mc1 = mcf.createManagedConnection(null, cri1);
ManagedConnection mc2 = mcf.createManagedConnection(null, cri2);
// Check if not same
assertTrue(mc1 != mc2);
// Create a sef of connections
HashSet connectionSet = new HashSet();
connectionSet.add(mc1);
connectionSet.add(mc2);
// Match the first connection
JCAConnectionRequestInfo cri3 = new JCAConnectionRequestInfo(cri1);
assertTrue((cri1 != cri3) && cri1.equals(cri3));
ManagedConnection mc3 = mcf.matchManagedConnections(connectionSet, null, cri3);
assertTrue(mc1 == mc3);
// Match the second connection
JCAConnectionRequestInfo cri4 = new JCAConnectionRequestInfo(cri2);
assertTrue((cri2 != cri4) && cri2.equals(cri4));
ManagedConnection mc4 = mcf.matchManagedConnections(connectionSet, null, cri4);
assertTrue(mc2 == mc4);
}
/**
* Test if the connection factory is serializable.
*/
public void testSerializable()
throws Exception {
// Create the connection factory
Object cf = mcf.createConnectionFactory();
// Check if serializable and referenceable
assertTrue(cf != null);
assertTrue(cf instanceof Serializable);
assertTrue(cf instanceof Referenceable);
}
}