package cl.fatman.capital.fund;

import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import java.time.LocalDate;
import java.util.List;
import java.util.ArrayList;

public class PersistenceDataTest {
	
	private static PersistenceData connection;
	
	
	@BeforeClass
	public static void setUp() {
		connection = PersistenceData.getInstance();
		connection.connect();
	}
	
	
	@AfterClass
	public static void tearDown() {
		connection.close();
	}
	
	
	@Test
	public void fomentUnitTest() {
		LocalDate ufDate = LocalDate.now();
		List<FomentUnit> ufList = new ArrayList<FomentUnit>();
		ufList.add(new FomentUnit(0.003, ufDate));
		connection.insertObjectList(ufList);
		List<FomentUnit> tmpList = (List<FomentUnit>)(List<?>)connection.selectAllObjects("from FomentUnit", FomentUnit.class);
		assertEquals("UF lists should be equals.", ufList.size(), tmpList.size());
	}
	
	
	@Test
	public void createFundEntryTest() {
		List<Fund> fundList = new ArrayList<Fund>();
		fundList.add(new Fund("Fake", "0-K", "A", "REM",  "Accionario", "Nacional", 1.0));
		fundList.add(new Fund("Fake", "0-K", "B", "REM",  "Accionario", "Nacional", 2.0));
		fundList.add(new Fund("Fake", "0-K", "C", "REM",  "Accionario", "Nacional", 3.0));
		connection.insertObjectList(fundList);
		List<Fund> tmpList = (List<Fund>)(List<?>)connection.selectAllObjects("from Fund", Fund.class);
		assertEquals("Fund lists should be equals", fundList.size(), tmpList.size());
	}

}
@@ -82,21 +82,16 @@
 it.After
-Class
 ;%0Aimport
@@ -107,21 +107,16 @@
 t.Before
-Class
 ;%0Aimport
@@ -259,23 +259,16 @@
 private 
-static 
 Persiste
@@ -299,21 +299,16 @@
 %09@Before
-Class
 %0A%09public
@@ -304,31 +304,24 @@
 ore%0A%09public 
-static 
 void setUp()
@@ -411,13 +411,8 @@
 fter
-Class
 %0A%09pu
@@ -416,23 +416,16 @@
 %09public 
-static 
 void tea
@@ -514,18 +514,18 @@
 calDate 
-u
 f
+u
 Date = L
@@ -559,18 +559,18 @@
 ntUnit%3E 
-u
 f
+u
 List = n
@@ -599,18 +599,18 @@
 t%3E();%0A%09%09
-u
 f
+u
 List.add
@@ -632,18 +632,18 @@
 (0.003, 
-u
 f
+u
 Date));%0A
@@ -672,18 +672,18 @@
 ectList(
-u
 f
+u
 List);%0A%09
@@ -823,10 +823,19 @@
 ls(%22
-U
 F
+oment Unit
  lis
@@ -861,10 +861,10 @@
 .%22, 
-u
 f
+u
 List
@@ -1464,10 +1464,741 @@
 ());%0A%09%7D%0A
+%09%0A%09@Test%0A%09public void createFundRateEntryTest() %7B%0A%09%09List%3CFundRate%3E frList = new ArrayList%3CFundRate%3E();%0A%09%09List%3CFund%3E fundList = new ArrayList%3CFund%3E();%0A%09%09LocalDate frDate = LocalDate.now();%0A%09%09FundRate frTmp = null;%0A%09%09Fund fundTmp = new Fund(%22Fake%22, %220-K%22, %22A%22, %22REM%22,  %22Accionario%22, %22Nacional%22, 1.0);%0A%09%09fundList.add(fundTmp);%0A%09%09connection.insertObjectList(fundList);%0A%09%09for (int i = 0; i %3C 10; i++) %7B%0A%09%09%09frTmp = new FundRate(i/10000, frDate);%0A%09%09%09frTmp.setFund(fundTmp);%0A%09%09%09frList.add(frTmp);%0A%09%09%7D%0A%09%09connection.insertObjectList(frList);%0A%09%09List%3CFundRate%3E tmpList = (List%3CFundRate%3E)(List%3C?%3E)connection.selectAllObjects(%22from FundRate%22, FundRate.class);%0A%09%09assertEquals(%22Fund Rate lists should be equals%22, frList.size(), tmpList.size());%0A%09%7D
 %0A%7D

Use before and after annotations to clean the database after every test execution (for the moment the test performance is not important).