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