package org.ihtsdo.buildcloud.service.execution.database;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;

public class SchemaFactoryTest {

	private SchemaFactory schemaFactory;

	private String rf2Filename;
	private String headerLine;

	@Before
	public void setUp() throws Exception {
		schemaFactory = new SchemaFactory();
		rf2Filename = "der2_Refset_SimpleDelta_INT_20140831.txt";
		InputStream rf2Stream = getClass().getResourceAsStream(rf2Filename);
		try (BufferedReader reader = new BufferedReader(new InputStreamReader(rf2Stream))) {
			headerLine = reader.readLine();
		}
	}

	@Test
	public void testCreateSchemaBeanSimpleRefset() throws Exception {
		TableSchema schemaBean = schemaFactory.createSchemaBean(rf2Filename, headerLine);

		Assert.assertEquals("der2_Refset_SimpleDelta_INT_20140831", schemaBean.getName());
		List<TableSchema.Field> fields = schemaBean.getFields();
		Assert.assertEquals(6, fields.size());
		Assert.assertEquals("id", fields.get(0).getName());
		Assert.assertEquals(DataType.UUID, fields.get(0).getType());
		Assert.assertEquals("referencedComponentId", fields.get(5).getName());
		Assert.assertEquals(DataType.SCTID, fields.get(5).getType());
	}

}

@@ -130,101 +130,8 @@
 t;%0A%0A
-import java.io.BufferedReader;%0Aimport java.io.InputStream;%0Aimport java.io.InputStreamReader;%0A
 impo
@@ -227,66 +227,8 @@
 y;%0A%0A
-%09private String rf2Filename;%0A%09private String headerLine;%0A%0A
 %09@Be
@@ -316,341 +316,243 @@
 );%0A%09
-%09rf2Filename = %22der2_Refset_SimpleDelta_INT_20140831.txt%22;%0A%09%09InputStream rf2Stream = getClass().getResourceAsStream(rf2Filename);%0A%09%09try (BufferedReader reader = new BufferedReader(new InputStreamReader(rf2Stream))) %7B%0A%09%09%09headerLine = reader.readLine();%0A%09%09%7D%0A%09%7D%0A%0A%09@Test%0A%09public void testCreateSchemaBeanSimpleRefset() throws Exception %7B
+%7D%0A%0A%09@Test%0A%09public void testCreateSchemaBeanSimpleRefset() throws Exception %7B%0A%09%09String filename = %22der2_Refset_SimpleDelta_INT_20140831.txt%22;%0A%09%09String headerLine = %22id%5CteffectiveTime%5Ctactive%5CtmoduleId%5CtrefSetId%5CtreferencedComponentId%22;%0A
 %0A%09%09T
@@ -610,12 +610,9 @@
 ean(
-rf2F
+f
 ilen
@@ -811,24 +811,25 @@
 ds.size());%0A
+%0A
 %09%09Assert.ass
@@ -929,24 +929,529 @@
 getType());%0A
+%0A%09%09Assert.assertEquals(%22effectiveTime%22, fields.get(1).getName());%0A%09%09Assert.assertEquals(DataType.TIME, fields.get(1).getType());%0A%0A%09%09Assert.assertEquals(%22active%22, fields.get(2).getName());%0A%09%09Assert.assertEquals(DataType.BOOLEAN, fields.get(2).getType());%0A%0A%09%09Assert.assertEquals(%22moduleId%22, fields.get(3).getName());%0A%09%09Assert.assertEquals(DataType.SCTID, fields.get(3).getType());%0A%0A%09%09Assert.assertEquals(%22refSetId%22, fields.get(4).getName());%0A%09%09Assert.assertEquals(DataType.SCTID, fields.get(4).getType());%0A%0A
 %09%09Assert.ass

Refactor SchemaFactoryTest.