6 changed files with 294 additions and 32 deletions
@ -0,0 +1,43 @@ |
|||||||
|
package com.fr.design.data.datapane.management.clip; |
||||||
|
|
||||||
|
import com.fr.data.impl.EmbeddedTableData; |
||||||
|
import com.fr.design.data.tabledata.wrapper.AbstractTableDataWrapper; |
||||||
|
import com.fr.design.data.tabledata.wrapper.TemplateTableDataWrapper; |
||||||
|
import junit.framework.TestCase; |
||||||
|
import org.junit.Assert; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Yvan |
||||||
|
*/ |
||||||
|
public class TableDataTreeClipboardTest extends TestCase { |
||||||
|
|
||||||
|
public void testAddAndTake() { |
||||||
|
Map<String, AbstractTableDataWrapper> testMap = new HashMap<>(); |
||||||
|
testMap.put("ds1", new TemplateTableDataWrapper(new EmbeddedTableData())); |
||||||
|
testMap.put("ds2", new TemplateTableDataWrapper(new EmbeddedTableData())); |
||||||
|
|
||||||
|
Map<String, AbstractTableDataWrapper> anotherTestMap = new HashMap<>(); |
||||||
|
anotherTestMap.put("ds3", new TemplateTableDataWrapper(new EmbeddedTableData())); |
||||||
|
|
||||||
|
Map<String, AbstractTableDataWrapper> clip; |
||||||
|
TableDataTreeClipboard.getInstance().addToClip(testMap); |
||||||
|
clip = TableDataTreeClipboard.getInstance().takeFromClip(); |
||||||
|
Assert.assertEquals(2, clip.size()); |
||||||
|
Assert.assertTrue(clip.containsKey("ds1")); |
||||||
|
Assert.assertTrue(clip.containsKey("ds2")); |
||||||
|
|
||||||
|
// 验证多次取出
|
||||||
|
clip = TableDataTreeClipboard.getInstance().takeFromClip(); |
||||||
|
Assert.assertEquals(2, clip.size()); |
||||||
|
Assert.assertTrue(clip.containsKey("ds1")); |
||||||
|
Assert.assertTrue(clip.containsKey("ds2")); |
||||||
|
|
||||||
|
TableDataTreeClipboard.getInstance().addToClip(anotherTestMap); |
||||||
|
clip = TableDataTreeClipboard.getInstance().takeFromClip(); |
||||||
|
Assert.assertEquals(1, clip.size()); |
||||||
|
Assert.assertTrue(clip.containsKey("ds3")); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,201 @@ |
|||||||
|
package com.fr.design.data.tabledata.paste; |
||||||
|
|
||||||
|
import com.fr.base.TableData; |
||||||
|
import com.fr.data.Dictionary; |
||||||
|
import com.fr.data.TableDataSource; |
||||||
|
import com.fr.data.impl.EmbeddedTableData; |
||||||
|
import com.fr.design.data.DesignTableDataManager; |
||||||
|
import com.fr.design.data.tabledata.wrapper.TableDataWrapper; |
||||||
|
import com.fr.design.data.tabledata.wrapper.TemplateTableDataWrapper; |
||||||
|
import com.fr.form.data.DataBinding; |
||||||
|
import com.fr.form.data.DataTableConfig; |
||||||
|
import com.fr.form.ui.AbstractDataControl; |
||||||
|
import com.fr.form.ui.DictionaryContainer; |
||||||
|
import com.fr.form.ui.Widget; |
||||||
|
import com.fr.form.ui.WidgetValue; |
||||||
|
import com.fr.report.cell.tabledata.ElementUsedTableDataProvider; |
||||||
|
import com.fr.script.Calculator; |
||||||
|
import com.fr.stable.script.CalculatorProvider; |
||||||
|
import com.fr.stable.script.NameSpace; |
||||||
|
import com.fr.web.core.TemplateSessionIDInfo; |
||||||
|
import junit.framework.TestCase; |
||||||
|
import org.easymock.EasyMock; |
||||||
|
import org.junit.Assert; |
||||||
|
import org.junit.Before; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.powermock.api.easymock.PowerMock; |
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest; |
||||||
|
import org.powermock.modules.junit4.PowerMockRunner; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.HashSet; |
||||||
|
import java.util.LinkedHashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Set; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Yvan |
||||||
|
*/ |
||||||
|
@RunWith(PowerMockRunner.class) |
||||||
|
@PrepareForTest({DesignTableDataManager.class}) |
||||||
|
public class TableDataFollowingPasteUtilsTest extends TestCase { |
||||||
|
|
||||||
|
@Before |
||||||
|
public void beforeTest() { |
||||||
|
Map<String, TableDataWrapper> templateDataMap = new LinkedHashMap<String, TableDataWrapper>(); |
||||||
|
Map<String, TableDataWrapper> serverDataMap = new LinkedHashMap<String, TableDataWrapper>(); |
||||||
|
Map<String, TableDataWrapper> storeProcedureMap = new LinkedHashMap<String, TableDataWrapper>(); |
||||||
|
templateDataMap.put("ds1", new TemplateTableDataWrapper(new EmbeddedTableData())); |
||||||
|
templateDataMap.put("ds2", new TemplateTableDataWrapper(new EmbeddedTableData())); |
||||||
|
templateDataMap.put("ds3", new TemplateTableDataWrapper(new EmbeddedTableData())); |
||||||
|
templateDataMap.put("ds4", new TemplateTableDataWrapper(new EmbeddedTableData())); |
||||||
|
templateDataMap.put("ds5", new TemplateTableDataWrapper(new EmbeddedTableData())); |
||||||
|
|
||||||
|
List<Map<String, TableDataWrapper>> list = new ArrayList<Map<String, TableDataWrapper>>(); |
||||||
|
list.add(templateDataMap); |
||||||
|
list.add(serverDataMap); |
||||||
|
list.add(storeProcedureMap); |
||||||
|
|
||||||
|
TableDataSource tableDataSource = EasyMock.mock(TableDataSource.class); |
||||||
|
PowerMock.mockStatic(DesignTableDataManager.class); |
||||||
|
EasyMock.expect(DesignTableDataManager.getEditingTableDataSource()).andReturn(tableDataSource).anyTimes(); |
||||||
|
EasyMock.expect(DesignTableDataManager.getEditingDataSet(tableDataSource)).andReturn(list).anyTimes(); |
||||||
|
PowerMock.replayAll(); |
||||||
|
} |
||||||
|
|
||||||
|
public void testTransferProvider2TableDataMap() { |
||||||
|
ElementUsedTableDataProvider[] providers = generateElementUsedTableDataProvider(); |
||||||
|
Map<String, TableData> tableDataMap = TableDataFollowingPasteUtils.transferProvider2TableDataMap(providers); |
||||||
|
Assert.assertEquals(2, tableDataMap.size()); |
||||||
|
Assert.assertTrue(tableDataMap.containsKey("ds1")); |
||||||
|
Assert.assertTrue(tableDataMap.containsKey("ds2")); |
||||||
|
} |
||||||
|
|
||||||
|
private ElementUsedTableDataProvider[] generateElementUsedTableDataProvider() { |
||||||
|
ElementUsedTableDataProvider elementUsedTableDataProvider1 = new ElementUsedTableDataProvider() { |
||||||
|
@Override |
||||||
|
public Set<String> getElementUsedTableDataNames() { |
||||||
|
Set<String> set = new HashSet<>(); |
||||||
|
set.add("ds1"); |
||||||
|
return set; |
||||||
|
} |
||||||
|
}; |
||||||
|
ElementUsedTableDataProvider elementUsedTableDataProvider2 = new ElementUsedTableDataProvider() { |
||||||
|
@Override |
||||||
|
public Set<String> getElementUsedTableDataNames() { |
||||||
|
Set<String> set = new HashSet<>(); |
||||||
|
set.add("ds2"); |
||||||
|
return set; |
||||||
|
} |
||||||
|
}; |
||||||
|
return new ElementUsedTableDataProvider[]{elementUsedTableDataProvider1, elementUsedTableDataProvider2}; |
||||||
|
} |
||||||
|
|
||||||
|
public void testTransferWidgetArray2TableDataMap() { |
||||||
|
Widget[] widgets = generateWidgetArray(); |
||||||
|
Map<String, TableData> tableDataMap = TableDataFollowingPasteUtils.transferWidgetArray2TableDataMap(widgets); |
||||||
|
Assert.assertEquals(3, tableDataMap.size()); |
||||||
|
Assert.assertTrue(tableDataMap.containsKey("ds3")); |
||||||
|
Assert.assertTrue(tableDataMap.containsKey("ds4")); |
||||||
|
Assert.assertTrue(tableDataMap.containsKey("ds5")); |
||||||
|
} |
||||||
|
|
||||||
|
private Widget[] generateWidgetArray() { |
||||||
|
Set<String> set = new HashSet<>(); |
||||||
|
set.add("ds3"); |
||||||
|
MockWidget widget1 = EasyMock.mock(MockWidget.class); |
||||||
|
EasyMock.expect(widget1.getUsedTableDataSets()).andReturn(set).anyTimes(); |
||||||
|
EasyMock.replay(widget1); |
||||||
|
|
||||||
|
DataBinding dataBinding = new DataBinding("ds4", ""); |
||||||
|
WidgetValue widgetValue2 = new WidgetValue(); |
||||||
|
widgetValue2.setValue(dataBinding); |
||||||
|
AbstractDataControl widget2 = EasyMock.mock(AbstractDataControl.class); |
||||||
|
EasyMock.expect(widget2.getWidgetValue()).andReturn(widgetValue2).anyTimes(); |
||||||
|
EasyMock.replay(widget2); |
||||||
|
|
||||||
|
DataTableConfig dataTableConfig = EasyMock.mock(DataTableConfig.class); |
||||||
|
EasyMock.expect(dataTableConfig.getTableDataName()).andReturn("ds5").anyTimes(); |
||||||
|
WidgetValue widgetValue3 = new WidgetValue(); |
||||||
|
widgetValue3.setValue(dataTableConfig); |
||||||
|
AbstractDataControl widget3 = EasyMock.mock(AbstractDataControl.class); |
||||||
|
EasyMock.expect(widget3.getWidgetValue()).andReturn(widgetValue3).anyTimes(); |
||||||
|
EasyMock.replay(dataTableConfig, widget3); |
||||||
|
|
||||||
|
Widget[] widgets = new Widget[3]; |
||||||
|
widgets[0] = widget1; |
||||||
|
widgets[1] = widget2; |
||||||
|
widgets[2] = widget3; |
||||||
|
return widgets; |
||||||
|
} |
||||||
|
|
||||||
|
private class MockWidget extends Widget implements DictionaryContainer { |
||||||
|
|
||||||
|
@Override |
||||||
|
public String[] supportedEvents() { |
||||||
|
return new String[0]; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setDictionary(Dictionary model) { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Dictionary getDictionary() { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object getViewValue(Object value, Calculator c, TemplateSessionIDInfo sessionIDInfor, HttpServletRequest req) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object getModuleValue(Object text, Calculator c, TemplateSessionIDInfo sessionIDInfor, HttpServletRequest req) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object getViewValue(Object value, Calculator c, TemplateSessionIDInfo sessionIDInfor, HttpServletRequest req, NameSpace dependenceNameSpace) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object getModuleValue(Object text, Calculator c, TemplateSessionIDInfo sessionIDInfor, HttpServletRequest req, NameSpace dependenceNameSpace) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean isValueAllInDictionary(Object value, Calculator c, TemplateSessionIDInfo sessionIDInfor, HttpServletRequest req, NameSpace dependenceNameSpace) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getXType() { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean isEditor() { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setDependenceMap(Map dependenceMap) { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Map getDependenceMap() { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String[] dependence(CalculatorProvider calculatorProvider) { |
||||||
|
return new String[0]; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue