InitStoreTestCase.java :  » Database-DBMS » jalisto » org » objectweb » jalisto » test » core » suite » Java Open Source

Java Open Source » Database DBMS » jalisto 
jalisto » org » objectweb » jalisto » test » core » suite » InitStoreTestCase.java
/*
 * Jalisto - JAva LIght STOrage
 * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
 * 
 * Xcalia
 * 71, rue Desnouettes
 * 75014 Paris - France
 * http://www.xcalia.com
 */
package org.objectweb.jalisto.test.core.suite;

import junit.framework.Test;
import org.objectweb.jalisto.se.JalistoFactory;
import org.objectweb.jalisto.se.api.Session;
import org.objectweb.jalisto.se.api.JalistoProperties;
import org.objectweb.jalisto.se.test.data.Author;
import org.objectweb.jalisto.se.test.data.Book;
import org.objectweb.jalisto.se.test.workbench.JalistoTestCase;
import org.objectweb.jalisto.se.test.workbench.JalistoTestSuite;

public class InitStoreTestCase extends JalistoTestCase {
    public InitStoreTestCase() {
    }

    public InitStoreTestCase(String name) {
        super(name);
    }

    public static Test suite() {
        JalistoTestSuite suite = new JalistoTestSuite();
        InitStoreTestCase tc = (InitStoreTestCase) newTestCase(suite, new InitStoreTestCase());

        tc.define();

        tc.printSessionProperties();

        tc.sameSession();
        tc.twoSessionsWithDifferentUserMode();

        tc.finishTests();

        return suite;
    }

    public void printSessionProperties() {
        if (session.getInternalSession().isRemoteSession()) {
            out("IS REMOTE SESSION");
            return;
        }
        JalistoProperties props = session.getInternalSession().getProperties();
        if (props.isMonoImplementation()) {
            out("USE MONO SESSION");
        } else {
            out("USE MULTI SESSION");
        }

    }

    public void sameSession() {
        if (session.getInternalSession().isRemoteSession()) {
            out("can't execute this test with remote client");
            return;
        }
        String path = getJalistoPropertiesFilename();
        JalistoProperties jalistoProps = JalistoFactory.getInternalFactory().getProperties(path);
        if (jalistoProps.isMonoImplementation()) {
            Session session1 = JalistoFactory.getSession(path);
            Session session2 = JalistoFactory.getSession(path);
            assertTrue("sessions must be equals in mono mode", session1 == session2);
        }
    }

    public void twoSessionsWithDifferentUserMode() {
        if (session.getInternalSession().isRemoteSession()) {
            out("can't execute this test with remote client");
            return;
        }
        String path;
        if (session.getInternalSession().getProperties().isMonoImplementation()) {
            path = "jalisto-multi.properties";
        } else {
            path = "jalisto-mono.properties";
        }
        Session parallelSession = JalistoFactory.getSession(path);
        try {
            parallelSession.openSession();
            parallelSession.currentTransaction().begin();
            parallelSession.currentTransaction().commit();
        } finally {
            if (parallelSession != null) {
                if (parallelSession.currentTransaction().isActive()) {
                    parallelSession.currentTransaction().commit();
                }
                if (parallelSession.isOpen()) {
                    parallelSession.closeSession();
                }
            }
        }
    }

    private static void out(Object message) {
        String s = "--> " + String.valueOf(message);
        System.out.println(s);
    }

    /**
     * **************************************************************************************
     */

    public void define() {
        super.initSession(false);
        if (!session.getInternalSession().isRemoteSession()) {
            super.define(Author.getMetaDescription());
            super.define(Book.getMetaDescription());
        }
    }

    public void finishTests() {
        super.finishTests();
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.