view geo-backend/src/test/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEConnectionPoolTestCase.java @ 1127:ebeb56428409

Added license headers and license file. geo-backend/trunk@1261 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 02 Nov 2010 17:52:22 +0000
parents b757def3ff55
children
line wrap: on
line source
/*
 * Copyright (c) 2010 by Intevation GmbH
 *
 * This program is free software under the LGPL (>=v2.1)
 * Read the file LGPL.txt coming with the software for details
 * or visit http://www.gnu.org/licenses/ if it does not exist.
 */

package de.intevation.gnv.geobackend.sde.datasources;

import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool;
import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPoolFactory;

import de.intevation.gnv.geobackend.base.connectionpool.exception.ConnectionException;

import de.intevation.gnv.geobackend.sde.connectionpool.ArcSDEPoolableObjectFactory;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import java.util.Properties;

import junit.framework.TestCase;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;

/**
 * TestCase for the usage of the ArcSDEConnectionPool.
 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a>
 *
 */
public class ArcSDEConnectionPoolTestCase extends TestCase {

    /**
     * the logger, used to log exceptions and additonaly information
     */
    private static Logger log = null;

    static {
        BasicConfigurator.configure();
        log = Logger.getLogger(ArcSDEPoolableObjectFactory.class);
    }
    /**
     *
     */
    public ArcSDEConnectionPoolTestCase() {
        super();
    }

    /**
     *
     * @param name
     */
    public ArcSDEConnectionPoolTestCase(String name) {
        super(name);
    }

    /**
     * Test if the ArcSDEConnectionPool can be established
     * and if a Request could be done.
     */
    public void testArcSDEConnectionPool(){
        log.debug("ArcSDEConnectionPoolTestCase.testArcSDEConnectionPool");
        try {
            InputStream inputStream = new FileInputStream("src/test/ressources/ArcSDEConnectionPoolTestCase.properties");
            Properties properties = new Properties();
            properties.load(inputStream);

            ConnectionPoolFactory cpf = ConnectionPoolFactory.getInstance();
            cpf.initializeConnectionPool(properties);

            assertTrue(cpf.isInitialized());
            log.debug("ConnectionPoolFactory ist initialisiert.");

            ConnectionPool cp = cpf.getConnectionPool();
            assertNotNull(cp);
            log.debug("ConnectionPool ist initialisiert.");

            Connection connection = null;
            try{
                try {
                    connection = cp.getConnection("N/N");
                    assertNotNull(connection);
                    log.debug("Connection ist initialisiert.");
                } catch (ConnectionException e) {
                    log.error("Es traten Probleme bei der Verbinung zur Datenbank auf.");
                    fail();
                }


                try {
                    Statement stmt = connection.createStatement();
                    ResultSet rs = stmt.executeQuery("Select MESHID, NAME from MEDIAN.MESH");

                    while (rs.next()){
                        log.debug(rs.getInt(1));
                        log.debug(rs.getString(2));

                        log.debug(rs.getInt("MESHID"));
                        log.debug(rs.getString("NAME"));
                    }

                } catch (SQLException e) {
                    log.error(e,e);
                }
            }finally{
                if (connection != null){
                    try {
                            connection.close();
                    } catch (SQLException e) {
                        log.error(e,e);
                        fail();
                    }
                }
            }
        } catch (FileNotFoundException e) {
            log.error(e,e);
            fail();
        } catch (IOException e) {
            log.error(e,e);
            fail();
        }
    }
}

http://dive4elements.wald.intevation.org