Skip to content

Commit 900b7e0

Browse files
committed
Added some more tests
1 parent f195067 commit 900b7e0

File tree

6 files changed

+495
-0
lines changed

6 files changed

+495
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright (C) 2015-2026 Philip Helger (www.helger.com)
3+
* philip[at]helger[dot]com
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.helger.phase4.crypto;
18+
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertFalse;
21+
import static org.junit.Assert.assertNotNull;
22+
import static org.junit.Assert.assertNull;
23+
import static org.junit.Assert.assertTrue;
24+
25+
import org.junit.Test;
26+
27+
/**
28+
* Test class for class {@link AS4SigningParams}.
29+
*
30+
* @author Philip Helger
31+
*/
32+
public final class AS4SigningParamsTest
33+
{
34+
@Test
35+
public void testDefaultValues ()
36+
{
37+
final AS4SigningParams aParams = new AS4SigningParams ();
38+
assertNull (aParams.getAlgorithmSign ());
39+
assertNull (aParams.getAlgorithmSignDigest ());
40+
// Default params have no signing algorithm set
41+
assertFalse (aParams.isSigningEnabled ());
42+
assertEquals (ECryptoAlgorithmC14N.C14N_ALGORITHM_DEFAULT, aParams.getAlgorithmC14N ());
43+
assertEquals (ECryptoKeyIdentifierType.BST_DIRECT_REFERENCE, aParams.getKeyIdentifierType ());
44+
assertTrue (aParams.isUseSingleCertificate ());
45+
assertNull (aParams.getSecurityProviderSign ());
46+
assertNull (aParams.getSecurityProviderVerify ());
47+
assertFalse (aParams.hasWSSecSignatureCustomizer ());
48+
assertNull (aParams.getWSSecSignatureCustomizer ());
49+
}
50+
51+
@Test
52+
public void testSetAlgorithms ()
53+
{
54+
final AS4SigningParams aParams = new AS4SigningParams ();
55+
aParams.setAlgorithmSign (ECryptoAlgorithmSign.EDDSA_ED25519);
56+
assertEquals (ECryptoAlgorithmSign.EDDSA_ED25519, aParams.getAlgorithmSign ());
57+
58+
aParams.setAlgorithmSignDigest (ECryptoAlgorithmSignDigest.DIGEST_SHA_256);
59+
assertEquals (ECryptoAlgorithmSignDigest.DIGEST_SHA_256, aParams.getAlgorithmSignDigest ());
60+
61+
aParams.setAlgorithmC14N (ECryptoAlgorithmC14N.C14N_EXCL_OMIT_COMMENTS);
62+
assertEquals (ECryptoAlgorithmC14N.C14N_EXCL_OMIT_COMMENTS, aParams.getAlgorithmC14N ());
63+
}
64+
65+
@Test
66+
public void testClone ()
67+
{
68+
final AS4SigningParams aParams = new AS4SigningParams ();
69+
aParams.setAlgorithmSign (ECryptoAlgorithmSign.ECDSA_SHA_384)
70+
.setAlgorithmSignDigest (ECryptoAlgorithmSignDigest.DIGEST_SHA_384)
71+
.setUseSingleCertificate (false);
72+
73+
final AS4SigningParams aClone = aParams.getClone ();
74+
assertNotNull (aClone);
75+
assertEquals (ECryptoAlgorithmSign.ECDSA_SHA_384, aClone.getAlgorithmSign ());
76+
assertEquals (ECryptoAlgorithmSignDigest.DIGEST_SHA_384, aClone.getAlgorithmSignDigest ());
77+
assertFalse (aClone.isUseSingleCertificate ());
78+
}
79+
80+
@Test
81+
public void testToString ()
82+
{
83+
final AS4SigningParams aParams = new AS4SigningParams ();
84+
final String s = aParams.toString ();
85+
assertNotNull (s);
86+
assertTrue (s.contains ("AlgorithmSign"));
87+
}
88+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (C) 2015-2026 Philip Helger (www.helger.com)
3+
* philip[at]helger[dot]com
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.helger.phase4.model;
18+
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertFalse;
21+
import static org.junit.Assert.assertNotNull;
22+
import static org.junit.Assert.assertNull;
23+
import static org.junit.Assert.assertSame;
24+
import static org.junit.Assert.assertTrue;
25+
26+
import org.junit.Test;
27+
28+
import com.helger.base.string.StringHelper;
29+
30+
/**
31+
* Test class for class {@link EMEP}.
32+
*
33+
* @author Philip Helger
34+
*/
35+
public final class EMEPTest
36+
{
37+
@Test
38+
public void testBasic ()
39+
{
40+
for (final EMEP e : EMEP.values ())
41+
{
42+
assertTrue (StringHelper.isNotEmpty (e.getID ()));
43+
assertTrue (StringHelper.isNotEmpty (e.getURI ()));
44+
assertSame (e, EMEP.getFromIDOrNull (e.getID ()));
45+
assertSame (e, EMEP.getFromURIOrNull (e.getURI ()));
46+
assertTrue (e.getMessageCount () > 0);
47+
}
48+
}
49+
50+
@Test
51+
public void testOneWay ()
52+
{
53+
assertTrue (EMEP.ONE_WAY.isOneWay ());
54+
assertFalse (EMEP.ONE_WAY.isTwoWay ());
55+
assertEquals (1, EMEP.ONE_WAY.getMessageCount ());
56+
}
57+
58+
@Test
59+
public void testTwoWay ()
60+
{
61+
assertFalse (EMEP.TWO_WAY.isOneWay ());
62+
assertTrue (EMEP.TWO_WAY.isTwoWay ());
63+
assertEquals (2, EMEP.TWO_WAY.getMessageCount ());
64+
}
65+
66+
@Test
67+
public void testDefault ()
68+
{
69+
assertNotNull (EMEP.DEFAULT_EBMS);
70+
assertSame (EMEP.ONE_WAY, EMEP.DEFAULT_EBMS);
71+
}
72+
73+
@Test
74+
public void testUnknown ()
75+
{
76+
assertNull (EMEP.getFromIDOrNull ("does-not-exist"));
77+
assertNull (EMEP.getFromIDOrNull (null));
78+
assertNull (EMEP.getFromURIOrNull (null));
79+
assertNull (EMEP.getFromURIOrNull (""));
80+
}
81+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright (C) 2015-2026 Philip Helger (www.helger.com)
3+
* philip[at]helger[dot]com
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.helger.phase4.model;
18+
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertFalse;
21+
import static org.junit.Assert.assertNotNull;
22+
import static org.junit.Assert.assertNull;
23+
import static org.junit.Assert.assertSame;
24+
import static org.junit.Assert.assertTrue;
25+
26+
import java.nio.charset.StandardCharsets;
27+
28+
import org.junit.Test;
29+
30+
import com.helger.base.string.StringHelper;
31+
32+
/**
33+
* Test class for class {@link ESoapVersion}.
34+
*
35+
* @author Philip Helger
36+
*/
37+
public final class ESoapVersionTest
38+
{
39+
@Test
40+
public void testBasic ()
41+
{
42+
for (final ESoapVersion e : ESoapVersion.values ())
43+
{
44+
assertTrue (StringHelper.isNotEmpty (e.getNamespaceURI ()));
45+
assertTrue (StringHelper.isNotEmpty (e.getNamespacePrefix ()));
46+
assertTrue (StringHelper.isNotEmpty (e.getVersion ()));
47+
assertNotNull (e.getMimeType ());
48+
assertNotNull (e.getHeaderElementName ());
49+
assertNotNull (e.getBodyElementName ());
50+
assertSame (e, ESoapVersion.getFromVersionOrNull (e.getVersion ()));
51+
assertSame (e, ESoapVersion.getFromNamespaceURIOrNull (e.getNamespaceURI ()));
52+
assertSame (e, ESoapVersion.getFromMimeTypeOrNull (e.getMimeType ()));
53+
}
54+
}
55+
56+
@Test
57+
public void testSoap11 ()
58+
{
59+
assertEquals ("1.1", ESoapVersion.SOAP_11.getVersion ());
60+
assertEquals ("S11", ESoapVersion.SOAP_11.getNamespacePrefix ());
61+
assertFalse (ESoapVersion.SOAP_11.isAS4Default ());
62+
assertEquals ("1", ESoapVersion.SOAP_11.getMustUnderstandValue (true));
63+
assertEquals ("0", ESoapVersion.SOAP_11.getMustUnderstandValue (false));
64+
}
65+
66+
@Test
67+
public void testSoap12 ()
68+
{
69+
assertEquals ("1.2", ESoapVersion.SOAP_12.getVersion ());
70+
assertEquals ("S12", ESoapVersion.SOAP_12.getNamespacePrefix ());
71+
assertTrue (ESoapVersion.SOAP_12.isAS4Default ());
72+
assertEquals ("true", ESoapVersion.SOAP_12.getMustUnderstandValue (true));
73+
assertEquals ("false", ESoapVersion.SOAP_12.getMustUnderstandValue (false));
74+
}
75+
76+
@Test
77+
public void testAS4Default ()
78+
{
79+
assertSame (ESoapVersion.SOAP_12, ESoapVersion.AS4_DEFAULT);
80+
}
81+
82+
@Test
83+
public void testMimeTypeWithCharset ()
84+
{
85+
assertNotNull (ESoapVersion.SOAP_12.getMimeType (StandardCharsets.UTF_8));
86+
}
87+
88+
@Test
89+
public void testUnknown ()
90+
{
91+
assertNull (ESoapVersion.getFromVersionOrNull (null));
92+
assertNull (ESoapVersion.getFromVersionOrNull (""));
93+
assertNull (ESoapVersion.getFromVersionOrNull ("9.9"));
94+
assertNull (ESoapVersion.getFromNamespaceURIOrNull (null));
95+
assertNull (ESoapVersion.getFromNamespaceURIOrNull (""));
96+
assertNull (ESoapVersion.getFromMimeTypeOrNull (null));
97+
assertSame (ESoapVersion.SOAP_12,
98+
ESoapVersion.getFromVersionOrDefault ("does-not-exist", ESoapVersion.SOAP_12));
99+
}
100+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (C) 2015-2026 Philip Helger (www.helger.com)
3+
* philip[at]helger[dot]com
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.helger.phase4.model.message;
18+
19+
import static org.junit.Assert.assertFalse;
20+
import static org.junit.Assert.assertNotNull;
21+
import static org.junit.Assert.assertNull;
22+
import static org.junit.Assert.assertSame;
23+
import static org.junit.Assert.assertTrue;
24+
25+
import org.junit.Test;
26+
27+
import com.helger.base.string.StringHelper;
28+
29+
/**
30+
* Test class for class {@link EAS4MessageType}.
31+
*
32+
* @author Philip Helger
33+
*/
34+
public final class EAS4MessageTypeTest
35+
{
36+
@Test
37+
public void testBasic ()
38+
{
39+
for (final EAS4MessageType e : EAS4MessageType.values ())
40+
{
41+
assertTrue (StringHelper.isNotEmpty (e.getID ()));
42+
assertTrue (StringHelper.isNotEmpty (e.getDisplayName ()));
43+
assertSame (e, EAS4MessageType.getFromIDOrNull (e.getID ()));
44+
// Each type is either a user message or a signal message
45+
assertTrue (e.isUserMessage () != e.isSignalMessage ());
46+
}
47+
}
48+
49+
@Test
50+
public void testUserMessage ()
51+
{
52+
assertTrue (EAS4MessageType.USER_MESSAGE.isUserMessage ());
53+
assertFalse (EAS4MessageType.USER_MESSAGE.isSignalMessage ());
54+
assertFalse (EAS4MessageType.USER_MESSAGE.isReceiptOrError ());
55+
}
56+
57+
@Test
58+
public void testSignalMessages ()
59+
{
60+
for (final EAS4MessageType e : new EAS4MessageType [] { EAS4MessageType.ERROR_MESSAGE,
61+
EAS4MessageType.PULL_REQUEST,
62+
EAS4MessageType.RECEIPT })
63+
{
64+
assertFalse (e.isUserMessage ());
65+
assertTrue (e.isSignalMessage ());
66+
}
67+
}
68+
69+
@Test
70+
public void testReceiptOrError ()
71+
{
72+
assertTrue (EAS4MessageType.RECEIPT.isReceiptOrError ());
73+
assertTrue (EAS4MessageType.ERROR_MESSAGE.isReceiptOrError ());
74+
assertFalse (EAS4MessageType.PULL_REQUEST.isReceiptOrError ());
75+
assertFalse (EAS4MessageType.USER_MESSAGE.isReceiptOrError ());
76+
}
77+
78+
@Test
79+
public void testUnknown ()
80+
{
81+
assertNull (EAS4MessageType.getFromIDOrNull ("does-not-exist"));
82+
assertNull (EAS4MessageType.getFromIDOrNull (null));
83+
}
84+
85+
@Test
86+
public void testDisplayNames ()
87+
{
88+
assertNotNull (EAS4MessageType.USER_MESSAGE.getDisplayName ());
89+
assertNotNull (EAS4MessageType.RECEIPT.getDisplayName ());
90+
assertNotNull (EAS4MessageType.ERROR_MESSAGE.getDisplayName ());
91+
assertNotNull (EAS4MessageType.PULL_REQUEST.getDisplayName ());
92+
}
93+
}

0 commit comments

Comments
 (0)