From 323deb6509b1bdc9ad7ed8c4145c9c15ed178813 Mon Sep 17 00:00:00 2001 From: Philip Helger Date: Fri, 15 Sep 2023 13:01:02 +0200 Subject: [PATCH] Specific test profile --- phase4-peppol-client/pom.xml | 4 + phase4-test/pom.xml | 5 +- .../profile/AS4TestProfileRegistarSPI.java | 72 +++++ .../helger/phase4/test/profile/TestPMode.java | 226 ++++++++++++++++ .../TestProfileCompatibilityValidator.java | 248 ++++++++++++++++++ .../servlet/AS4WebAppListener.java | 2 +- ...ger.phase4.profile.IAS4ProfileRegistrarSPI | 1 + phase4-test/src/main/webapp/WEB-INF/web.xml | 4 +- .../phase4/CEF/AS4eSENSCEFOneWayFuncTest.java | 8 +- .../phase4/CEF/AbstractCEFTestSetUp.java | 4 +- .../CEF/AbstractCEFTwoWayTestSetUp.java | 18 +- ...onfig.java => ScopedAS4Configuration.java} | 18 +- .../client/AS4ClientUserMessageTest.java | 4 +- .../helger/phase4/server/AS4JettyRunner.java | 43 +++ .../phase4/server/AbstractAS4TestSetUp.java | 6 +- .../helger/phase4/server/MockJettySetup.java | 5 +- .../phase4/server/MockPModeGenerator.java | 2 + .../server/external/AS4_NETFuncTest.java | 6 +- .../server/external/HolodeckFuncTest.java | 6 +- .../external/HolodeckOnlineTestSuite.java | 6 +- .../server/external/HolodeckTestSuite.java | 6 +- .../message/AbstractUserMessageTestSetUp.java | 4 +- .../UserMessageManyAttachmentTest.java | 89 +++---- .../phase4/server/servlet/CEFProfileTest.java | 4 +- .../servlet/TwoWayAsyncPullPushTest.java | 4 +- .../servlet/TwoWayAsyncPushPullTest.java | 4 +- .../phase4/server/servlet/TwoWayMEPTest.java | 4 +- .../spi/MockPullRequestProcessorSPI.java | 4 +- .../standalone/RunInJettyAS4TEST9090.java | 6 +- 29 files changed, 696 insertions(+), 117 deletions(-) create mode 100644 phase4-test/src/main/java/com/helger/phase4/test/profile/AS4TestProfileRegistarSPI.java create mode 100644 phase4-test/src/main/java/com/helger/phase4/test/profile/TestPMode.java create mode 100644 phase4-test/src/main/java/com/helger/phase4/test/profile/TestProfileCompatibilityValidator.java rename phase4-test/src/main/java/com/helger/phase4/{server => test}/servlet/AS4WebAppListener.java (98%) create mode 100644 phase4-test/src/main/resources/META-INF/services/com.helger.phase4.profile.IAS4ProfileRegistrarSPI rename phase4-test/src/test/java/com/helger/phase4/{ScopedConfig.java => ScopedAS4Configuration.java} (83%) create mode 100644 phase4-test/src/test/java/com/helger/phase4/server/AS4JettyRunner.java diff --git a/phase4-peppol-client/pom.xml b/phase4-peppol-client/pom.xml index ec50b9292..15a09a3d5 100644 --- a/phase4-peppol-client/pom.xml +++ b/phase4-peppol-client/pom.xml @@ -87,6 +87,10 @@ + + com.helger.commons + ph-commons + com.helger.phase4 phase4-lib diff --git a/phase4-test/pom.xml b/phase4-test/pom.xml index 10f6d8312..ebbe9cdb5 100644 --- a/phase4-test/pom.xml +++ b/phase4-test/pom.xml @@ -68,14 +68,11 @@ com.helger.phase4 phase4-lib - - com.helger.phase4 - phase4-profile-cef - com.helger.photon ph-oton-core + org.apache.logging.log4j log4j-core diff --git a/phase4-test/src/main/java/com/helger/phase4/test/profile/AS4TestProfileRegistarSPI.java b/phase4-test/src/main/java/com/helger/phase4/test/profile/AS4TestProfileRegistarSPI.java new file mode 100644 index 000000000..18b9c5c57 --- /dev/null +++ b/phase4-test/src/main/java/com/helger/phase4/test/profile/AS4TestProfileRegistarSPI.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2015-2023 Philip Helger (www.helger.com) + * philip[at]helger[dot]com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.helger.phase4.test.profile; + +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.EProfileRequirement; +import com.helger.phase4.profile.IAS4ProfilePModeProvider; +import com.helger.phase4.profile.IAS4ProfileRegistrar; +import com.helger.phase4.profile.IAS4ProfileRegistrarSPI; + +/** + * Library specific implementation of {@link IAS4ProfileRegistrarSPI}. This test + * profile registrar was created after the profile usage was intensified and the + * CEF profile would have had been chosen. The profile registered here is very + * lax and tries to support as much as possible. + * + * @author Philip Helger + * @since 2.3.0 + */ +@IsSPIImplementation +public final class AS4TestProfileRegistarSPI implements IAS4ProfileRegistrarSPI +{ + public static final String AS4_PROFILE_ID_FOUR_CORNER = "test"; + + private static final Logger LOGGER = LoggerFactory.getLogger (AS4TestProfileRegistarSPI.class); + + public void registerAS4Profile (@Nonnull final IAS4ProfileRegistrar aRegistrar) + { + final IPModeIDProvider aPMIDProv = IPModeIDProvider.DEFAULT_DYNAMIC; + + final IAS4ProfilePModeProvider aDefaultPModeProvider = (i, r, a) -> TestPMode.createTestPMode (i, + r, + a, + aPMIDProv, + false); + + if (LOGGER.isDebugEnabled ()) + LOGGER.debug ("Registering phase4 profile '" + AS4_PROFILE_ID_FOUR_CORNER + "'"); + final AS4Profile aTestProfile = new AS4Profile (AS4_PROFILE_ID_FOUR_CORNER, + "Unit Testing Profile", + TestProfileCompatibilityValidator::new, + aDefaultPModeProvider, + aPMIDProv, + false, + EProfileRequirement.MAY, + EProfileRequirement.MAY); + aRegistrar.registerProfile (aTestProfile); + + aRegistrar.setDefaultProfile (aTestProfile); + } +} diff --git a/phase4-test/src/main/java/com/helger/phase4/test/profile/TestPMode.java b/phase4-test/src/main/java/com/helger/phase4/test/profile/TestPMode.java new file mode 100644 index 000000000..40505f561 --- /dev/null +++ b/phase4-test/src/main/java/com/helger/phase4/test/profile/TestPMode.java @@ -0,0 +1,226 @@ +/* + * Copyright (C) 2015-2023 Philip Helger (www.helger.com) + * philip[at]helger[dot]com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.helger.phase4.test.profile; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.annotation.concurrent.Immutable; + +import com.helger.commons.annotation.Nonempty; +import com.helger.commons.state.ETriState; +import com.helger.phase4.CAS4; +import com.helger.phase4.crypto.ECryptoAlgorithmCrypt; +import com.helger.phase4.crypto.ECryptoAlgorithmSign; +import com.helger.phase4.crypto.ECryptoAlgorithmSignDigest; +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; +import com.helger.phase4.model.pmode.PModeReceptionAwareness; +import com.helger.phase4.model.pmode.leg.EPModeSendReceiptReplyPattern; +import com.helger.phase4.model.pmode.leg.PModeAddressList; +import com.helger.phase4.model.pmode.leg.PModeLeg; +import com.helger.phase4.model.pmode.leg.PModeLegBusinessInformation; +import com.helger.phase4.model.pmode.leg.PModeLegErrorHandling; +import com.helger.phase4.model.pmode.leg.PModeLegProtocol; +import com.helger.phase4.model.pmode.leg.PModeLegReliability; +import com.helger.phase4.model.pmode.leg.PModeLegSecurity; +import com.helger.phase4.wss.EWSSVersion; + +/** + * Test PMode creation code. + * + * @author Philip Helger + * @since 2.3.0 + */ +@Immutable +public final class TestPMode +{ + public static final String DEFAULT_AGREEMENT_ID = "urn:as4:agreement"; + + private TestPMode () + {} + + @Nonnull + public static PModeLegProtocol generatePModeLegProtocol (@Nullable final String sAddress) + { + // Set the endpoint URL + return PModeLegProtocol.createForDefaultSoapVersion (sAddress); + } + + @Nonnull + public static PModeLegBusinessInformation generatePModeLegBusinessInformation () + { + final String sService = null; + final String sAction = CAS4.DEFAULT_ACTION_URL; + final Long nPayloadProfileMaxKB = null; + final String sMPCID = CAS4.DEFAULT_MPC_ID; + return PModeLegBusinessInformation.create (sService, sAction, nPayloadProfileMaxKB, sMPCID); + } + + @Nonnull + public static PModeLegErrorHandling generatePModeLegErrorHandling () + { + final PModeAddressList aReportSenderErrorsTo = null; + final PModeAddressList aReportReceiverErrorsTo = null; + final ETriState eReportAsResponse = ETriState.TRUE; + final ETriState eReportProcessErrorNotifyConsumer = ETriState.TRUE; + final ETriState eReportProcessErrorNotifyProducer = ETriState.TRUE; + final ETriState eReportDeliveryFailuresNotifyProducer = ETriState.TRUE; + return new PModeLegErrorHandling (aReportSenderErrorsTo, + aReportReceiverErrorsTo, + eReportAsResponse, + eReportProcessErrorNotifyConsumer, + eReportProcessErrorNotifyProducer, + eReportDeliveryFailuresNotifyProducer); + } + + @Nonnull + public static PModeLegSecurity generatePModeLegSecurity () + { + final PModeLegSecurity aPModeLegSecurity = new PModeLegSecurity (); + aPModeLegSecurity.setWSSVersion (EWSSVersion.WSS_111); + aPModeLegSecurity.setX509SignatureAlgorithm (ECryptoAlgorithmSign.RSA_SHA_256); + aPModeLegSecurity.setX509SignatureHashFunction (ECryptoAlgorithmSignDigest.DIGEST_SHA_256); + aPModeLegSecurity.setX509EncryptionAlgorithm (ECryptoAlgorithmCrypt.AES_128_GCM); + aPModeLegSecurity.setX509EncryptionMinimumStrength (Integer.valueOf (128)); + aPModeLegSecurity.setPModeAuthorize (false); + aPModeLegSecurity.setSendReceipt (true); + aPModeLegSecurity.setSendReceiptNonRepudiation (true); + aPModeLegSecurity.setSendReceiptReplyPattern (EPModeSendReceiptReplyPattern.RESPONSE); + return aPModeLegSecurity; + } + + @Nonnull + public static PModeLeg generatePModeLeg (@Nullable final String sResponderAddress) + { + return new PModeLeg (generatePModeLegProtocol (sResponderAddress), + generatePModeLegBusinessInformation (), + generatePModeLegErrorHandling (), + (PModeLegReliability) null, + generatePModeLegSecurity ()); + } + + @Nonnull + public static PModeReceptionAwareness generatePModeReceptionAwareness () + { + final ETriState eReceptionAwareness = ETriState.TRUE; + final ETriState eRetry = ETriState.TRUE; + final int nMaxRetries = 1; + final long nRetryIntervalMS = 10_000; + final ETriState eDuplicateDetection = ETriState.TRUE; + return new PModeReceptionAwareness (eReceptionAwareness, + eRetry, + nMaxRetries, + nRetryIntervalMS, + eDuplicateDetection); + } + + /** + * One-Way Version of the Test pmode uses one-way push + * + * @param sInitiatorID + * Initiator ID + * @param sResponderID + * Responder ID + * @param sResponderAddress + * Responder URL + * @param aPModeIDProvider + * PMode ID provider + * @param bPersist + * true to persist the PMode in the PModeManager, + * false to have it only in memory. + * @return New PMode + */ + @Nonnull + public static PMode createTestPMode (@Nonnull @Nonempty final String sInitiatorID, + @Nonnull @Nonempty final String sResponderID, + @Nullable final String sResponderAddress, + @Nonnull final IPModeIDProvider aPModeIDProvider, + final boolean bPersist) + { + final PModeParty aInitiator = PModeParty.createSimple (sInitiatorID, CAS4.DEFAULT_INITIATOR_URL); + final PModeParty aResponder = PModeParty.createSimple (sResponderID, CAS4.DEFAULT_RESPONDER_URL); + + final PMode aPMode = new PMode (aPModeIDProvider.getPModeID (aInitiator, aResponder), + aInitiator, + aResponder, + DEFAULT_AGREEMENT_ID, + EMEP.ONE_WAY, + EMEPBinding.PUSH, + generatePModeLeg (sResponderAddress), + (PModeLeg) null, + (PModePayloadService) null, + generatePModeReceptionAwareness ()); + // Leg 2 stays null, because we only use one-way + // By default no compression active + + if (bPersist) + { + // Ensure it is stored + MetaAS4Manager.getPModeMgr ().createOrUpdatePMode (aPMode); + } + return aPMode; + } + + /** + * Two-Way Version of the Test pmode uses two-way push-push + * + * @param sInitiatorID + * Initiator ID + * @param sResponderID + * Responder ID + * @param sResponderAddress + * Responder URL + * @param aPModeIDProvider + * PMode ID provider + * @param bPersist + * true to persist the PMode false to have it + * only in memory. + * @return New PMode + */ + @Nonnull + public static PMode createTestPModeTwoWay (@Nonnull @Nonempty final String sInitiatorID, + @Nonnull @Nonempty final String sResponderID, + @Nullable final String sResponderAddress, + @Nonnull final IPModeIDProvider aPModeIDProvider, + final boolean bPersist) + { + final PModeParty aInitiator = PModeParty.createSimple (sInitiatorID, CAS4.DEFAULT_INITIATOR_URL); + final PModeParty aResponder = PModeParty.createSimple (sResponderID, CAS4.DEFAULT_RESPONDER_URL); + + final PMode aPMode = new PMode (aPModeIDProvider.getPModeID (aInitiator, aResponder), + aInitiator, + aResponder, + DEFAULT_AGREEMENT_ID, + EMEP.TWO_WAY, + EMEPBinding.PUSH_PUSH, + generatePModeLeg (sResponderAddress), + generatePModeLeg (sResponderAddress), + (PModePayloadService) null, + PModeReceptionAwareness.createDefault ()); + if (bPersist) + { + // Ensure it is stored + MetaAS4Manager.getPModeMgr ().createOrUpdatePMode (aPMode); + } + return aPMode; + } +} diff --git a/phase4-test/src/main/java/com/helger/phase4/test/profile/TestProfileCompatibilityValidator.java b/phase4-test/src/main/java/com/helger/phase4/test/profile/TestProfileCompatibilityValidator.java new file mode 100644 index 000000000..4d24f1f77 --- /dev/null +++ b/phase4-test/src/main/java/com/helger/phase4/test/profile/TestProfileCompatibilityValidator.java @@ -0,0 +1,248 @@ +/* + * Copyright (C) 2015-2023 Philip Helger (www.helger.com) + * philip[at]helger[dot]com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.helger.phase4.test.profile; + +import java.util.List; + +import javax.annotation.Nonnull; + +import com.helger.commons.ValueEnforcer; +import com.helger.commons.annotation.Nonempty; +import com.helger.commons.error.IError; +import com.helger.commons.error.SingleError; +import com.helger.commons.error.list.ErrorList; +import com.helger.commons.string.StringHelper; +import com.helger.phase4.CAS4; +import com.helger.phase4.attachment.EAS4CompressionMode; +import com.helger.phase4.ebms3header.Ebms3From; +import com.helger.phase4.ebms3header.Ebms3MessageProperties; +import com.helger.phase4.ebms3header.Ebms3Property; +import com.helger.phase4.ebms3header.Ebms3SignalMessage; +import com.helger.phase4.ebms3header.Ebms3To; +import com.helger.phase4.ebms3header.Ebms3UserMessage; +import com.helger.phase4.mgr.MetaAS4Manager; +import com.helger.phase4.model.EMEP; +import com.helger.phase4.model.pmode.IPMode; +import com.helger.phase4.model.pmode.PModePayloadService; +import com.helger.phase4.model.pmode.PModeValidationException; +import com.helger.phase4.model.pmode.leg.PModeLeg; +import com.helger.phase4.model.pmode.leg.PModeLegProtocol; +import com.helger.phase4.profile.IAS4ProfileValidator; + +/** + * Validate certain requirements imposed by the Test profile. + * + * @author Philip Helger + * @since 2.3.0 + */ +public class TestProfileCompatibilityValidator implements IAS4ProfileValidator +{ + public TestProfileCompatibilityValidator () + {} + + @Nonnull + private static IError _createError (@Nonnull final String sMsg) + { + return SingleError.builderError ().errorText (sMsg).build (); + } + + @Nonnull + private static IError _createWarn (@Nonnull final String sMsg) + { + return SingleError.builderWarn ().errorText (sMsg).build (); + } + + private static void _checkIfLegIsValid (@Nonnull final ErrorList aErrorList, + @Nonnull final PModeLeg aPModeLeg, + @Nonnull @Nonempty final String sFieldPrefix) + { + final PModeLegProtocol aLegProtocol = aPModeLeg.getProtocol (); + if (aLegProtocol == null) + { + aErrorList.add (_createError (sFieldPrefix + "Protocol is missing")); + } + else + { + // PROTOCOL Address only https allowed + final String sAddressProtocol = aLegProtocol.getAddressProtocol (); + if (StringHelper.hasText (sAddressProtocol)) + { + if (sAddressProtocol.equalsIgnoreCase ("http") || sAddressProtocol.equalsIgnoreCase ("https")) + { + // Always okay + } + else + { + // Other protocol + aErrorList.add (_createError (sFieldPrefix + "AddressProtocol '" + sAddressProtocol + "' is unsupported")); + } + } + else + { + // Empty address protocol + aErrorList.add (_createError (sFieldPrefix + "AddressProtocol is missing")); + } + + // Support any SOAP version + } + } + + @Override + public void validatePMode (@Nonnull final IPMode aPMode, @Nonnull final ErrorList aErrorList) + { + ValueEnforcer.isTrue (aErrorList.isEmpty (), () -> "Errors in global PMode validation: " + aErrorList.toString ()); + + try + { + MetaAS4Manager.getPModeMgr ().validatePMode (aPMode); + } + catch (final PModeValidationException ex) + { + aErrorList.add (_createError (ex.getMessage ())); + } + + final EMEP eMEP = aPMode.getMEP (); + + // Leg1 must be present + final PModeLeg aPModeLeg1 = aPMode.getLeg1 (); + if (aPModeLeg1 == null) + { + aErrorList.add (_createError ("PMode.Leg[1] is missing")); + } + else + { + _checkIfLegIsValid (aErrorList, aPModeLeg1, "PMode.Leg[1]."); + } + + if (eMEP.isTwoWay ()) + { + final PModeLeg aPModeLeg2 = aPMode.getLeg2 (); + if (aPModeLeg2 == null) + { + aErrorList.add (_createError ("PMode.Leg[2] is missing as it specified as TWO-WAY")); + } + else + { + _checkIfLegIsValid (aErrorList, aPModeLeg2, "PMode.Leg[2]."); + } + } + + // Compression application/gzip ONLY + // other possible states are absent or "" (No input) + final PModePayloadService aPayloadService = aPMode.getPayloadService (); + if (aPayloadService != null) + { + final EAS4CompressionMode eCompressionMode = aPayloadService.getCompressionMode (); + if (eCompressionMode != null) + { + if (!eCompressionMode.equals (EAS4CompressionMode.GZIP)) + aErrorList.add (_createError ("PMode.PayloadService.CompressionMode must be " + + EAS4CompressionMode.GZIP + + " instead of " + + eCompressionMode)); + } + } + } + + @Override + public void validateUserMessage (@Nonnull final Ebms3UserMessage aUserMsg, @Nonnull final ErrorList aErrorList) + { + ValueEnforcer.notNull (aUserMsg, "UserMsg"); + + if (aUserMsg.getMessageInfo () == null) + { + aErrorList.add (_createError ("MessageInfo is missing")); + } + else + { + if (StringHelper.hasNoText (aUserMsg.getMessageInfo ().getMessageId ())) + aErrorList.add (_createError ("MessageInfo/MessageId is missing")); + + // Check if originalSender and finalRecipient are present + // Since these two properties are mandatory + final Ebms3MessageProperties aMessageProperties = aUserMsg.getMessageProperties (); + if (aMessageProperties == null) + aErrorList.add (_createError ("MessageProperties is missing but 'originalSender' and 'finalRecipient' properties are required")); + else + { + final List aProps = aMessageProperties.getProperty (); + if (aProps.isEmpty ()) + aErrorList.add (_createError ("MessageProperties/Property must not be empty")); + else + { + String sOriginalSenderC1 = null; + String sFinalRecipientC4 = null; + + for (final Ebms3Property sProperty : aProps) + { + if (sProperty.getName ().equals (CAS4.ORIGINAL_SENDER)) + sOriginalSenderC1 = sProperty.getValue (); + else + if (sProperty.getName ().equals (CAS4.FINAL_RECIPIENT)) + sFinalRecipientC4 = sProperty.getValue (); + } + + if (StringHelper.hasNoText (sOriginalSenderC1)) + aErrorList.add (_createError ("MessageProperties/Property '" + + CAS4.ORIGINAL_SENDER + + "' property is empty or not existant but mandatory")); + if (StringHelper.hasNoText (sFinalRecipientC4)) + aErrorList.add (_createError ("MessageProperties/Property '" + + CAS4.FINAL_RECIPIENT + + "' property is empty or not existant but mandatory")); + } + } + } + + if (aUserMsg.getPartyInfo () == null) + { + aErrorList.add (_createError ("PartyInfo is missing")); + } + else + { + final Ebms3From aFrom = aUserMsg.getPartyInfo ().getFrom (); + if (aFrom != null) + { + if (aFrom.getPartyIdCount () > 1) + aErrorList.add (_createError ("PartyInfo/From must contain no more than one PartyID")); + } + + final Ebms3To aTo = aUserMsg.getPartyInfo ().getTo (); + if (aTo != null) + { + if (aTo.getPartyIdCount () > 1) + aErrorList.add (_createError ("PartyInfo/To must contain no more than one PartyID")); + } + } + } + + @Override + public void validateSignalMessage (@Nonnull final Ebms3SignalMessage aSignalMsg, @Nonnull final ErrorList aErrorList) + { + ValueEnforcer.notNull (aSignalMsg, "SignalMsg"); + + if (aSignalMsg.getMessageInfo () == null) + { + aErrorList.add (_createError ("MessageInfo is missing")); + } + else + { + if (StringHelper.hasNoText (aSignalMsg.getMessageInfo ().getMessageId ())) + aErrorList.add (_createError ("MessageInfo/MessageId is missing")); + } + } +} diff --git a/phase4-test/src/main/java/com/helger/phase4/server/servlet/AS4WebAppListener.java b/phase4-test/src/main/java/com/helger/phase4/test/servlet/AS4WebAppListener.java similarity index 98% rename from phase4-test/src/main/java/com/helger/phase4/server/servlet/AS4WebAppListener.java rename to phase4-test/src/main/java/com/helger/phase4/test/servlet/AS4WebAppListener.java index cf12a3aff..9ba6d0cf2 100644 --- a/phase4-test/src/main/java/com/helger/phase4/server/servlet/AS4WebAppListener.java +++ b/phase4-test/src/main/java/com/helger/phase4/test/servlet/AS4WebAppListener.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.helger.phase4.server.servlet; +package com.helger.phase4.test.servlet; import java.util.Locale; diff --git a/phase4-test/src/main/resources/META-INF/services/com.helger.phase4.profile.IAS4ProfileRegistrarSPI b/phase4-test/src/main/resources/META-INF/services/com.helger.phase4.profile.IAS4ProfileRegistrarSPI new file mode 100644 index 000000000..b28b72244 --- /dev/null +++ b/phase4-test/src/main/resources/META-INF/services/com.helger.phase4.profile.IAS4ProfileRegistrarSPI @@ -0,0 +1 @@ +com.helger.phase4.test.profile.AS4TestProfileRegistarSPI diff --git a/phase4-test/src/main/webapp/WEB-INF/web.xml b/phase4-test/src/main/webapp/WEB-INF/web.xml index 12f07b991..f2f452232 100644 --- a/phase4-test/src/main/webapp/WEB-INF/web.xml +++ b/phase4-test/src/main/webapp/WEB-INF/web.xml @@ -25,9 +25,11 @@ secure + - com.helger.phase4.server.servlet.AS4WebAppListener + com.helger.phase4.test.servlet.AS4WebAppListener + AS4Servlet com.helger.phase4.servlet.AS4Servlet diff --git a/phase4-test/src/test/java/com/helger/phase4/CEF/AS4eSENSCEFOneWayFuncTest.java b/phase4-test/src/test/java/com/helger/phase4/CEF/AS4eSENSCEFOneWayFuncTest.java index 54608526c..863c904ce 100644 --- a/phase4-test/src/test/java/com/helger/phase4/CEF/AS4eSENSCEFOneWayFuncTest.java +++ b/phase4-test/src/test/java/com/helger/phase4/CEF/AS4eSENSCEFOneWayFuncTest.java @@ -45,7 +45,7 @@ import com.helger.commons.mime.CMimeType; import com.helger.phase4.AS4TestConstants; import com.helger.phase4.CAS4; -import com.helger.phase4.ScopedConfig; +import com.helger.phase4.ScopedAS4Configuration; import com.helger.phase4.attachment.AS4OutgoingAttachment; import com.helger.phase4.attachment.WSS4JAttachment; import com.helger.phase4.crypto.AS4SigningParams; @@ -461,7 +461,7 @@ public void testEsens_TA10 () throws Exception aSettings.putIn (SETTINGS_SERVER_PROXY_ENABLED, true); aSettings.putIn (SETTINGS_SERVER_PROXY_ADDRESS, "localhost"); aSettings.putIn (SETTINGS_SERVER_PROXY_PORT, nProxyPort); - try (final ScopedConfig aSC = ScopedConfig.createTestConfig (aSettings)) + try (final ScopedAS4Configuration aSC = ScopedAS4Configuration.createTestConfig (aSettings)) { final HttpProxyServer aProxyServer = _startProxyServerInterceptingFirstCall (nProxyPort); try @@ -507,7 +507,7 @@ public void testEsens_TA11 () throws Exception aSettings.putIn (SETTINGS_SERVER_PROXY_ADDRESS, "localhost"); aSettings.putIn (SETTINGS_SERVER_PROXY_PORT, nProxyPort); - try (final ScopedConfig aSC = ScopedConfig.createTestConfig (aSettings)) + try (final ScopedAS4Configuration aSC = ScopedAS4Configuration.createTestConfig (aSettings)) { // Simulating a timeout with Thread.sleep but before it entirely triggers // let the program continue as if the Connection is back up again @@ -689,7 +689,7 @@ public void testEsens_TA17 () throws Exception aSettings.putIn (SETTINGS_SERVER_PROXY_ADDRESS, "localhost"); aSettings.putIn (SETTINGS_SERVER_PROXY_PORT, nProxyPort); - try (final ScopedConfig aSC = ScopedConfig.createTestConfig (aSettings)) + try (final ScopedAS4Configuration aSC = ScopedAS4Configuration.createTestConfig (aSettings)) { // Forcing a Timeout from the retry handler final HttpProxyServer aProxyServer = DefaultHttpProxyServer.bootstrap () diff --git a/phase4-test/src/test/java/com/helger/phase4/CEF/AbstractCEFTestSetUp.java b/phase4-test/src/test/java/com/helger/phase4/CEF/AbstractCEFTestSetUp.java index 5bec98c73..3f16d0687 100644 --- a/phase4-test/src/test/java/com/helger/phase4/CEF/AbstractCEFTestSetUp.java +++ b/phase4-test/src/test/java/com/helger/phase4/CEF/AbstractCEFTestSetUp.java @@ -41,10 +41,10 @@ import com.helger.phase4.messaging.domain.MessageHelperMethods; import com.helger.phase4.model.pmode.IPModeIDProvider; import com.helger.phase4.model.pmode.PMode; -import com.helger.phase4.profile.cef.CEFPMode; import com.helger.phase4.server.MockPModeGenerator; import com.helger.phase4.server.message.AbstractUserMessageTestSetUp; import com.helger.phase4.soap.ESoapVersion; +import com.helger.phase4.test.profile.TestPMode; import com.helger.phase4.util.AS4ResourceHelper; import com.helger.xml.serialize.read.DOMReader; @@ -59,7 +59,7 @@ public abstract class AbstractCEFTestSetUp extends AbstractUserMessageTestSetUp @Before public void setUpCEF () { - m_aESENSOneWayPMode = CEFPMode.createCEFPMode (AS4TestConstants.CEF_INITIATOR_ID, + m_aESENSOneWayPMode = TestPMode.createTestPMode (AS4TestConstants.CEF_INITIATOR_ID, AS4TestConstants.CEF_RESPONDER_ID, AS4TestConstants.DEFAULT_SERVER_ADDRESS, IPModeIDProvider.DEFAULT_DYNAMIC, diff --git a/phase4-test/src/test/java/com/helger/phase4/CEF/AbstractCEFTwoWayTestSetUp.java b/phase4-test/src/test/java/com/helger/phase4/CEF/AbstractCEFTwoWayTestSetUp.java index f1be7e3db..d166f9bc1 100644 --- a/phase4-test/src/test/java/com/helger/phase4/CEF/AbstractCEFTwoWayTestSetUp.java +++ b/phase4-test/src/test/java/com/helger/phase4/CEF/AbstractCEFTwoWayTestSetUp.java @@ -45,11 +45,11 @@ import com.helger.phase4.messaging.domain.MessageHelperMethods; import com.helger.phase4.model.pmode.IPModeIDProvider; import com.helger.phase4.model.pmode.PMode; -import com.helger.phase4.profile.cef.CEFPMode; import com.helger.phase4.server.MockPModeGenerator; import com.helger.phase4.server.message.AbstractUserMessageTestSetUp; import com.helger.phase4.server.standalone.RunInJettyAS4TEST9090; import com.helger.phase4.soap.ESoapVersion; +import com.helger.phase4.test.profile.TestPMode; import com.helger.phase4.util.AS4ResourceHelper; import com.helger.photon.core.servlet.WebAppListener; import com.helger.xml.serialize.read.DOMReader; @@ -90,11 +90,11 @@ public static void shutDownServerNinety () throws Exception @Before public void setUpCEF () { - m_aESENSTwoWayPMode = CEFPMode.createCEFPModeTwoWay (AS4TestConstants.CEF_INITIATOR_ID, - AS4TestConstants.CEF_RESPONDER_ID, - AS4TestConstants.DEFAULT_SERVER_ADDRESS, - IPModeIDProvider.DEFAULT_DYNAMIC, - true); + m_aESENSTwoWayPMode = TestPMode.createTestPModeTwoWay (AS4TestConstants.CEF_INITIATOR_ID, + AS4TestConstants.CEF_RESPONDER_ID, + AS4TestConstants.DEFAULT_SERVER_ADDRESS, + IPModeIDProvider.DEFAULT_DYNAMIC, + true); m_eSoapVersion = m_aESENSTwoWayPMode.getLeg1 ().getProtocol ().getSoapVersion (); m_aPayload = DOMReader.readXMLDOM (new ClassPathResource (AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML)); @@ -125,7 +125,8 @@ protected AS4UserMessage testUserMessageSoapNotSigned (@Nullable final Node aPay final ICommonsList aEbms3Properties = AS4TestConstants.getEBMSProperties (); final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo (); - final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo (aPayload != null, aAttachments); + final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo (aPayload != null, + aAttachments); final Ebms3CollaborationInfo aEbms3CollaborationInfo; final Ebms3PartyInfo aEbms3PartyInfo; @@ -147,7 +148,6 @@ protected AS4UserMessage testUserMessageSoapNotSigned (@Nullable final Node aPay aEbms3CollaborationInfo, aEbms3PartyInfo, aEbms3MessageProperties, - m_eSoapVersion) - .setMustUnderstand (true); + m_eSoapVersion).setMustUnderstand (true); } } diff --git a/phase4-test/src/test/java/com/helger/phase4/ScopedConfig.java b/phase4-test/src/test/java/com/helger/phase4/ScopedAS4Configuration.java similarity index 83% rename from phase4-test/src/test/java/com/helger/phase4/ScopedConfig.java rename to phase4-test/src/test/java/com/helger/phase4/ScopedAS4Configuration.java index 928c996fa..b6b9682d9 100644 --- a/phase4-test/src/test/java/com/helger/phase4/ScopedConfig.java +++ b/phase4-test/src/test/java/com/helger/phase4/ScopedAS4Configuration.java @@ -38,13 +38,13 @@ * @author Philip Helger */ @ThreadSafe -public final class ScopedConfig implements AutoCloseable +public final class ScopedAS4Configuration implements AutoCloseable { private static final String TEST_CONFIG_FILE = "src/test/resources/test-phase4.properties"; private final IConfig m_aOldConfig; - private ScopedConfig (@Nonnull final IConfig aConfig) + private ScopedAS4Configuration (@Nonnull final IConfig aConfig) { m_aOldConfig = AS4Configuration.setConfig (aConfig); } @@ -56,15 +56,15 @@ public void close () } @Nonnull - public static ScopedConfig create (@Nonnull final IStringMap aMap) + public static ScopedAS4Configuration create (@Nonnull final IStringMap aMap) { final MultiConfigurationValueProvider aVP = AS4Configuration.createPhase4ValueProvider (); aVP.addConfigurationSource (new ConfigurationSourceFunction (aMap::getAsString), EConfigSourceType.RESOURCE.getDefaultPriority () + 20); - return new ScopedConfig (new Config (aVP)); + return new ScopedAS4Configuration (new Config (aVP)); } @Nonnull - public static ScopedConfig create (@Nonnull final IReadableResource aRes) + public static ScopedAS4Configuration create (@Nonnull final IReadableResource aRes) { ValueEnforcer.notNull (aRes, "Res"); ValueEnforcer.isTrue (aRes.exists (), () -> "Resource does not exist: " + aRes); @@ -72,22 +72,22 @@ public static ScopedConfig create (@Nonnull final IReadableResource aRes) final MultiConfigurationValueProvider aVP = AS4Configuration.createPhase4ValueProvider (); // By default priority must be higher than the default aVP.addConfigurationSource (new ConfigurationSourceProperties (aRes), EConfigSourceType.RESOURCE.getDefaultPriority () + 10); - return new ScopedConfig (new Config (aVP)); + return new ScopedAS4Configuration (new Config (aVP)); } @Nonnull - public static ScopedConfig createTestConfig () + public static ScopedAS4Configuration createTestConfig () { return create (new FileSystemResource (TEST_CONFIG_FILE)); } @Nonnull - public static ScopedConfig createTestConfig (@Nonnull final IStringMap aMap) + public static ScopedAS4Configuration createTestConfig (@Nonnull final IStringMap aMap) { final MultiConfigurationValueProvider aVP = AS4Configuration.createPhase4ValueProvider (); aVP.addConfigurationSource (new ConfigurationSourceFunction (aMap::getAsString), EConfigSourceType.RESOURCE.getDefaultPriority () + 20); aVP.addConfigurationSource (new ConfigurationSourceProperties (new FileSystemResource (TEST_CONFIG_FILE)), EConfigSourceType.RESOURCE.getDefaultPriority () + 10); - return new ScopedConfig (new Config (aVP)); + return new ScopedAS4Configuration (new Config (aVP)); } } diff --git a/phase4-test/src/test/java/com/helger/phase4/client/AS4ClientUserMessageTest.java b/phase4-test/src/test/java/com/helger/phase4/client/AS4ClientUserMessageTest.java index 708cecb48..6f971e91e 100644 --- a/phase4-test/src/test/java/com/helger/phase4/client/AS4ClientUserMessageTest.java +++ b/phase4-test/src/test/java/com/helger/phase4/client/AS4ClientUserMessageTest.java @@ -50,10 +50,10 @@ import com.helger.phase4.http.AS4HttpDebug; import com.helger.phase4.messaging.domain.MessageHelperMethods; import com.helger.phase4.mgr.MetaAS4Manager; -import com.helger.phase4.profile.cef.AS4CEFProfileRegistarSPI; import com.helger.phase4.server.AbstractAS4TestSetUp; import com.helger.phase4.server.MockJettySetup; import com.helger.phase4.soap.ESoapVersion; +import com.helger.phase4.test.profile.AS4TestProfileRegistarSPI; import com.helger.phase4.util.AS4ResourceHelper; import com.helger.security.keystore.EKeyStoreType; import com.helger.xml.microdom.IMicroDocument; @@ -82,7 +82,7 @@ public static void beforeClass () throws Exception { MockJettySetup.startServer (); s_aResMgr = MockJettySetup.getResourceManagerInstance (); - MetaAS4Manager.getProfileMgr ().setDefaultProfileID (AS4CEFProfileRegistarSPI.AS4_PROFILE_ID_FOUR_CORNER); + MetaAS4Manager.getProfileMgr ().setDefaultProfileID (AS4TestProfileRegistarSPI.AS4_PROFILE_ID_FOUR_CORNER); } @AfterClass diff --git a/phase4-test/src/test/java/com/helger/phase4/server/AS4JettyRunner.java b/phase4-test/src/test/java/com/helger/phase4/server/AS4JettyRunner.java new file mode 100644 index 000000000..d89d3b0c5 --- /dev/null +++ b/phase4-test/src/test/java/com/helger/phase4/server/AS4JettyRunner.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2015-2023 Philip Helger (www.helger.com) + * philip[at]helger[dot]com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.helger.phase4.server; + +import org.eclipse.jetty.webapp.WebAppContext; + +import com.helger.photon.core.servlet.WebAppListener; +import com.helger.photon.jetty.JettyRunner; + +/** + * Special JettyRunne for AS4 + * + * @author Philip Helger + */ +public class AS4JettyRunner extends JettyRunner +{ + public AS4JettyRunner () + { + super ("AS4 Mock Jetty"); + } + + @Override + protected void customizeWebAppCtx (final WebAppContext aWebAppCtx) throws Exception + { + // This enables GlobalDebug mode + // GlobalDebug mode is required to use the "http" protocol in test + aWebAppCtx.setInitParameter (WebAppListener.DEFAULT_INIT_PARAMETER_DEBUG, "true"); + } +} diff --git a/phase4-test/src/test/java/com/helger/phase4/server/AbstractAS4TestSetUp.java b/phase4-test/src/test/java/com/helger/phase4/server/AbstractAS4TestSetUp.java index 76c4aca15..5d79ece41 100644 --- a/phase4-test/src/test/java/com/helger/phase4/server/AbstractAS4TestSetUp.java +++ b/phase4-test/src/test/java/com/helger/phase4/server/AbstractAS4TestSetUp.java @@ -20,7 +20,7 @@ import org.junit.Before; import org.junit.BeforeClass; -import com.helger.phase4.ScopedConfig; +import com.helger.phase4.ScopedAS4Configuration; import com.helger.scope.ScopeHelper; /** @@ -34,12 +34,12 @@ */ public abstract class AbstractAS4TestSetUp { - private static ScopedConfig s_aSC; + private static ScopedAS4Configuration s_aSC; @BeforeClass public static void startTest () throws Exception { - s_aSC = ScopedConfig.createTestConfig (); + s_aSC = ScopedAS4Configuration.createTestConfig (); } @AfterClass diff --git a/phase4-test/src/test/java/com/helger/phase4/server/MockJettySetup.java b/phase4-test/src/test/java/com/helger/phase4/server/MockJettySetup.java index fe52d201d..6d6e4e844 100644 --- a/phase4-test/src/test/java/com/helger/phase4/server/MockJettySetup.java +++ b/phase4-test/src/test/java/com/helger/phase4/server/MockJettySetup.java @@ -34,7 +34,6 @@ import com.helger.phase4.config.AS4Configuration; import com.helger.phase4.util.AS4ResourceHelper; import com.helger.photon.io.WebFileIO; -import com.helger.photon.jetty.JettyRunner; import com.helger.servlet.mock.MockServletContext; import com.helger.web.scope.mgr.WebScopeManager; import com.helger.xservlet.requesttrack.RequestTrackerSettings; @@ -46,7 +45,7 @@ public final class MockJettySetup extends AbstractAS4TestSetUp private static final Logger LOGGER = LoggerFactory.getLogger (MockJettySetup.class); - private static JettyRunner s_aJetty; + private static AS4JettyRunner s_aJetty; private static AS4ResourceHelper s_aResMgr; static @@ -83,7 +82,7 @@ public static void startServer () throws Exception if (_isRunJetty ()) { final int nPort = _getJettyPort (); - s_aJetty = new JettyRunner ("AS4 Mock Jetty"); + s_aJetty = new AS4JettyRunner (); s_aJetty.setPort (nPort).setStopPort (nPort + 1000).setAllowAnnotationBasedConfig (false); s_aJetty.startServer (); } diff --git a/phase4-test/src/test/java/com/helger/phase4/server/MockPModeGenerator.java b/phase4-test/src/test/java/com/helger/phase4/server/MockPModeGenerator.java index 0de2169e6..8ab7f38ad 100644 --- a/phase4-test/src/test/java/com/helger/phase4/server/MockPModeGenerator.java +++ b/phase4-test/src/test/java/com/helger/phase4/server/MockPModeGenerator.java @@ -124,6 +124,8 @@ public static PMode getTestPModeWithSecurity (@Nonnull final ESoapVersion eSOAPV aPModeLegSecurity.setX509EncryptionAlgorithm (ECryptoAlgorithmCrypt.ENCRPYTION_ALGORITHM_DEFAULT); aPModeLegSecurity.setSendReceiptReplyPattern (EPModeSendReceiptReplyPattern.RESPONSE); aPModeLegSecurity.setSendReceiptNonRepudiation (true); + // Required for compatibility with the Test profile PModes + aPModeLegSecurity.setPModeAuthorize (false); aPMode.setLeg1 (new PModeLeg (_createPModeLegProtocol (eSOAPVersion), _createPModeLegBusinessInformation (eSOAPVersion), diff --git a/phase4-test/src/test/java/com/helger/phase4/server/external/AS4_NETFuncTest.java b/phase4-test/src/test/java/com/helger/phase4/server/external/AS4_NETFuncTest.java index 1a1138afe..6193dc501 100644 --- a/phase4-test/src/test/java/com/helger/phase4/server/external/AS4_NETFuncTest.java +++ b/phase4-test/src/test/java/com/helger/phase4/server/external/AS4_NETFuncTest.java @@ -29,7 +29,7 @@ import com.helger.commons.io.resource.ClassPathResource; import com.helger.phase4.AS4TestConstants; import com.helger.phase4.CAS4; -import com.helger.phase4.ScopedConfig; +import com.helger.phase4.ScopedAS4Configuration; import com.helger.phase4.CEF.AbstractCEFTestSetUp; import com.helger.phase4.attachment.AS4OutgoingAttachment; import com.helger.phase4.attachment.WSS4JAttachment; @@ -59,7 +59,7 @@ public final class AS4_NETFuncTest extends AbstractCEFTestSetUp private static final String COLLABORATION_INFO_ACTION = "ACT_SIMPLE_ONEWAY_DYN"; private static final String TO_PARTY_ID = "as4.net-c3"; - private static ScopedConfig s_aSC; + private static ScopedAS4Configuration s_aSC; @BeforeClass public static void noJetty () @@ -67,7 +67,7 @@ public static void noJetty () final IStringMap aSettings = new StringMap (); aSettings.putIn (MockJettySetup.SETTINGS_SERVER_JETTY_ENABLED, false); aSettings.putIn (MockJettySetup.SETTINGS_SERVER_ADDRESS, DEFAULT_AS4_NET_URI); - s_aSC = ScopedConfig.create (aSettings); + s_aSC = ScopedAS4Configuration.create (aSettings); AS4HttpDebug.setEnabled (false); } diff --git a/phase4-test/src/test/java/com/helger/phase4/server/external/HolodeckFuncTest.java b/phase4-test/src/test/java/com/helger/phase4/server/external/HolodeckFuncTest.java index 6944c5615..42f763020 100644 --- a/phase4-test/src/test/java/com/helger/phase4/server/external/HolodeckFuncTest.java +++ b/phase4-test/src/test/java/com/helger/phase4/server/external/HolodeckFuncTest.java @@ -29,7 +29,7 @@ import com.helger.commons.io.resource.ClassPathResource; import com.helger.phase4.AS4TestConstants; import com.helger.phase4.CAS4; -import com.helger.phase4.ScopedConfig; +import com.helger.phase4.ScopedAS4Configuration; import com.helger.phase4.CEF.AbstractCEFTestSetUp; import com.helger.phase4.attachment.AS4OutgoingAttachment; import com.helger.phase4.attachment.WSS4JAttachment; @@ -58,7 +58,7 @@ public final class HolodeckFuncTest extends AbstractCEFTestSetUp private static final String COLLABORATION_INFO_SERVICE_TYPE = null; private static final String COLLABORATION_INFO_ACTION = "ACT_SIMPLE_ONEWAY_DYN"; private static final String TO_PARTY_ID = "holodeck-c3"; - private static ScopedConfig s_aSC; + private static ScopedAS4Configuration s_aSC; @BeforeClass public static void noJetty () @@ -66,7 +66,7 @@ public static void noJetty () final IStringMap aSettings = new StringMap (); aSettings.putIn (MockJettySetup.SETTINGS_SERVER_JETTY_ENABLED, false); aSettings.putIn (MockJettySetup.SETTINGS_SERVER_ADDRESS, DEFAULT_AS4_NET_URI); - s_aSC = ScopedConfig.create (aSettings); + s_aSC = ScopedAS4Configuration.create (aSettings); AS4HttpDebug.setEnabled (false); } diff --git a/phase4-test/src/test/java/com/helger/phase4/server/external/HolodeckOnlineTestSuite.java b/phase4-test/src/test/java/com/helger/phase4/server/external/HolodeckOnlineTestSuite.java index 1c2ef87a4..22cd2dd72 100644 --- a/phase4-test/src/test/java/com/helger/phase4/server/external/HolodeckOnlineTestSuite.java +++ b/phase4-test/src/test/java/com/helger/phase4/server/external/HolodeckOnlineTestSuite.java @@ -26,7 +26,7 @@ import com.helger.commons.collection.attr.IStringMap; import com.helger.commons.collection.attr.StringMap; -import com.helger.phase4.ScopedConfig; +import com.helger.phase4.ScopedAS4Configuration; import com.helger.phase4.server.MockJettySetup; import com.helger.phase4.server.message.ReceiptMessageTest; import com.helger.phase4.server.message.UserMessageOneAttachmentTest; @@ -42,7 +42,7 @@ public final class HolodeckOnlineTestSuite // TODO will be changed soon public static final String DEFAULT_HOLODECK_URI = "http://localhost:8080/msh"; - private static ScopedConfig s_aSC; + private static ScopedAS4Configuration s_aSC; @BeforeClass public static void init () @@ -50,7 +50,7 @@ public static void init () final IStringMap aSettings = new StringMap (); aSettings.putIn (MockJettySetup.SETTINGS_SERVER_JETTY_ENABLED, false); aSettings.putIn (MockJettySetup.SETTINGS_SERVER_ADDRESS, DEFAULT_HOLODECK_URI); - s_aSC = ScopedConfig.create (aSettings); + s_aSC = ScopedAS4Configuration.create (aSettings); } @AfterClass diff --git a/phase4-test/src/test/java/com/helger/phase4/server/external/HolodeckTestSuite.java b/phase4-test/src/test/java/com/helger/phase4/server/external/HolodeckTestSuite.java index 8b4fa2e38..c71a221e0 100644 --- a/phase4-test/src/test/java/com/helger/phase4/server/external/HolodeckTestSuite.java +++ b/phase4-test/src/test/java/com/helger/phase4/server/external/HolodeckTestSuite.java @@ -26,7 +26,7 @@ import com.helger.commons.collection.attr.IStringMap; import com.helger.commons.collection.attr.StringMap; -import com.helger.phase4.ScopedConfig; +import com.helger.phase4.ScopedAS4Configuration; import com.helger.phase4.server.MockJettySetup; import com.helger.phase4.server.message.ReceiptMessageTest; import com.helger.phase4.server.message.UserMessageOneAttachmentTest; @@ -48,7 +48,7 @@ public final class HolodeckTestSuite /** The default URL where Holodeck is supposed to run */ public static final String DEFAULT_HOLODECK_URI = "http://localhost:8080/msh"; - private static ScopedConfig s_aSC; + private static ScopedAS4Configuration s_aSC; @BeforeClass public static void init () @@ -56,7 +56,7 @@ public static void init () final IStringMap aSettings = new StringMap (); aSettings.putIn (MockJettySetup.SETTINGS_SERVER_JETTY_ENABLED, false); aSettings.putIn (MockJettySetup.SETTINGS_SERVER_ADDRESS, DEFAULT_HOLODECK_URI); - s_aSC = ScopedConfig.create (aSettings); + s_aSC = ScopedAS4Configuration.create (aSettings); } @AfterClass diff --git a/phase4-test/src/test/java/com/helger/phase4/server/message/AbstractUserMessageTestSetUp.java b/phase4-test/src/test/java/com/helger/phase4/server/message/AbstractUserMessageTestSetUp.java index cf01b8c6e..9f6ada62c 100644 --- a/phase4-test/src/test/java/com/helger/phase4/server/message/AbstractUserMessageTestSetUp.java +++ b/phase4-test/src/test/java/com/helger/phase4/server/message/AbstractUserMessageTestSetUp.java @@ -55,9 +55,9 @@ import com.helger.phase4.http.HttpMimeMessageEntity; import com.helger.phase4.messaging.domain.MessageHelperMethods; import com.helger.phase4.mgr.MetaAS4Manager; -import com.helger.phase4.profile.cef.AS4CEFProfileRegistarSPI; import com.helger.phase4.server.AbstractAS4TestSetUp; import com.helger.phase4.server.MockJettySetup; +import com.helger.phase4.test.profile.AS4TestProfileRegistarSPI; import com.helger.phase4.util.AS4ResourceHelper; import jakarta.mail.MessagingException; @@ -93,7 +93,7 @@ public static void startServer () throws Exception { MockJettySetup.startServer (); s_aResMgr = MockJettySetup.getResourceManagerInstance (); - MetaAS4Manager.getProfileMgr ().setDefaultProfileID (AS4CEFProfileRegistarSPI.AS4_PROFILE_ID_FOUR_CORNER); + MetaAS4Manager.getProfileMgr ().setDefaultProfileID (AS4TestProfileRegistarSPI.AS4_PROFILE_ID_FOUR_CORNER); } @AfterClass diff --git a/phase4-test/src/test/java/com/helger/phase4/server/message/UserMessageManyAttachmentTest.java b/phase4-test/src/test/java/com/helger/phase4/server/message/UserMessageManyAttachmentTest.java index cecc109c8..3c261885f 100644 --- a/phase4-test/src/test/java/com/helger/phase4/server/message/UserMessageManyAttachmentTest.java +++ b/phase4-test/src/test/java/com/helger/phase4/server/message/UserMessageManyAttachmentTest.java @@ -30,7 +30,6 @@ import org.junit.runners.Parameterized.Parameters; import org.w3c.dom.Document; -import com.helger.commons.collection.CollectionHelper; import com.helger.commons.collection.impl.CommonsArrayList; import com.helger.commons.collection.impl.ICommonsList; import com.helger.commons.io.resource.ClassPathResource; @@ -61,11 +60,10 @@ @RunWith (Parameterized.class) public final class UserMessageManyAttachmentTest extends AbstractUserMessageTestSetUp { - @Parameters (name = "{index}: {0}") public static Collection data () { - return CollectionHelper.newListMapped (ESoapVersion.values (), x -> new Object [] { x }); + return new CommonsArrayList <> (ESoapVersion.values (), x -> new Object [] { x }); } private final ESoapVersion m_eSOAPVersion; @@ -80,20 +78,17 @@ public void testUserMessageManyAttachmentsMimeSuccess () throws IOException, Mes { final ICommonsList aAttachments = new CommonsArrayList <> (); aAttachments.add (WSS4JAttachment.createOutgoingFileAttachment (AS4OutgoingAttachment.builder () - .data (ClassPathResource.getAsFile (AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML)) - .mimeTypeXML () - .build (), - s_aResMgr)); + .data (ClassPathResource.getAsFile (AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML)) + .mimeTypeXML () + .build (), s_aResMgr)); aAttachments.add (WSS4JAttachment.createOutgoingFileAttachment (AS4OutgoingAttachment.builder () - .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_TEST_IMG_JPG)) - .mimeType (CMimeType.IMAGE_JPG) - .build (), - s_aResMgr)); + .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_TEST_IMG_JPG)) + .mimeType (CMimeType.IMAGE_JPG) + .build (), s_aResMgr)); aAttachments.add (WSS4JAttachment.createOutgoingFileAttachment (AS4OutgoingAttachment.builder () - .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_SHORTXML2_XML)) - .mimeTypeXML () - .build (), - s_aResMgr)); + .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_SHORTXML2_XML)) + .mimeTypeXML () + .build (), s_aResMgr)); final AS4MimeMessage aMimeMsg = MimeMessageCreator.generateMimeMessage (m_eSOAPVersion, MockMessages.createUserMessageNotSigned (m_eSOAPVersion, @@ -111,20 +106,17 @@ public void testUserMessageManyAttachmentsSignedMimeSuccess () throws WSSecurity { final ICommonsList aAttachments = new CommonsArrayList <> (); aAttachments.add (WSS4JAttachment.createOutgoingFileAttachment (AS4OutgoingAttachment.builder () - .data (ClassPathResource.getAsFile (AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML)) - .mimeTypeXML () - .build (), - s_aResMgr)); + .data (ClassPathResource.getAsFile (AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML)) + .mimeTypeXML () + .build (), s_aResMgr)); aAttachments.add (WSS4JAttachment.createOutgoingFileAttachment (AS4OutgoingAttachment.builder () - .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_TEST_IMG_JPG)) - .mimeType (CMimeType.IMAGE_JPG) - .build (), - s_aResMgr)); + .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_TEST_IMG_JPG)) + .mimeType (CMimeType.IMAGE_JPG) + .build (), s_aResMgr)); aAttachments.add (WSS4JAttachment.createOutgoingFileAttachment (AS4OutgoingAttachment.builder () - .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_SHORTXML2_XML)) - .mimeTypeXML () - .build (), - s_aResMgr)); + .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_SHORTXML2_XML)) + .mimeTypeXML () + .build (), s_aResMgr)); final AS4UserMessage aMsg = MockMessages.createUserMessageNotSigned (m_eSOAPVersion, null, aAttachments); final AS4MimeMessage aMimeMsg = MimeMessageCreator.generateMimeMessage (m_eSOAPVersion, @@ -149,20 +141,17 @@ public void testUserMessageManyAttachmentsEncryptedMimeSuccess () throws WSSecur { final ICommonsList aAttachments = new CommonsArrayList <> (); aAttachments.add (WSS4JAttachment.createOutgoingFileAttachment (AS4OutgoingAttachment.builder () - .data (ClassPathResource.getAsFile (AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML)) - .mimeTypeXML () - .build (), - s_aResMgr)); + .data (ClassPathResource.getAsFile (AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML)) + .mimeTypeXML () + .build (), s_aResMgr)); aAttachments.add (WSS4JAttachment.createOutgoingFileAttachment (AS4OutgoingAttachment.builder () - .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_TEST_IMG_JPG)) - .mimeType (CMimeType.IMAGE_JPG) - .build (), - s_aResMgr)); + .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_TEST_IMG_JPG)) + .mimeType (CMimeType.IMAGE_JPG) + .build (), s_aResMgr)); aAttachments.add (WSS4JAttachment.createOutgoingFileAttachment (AS4OutgoingAttachment.builder () - .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_SHORTXML2_XML)) - .mimeTypeXML () - .build (), - s_aResMgr)); + .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_SHORTXML2_XML)) + .mimeTypeXML () + .build (), s_aResMgr)); final AS4MimeMessage aMimeMsg = AS4Encryptor.encryptMimeMessage (m_eSOAPVersion, MockMessages.createUserMessageNotSigned (m_eSOAPVersion, @@ -177,7 +166,6 @@ public void testUserMessageManyAttachmentsEncryptedMimeSuccess () throws WSSecur final String sResponse = sendMimeMessage (HttpMimeMessageEntity.create (aMimeMsg), true, null); assertTrue (sResponse.contains (AS4TestConstants.RECEIPT_ASSERTCHECK)); - } @Test @@ -185,20 +173,17 @@ public void testUserMessageManyAttachmentsSignedEncryptedMimeSuccess () throws W { final ICommonsList aAttachments = new CommonsArrayList <> (); aAttachments.add (WSS4JAttachment.createOutgoingFileAttachment (AS4OutgoingAttachment.builder () - .data (ClassPathResource.getAsFile (AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML)) - .mimeTypeXML () - .build (), - s_aResMgr)); + .data (ClassPathResource.getAsFile (AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML)) + .mimeTypeXML () + .build (), s_aResMgr)); aAttachments.add (WSS4JAttachment.createOutgoingFileAttachment (AS4OutgoingAttachment.builder () - .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_TEST_IMG_JPG)) - .mimeType (CMimeType.IMAGE_JPG) - .build (), - s_aResMgr)); + .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_TEST_IMG_JPG)) + .mimeType (CMimeType.IMAGE_JPG) + .build (), s_aResMgr)); aAttachments.add (WSS4JAttachment.createOutgoingFileAttachment (AS4OutgoingAttachment.builder () - .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_SHORTXML2_XML)) - .mimeTypeXML () - .build (), - s_aResMgr)); + .data (ClassPathResource.getAsFile (AS4TestConstants.ATTACHMENT_SHORTXML2_XML)) + .mimeTypeXML () + .build (), s_aResMgr)); final AS4UserMessage aMsg = MockMessages.createUserMessageNotSigned (m_eSOAPVersion, null, aAttachments); final Document aDoc = AS4Signer.createSignedMessage (m_aCryptoFactory, diff --git a/phase4-test/src/test/java/com/helger/phase4/server/servlet/CEFProfileTest.java b/phase4-test/src/test/java/com/helger/phase4/server/servlet/CEFProfileTest.java index 27c98a05d..52672b336 100644 --- a/phase4-test/src/test/java/com/helger/phase4/server/servlet/CEFProfileTest.java +++ b/phase4-test/src/test/java/com/helger/phase4/server/servlet/CEFProfileTest.java @@ -40,9 +40,9 @@ import com.helger.phase4.http.HttpXMLEntity; import com.helger.phase4.messaging.domain.AS4UserMessage; import com.helger.phase4.messaging.domain.MessageHelperMethods; -import com.helger.phase4.profile.cef.AS4CEFProfileRegistarSPI; import com.helger.phase4.servlet.mgr.AS4ProfileSelector; import com.helger.phase4.soap.ESoapVersion; +import com.helger.phase4.test.profile.AS4TestProfileRegistarSPI; import com.helger.xml.serialize.read.DOMReader; /** @@ -92,7 +92,7 @@ public void before () // Default MessageProperties for testing m_aEbms3UserMessage.setMessageProperties (createDefaultProperties ()); - AS4ProfileSelector.setCustomAS4ProfileID (AS4CEFProfileRegistarSPI.AS4_PROFILE_ID_FOUR_CORNER); + AS4ProfileSelector.setCustomAS4ProfileID (AS4TestProfileRegistarSPI.AS4_PROFILE_ID_FOUR_CORNER); } @After diff --git a/phase4-test/src/test/java/com/helger/phase4/server/servlet/TwoWayAsyncPullPushTest.java b/phase4-test/src/test/java/com/helger/phase4/server/servlet/TwoWayAsyncPullPushTest.java index 0388241b3..e152dc244 100644 --- a/phase4-test/src/test/java/com/helger/phase4/server/servlet/TwoWayAsyncPullPushTest.java +++ b/phase4-test/src/test/java/com/helger/phase4/server/servlet/TwoWayAsyncPullPushTest.java @@ -47,10 +47,10 @@ import com.helger.phase4.model.pmode.PMode; import com.helger.phase4.model.pmode.PModeParty; import com.helger.phase4.model.pmode.leg.PModeLeg; -import com.helger.phase4.profile.cef.CEFPMode; import com.helger.phase4.server.MockJettySetup; import com.helger.phase4.server.standalone.RunInJettyAS4TEST9090; import com.helger.phase4.soap.ESoapVersion; +import com.helger.phase4.test.profile.TestPMode; import com.helger.photon.core.servlet.WebAppListener; import com.helger.xml.serialize.read.DOMReader; @@ -79,7 +79,7 @@ public static void afterClass () throws Exception @Before public void before () { - final PMode aPMode = CEFPMode.createCEFPMode (AS4TestConstants.TEST_INITIATOR, + final PMode aPMode = TestPMode.createTestPMode (AS4TestConstants.TEST_INITIATOR, AS4TestConstants.TEST_RESPONDER, MockJettySetup.getServerAddressFromSettings (), (i, r) -> "pmode" + GlobalIDFactory.getNewPersistentLongID (), diff --git a/phase4-test/src/test/java/com/helger/phase4/server/servlet/TwoWayAsyncPushPullTest.java b/phase4-test/src/test/java/com/helger/phase4/server/servlet/TwoWayAsyncPushPullTest.java index 29224e5f9..8aa2da561 100644 --- a/phase4-test/src/test/java/com/helger/phase4/server/servlet/TwoWayAsyncPushPullTest.java +++ b/phase4-test/src/test/java/com/helger/phase4/server/servlet/TwoWayAsyncPushPullTest.java @@ -47,10 +47,10 @@ import com.helger.phase4.model.pmode.PMode; import com.helger.phase4.model.pmode.PModeParty; import com.helger.phase4.model.pmode.leg.PModeLeg; -import com.helger.phase4.profile.cef.CEFPMode; import com.helger.phase4.server.MockJettySetup; import com.helger.phase4.server.standalone.RunInJettyAS4TEST9090; import com.helger.phase4.soap.ESoapVersion; +import com.helger.phase4.test.profile.TestPMode; import com.helger.photon.core.servlet.WebAppListener; import com.helger.xml.serialize.read.DOMReader; @@ -79,7 +79,7 @@ public static void afterClass () throws Exception @Before public void before () { - final PMode aPMode = CEFPMode.createCEFPMode (AS4TestConstants.TEST_INITIATOR, + final PMode aPMode = TestPMode.createTestPMode (AS4TestConstants.TEST_INITIATOR, AS4TestConstants.TEST_RESPONDER, MockJettySetup.getServerAddressFromSettings (), (i, r) -> "pmode" + GlobalIDFactory.getNewPersistentLongID (), diff --git a/phase4-test/src/test/java/com/helger/phase4/server/servlet/TwoWayMEPTest.java b/phase4-test/src/test/java/com/helger/phase4/server/servlet/TwoWayMEPTest.java index 32d9cf70e..a8bff58d1 100644 --- a/phase4-test/src/test/java/com/helger/phase4/server/servlet/TwoWayMEPTest.java +++ b/phase4-test/src/test/java/com/helger/phase4/server/servlet/TwoWayMEPTest.java @@ -46,9 +46,9 @@ import com.helger.phase4.model.pmode.PMode; import com.helger.phase4.model.pmode.PModeParty; import com.helger.phase4.model.pmode.leg.PModeLeg; -import com.helger.phase4.profile.cef.CEFPMode; import com.helger.phase4.server.MockJettySetup; import com.helger.phase4.soap.ESoapVersion; +import com.helger.phase4.test.profile.TestPMode; import com.helger.xml.serialize.read.DOMReader; public final class TwoWayMEPTest extends AbstractUserMessageTestSetUpExt @@ -59,7 +59,7 @@ public final class TwoWayMEPTest extends AbstractUserMessageTestSetUpExt @Before public void before () { - final PMode aPMode = CEFPMode.createCEFPMode (AS4TestConstants.TEST_INITIATOR, + final PMode aPMode = TestPMode.createTestPMode (AS4TestConstants.TEST_INITIATOR, AS4TestConstants.TEST_RESPONDER, MockJettySetup.getServerAddressFromSettings (), (i, r) -> "pmode" + GlobalIDFactory.getNewPersistentLongID (), diff --git a/phase4-test/src/test/java/com/helger/phase4/server/spi/MockPullRequestProcessorSPI.java b/phase4-test/src/test/java/com/helger/phase4/server/spi/MockPullRequestProcessorSPI.java index 651854caa..63075a880 100644 --- a/phase4-test/src/test/java/com/helger/phase4/server/spi/MockPullRequestProcessorSPI.java +++ b/phase4-test/src/test/java/com/helger/phase4/server/spi/MockPullRequestProcessorSPI.java @@ -25,8 +25,8 @@ import com.helger.phase4.model.EMEPBinding; import com.helger.phase4.model.pmode.IPMode; import com.helger.phase4.model.pmode.PMode; -import com.helger.phase4.profile.cef.CEFPMode; import com.helger.phase4.servlet.spi.IAS4ServletPullRequestProcessorSPI; +import com.helger.phase4.test.profile.TestPMode; @IsSPIImplementation public class MockPullRequestProcessorSPI implements IAS4ServletPullRequestProcessorSPI @@ -34,7 +34,7 @@ public class MockPullRequestProcessorSPI implements IAS4ServletPullRequestProces @Nonnull public IPMode findPMode (@Nonnull final Ebms3SignalMessage aSignalMessage) { - final PMode aPMode = CEFPMode.createCEFPMode ("pullinitiator", "pullresponder", null, (i, r) -> "PullPMode", false); + final PMode aPMode = TestPMode.createTestPMode ("pullinitiator", "pullresponder", null, (i, r) -> "PullPMode", false); if (aSignalMessage.getPullRequest () != null) { if (!aSignalMessage.getAny ().isEmpty ()) diff --git a/phase4-test/src/test/java/com/helger/phase4/server/standalone/RunInJettyAS4TEST9090.java b/phase4-test/src/test/java/com/helger/phase4/server/standalone/RunInJettyAS4TEST9090.java index 7503a0ed4..f71921a7c 100644 --- a/phase4-test/src/test/java/com/helger/phase4/server/standalone/RunInJettyAS4TEST9090.java +++ b/phase4-test/src/test/java/com/helger/phase4/server/standalone/RunInJettyAS4TEST9090.java @@ -19,7 +19,7 @@ import java.io.IOException; import com.helger.commons.io.resource.FileSystemResource; -import com.helger.phase4.ScopedConfig; +import com.helger.phase4.ScopedAS4Configuration; import com.helger.photon.jetty.JettyRunner; import com.helger.photon.jetty.JettyStopper; @@ -33,11 +33,11 @@ public final class RunInJettyAS4TEST9090 private static final int PORT = 9090; private static final int STOP_PORT = PORT + 1000; - private static ScopedConfig s_aSC; + private static ScopedAS4Configuration s_aSC; public static void startNinetyServer () throws Exception { - s_aSC = ScopedConfig.create (new FileSystemResource ("src/test/resources/test-phase4-9090.properties")); + s_aSC = ScopedAS4Configuration.create (new FileSystemResource ("src/test/resources/test-phase4-9090.properties")); final JettyRunner aJetty = new JettyRunner (); aJetty.setPort (PORT).setStopPort (STOP_PORT).setAllowAnnotationBasedConfig (false); aJetty.startServer ();