2828import org .neo4j .gds .catalog .GraphProjectProc ;
2929import org .neo4j .gds .core .loading .GraphStoreCatalog ;
3030import org .neo4j .gds .extension .Neo4jGraph ;
31+ import org .neo4j .graphdb .QueryExecutionException ;
3132
3233import java .util .List ;
3334import java .util .Map ;
3435
3536import static org .hamcrest .Matchers .instanceOf ;
37+ import static org .junit .jupiter .api .Assertions .assertEquals ;
38+ import static org .junit .jupiter .api .Assertions .assertThrows ;
3639import static org .neo4j .gds .TestSupport .assertGraphEquals ;
3740import static org .neo4j .gds .TestSupport .fromGdl ;
41+ import static org .neo4j .gds .utils .ExceptionUtil .rootCause ;
42+ import static org .neo4j .gds .utils .StringFormatting .formatWithLocale ;
3843
3944class ToUndirectedProcTest extends BaseProcTest {
4045
@@ -62,7 +67,7 @@ void setup() throws Exception {
6267 }
6368
6469 @ Test
65- void convertToUndirect () {
70+ void convertToUndirected () {
6671 String query = "CALL gds.beta.graph.relationships.toUndirected('graph', {relationshipType: 'REL', mutateRelationshipType: 'REL2'})" ;
6772
6873 assertCypherResult (query , List .of (Map .of ("inputRelationships" , 3L ,
@@ -78,4 +83,28 @@ void convertToUndirect() {
7883 var graph = gs .graphStore ().getGraph (RelationshipType .of ("REL2" ));
7984 assertGraphEquals (fromGdl (DB .replace ("REL" , "REL2" ), Orientation .UNDIRECTED ), graph );
8085 }
86+
87+ @ Test
88+ void shouldFailIfMutateRelationshipTypeExists () {
89+ String query = "CALL gds.beta.graph.relationships.toUndirected('graph', {relationshipType: 'REL', mutateRelationshipType: 'REL'})" ;
90+
91+ Throwable throwable = rootCause (assertThrows (QueryExecutionException .class , () -> runQuery (query )));
92+ assertEquals (IllegalArgumentException .class , throwable .getClass ());
93+ String expectedMessage = formatWithLocale (
94+ "Relationship type `REL` already exists in the in-memory graph."
95+ );
96+ assertEquals (expectedMessage , throwable .getMessage ());
97+ }
98+
99+ @ Test
100+ void shouldFailIfRelationshipTypeDoesNotExists () {
101+ String query = "CALL gds.beta.graph.relationships.toUndirected('graph', {relationshipType: 'REL2', mutateRelationshipType: 'REL2'})" ;
102+
103+ Throwable throwable = rootCause (assertThrows (QueryExecutionException .class , () -> runQuery (query )));
104+ assertEquals (IllegalArgumentException .class , throwable .getClass ());
105+ String expectedMessage = formatWithLocale (
106+ "Could not find the specified `relationshipType` of ['REL2']. Available relationship types are ['REL']."
107+ );
108+ assertEquals (expectedMessage , throwable .getMessage ());
109+ }
81110}
0 commit comments