All Downloads are FREE. Search and download functionalities are using the official Maven repository.

at.spardat.xma.datasource.test.TabularDataTest Maven / Gradle / Ivy

There is a newer version: 6.0.2
Show newest version
/*******************************************************************************
 * Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     s IT Solutions AT Spardat GmbH - initial API and implementation
 *******************************************************************************/

/*
 * Created on 19.05.2003
 *
 * To change this generated comment go to 
 * 
 */
package at.spardat.xma.datasource.test;

import java.io.File;
import java.io.InputStream;

import junit.framework.TestCase;
import at.spardat.xma.datasource.TabularDataSourceClient;
import at.spardat.xma.datasource.TabularData;
import at.spardat.xma.datasource.TabularDataRow;
import at.spardat.xma.mdl.Atom;


/**
 * @author S2606
 *
 * To change this generated comment go to 
 * 
 */
public class TabularDataTest extends TestCase {

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

	public void testCreateFiles() {
		
		try {
		
			// Create and fill
			TabularData t = new TabularData();
			t.addColumn("ID");
			t.addColumn("NAME");
			t.addColumn("NAME_LATEIN");		
			
			TabularDataRow row=null;			
			
			row = new TabularDataRow(t);			
			row.set("ID",new Atom(1));
			row.set("NAME",new Atom("Tanne"));			
			row.set("NAME_LATEIN",new Atom("Abies alba"));
			t.addRow(row);								

			row = new TabularDataRow(t);					
			row.add(new Atom(2));		
			row.add(new Atom("Fichte"));			
			row.add(new Atom("Picea abies"));		
			t.addRow(row);			
			
			row = new TabularDataRow(t);			
			row.set(0,new Atom(3));
			row.set(1,new Atom("Buche"));			
			row.set(2,new Atom("Fagus sylvatica"));
			t.addRow(row);
			
			File file1 = new File("c:\\trees1.txt");
			t.save(file1);			
			
			// Clean and fill
			t.clear();	
			
			row = new TabularDataRow(t);			
			row.set("ID",new Atom(4));
			row.set("NAME",new Atom("Gr?nerle"));			
			row.set("NAME_LATEIN",new Atom("Alnus viridis"));
			t.addRow(row);
			
			row = new TabularDataRow(t);			
			row.set("ID",new Atom(5));
			row.set("NAME",new Atom("Schwarzkiefer"));			
			row.set("NAME_LATEIN",new Atom("Pinus nigra"));
			t.addRow(row);			
			t.save(new File("c:\\trees2.txt"));
			
			// Load from file
			t = TabularData.readFrom(file1);			
			t.save(new File("c:\\trees3.txt"));		
			
			// Load from arrays
			String[] header = {"COD_KEY","SHORT_VALUE","LONG_VALUE"};
			Atom [][] data = {
				{ new Atom("bl"), new Atom(""), new Atom("bl?d") },
				{ new Atom("ge"), new Atom(""), new Atom("genial") },
				{ new Atom("iv"), new Atom(""), new Atom("im Verzug")},
				{ new Atom("ivs"), new Atom(""), new Atom("schwer im Verzug")},
				{ new Atom("ivse"), new Atom(""), new Atom("schwer im Verzug und eingestellt")},
				{ new Atom("i"), new Atom(""), new Atom("in Konstruktion")},
			   };
			           	
			t = new TabularData(header,data);		
			t.save(new File("c:\\domain1.txt"));
		
			// Load from resource				
			ClassLoader classLoader = getClass().getClassLoader();
			InputStream inputStream = classLoader.getResourceAsStream("at/spardat/xma/datasource/dummy/Gender.csv");
			if (inputStream==null) {
				throw new Exception("Resource not found");
			}
		
			t = TabularData.readFrom(inputStream);		
			t.save(new File("c:\\domain2.txt"));
			
			// Get from DummyTabularDataSource			
			TabularDataSourceClient dummy = new TabularDataSourceClient();
			t = (TabularData)dummy.getTable("StatusXMA",null);
			t.save(new File("c:\\domain3.txt"));
			        	
		} catch (Exception ex) {
			ex.printStackTrace(); 
			throw new RuntimeException(ex.toString());
		}
		

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy