Mercurial > hg > release > icedtea-web-1.7
changeset 1217:549f1b0519ce
Added MultipleDeploymentPropertiesModifier improvement to testsuite
author | Jiri Vanek <jvanek@redhat.com> |
---|---|
date | Fri, 24 Apr 2015 14:47:45 +0200 |
parents | 251db06da1e5 |
children | ff7dc55d6b44 |
files | ChangeLog tests/reproducers/custom/PartiallySignedAppletManifestSpecifiesSandbox/testcases/PartiallySignedAppletManifestSpecifiesSandboxTests.java tests/test-extensions-tests/net/sourceforge/jnlp/tools/DeploymentPropertiesModifierTest.java tests/test-extensions/net/sourceforge/jnlp/tools/DeploymentPropertiesModifier.java |
diffstat | 4 files changed, 119 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Apr 23 19:14:53 2015 +0200 +++ b/ChangeLog Fri Apr 24 14:47:45 2015 +0200 @@ -1,3 +1,14 @@ +2015-04-23 Jiri Vanek <jvanek@redhat.com> + + * tests/reproducers/custom/PartiallySignedAppletManifestSpecifiesSandbox/testcases/PartiallySignedAppletManifestSpecifiesSandboxTests.java: + used new MultipleDeploymentPropertiesModifier + * tests/test-extensions-tests/net/sourceforge/jnlp/tools/DeploymentPropertiesModifierTest.java: + add new inner class, MultipleDeploymentPropertiesModifier able to gather and apply/revert in bulk + normal DeploymentPropertiesModifier + * tests/test-extensions/net/sourceforge/jnlp/tools/DeploymentPropertiesModifier.java: + Added testMultipleDeploymentPropertiesModifier, test to new MultipleDeploymentPropertiesModifier + class + 2015-04-23 Jiri Vanek <jvanek@redhat.com> * javac.in: removed. Its usage gone out with removal of bootstrap.
--- a/tests/reproducers/custom/PartiallySignedAppletManifestSpecifiesSandbox/testcases/PartiallySignedAppletManifestSpecifiesSandboxTests.java Thu Apr 23 19:14:53 2015 +0200 +++ b/tests/reproducers/custom/PartiallySignedAppletManifestSpecifiesSandbox/testcases/PartiallySignedAppletManifestSpecifiesSandboxTests.java Fri Apr 24 14:47:45 2015 +0200 @@ -38,6 +38,7 @@ import static org.junit.Assert.assertTrue; import java.io.IOException; +import java.util.AbstractMap; import net.sourceforge.jnlp.ProcessResult; import net.sourceforge.jnlp.annotations.Bug; @@ -65,22 +66,21 @@ private static final String STACKTRACE_NOT_GRANT_PERMISSIONS_TYPE = "Cannot grant permissions to unsigned jars"; private static final String USER_HOME = System.getProperty("user.home"); - private static DeploymentPropertiesModifier permissionsModifier; - private static DeploymentPropertiesModifier securityLevelModifier; - + private static DeploymentPropertiesModifier.MultipleDeploymentPropertiesModifier modifier; + @BeforeClass public static void setupDeploymentProperties() throws IOException { - permissionsModifier = new DeploymentPropertiesModifier(); - permissionsModifier.setProperties(DeploymentConfiguration.KEY_ENABLE_MANIFEST_ATTRIBUTES_CHECK, ManifestAttributesChecker.MANIFEST_ATTRIBUTES_CHECK.PERMISSIONS.toString()); - - securityLevelModifier = new DeploymentPropertiesModifier(); - securityLevelModifier.setProperties(DeploymentConfiguration.KEY_SECURITY_LEVEL, AppletSecurityLevel.ALLOW_UNSIGNED.toChars()); + modifier = new DeploymentPropertiesModifier.MultipleDeploymentPropertiesModifier( + new AbstractMap.SimpleEntry<>(DeploymentConfiguration.KEY_ENABLE_MANIFEST_ATTRIBUTES_CHECK, ManifestAttributesChecker.MANIFEST_ATTRIBUTES_CHECK.PERMISSIONS.toString()), + new AbstractMap.SimpleEntry<>(DeploymentConfiguration.KEY_SECURITY_LEVEL, AppletSecurityLevel.ALLOW_UNSIGNED.toChars() + ) + ); + modifier.setProperties(); } @AfterClass public static void setbackDeploymentProperties() throws IOException { - securityLevelModifier.restoreProperties(); - permissionsModifier.restoreProperties(); + modifier.restoreProperties(); } @Test
--- a/tests/test-extensions-tests/net/sourceforge/jnlp/tools/DeploymentPropertiesModifierTest.java Thu Apr 23 19:14:53 2015 +0200 +++ b/tests/test-extensions-tests/net/sourceforge/jnlp/tools/DeploymentPropertiesModifierTest.java Fri Apr 24 14:47:45 2015 +0200 @@ -35,19 +35,20 @@ exception statement from your version. */ -package tools; +package net.sourceforge.jnlp.tools; import static org.junit.Assert.assertEquals; import java.io.File; import java.io.IOException; +import java.util.AbstractMap; import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.config.InfrastructureFileDescriptor; import net.sourceforge.jnlp.runtime.ManifestAttributesChecker; import net.sourceforge.jnlp.security.appletextendedsecurity.AppletSecurityLevel; -import net.sourceforge.jnlp.tools.DeploymentPropertiesModifier; import net.sourceforge.jnlp.util.FileUtils; +import org.junit.Assert; import org.junit.Test; public class DeploymentPropertiesModifierTest { @@ -155,6 +156,58 @@ dpm2.restoreProperties(); dpm1.restoreProperties(); } + + @Test + public void testMultipleDeploymentPropertiesModifier() throws IOException { + File tempUserFile = File.createTempFile("userDeploy", ""); + tempUserFile.deleteOnExit(); + + String content = "a.b=12\nc.d=34\ne.f=56\ng.h=78\ni.j=90"; + FileUtils.saveFile(content, tempUserFile); + deploymentFile = tempUserFile; + DummyInfrastructureFileDescriptor deploymentInfrastructure = new DummyInfrastructureFileDescriptor(deploymentFile); + + DeploymentPropertiesModifier.MultipleDeploymentPropertiesModifier dpm1 + = new DeploymentPropertiesModifier.MultipleDeploymentPropertiesModifier(deploymentInfrastructure, + new AbstractMap.SimpleEntry<>("c.d", "22"), + new AbstractMap.SimpleEntry<>("i.j", "44") + ); + dpm1.setProperties(); + String propertiesChanged = FileUtils.loadFileAsString(deploymentFile); + Assert.assertNotEquals(content, propertiesChanged); + Assert.assertTrue(propertiesChanged.contains("12")); + Assert.assertFalse(propertiesChanged.contains("34")); + Assert.assertTrue(propertiesChanged.contains("22")); + Assert.assertTrue(propertiesChanged.contains("56")); + Assert.assertTrue(propertiesChanged.contains("78")); + Assert.assertFalse(propertiesChanged.contains("90")); + Assert.assertTrue(propertiesChanged.contains("44")); + Assert.assertTrue(propertiesChanged.contains("a.b")); + Assert.assertTrue(propertiesChanged.contains("c.d")); + Assert.assertTrue(propertiesChanged.contains("e.f")); + Assert.assertTrue(propertiesChanged.contains("g.h")); + Assert.assertTrue(propertiesChanged.contains("i.j")); + + dpm1.restoreProperties(); + String propertiesResored = FileUtils.loadFileAsString(deploymentFile); + + Assert.assertNotEquals(content, propertiesChanged); + Assert.assertTrue(propertiesResored.contains("12")); + Assert.assertTrue(propertiesResored.contains("34")); + Assert.assertFalse(propertiesResored.contains("22")); + Assert.assertTrue(propertiesResored.contains("56")); + Assert.assertTrue(propertiesResored.contains("78")); + Assert.assertTrue(propertiesResored.contains("90")); + Assert.assertFalse(propertiesResored.contains("44")); + Assert.assertTrue(propertiesResored.contains("a.b")); + Assert.assertTrue(propertiesResored.contains("c.d")); + Assert.assertTrue(propertiesResored.contains("e.f")); + Assert.assertTrue(propertiesResored.contains("g.h")); + Assert.assertTrue(propertiesResored.contains("i.j")); + + // /n at the end of last line may not matter + assertEquals(content.trim(), propertiesResored.trim()); + } private static class DummyInfrastructureFileDescriptor extends InfrastructureFileDescriptor { private final File file;
--- a/tests/test-extensions/net/sourceforge/jnlp/tools/DeploymentPropertiesModifier.java Thu Apr 23 19:14:53 2015 +0200 +++ b/tests/test-extensions/net/sourceforge/jnlp/tools/DeploymentPropertiesModifier.java Fri Apr 24 14:47:45 2015 +0200 @@ -38,12 +38,53 @@ package net.sourceforge.jnlp.tools; import java.io.IOException; +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import net.sourceforge.jnlp.config.InfrastructureFileDescriptor; import net.sourceforge.jnlp.config.PathsAndFiles; import net.sourceforge.jnlp.util.FileUtils; public class DeploymentPropertiesModifier { + + + /** + * for advanced users, less verbose, less fool-proof multi-impl + */ + public static class MultipleDeploymentPropertiesModifier { + + private final InfrastructureFileDescriptor src; + private final AbstractMap.SimpleEntry<String, String>[] keyValue; + private List<DeploymentPropertiesModifier> modifications; + + public MultipleDeploymentPropertiesModifier(AbstractMap.SimpleEntry<String, String>... keyValue) { + this(PathsAndFiles.USER_DEPLOYMENT_FILE, keyValue); + } + + public MultipleDeploymentPropertiesModifier(InfrastructureFileDescriptor src, HashMap.SimpleEntry<String, String>... keyValue) { + this.src = src; + this.keyValue = keyValue; + } + + public void setProperties() throws IOException { + modifications = new ArrayList<>(keyValue.length); + for (AbstractMap.SimpleEntry<String, String> keyValue1 : keyValue) { + DeploymentPropertiesModifier dm = new DeploymentPropertiesModifier(src); + dm.setProperties(keyValue1.getKey(), keyValue1.getValue()); + //adding to beggining, soe restoring goes from last. Not necessary, but nice. + modifications.add(0, dm); + } + } + + public void restoreProperties() throws IOException { + for (DeploymentPropertiesModifier dm : modifications) { + dm.restoreProperties(); + } + } + + } private final InfrastructureFileDescriptor src; private String savedValue; @@ -62,7 +103,7 @@ public void setProperties(String property, String value) throws IOException { if (isPropertiesSet) { - throw new IllegalStateException(); + throw new IllegalStateException("Properties can be set only once. Revert and use naother instance."); } isPropertiesSet = true; requestedProperty = property; @@ -73,7 +114,7 @@ public void restoreProperties() throws IOException { if (!isPropertiesSet) { - throw new IllegalStateException(); + throw new IllegalStateException("Prperties must be set before they can be reverted"); } isPropertiesSet = false;