Skip to content

Commit

Permalink
align enhancer integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
floriangantner committed Feb 22, 2024
1 parent 5ab97e4 commit 81aa4a4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import static org.dspace.app.matcher.MetadataValueMatcher.with;
import static org.dspace.content.Item.ANY;
import static org.dspace.content.enhancer.consumer.ItemEnhancerConsumer.ITEMENHANCER_ENABLED;
import static org.dspace.core.CrisConstants.PLACEHOLDER_PARENT_METADATA_VALUE;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
Expand Down Expand Up @@ -47,6 +48,10 @@

public class ItemEnhancerByDateScriptIT extends AbstractIntegrationTestWithDatabase {

private static ConfigurationService configService = DSpaceServicesFactory.getInstance().getConfigurationService();

private static final EventService eventService = EventServiceFactory.getInstance().getEventService();
private static boolean isEnabled;
private static String[] consumers;

private ItemService itemService;
Expand All @@ -60,32 +65,33 @@ public class ItemEnhancerByDateScriptIT extends AbstractIntegrationTestWithDatab
*/
@BeforeClass
public static void initConsumers() {
ConfigurationService configService = DSpaceServicesFactory.getInstance().getConfigurationService();
consumers = configService.getArrayProperty("event.dispatcher.default.consumers");
Set<String> consumersSet = new HashSet<String>(Arrays.asList(consumers));
consumersSet.remove("itemenhancer");
configService.setProperty("event.dispatcher.default.consumers", consumersSet.toArray());
EventService eventService = EventServiceFactory.getInstance().getEventService();
eventService.reloadConfiguration();
if (!consumersSet.contains("itemenhancer")) {
consumersSet.add("itemenhancer");
configService.setProperty("event.dispatcher.default.consumers", consumersSet.toArray());
eventService.reloadConfiguration();
}
}

/**
* Reset the event.dispatcher.default.consumers property value.
*/
@AfterClass
public static void resetDefaultConsumers() {
ConfigurationService configService = DSpaceServicesFactory.getInstance().getConfigurationService();
configService.setProperty("event.dispatcher.default.consumers", consumers);
EventService eventService = EventServiceFactory.getInstance().getEventService();
eventService.reloadConfiguration();
}

@Before
public void setup() {

configService.setProperty(ITEMENHANCER_ENABLED, false);

itemService = ContentServiceFactory.getInstance().getItemService();

context.turnOffAuthorisationSystem();

parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import static org.dspace.app.matcher.MetadataValueMatcher.with;
import static org.dspace.content.Item.ANY;
import static org.dspace.content.enhancer.consumer.ItemEnhancerConsumer.ITEMENHANCER_ENABLED;
import static org.dspace.core.CrisConstants.PLACEHOLDER_PARENT_METADATA_VALUE;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
Expand Down Expand Up @@ -47,8 +48,11 @@

public class ItemEnhancerEntityTypeScriptIT extends AbstractIntegrationTestWithDatabase {

private static final ConfigurationService configService =
DSpaceServicesFactory.getInstance().getConfigurationService();
private static final EventService eventService = EventServiceFactory.getInstance().getEventService();
private static String[] consumers;

private static boolean isEnabled;
private ItemService itemService;

private Collection collection;
Expand All @@ -60,32 +64,33 @@ public class ItemEnhancerEntityTypeScriptIT extends AbstractIntegrationTestWithD
*/
@BeforeClass
public static void initConsumers() {
ConfigurationService configService = DSpaceServicesFactory.getInstance().getConfigurationService();
consumers = configService.getArrayProperty("event.dispatcher.default.consumers");
Set<String> consumersSet = new HashSet<String>(Arrays.asList(consumers));
consumersSet.remove("itemenhancer");
configService.setProperty("event.dispatcher.default.consumers", consumersSet.toArray());
EventService eventService = EventServiceFactory.getInstance().getEventService();
eventService.reloadConfiguration();
if (!consumersSet.contains("itemenhancer")) {
consumersSet.add("itemenhancer");
configService.setProperty("event.dispatcher.default.consumers", consumersSet.toArray());
eventService.reloadConfiguration();
}
}

/**
* Reset the event.dispatcher.default.consumers property value.
*/
@AfterClass
public static void resetDefaultConsumers() {
ConfigurationService configService = DSpaceServicesFactory.getInstance().getConfigurationService();
configService.setProperty("event.dispatcher.default.consumers", consumers);
EventService eventService = EventServiceFactory.getInstance().getEventService();
eventService.reloadConfiguration();
}

@Before
public void setup() {

configService.setProperty(ITEMENHANCER_ENABLED, false);

itemService = ContentServiceFactory.getInstance().getItemService();

context.turnOffAuthorisationSystem();

parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Expand Down

0 comments on commit 81aa4a4

Please sign in to comment.