From 6d5cd48d444eb6bef3373eef61e894fd7e15fefb Mon Sep 17 00:00:00 2001 From: richie Date: Mon, 19 Aug 2019 13:51:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/com/fanruan/api/Prepare.java | 4 ++ .../fanruan/api/data/TableDataKitTest.java | 68 ++++++------------- .../java/com/fanruan/api/data/TestTD.java | 59 ++++++++++++++++ 3 files changed, 83 insertions(+), 48 deletions(-) create mode 100644 src/test/java/com/fanruan/api/data/TestTD.java diff --git a/src/test/java/com/fanruan/api/Prepare.java b/src/test/java/com/fanruan/api/Prepare.java index caba8ee..d74dfbf 100644 --- a/src/test/java/com/fanruan/api/Prepare.java +++ b/src/test/java/com/fanruan/api/Prepare.java @@ -8,6 +8,8 @@ import com.fr.runtime.FineRuntime; import com.fr.store.StateHubManager; import com.fr.store.impl.MemoryLock; import com.fr.store.impl.MemoryStore; +import com.fr.transaction.Configurations; +import com.fr.transaction.LocalConfigurationHelper; import org.junit.After; import org.junit.Before; @@ -24,6 +26,7 @@ public class Prepare { DaoContext.setEntityDao(new LocalEntityDao()); DaoContext.setClassHelperDao(new LocalClassHelperDao()); DaoContext.setXmlEntityDao(new LocalXmlEntityDao()); + Configurations.setHelper(new LocalConfigurationHelper()); StateHubManager.setStorage(new MemoryStore()); StateHubManager.setLock(new MemoryLock()); } @@ -33,6 +36,7 @@ public class Prepare { DaoContext.setEntityDao(null); DaoContext.setClassHelperDao(null); DaoContext.setXmlEntityDao(null); + Configurations.setHelper(null); StateHubManager.setStorage(null); StateHubManager.setLock(null); } diff --git a/src/test/java/com/fanruan/api/data/TableDataKitTest.java b/src/test/java/com/fanruan/api/data/TableDataKitTest.java index 7367acc..f898f40 100644 --- a/src/test/java/com/fanruan/api/data/TableDataKitTest.java +++ b/src/test/java/com/fanruan/api/data/TableDataKitTest.java @@ -1,24 +1,17 @@ package com.fanruan.api.data; import com.fanruan.api.Prepare; -import com.fr.base.AbstractTableData; import com.fr.base.TableData; +import com.fr.config.Configuration; import com.fr.data.TableDataSource; import com.fr.file.TableDataConfig; -import com.fr.general.data.DataModel; import com.fr.main.impl.WorkBook; import com.fr.script.Calculator; -import com.fr.stable.ParameterProvider; -import com.fr.stable.xml.XMLPrintWriter; -import com.fr.stable.xml.XMLableReader; +import com.fr.transaction.Configurations; +import com.fr.transaction.Worker; import org.junit.Assert; import org.junit.Test; -import java.util.HashMap; -import java.util.Map; - -import static org.junit.Assert.*; - /** * @author richie * @version 10.0 @@ -28,54 +21,33 @@ public class TableDataKitTest extends Prepare { @Test public void getTableData() { - Map map = new HashMap<>(); - map.put("test", TD); - TableDataConfig.getInstance().setTableDatas(map); + TestTD td = new TestTD(); + Configurations.update(new Worker() { + @Override + public void run() { + TableDataConfig.getInstance().addTableData("first", td); + } + + @Override + public Class[] targets() { + return new Class[]{TableDataConfig.class}; + } + }); Calculator calculator = Calculator.createCalculator(); calculator.setAttribute(TableDataSource.KEY, new WorkBook()); - TableData r = TableDataKit.getTableData(calculator, "test"); - Assert.assertEquals(TD, r); + TableData r = TableDataKit.getTableData(calculator, "first"); + Assert.assertEquals(td, r); } @Test public void testGetTableData() { + TestTD td = new TestTD(); Calculator calculator = Calculator.createCalculator(); WorkBook workBook = new WorkBook(); - workBook.putTableData("test", TD); + workBook.putTableData("test", td); calculator.setAttribute(TableDataSource.KEY, workBook); TableData r = TableDataKit.getTableData(calculator, "test"); - Assert.assertEquals(TD, r); + Assert.assertEquals(td, r); } - private static final TableData TD = new AbstractTableData() { - @Override - public ParameterProvider[] getParameters(Calculator calculator) { - return new ParameterProvider[0]; - } - - @Override - public DataModel createDataModel(Calculator calculator) { - return null; - } - - @Override - public DataModel createDataModel(Calculator calculator, String s) { - return null; - } - - @Override - public DataModel createDataModel(Calculator calculator, int i) { - return null; - } - - @Override - public void readXML(XMLableReader xmLableReader) { - - } - - @Override - public void writeXML(XMLPrintWriter xmlPrintWriter) { - - } - }; } \ No newline at end of file diff --git a/src/test/java/com/fanruan/api/data/TestTD.java b/src/test/java/com/fanruan/api/data/TestTD.java new file mode 100644 index 0000000..f531706 --- /dev/null +++ b/src/test/java/com/fanruan/api/data/TestTD.java @@ -0,0 +1,59 @@ +package com.fanruan.api.data; + +import com.fanruan.api.conf.HolderKit; +import com.fr.base.AbstractTableData; +import com.fr.config.holder.Conf; +import com.fr.general.data.DataModel; +import com.fr.script.Calculator; +import com.fr.stable.ParameterProvider; +import com.fr.stable.xml.XMLPrintWriter; +import com.fr.stable.xml.XMLableReader; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-08-19 + */ +public class TestTD extends AbstractTableData { + + private Conf count = HolderKit.simple(10); + + public TestTD() { + + } + + @Override + public ParameterProvider[] getParameters(Calculator calculator) { + return new ParameterProvider[0]; + } + + @Override + public DataModel createDataModel(Calculator calculator) { + return DataModel.EMPTY_DATAMODEL; + } + + @Override + public DataModel createDataModel(Calculator calculator, String s) { + return DataModel.EMPTY_DATAMODEL; + } + + @Override + public DataModel createDataModel(Calculator calculator, int i) { + return DataModel.EMPTY_DATAMODEL; + } + + @Override + public void readXML(XMLableReader xmLableReader) { + + } + + @Override + public void writeXML(XMLPrintWriter xmlPrintWriter) { + + } + + @Override + public boolean equals(Object obj) { + return obj instanceof TestTD; + } +}