Search in sources :

Example 1 with IRoute

use of com.openshift.restclient.model.route.IRoute in project jbosstools-openshift by jbosstools.

the class OpenShiftDebugModeTest method createRouteFor.

/**
 * Returns a route that points to a service, that's related to the given deployment config.
 * Creating the route it will stub 2 services and 2 routes to the given connection.
 *
 * @param dc to create a route for
 * @param connection to create the route, services and routes in
 * @return
 */
private IRoute createRouteFor(IDeploymentConfig dc, IProject project, Connection connection) {
    @SuppressWarnings("serial") Map<String, String> selectors = new HashMap<String, String>() {

        {
            put("aSelector", "42");
        }
    };
    doReturn(selectors).when(dc).getReplicaSelector();
    // doesnt match dc
    IService service1 = createService("service1", project, new HashMap<String, String>());
    // matches dc
    IService service2 = createService("service2", project, selectors);
    when(connection.getResources(ResourceKind.SERVICE, project.getNamespaceName())).thenReturn(Arrays.asList(service1, service2));
    // matches inexistent service
    IRoute route1 = createRoute("route1", project, "service42");
    // matches service2
    IRoute route2 = createRoute("route2", project, "service2");
    when(connection.getResources(ResourceKind.ROUTE, project.getNamespaceName())).thenReturn(Arrays.asList(route1, route2));
    return route2;
}
Also used : HashMap(java.util.HashMap) IRoute(com.openshift.restclient.model.route.IRoute) Matchers.anyString(org.mockito.Matchers.anyString) IService(com.openshift.restclient.model.IService)

Example 2 with IRoute

use of com.openshift.restclient.model.route.IRoute in project jbosstools-openshift by jbosstools.

the class OpenShiftDebugModeTest method shouldRestoreRouteTimeoutThatExistedBeforeDebugging.

@Test
public void shouldRestoreRouteTimeoutThatExistedBeforeDebugging() throws CoreException {
    // given
    IRoute route = createRouteFor(dc, project, connection);
    doReturn("4242").when(server).getAttribute(OpenShiftServerUtils.ATTR_DEBUG_ROUTE_TIMEOUT, (String) null);
    context.setDebugEnabled(false);
    // when
    debugMode.execute(new NullProgressMonitor());
    // then
    verify(route, atLeastOnce()).setAnnotation(eq(OpenShiftAPIAnnotations.TIMEOUT), eq("4242"));
    // send updated route
    verify(debugMode, atLeastOnce()).send(eq(route), eq(connection), any(IProgressMonitor.class));
    // clear backup
    verify(serverWorkingCopy).setAttribute(OpenShiftServerUtils.ATTR_DEBUG_ROUTE_TIMEOUT, (String) null);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IRoute(com.openshift.restclient.model.route.IRoute) Test(org.junit.Test)

Example 3 with IRoute

use of com.openshift.restclient.model.route.IRoute in project jbosstools-openshift by jbosstools.

the class OpenShiftDebugModeTest method shouldReplaceRouteTimeoutIfCustomTimeoutExistAlready.

@Test
public void shouldReplaceRouteTimeoutIfCustomTimeoutExistAlready() throws CoreException {
    // given
    IRoute route = createRouteFor(dc, project, connection);
    doReturn("4242").when(route).getAnnotation(eq(OpenShiftAPIAnnotations.TIMEOUT));
    context.setDebugEnabled(true);
    // when
    debugMode.execute(new NullProgressMonitor());
    // then
    verify(route, atLeastOnce()).setAnnotation(eq(OpenShiftAPIAnnotations.TIMEOUT), anyString());
    // send updated dc
    verify(debugMode, atLeastOnce()).send(eq(route), eq(connection), any(IProgressMonitor.class));
    // backup stored
    verify(serverWorkingCopy).setAttribute(OpenShiftServerUtils.ATTR_DEBUG_ROUTE_TIMEOUT, "4242");
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IRoute(com.openshift.restclient.model.route.IRoute) Test(org.junit.Test)

Example 4 with IRoute

use of com.openshift.restclient.model.route.IRoute in project jbosstools-openshift by jbosstools.

the class OpenShiftDebugModeTest method shouldNotAddRouteTimeoutIfExistAlready.

@Test
public void shouldNotAddRouteTimeoutIfExistAlready() throws CoreException {
    // given
    IRoute route = createRouteFor(dc, project, connection);
    doReturn(RouteTimeout.ROUTE_DEBUG_TIMEOUT).when(route).getAnnotation(eq(OpenShiftAPIAnnotations.TIMEOUT));
    context.setDebugEnabled(true);
    // when
    debugMode.execute(new NullProgressMonitor());
    // then
    verify(route, never()).setAnnotation(eq(OpenShiftAPIAnnotations.TIMEOUT), anyString());
    // dont send updated dc
    verify(debugMode, never()).send(eq(route), eq(connection), any(IProgressMonitor.class));
    // store backup
    verify(serverWorkingCopy).setAttribute(OpenShiftServerUtils.ATTR_DEBUG_ROUTE_TIMEOUT, RouteTimeout.ROUTE_DEBUG_TIMEOUT);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IRoute(com.openshift.restclient.model.route.IRoute) Test(org.junit.Test)

Example 5 with IRoute

use of com.openshift.restclient.model.route.IRoute in project jbosstools-openshift by jbosstools.

the class DeployImageJob method stubRoute.

private IResource stubRoute(IResourceFactory factory, String name, String serviceName) {
    IRoute route = factory.stub(ResourceKind.ROUTE, name, parameters.getProject().getName());
    route.setServiceName(serviceName);
    String hostname = parameters.getRouteHostname();
    if (StringUtils.isNotBlank(hostname)) {
        route.setHost(hostname);
    }
    IServicePort port = parameters.getRoutingPort();
    if (port != null) {
        ITargetPort targetPort = route.createPort();
        if (port.getName() != null) {
            targetPort.setTargetPortName(port.getName());
        } else {
            targetPort.setTargetPort(port.getPort());
        }
    }
    return route;
}
Also used : IServicePort(com.openshift.restclient.model.IServicePort) ITargetPort(com.openshift.restclient.model.route.ITargetPort) IRoute(com.openshift.restclient.model.route.IRoute)

Aggregations

IRoute (com.openshift.restclient.model.route.IRoute)34 Test (org.junit.Test)15 IService (com.openshift.restclient.model.IService)10 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 List (java.util.List)6 ResourceKind (com.openshift.restclient.ResourceKind)5 Connection (org.jboss.tools.openshift.core.connection.Connection)5 IProject (com.openshift.restclient.model.IProject)4 IResource (com.openshift.restclient.model.IResource)4 Collection (java.util.Collection)4 CoreException (org.eclipse.core.runtime.CoreException)4 NLS (org.eclipse.osgi.util.NLS)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 AbstractHandler (org.eclipse.core.commands.AbstractHandler)3 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)3 ExecutionException (org.eclipse.core.commands.ExecutionException)3 IStatus (org.eclipse.core.runtime.IStatus)3 ISelection (org.eclipse.jface.viewers.ISelection)3