bug 324927 test notification about modifications on plug-in projects

Signed-off-by: Florian Thienel <florian@thienel.org>
diff --git a/sourceediting/tests/org.eclipse.wst.xml.vex.ui.tests/src/org/eclipse/wst/xml/vex/ui/internal/config/tests/ConfigurationRegistryTest.java b/sourceediting/tests/org.eclipse.wst.xml.vex.ui.tests/src/org/eclipse/wst/xml/vex/ui/internal/config/tests/ConfigurationRegistryTest.java
index 30f5aba..83b691a 100644
--- a/sourceediting/tests/org.eclipse.wst.xml.vex.ui.tests/src/org/eclipse/wst/xml/vex/ui/internal/config/tests/ConfigurationRegistryTest.java
+++ b/sourceediting/tests/org.eclipse.wst.xml.vex.ui.tests/src/org/eclipse/wst/xml/vex/ui/internal/config/tests/ConfigurationRegistryTest.java
@@ -13,17 +13,18 @@
 import static org.junit.Assert.assertFalse;

 import static org.junit.Assert.assertTrue;

 

-import java.net.MalformedURLException;

-import java.net.URL;

+import java.io.ByteArrayInputStream;

 import java.util.Collections;

 import java.util.List;

 

+import org.eclipse.core.resources.IProject;

 import org.eclipse.wst.xml.vex.ui.internal.config.ConfigEvent;

 import org.eclipse.wst.xml.vex.ui.internal.config.ConfigSource;

 import org.eclipse.wst.xml.vex.ui.internal.config.ConfigurationLoader;

 import org.eclipse.wst.xml.vex.ui.internal.config.ConfigurationRegistry;

 import org.eclipse.wst.xml.vex.ui.internal.config.ConfigurationRegistryImpl;

 import org.eclipse.wst.xml.vex.ui.internal.config.IConfigListener;

+import org.eclipse.wst.xml.vex.ui.internal.config.PluginProject;

 import org.junit.After;

 import org.junit.Rule;

 import org.junit.Test;

@@ -46,7 +47,7 @@
 			registry.dispose();

 		registry = null;

 	}

-	

+

 	@Test

 	public void notAutomaticallyLoaded() throws Exception {

 		registry = new ConfigurationRegistryImpl(new MockConfigurationLoader());

@@ -63,7 +64,7 @@
 		assertTrue(configListener.loaded);

 		assertFalse(configListener.changed);

 	}

-	

+

 	@Test

 	public void loadNewPluginProjectAndFireChangedEvent() throws Exception {

 		registry = new ConfigurationRegistryImpl(new MockConfigurationLoader());

@@ -75,19 +76,32 @@
 		assertFalse(configListener.loaded);

 		assertTrue(configListener.changed);

 	}

-	

+

+	@Test

+	public void fireConfigChangedEventOnPluginModification() throws Exception {

+		registry = new ConfigurationRegistryImpl(new MockConfigurationLoader());

+		registry.loadConfigurations();

+		final IProject project = PluginProjectTest.createVexPluginProject(name.getMethodName());

+		final MockConfigListener configListener = new MockConfigListener();

+		registry.addConfigListener(configListener);

+		final String fileContent = PluginProjectTest.createVexPluginFileContent(project);

+		project.getFile(PluginProject.PLUGIN_XML).setContents(new ByteArrayInputStream(fileContent.getBytes()), true, true, null);

+		assertFalse(configListener.loaded);

+		assertTrue(configListener.changed);

+	}

+

 	private static class MockConfigurationLoader implements ConfigurationLoader {

-		private List<ConfigSource> loadedConfigSources;

+		private final List<ConfigSource> loadedConfigSources;

 

 		public MockConfigurationLoader() {

 			this(Collections.<ConfigSource> emptyList());

 		}

-		

-		public MockConfigurationLoader(List<ConfigSource> loadedConfigSources) {

+

+		public MockConfigurationLoader(final List<ConfigSource> loadedConfigSources) {

 			this.loadedConfigSources = loadedConfigSources;

 		}

-		

-		public void load(Runnable whenDone) {

+

+		public void load(final Runnable whenDone) {

 			whenDone.run();

 		}

 

@@ -103,33 +117,22 @@
 			return;

 		}

 	}

-	

+

 	private static class MockConfigListener implements IConfigListener {

 		public boolean changed = false;

 		public boolean loaded = false;

-		

-		public void configChanged(ConfigEvent e) {

+

+		public void configChanged(final ConfigEvent e) {

 			changed = true;

 		}

 

-		public void configLoaded(ConfigEvent e) {

+		public void configLoaded(final ConfigEvent e) {

 			loaded = true;

 		}

-		

+

 		public void reset() {

 			changed = false;

 			loaded = false;

 		}

 	}

-	

-	private static class MockConfigSource extends ConfigSource {

-		@Override

-		public URL getBaseUrl() {

-			try {

-				return new URL("test:/test");

-			} catch (MalformedURLException e) {

-				throw new AssertionError(e);

-			}

-		}

-	}

 }

diff --git a/sourceediting/tests/org.eclipse.wst.xml.vex.ui.tests/src/org/eclipse/wst/xml/vex/ui/internal/config/tests/PluginProjectTest.java b/sourceediting/tests/org.eclipse.wst.xml.vex.ui.tests/src/org/eclipse/wst/xml/vex/ui/internal/config/tests/PluginProjectTest.java
index 5342d3b..20407e5 100644
--- a/sourceediting/tests/org.eclipse.wst.xml.vex.ui.tests/src/org/eclipse/wst/xml/vex/ui/internal/config/tests/PluginProjectTest.java
+++ b/sourceediting/tests/org.eclipse.wst.xml.vex.ui.tests/src/org/eclipse/wst/xml/vex/ui/internal/config/tests/PluginProjectTest.java
@@ -11,8 +11,8 @@
 package org.eclipse.wst.xml.vex.ui.internal.config.tests;

 

 import java.io.ByteArrayInputStream;

-import java.io.ByteArrayOutputStream;

-import java.io.PrintStream;

+import java.io.PrintWriter;

+import java.io.StringWriter;

 

 import org.eclipse.core.resources.IProject;

 import org.eclipse.core.resources.IProjectDescription;

@@ -41,8 +41,13 @@
 	}

 

 	public static void createVexPluginFile(final IProject project) throws CoreException {

-		final ByteArrayOutputStream baos = new ByteArrayOutputStream();

-		final PrintStream out = new PrintStream(baos);

+		final String fileContent = createVexPluginFileContent(project);

+		project.getFile(PluginProject.PLUGIN_XML).create(new ByteArrayInputStream(fileContent.getBytes()), true, null);

+	}

+

+	public static String createVexPluginFileContent(final IProject project) {

+		final StringWriter result = new StringWriter();

+		final PrintWriter out = new PrintWriter(result);

 		out.println("<?xml version='1.0'?>"); //$NON-NLS-1$

 		// HINT: It is important to set the id attribute, because this is used as the unique identifier for the configuration. 

 		out.println("<plugin id=\"" + project.getName() + "\">"); //$NON-NLS-1$

@@ -54,7 +59,7 @@
 		out.println("</extension>"); //$NON-NLS-1$

 		out.println("</plugin>"); //$NON-NLS-1$

 		out.close();

-		project.getFile(PluginProject.PLUGIN_XML).create(new ByteArrayInputStream(baos.toByteArray()), true, null);

+		return result.toString();

 	}

 

 	public static void addVexProjectNature(final IProject project) throws CoreException {