Skip to content

Commit

Permalink
Test fix; changed mock PMode names
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Jan 26, 2017
1 parent 061d463 commit db773cc
Show file tree
Hide file tree
Showing 12 changed files with 656 additions and 682 deletions.
330 changes: 171 additions & 159 deletions ph-as4-lib/src/main/java/com/helger/as4/mock/MockPModeGenerator.java
Original file line number Diff line number Diff line change
@@ -1,159 +1,171 @@
/**
* Copyright (C) 2015-2017 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.as4.mock;

import javax.annotation.Nonnull;

import com.helger.as4.crypto.ECryptoAlgorithmCrypt;
import com.helger.as4.crypto.ECryptoAlgorithmSign;
import com.helger.as4.crypto.ECryptoAlgorithmSignDigest;
import com.helger.as4.mgr.MetaAS4Manager;
import com.helger.as4.model.EMEP;
import com.helger.as4.model.ETransportChannelBinding;
import com.helger.as4.model.pmode.EPModeSendReceiptReplyPattern;
import com.helger.as4.model.pmode.PMode;
import com.helger.as4.model.pmode.PModeParty;
import com.helger.as4.model.pmode.config.PModeConfig;
import com.helger.as4.model.pmode.leg.PModeLeg;
import com.helger.as4.model.pmode.leg.PModeLegBusinessInformation;
import com.helger.as4.model.pmode.leg.PModeLegErrorHandling;
import com.helger.as4.model.pmode.leg.PModeLegProtocol;
import com.helger.as4.model.pmode.leg.PModeLegReliability;
import com.helger.as4.model.pmode.leg.PModeLegSecurity;
import com.helger.as4.soap.ESOAPVersion;
import com.helger.as4.wss.EWSSVersion;
import com.helger.commons.state.ETriState;

public final class MockPModeGenerator
{
public static String PMODE_CONFIG_ID_SOAP11_TEST = "pmode-test11";
public static String PMODE_CONFIG_ID_SOAP12_TEST = "pmode-test";

private MockPModeGenerator ()
{}

@Nonnull
public static PModeConfig getTestPModeConfig (@Nonnull final ESOAPVersion eSOAPVersion)
{
return getTestPModeConfigSetID (eSOAPVersion,
eSOAPVersion.equals (ESOAPVersion.SOAP_12) ? PMODE_CONFIG_ID_SOAP12_TEST
: PMODE_CONFIG_ID_SOAP11_TEST);
}

@Nonnull
public static PModeConfig getTestPModeConfigSetID (@Nonnull final ESOAPVersion eSOAPVersion, final String sPModeID)
{
final PModeConfig aConfig = new PModeConfig (sPModeID);
aConfig.setMEP (EMEP.ONE_WAY);
aConfig.setMEPBinding (ETransportChannelBinding.PUSH);
aConfig.setLeg1 (_generatePModeLeg (eSOAPVersion));
// Leg 2 stays null, because we only use one-way
return aConfig;
}

@Nonnull
private static PMode _createTestPMode (@Nonnull final PModeConfig aConfig)
{
MetaAS4Manager.getPModeConfigMgr ().createPModeConfigIfNotExisting (aConfig);
return new PMode (_generateInitiatorOrResponder (true), _generateInitiatorOrResponder (false), aConfig);
}

@Nonnull
public static PMode getTestPMode (@Nonnull final ESOAPVersion eSOAPVersion)
{
return _createTestPMode (getTestPModeConfig (eSOAPVersion));
}

@Nonnull
public static PMode getTestPModeSetID (@Nonnull final ESOAPVersion eSOAPVersion, @Nonnull final String sPModeID)
{
return _createTestPMode (getTestPModeConfigSetID (eSOAPVersion, sPModeID));
}

@Nonnull
public static PMode getTestPModeWithSecurity (@Nonnull final ESOAPVersion eSOAPVersion)
{
final PModeConfig aConfig = getTestPModeConfig (eSOAPVersion);

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.setSendReceiptReplyPattern (EPModeSendReceiptReplyPattern.RESPONSE);
aPModeLegSecurity.setSendReceiptNonRepudiation (true);

aConfig.setLeg1 (new PModeLeg (_generatePModeLegProtocol (eSOAPVersion),
_generatePModeLegBusinessInformation (),
_generatePModeLegErrorHandling (),
null,
aPModeLegSecurity));
// Leg 2 stays null, because we only use one-way
return _createTestPMode (aConfig);

}

@Nonnull
private static PModeLeg _generatePModeLeg (@Nonnull final ESOAPVersion eSOAPVersion)
{
final PModeLegReliability aPModeLegReliability = null;
final PModeLegSecurity aPModeLegSecurity = null;
return new PModeLeg (_generatePModeLegProtocol (eSOAPVersion),
_generatePModeLegBusinessInformation (),
_generatePModeLegErrorHandling (),
aPModeLegReliability,
aPModeLegSecurity);
}

private static PModeLegErrorHandling _generatePModeLegErrorHandling ()
{
return new PModeLegErrorHandling (null, null, ETriState.TRUE, ETriState.TRUE, ETriState.TRUE, ETriState.TRUE);
}

@Nonnull
private static PModeLegBusinessInformation _generatePModeLegBusinessInformation ()
{
return new PModeLegBusinessInformation ("http://docs.oasis-open.org/ebxml-msg/ebms/v3.0/ns/core/200704/test",
null,
null,
null,
null,
"http://docs.oasis-open.org/ebxml-msg/ebms/v3.0/ns/core/200704/defaultMPC");
}

@Nonnull
private static PModeLegProtocol _generatePModeLegProtocol (@Nonnull final ESOAPVersion eSOAPVersion)
{
return new PModeLegProtocol ("http://localhost:8080", eSOAPVersion);
}

@Nonnull
private static PModeParty _generateInitiatorOrResponder (final boolean bInitiator)
{
if (bInitiator)
return new PModeParty (null,
"APP_1000000101",
"http://docs.oasis-open.org/ebxml-msg/ebms/v3.0/ns/core/200704/sender",
null,
null);
return new PModeParty (null,
"APP_1000000101",
"http://docs.oasis-open.org/ebxml-msg/ebms/v3.0/ns/core/200704/responder",
null,
null);
}
}
/**
* Copyright (C) 2015-2017 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.as4.mock;

import javax.annotation.Nonnull;

import com.helger.as4.crypto.ECryptoAlgorithmCrypt;
import com.helger.as4.crypto.ECryptoAlgorithmSign;
import com.helger.as4.crypto.ECryptoAlgorithmSignDigest;
import com.helger.as4.mgr.MetaAS4Manager;
import com.helger.as4.model.EMEP;
import com.helger.as4.model.ETransportChannelBinding;
import com.helger.as4.model.pmode.EPModeSendReceiptReplyPattern;
import com.helger.as4.model.pmode.PMode;
import com.helger.as4.model.pmode.PModeManager;
import com.helger.as4.model.pmode.PModeParty;
import com.helger.as4.model.pmode.config.PModeConfig;
import com.helger.as4.model.pmode.leg.PModeLeg;
import com.helger.as4.model.pmode.leg.PModeLegBusinessInformation;
import com.helger.as4.model.pmode.leg.PModeLegErrorHandling;
import com.helger.as4.model.pmode.leg.PModeLegProtocol;
import com.helger.as4.model.pmode.leg.PModeLegReliability;
import com.helger.as4.model.pmode.leg.PModeLegSecurity;
import com.helger.as4.soap.ESOAPVersion;
import com.helger.as4.wss.EWSSVersion;
import com.helger.commons.state.ETriState;

public final class MockPModeGenerator
{
public static String PMODE_CONFIG_ID_SOAP11_TEST = "mock-pmode-soap11";
public static String PMODE_CONFIG_ID_SOAP12_TEST = "mock-pmode-soap12";

private MockPModeGenerator ()
{}

@Nonnull
public static PModeConfig getTestPModeConfig (@Nonnull final ESOAPVersion eSOAPVersion)
{
return getTestPModeConfigSetID (eSOAPVersion,
eSOAPVersion.equals (ESOAPVersion.SOAP_12) ? PMODE_CONFIG_ID_SOAP12_TEST
: PMODE_CONFIG_ID_SOAP11_TEST);
}

@Nonnull
public static PModeConfig getTestPModeConfigSetID (@Nonnull final ESOAPVersion eSOAPVersion, final String sPModeID)
{
final PModeConfig aConfig = new PModeConfig (sPModeID);
aConfig.setMEP (EMEP.ONE_WAY);
aConfig.setMEPBinding (ETransportChannelBinding.PUSH);
aConfig.setLeg1 (_generatePModeLeg (eSOAPVersion));
// Leg 2 stays null, because we only use one-way
return aConfig;
}

@Nonnull
private static PMode _createTestPMode (@Nonnull final PModeConfig aConfig)
{
MetaAS4Manager.getPModeConfigMgr ().createOrUpdatePModeConfig (aConfig);
return new PMode (_generateInitiatorOrResponder (true), _generateInitiatorOrResponder (false), aConfig);
}

@Nonnull
public static PMode getTestPMode (@Nonnull final ESOAPVersion eSOAPVersion)
{
return _createTestPMode (getTestPModeConfig (eSOAPVersion));
}

@Nonnull
public static PMode getTestPModeSetID (@Nonnull final ESOAPVersion eSOAPVersion, @Nonnull final String sPModeID)
{
return _createTestPMode (getTestPModeConfigSetID (eSOAPVersion, sPModeID));
}

@Nonnull
public static PMode getTestPModeWithSecurity (@Nonnull final ESOAPVersion eSOAPVersion)
{
final PModeConfig aConfig = getTestPModeConfig (eSOAPVersion);

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.setSendReceiptReplyPattern (EPModeSendReceiptReplyPattern.RESPONSE);
aPModeLegSecurity.setSendReceiptNonRepudiation (true);

aConfig.setLeg1 (new PModeLeg (_generatePModeLegProtocol (eSOAPVersion),
_generatePModeLegBusinessInformation (),
_generatePModeLegErrorHandling (),
null,
aPModeLegSecurity));
// Leg 2 stays null, because we only use one-way
return _createTestPMode (aConfig);

}

@Nonnull
private static PModeLeg _generatePModeLeg (@Nonnull final ESOAPVersion eSOAPVersion)
{
final PModeLegReliability aPModeLegReliability = null;
final PModeLegSecurity aPModeLegSecurity = null;
return new PModeLeg (_generatePModeLegProtocol (eSOAPVersion),
_generatePModeLegBusinessInformation (),
_generatePModeLegErrorHandling (),
aPModeLegReliability,
aPModeLegSecurity);
}

private static PModeLegErrorHandling _generatePModeLegErrorHandling ()
{
return new PModeLegErrorHandling (null, null, ETriState.TRUE, ETriState.TRUE, ETriState.TRUE, ETriState.TRUE);
}

@Nonnull
private static PModeLegBusinessInformation _generatePModeLegBusinessInformation ()
{
return new PModeLegBusinessInformation ("http://docs.oasis-open.org/ebxml-msg/ebms/v3.0/ns/core/200704/test",
null,
null,
null,
null,
"http://docs.oasis-open.org/ebxml-msg/ebms/v3.0/ns/core/200704/defaultMPC");
}

@Nonnull
private static PModeLegProtocol _generatePModeLegProtocol (@Nonnull final ESOAPVersion eSOAPVersion)
{
return new PModeLegProtocol ("http://localhost:8080", eSOAPVersion);
}

@Nonnull
private static PModeParty _generateInitiatorOrResponder (final boolean bInitiator)
{
if (bInitiator)
return new PModeParty (null,
"APP_1000000101",
"http://docs.oasis-open.org/ebxml-msg/ebms/v3.0/ns/core/200704/sender",
null,
null);
return new PModeParty (null,
"APP_1000000101",
"http://docs.oasis-open.org/ebxml-msg/ebms/v3.0/ns/core/200704/responder",
null,
null);
}

public static void ensureMockPModesArePresent ()
{
final PModeManager aPModeMgr = MetaAS4Manager.getPModeMgr ();
for (final ESOAPVersion e : ESOAPVersion.values ())
{
final PMode aPMode = MockPModeGenerator.getTestPModeWithSecurity (e);
if (!aPModeMgr.containsWithID (aPMode.getID ()))
aPModeMgr.createPMode (aPMode);
}
}
}
Loading

0 comments on commit db773cc

Please sign in to comment.