Search in sources :

Example 26 with InsertQuery

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);
}
Also used : InsertQuery(ai.grakn.graql.InsertQuery) Test(org.junit.Test)

Example 27 with InsertQuery

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();
}
Also used : InsertQuery(ai.grakn.graql.InsertQuery) Test(org.junit.Test)

Example 28 with InsertQuery

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());
}
Also used : InsertQuery(ai.grakn.graql.InsertQuery) VarPattern(ai.grakn.graql.VarPattern) Test(org.junit.Test)

Example 29 with InsertQuery

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));
}
Also used : InsertQuery(ai.grakn.graql.InsertQuery) Answer(ai.grakn.graql.admin.Answer) Entity(ai.grakn.concept.Entity) Relationship(ai.grakn.concept.Relationship) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 30 with InsertQuery

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)));
}
Also used : InsertQuery(ai.grakn.graql.InsertQuery) Answer(ai.grakn.graql.admin.Answer) Test(org.junit.Test)

Aggregations

InsertQuery (ai.grakn.graql.InsertQuery)31 Test (org.junit.Test)29 Answer (ai.grakn.graql.admin.Answer)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 QueryBuilder (ai.grakn.graql.QueryBuilder)3 GraknTx (ai.grakn.GraknTx)2 ConceptId (ai.grakn.concept.ConceptId)2 Entity (ai.grakn.concept.Entity)2 Label (ai.grakn.concept.Label)2 Relationship (ai.grakn.concept.Relationship)2 SchemaConcept (ai.grakn.concept.SchemaConcept)2 DeleteQuery (ai.grakn.graql.DeleteQuery)2 Graql (ai.grakn.graql.Graql)2 Graql.label (ai.grakn.graql.Graql.label)2 Graql.var (ai.grakn.graql.Graql.var)2 Match (ai.grakn.graql.Match)2 VarPattern (ai.grakn.graql.VarPattern)2 Conjunction (ai.grakn.graql.admin.Conjunction)2 PatternAdmin (ai.grakn.graql.admin.PatternAdmin)2 MovieKB (ai.grakn.test.kbs.MovieKB)2