Author: rob.stryker(a)jboss.com
Date: 2010-04-20 23:22:35 -0400 (Tue, 20 Apr 2010)
New Revision: 21566
Added:
trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/
trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/3.2.8.mf.twiddle.jar
trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/4.0.5.mf.twiddle.jar
trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/4.2.3.mf.twiddle.jar
trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/5.0.0.mf.twiddle.jar
trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/5.0.1.mf.twiddle.jar
trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/5.1.0.mf.twiddle.jar
trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/6.0.0.mf.twiddle.jar
trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/eap4.3.mf.twiddle.jar
trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/eap5.0.mf.twiddle.jar
trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/jboss-service.xml
trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/run.jar
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/server/MockTests.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServerBehavior.java
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/AbstractDeploymentTest.java
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/util/ServerRuntimeUtils.java
Log:
Added some tests for making sure changing args works properly
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServerBehavior.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServerBehavior.java 2010-04-21
03:21:14 UTC (rev 21565)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServerBehavior.java 2010-04-21
03:22:35 UTC (rev 21566)
@@ -92,7 +92,7 @@
}}.start();
}
- public void forceStop() {
+ public synchronized void forceStop() {
// just terminate the process.
if( process != null && !process.isTerminated()) {
try {
@@ -132,7 +132,7 @@
protected transient IDebugEventSetListener processListener;
- public void setProcess(final IProcess newProcess) {
+ public synchronized void setProcess(final IProcess newProcess) {
if (process != null) {
return;
}
@@ -175,7 +175,7 @@
pollServer(IServerStatePoller.SERVER_DOWN);
}
- public IProcess getProcess() {
+ public synchronized IProcess getProcess() {
return process;
}
Added: trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/3.2.8.mf.twiddle.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/3.2.8.mf.twiddle.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/4.0.5.mf.twiddle.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/4.0.5.mf.twiddle.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/4.2.3.mf.twiddle.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/4.2.3.mf.twiddle.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/5.0.0.mf.twiddle.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/5.0.0.mf.twiddle.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/5.0.1.mf.twiddle.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/5.0.1.mf.twiddle.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/5.1.0.mf.twiddle.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/5.1.0.mf.twiddle.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/6.0.0.mf.twiddle.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/6.0.0.mf.twiddle.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/eap4.3.mf.twiddle.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/eap4.3.mf.twiddle.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/eap5.0.mf.twiddle.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/eap5.0.mf.twiddle.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/jboss-service.xml
===================================================================
Added: trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/run.jar
===================================================================
(Binary files differ)
Property changes on: trunk/as/tests/org.jboss.ide.eclipse.as.test/serverMock/run.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/AbstractDeploymentTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/AbstractDeploymentTest.java 2010-04-21
03:21:14 UTC (rev 21565)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/AbstractDeploymentTest.java 2010-04-21
03:22:35 UTC (rev 21566)
@@ -33,7 +33,7 @@
import org.osgi.framework.Bundle;
public abstract class AbstractDeploymentTest extends TestCase {
- protected String BUNDLE_NAME = "org.jboss.ide.eclipse.as.test";
+ public static String BUNDLE_NAME = "org.jboss.ide.eclipse.as.test";
private TestProjectProvider[] provider;
protected IProject[] workspaceProject;
protected String[] sourceProjectName;
Added:
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/server/MockTests.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/server/MockTests.java
(rev 0)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/server/MockTests.java 2010-04-21
03:22:35 UTC (rev 21566)
@@ -0,0 +1,150 @@
+package org.jboss.ide.eclipse.as.test.server;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+import org.jboss.ide.eclipse.as.core.server.internal.JBossServerBehavior;
+import org.jboss.ide.eclipse.as.core.server.internal.LocalJBossServerRuntime;
+import org.jboss.ide.eclipse.as.core.server.internal.ServerAttributeHelper;
+import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
+import org.jboss.ide.eclipse.as.test.util.ServerRuntimeUtils;
+
+public class MockTests extends TestCase {
+ public void setUp() {
+ }
+ public void tearDown() {
+ try {
+ ServerRuntimeUtils.deleteAllServers();
+ ServerRuntimeUtils.deleteAllRuntimes();
+ } catch(CoreException ce) {}
+ }
+
+
+ public void testRemoveCriticalVMArgs() {
+ IServer server = serverTestImpl(IJBossToolingConstants.SERVER_AS_50);
+ try {
+ ILaunchConfiguration config = server.getLaunchConfiguration(true, new
NullProgressMonitor());
+ ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
"hello");
+ wc.doSave();
+
+ // re-get it and check the changes
+ ILaunchConfiguration launchConfig = server.getLaunchConfiguration(false, null);
+ String vmArgs =
launchConfig.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
(String)null);
+ LocalJBossServerRuntime rt =
(LocalJBossServerRuntime)server.getRuntime().loadAdapter(LocalJBossServerRuntime.class,
new NullProgressMonitor());
+ String defaultVMArgs = rt.getDefaultRunVMArgs();
+ assertFalse(vmArgs == null);
+ assertFalse(vmArgs.equals(rt.getDefaultRunVMArgs()));
+ assertFalse(vmArgs.equals(defaultVMArgs));
+ assertTrue(vmArgs.startsWith("hello -Djava.endorsed.dirs=\""));
+ assertTrue(vmArgs.endsWith(".metadata/.plugins/org.jboss.ide.eclipse.as.test/mockedServers/server1/lib/endorsed\""));
+ } catch(CoreException ce) {
+ fail(ce.getMessage());
+ }
+ }
+
+ public void testChangeArgs() {
+ // should still match the defaults since the defaults are extremely all required
+ IServer server = serverTestImpl(IJBossToolingConstants.SERVER_AS_50);
+ try {
+ ILaunchConfiguration config = server.getLaunchConfiguration(true, new
NullProgressMonitor());
+ ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
"");
+ wc.doSave();
+ String command = runAndGetCommand(server);
+ assertFalse("No args found from process", command == null);
+ LocalJBossServerRuntime rt =
(LocalJBossServerRuntime)server.getRuntime().loadAdapter(LocalJBossServerRuntime.class,
new NullProgressMonitor());
+ String defaultArgs = rt.getDefaultRunArgs().replace("\"",
"");
+ assertTrue(command.replace("\"", "").contains(defaultArgs));
+ } catch(CoreException ce) {
+ fail(ce.getMessage());
+ }
+ }
+
+ protected IServer serverTestImpl(String type) {
+ IServer server = ServerRuntimeUtils.createMockServerWithRuntime(type,
"server1", "default");
+ IServer fixed = setMockDetails(server);
+ String command = runAndGetCommand(fixed);
+ assertFalse("No args found from process", command == null);
+
+ LocalJBossServerRuntime rt =
(LocalJBossServerRuntime)server.getRuntime().loadAdapter(LocalJBossServerRuntime.class,
new NullProgressMonitor());
+ String defaultArgs = rt.getDefaultRunArgs().replace("\"",
"");
+ String defaultVMArgs = rt.getDefaultRunVMArgs().replace("\"",
"");
+ assertTrue(command.replace("\"", "").contains(defaultArgs));
+ assertTrue(command.replace("\"",
"").contains(defaultVMArgs));
+ return fixed;
+ }
+
+ protected IProcess runAndGetProcess(final IServer server) {
+ try {
+ server.start("run", new NullProgressMonitor());
+ } catch( CoreException ce) {}
+
+ int loops = 0;
+ JBossServerBehavior behavior =
(JBossServerBehavior)server.loadAdapter(JBossServerBehavior.class, null);
+
+ while(loops < 50) {
+ if( behavior.getProcess() != null ) {
+ return behavior.getProcess();
+ }
+ try {
+ loops++;
+ Thread.sleep(1000);
+ } catch(Exception e){}
+ }
+ return null;
+ }
+
+ protected String runAndGetCommand(final IServer server) {
+ return runAndGetProcess(server).getAttribute(IProcess.ATTR_CMDLINE);
+ }
+
+ private IServer setMockDetails(IServer server) {
+ IServerWorkingCopy copy = server.createWorkingCopy();
+ ServerAttributeHelper helper = new ServerAttributeHelper(server, copy);
+ helper.setAttribute("start-timeout", "2");
+ helper.setAttribute("org.jboss.ide.eclipse.as.core.server.attributes.startupPollerKey",
+ "org.jboss.ide.eclipse.as.core.runtime.server.timeoutpoller");
+ try {
+ return copy.save(true, new NullProgressMonitor());
+ } catch( CoreException ce ) {
+ }
+ return null;
+ }
+
+ public void test32Mock() {
+ serverTestImpl(IJBossToolingConstants.SERVER_AS_32);
+ }
+
+ public void test40Mock() {
+ serverTestImpl(IJBossToolingConstants.SERVER_AS_40);
+ }
+
+ public void test42Mock() {
+ serverTestImpl(IJBossToolingConstants.SERVER_AS_42);
+ }
+
+ public void test50Mock() {
+ serverTestImpl(IJBossToolingConstants.SERVER_AS_50);
+ }
+ public void test51Mock() {
+ serverTestImpl(IJBossToolingConstants.SERVER_AS_51);
+ }
+ public void test60Mock() {
+ serverTestImpl(IJBossToolingConstants.SERVER_AS_60);
+ }
+ public void testEap43Mock() {
+ serverTestImpl(IJBossToolingConstants.SERVER_EAP_43);
+ }
+ public void testEap50Mock() {
+ serverTestImpl(IJBossToolingConstants.SERVER_EAP_50);
+ }
+}
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/util/ServerRuntimeUtils.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/util/ServerRuntimeUtils.java 2010-04-21
03:21:14 UTC (rev 21565)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/util/ServerRuntimeUtils.java 2010-04-21
03:22:35 UTC (rev 21566)
@@ -1,8 +1,20 @@
package org.jboss.ide.eclipse.as.test.util;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.HashMap;
+
+import junit.framework.TestCase;
+
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.wst.server.core.IRuntime;
@@ -15,13 +27,60 @@
import org.eclipse.wst.server.core.ServerUtil;
import org.eclipse.wst.server.core.internal.RuntimeWorkingCopy;
import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
+import org.jboss.ide.eclipse.as.core.util.FileUtil;
+import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
+import org.jboss.ide.eclipse.as.test.ASTest;
+import org.jboss.ide.eclipse.as.test.publishing.AbstractDeploymentTest;
+import org.osgi.framework.Bundle;
-import junit.framework.TestCase;
-
public class ServerRuntimeUtils extends TestCase {
public static final IVMInstall VM_INSTALL = JavaRuntime.getDefaultVMInstall();
public static final String DEFAULT_CONFIG = "default";
+ public static final String twiddle_suffix = ".mf.twiddle.jar";
+ public static final String twiddle_3_2_8 = "3.2.8" + twiddle_suffix;
+ public static final String twiddle_4_0_5 = "4.0.5" + twiddle_suffix;
+ public static final String twiddle_4_2_3 = "4.2.3" + twiddle_suffix;
+ public static final String twiddle_5_0_0 = "5.0.0" + twiddle_suffix;
+ public static final String twiddle_5_0_1 = "5.0.1" + twiddle_suffix;
+ public static final String twiddle_5_1_0 = "5.1.0" + twiddle_suffix;
+ public static final String twiddle_6_0_0 = "6.0.0" + twiddle_suffix;
+ public static final String twiddle_eap_4_3 = "eap4.3" + twiddle_suffix;
+ public static final String twiddle_eap_5_0 = "eap5.0" + twiddle_suffix;
+ public static final String run_jar = "run.jar";
+ public static final String service_xml = "service.xml";
+ public static final IPath mockedServers =
ASTest.getDefault().getStateLocation().append("mockedServers");
+ public static HashMap<String, String> twiddleMap = new HashMap<String,
String>();
+ public static HashMap<String, String> serverRuntimeMap = new HashMap<String,
String>();
+
+ static {
+ twiddleMap.put(IJBossToolingConstants.SERVER_AS_32, twiddle_3_2_8);
+ twiddleMap.put(IJBossToolingConstants.SERVER_AS_40, twiddle_4_0_5);
+ twiddleMap.put(IJBossToolingConstants.SERVER_AS_42, twiddle_4_2_3);
+ twiddleMap.put(IJBossToolingConstants.SERVER_AS_50, twiddle_5_0_0);
+ twiddleMap.put(IJBossToolingConstants.SERVER_AS_51, twiddle_5_1_0);
+ twiddleMap.put(IJBossToolingConstants.SERVER_AS_60, twiddle_6_0_0);
+ twiddleMap.put(IJBossToolingConstants.SERVER_EAP_43, twiddle_eap_4_3);
+ twiddleMap.put(IJBossToolingConstants.SERVER_EAP_50, twiddle_eap_5_0);
+ serverRuntimeMap.put(IJBossToolingConstants.SERVER_AS_32,
IJBossToolingConstants.AS_32);
+ serverRuntimeMap.put(IJBossToolingConstants.SERVER_AS_40,
IJBossToolingConstants.AS_40);
+ serverRuntimeMap.put(IJBossToolingConstants.SERVER_AS_42,
IJBossToolingConstants.AS_42);
+ serverRuntimeMap.put(IJBossToolingConstants.SERVER_AS_50,
IJBossToolingConstants.AS_50);
+ serverRuntimeMap.put(IJBossToolingConstants.SERVER_AS_51,
IJBossToolingConstants.AS_51);
+ serverRuntimeMap.put(IJBossToolingConstants.SERVER_AS_60,
IJBossToolingConstants.AS_60);
+ serverRuntimeMap.put(IJBossToolingConstants.SERVER_EAP_43,
IJBossToolingConstants.EAP_43);
+ serverRuntimeMap.put(IJBossToolingConstants.SERVER_EAP_50,
IJBossToolingConstants.EAP_50);
+}
+
+ public static IServer createMockServerWithRuntime(String serverType, String name, String
config) {
+ try {
+ IPath serverDir = createMockServerDirectory(name, twiddleMap.get(serverType),
config);
+ return createServer(serverRuntimeMap.get(serverType), serverType,
serverDir.toOSString(), config);
+ } catch( CoreException ce ) {
+ }
+ return null;
+ }
+
public static IServer createServer(String runtimeID, String serverID,
String location, String configuration) throws CoreException {
// if file doesnt exist, abort immediately.
@@ -70,7 +129,49 @@
public static void deleteAllRuntimes() throws CoreException {
IRuntime[] runtimes = ServerCore.getRuntimes();
for( int i = 0; i < runtimes.length; i++ ) {
+ if( mockedServers.isPrefixOf(runtimes[i].getLocation())) {
+ FileUtil.completeDelete(runtimes[i].getLocation().toFile());
+ }
runtimes[i].delete();
}
}
+
+
+
+ public static IPath createMockServerDirectory(String name, String twiddleJar, String
configurationName ) {
+ IPath loc = mockedServers.append(name);
+ try {
+ loc.toFile().mkdirs();
+ loc.append("bin").toFile().mkdirs();
+ loc.append("server").toFile().mkdirs();
+ loc.append("server").append(configurationName).toFile().mkdirs();
+ IPath configConf =
loc.append("server").append(configurationName).append("conf");
+ configConf.toFile().mkdirs();
+ File twiddleLoc = getFileLocation("serverMock/" + twiddleJar);
+ FileUtil.fileSafeCopy(twiddleLoc,
loc.append("bin").append("twiddle.jar").toFile());
+ File runJar = getFileLocation("serverMock/run.jar");
+ FileUtil.fileSafeCopy(runJar,
loc.append("bin").append("run.jar").toFile());
+ File serviceXml = getFileLocation("serverMock/jboss-service.xml");
+ FileUtil.fileSafeCopy(serviceXml,
configConf.append("jboss-service.xml").toFile());
+ return loc;
+ } catch( CoreException ce ) {
+ FileUtil.completeDelete(loc.toFile());
+ return null;
+ }
+ }
+
+ // Find a file in our bundle
+ protected static File getFileLocation(String path) throws CoreException {
+ Bundle bundle = Platform.getBundle(AbstractDeploymentTest.BUNDLE_NAME);
+ URL url = null;
+ try {
+ url = FileLocator.resolve(bundle.getEntry(path));
+ } catch (IOException e) {
+ String msg = "Cannot find file " + path + " in " +
AbstractDeploymentTest.BUNDLE_NAME;
+ IStatus status = new Status(IStatus.ERROR, ASTest.PLUGIN_ID, msg, e);
+ throw new CoreException(status);
+ }
+ String location = url.getFile();
+ return new File(location);
+ }
}