Author: rob.stryker(a)jboss.com
Date: 2012-08-03 02:50:11 -0400 (Fri, 03 Aug 2012)
New Revision: 42846
Added:
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/classpath/ClasspathSuite.java
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/classpath/EJB3SupportVerifierTest.java
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/parametized/server/publishing/defect/PublishDefectSuite.java
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/parametized/server/publishing/defect/PublishWeb2DeletesWeb1LibsTest.java
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/polling/
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/polling/AbstractTestInternalPoller.java
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/polling/DummyYesOrNoPoller.java
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/polling/PollThreadTest.java
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/polling/PollerFailureHandler.java
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/polling/TestInternalPoller.java
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/utiltests/ConfigNameResolverTest.java
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/utiltests/UnitedServerListenerTest.java
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/utiltests/UtilsSuite.java
Removed:
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/MySuite.java
Log:
JBIDE-12363 unit tests
Deleted:
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/MySuite.java
===================================================================
---
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/MySuite.java 2012-08-03
06:47:04 UTC (rev 42845)
+++
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/MySuite.java 2012-08-03
06:50:11 UTC (rev 42846)
@@ -1,17 +0,0 @@
-package org.jboss.tools.as.test.core;
-
-import org.jboss.tools.as.test.core.classpath.ClasspathSuite;
-import org.jboss.tools.as.test.core.parametized.server.ParametizedSuite;
-import org.jboss.tools.as.test.core.utiltests.UtilsSuite;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-import org.junit.runners.Suite.SuiteClasses;
-
-(a)RunWith(Suite.class)
-@SuiteClasses({
- ParametizedSuite.class,
- UtilsSuite.class,
- ClasspathSuite.class
-})
-public class MySuite {
-}
Added:
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/classpath/ClasspathSuite.java
===================================================================
---
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/classpath/ClasspathSuite.java
(rev 0)
+++
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/classpath/ClasspathSuite.java 2012-08-03
06:50:11 UTC (rev 42846)
@@ -0,0 +1,13 @@
+package org.jboss.tools.as.test.core.classpath;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+(a)RunWith(Suite.class)
+@SuiteClasses({
+ JEEClasspathContainerTest.class,
+ EJB3SupportVerifierTest.class
+})
+public class ClasspathSuite {
+}
Added:
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/classpath/EJB3SupportVerifierTest.java
===================================================================
---
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/classpath/EJB3SupportVerifierTest.java
(rev 0)
+++
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/classpath/EJB3SupportVerifierTest.java 2012-08-03
06:50:11 UTC (rev 42846)
@@ -0,0 +1,88 @@
+package org.jboss.tools.as.test.core.classpath;
+
+import java.util.Collection;
+import java.util.HashMap;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.as.classpath.core.ejb3.EJB30SupportVerifier;
+import org.jboss.ide.eclipse.as.classpath.core.ejb3.EJB3ClasspathContainer;
+import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
+import org.jboss.tools.as.test.core.internal.utils.ServerCreationTestUtils;
+import org.jboss.tools.as.test.core.parametized.server.ServerParameterUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * This class will test properties of a default created server and runtime
+ * for properties that should never be null.
+ *
+ * @author rob
+ *
+ */
+@RunWith(value = Parameterized.class)
+public class EJB3SupportVerifierTest extends TestCase {
+ private String serverType;
+ private IServer server;
+ @Parameters
+ public static Collection<Object[]> data() {
+ return
ServerParameterUtils.asCollection(ServerParameterUtils.getAllJBossServerTypeParamterers());
+ }
+
+ private static HashMap<String, Boolean> expected;
+ static {
+ expected = new HashMap<String, Boolean>();
+ expected.put(IJBossToolingConstants.DEPLOY_ONLY_SERVER, false);
+ expected.put(IJBossToolingConstants.SERVER_AS_32, false);
+ expected.put(IJBossToolingConstants.SERVER_AS_40, false);
+ expected.put(IJBossToolingConstants.SERVER_AS_42, true);
+ expected.put(IJBossToolingConstants.SERVER_AS_50, true);
+ expected.put(IJBossToolingConstants.SERVER_AS_51, true);
+ expected.put(IJBossToolingConstants.SERVER_AS_60, true);
+ expected.put(IJBossToolingConstants.SERVER_AS_70, true);
+ expected.put(IJBossToolingConstants.SERVER_AS_71, true);
+ expected.put(IJBossToolingConstants.SERVER_EAP_43, true);
+ expected.put(IJBossToolingConstants.SERVER_EAP_50, true);
+ expected.put(IJBossToolingConstants.SERVER_EAP_60, true);
+ }
+
+ public EJB3SupportVerifierTest(String serverType) {
+ this.serverType = serverType;
+ }
+
+ @Before
+ public void setUp() throws CoreException {
+ server = ServerCreationTestUtils.createServerWithRuntime(serverType,
getClass().getName() + serverType);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ ServerCreationTestUtils.deleteAllServersAndRuntimes();
+ }
+
+ @Test
+ public void testEJB30Support() {
+ if( expected.get(serverType) == null )
+ fail("Test needs to be updated for new server type");
+ boolean supported = EJB30SupportVerifier.verify(server.getRuntime());
+ assertEquals(new Boolean(supported), new Boolean(expected.get(serverType)));
+ IPath containerPath = new
Path(EJB3ClasspathContainer.CONTAINER_ID).append(server.getName());
+ EJB3ClasspathContainer container = new EJB3ClasspathContainer(containerPath, null);
+ IClasspathEntry[] entries = container.getClasspathEntries();
+ if( supported ) {
+ assertTrue("server type " + serverType + " supports ejb3 but receives
no jars from this classpath container",
+ entries != null && entries.length > 0);
+ } else {
+ assertTrue(entries != null && entries.length == 0);
+ }
+ }
+}
Added:
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/parametized/server/publishing/defect/PublishDefectSuite.java
===================================================================
---
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/parametized/server/publishing/defect/PublishDefectSuite.java
(rev 0)
+++
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/parametized/server/publishing/defect/PublishDefectSuite.java 2012-08-03
06:50:11 UTC (rev 42846)
@@ -0,0 +1,14 @@
+package org.jboss.tools.as.test.core.parametized.server.publishing.defect;
+
+import
org.jboss.tools.as.test.core.parametized.server.publishing.defect.RepublishDefectTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+(a)RunWith(Suite.class)
+@SuiteClasses({
+ PublishWeb2DeletesWeb1LibsTest.class,
+ RepublishDefectTest.class
+})
+public class PublishDefectSuite {
+}
Added:
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/parametized/server/publishing/defect/PublishWeb2DeletesWeb1LibsTest.java
===================================================================
---
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/parametized/server/publishing/defect/PublishWeb2DeletesWeb1LibsTest.java
(rev 0)
+++
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/parametized/server/publishing/defect/PublishWeb2DeletesWeb1LibsTest.java 2012-08-03
06:50:11 UTC (rev 42846)
@@ -0,0 +1,135 @@
+package org.jboss.tools.as.test.core.parametized.server.publishing.defect;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.wst.common.project.facet.core.internal.FacetedProjectNature;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+import org.eclipse.wst.server.core.ServerUtil;
+import org.jboss.ide.eclipse.as.core.publishers.PublishUtil;
+import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
+import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
+import org.jboss.ide.eclipse.as.core.util.ServerConverter;
+import org.jboss.tools.as.test.core.internal.utils.ResourceUtils;
+import org.jboss.tools.as.test.core.internal.utils.ServerCreationTestUtils;
+import org.jboss.tools.jmx.core.test.util.TestProjectProvider;
+import org.jboss.tools.test.util.JobUtils;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class PublishWeb2DeletesWeb1LibsTest extends TestCase {
+ TestProjectProvider[] providers = null;
+ IProject[] projects = null;
+ IServer server;
+
+ @Before
+ public void setUp() throws Exception {
+ TestProjectProvider util1Provider = new
TestProjectProvider("org.jboss.tools.as.test.core", null,
+ "UserForum1Util1", true);
+ IProject util1Project = util1Provider.getProject();
+ util1Project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+
+ TestProjectProvider util2Provider = new
TestProjectProvider("org.jboss.tools.as.test.core", null,
+ "UserForum1Util2", true);
+ IProject util2Project = util2Provider.getProject();
+ util2Project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+
+ TestProjectProvider ejb1Provider = new
TestProjectProvider("org.jboss.tools.as.test.core", null,
+ "UserForum1EJB1", true);
+ IProject ejb1Project = ejb1Provider.getProject();
+ ejb1Project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+
+
+ TestProjectProvider web1Provider = new
TestProjectProvider("org.jboss.tools.as.test.core", null,
+ "UserForum1Web1", true);
+ IProject web1Project = web1Provider.getProject();
+ web1Project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+
+ TestProjectProvider web2Provider = new
TestProjectProvider("org.jboss.tools.as.test.core", null,
+ "UserForum1Web2", true);
+ IProject web2Project = web2Provider.getProject();
+ web2Project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+
+ JobUtils.waitForIdle();
+ projects = new IProject[]{ util1Project, util2Project, ejb1Project, web1Project,
web2Project};
+ providers = new TestProjectProvider[]{util1Provider, util2Provider, ejb1Provider,
web1Provider, web2Provider};
+
+ for( int i = 0; i < projects.length; i++ ) {
+ assertTrue(projects[i].exists());
+ assertTrue(projects[i].isAccessible());
+ assertTrue(projects[i].isNatureEnabled( FacetedProjectNature.NATURE_ID ));
+ }
+
+ server =
ServerCreationTestUtils.createServerWithRuntime(IJBossToolingConstants.DEPLOY_ONLY_SERVER,
getClass().getName());
+ }
+
+ private void addModuleAndFullPublish(String projectName) throws CoreException {
+ IDeployableServer ds = ServerConverter.getDeployableServer(server);
+ server = addModuleToServer(findModuleForProject(projectName));
+ server.publish(IServer.PUBLISH_FULL, new NullProgressMonitor());
+ JobUtils.waitForIdle();
+ }
+
+ @Test
+ public void testFullPublishes() throws CoreException {
+ addModuleAndFullPublish("UserForum1EJB1");
+ verifyEJBAndJarExist();
+
+ addModuleAndFullPublish("UserForum1Web1");
+ verifyEJBAndJarExist();
+ verifyWeb1AndLibsExist();
+
+ addModuleAndFullPublish("UserForum1Web2");
+ verifyEJBAndJarExist();
+ verifyWeb1AndLibsExist();
+ verifyWeb2AndLibsExist();
+
+ }
+
+
+ private void verifyEJBAndJarExist() {
+ // Make sure ejb and libs exist
+ IDeployableServer ds = ServerConverter.getDeployableServer(server);
+ IPath fullPath =
PublishUtil.getDeployPath(findArrayForProject("UserForum1EJB1"), ds);
+ assertTrue(fullPath.toFile().exists());
+ assertTrue(fullPath.append("UserForum1Util1.jar").toFile().exists());
+ }
+ private void verifyWeb1AndLibsExist() {
+ // Make sure ejb and libs exist
+ IDeployableServer ds = ServerConverter.getDeployableServer(server);
+ IPath fullPath =
PublishUtil.getDeployPath(findArrayForProject("UserForum1Web1"), ds);
+ assertTrue(fullPath.toFile().exists());
+ assertTrue(fullPath.append("WEB-INF").append("lib").append("UserForum1Util1.jar").toFile().exists());
+ assertTrue(fullPath.append("WEB-INF").append("lib").append("UserForum1Util2.jar").toFile().exists());
+ }
+ private void verifyWeb2AndLibsExist() {
+ // Make sure ejb and libs exist
+ IDeployableServer ds = ServerConverter.getDeployableServer(server);
+ IPath fullPath =
PublishUtil.getDeployPath(findArrayForProject("UserForum1Web2"), ds);
+ assertTrue(fullPath.toFile().exists());
+ assertTrue(fullPath.append("WEB-INF").append("lib").append("UserForum1Util1.jar").toFile().exists());
+ assertTrue(fullPath.append("WEB-INF").append("lib").append("UserForum1Util2.jar").toFile().exists());
+ }
+
+ public IModule[] findArrayForProject(String projectName) {
+ return new IModule[] { findModuleForProject(projectName) };
+ }
+
+ public IModule findModuleForProject(String projectName) {
+ return ServerUtil.getModule(ResourceUtils.findProject(projectName));
+ }
+
+ public IServer addModuleToServer(IModule module) throws CoreException {
+ IServerWorkingCopy wc = server.createWorkingCopy();
+ wc.modifyModules(new IModule[]{module}, new IModule[0], new NullProgressMonitor());
+ return wc.save(true, null);
+ }
+
+}
Added:
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/polling/AbstractTestInternalPoller.java
===================================================================
---
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/polling/AbstractTestInternalPoller.java
(rev 0)
+++
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/polling/AbstractTestInternalPoller.java 2012-08-03
06:50:11 UTC (rev 42846)
@@ -0,0 +1,53 @@
+package org.jboss.tools.as.test.core.polling;
+
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.as.core.server.IServerStatePoller;
+import org.jboss.ide.eclipse.as.core.server.IServerStatePoller2;
+import org.jboss.ide.eclipse.as.core.server.internal.ServerStatePollerType;
+
+public class AbstractTestInternalPoller implements IServerStatePoller2 {
+ private ServerStatePollerType type;
+ private IServer server;
+ public AbstractTestInternalPoller() {
+ }
+
+ public ServerStatePollerType getPollerType() {
+ return type;
+ }
+ public void setPollerType(ServerStatePollerType type) {
+ this.type = type;
+ }
+ public void beginPolling(IServer server, boolean expectedState)
+ throws PollingException {
+ this.server = server;
+ }
+ public IServer getServer() {
+ return server;
+ }
+ public boolean isComplete() throws PollingException, RequiresInfoException {
+ return false;
+ }
+ public boolean getState() throws PollingException, RequiresInfoException {
+ return IServerStatePoller.SERVER_DOWN;
+ }
+ public void cleanup() {
+ }
+ public void cancel(int type) {
+ }
+ public int getTimeoutBehavior() {
+ return 0;
+ }
+ public List<String> getRequiredProperties() {
+ return null;
+ }
+ public void provideCredentials(Properties credentials) {
+ }
+ public IStatus getCurrentStateSynchronous(IServer server) {
+ return null;
+ }
+
+}
Added:
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/polling/DummyYesOrNoPoller.java
===================================================================
---
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/polling/DummyYesOrNoPoller.java
(rev 0)
+++
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/polling/DummyYesOrNoPoller.java 2012-08-03
06:50:11 UTC (rev 42846)
@@ -0,0 +1,47 @@
+package org.jboss.tools.as.test.core.polling;
+
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.as.core.server.IServerStatePoller2;
+import org.jboss.ide.eclipse.as.core.server.internal.ServerStatePollerType;
+
+public class DummyYesOrNoPoller implements IServerStatePoller2 {
+ private ServerStatePollerType type;
+ public ServerStatePollerType getPollerType() {
+ return type;
+ }
+ public IStatus getCurrentStateSynchronous(IServer server) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ public void setPollerType(ServerStatePollerType type) {
+ this.type = type;
+ }
+ public void beginPolling(IServer server, boolean expectedState)
+ throws PollingException {
+ }
+ public boolean isComplete() throws PollingException, RequiresInfoException {
+ return false;
+ }
+ public boolean getState() throws PollingException, RequiresInfoException {
+ return false;
+ }
+ public void cleanup() {
+ }
+ public void cancel(int type) {
+ }
+ public int getTimeoutBehavior() {
+ return 0;
+ }
+ public List<String> getRequiredProperties() {
+ return null;
+ }
+ public void provideCredentials(Properties credentials) {
+ }
+ public IServer getServer() {
+ return null;
+ }
+}
Added:
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/polling/PollThreadTest.java
===================================================================
---
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/polling/PollThreadTest.java
(rev 0)
+++
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/polling/PollThreadTest.java 2012-08-03
06:50:11 UTC (rev 42846)
@@ -0,0 +1,249 @@
+package org.jboss.tools.as.test.core.polling;
+
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+import org.eclipse.wst.server.core.internal.Server;
+import org.jboss.ide.eclipse.as.core.ExtensionManager;
+import org.jboss.ide.eclipse.as.core.extensions.polling.ProcessTerminatedPoller;
+import org.jboss.ide.eclipse.as.core.extensions.polling.WebPortPoller;
+import org.jboss.ide.eclipse.as.core.server.IPollResultListener;
+import org.jboss.ide.eclipse.as.core.server.IProvideCredentials;
+import org.jboss.ide.eclipse.as.core.server.IServerProvider;
+import org.jboss.ide.eclipse.as.core.server.IServerStatePoller;
+import org.jboss.ide.eclipse.as.core.server.IServerStatePoller.PollingException;
+import org.jboss.ide.eclipse.as.core.server.IServerStatePoller.RequiresInfoException;
+import org.jboss.ide.eclipse.as.core.server.internal.PollThread;
+import org.jboss.ide.eclipse.as.core.server.internal.v7.JBoss7ManagerServicePoller;
+import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
+import org.jboss.ide.eclipse.as.core.util.PollThreadUtils;
+import org.jboss.tools.as.test.core.ASMatrixTests;
+import org.jboss.tools.as.test.core.internal.utils.ServerCreationTestUtils;
+import org.jboss.tools.test.util.JobUtils;
+import org.junit.After;
+import org.junit.Test;
+
+public class PollThreadTest extends TestCase {
+
+ @After
+ public void cleanup() throws Exception {
+ ASMatrixTests.cleanup();
+ }
+
+ @Test
+ public void testPollersFound() {
+ assertNotNull(PollThreadUtils.getPoller(WebPortPoller.WEB_POLLER_ID));
+ assertNotNull(PollThreadUtils.getPoller(ProcessTerminatedPoller.POLLER_ID));
+ assertNotNull(PollThreadUtils.getPoller("org.jboss.ide.eclipse.as.core.runtime.server.JMXPoller"));
+ assertNotNull(PollThreadUtils.getPoller(JBoss7ManagerServicePoller.POLLER_ID));
+ }
+
+ private IServer createServer(String addendum) throws CoreException {
+ return
ServerCreationTestUtils.createServerWithRuntime(IJBossToolingConstants.SERVER_AS_32,
+ IJBossToolingConstants.SERVER_AS_32 + addendum);
+ }
+
+ @Test
+ public void testPollerStringAttributes() throws CoreException {
+ IServer s = createServer("a");
+ IServerWorkingCopy wc = s.createWorkingCopy();
+ wc.setAttribute(IJBossToolingConstants.STARTUP_POLLER_KEY, "startupPoller");
+ wc.setAttribute(IJBossToolingConstants.SHUTDOWN_POLLER_KEY,
"shutdownPoller");
+ s = wc.save(true, null);
+ JobUtils.waitForIdle();
+ String startupPoller = PollThreadUtils.getPollerId(IServerStatePoller.SERVER_UP, s);
+ String shutdownPoller = PollThreadUtils.getPollerId(IServerStatePoller.SERVER_DOWN,
s);
+ assertEquals("startupPoller", startupPoller);
+ assertEquals("shutdownPoller", shutdownPoller);
+ }
+
+ @Test
+ public void testPollerResolution() throws CoreException {
+ IServer s = createServer("b");
+ IServerWorkingCopy wc = s.createWorkingCopy();
+ wc.setAttribute(IJBossToolingConstants.STARTUP_POLLER_KEY,
TestInternalPoller.POLLER_ID);
+ wc.setAttribute(IJBossToolingConstants.SHUTDOWN_POLLER_KEY,
TestInternalPoller.POLLER_ID);
+ s = wc.save(true, null);
+ JobUtils.waitForIdle();
+ String startupPoller = PollThreadUtils.getPollerId(IServerStatePoller.SERVER_UP, s);
+ String shutdownPoller = PollThreadUtils.getPollerId(IServerStatePoller.SERVER_DOWN,
s);
+ assertEquals(TestInternalPoller.POLLER_ID, startupPoller);
+ assertEquals(TestInternalPoller.POLLER_ID, shutdownPoller);
+ IServerStatePoller testPoller =
PollThreadUtils.getPoller(TestInternalPoller.POLLER_ID);
+ assertNotNull(testPoller);
+ assertEquals(testPoller.getClass(), TestInternalPoller.class);
+ }
+
+ private static class ServerProvider implements IServerProvider {
+ private IServer server;
+ public ServerProvider(IServer server) {
+ this.server = server;
+ }
+ public IServer getServer() {
+ return server;
+ }
+ }
+
+ private List<String> asList(String[] a) {
+ return Arrays.asList(a);
+ }
+
+ @Test
+ public void testInternalRequiresMoreInfoHandlerResolved() throws Exception {
+ IServer s = createServer("c");
+ IServerProvider pro = new ServerProvider(s);
+ String[] atts = new String[]{"a","b"};
+ IProvideCredentials provider =
ExtensionManager.getDefault().getFirstCredentialProvider(pro,asList(atts));
+ assertNotNull(provider);
+ assertFalse(provider instanceof PollerFailureHandler);
+ atts = new String[]{"a","b","c"};
+ provider = ExtensionManager.getDefault().getFirstCredentialProvider(pro,asList(atts));
+ assertNotNull(provider);
+ assertTrue(provider instanceof PollerFailureHandler);
+ atts = new String[]{"a","b","c","d"};
+ provider = ExtensionManager.getDefault().getFirstCredentialProvider(pro,asList(atts));
+ assertNull(provider);
+ }
+
+ @Test
+ public void testSynchronousResults() throws Exception {
+ IServer s = createServer("d");
+ IServerStatePoller currentlyUp = new AbstractTestInternalPoller() {
+ public IStatus getCurrentStateSynchronous(IServer server) {
+ return Status.OK_STATUS;
+ }
+ };
+ IStatus retStat = PollThreadUtils.isServerStarted(s, currentlyUp);
+ assertTrue(retStat.isOK());
+
+ IServerStatePoller currentlyDown = new AbstractTestInternalPoller() {
+ public IStatus getCurrentStateSynchronous(IServer server) {
+ return new Status(IStatus.ERROR, ASMatrixTests.PLUGIN_ID, "failure");
+ }
+ };
+ retStat = PollThreadUtils.isServerStarted(s, currentlyDown);
+ assertFalse(retStat.isOK());
+ }
+
+ @Test
+ public void testCancelReceivedDuringStartupPoll() throws Exception {
+ IServer s = createServer("d");
+ ((Server)s).setServerState(IServer.STATE_STARTING);
+ final int[] canceledHow = new int[]{-1};
+ final boolean[] cleanedUp = new boolean[]{false};
+ IServerStatePoller doNothingForever = new AbstractTestInternalPoller() {
+ public void cancel(int type) {
+ canceledHow[0] = type;
+ }
+ public void cleanup() {
+ cleanedUp[0] = true;
+ }
+ };
+ PollerListener listener = new PollerListener();
+ PollThread pt = new PollThread(IServerStatePoller.SERVER_UP, doNothingForever,
listener, s);
+ pt.start();
+ try {
+ Thread.sleep(500);
+ } catch(InterruptedException ie) {}
+ assertFalse(listener.anythingAsserted);
+ assertNull(listener.assertedWhat);
+ PollThreadUtils.cancelPolling("Some Message", pt);
+ assertEquals(canceledHow[0], IServerStatePoller.CANCEL);
+ try {
+ Thread.sleep(200);
+ } catch(InterruptedException ie){}
+ assertFalse(listener.anythingAsserted);
+ assertEquals(null, listener.assertedWhat);
+ assertTrue(cleanedUp[0]);
+ }
+
+ @Test
+ public void testCancelReceivedDuringShutdownPoll() throws Exception {
+ IServer s = createServer("e");
+ ((Server)s).setServerState(IServer.STATE_STOPPING);
+ final int[] canceledHow = new int[]{-1};
+ final boolean[] cleanedUp = new boolean[]{false};
+ IServerStatePoller doNothingForever = new AbstractTestInternalPoller() {
+ public boolean getState() throws PollingException, RequiresInfoException {
+ return IServerStatePoller.SERVER_UP;
+ }
+ public void cancel(int type) {
+ canceledHow[0] = type;
+ }
+ public void cleanup() {
+ cleanedUp[0] = true;
+ }
+ };
+ PollerListener listener = new PollerListener();
+ PollThread pt = new PollThread(IServerStatePoller.SERVER_DOWN, doNothingForever,
listener, s);
+ pt.start();
+ try {
+ Thread.sleep(500);
+ } catch(InterruptedException ie) {}
+ assertFalse(listener.anythingAsserted);
+ assertNull(listener.assertedWhat);
+ PollThreadUtils.cancelPolling("Some Message", pt);
+ assertEquals(canceledHow[0], IServerStatePoller.CANCEL);
+ try {
+ Thread.sleep(200);
+ } catch(InterruptedException ie){}
+ assertFalse(listener.anythingAsserted);
+ assertEquals(null, listener.assertedWhat);
+ assertTrue(cleanedUp[0]);
+ }
+
+ private static class PollerListener implements IPollResultListener {
+
+ private boolean anythingAsserted = false;
+ private boolean[] assertedWhat = null;
+ public void stateAsserted(boolean expectedState, boolean currentState) {
+ anythingAsserted = true;
+ assertedWhat = new boolean[]{expectedState, currentState};
+ }
+
+ @Override
+ public void stateNotAsserted(boolean expectedState, boolean currentState) {
+ anythingAsserted = true;
+ assertedWhat = new boolean[]{expectedState, currentState};
+ }
+ }
+
+ @Test
+ public void testPollerFailureCancelsThread() throws Exception {
+ IServer s = createServer("g");
+ ((Server)s).setServerState(IServer.STATE_STARTING);
+ final int[] canceledHow = new int[]{-1};
+ final boolean[] cleanedUp = new boolean[]{false};
+ IServerStatePoller failPoller = new AbstractTestInternalPoller() {
+ public boolean isComplete() throws PollingException, RequiresInfoException {
+ throw new PollingException("Automatic failure");
+ }
+ public void cancel(int type) {
+ canceledHow[0] = type;
+ }
+ public void cleanup() {
+ cleanedUp[0] = true;
+ }
+ };
+ PollerListener listener = new PollerListener();
+ PollThread pt = new PollThread(IServerStatePoller.SERVER_UP, failPoller, listener, s);
+ pt.start();
+ try {
+ Thread.sleep(500);
+ } catch(InterruptedException ie) {}
+ assertTrue(listener.anythingAsserted);
+ assertTrue(listener.assertedWhat[0]);
+ assertFalse(listener.assertedWhat[1]);
+ assertTrue(cleanedUp[0]);
+ assertEquals(canceledHow[0], IServerStatePoller.CANCEL);
+ assertFalse(pt.isAlive());
+ }
+
+}
Added:
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/polling/PollerFailureHandler.java
===================================================================
---
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/polling/PollerFailureHandler.java
(rev 0)
+++
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/polling/PollerFailureHandler.java 2012-08-03
06:50:11 UTC (rev 42846)
@@ -0,0 +1,29 @@
+package org.jboss.tools.as.test.core.polling;
+
+import java.util.List;
+
+import org.jboss.ide.eclipse.as.core.server.INeedCredentials;
+import org.jboss.ide.eclipse.as.core.server.IProvideCredentials;
+import org.jboss.ide.eclipse.as.core.server.IServerProvider;
+
+public class PollerFailureHandler implements IProvideCredentials {
+
+ public PollerFailureHandler() {
+ }
+
+ @Override
+ public boolean accepts(IServerProvider serverProvider,
+ List<String> requiredProperties) {
+ int size = requiredProperties.size();
+ if( size <= 2 )
+ return false;
+ if( size > 3 )
+ return false;
+ return true;
+ }
+
+ @Override
+ public void handle(INeedCredentials inNeed, List<String> requiredProperties) {
+ }
+
+}
Added:
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/polling/TestInternalPoller.java
===================================================================
---
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/polling/TestInternalPoller.java
(rev 0)
+++
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/polling/TestInternalPoller.java 2012-08-03
06:50:11 UTC (rev 42846)
@@ -0,0 +1,15 @@
+package org.jboss.tools.as.test.core.polling;
+
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.as.core.server.IServerStatePoller2;
+import org.jboss.ide.eclipse.as.core.server.internal.ServerStatePollerType;
+
+public class TestInternalPoller extends AbstractTestInternalPoller implements
IServerStatePoller2 {
+ public static final String POLLER_ID =
"org.jboss.tools.as.test.core.poller.TestInternalPoller";
+
+ // TODO
+}
Added:
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/utiltests/ConfigNameResolverTest.java
===================================================================
---
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/utiltests/ConfigNameResolverTest.java
(rev 0)
+++
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/utiltests/ConfigNameResolverTest.java 2012-08-03
06:50:11 UTC (rev 42846)
@@ -0,0 +1,94 @@
+package org.jboss.tools.as.test.core.utiltests;
+
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.as.core.resolvers.ConfigNameResolver;
+import org.jboss.ide.eclipse.as.core.server.internal.JBossServer;
+import org.jboss.ide.eclipse.as.core.util.ServerConverter;
+import org.jboss.ide.eclipse.as.core.util.ServerUtil;
+import org.jboss.tools.as.test.core.internal.utils.ServerCreationTestUtils;
+import org.jboss.tools.as.test.core.parametized.server.ServerParameterUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * This class will test properties of a default created server and runtime
+ * for properties that should never be null.
+ *
+ * @author rob
+ *
+ */
+@RunWith(value = Parameterized.class)
+public class ConfigNameResolverTest extends TestCase {
+ private String serverType;
+ private IServer server;
+ @Parameters
+ public static Collection<Object[]> data() {
+ return
ServerParameterUtils.asCollection(ServerParameterUtils.getAllJBossServerTypeParamterers());
+ }
+
+ public ConfigNameResolverTest(String serverType) {
+ this.serverType = serverType;
+ }
+
+ @Before
+ public void setUp() throws CoreException {
+ server = ServerCreationTestUtils.createServerWithRuntime(serverType,
getClass().getName() + serverType);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ ServerCreationTestUtils.deleteAllServersAndRuntimes();
+ }
+
+ @Test
+ public void testConfigNameResolver() {
+ String[] vars = ConfigNameResolver.ALL_VARIABLES;
+ for( int i = 0; i < vars.length; i++ ) {
+ String var = ConfigNameResolver.getVariablePattern(vars[i]);
+ String result = new ConfigNameResolver().performSubstitutions(var, server.getName());
+ JBossServer jbs = ServerConverter.getJBossServer(server);
+ if( jbs == null ) {
+ assertEquals("", result);
+ } else if( vars[i].equals(ConfigNameResolver.JBOSS_CONFIG))
+ testConfig(var, result, ServerUtil.isJBoss7(server));
+ else if( vars[i].equals(ConfigNameResolver.JBOSS_CONFIG_DIR))
+ testConfigDir(var, result, ServerUtil.isJBoss7(server));
+ else if( vars[i].equals(ConfigNameResolver.JBOSS_AS7_CONFIG_FILE))
+ testAS7ConfigFile(var, result, ServerUtil.isJBoss7(server));
+ else
+ fail("Variable " + vars[i] + " not tested");
+ }
+ }
+
+ private void testConfig(String var, String result, boolean isAS7 ) {
+ if( !isAS7)
+ assertEquals(result, "default");
+ else
+ assertEquals(result, "");
+ }
+ private void testConfigDir(String var, String result, boolean isAS7 ) {
+ if( !isAS7 ) {
+ assertNotSame(result, var);
+ assertNotSame(result, "");
+ } else
+ // This is more documenting current behaviour than what it *should* be.
+ // Oh well :(
+ assertEquals(result, server.getRuntime().getLocation().toString());
+ }
+ private void testAS7ConfigFile(String var, String result, boolean isAS7 ) {
+ if( isAS7 )
+ assertEquals(result, "standalone.xml");
+ else
+ assertEquals(result, "");
+ }
+
+}
Added:
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/utiltests/UnitedServerListenerTest.java
===================================================================
---
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/utiltests/UnitedServerListenerTest.java
(rev 0)
+++
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/utiltests/UnitedServerListenerTest.java 2012-08-03
06:50:11 UTC (rev 42846)
@@ -0,0 +1,48 @@
+package org.jboss.tools.as.test.core.utiltests;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+import org.eclipse.wst.server.core.ServerEvent;
+import org.jboss.ide.eclipse.as.core.server.UnitedServerListener;
+import org.jboss.ide.eclipse.as.core.server.UnitedServerListenerManager;
+import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
+import org.jboss.tools.as.test.core.internal.utils.ServerCreationTestUtils;
+import org.jboss.tools.test.util.JobUtils;
+import org.junit.After;
+import org.junit.Test;
+
+public class UnitedServerListenerTest extends TestCase {
+ @Test
+ public void testExistingServerGetsUpdates() throws CoreException {
+ final boolean[] changes = new boolean[]{false,false};
+ IServer s1 =
ServerCreationTestUtils.createServerWithRuntime(IJBossToolingConstants.DEPLOY_ONLY_SERVER,
"name1");
+ UnitedServerListener l = new UnitedServerListener() {
+ public boolean canHandleServer(IServer server) {
+ return true;
+ }
+ public void serverChanged(IServer server) {
+ changes[0] = true;
+ }
+ public void serverChanged(ServerEvent event) {
+ changes[1] = true;
+ }
+ };
+ UnitedServerListenerManager.getDefault().addListener(l);
+
+ IServerWorkingCopy wc = s1.createWorkingCopy();
+ wc.setAttribute("test1", "test2");
+ s1 = wc.save(true, null);
+ assertTrue(changes[0]);
+ s1.publish(IServer.PUBLISH_FULL, null);
+ JobUtils.waitForIdle(1000);
+ assertTrue(changes[1]);
+ }
+
+ @After
+ public void cleanup() throws Exception {
+ ServerCreationTestUtils.deleteAllServersAndRuntimes();
+ }
+}
Added:
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/utiltests/UtilsSuite.java
===================================================================
---
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/utiltests/UtilsSuite.java
(rev 0)
+++
trunk/as/tests/org.jboss.tools.as.test.core/src/org/jboss/tools/as/test/core/utiltests/UtilsSuite.java 2012-08-03
06:50:11 UTC (rev 42846)
@@ -0,0 +1,15 @@
+package org.jboss.tools.as.test.core.utiltests;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+(a)RunWith(Suite.class)
+@SuiteClasses({
+ ConfigNameResolverTest.class,
+ ArgsUtilTest.class,
+ ExpressionResolverUtilTest.class,
+ UnitedServerListenerTest.class
+})
+public class UtilsSuite {
+}