diff options
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTestExtendedConfigured.java')
-rw-r--r-- | bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTestExtendedConfigured.java | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTestExtendedConfigured.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTestExtendedConfigured.java new file mode 100644 index 000000000..5de86bea9 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTestExtendedConfigured.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2012,2013 Red Hat, Inc. and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + * Ericsson AB - ongoing development + ******************************************************************************/ +package org.eclipse.equinox.p2.tests.simpleconfigurator; + +import java.io.*; +import java.net.URISyntaxException; +import java.util.ArrayList; +import org.eclipse.equinox.internal.simpleconfigurator.Activator; +import org.eclipse.equinox.internal.simpleconfigurator.utils.SimpleConfiguratorUtils; + +public class SimpleConfiguratorTestExtendedConfigured extends SimpleConfiguratorTestExtended { + + private File parentFolder; + private File ext1Info; + private File ext1Parent; + private File ext3Info; + private File ext3Parent; + + @Override + public void setUp() throws Exception { + super.setUp(); + parentFolder = new File(getTempFolder(), "extension"); + ext1Parent = new File(parentFolder, "ext1"); + ext1Parent.mkdirs(); + ext1Info = new File(ext1Parent, "ext1.info"); + ext1Info.createNewFile(); + ext3Parent = new File(parentFolder, "ext3"); + ext3Parent.mkdirs(); + ext3Info = new File(ext3Parent, "ext3.info"); + ext3Info.createNewFile(); + ext1Info.setLastModified(System.currentTimeMillis() + 1000); + ext1Parent.setWritable(false); + ext3Info.setLastModified(System.currentTimeMillis() + 1000); + } + + @Override + protected void tearDown() throws Exception { + Activator.EXTENSIONS = null; + ext1Parent.setWritable(true); + super.tearDown(); + } + + public void testWriteableExtension() throws FileNotFoundException, IOException, URISyntaxException { + Activator.EXTENSIONS = parentFolder.toString(); + ArrayList<File> infoFiles = SimpleConfiguratorUtils.getInfoFiles(); + assertEquals("only read-only info file should be considered", 1, infoFiles.size()); + // ext1 is expected because ext3 is writeable + assertEquals(ext1Info.getName(), infoFiles.get(0).getName()); + } + + public void testExtensionAdded() throws IOException { + + storeTimestamp(new File(masterConfguration, relativeURL.getFile()).lastModified()); + assertEquals(sharedConfiguration[0], configurator.chooseConfigurationURL(relativeURL, sharedConfiguration)); + assertIsPropertySet(false); + + Activator.EXTENSIONS = parentFolder.toString(); + + assertEquals(sharedConfiguration[1], configurator.chooseConfigurationURL(relativeURL, sharedConfiguration)); + assertIsPropertySet(true); + } + + public void testExtensionRemoved() throws IOException { + + Activator.EXTENSIONS = parentFolder.toString(); + storeTimestamp(ext1Info.lastModified()); + //on adding extension master must be selected in order to create new profile with extensions! + assertEquals(sharedConfiguration[1], configurator.chooseConfigurationURL(relativeURL, sharedConfiguration)); + assertIsPropertySet(true); + + //disable extension + Activator.EXTENSIONS = null; + + assertEquals(sharedConfiguration[1], configurator.chooseConfigurationURL(relativeURL, sharedConfiguration)); + assertIsPropertySet(true); + } + + public void testExtensionModified() throws IOException { + + Activator.EXTENSIONS = parentFolder.toString(); + storeTimestamp(ext1Info.lastModified()); + //on adding extension master must be selected in order to create new profile with extensions! + assertEquals(sharedConfiguration[1], configurator.chooseConfigurationURL(relativeURL, sharedConfiguration)); + assertIsPropertySet(true); + + //add new extension + File ext2Dir = new File(parentFolder, "ext2"); + ext2Dir.mkdirs(); + File file = new File(ext2Dir, "ext2.info"); + file.createNewFile(); + file.setLastModified(parentFolder.lastModified() + 3000); + + assertEquals(sharedConfiguration[1], configurator.chooseConfigurationURL(relativeURL, sharedConfiguration)); + assertIsPropertySet(true); + } +} |