Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand transport profiles detection with a filtering by modes #624

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import network.oxalis.api.lang.OxalisTransmissionException;
import network.oxalis.api.outbound.MessageSender;
import network.oxalis.vefa.peppol.common.model.TransportProfile;
import network.oxalis.vefa.peppol.mode.Mode;

import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -64,7 +65,7 @@ class MessageSenderFactory {
private final List<TransportProfile> prioritizedTransportProfiles;

@Inject
public MessageSenderFactory(Injector injector, Config config) {
public MessageSenderFactory(Injector injector, Config config, Mode mode) {
this.injector = injector;

// Construct map of configuration for detected transport profiles.
Expand All @@ -75,6 +76,7 @@ public MessageSenderFactory(Injector injector, Config config) {
// Create prioritized list of transport profiles.
prioritizedTransportProfiles = Collections.unmodifiableList(configMap.values().stream()
.filter(o -> !o.hasPath("enabled") || o.getBoolean("enabled"))
.filter(o -> !o.hasPath("modes") || o.getStringList("modes").contains(mode.getIdentifier()))
.sorted((o1, o2) -> Integer.compare(o2.getInt("weight"), o1.getInt("weight")))
.map(o -> o.getString("profile"))
.map(TransportProfile::of)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.testng.annotations.Guice;
import org.testng.annotations.Test;

import java.util.List;

@Guice(modules = GuiceModuleLoader.class)
public class MessageSenderFactoryTest {

Expand All @@ -52,4 +54,18 @@ public void validTransportProfile() throws OxalisTransmissionException {
public void invalidTransportProfile() throws OxalisTransmissionException {
messageSenderFactory.getMessageSender(TransportProfile.START);
}

@Test
public void canDisableTransportProfileByMode() {
List<TransportProfile> transportProfileList = messageSenderFactory.getPrioritizedTransportProfiles();
Assert.assertNotNull(transportProfileList);
Assert.assertFalse(transportProfileList.stream().anyMatch(t -> t.getIdentifier().equals("foo-mode-transport")), "should not contain transport which is only enabled in other modes");
}

@Test
public void canEnableTransportProfileByMode() {
List<TransportProfile> transportProfileList = messageSenderFactory.getPrioritizedTransportProfiles();
Assert.assertNotNull(transportProfileList);
Assert.assertTrue(transportProfileList.stream().anyMatch(t -> t.getIdentifier().equals("dummy-mode-transport")), "should contain transport which is only enabled in DUMMY mode");
}
}
14 changes: 14 additions & 0 deletions oxalis-outbound/src/test/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ defaults.transport.invalid = {
weight: 0
}

defaults.transport.foo_mode_transport = {
profile: foo-mode-transport
sender: invalid
weight: 0
modes: [foo, foo_test]
}

defaults.transport.dummy_mode_transport = {
profile: dummy-mode-transport
sender: invalid
weight: -1
modes: [DUMMY]
}

oxalis.statistics.service = noop

oxalis.asd.sender.skip = true