Browse Source

单元测试

remotes/1611766341912730171/master
richie 5 years ago
parent
commit
6d5cd48d44
  1. 4
      src/test/java/com/fanruan/api/Prepare.java
  2. 68
      src/test/java/com/fanruan/api/data/TableDataKitTest.java
  3. 59
      src/test/java/com/fanruan/api/data/TestTD.java

4
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.StateHubManager;
import com.fr.store.impl.MemoryLock; import com.fr.store.impl.MemoryLock;
import com.fr.store.impl.MemoryStore; import com.fr.store.impl.MemoryStore;
import com.fr.transaction.Configurations;
import com.fr.transaction.LocalConfigurationHelper;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
@ -24,6 +26,7 @@ public class Prepare {
DaoContext.setEntityDao(new LocalEntityDao()); DaoContext.setEntityDao(new LocalEntityDao());
DaoContext.setClassHelperDao(new LocalClassHelperDao()); DaoContext.setClassHelperDao(new LocalClassHelperDao());
DaoContext.setXmlEntityDao(new LocalXmlEntityDao()); DaoContext.setXmlEntityDao(new LocalXmlEntityDao());
Configurations.setHelper(new LocalConfigurationHelper());
StateHubManager.setStorage(new MemoryStore()); StateHubManager.setStorage(new MemoryStore());
StateHubManager.setLock(new MemoryLock()); StateHubManager.setLock(new MemoryLock());
} }
@ -33,6 +36,7 @@ public class Prepare {
DaoContext.setEntityDao(null); DaoContext.setEntityDao(null);
DaoContext.setClassHelperDao(null); DaoContext.setClassHelperDao(null);
DaoContext.setXmlEntityDao(null); DaoContext.setXmlEntityDao(null);
Configurations.setHelper(null);
StateHubManager.setStorage(null); StateHubManager.setStorage(null);
StateHubManager.setLock(null); StateHubManager.setLock(null);
} }

68
src/test/java/com/fanruan/api/data/TableDataKitTest.java

@ -1,24 +1,17 @@
package com.fanruan.api.data; package com.fanruan.api.data;
import com.fanruan.api.Prepare; import com.fanruan.api.Prepare;
import com.fr.base.AbstractTableData;
import com.fr.base.TableData; import com.fr.base.TableData;
import com.fr.config.Configuration;
import com.fr.data.TableDataSource; import com.fr.data.TableDataSource;
import com.fr.file.TableDataConfig; import com.fr.file.TableDataConfig;
import com.fr.general.data.DataModel;
import com.fr.main.impl.WorkBook; import com.fr.main.impl.WorkBook;
import com.fr.script.Calculator; import com.fr.script.Calculator;
import com.fr.stable.ParameterProvider; import com.fr.transaction.Configurations;
import com.fr.stable.xml.XMLPrintWriter; import com.fr.transaction.Worker;
import com.fr.stable.xml.XMLableReader;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.*;
/** /**
* @author richie * @author richie
* @version 10.0 * @version 10.0
@ -28,54 +21,33 @@ public class TableDataKitTest extends Prepare {
@Test @Test
public void getTableData() { public void getTableData() {
Map<String, TableData> map = new HashMap<>(); TestTD td = new TestTD();
map.put("test", TD); Configurations.update(new Worker() {
TableDataConfig.getInstance().setTableDatas(map); @Override
public void run() {
TableDataConfig.getInstance().addTableData("first", td);
}
@Override
public Class<? extends Configuration>[] targets() {
return new Class[]{TableDataConfig.class};
}
});
Calculator calculator = Calculator.createCalculator(); Calculator calculator = Calculator.createCalculator();
calculator.setAttribute(TableDataSource.KEY, new WorkBook()); calculator.setAttribute(TableDataSource.KEY, new WorkBook());
TableData r = TableDataKit.getTableData(calculator, "test"); TableData r = TableDataKit.getTableData(calculator, "first");
Assert.assertEquals(TD, r); Assert.assertEquals(td, r);
} }
@Test @Test
public void testGetTableData() { public void testGetTableData() {
TestTD td = new TestTD();
Calculator calculator = Calculator.createCalculator(); Calculator calculator = Calculator.createCalculator();
WorkBook workBook = new WorkBook(); WorkBook workBook = new WorkBook();
workBook.putTableData("test", TD); workBook.putTableData("test", td);
calculator.setAttribute(TableDataSource.KEY, workBook); calculator.setAttribute(TableDataSource.KEY, workBook);
TableData r = TableDataKit.getTableData(calculator, "test"); 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) {
}
};
} }

59
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<Integer> 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;
}
}
Loading…
Cancel
Save