Search in sources :

Example 1 with IConnectionWrapper

use of org.jboss.tools.openshift.internal.ui.models.IConnectionWrapper in project jbosstools-openshift by jbosstools.

the class RefreshTest method testRefreshConnection.

@Test
public void testRefreshConnection() throws InterruptedException, TimeoutException {
    IProject project1 = stubProject("test1", 1);
    IProject project2 = stubProject("test2", 1);
    IProject project2prime = stubProject("test2", 2);
    when(getConnectionMock().getResources(ResourceKind.PROJECT)).thenReturn(Collections.singletonList(project1));
    IConnectionWrapper connection = getConnection();
    getConnection().load(IExceptionHandler.NULL_HANDLER);
    UITestUtils.waitForState(connection, LoadingState.LOADED);
    assertEquals(1, connection.getResources().size());
    assertTrue(connection.getResources().stream().anyMatch(projectWrapper -> project1.equals(projectWrapper.getWrapped())));
    registry.fireConnectionChanged(getConnectionMock(), ConnectionProperties.PROPERTY_PROJECTS, null, Arrays.asList(project1, project2));
    verify(listener).elementChanged(connection);
    assertEquals(2, connection.getResources().size());
    assertTrue(connection.getResources().stream().anyMatch(projectWrapper -> project1.equals(projectWrapper.getWrapped())));
    assertTrue(connection.getResources().stream().anyMatch(projectWrapper -> project2.equals(projectWrapper.getWrapped())));
    registry.fireConnectionChanged(getConnectionMock(), ConnectionProperties.PROPERTY_PROJECTS, null, Arrays.asList(project2));
    verify(listener, times(2)).elementChanged(connection);
    assertEquals(1, connection.getResources().size());
    Optional<IResourceWrapper<?, ?>> project2Wrapper = connection.getResources().stream().filter(projectWrapper -> project2.equals(projectWrapper.getWrapped())).findFirst();
    assertTrue(project2Wrapper.isPresent());
    registry.fireConnectionChanged(getConnectionMock(), ConnectionProperties.PROPERTY_PROJECTS, null, Arrays.asList(project2prime));
    verify(listener, times(2)).elementChanged(connection);
    verify(listener).elementChanged(project2Wrapper.get());
    assertEquals(1, connection.getResources().size());
    assertTrue(connection.getResources().stream().anyMatch(projectWrapper -> {
        IResource resource = projectWrapper.getWrapped();
        String version = resource.getResourceVersion();
        return project2.equals(resource) && version.equals("2");
    }));
}
Also used : Arrays(java.util.Arrays) Proxy(java.lang.reflect.Proxy) TimeoutException(java.util.concurrent.TimeoutException) IConnectionWrapper(org.jboss.tools.openshift.internal.ui.models.IConnectionWrapper) IProject(com.openshift.restclient.model.IProject) IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) UITestUtils(org.jboss.tools.openshift.test.util.UITestUtils) ConnectionsRegistry(org.jboss.tools.openshift.common.core.connection.ConnectionsRegistry) Before(org.junit.Before) LoadingState(org.jboss.tools.openshift.internal.ui.models.LoadingState) IResource(com.openshift.restclient.model.IResource) ResourceKind(com.openshift.restclient.ResourceKind) ConnectionProperties(org.jboss.tools.openshift.core.connection.ConnectionProperties) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) OpenshiftUIModel(org.jboss.tools.openshift.internal.ui.models.OpenshiftUIModel) IExceptionHandler(org.jboss.tools.openshift.internal.ui.models.IExceptionHandler) Mockito.verify(org.mockito.Mockito.verify) IOpenShiftConnection(org.jboss.tools.openshift.core.connection.IOpenShiftConnection) Optional(java.util.Optional) IElementListener(org.jboss.tools.openshift.internal.ui.models.IElementListener) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) IConnectionWrapper(org.jboss.tools.openshift.internal.ui.models.IConnectionWrapper) IProject(com.openshift.restclient.model.IProject) IResource(com.openshift.restclient.model.IResource) Test(org.junit.Test)

Aggregations

ResourceKind (com.openshift.restclient.ResourceKind)1 IProject (com.openshift.restclient.model.IProject)1 IResource (com.openshift.restclient.model.IResource)1 Proxy (java.lang.reflect.Proxy)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Optional (java.util.Optional)1 TimeoutException (java.util.concurrent.TimeoutException)1 ConnectionsRegistry (org.jboss.tools.openshift.common.core.connection.ConnectionsRegistry)1 ConnectionProperties (org.jboss.tools.openshift.core.connection.ConnectionProperties)1 IOpenShiftConnection (org.jboss.tools.openshift.core.connection.IOpenShiftConnection)1 IConnectionWrapper (org.jboss.tools.openshift.internal.ui.models.IConnectionWrapper)1 IElementListener (org.jboss.tools.openshift.internal.ui.models.IElementListener)1 IExceptionHandler (org.jboss.tools.openshift.internal.ui.models.IExceptionHandler)1 IResourceWrapper (org.jboss.tools.openshift.internal.ui.models.IResourceWrapper)1 LoadingState (org.jboss.tools.openshift.internal.ui.models.LoadingState)1 OpenshiftUIModel (org.jboss.tools.openshift.internal.ui.models.OpenshiftUIModel)1 UITestUtils (org.jboss.tools.openshift.test.util.UITestUtils)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertTrue (org.junit.Assert.assertTrue)1