From 815be5bc1ba2ec74224e78c3110725a506145a08 Mon Sep 17 00:00:00 2001 From: Ali Hamdi Date: Thu, 19 Oct 2023 18:08:41 +0100 Subject: [PATCH 1/2] fix: stabilize unit test SpaceApplicationMigrationTest - EXO-66907 --- .../migration/SpaceApplicationMigrationTest.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/data-upgrade-pages/src/test/java/org/exoplatform/migration/SpaceApplicationMigrationTest.java b/data-upgrade-pages/src/test/java/org/exoplatform/migration/SpaceApplicationMigrationTest.java index 270fd0a56..965074b36 100644 --- a/data-upgrade-pages/src/test/java/org/exoplatform/migration/SpaceApplicationMigrationTest.java +++ b/data-upgrade-pages/src/test/java/org/exoplatform/migration/SpaceApplicationMigrationTest.java @@ -22,6 +22,8 @@ import org.exoplatform.social.core.space.*; import org.exoplatform.social.core.space.model.Space; import org.exoplatform.social.core.space.spi.SpaceService; +import org.gatein.pc.api.PortletInvoker; +import org.gatein.pc.api.PortletInvokerException; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -32,6 +34,8 @@ import java.util.HashSet; import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) @ConfiguredBy({ @@ -60,13 +64,17 @@ public SpaceApplicationMigrationTest() { } @Before - public void setUp() { + public void setUp() throws PortletInvokerException { container = getContainer(); this.spaceService = container.getComponentInstanceOfType(SpaceService.class); this.navigationService = container.getComponentInstanceOfType(NavigationService.class); this.identityRegistry = container.getComponentInstanceOfType(IdentityRegistry.class); this.entityManagerService = container.getComponentInstanceOfType(EntityManagerService.class); this.settingService = container.getComponentInstanceOfType(SettingService.class); + PortletInvoker portletInvoker = mock(PortletInvoker.class); + when(portletInvoker.getPortlets()).thenReturn(new HashSet<>()); + container.unregisterComponent(PortletInvoker.class); + container.registerComponentInstance(PortletInvoker.class, portletInvoker); HashSet memberships = new HashSet(); memberships.add(new MembershipEntry("/platform/users", "*")); memberships.add(new MembershipEntry("/platform/administrators", "*")); From 6f32650e13d9d51ba145796c8668d94a7724c352 Mon Sep 17 00:00:00 2001 From: Ali Hamdi Date: Thu, 19 Oct 2023 19:11:51 +0100 Subject: [PATCH 2/2] fix: stabilize unit test SpaceApplicationMigrationTest - EXO-66907 --- .../SpaceApplicationMigrationTest.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/data-upgrade-pages/src/test/java/org/exoplatform/migration/SpaceApplicationMigrationTest.java b/data-upgrade-pages/src/test/java/org/exoplatform/migration/SpaceApplicationMigrationTest.java index 965074b36..c8813b903 100644 --- a/data-upgrade-pages/src/test/java/org/exoplatform/migration/SpaceApplicationMigrationTest.java +++ b/data-upgrade-pages/src/test/java/org/exoplatform/migration/SpaceApplicationMigrationTest.java @@ -22,8 +22,11 @@ import org.exoplatform.social.core.space.*; import org.exoplatform.social.core.space.model.Space; import org.exoplatform.social.core.space.spi.SpaceService; +import org.gatein.pc.api.Portlet; +import org.gatein.pc.api.PortletContext; import org.gatein.pc.api.PortletInvoker; import org.gatein.pc.api.PortletInvokerException; +import org.gatein.pc.api.info.PortletInfo; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -31,6 +34,7 @@ import org.mockito.junit.MockitoJUnitRunner; +import java.util.Collections; import java.util.HashSet; import static org.junit.Assert.*; @@ -72,7 +76,23 @@ public void setUp() throws PortletInvokerException { this.entityManagerService = container.getComponentInstanceOfType(EntityManagerService.class); this.settingService = container.getComponentInstanceOfType(SettingService.class); PortletInvoker portletInvoker = mock(PortletInvoker.class); - when(portletInvoker.getPortlets()).thenReturn(new HashSet<>()); + Portlet portlet = new Portlet() { + @Override + public PortletContext getContext() { + return null; + } + + @Override + public PortletInfo getInfo() { + return null; + } + + @Override + public boolean isRemote() { + return false; + } + }; + when(portletInvoker.getPortlets()).thenReturn(Collections.singleton(portlet)); container.unregisterComponent(PortletInvoker.class); container.registerComponentInstance(PortletInvoker.class, portletInvoker); HashSet memberships = new HashSet();