LightJason - AgentSpeak(L++)
TestCActionWebGraphQL.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.action.builtin;
25 
26 import org.junit.Assert;
27 import org.junit.Test;
36 
37 import java.util.ArrayList;
38 import java.util.List;
39 import java.util.stream.Collectors;
40 import java.util.stream.Stream;
41 
42 
46 public final class TestCActionWebGraphQL extends IBaseTest
47 {
48 
52  @Test
53  public final void queryliteral()
54  {
55  final List<ITerm> l_return = new ArrayList<>();
56 
57  Assert.assertTrue(
58  new CQueryLiteral().execute(
59  false,
61  Stream.of(
62  CRawTerm.from( "https://fakerql.com/graphql" ),
63  CLiteral.from(
64  "allUsers",
65  CLiteral.from( "id" ),
66  CLiteral.from( "firstName" ),
67  CLiteral.from( "lastName" )
68  ),
69  CRawTerm.from( "graphql" )
70  ).collect( Collectors.toList() ),
71  l_return
72  ).value()
73  );
74 
75  Assert.assertEquals( l_return.size(), 1 );
76  Assert.assertTrue( l_return.get( 0 ) instanceof ILiteral );
77  Assert.assertEquals( l_return.get( 0 ).<ILiteral>raw().functor(), "graphql" );
78  }
79 
80 
84  @Test
85  public final void querymanual()
86  {
87  final List<ITerm> l_return = new ArrayList<>();
88 
89  Assert.assertTrue(
90  new CQueryNative().execute(
91  false,
93  Stream.of(
94  CRawTerm.from( "https://fakerql.com/graphql" ),
95  CRawTerm.from( "{Product(id: \"cjdn6szou00dw25107gcuy114\") {id price name}}" ),
96  CRawTerm.from( "graphql" )
97  ).collect( Collectors.toList() ),
98  l_return
99  ).value()
100  );
101 
102  Assert.assertEquals( l_return.size(), 1 );
103  Assert.assertTrue( l_return.get( 0 ) instanceof ILiteral );
104  Assert.assertEquals( l_return.get( 0 ).<ILiteral>raw().functor(), "graphql" );
105 
106  // test-case returns random datasets back
107  Assert.assertEquals( l_return.get( 0 ).<ILiteral>raw().structurehash(), CLiteral.from(
108  "graphql", CLiteral.from(
109  "data", CLiteral.from(
110  "product", CLiteral.from(
111  "id",
112  CRawTerm.from( "cjdn6szou00dw25107gcuy114" )
113  ),
114  CLiteral.from(
115  "price",
116  CRawTerm.from( 126D )
117  ),
118  CLiteral.from(
119  "name",
120  CRawTerm.from( "Handmade Granite Cheese" )
121  )
122  )
123  )
124  ).structurehash() );
125  }
126 
127 }
base test class with helpers
Definition: IBaseTest.java:33
IContext EMPTYPLAN
empty context with plan
Definition: IContext.java:47
final void queryliteral()
run graphql query test with literal
action to run a graphql query by a native graphql query.
execution context with local data
Definition: IContext.java:42
int structurehash()
returns a hash value which defines a hash ove rthe structure
String functor()
returns the functor without path
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
final void querymanual()
run graphql query test with native query
term structure for simple datatypes
Definition: CRawTerm.java:45