use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class GrpcServerTest method setUp.
@Before
public void setUp() throws IOException {
doNothing().when(mockedPostProcessor).submit(any(CommitLog.class));
GrpcOpenRequestExecutor requestExecutor = new GrpcOpenRequestExecutorImpl(txFactory);
Server server = ServerBuilder.forPort(PORT).addService(new GrpcGraknService(requestExecutor, mockedPostProcessor)).build();
grpcServer = GrpcServer.create(server);
grpcServer.start();
QueryBuilder qb = mock(QueryBuilder.class);
when(tx.admin()).thenReturn(tx);
when(txFactory.tx(eq(MYKS), any())).thenReturn(tx);
when(tx.graql()).thenReturn(qb);
when(qb.parse(QUERY)).thenReturn(query);
when(query.results(any())).thenAnswer(params -> Stream.of(QueryResult.getDefaultInstance()));
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class DirectIsaTest method testMatchSyntax.
@Test
public void testMatchSyntax() {
QueryBuilder queryBuilder = tx.graql();
Match matchQuery;
GetQuery getQuery;
matchQuery = queryBuilder.match(x.directIsa(thingy1));
assertEquals("match $x isa! thingy1;", matchQuery.toString());
matchQuery = queryBuilder.match(x.directIsa(y));
assertEquals("match $x isa! $y;", matchQuery.toString());
getQuery = queryBuilder.parse("match $x isa! thingy1; get;");
assertEquals(queryBuilder.match(x.directIsa(thingy1)), getQuery.match());
getQuery = queryBuilder.parse("match $x isa! $y; get;");
assertEquals(queryBuilder.match(x.directIsa(y)), getQuery.match());
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class DirectIsaTest method testInsertSyntax.
@Test
public void testInsertSyntax() {
QueryBuilder queryBuilder = tx.graql();
InsertQuery insertQuery;
insertQuery = queryBuilder.insert(x.directIsa(thingy));
assertEquals("insert $x isa! thingy;", insertQuery.toString());
insertQuery = queryBuilder.parse("insert $x isa! thingy;");
assertEquals(queryBuilder.insert(x.directIsa(thingy)), insertQuery);
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class DirectIsaTest method whenInsertDirectIsa_InsertsADirectInstanceOfAType.
@Test
public void whenInsertDirectIsa_InsertsADirectInstanceOfAType() {
QueryBuilder queryBuilder = tx.graql();
queryBuilder.insert(x.directIsa(thingy)).execute();
assertEquals(1L, queryBuilder.parse("match $z isa! thingy; aggregate count;").execute());
assertEquals(2L, queryBuilder.parse("match $z isa thingy; aggregate count;").execute());
}
use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.
the class ReasoningTests method reusingResources_usingExistingResourceToDefineSubResource.
// TODO potentially a graql bug when executing match insert on shared resources
@Ignore
// Expected result: When the head of a rule contains resource assertions, the respective unique resources should be generated or reused.
@Test
public void reusingResources_usingExistingResourceToDefineSubResource() {
QueryBuilder qb = testSet14.tx().graql().infer(true);
String queryString = "match $x isa entity1, has subResource $y;";
List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
assertEquals(answers.size(), 1);
String queryString2 = "match $x isa subResource;";
List<Answer> answers2 = qb.<GetQuery>parse(queryString2).execute();
assertEquals(answers2.size(), 1);
assertTrue(answers2.iterator().next().get(var("x")).isAttribute());
String queryString3 = "match $x isa resource; $y isa subResource;";
List<Answer> answers3 = qb.<GetQuery>parse(queryString3).execute();
assertEquals(answers3.size(), 1);
assertTrue(answers3.iterator().next().get(var("x")).isAttribute());
assertTrue(answers3.iterator().next().get(var("y")).isAttribute());
}
Aggregations