Author: adietish
Date: 2011-06-06 08:07:34 -0400 (Mon, 06 Jun 2011)
New Revision: 31844
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/MockJSTPublisherTest.java
Log:
[JBIDE-9069] fixed MockJSTPublisherTest#testForced7Logic
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/MockJSTPublisherTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/MockJSTPublisherTest.java 2011-06-06
12:05:39 UTC (rev 31843)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/MockJSTPublisherTest.java 2011-06-06
12:07:34 UTC (rev 31844)
@@ -4,6 +4,7 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.ServerUtil;
import org.jboss.ide.eclipse.as.test.util.IOUtil;
@@ -22,38 +23,106 @@
MockPublishMethod.reset();
theTest(true);
}
-
- private void theTest(boolean as7) throws CoreException, IOException {
-
+
+ private void theTest(boolean isAs7) throws CoreException, IOException {
+
IModule mod = ServerUtil.getModule(project);
- IModule[] module = new IModule[] { mod };
- server = ServerRuntimeUtils.addModule(server,mod);
+ server = ServerRuntimeUtils.addModule(server, mod);
ServerRuntimeUtils.publish(server);
- // one additional for doDeploy
- assertEquals(as7 ? 3 : 2, MockPublishMethod.getChanged().length);
+ assertChanged(
+ isAs7,
+ new String[] { "newModule.ear",
"newModule.ear/META-INF/application.xml" },
+ new String[] { "newModule.ear",
"newModule.ear/META-INF/application.xml", "newModule.ear.dodeploy"
});
+ assertRemoved(
+ isAs7,
+ new String[] { "newModule.ear" },
+ // jst publisher always removes the prior deployed artifact since we could have
switched from zipped to exploded
+ new String[] { "newModule.ear", "newModule.ear.failed" });
MockPublishMethod.reset();
-
+
IFile textFile = project.getFile(CONTENT_TEXT_FILE);
IOUtil.setContents(textFile, 0);
assertEquals(0, MockPublishMethod.getChanged().length);
ServerRuntimeUtils.publish(server);
- assertEquals(as7 ? 3 : 2, MockPublishMethod.getChanged().length);
+ assertChanged(
+ isAs7,
+ new String[] { "newModule.ear", "newModule.ear/test.txt" },
+ new String[] { "newModule.ear", "newModule.ear/test.txt",
"newModule.ear.dodeploy" });
+ assertRemoved(
+ isAs7,
+ new String[] {}, new String[] { "newModule.ear.failed" });
MockPublishMethod.reset();
IOUtil.setContents(textFile, 1);
ServerRuntimeUtils.publish(server);
- assertEquals(as7 ? 3 : 2, MockPublishMethod.getChanged().length);
+ assertChanged(
+ isAs7,
+ new String[] { "newModule.ear", "newModule.ear/test.txt" },
+ new String[] { "newModule.ear", "newModule.ear/test.txt",
"newModule.ear.dodeploy" });
+ assertRemoved(
+ isAs7,
+ new String[] {},
+ new String[] { "newModule.ear.failed" });
MockPublishMethod.reset();
textFile.delete(true, null);
ServerRuntimeUtils.publish(server);
- assertEquals(1, MockPublishMethod.getRemoved().length);
+ assertRemoved(
+ isAs7,
+ new String[] { "newModule.ear/test.txt" },
+ new String[] { "newModule.ear.failed", "newModule.ear/test.txt"
});
+ assertChanged(
+ isAs7,
+ new String[] {},
+ new String[] { "newModule.ear.dodeploy" });
MockPublishMethod.reset();
server = ServerRuntimeUtils.removeModule(server, mod);
assertEquals(0, MockPublishMethod.getRemoved().length);
-
- // Still just one delete, but should be the .deployed file
+
ServerRuntimeUtils.publish(server);
- assertEquals(1, MockPublishMethod.getRemoved().length);
+ assertRemoved(
+ isAs7,
+ new String[] { "newModule.ear" },
+ new String[] { "newModule.ear.deployed", "newModule.ear.failed"
});
}
+
+ private void assertRemoved(boolean isAs7, String[] nonAs7, String[] as7) {
+ assertExpectedArtifacts(isAs7, nonAs7, as7, MockPublishMethod.getRemoved());
+ }
+ private void assertChanged(boolean isAs7, String[] nonAs7, String[] as7) {
+ assertExpectedArtifacts(isAs7, nonAs7, as7, MockPublishMethod.getChanged());
+ }
+
+ private void assertExpectedArtifacts(boolean isAs7, String[] nonAs7, String[] as7,
IPath[] artifacts) {
+ if (isAs7) {
+ assertEquals(as7.length, artifacts.length);
+ } else {
+ assertEquals(nonAs7.length, artifacts.length);
+ }
+
+ if (isAs7) {
+ for (String expectedPath : as7) {
+ if (contains(expectedPath, artifacts)) {
+ continue;
+ }
+ fail(expectedPath + " was not among the changed/removed artifacts");
+ }
+ } else {
+ for (String expectedPath : nonAs7) {
+ if (contains(expectedPath, artifacts)) {
+ continue;
+ }
+ fail(expectedPath + " was not among the changed/removed artifacts");
+ }
+ }
+ }
+
+ private boolean contains(String expectedPath, IPath[] paths) {
+ for (IPath path : paths) {
+ if (expectedPath.equals(path.toString())) {
+ return true;
+ }
+ }
+ return false;
+ }
}