You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
4.5 KiB
103 lines
4.5 KiB
6 years ago
|
package com.fr.design.mainframe;
|
||
|
|
||
2 years ago
|
import com.fr.base.theme.FormTheme;
|
||
2 years ago
|
import com.fr.base.theme.FormThemeConfig;
|
||
2 years ago
|
import com.fr.base.theme.ReportThemeConfig;
|
||
2 years ago
|
import com.fr.base.theme.TemplateTheme;
|
||
|
import com.fr.base.theme.TemplateThemeConfig;
|
||
6 years ago
|
import com.fr.config.dao.DaoContext;
|
||
|
import com.fr.config.dao.impl.LocalClassHelperDao;
|
||
|
import com.fr.config.dao.impl.LocalEntityDao;
|
||
|
import com.fr.config.dao.impl.LocalXmlEntityDao;
|
||
4 years ago
|
import com.fr.design.mainframe.theme.utils.DefaultThemedTemplateCellElementCase;
|
||
6 years ago
|
import com.fr.form.main.Form;
|
||
|
import com.fr.form.ui.ElementCaseEditor;
|
||
2 years ago
|
import com.fr.form.ui.container.WFitLayout;
|
||
6 years ago
|
import com.fr.general.ImageWithSuffix;
|
||
|
import com.fr.general.ModuleContext;
|
||
2 years ago
|
import com.fr.invoke.Reflect;
|
||
6 years ago
|
import com.fr.main.impl.WorkBook;
|
||
|
import com.fr.report.cell.TemplateCellElement;
|
||
|
import com.fr.report.cell.cellattr.CellImage;
|
||
|
import com.fr.report.restriction.CellCountRestriction;
|
||
|
import com.fr.report.restriction.ReportRestrictionScene;
|
||
|
import com.fr.report.worksheet.FormElementCase;
|
||
|
import com.fr.report.worksheet.WorkSheet;
|
||
|
import com.fr.restriction.Restrictions;
|
||
|
import com.fr.stable.module.Module;
|
||
5 years ago
|
import com.fr.start.MainDesigner;
|
||
2 years ago
|
import com.fr.third.guava.collect.Lists;
|
||
6 years ago
|
import junit.framework.TestCase;
|
||
|
import org.junit.Assert;
|
||
2 months ago
|
import org.junit.Ignore;
|
||
2 years ago
|
import org.junit.runner.RunWith;
|
||
|
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||
6 years ago
|
|
||
|
import java.awt.image.BufferedImage;
|
||
2 years ago
|
import java.util.HashMap;
|
||
|
import java.util.Map;
|
||
6 years ago
|
|
||
2 years ago
|
@RunWith(PowerMockRunner.class)
|
||
|
@PowerMockIgnore("javax.swing.*")
|
||
6 years ago
|
public class JFileTest extends TestCase {
|
||
|
@Override
|
||
|
protected void setUp() throws Exception {
|
||
|
DaoContext.setEntityDao(new LocalEntityDao());
|
||
|
DaoContext.setClassHelperDao(new LocalClassHelperDao());
|
||
|
DaoContext.setXmlEntityDao(new LocalXmlEntityDao());
|
||
|
Restrictions.register(ReportRestrictionScene.CELL_COUNT, new CellCountRestriction());
|
||
|
ModuleContext.startModule(Module.PAGE_MODULE);
|
||
|
ModuleContext.startModule(Module.VIEW_MODULE);
|
||
5 years ago
|
MainDesigner designer = new MainDesigner(new String[0]);
|
||
6 years ago
|
}
|
||
|
|
||
2 months ago
|
@Ignore("涉及到UI")
|
||
6 years ago
|
public void testJWorkBookSetPicture() {
|
||
6 years ago
|
WorkBook workBook = new WorkBook();
|
||
|
WorkSheet workSheet = new WorkSheet();
|
||
|
workBook.addReport("sheet1", workSheet);
|
||
4 years ago
|
TemplateCellElement cellElement = DefaultThemedTemplateCellElementCase.createInstance();
|
||
6 years ago
|
workSheet.addCellElement(cellElement);
|
||
|
ImageWithSuffix imageWithSuffix = ImageWithSuffix.build(new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB), "jpg");
|
||
|
CellImage cellImage = new CellImage();
|
||
|
cellImage.setImage(imageWithSuffix);
|
||
2 years ago
|
mockJCreateConfigEnv(ReportThemeConfig.getInstance());
|
||
6 years ago
|
JWorkBook jWorkBook = new JWorkBook(workBook, "text");
|
||
|
jWorkBook.setPictureElem(cellElement, cellImage);
|
||
|
Assert.assertEquals(imageWithSuffix, cellElement.getValue());
|
||
|
}
|
||
|
|
||
2 months ago
|
@Ignore("涉及到UI")
|
||
6 years ago
|
public void testJFormSetPicture() {
|
||
6 years ago
|
Form form = new Form();
|
||
|
ElementCaseEditor editor = new ElementCaseEditor();
|
||
|
FormElementCase elementCase = new FormElementCase();
|
||
4 years ago
|
TemplateCellElement cellElement = DefaultThemedTemplateCellElementCase.createInstance();
|
||
6 years ago
|
elementCase.addCellElement(cellElement);
|
||
|
editor.setElementCase(elementCase);
|
||
|
form.getContainer().addWidget(editor);
|
||
|
ImageWithSuffix imageWithSuffix = ImageWithSuffix.build(new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB), "jpg");
|
||
|
CellImage cellImage = new CellImage();
|
||
|
cellImage.setImage(imageWithSuffix);
|
||
2 years ago
|
mockJCreateConfigEnv(FormThemeConfig.getInstance());
|
||
|
form.setContainer(new WFitLayout());
|
||
|
JForm jForm = new JForm(form);
|
||
6 years ago
|
jForm.setTarget(form);
|
||
|
jForm.setPictureElem(cellElement, cellImage);
|
||
|
Assert.assertEquals(imageWithSuffix, cellElement.getValue());
|
||
|
}
|
||
2 years ago
|
|
||
|
private void mockJCreateConfigEnv(TemplateThemeConfig instance) {
|
||
|
Reflect.on(instance).field("themeName4NewTemplate").call("set", "test");
|
||
|
TemplateThemeConfig.OrderedNameList list = new TemplateThemeConfig.OrderedNameList();
|
||
|
list.setThemeNames(Lists.newArrayList("test"));
|
||
|
Reflect.on(instance).field("themeNameList").call("set", list);
|
||
|
TemplateTheme testTheme = new FormTheme();
|
||
|
testTheme.setDark(false);
|
||
|
testTheme.setName("test");
|
||
|
Map<String, TemplateTheme> testMap = new HashMap<>();
|
||
|
testMap.put("test", testTheme);
|
||
|
Reflect.on(instance).call("put", "test", testTheme, true);
|
||
|
}
|
||
6 years ago
|
}
|