Skip to content

Commit

Permalink
add test on adding global variable
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@1201892 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
olamy committed Nov 14, 2011
1 parent 74ccfe8 commit 52d42e2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ public void testBeanshell()
SystemStreamLog systemStreamLog = new SystemStreamLog();

ScriptRunner scriptRunner = new ScriptRunner( systemStreamLog );
scriptRunner.setGlobalVariable( "globalVar", "Yeah baby it's rocks" );
scriptRunner.run( "test", new File( "src/test/resources/bsh-test" ), "verify", buildContext(),
new FileLogger( logFile ), "foo", true );

String logContent = FileUtils.fileRead( logFile );
assertTrue( logContent.contains( new File( "src/test/resources/bsh-test/verify.bsh" ).getPath() ) );
assertTrue( logContent.contains( "foo=bar" ) );
assertTrue( logContent.contains( "globalVar=Yeah baby it's rocks"));

}

Expand All @@ -63,13 +65,15 @@ public void testBeanshellWithFile()
SystemStreamLog systemStreamLog = new SystemStreamLog();

ScriptRunner scriptRunner = new ScriptRunner( systemStreamLog );
scriptRunner.setGlobalVariable( "globalVar", "Yeah baby it's rocks" );
scriptRunner.run( "test", new File( "src/test/resources/bsh-test/verify.bsh" ), buildContext(),
new FileLogger( logFile ), "foo", true );

String logContent = FileUtils.fileRead( logFile );
assertTrue( logContent.contains( new File( "src/test/resources/bsh-test/verify.bsh" ).getPath() ) );
assertTrue( logContent.contains( "foo=bar" ) );


}

public void testGroovy()
Expand All @@ -83,12 +87,14 @@ public void testGroovy()
SystemStreamLog systemStreamLog = new SystemStreamLog();

ScriptRunner scriptRunner = new ScriptRunner( systemStreamLog );
scriptRunner.setGlobalVariable( "globalVar", "Yeah baby it's rocks" );
scriptRunner.run( "test", new File( "src/test/resources/groovy-test" ), "verify", buildContext(),
new FileLogger( logFile ), "foo", true );

String logContent = FileUtils.fileRead( logFile );
assertTrue( logContent.contains( new File( "src/test/resources/groovy-test/verify.groovy" ).getPath() ) );
assertTrue( logContent.contains( "foo=bar" ) );
assertTrue( logContent.contains( "globalVar=Yeah baby it's rocks"));

}

Expand All @@ -110,6 +116,7 @@ public void testGroovyWithFile()
assertTrue( logContent.contains( new File( "src/test/resources/groovy-test/verify.groovy" ).getPath() ) );
assertTrue( logContent.contains( "foo=bar" ) );


}


Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/bsh-test/verify.bsh
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ if ( !file.exists())
String value = context.get( "foo" );
System.out.println("foo="+value);

System.out.println("globalVar="+globalVar);

System.out.print("Test");
return true;
3 changes: 3 additions & 0 deletions src/test/resources/groovy-test/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ if ( !( context instanceof Map ) )
}

System.out.println("foo="+context.get("foo"));

if (binding.variables.containsKey("globalVar")) System.out.println("globalVar="+globalVar);

return true

0 comments on commit 52d42e2

Please sign in to comment.