From 61454c3a644d0cdef0cfd1aa8140dd9c81efa727 Mon Sep 17 00:00:00 2001
From: Omair Majid <omajid@redhat.com>
Date: Fri, 30 Aug 2013 11:02:08 -0400
Subject: Test case for PR1533

Add a unit test that checks the behaviour of JNLPFile when combining
and filtering properties.

2013-08-29  Omair Majid  <omajid@redhat.com>

        * tests/netx/unit/net/sourceforge/jnlp/JNLPFileTest.java
        (testPropertyRestrictions): New method. Check that properties in
        resources are are combined and filtered as approp
---
 .../unit/net/sourceforge/jnlp/JNLPFileTest.java    | 60 ++++++++++++++++++++++
 1 file changed, 60 insertions(+)

(limited to 'tests/netx/unit/net/sourceforge/jnlp/JNLPFileTest.java')

diff --git a/tests/netx/unit/net/sourceforge/jnlp/JNLPFileTest.java b/tests/netx/unit/net/sourceforge/jnlp/JNLPFileTest.java
index 1056ea2..1f517be 100644
--- a/tests/netx/unit/net/sourceforge/jnlp/JNLPFileTest.java
+++ b/tests/netx/unit/net/sourceforge/jnlp/JNLPFileTest.java
@@ -42,6 +42,7 @@ import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Locale;
+import java.util.Map;
 
 import net.sourceforge.jnlp.JNLPFile.Match;
 import net.sourceforge.jnlp.mock.MockJNLPFile;
@@ -148,4 +149,63 @@ public class JNLPFileTest {
         Assert.assertEquals("Sample Test", jnlpFile.getTitle());
         Assert.assertEquals(2, jnlpFile.getResources().getJARs().length);
     }
+
+    @Test
+    public void testPropertyRestrictions() throws MalformedURLException, ParseException {
+        String jnlpContents = "<?xml version='1.0'?>\n" +
+                "<jnlp spec='1.5' href='foo' codebase='bar'>\n" +
+                "  <information>\n" +
+                "    <title>Parsing Test</title>\n" +
+                "    <vendor>IcedTea</vendor>\n" +
+                "    <offline-allowed/>\n" +
+                "  </information>\n" +
+                "  <resources>\n" +
+                "    <property name='general' value='general'/>\n" +
+                "    <property name='os' value='general'/>\n" +
+                "    <property name='arch' value='general'/>\n" +
+                "  </resources>\n" +
+                "  <resources os='os1'>" +
+                "    <property name='os' value='os1'/>\n" +
+                "  </resources>\n" +
+                "  <resources os='os1' arch='arch1'>" +
+                "    <property name='arch' value='arch1'/>\n" +
+                "  </resources>\n" +
+                "  <resources os='os2' arch='arch2'>\n" +
+                "    <property name='os' value='os2'/>\n" +
+                "    <property name='arch' value='arch2'/>\n" +
+                "  </resources>\n" +
+                "  <installer-desc/>\n" +
+                "</jnlp>";
+
+        URL codeBase = new URL("http://www.redhat.com/");
+        InputStream is = new ByteArrayInputStream(jnlpContents.getBytes());
+        JNLPFile jnlpFile = new JNLPFile(is, codeBase, new ParserSettings(false,false,false));
+
+        ResourcesDesc resources;
+        Map<String,String> properties;
+
+        resources = jnlpFile.getResources(Locale.getDefault(), "os0", "arch0");
+        properties = resources.getPropertiesMap();
+        Assert.assertEquals("general", properties.get("general"));
+        Assert.assertEquals("general", properties.get("os"));
+        Assert.assertEquals("general", properties.get("arch"));
+
+        resources = jnlpFile.getResources(Locale.getDefault(), "os1", "arch0");
+        properties = resources.getPropertiesMap();
+        Assert.assertEquals("general", properties.get("general"));
+        Assert.assertEquals("os1", properties.get("os"));
+        Assert.assertEquals("general", properties.get("arch"));
+
+        resources = jnlpFile.getResources(Locale.getDefault(), "os1", "arch1");
+        properties = resources.getPropertiesMap();
+        Assert.assertEquals("general", properties.get("general"));
+        Assert.assertEquals("os1", properties.get("os"));
+        Assert.assertEquals("arch1", properties.get("arch"));
+
+        resources = jnlpFile.getResources(Locale.getDefault(), "os2", "arch2");
+        properties = resources.getPropertiesMap();
+        Assert.assertEquals("general", properties.get("general"));
+        Assert.assertEquals("os2", properties.get("os"));
+        Assert.assertEquals("arch2", properties.get("arch"));
+    }
 }
-- 
cgit v1.2.3