Skip to content

Commit

Permalink
add more coverage test for update clause
Browse files Browse the repository at this point in the history
  • Loading branch information
alyaa999 committed Aug 17, 2024
1 parent a7a48e0 commit c7ed8c2
Showing 1 changed file with 77 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.polypheny.db.cypher.CypherTestTemplate;
import org.polypheny.db.cypher.helper.TestLiteral;
import org.polypheny.db.cypher.helper.TestNode;
import org.polypheny.db.util.Pair;
import org.polypheny.db.webui.models.results.GraphResult;
Expand Down Expand Up @@ -86,17 +87,50 @@ assert containsRows( res, true, true,
public void updateVariablesIncrementTest() {
execute( SINGLE_NODE_PERSON_1 );
execute( "MATCH (a:Person {name: 'Max'})\n"
+ "SET a = { age: 13, job: 'Developer'} " );
+ "SET a = { name : 'Max' , age: 13, job: 'Developer'} " );

GraphResult res = matchAndReturnAllNodes();
assert containsRows( res, true, true,
Row.of( TestNode.from(
List.of( "Person" ),
Pair.of( "name", "Max" ),
Pair.of( "age", 13 ),
Pair.of( "job", "Developer" ) ) ) );
}


@Test
public void updateVariablesDecrementTest() {
execute( SINGLE_NODE_PERSON_COMPLEX_1 );
execute( "MATCH (p {name: 'Ann'})\n"
+ "SET p = {name: 'Ann Smith'}" );

GraphResult res = matchAndReturnAllNodes();
containsNodes( res, true,
TestNode.from( List.of( "Person" ),
Pair.of( "name", "'Ann Smith" ) ) );

}


@Test
public void updateVariablesIncrementAndDecrementTest() {
execute( SINGLE_NODE_PERSON_COMPLEX_1 );
execute( "MATCH (p {name: 'Ann'})\n"
+ "SET p = {name: 'Peter Smith', position: 'Entrepreneur'}\n"
+ "RETURN p.name, p.age, p.position" );

GraphResult res = matchAndReturnAllNodes();
assert containsRows( res, true, true,
Row.of( TestNode.from(
List.of( "Person" ),
Pair.of( "name", "Peter Smith" ),
Pair.of( "position", "Entrepreneur" ) ) ) );


}


@Test
@Disabled // Extension of Cypher implementation required
public void updatePropertyReturnTest() {
Expand Down Expand Up @@ -126,10 +160,50 @@ public void updateRelationshipNewPropertyTest() {
public void updateCaseWhenTest() {
execute( SINGLE_NODE_PERSON_COMPLEX_1 );
execute( "MATCH (n {name: 'Ann'})\n"
+ "SET (CASE WHEN n.age = 45 THEN n END).worksIn = 'Malmo'\n"
+ "RETURN n.name, n.worksIn" );
+ "SET (CASE WHEN n.age = 45 THEN n END).worksIn = 'Malmo" );

GraphResult res = matchAndReturnAllNodes();
containsNodes( res, true,
TestNode.from( List.of( "Person" ),
Pair.of( "name", "Ann" ),
Pair.of( "worksIn", "Malmo" ) ) );

execute( "MATCH (n {name: 'Ann'})\n"
+ "SET (CASE WHEN n.age = 45 THEN n END).name = 'Max"
+ "RETURN n.name, n.age" );

containsNodes( res, true,
TestNode.from( List.of( "Person" ),
Pair.of( "name", "Max" ),
Pair.of( "age", 45 ) ) );
}


@Test
public void updatePropertyWithNullTest() {
execute( SINGLE_NODE_PERSON_COMPLEX_1 );
execute( "MATCH (n {name: 'Ann'})\n"
+ "SET n.name = null\n" );

GraphResult res = matchAndReturnAllNodes();
containsNodes( res, true,
TestNode.from( List.of( "Person" ),
Pair.of( "age", 54 ) ) );
}


@Test
public void updateMultiplePropertiesWithOneSetTest() {
execute( SINGLE_NODE_PERSON_1 );
execute( "MATCH (n {name: 'Max'})\n"
+ "SET n.position = 'Developer', n.surname = 'Taylor'" );
GraphResult res = matchAndReturnAllNodes();
containsNodes( res, true,
TestNode.from( List.of( "Person" ),
Pair.of( "name", "Max" ),
Pair.of( "position", "Developer" ),
Pair.of( "surname", "Taylor " ) ) );
}


}

0 comments on commit c7ed8c2

Please sign in to comment.