com.surveypanel.form.config.LoadConfigTest.java Source code

Java tutorial

Introduction

Here is the source code for com.surveypanel.form.config.LoadConfigTest.java

Source

/*
* SurveyPanel
* Copyright (C) 2009 Serge Tan Panza
* All rights reserved.
* License: GNU/GPL License v3 , see LICENSE.txt
* SurveyPanel is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.txt for copyright notices and details.
*/
package com.surveypanel.form.config;

import junit.framework.TestCase;

import org.apache.commons.dbcp.BasicDataSource;

import com.surveypanel.dao.JDBCFormDAO;
import com.surveypanel.form.Form;
import com.surveypanel.form.InMemoryFormFactory;
import com.surveypanel.form.RDBSFormFactory;
import com.surveypanel.js.JSManager;
import com.surveypanel.js.Result;

public class LoadConfigTest extends TestCase {

    public void testLoadConfig() {
        InMemoryFormFactory inMemoryFormFactory = new InMemoryFormFactory("/form/");
        Form form = inMemoryFormFactory.create(0, false);
        JSManager jsManager = new JSManager(inMemoryFormFactory);
        Result execute = (Result) jsManager.execute(form, "flow");
        System.out.println(execute.getLogs());
        System.out.println(execute.getDisplay());
        System.out.println(execute.getError());
    }

    public void testRbs() {

        BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName("org.h2.Driver");
        ds.setUsername("sa");
        ds.setPassword("");
        ds.setUrl("jdbc:h2:mem:surveypanel");

        JDBCFormDAO jdbcFormDAO = new JDBCFormDAO();
        jdbcFormDAO.setDataSource(ds);

        RDBSFormFactory formFactory = new RDBSFormFactory("/form/", jdbcFormDAO);
        formFactory.init(0);
        Form form = formFactory.create(0, false);
        System.out.println(form.getId());
        JSManager jsManager = new JSManager(formFactory);
        Result execute = (Result) jsManager.execute(form, "flow.next();save();");

        System.out.println(form.getId());

        formFactory.load(form.getId(), 0, false);

        System.out.println(execute.getLogs());
        System.out.println(execute.getError());
        assertFalse(execute.hasError());
    }
}