-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix rendering of TreeGrid's frozen columns after hierarchy-column reset (#12028) * Add tests * Fix getVisibleFrozenColumnCount() if SelectionMode is multi * Update ComboBox popup position comparison to use correct top value. (#12041) Fixes #12029 * Clear thread local instances on connection lost in push handler (#12042) Adopted from vaadin/flow#8567 Co-authored-by: Tarek Oraby <42799254+tarekoraby@users.noreply.github.com> Co-authored-by: Anna Koskinen <Ansku@users.noreply.github.com> Co-authored-by: Tatu Lund <tatu@vaadin.com>
- Loading branch information
1 parent
d1b3a39
commit 89dfd79
Showing
11 changed files
with
337 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
server/src/test/java/com/vaadin/server/MockVaadinServletService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2000-2020 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.server; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import javax.servlet.ServletException; | ||
|
||
import com.vaadin.tests.util.MockDeploymentConfiguration; | ||
|
||
/** | ||
* | ||
* @author Vaadin Ltd | ||
*/ | ||
public class MockVaadinServletService extends VaadinServletService { | ||
|
||
public MockVaadinServletService() throws ServiceException { | ||
this(new MockDeploymentConfiguration()); | ||
} | ||
|
||
public MockVaadinServletService( | ||
DeploymentConfiguration deploymentConfiguration) throws ServiceException { | ||
this(new VaadinServlet(), deploymentConfiguration); | ||
} | ||
|
||
public MockVaadinServletService(VaadinServlet servlet, | ||
DeploymentConfiguration deploymentConfiguration) throws ServiceException { | ||
super(servlet, deploymentConfiguration); | ||
|
||
try { | ||
servlet.init(new MockServletConfig()); | ||
} catch (ServletException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
protected List<RequestHandler> createRequestHandlers() | ||
throws ServiceException { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public void init() { | ||
try { | ||
super.init(); | ||
} catch (ServiceException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
server/src/test/java/com/vaadin/server/communication/PushHandlerTest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2000-2020 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.server.communication; | ||
|
||
import java.util.concurrent.Future; | ||
|
||
import org.atmosphere.cpr.AtmosphereRequest; | ||
import org.atmosphere.cpr.AtmosphereResource; | ||
import org.atmosphere.cpr.AtmosphereResourceEvent; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
import com.vaadin.server.MockVaadinServletService; | ||
import com.vaadin.server.MockVaadinSession; | ||
import com.vaadin.server.ServiceException; | ||
import com.vaadin.server.SessionExpiredException; | ||
import com.vaadin.server.VaadinRequest; | ||
import com.vaadin.server.VaadinSession; | ||
import com.vaadin.ui.UI; | ||
|
||
public class PushHandlerTest { | ||
|
||
MockVaadinSession session = null; | ||
|
||
@Test | ||
public void connectionLost_currentInstancesAreCleared() | ||
throws SessionExpiredException, ServiceException { | ||
session = new MockVaadinSession() { | ||
@Override | ||
public Future<Void> access(Runnable runnable) { | ||
runnable.run(); | ||
return Mockito.mock(Future.class); | ||
} | ||
}; | ||
VaadinSession.setCurrent(session); | ||
Assert.assertNotNull(VaadinSession.getCurrent()); | ||
MockVaadinServletService service = null; | ||
service = new MockVaadinServletService() { | ||
@Override | ||
public com.vaadin.server.VaadinSession findVaadinSession( | ||
VaadinRequest request) throws SessionExpiredException { | ||
return session; | ||
} | ||
|
||
@Override | ||
public UI findUI(VaadinRequest request) { | ||
return null; | ||
} | ||
}; | ||
|
||
service.init(); | ||
PushHandler handler = new PushHandler(service); | ||
|
||
AtmosphereResource resource = Mockito.mock(AtmosphereResource.class); | ||
AtmosphereRequest request = Mockito.mock(AtmosphereRequest.class); | ||
Mockito.when(resource.getRequest()).thenReturn(request); | ||
|
||
AtmosphereResourceEvent event = Mockito | ||
.mock(AtmosphereResourceEvent.class); | ||
Mockito.when(event.getResource()).thenReturn(resource); | ||
handler.connectionLost(event); | ||
|
||
Assert.assertNull(VaadinSession.getCurrent()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridChangeHierarchyColumn.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.vaadin.tests.components.treegrid; | ||
|
||
import com.vaadin.data.TreeData; | ||
import com.vaadin.server.VaadinRequest; | ||
import com.vaadin.tests.components.AbstractTestUI; | ||
import com.vaadin.ui.Button; | ||
import com.vaadin.ui.Component; | ||
import com.vaadin.ui.CssLayout; | ||
import com.vaadin.ui.Grid; | ||
import com.vaadin.ui.Label; | ||
import com.vaadin.ui.TreeGrid; | ||
|
||
public class TreeGridChangeHierarchyColumn extends AbstractTestUI { | ||
|
||
@Override | ||
protected String getTestDescription() { | ||
return "TreeGrid in MultiSelect mode should take hiden columns into account when" | ||
+ " rendering frozen columns after hierarchy-column reset."; | ||
} | ||
|
||
@Override | ||
protected Integer getTicketNumber() { | ||
return 12026; | ||
} | ||
|
||
@Override | ||
protected void setup(VaadinRequest request) { | ||
TreeGrid<String> treeGrid = new TreeGrid<>(); | ||
treeGrid.setId("TreeGrid"); | ||
|
||
for (int i = 0; i < 20; i++) { | ||
String columnId = String.valueOf(i); | ||
Grid.Column<String, Component> column = addColumn(treeGrid, | ||
columnId); | ||
column.setCaption(columnId); | ||
column.setId(columnId); | ||
} | ||
|
||
TreeData<String> data = treeGrid.getTreeData(); | ||
data.addItem(null, "child"); | ||
data.addItem("child", "grandChild"); | ||
|
||
treeGrid.setHierarchyColumn(treeGrid.getColumns().get(0)); | ||
|
||
Button hideHierCol = new Button("Hide Hierarchy Column"); | ||
hideHierCol.addClickListener(e -> { | ||
treeGrid.getHierarchyColumn().setHidden(true); | ||
}); | ||
hideHierCol.setId("hideHierColButton"); | ||
|
||
Button setHierCol = new Button("Set new Hierarchy Column"); | ||
setHierCol.addClickListener(e -> { | ||
treeGrid.getColumns().stream().filter(column -> !column.isHidden()) | ||
.findFirst().ifPresent(col -> { | ||
treeGrid.setHierarchyColumn(col.getId()); | ||
}); | ||
}); | ||
setHierCol.setId("setHierColButton"); | ||
|
||
treeGrid.setSelectionMode(Grid.SelectionMode.MULTI); | ||
treeGrid.setFrozenColumnCount(1); | ||
|
||
addComponents(treeGrid, hideHierCol, setHierCol); | ||
} | ||
|
||
private Grid.Column<String, Component> addColumn(Grid<String> grid, | ||
String columnId) { | ||
return grid.addComponentColumn(val -> { | ||
Label label = new Label(columnId); | ||
label.setWidth(50, Unit.PIXELS); | ||
return new CssLayout(label); | ||
}); | ||
} | ||
|
||
} |
Oops, something went wrong.