Skip to content

Commit

Permalink
Mixing PerformsWrites and mode in Procedure is invalid
Browse files Browse the repository at this point in the history
Throws an exception if PerformsWrites and Procedure( mode = ... ) is used together
  • Loading branch information
OliviaYtterbrink committed Jul 1, 2016
1 parent 9a371ba commit 302c4ee
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
Expand Up @@ -123,10 +123,10 @@ else if ( procedure.mode().equals( Procedure.Mode.WRITE ) )
}
if ( method.isAnnotationPresent( PerformsWrites.class ) )
{
if ( mode == ProcedureSignature.Mode.DBMS || mode == ProcedureSignature.Mode.SCHEMA_WRITE )
if ( !procedure.mode().equals( Procedure.Mode.DEFAULT ) )
{
throw new ProcedureException( Status.Procedure.ProcedureRegistrationFailed,
"Conflicting procedure annotation, PerformsWrites and mode = %s.", procedure.mode() );
"Conflicting procedure annotation, cannot use PerformsWrites and mode" );
}
else
{
Expand Down
Expand Up @@ -128,10 +128,10 @@
* SCHEMA allows reading the graphs and performing schema operations
* DBMS allows managing the database (i.e. change password)
*/
Mode mode() default Mode.READ;
Mode mode() default Mode.DEFAULT;

enum Mode
{
READ, WRITE, SCHEMA, DBMS
READ, WRITE, SCHEMA, DBMS, DEFAULT
}
}
Expand Up @@ -187,39 +187,48 @@ public RawIterator<Object[], ProcedureException> apply( Context ctx, Object[] in
}

@Test
public void shouldCompileProcedureWithPerformsWrites() throws Throwable
public void shouldFailCompileProcedureWithReadConflict() throws Throwable
{
procs.register( ProcedureWithPerformsWritesAndRead.class );
assertNotNull( procs.get( new ProcedureSignature.ProcedureName( "org.neo4j.kernel.impl.proc".split( "\\." ),
"shouldCompile" ) ) );
assertNotNull( procs.get( new ProcedureSignature.ProcedureName( "org.neo4j.kernel.impl.proc".split( "\\." ),
"shouldCompileToo" ) ) );
exception.expect( ProcedureException.class );
exception.expectMessage( "Conflicting procedure annotation, cannot use PerformsWrites and mode" );
procs.register( ProcedureWithReadConflictAnnotation.class );
}

@Test
public void shouldFailCompileProcedureWithDBMSConflict() throws Throwable
public void shouldFailCompileProcedureWithWriteConflict() throws Throwable
{
exception.expect( ProcedureException.class );
exception.expectMessage( "Conflicting procedure annotation, PerformsWrites and mode = DBMS." );
procs.register( ProcedureWithDBMSConflictAnnotation.class );
exception.expectMessage( "Conflicting procedure annotation, cannot use PerformsWrites and mode" );
procs.register( ProcedureWithWriteConflictAnnotation.class );
}

@Test
public void shouldFailCompileProcedureWithSchemaConflict() throws Throwable
{
exception.expect( ProcedureException.class );
exception.expectMessage( "Conflicting procedure annotation, PerformsWrites and mode = SCHEMA." );
exception.expectMessage( "Conflicting procedure annotation, cannot use PerformsWrites and mode" );
procs.register( ProcedureWithSchemaConflictAnnotation.class );
}

public static class ProcedureWithPerformsWritesAndRead
@Test
public void shouldFailCompileProcedureWithDBMSConflict() throws Throwable
{
exception.expect( ProcedureException.class );
exception.expectMessage( "Conflicting procedure annotation, cannot use PerformsWrites and mode" );
procs.register( ProcedureWithDBMSConflictAnnotation.class );
}

public static class ProcedureWithReadConflictAnnotation
{
@PerformsWrites
@Procedure( mode = Procedure.Mode.READ )
public void shouldCompile()
{
}
}

public static class ProcedureWithWriteConflictAnnotation
{
@PerformsWrites
@Procedure( mode = Procedure.Mode.WRITE )
public void shouldCompileToo()
Expand Down

0 comments on commit 302c4ee

Please sign in to comment.