[fyi][icedtea-web] strict test

adomurad adomurad at redhat.com
Thu Sep 6 06:35:30 PDT 2012


On Thu, 2012-09-06 at 15:26 +0200, Jiri Vanek wrote:
> Just simple test about passing of -strict parameter.  I Have written it to my to do long ago, donot 
> remember even why... so finally done...
> 
> 
> 2012-09-06  Jiri Vanek  <jvanek at redhat.com>
> 
> 	Added strict test
> 	* tests/reproducers/simple/simpletest1/testcases/SimpleTest1Test.java:
> 	Removed deprecated ServerAccess.ProcessResult
> 	(testSimpletest1lunchOk) extracted asserting code
> 	(checkLaunched) family of methods to evaluate output of application
> 	(createStrictFile) method to prepare file which will pass strict checking
> 	(testSimpletest1lunchOkStrictJnlp) new test, ensuring that even strict
> 	file can be read without strict option
> 	(testSimpletest1lunchNotOkJnlpStrict) new test ensuring that strictly
> 	read no-strict file will fail
> 	(testSimpletest1lunchOkStrictJnlpStrict) new test ensuring that strictly
> 	read strict file will pass

Hey just skimming, comments inline.


> diff -r 83032226f86a
> tests/reproducers/simple/simpletest1/testcases/SimpleTest1Test.java
> ---
> a/tests/reproducers/simple/simpletest1/testcases/SimpleTest1Test.java       Thu Sep 06 14:09:09 2012 +0200
> +++
> b/tests/reproducers/simple/simpletest1/testcases/SimpleTest1Test.java       Thu Sep 06 15:18:48 2012 +0200
> @@ -35,7 +35,14 @@
>  exception statement from your version.
>   */
>  
> -
> +import java.io.File;
> +import java.io.FileInputStream;
> +import java.io.IOException;
> +import java.net.MalformedURLException;
> +import java.net.URL;
> +import java.util.Arrays;
> +import java.util.List;
> +import net.sourceforge.jnlp.ProcessResult;
>  import net.sourceforge.jnlp.ServerAccess;
>  import org.junit.Assert;
>  
> @@ -44,18 +51,63 @@
>  public class SimpleTest1Test {
>  
>      private static ServerAccess server = new ServerAccess();
> +    private static final List<String> strict = Arrays.asList(new
> String[]{"-strict", ServerAccess.VERBOSE_OPTION});
>  
> -  
> +    private void checkLaunched(ProcessResult pr) {
> +        checkLaunched(pr, false);
> +    }
> +
> +    private void checkLaunched(ProcessResult pr, boolean negate) {
> +        String s = "Good simple javaws exapmle";
> +        if (negate) {
> +            Assert.assertFalse("testSimpletest1lunchOk stdout should
> NOT contains " + s + " bud did", pr.stdout.contains(s));
> +        } else {
> +            Assert.assertTrue("testSimpletest1lunchOk stdout should
> contains " + s + " bud didn't", pr.stdout.contains(s));
> +        }
> +        String ss = "xception";
> +        if (negate) {
Surely one of these should be !negate ??
> +            Assert.assertTrue("testSimpletest1lunchOk stderr should
> contains " + ss + " but didn't", pr.stderr.contains(ss));
> +        } else {
> +            Assert.assertFalse("testSimpletest1lunchOk stderr should
> not contains " + ss + " but did", pr.stderr.contains(ss));
> +        }
> +        Assert.assertFalse(pr.wasTerminated);
> +        Assert.assertEquals((Integer) 0, pr.returnValue);
> +    }
>  
>      @Test
>      public void testSimpletest1lunchOk() throws Exception {
> -        ServerAccess.ProcessResult
> pr=server.executeJavawsHeadless(null,"/simpletest1.jnlp");
> -        String s="Good simple javaws exapmle";
> -        Assert.assertTrue("testSimpletest1lunchOk stdout should
> contains "+s+" bud didn't",pr.stdout.contains(s));
> -        String ss="xception";
> -        Assert.assertFalse("testSimpletest1lunchOk stderr should not
> contains "+ss+" but did",pr.stderr.contains(ss));
> -        Assert.assertFalse(pr.wasTerminated);
> -        Assert.assertEquals((Integer)0, pr.returnValue);
> +        ProcessResult pr = server.executeJavawsHeadless(null,
> "/simpletest1.jnlp");
> +        checkLaunched(pr);
>      }
>  
> - }
> +    @Test
> +    public void testSimpletest1lunchNotOkJnlpStrict() throws
> Exception {
> +        ProcessResult pr = server.executeJavawsHeadless(strict,
> "/simpletest1.jnlp");
> +        checkLaunched(pr, true);
> +    }
> +
> +    @Test
> +    public void testSimpletest1lunchOkStrictJnlp() throws Exception {
> +        String originalResourceName = "simpletest1.jnlp";
> +        String newResourceName = "simpletest1_strict.jnlp";
> +        createStrictFile(originalResourceName, newResourceName,
> server.getUrl(""));
> +        ProcessResult pr = server.executeJavawsHeadless(null, "/" +
> newResourceName);
> +        checkLaunched(pr);
> +    }
> +
> +    @Test
> +    public void testSimpletest1lunchOkStrictJnlpStrict() throws
> Exception {
> +        String originalResourceName = "simpletest1.jnlp";
> +        String newResourceName = "simpletest1_strict.jnlp";
> +        createStrictFile(originalResourceName, newResourceName,
> server.getUrl(""));
> +        ProcessResult pr = server.executeJavawsHeadless(strict, "/" +
> newResourceName);
> +        checkLaunched(pr);
> +    }
> +
> +    private void createStrictFile(String originalResourceName, String
> newResourceName, URL codebase) throws MalformedURLException,
> IOException {
> +        String originalContent = ServerAccess.getContentOfStream(new
> FileInputStream(new File(server.getDir(), originalResourceName)));
> +        String nwContent1 = originalContent.replaceAll("href=
> \"simpletest1.jnlp\"", "href=\"simpletest1_strict.jnlp\"");
I'm not sure how I feel about this rewriting scheme. I suppose its less
error prone here than putting it manually, and less work than a custom
reproducer. 

One thing I would suggest though is, you rely on 'originalResourceName'
to be passed to you, but then the method assumes the href is
"simpletest1.jnlp". Surely you want to use originalResourceName and
newResourceName variables here ?
> +        String nwContent = nwContent1.replaceAll("codebase=\".\"",
> "codebase=\"" + codebase + "\"");
> +        ServerAccess.saveFile(nwContent, new File(server.getDir(),
> newResourceName));
> +    }
> +}

Will look into again once these are fixed.
Thanks, Adam.




More information about the distro-pkg-dev mailing list