24 package org.lightjason.agentspeak.agent;
26 import com.tngtech.java.junit.dataprovider.DataProvider;
27 import com.tngtech.java.junit.dataprovider.DataProviderRunner;
28 import com.tngtech.java.junit.dataprovider.UseDataProvider;
29 import org.apache.commons.lang3.tuple.ImmutablePair;
30 import org.apache.commons.lang3.tuple.ImmutableTriple;
31 import org.apache.commons.lang3.tuple.Pair;
32 import org.apache.commons.lang3.tuple.Triple;
33 import org.junit.Assert;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
51 import javax.annotation.Nonnegative;
52 import javax.annotation.Nonnull;
53 import java.io.FileInputStream;
54 import java.io.InputStream;
55 import java.text.MessageFormat;
56 import java.util.ArrayList;
57 import java.util.Collections;
58 import java.util.List;
60 import java.util.logging.LogManager;
61 import java.util.stream.Collectors;
62 import java.util.stream.IntStream;
63 import java.util.stream.Stream;
70 @RunWith( DataProviderRunner.class )
81 LogManager.getLogManager().reset();
92 new ImmutableTriple<>(
"src/test/resources/agent/language/crypto.asl", 2, 9 ),
93 new ImmutableTriple<>(
"src/test/resources/agent/language/math.asl", 2, 10 ),
94 new ImmutableTriple<>(
"src/test/resources/agent/language/collection.asl", 2, 5 ),
95 new ImmutableTriple<>(
"src/test/resources/agent/language/generic.asl", 3, 27 ),
96 new ImmutableTriple<>(
"src/test/resources/agent/language/rules.asl", 2, 4 ),
97 new ImmutableTriple<>(
"src/test/resources/agent/language/trigger.asl", 3, 21 ),
98 new ImmutableTriple<>(
"src/test/resources/agent/language/execution.asl", 3, 4 ),
99 new ImmutableTriple<>(
"src/test/resources/agent/language/webservice.asl", 4, 5 )
109 m_testlog = Collections.synchronizedList(
new ArrayList<>() );
119 @UseDataProvider(
"generate" )
120 public final
void testASLDefault( final Triple<String, Number, Number> p_asl ) throws Exception
124 final InputStream l_stream =
new FileInputStream( p_asl.getLeft() )
134 ).collect( Collectors.toSet() )
137 IntStream.range( 0, p_asl.getMiddle().intValue() )
144 catch (
final Exception l_exception )
146 Assert.assertTrue( MessageFormat.format(
"{0}: {1}", p_asl.getLeft(), l_exception.getMessage() ),
false );
150 catch (
final Exception l_exception )
152 Assert.assertTrue( MessageFormat.format(
"{0}: {1}", p_asl.getLeft(), l_exception.getMessage() ),
false );
155 Assert.assertEquals( MessageFormat.format(
"{0} {1}",
"number of tests", p_asl.getLeft() ), p_asl.getRight().longValue(), m_testlog.size() );
157 MessageFormat.format(
"{0}", m_testlog.stream().filter( i -> !i.getLeft() ).map( Pair::getRight ).collect( Collectors.toList() ) ),
158 m_testlog.stream().anyMatch( Pair::getLeft )
172 private static final long serialVersionUID = 8344720639088993942L;
191 @Nonnull
final List<ITerm> p_argument, @Nonnull
final List<ITerm> p_return
206 private static final long serialVersionUID = 9032624165822970132L;
225 @Nonnull
final List<ITerm> p_argument, @Nonnull
final List<ITerm> p_return
230 p_argument.get( 0 ).<Boolean>raw(),
231 p_argument.size() > 1
232 ? p_argument.get( 1 ).<String>raw()
249 private static final long serialVersionUID = 7077303993134371057L;
258 super( p_configuration );
274 CAgentGenerator(
final InputStream p_stream,
final Set<IAction> p_actions )
throws Exception
276 super( p_stream, p_actions, ( p_agent, p_runningcontext ) -> Stream.of(
278 new CConstant<>(
"MyConstString",
"here is a test string" )
285 return new CAgent( m_configuration );
CAgent(final IAgentConfiguration< IAgent<?>> p_configuration)
ctor
default implementation of an action
base test class with helpers
List< Pair< Boolean, String > > m_testlog
list with successful plans
static< N > IFuzzyValue< N > from( @Nonnull final N p_value)
factory
final IPath name()
returns the name with path of the action
final IPath name()
returns the name with path of the action
static IPath from( @Nonnull final String p_string)
factor method to build path
final int minimalArgumentNumber()
minimum number of arguments
class to create a path structure
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
static Object [] generate()
data provider for defining asl files
execution context with local data
external action interface
static Stream< IAction > actionsFromPackage( @Nullable final String... p_package)
get all classes within an Java package as action
final void initialize()
return list initialize
result for an immutable fuzzy value
interface to define the agent configuration
final int minimalArgumentNumber()
minimum number of arguments
CAgentGenerator(final InputStream p_stream, final Set< IAction > p_actions)
ctor
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
class for any helper calls
IAgent<?> generatesingle(final Object... p_data)