Browse Source

Merge pull request #7197 in DESIGN/design from release/10.0 to bugfix/10.0

* commit '1b0ae7b6eed937d07f7be3d7ac2bbf5dde6c795e':
  无jira任务 单元测试打包
bugfix/10.0
superman 3 years ago
parent
commit
4805c8a0c2
  1. 41
      designer-realize/src/test/java/com/fr/design/mainframe/app/DesignerAppUtilsTest.java

41
designer-realize/src/test/java/com/fr/design/mainframe/app/DesignerAppUtilsTest.java

@ -3,15 +3,11 @@ package com.fr.design.mainframe.app;
import com.fr.invoke.Reflect; import com.fr.invoke.Reflect;
import com.fr.plugin.context.PluginMarker; import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.context.PluginMarkerAdapter; import com.fr.plugin.context.PluginMarkerAdapter;
import com.fr.plugin.engine.remote.PluginRemoteSync;
import com.fr.stable.TemplateIOErrorContextHolder; import com.fr.stable.TemplateIOErrorContextHolder;
import com.fr.third.guava.collect.Multimap; import com.fr.third.guava.collect.Multimap;
import org.easymock.EasyMock;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; 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 org.powermock.modules.junit4.PowerMockRunner;
import java.util.Collection; import java.util.Collection;
@ -24,13 +20,12 @@ import java.util.HashSet;
* Created by vito on 2021/5/31 * Created by vito on 2021/5/31
*/ */
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({PluginRemoteSync.class})
public class DesignerAppUtilsTest { public class DesignerAppUtilsTest {
@Test @Test
public void testDealWithErrorDetailMultiLineAndCache() { public void testDealWithErrorDetailMultiLineAndCache() {
TemplateIOErrorContextHolder.registerPluginNameMap(new HashMap<String, String>() {{ TemplateIOErrorContextHolder.registerPluginNameMap(new HashMap<String, String>() {{
put("2", "好用的插件"); put("2", "好用的插件");
}},new HashSet<>()); }}, new HashSet<>());
TemplateIOErrorContextHolder.addNeedEnablePlugin(PluginMarkerAdapter.create("1", "1.0", "1插件")); TemplateIOErrorContextHolder.addNeedEnablePlugin(PluginMarkerAdapter.create("1", "1.0", "1插件"));
TemplateIOErrorContextHolder.addNeedInstallPlugin(PluginMarker.create("2", "1.0")); TemplateIOErrorContextHolder.addNeedInstallPlugin(PluginMarker.create("2", "1.0"));
TemplateIOErrorContextHolder.addNeedInstallPlugin(PluginMarker.create("3", "1.0")); TemplateIOErrorContextHolder.addNeedInstallPlugin(PluginMarker.create("3", "1.0"));
@ -47,7 +42,7 @@ public class DesignerAppUtilsTest {
public void testInvalidatePlugins() { public void testInvalidatePlugins() {
TemplateIOErrorContextHolder.registerPluginNameMap(new HashMap<String, String>() {{ TemplateIOErrorContextHolder.registerPluginNameMap(new HashMap<String, String>() {{
put("2", "好用的插件"); put("2", "好用的插件");
}},new HashSet<>()); }}, new HashSet<>());
TemplateIOErrorContextHolder.addNeedEnablePlugin(PluginMarkerAdapter.create("1", "1.0", "1插件")); TemplateIOErrorContextHolder.addNeedEnablePlugin(PluginMarkerAdapter.create("1", "1.0", "1插件"));
TemplateIOErrorContextHolder.addNeedInstallPlugin(PluginMarker.create("2", "1.0")); TemplateIOErrorContextHolder.addNeedInstallPlugin(PluginMarker.create("2", "1.0"));
TemplateIOErrorContextHolder.addNeedInstallPlugin(PluginMarker.create("3", "1.0")); TemplateIOErrorContextHolder.addNeedInstallPlugin(PluginMarker.create("3", "1.0"));
@ -60,19 +55,19 @@ public class DesignerAppUtilsTest {
} }
@Test @Test
public void testRearrange(){ public void testRearrange() {
// 远程插件模拟注册 // 远程插件模拟注册
PluginRemoteSync pluginRemoteSync = EasyMock.createMock(PluginRemoteSync.class); // PluginRemoteSync pluginRemoteSync = EasyMock.createMock(PluginRemoteSync.class);
EasyMock.expect(pluginRemoteSync.getPluginRemoteStatusByIdIndex()).andReturn(new HashMap<String, PluginRemoteSync.PluginStatus>(){{ // EasyMock.expect(pluginRemoteSync.getPluginRemoteStatusByIdIndex()).andReturn(new HashMap<String, PluginRemoteSync.PluginStatus>(){{
put("com.fr.plugin1", Reflect.on(PluginRemoteSync.PluginStatus.class).call("create","com.fr.plugin1","1",true).get()); // put("com.fr.plugin1", Reflect.on(PluginRemoteSync.PluginStatus.class).call("create","com.fr.plugin1","1",true).get());
put("com.fr.plugin2", Reflect.on(PluginRemoteSync.PluginStatus.class).call("create","com.fr.plugin2","1",true).get()); // put("com.fr.plugin2", Reflect.on(PluginRemoteSync.PluginStatus.class).call("create","com.fr.plugin2","1",true).get());
put("com.fr.plugin3", Reflect.on(PluginRemoteSync.PluginStatus.class).call("create","com.fr.plugin3","1",false).get()); // put("com.fr.plugin3", Reflect.on(PluginRemoteSync.PluginStatus.class).call("create","com.fr.plugin3","1",false).get());
put("com.fr.plugin4", Reflect.on(PluginRemoteSync.PluginStatus.class).call("create","com.fr.plugin4","1",false).get()); // put("com.fr.plugin4", Reflect.on(PluginRemoteSync.PluginStatus.class).call("create","com.fr.plugin4","1",false).get());
}}).anyTimes(); // }}).anyTimes();
EasyMock.replay(pluginRemoteSync); // EasyMock.replay(pluginRemoteSync);
PowerMock.mockStaticPartial(PluginRemoteSync.class, "getInstance"); // PowerMock.mockStaticPartial(PluginRemoteSync.class, "getInstance");
EasyMock.expect(PluginRemoteSync.getInstance()).andReturn(pluginRemoteSync).anyTimes(); // EasyMock.expect(PluginRemoteSync.getInstance()).andReturn(pluginRemoteSync).anyTimes();
PowerMock.replay(PluginRemoteSync.class); // PowerMock.replay(PluginRemoteSync.class);
// 本地插件模拟检查 // 本地插件模拟检查
TemplateIOErrorContextHolder.registerPluginNameMap(new HashMap<String, String>() {{ TemplateIOErrorContextHolder.registerPluginNameMap(new HashMap<String, String>() {{
@ -81,7 +76,7 @@ public class DesignerAppUtilsTest {
put("com.fr.plugin3", "好用的插件3"); put("com.fr.plugin3", "好用的插件3");
put("com.fr.plugin4", "好用的插件4"); put("com.fr.plugin4", "好用的插件4");
put("com.fr.plugin5", "好用的插件5"); put("com.fr.plugin5", "好用的插件5");
}},new HashSet<>()); }}, new HashSet<>());
// unknown // unknown
TemplateIOErrorContextHolder.addNeedInstallPlugin(PluginMarker.create("com.fr.plugin7", "1")); TemplateIOErrorContextHolder.addNeedInstallPlugin(PluginMarker.create("com.fr.plugin7", "1"));
// disable // disable
@ -93,14 +88,14 @@ public class DesignerAppUtilsTest {
Multimap<String, PluginMarkerAdapter> pendingPlugins = TemplateIOErrorContextHolder.getPendingPlugin(); Multimap<String, PluginMarkerAdapter> pendingPlugins = TemplateIOErrorContextHolder.getPendingPlugin();
Reflect.on(DesignerAppUtils.class).call("rearrange",pendingPlugins).get(); Reflect.on(DesignerAppUtils.class).call("rearrange", pendingPlugins).get();
Assert.assertEquals(1,pendingPlugins.get(TemplateIOErrorContextHolder.UNKNOWN_PLUGIN).size()); Assert.assertEquals(1, pendingPlugins.get(TemplateIOErrorContextHolder.UNKNOWN_PLUGIN).size());
Collection<PluginMarkerAdapter> pluginMarkerAdapters = pendingPlugins.get(TemplateIOErrorContextHolder.DISABLE_PLUGIN); Collection<PluginMarkerAdapter> pluginMarkerAdapters = pendingPlugins.get(TemplateIOErrorContextHolder.DISABLE_PLUGIN);
Assert.assertEquals(2, pluginMarkerAdapters.size()); Assert.assertEquals(2, pluginMarkerAdapters.size());
pluginMarkerAdapters.contains(PluginMarker.create("com.fr.plugin3", "1")); pluginMarkerAdapters.contains(PluginMarker.create("com.fr.plugin3", "1"));
pluginMarkerAdapters.contains(PluginMarker.create("com.fr.plugin4", "1")); pluginMarkerAdapters.contains(PluginMarker.create("com.fr.plugin4", "1"));
Collection<PluginMarkerAdapter> pluginMarkerAdapters1 = pendingPlugins.get(TemplateIOErrorContextHolder.NOT_INSTALLED_PLUGIN); Collection<PluginMarkerAdapter> pluginMarkerAdapters1 = pendingPlugins.get(TemplateIOErrorContextHolder.NOT_INSTALLED_PLUGIN);
Assert.assertEquals(1, pluginMarkerAdapters1.size()); Assert.assertEquals(1, pluginMarkerAdapters1.size());
pluginMarkerAdapters1.contains(PluginMarker.create("com.fr.plugin5","1")); pluginMarkerAdapters1.contains(PluginMarker.create("com.fr.plugin5", "1"));
} }
} }
Loading…
Cancel
Save