24 package org.lightjason.agentspeak.action.builtin;
26 import com.codepoetics.protonpack.StreamUtils;
27 import com.tngtech.java.junit.dataprovider.DataProvider;
28 import com.tngtech.java.junit.dataprovider.DataProviderRunner;
29 import com.tngtech.java.junit.dataprovider.UseDataProvider;
30 import org.apache.commons.lang3.tuple.ImmutablePair;
31 import org.apache.commons.lang3.tuple.ImmutableTriple;
32 import org.apache.commons.lang3.tuple.Pair;
33 import org.apache.commons.lang3.tuple.Triple;
34 import org.junit.Assert;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
48 import javax.crypto.KeyGenerator;
49 import java.security.Key;
50 import java.security.NoSuchAlgorithmException;
51 import java.util.ArrayList;
52 import java.util.Collections;
53 import java.util.List;
54 import java.util.stream.Collectors;
55 import java.util.stream.Stream;
61 @RunWith( DataProviderRunner.class )
73 return StreamUtils.zip(
74 Stream.of(
"adler-32",
"crc-32",
"crc-32c",
"murmur3-32",
"murmur3-128",
"siphash-2-4" ),
75 Stream.of(
new String[]{
"7804c01a",
"911c63b0"},
new String[]{
"45154713",
"29369833"},
76 new String[]{
"387e0716",
"4411bf68"},
new String[]{
"306202a8",
"08b9852d"},
77 new String[]{
"636cc4ff5f7ed59b51f29d6d949b4709",
"f4459439308d1248efc0532fb4cd6d79"},
78 new String[]{
"4f27c08e5981bc5a",
"82ee572bf0a0dde4"}
91 @UseDataProvider(
"generatecrypt" )
92 public final
void createkey( final Triple<String, Integer, Integer> p_crypt )
94 final List<ITerm> l_return =
new ArrayList<>();
98 Stream.of(
CRawTerm.
from( p_crypt.getLeft() ) ).collect( Collectors.toList() ),
102 Assert.assertEquals( l_return.size(), p_crypt.getMiddle().intValue() );
114 final Key l_key = KeyGenerator.getInstance(
"HmacSHA1" ).generateKey();
119 Stream.of( l_key ).map(
CRawTerm::from ).collect( Collectors.toList() ),
120 Collections.emptyList()
128 Stream.of( l_key ).map(
CRawTerm::from ).collect( Collectors.toList() ),
129 Collections.emptyList()
143 final List<ITerm> l_return =
new ArrayList<>();
147 Stream.of( l_key.getLeft(),
"xxx" ).map(
CRawTerm::from ).collect( Collectors.toList() ),
151 Assert.assertEquals( l_return.size(), 1 );
155 Stream.of( l_key.getLeft(), l_return.get( 0 ).<String>raw() ).map(
CRawTerm::from ).collect( Collectors.toList() ),
167 @UseDataProvider(
"generatehash" )
168 public final
void hash( final Pair<String, String[]> p_hash )
170 final List<ITerm> l_return =
new ArrayList<>();
178 Assert.assertArrayEquals( l_return.stream().map(
ITerm::<String>raw ).toArray( String[]::
new ), p_hash.getRight() );
185 public final
void hashexception()
190 Collections.emptyList()
203 new ImmutableTriple<>(
"des", 1, 0 ),
204 new ImmutableTriple<>(
"aes", 1, 0 ),
205 new ImmutableTriple<>(
"rsa", 2, 1 )
219 Stream.of(
CRawTerm.
from(
"test" ) ).collect( Collectors.toList() ),
220 Collections.emptyList()
231 @UseDataProvider(
"generatecrypt" )
232 public final
void encryptdecreypt( final Triple<String, Integer, Integer> p_crypt )
234 final List<ITerm> l_returnkey =
new ArrayList<>();
238 Stream.of(
CRawTerm.
from( p_crypt.getLeft() ) ).collect( Collectors.toList() ),
242 Assert.assertEquals( l_returnkey.size(), p_crypt.getMiddle().intValue() );
245 final List<ITerm> l_returnencrypt =
new ArrayList<>();
249 Stream.of( l_returnkey.get( 0 ),
CRawTerm.
from(
"test string" ),
CRawTerm.
from( 12345 ) ).collect( Collectors.toList() ),
254 final List<ITerm> l_return =
new ArrayList<>();
258 Stream.concat( Stream.of( l_returnkey.get( p_crypt.getRight() ) ), l_returnencrypt.stream() ).collect( Collectors.toList() ),
263 Assert.assertEquals( l_return.size(), 2 );
264 Assert.assertEquals( l_return.get( 0 ).raw(),
"test string" );
265 Assert.assertEquals( l_return.get( 1 ).<Number>raw(), 12345 );
static Object [] generatecrypt()
data provider generator of crypt key definition
base test class with helpers
creates an encrypting / decrypting key pair.
IContext EMPTYPLAN
empty context with plan
dencrypting algorithm for decrypting data.
final void wrongalgorithm()
test wrong algorithm
execution context with local data
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
enum with encrypting types
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
final void decryptexecutionerror()
test decrypt execution array
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
final void createkeyError()
test key generation on error call
static< N > CRawTerm< N > from(final N p_value)
factory for a raw term
static Object [] generatehash()
data provider generator of hash definition
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
term structure for simple datatypes