Search in sources :

Example 71 with IResource

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

the class ConnectionTest method ownsResource_should_return_false_when_clients_are_different.

@Test
public void ownsResource_should_return_false_when_clients_are_different() {
    IClient diffClient = mock(IClient.class);
    Map<String, Object> mocks = givenAResourceThatAcceptsAVisitorForIClientCapability(diffClient);
    assertFalse(connection.ownsResource((IResource) mocks.get("resource")));
}
Also used : IClient(com.openshift.restclient.IClient) Matchers.anyString(org.mockito.Matchers.anyString) IResource(com.openshift.restclient.model.IResource) Test(org.junit.Test)

Example 72 with IResource

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

the class OpenInWebConsoleHandlerTest method test.

@Theory
public void test(DataPair dataPair) {
    IResource resourceMock = dataPair.getResource();
    if (resourceMock != null) {
        when(resourceMock.getNamespaceName()).thenReturn("namespace");
        when(resourceMock.getName()).thenReturn("qwerty");
        when(resourceMock.getLabels()).thenReturn(new HashMap<String, String>() {

            {
                put("buildconfig", "label");
            }
        });
    }
    assertEquals(dataPair.getExpected(), handlerMock.getWebConsoleUrl(connectionMock, resourceMock));
}
Also used : IResource(com.openshift.restclient.model.IResource) Theory(org.junit.experimental.theories.Theory)

Example 73 with IResource

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

the class ServerResourceViewModelWithDeploymentConfigTest method shouldReturnNewSelectedDeploymentConfigIfLoadResourcesWithConnection.

@Test
public void shouldReturnNewSelectedDeploymentConfigIfLoadResourcesWithConnection() {
    // given
    IResource selectedDeploymentConfig = model.getResource();
    Connection connection = ResourceMocks.createConnection("https://localhost:8181", "ops@42.org");
    ConnectionsRegistrySingleton.getInstance().add(connection);
    try {
        IProject project = ResourceMocks.createResource(IProject.class, ResourceKind.PROJECT);
        when(connection.getResources(ResourceKind.PROJECT)).thenReturn(Collections.singletonList(project));
        IDeploymentConfig deploymentConfig = ResourceMocks.createResource(IDeploymentConfig.class, ResourceKind.DEPLOYMENT_CONFIG);
        when(project.getResources(ResourceKind.DEPLOYMENT_CONFIG)).thenReturn(Collections.singletonList(deploymentConfig));
        // when
        model.loadResources(connection);
        // then
        IResource newSelectedDeploymentConfig = model.getResource();
        assertThat(selectedDeploymentConfig).isNotEqualTo(newSelectedDeploymentConfig);
    } finally {
        ConnectionsRegistrySingleton.getInstance().remove(connection);
    }
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IResource(com.openshift.restclient.model.IResource) IProject(com.openshift.restclient.model.IProject) Test(org.junit.Test)

Example 74 with IResource

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

the class ServerResourceViewModelWithServiceTest method shouldReturnNewSelectedServiceIfLoadResourcesWithConnection.

@Test
public void shouldReturnNewSelectedServiceIfLoadResourcesWithConnection() {
    // given
    IResource selectedService = model.getResource();
    Connection connection = ResourceMocks.createConnection("https://localhost:8181", "ops@42.org");
    ConnectionsRegistrySingleton.getInstance().add(connection);
    try {
        IProject project = ResourceMocks.createResource(IProject.class, ResourceKind.PROJECT);
        when(connection.getResources(ResourceKind.PROJECT)).thenReturn(Collections.singletonList(project));
        IService service = ResourceMocks.createResource(IService.class, ResourceKind.SERVICE);
        when(project.getResources(ResourceKind.SERVICE)).thenReturn(Collections.singletonList(service));
        // when
        model.loadResources(connection);
        // then
        IResource newSelectedService = model.getResource();
        assertThat(selectedService).isNotEqualTo(newSelectedService);
    } finally {
        ConnectionsRegistrySingleton.getInstance().remove(connection);
    }
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) IResource(com.openshift.restclient.model.IResource) IProject(com.openshift.restclient.model.IProject) IService(com.openshift.restclient.model.IService) Test(org.junit.Test)

Example 75 with IResource

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

the class ServerResourceViewModelWithServiceTest method shouldReturn1stServiceInListIfInitializedServiceIsNotInListOfAllServices.

@Test
public void shouldReturn1stServiceInListIfInitializedServiceIsNotInListOfAllServices() {
    // given
    IService otherService = ResourceMocks.createResource(IService.class, ResourceKind.SERVICE);
    ServerResourceViewModel model = new ServerResourceViewModel(otherService, connection);
    model.loadResources();
    // when
    IResource service = model.getResource();
    // then
    assertThat(service).isEqualTo(ResourceMocks.PROJECT2_SERVICES[0]);
}
Also used : ServerResourceViewModel(org.jboss.tools.openshift.internal.ui.server.ServerResourceViewModel) IService(com.openshift.restclient.model.IService) IResource(com.openshift.restclient.model.IResource) Test(org.junit.Test)

Aggregations

IResource (com.openshift.restclient.model.IResource)101 Test (org.junit.Test)32 Connection (org.jboss.tools.openshift.core.connection.Connection)27 IProject (com.openshift.restclient.model.IProject)14 IStatus (org.eclipse.core.runtime.IStatus)12 Collection (java.util.Collection)10 ServerResourceViewModel (org.jboss.tools.openshift.internal.ui.server.ServerResourceViewModel)9 IReplicationController (com.openshift.restclient.model.IReplicationController)8 IService (com.openshift.restclient.model.IService)8 ArrayList (java.util.ArrayList)8 CoreException (org.eclipse.core.runtime.CoreException)8 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)7 Status (org.eclipse.core.runtime.Status)7 ISelection (org.eclipse.jface.viewers.ISelection)7 OpenShiftException (com.openshift.restclient.OpenShiftException)6 ResourceKind (com.openshift.restclient.ResourceKind)6 IPod (com.openshift.restclient.model.IPod)6 List (java.util.List)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 IBuildConfig (com.openshift.restclient.model.IBuildConfig)5