use of ai.grakn.graql.InsertQuery in project grakn by graknlabs.
the class InsertQueryImplTest method insertQueriesWithDifferentMatchesAreDifferent.
@Test
public void insertQueriesWithDifferentMatchesAreDifferent() {
InsertQuery query1 = InsertQueryImpl.create(vars1, match1, Optional.empty());
InsertQuery query2 = InsertQueryImpl.create(vars1, match2, Optional.empty());
assertNotEquals(query1, query2);
}
use of ai.grakn.graql.InsertQuery in project grakn by graknlabs.
the class QueryBuilderTest method whenExecutingAnInsertQueryWithoutAGraph_Throw.
@Test
public void whenExecutingAnInsertQueryWithoutAGraph_Throw() {
InsertQuery query = insert(var().id(ConceptId.of("another-movie")).isa("movie"));
exception.expect(GraqlQueryException.class);
exception.expectMessage("graph");
query.execute();
}
use of ai.grakn.graql.InsertQuery in project grakn by graknlabs.
the class InsertQueryTest method testInsertRepeat.
@Test
public void testInsertRepeat() {
VarPattern language = var("x").has("name", "123").isa("language");
InsertQuery query = qb.insert(language);
assertEquals(0, qb.match(language).stream().count());
query.execute();
assertEquals(1, qb.match(language).stream().count());
query.execute();
assertEquals(2, qb.match(language).stream().count());
query.execute();
assertEquals(3, qb.match(language).stream().count());
qb.match(language).delete("x").execute();
assertEquals(0, qb.match(language).stream().count());
}
use of ai.grakn.graql.InsertQuery in project grakn by graknlabs.
the class InsertQueryTest method whenAddingProvenanceToAnExistingRelationship_TheProvenanceIsAdded.
@Test
public void whenAddingProvenanceToAnExistingRelationship_TheProvenanceIsAdded() {
InsertQuery query = qb.match(w.isa("movie").has(title, x.val("The Muppets"), y)).insert(x, w, y.has("provenance", z.val("Someone told me")));
Answer answer = Iterables.getOnlyElement(query.execute());
Entity movie = answer.get(w).asEntity();
Attribute<String> theTitle = answer.get(x).asAttribute();
Relationship hasTitle = answer.get(y).asRelationship();
Attribute<String> provenance = answer.get(z).asAttribute();
assertThat(hasTitle.rolePlayers().toArray(), arrayContainingInAnyOrder(movie, theTitle));
assertThat(hasTitle.attributes().toArray(), arrayContaining(provenance));
}
use of ai.grakn.graql.InsertQuery in project grakn by graknlabs.
the class InsertQueryTest method testIterateInsertResults.
@Test
public void testIterateInsertResults() {
InsertQuery insert = qb.insert(var("x").has("name", "123").isa("person"), var("z").has("name", "xyz").isa("language"));
Set<Answer> results = insert.stream().collect(toSet());
assertEquals(1, results.size());
Answer result = results.iterator().next();
assertEquals(ImmutableSet.of(var("x"), var("z")), result.vars());
assertThat(result.concepts(), Matchers.everyItem(notNullValue(Concept.class)));
}
Aggregations