Package org.wso2.carbon.humantask.test

Source Code of org.wso2.carbon.humantask.test.DAOModuleTest

/*
* Copyright (c) 2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* 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.wso2.carbon.humantask.test;

import junit.framework.TestCase;
import org.apache.commons.dbcp.BasicDataSource;
import org.wso2.carbon.humantask.olddao.Constants;
import org.wso2.carbon.humantask.olddao.DAOFactory;
import org.wso2.carbon.humantask.olddao.DAOFactoryType;

import javax.sql.DataSource;
import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class DAOModuleTest extends TestCase {

    private DataSource dataSource;

    private DAOFactory daoFactory;

    public void setUp() throws Exception {
        initDataSource();
        initDAOFactory();
    }

    private void initDAOFactory() {
        Map<String, Object> doaFactorySettings = new HashMap<String, Object>();
        doaFactorySettings.put(Constants.PROP_DATA_SOURCE, dataSource);

        daoFactory = DAOFactory.getDAOFactory(DAOFactoryType.JPA, doaFactorySettings);
    }

    private void initDataSource() {
        BasicDataSource d = new BasicDataSource();

        d.setDriverClassName("org.h2.Driver");
        d.setUsername("sa");
        d.setPassword("");
        d.setUrl(calculateDBUrl(getWorkingDirectory()));

        this.dataSource = d;
    }

    private String getWorkingDirectory(){
        return System.getProperty("user.dir");
    }

    private String calculateDBUrl(String workingDirectory){
        return "jdbc:h2:file:" + workingDirectory + File.separator + "target/htdb;MVCC=TRUE";
    }

}
TOP

Related Classes of org.wso2.carbon.humantask.test.DAOModuleTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.