Skip to content

Commit

Permalink
Improved
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Apr 1, 2022
1 parent 8852bca commit c3b753b
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
*/
package com.helger.phase4.profile.bpc;

import java.util.function.Supplier;

import javax.annotation.Nonnull;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.helger.commons.annotation.IsSPIImplementation;
import com.helger.phase4.model.pmode.IPModeIDProvider;
import com.helger.phase4.profile.AS4Profile;
import com.helger.phase4.profile.IAS4ProfilePModeProvider;
import com.helger.phase4.profile.IAS4ProfileRegistrar;
import com.helger.phase4.profile.IAS4ProfileRegistrarSPI;
import com.helger.phase4.profile.IAS4ProfileValidator;

/**
* Library specific implementation of {@link IAS4ProfileRegistrarSPI}.
Expand All @@ -36,17 +36,25 @@
@IsSPIImplementation
public final class AS4BPCProfileRegistarSPI implements IAS4ProfileRegistrarSPI
{
public static final String AS4_PROFILE_ID = "bpc";
public static final String AS4_PROFILE_NAME = "BPC";
public static final String AS4_PROFILE_ID = "bpc-mp";
public static final String AS4_PROFILE_NAME = "BPC Market Pilot";
public static final IPModeIDProvider PMODE_ID_PROVIDER = IPModeIDProvider.DEFAULT_DYNAMIC;

private static final Logger LOGGER = LoggerFactory.getLogger (AS4BPCProfileRegistarSPI.class);

public void registerAS4Profile (@Nonnull final IAS4ProfileRegistrar aRegistrar)
{
final Supplier <? extends IAS4ProfileValidator> aProfileValidatorProvider = () -> new BPCCompatibilityValidator ();
final IAS4ProfilePModeProvider aDefaultPModeProvider = (i, r, a) -> BPCPMode.createBPCPMode (i, r, a, true);
final IAS4ProfilePModeProvider aDefaultPModeProvider = (i, r, a) -> BPCPMode.createBPCPMode (i,
r,
a,
PMODE_ID_PROVIDER,
true);

if (LOGGER.isDebugEnabled ())
LOGGER.debug ("Registering phase4 profile '" + AS4_PROFILE_ID + "'");
final AS4Profile aProfile = new AS4Profile (AS4_PROFILE_ID,
AS4_PROFILE_NAME,
aProfileValidatorProvider,
BPCCompatibilityValidator::new,
aDefaultPModeProvider,
PMODE_ID_PROVIDER,
false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,21 @@ private static void _checkIfLegIsValid (@Nonnull final ErrorList aErrorList,
aErrorList.add (_createError (sFieldPrefix + "ErrorHandling.Report.ProcessErrorNotifyConsumer is missing"));
}

if (aErrorHandling.isReportProcessErrorNotifyProducerDefined ())
{
if (!aErrorHandling.isReportProcessErrorNotifyProducer ())
aErrorList.add (_createWarn (sFieldPrefix + "ErrorHandling.Report.ProcessErrorNotifyProducer should be 'true'"));
}
else
{
aErrorList.add (_createError (sFieldPrefix + "ErrorHandling.Report.ProcessErrorNotifyProducer is missing"));
}

if (aErrorHandling.isReportDeliveryFailuresNotifyProducerDefined ())
{
if (!aErrorHandling.isReportDeliveryFailuresNotifyProducer ())
aErrorList.add (_createError (sFieldPrefix +
"ErrorHandling.Report.DeliveryFailuresNotifyProducer must be 'true'"));
aErrorList.add (_createWarn (sFieldPrefix +
"ErrorHandling.Report.DeliveryFailuresNotifyProducer should be 'true'"));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.helger.phase4.mgr.MetaAS4Manager;
import com.helger.phase4.model.EMEP;
import com.helger.phase4.model.EMEPBinding;
import com.helger.phase4.model.pmode.IPModeIDProvider;
import com.helger.phase4.model.pmode.PMode;
import com.helger.phase4.model.pmode.PModeParty;
import com.helger.phase4.model.pmode.PModePayloadService;
Expand Down Expand Up @@ -86,6 +87,7 @@ public static PModeLegErrorHandling generatePModeLegErrorHandling ()
final ETriState eReportAsResponse = ETriState.TRUE;
final ETriState eReportProcessErrorNotifyConsumer = ETriState.TRUE;
final ETriState eReportProcessErrorNotifyProducer = ETriState.TRUE;
// Called Report.MissingReceiptNotifyProducer in BPC
final ETriState eReportDeliveryFailuresNotifyProducer = ETriState.TRUE;
return new PModeLegErrorHandling (aReportSenderErrorsTo,
aReportReceiverErrorsTo,
Expand All @@ -112,9 +114,9 @@ public static PModeLegSecurity generatePModeLegSecurity ()
}

@Nonnull
public static PModeLeg generatePModeLeg (@Nullable final String sResponderAddress)
public static PModeLeg generatePModeLeg (@Nullable final String sAddress)
{
return new PModeLeg (generatePModeLegProtocol (sResponderAddress),
return new PModeLeg (generatePModeLegProtocol (sAddress),
generatePModeLegBusinessInformation (),
generatePModeLegErrorHandling (),
(PModeLegReliability) null,
Expand Down Expand Up @@ -147,11 +149,13 @@ public static PModeParty createParty (@Nonnull @Nonempty final String sPartyID,
* One-Way Version of the BPC pmode uses one-way push
*
* @param sInitiatorID
* Initiator ID
* Initiator ID. May neither be <code>null</code> nor empty.
* @param sResponderID
* Responder ID
* @param sResponderAddress
* Responder URL
* Responder ID. May neither be <code>null</code> nor empty.
* @param sAddress
* Endpoint address URL. May be <code>null</code>.
* @param aPModeIDProvider
* PMode ID provider. May not be <code>null</code>.
* @param bPersist
* <code>true</code> to persist the PMode in the PModeManager,
* <code>false</code> to have it only in memory.
Expand All @@ -160,19 +164,20 @@ public static PModeParty createParty (@Nonnull @Nonempty final String sPartyID,
@Nonnull
public static PMode createBPCPMode (@Nonnull @Nonempty final String sInitiatorID,
@Nonnull @Nonempty final String sResponderID,
@Nullable final String sResponderAddress,
@Nullable final String sAddress,
@Nonnull final IPModeIDProvider aPModeIDProvider,
final boolean bPersist)
{
final PModeParty aInitiator = createParty (sInitiatorID, CAS4.DEFAULT_INITIATOR_URL);
final PModeParty aResponder = createParty (sResponderID, CAS4.DEFAULT_RESPONDER_URL);

final PMode aPMode = new PMode (aInitiator.getID () + "-" + aResponder.getID (),
final PMode aPMode = new PMode (aPModeIDProvider.getPModeID (sInitiatorID, sResponderID),
aInitiator,
aResponder,
DEFAULT_AGREEMENT_ID,
EMEP.ONE_WAY,
EMEPBinding.PUSH,
generatePModeLeg (sResponderAddress),
generatePModeLeg (sAddress),
(PModeLeg) null,
(PModePayloadService) null,
generatePModeReceptionAwareness ());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.helger.phase4.messaging.domain.MessageHelperMethods;
import com.helger.phase4.model.EMEP;
import com.helger.phase4.model.EMEPBinding;
import com.helger.phase4.model.pmode.IPModeIDProvider;
import com.helger.phase4.model.pmode.PMode;
import com.helger.phase4.model.pmode.leg.EPModeSendReceiptReplyPattern;
import com.helger.phase4.model.pmode.leg.PModeLeg;
Expand Down Expand Up @@ -73,7 +74,11 @@ public final class BPCCompatibilityValidatorTest
public void before ()
{
m_aErrorList = new ErrorList ();
m_aPMode = BPCPMode.createBPCPMode ("TestInitiator", "TestResponder", "http://localhost:8080", true);
m_aPMode = BPCPMode.createBPCPMode ("TestInitiator",
"TestResponder",
"http://localhost:8080",
IPModeIDProvider.DEFAULT_DYNAMIC,
true);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.ClassRule;
import org.junit.Test;

import com.helger.phase4.model.pmode.IPModeIDProvider;
import com.helger.phase4.model.pmode.PMode;
import com.helger.photon.app.mock.PhotonAppWebTestRule;

Expand All @@ -32,12 +33,16 @@
public final class BPCPModeTest
{
@ClassRule
public static final PhotonAppWebTestRule s_aRule = new PhotonAppWebTestRule ();
public static final PhotonAppWebTestRule RULE = new PhotonAppWebTestRule ();

@Test
public void testBPCPMode ()
{
final PMode aPMode = BPCPMode.createBPCPMode ("TestInitiator", "TestResponder", "https://test.example.org", false);
final PMode aPMode = BPCPMode.createBPCPMode ("TestInitiator",
"TestResponder",
"https://test.example.org",
IPModeIDProvider.DEFAULT_DYNAMIC,
false);
assertNotNull (aPMode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@
*/
package com.helger.phase4.profile.cef;

