Search in sources :

Example 16 with IService

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();
}
Also used : IBuildConfig(com.openshift.restclient.model.IBuildConfig) IService(com.openshift.restclient.model.IService) Test(org.junit.Test)

Example 17 with IService

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();
}
Also used : IService(com.openshift.restclient.model.IService) Test(org.junit.Test)

Example 18 with IService

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();
}
Also used : IService(com.openshift.restclient.model.IService) Test(org.junit.Test)

Example 19 with IService

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();
}
Also used : KeyValueFilter(org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory.KeyValueFilter) IService(com.openshift.restclient.model.IService) Test(org.junit.Test)

Example 20 with IService

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;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OpenShiftException(com.openshift.restclient.OpenShiftException) Connection(org.jboss.tools.openshift.core.connection.Connection) IRoute(com.openshift.restclient.model.route.IRoute) IResource(com.openshift.restclient.model.IResource) IProject(com.openshift.restclient.model.IProject) IService(com.openshift.restclient.model.IService)

Aggregations

IService (com.openshift.restclient.model.IService)32 Test (org.junit.Test)15 Connection (org.jboss.tools.openshift.core.connection.Connection)10 IResource (com.openshift.restclient.model.IResource)9 IRoute (com.openshift.restclient.model.route.IRoute)8 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)6 IProject (com.openshift.restclient.model.IProject)5 ResourceKind (com.openshift.restclient.ResourceKind)4 IBuildConfig (com.openshift.restclient.model.IBuildConfig)4 IPod (com.openshift.restclient.model.IPod)4 IReplicationController (com.openshift.restclient.model.IReplicationController)4 Collection (java.util.Collection)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)3 CoreException (org.eclipse.core.runtime.CoreException)3 ResourceUtils (org.jboss.tools.openshift.internal.core.util.ResourceUtils)3 IClient (com.openshift.restclient.IClient)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2