use of com.openshift.restclient.model.IService in project jbosstools-openshift by jbosstools.
the class ResourceUtilsTest method testGetBuildConfigForService.
@Test
public void testGetBuildConfigForService() {
// given
// when
IBuildConfig matchingConfig = getBuildConfigFor(SERVICE_42, Arrays.asList(BUILDCONFIGS));
// then
assertThat(matchingConfig).isEqualTo(BUILDCONFIGS[1]);
// when
matchingConfig = getBuildConfigFor(SERVICE_42, null);
// then
assertThat(matchingConfig).isNull();
// when
matchingConfig = getBuildConfigFor((IService) null, Arrays.asList(BUILDCONFIGS));
// then
assertThat(matchingConfig).isNull();
// when
matchingConfig = getBuildConfigFor(ResourceMocks.createResource(IService.class, ResourceKind.SERVICE, config -> when(config.getName()).thenReturn("0")), Arrays.asList(BUILDCONFIGS));
// then
assertThat(matchingConfig).isNull();
}
use of com.openshift.restclient.model.IService in project jbosstools-openshift by jbosstools.
the class ResourceUtilsIsMatchingLabelsTest method shouldReturnEmptyLabelsMapIfFilterIsNullAndNoLabelsPresent.
@Test
public void shouldReturnEmptyLabelsMapIfFilterIsNullAndNoLabelsPresent() {
// given
IService service = ResourceMocks.createResource(IService.class, ResourceKind.SERVICE, resource -> {
doReturn(new HashMap<String, String>()).when(resource).getLabels();
});
// when
Map<String, String> labels = ResourceUtils.getMatchingLabels(null, service);
// then
assertThat(labels).isEmpty();
}
use of com.openshift.restclient.model.IService in project jbosstools-openshift by jbosstools.
the class ResourceUtilsIsMatchingLabelsTest method shouldMatchLabelsIfFilterIsNullAndNoLabelsExists.
@Test
public void shouldMatchLabelsIfFilterIsNullAndNoLabelsExists() {
// given
IService service = ResourceMocks.createResource(IService.class, ResourceKind.SERVICE, resource -> {
doReturn(new HashMap<String, String>()).when(resource).getLabels();
});
// when
boolean isMatching = ResourceUtils.hasMatchingLabels(null, service);
// then
assertThat(isMatching).isTrue();
}
use of com.openshift.restclient.model.IService in project jbosstools-openshift by jbosstools.
the class ResourceUtilsIsMatchingLabelsTest method emptyLabelResourceHasMatchingLabelsIfFilterIsEmptyNull.
@Test
public void emptyLabelResourceHasMatchingLabelsIfFilterIsEmptyNull() {
// given
IService service = ResourceMocks.createResource(IService.class, ResourceKind.SERVICE, resource -> {
doReturn(new HashMap<String, String>()).when(resource).getLabels();
});
assertThat(hasMatchingLabels(new KeyValueFilter(), service)).isTrue();
}
use of com.openshift.restclient.model.IService in project jbosstools-openshift by jbosstools.
the class OpenShiftServerExtendedProperties method getWelcomePageUrl.
@Override
public String getWelcomePageUrl() throws GetWelcomePageURLException {
String welcomePageUrl = null;
try {
// Get connection explicitly to report failure. Try and connect right now to know if it fails.
// Do not catch OpenShiftException, let it be reported. We are more concerned of NPE.
Connection connection = OpenShiftServerUtils.getConnection(server);
if (connection == null || !connection.connect()) {
throw new GetWelcomePageURLException("Connection is not established.");
}
IResource resource = OpenShiftServerUtils.getResource(server, connection, new NullProgressMonitor());
if (resource == null) {
throw new GetWelcomePageURLException("Resource is missing.");
}
IProject project = resource.getProject();
if ((project != null) && (resource instanceof IService)) {
List<IRoute> routes = ResourceUtils.getRoutesFor((IService) resource, project.getResources(ResourceKind.ROUTE));
IRoute route = getRoute(OpenShiftServerUtils.getRouteURL(server), routes);
if (route == null) {
route = getRoute(routes);
}
// Reporting route == null is implemented in getRoute.
if (route != null) {
welcomePageUrl = route.getURL();
}
}
} catch (OpenShiftException e) {
throw new GetWelcomePageURLException(e.getMessage(), e);
}
return welcomePageUrl;
}
Aggregations