import static org.junit.Assert.assertNotNull;

import org.junit.ClassRule;
import org.junit.Test;

import com.helger.phase4.model.pmode.IPModeIDProvider;
import com.helger.phase4.model.pmode.PMode;
import com.helger.photon.app.mock.PhotonAppWebTestRule;

/**
* Test class for class {@link CEFPMode}.
*
*
* @author Philip Helger
*/
public final class CEFPModeTest
Expand All @@ -35,12 +38,22 @@ public final class CEFPModeTest
@Test
public void testCEFPMode ()
{
CEFPMode.createCEFPMode ("TestInitiator", "TestResponder", "https://test.example.org", IPModeIDProvider.DEFAULT_DYNAMIC, false);
final PMode aPMode = CEFPMode.createCEFPMode ("TestInitiator",
"TestResponder",
"https://test.example.org",
IPModeIDProvider.DEFAULT_DYNAMIC,
false);
assertNotNull (aPMode);
}

@Test
public void testCEFPModeTwoWay ()
{
CEFPMode.createCEFPModeTwoWay ("TestInitiator", "TestResponder", "https://test.example.org", IPModeIDProvider.DEFAULT_DYNAMIC, false);
final PMode aPMode = CEFPMode.createCEFPModeTwoWay ("TestInitiator",
"TestResponder",
"https://test.example.org",
IPModeIDProvider.DEFAULT_DYNAMIC,
false);
assertNotNull (aPMode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,33 @@
*/
package com.helger.phase4.profile.peppol;

import static org.junit.Assert.assertNotNull;

import org.junit.ClassRule;
import org.junit.Test;

import com.helger.phase4.model.pmode.IPModeIDProvider;
import com.helger.phase4.model.pmode.PMode;
import com.helger.photon.app.mock.PhotonAppWebTestRule;

/**
* Test class for class {@link PeppolPMode}
*
*
* @author Philip Helger
*/
public final class PeppolPModeTest
{
@ClassRule
public static final PhotonAppWebTestRule s_aRule = new PhotonAppWebTestRule ();
public static final PhotonAppWebTestRule RULE = new PhotonAppWebTestRule ();

@Test
public void testCEFPMode ()
{
PeppolPMode.createPeppolPMode ("TestInitiator", "TestResponder", "https://test.example.org", IPModeIDProvider.DEFAULT_DYNAMIC, false);
final PMode aPMode = PeppolPMode.createPeppolPMode ("TestInitiator",
"TestResponder",
"https://test.example.org",
IPModeIDProvider.DEFAULT_DYNAMIC,
false);
assertNotNull (aPMode);
}
}

0 comments on commit c3b753b

Please sign in to comment.