LightJason - AgentSpeak(L++)
TestCPropertyBeliefbase.java
Go to the documentation of this file.
1 /*
2  * @cond LICENSE
3  * ######################################################################################
4  * # LGPL License #
5  * # #
6  * # This file is part of the LightJason AgentSpeak(L++) #
7  * # Copyright (c) 2015-19, LightJason (info@lightjason.org) #
8  * # This program is free software: you can redistribute it and/or modify #
9  * # it under the terms of the GNU Lesser General Public License as #
10  * # published by the Free Software Foundation, either version 3 of the #
11  * # License, or (at your option) any later version. #
12  * # #
13  * # This program is distributed in the hope that it will be useful, #
14  * # but WITHOUT ANY WARRANTY; without even the implied warranty of #
15  * # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
16  * # GNU Lesser General Public License for more details. #
17  * # #
18  * # You should have received a copy of the GNU Lesser General Public License #
19  * # along with this program. If not, see http://www.gnu.org/licenses/ #
20  * ######################################################################################
21  * @endcond
22  */
23 
24 package org.lightjason.agentspeak.beliefbase;
25 
26 import org.apache.commons.io.IOUtils;
27 import org.junit.Assert;
28 import org.junit.Test;
37 
38 import java.util.Collections;
39 import java.util.stream.Stream;
40 
41 
45 public final class TestCPropertyBeliefbase extends IBaseTest
46 {
47 
53  @Test
54  public final void belieflist() throws Exception
55  {
56  final IAgent<?> l_agent = new CAgent.CAgentGenerator( "" ).generatesingle();
57 
58  if ( PRINTENABLE )
59  l_agent.beliefbase().stream().forEach( System.out::println );
60 
61  Assert.assertArrayEquals(
62  Stream.of(
63  CLiteral.from( "self/m_stringvalue", CRawTerm.EMPTY ),
64  CLiteral.from( "self/m_integervalue", CRawTerm.from( 42 ) )
65  ).toArray(),
66  l_agent.beliefbase().stream().toArray()
67  );
68  }
69 
70  // ---------------------------------------------------------------------------------------------------------------------------------------------------------
71 
72 
76  private static final class CAgent extends IBaseAgent<IAgent<?>>
77  {
81  private static final long serialVersionUID = 3053608318122134408L;
85  private String m_stringvalue;
89  private final int m_integervalue = 42;
93  private final transient String m_stringvaluenotlisten = "not shown";
94 
95 
101  private CAgent( final IAgentConfiguration<IAgent<?>> p_configuration )
102  {
103  super( p_configuration );
104  m_beliefbase.add( new CBeliefbase( new CClassStorage<>( this ) ).create( "self", m_beliefbase ) );
105  }
106 
110  private static final class CAgentGenerator extends IBaseAgentGenerator<IAgent<?>>
111  {
112 
119  CAgentGenerator( final String p_asl ) throws Exception
120  {
121  super( IOUtils.toInputStream( p_asl, "UTF-8" ), Collections.emptySet() );
122  }
123 
124  @Override
125  public IAgent<?> generatesingle( final Object... p_data )
126  {
127  return new CAgent( m_configuration );
128  }
129  }
130 
131  }
132 
133 }
base test class with helpers
Definition: IBaseTest.java:33
CAgent(final IAgentConfiguration< IAgent<?>> p_configuration)
ctor
Stream< ILiteral > stream( @Nullable final IPath... p_path)
returns stream of literal
static final ITerm EMPTY
empty raw term
Definition: CRawTerm.java:50
static final boolean PRINTENABLE
enable printing of test-data
Definition: IBaseTest.java:38
default generic literal class for agent beliefs a literal consists of a functor, an optional list of ...
Definition: CLiteral.java:64
static< N > CRawTerm< N > from(final N p_value)
factory for a raw term
Definition: CRawTerm.java:104
static ILiteral from( @Nonnull final String p_functor, @Nullable final ITerm... p_values)
factory
Definition: CLiteral.java:161
IView add( @Nonnull final ILiteral... p_literal)
adds a literal in the current structure
IView beliefbase()
returns the beliefbase
belief storage to get access to all class attributes
term structure for simple datatypes
Definition: CRawTerm.java:45
beliefbase to generate any event-based data by reference counting
final IAgentConfiguration< T > m_configuration
configuration of an agent