Skip to content

Commit

Permalink
[JBIDE-24184] adding DebugMode tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adietish committed Aug 9, 2017
1 parent e480132 commit 5411924
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.osgi.util.NLS;
import org.jboss.ide.eclipse.as.wtp.core.server.behavior.IControllableServerBehavior;
import org.jboss.tools.foundation.core.plugin.log.StatusFactory;
import org.jboss.tools.openshift.common.core.OpenShiftCoreException;
import org.jboss.tools.openshift.core.connection.Connection;
import org.jboss.tools.openshift.core.connection.ConnectionsRegistryUtil;
import org.jboss.tools.openshift.core.server.OpenShiftServerBehaviour;
import org.jboss.tools.openshift.core.server.OpenShiftServerUtils;
import org.jboss.tools.openshift.internal.core.OpenShiftCoreActivator;
import org.jboss.tools.openshift.internal.core.models.PortSpecAdapter;
Expand Down Expand Up @@ -73,7 +73,7 @@ public class OpenShiftDebugMode {
* @return
* @throws CoreException
*/
public static DebugContext createContext(OpenShiftServerBehaviour behaviour, String devmodeKey, String debugPortKey, String debugPort) {
public static DebugContext createContext(IControllableServerBehavior behaviour, String devmodeKey, String debugPortKey, String debugPort) {
Assert.isNotNull(behaviour);

DebugContext context = new DebugContext(behaviour,
Expand Down Expand Up @@ -374,7 +374,7 @@ public static class DebugContext {

public static final int NO_DEBUG_PORT = -1;

private OpenShiftServerBehaviour behaviour;
private IControllableServerBehavior behaviour;

private boolean debugEnabled;
private boolean devmodeEnabled;
Expand All @@ -383,14 +383,14 @@ public static class DebugContext {
private int debugPort = NO_DEBUG_PORT;
private IDebugListener listener;

private DebugContext(OpenShiftServerBehaviour behaviour, String devmodeKey, String debugPortKey, String debugPort) {
private DebugContext(IControllableServerBehavior behaviour, String devmodeKey, String debugPortKey, String debugPort) {
this.behaviour = behaviour;
this.devmodeKey = devmodeKey;
this.debugPortKey = debugPortKey;
this.debugPort = getDebugPort(debugPort);
}

public OpenShiftServerBehaviour getServerBehaviour() {
public IControllableServerBehavior getServerBehaviour() {
return behaviour;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;

import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
Expand All @@ -25,9 +24,9 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.wst.server.core.IServer;
import org.jboss.ide.eclipse.as.wtp.core.server.behavior.IControllableServerBehavior;
import org.jboss.tools.openshift.common.core.connection.ConnectionsRegistrySingleton;
import org.jboss.tools.openshift.core.connection.Connection;
import org.jboss.tools.openshift.core.server.OpenShiftServerBehaviour;
import org.jboss.tools.openshift.core.server.OpenShiftServerUtils;
import org.jboss.tools.openshift.internal.core.server.debug.OpenShiftDebugMode;
import org.jboss.tools.openshift.internal.core.server.debug.OpenShiftDebugMode.DebugContext;
Expand All @@ -45,7 +44,7 @@
public class OpenShiftDebugModeTest {

private Connection connection;
private OpenShiftServerBehaviour serverBehaviour;
private IControllableServerBehavior serverBehaviour;
private IDeploymentConfig dc;
private IService service;
private DebugContext context;
Expand All @@ -58,11 +57,12 @@ public void setUp() throws CoreException, UnsupportedEncodingException, Malforme
ConnectionsRegistrySingleton.getInstance().add(connection);
this.service = ResourceMocks.PROJECT2_SERVICES[1];
this.dc = ResourceMocks.PROJECT2_DEPLOYMENTCONFIGS[1];
// IServer server = OpenShiftServerTestUtils.createOpenshift3Server("dummy", "", service, connection);
IServer server = OpenShiftServerTestUtils.mockServer(service, connection);
// this.serverBehaviour = OpenShiftServerTestUtils.mockServerBehaviour(service, connection);
this.serverBehaviour = spy(new OpenShiftServerBehaviour());
this.serverBehaviour = OpenShiftServerTestUtils.mockServerBehaviour(server);
// this.serverBehaviour = spy(new OpenShiftServerBehaviour());
// when(serverBehaviour.getServer()).thenReturn(server);
// this.context = OpenShiftDebugMode.createContext(serverBehaviour, "devmode", "debugPort", "42");
this.context = OpenShiftDebugMode.createContext(serverBehaviour, "devmode", "debugPort", "42");
// System.setProperty(NewPodDetectorJob.DEPLOYMENT_CONFIG_LISTENER_JOB_TIMEOUT_KEY, "2000");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

import org.eclipse.core.runtime.CoreException;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.IServerAttributes;
import org.eclipse.wst.server.core.IServerType;
import org.eclipse.wst.server.core.IServerWorkingCopy;
import org.eclipse.wst.server.core.ServerCore;
import org.jboss.ide.eclipse.as.wtp.core.server.behavior.IControllableServerBehavior;
import org.jboss.ide.eclipse.as.wtp.core.server.behavior.ServerProfileModel;
import org.jboss.tools.openshift.common.core.connection.ConnectionURL;
import org.jboss.tools.openshift.core.connection.Connection;
import org.jboss.tools.openshift.core.server.OpenShiftServerBehaviour;
import org.jboss.tools.openshift.core.connection.IOpenShiftConnection;
import org.jboss.tools.openshift.core.server.OpenShiftServerUtils;
import org.jboss.tools.openshift.core.util.OpenShiftResourceUniqueId;

Expand All @@ -46,17 +46,24 @@ public static void cleanup() {
}
}

public static IServer createOpenshift3Server(String name, String profile) throws CoreException {
public static IServer createOpenshift3Server(String name, String profile) throws CoreException, UnsupportedEncodingException, MalformedURLException {
return createOpenshift3Server(name, profile, null, null);
}

public static IServer createOpenshift3Server(String name, String profile, IService service, IOpenShiftConnection connection)
throws CoreException, UnsupportedEncodingException, MalformedURLException {
IServerType type = OpenShiftServerUtils.getServerType();
IServerWorkingCopy wc = type.createServer(name, null, null);
String serviceId = service == null? null : OpenShiftResourceUniqueId.get(service);
String connectionUrl = connection == null? null : ConnectionURL.forConnection(connection).getUrl();
OpenShiftServerUtils.updateServer(
name, "http://www.example.com", "dummy", "dummy", "dummy", "dummy", "dummy", "dummy", "dummy", "dummy", "dummy", wc);
name, "http://www.example.com", "dummy", connectionUrl, "dummy", serviceId, "dummy", "dummy", "dummy", "dummy", "dummy", wc);
if (profile != null) {
ServerProfileModel.setProfile(wc, profile);
}
return wc.save(false, null);
}

public static IServer mockServer(IService service, Connection connection)
throws UnsupportedEncodingException, MalformedURLException {
IServer server = mock(IServer.class);
Expand All @@ -67,11 +74,9 @@ public static IServer mockServer(IService service, Connection connection)
return server;
}

public static OpenShiftServerBehaviour mockServerBehaviour(IServerAttributes server) {
OpenShiftServerBehaviour behaviour = mock(OpenShiftServerBehaviour.class);
public static IControllableServerBehavior mockServerBehaviour(IServer server) {
IControllableServerBehavior behaviour = mock(IControllableServerBehavior.class);
doReturn(server).when(behaviour).getServer();
return behaviour;
}


}

0 comments on commit 5411924

Please sign in to comment.