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;
}
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);
}
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");
}
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);
}
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;
}
Aggregations