Skip to content

Commit

Permalink
#1007 Do not bind session as a side effect when removing pages (#1008)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Martin Grigorov <[email protected]>
Co-authored-by: Maxim Solodovnik <[email protected]>
  • Loading branch information
3 people authored Aug 22, 2024
1 parent cc03efd commit 1d780e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,7 @@ public SessionQuotaManagingDataStore(IPageStore delegate, Bytes maxBytes)

private SessionData getSessionData(IPageContext context, boolean create)
{
return context.getSessionData(KEY, () -> {
if (create)
{
return dataCreator.get();
}

return null;
});
return context.getSessionData(KEY, create ? dataCreator : null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.wicketstuff.datastores.common;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

import org.apache.wicket.MetaDataKey;
import org.apache.wicket.mock.MockPageContext;
import org.apache.wicket.mock.MockPageStore;
import org.apache.wicket.pageStore.IPageContext;
Expand Down Expand Up @@ -97,7 +100,19 @@ public void removePage() {
}

@Test
void addPageDoesNotRemovePageFromDelegate() {
public void removePageShouldNotSupplyDefaultValueWhenGettingSessionData() {
MockPageStore delegate = new MockPageStore();

IPageContext context = mock(IPageContext.class);

IPageStore quotaStore = new SessionQuotaManagingDataStore(delegate, Bytes.bytes(page1.getData().length + page3.getData().length));
quotaStore.removePage(context, page1);

verify(context).getSessionData(any(MetaDataKey.class), eq(null));
}

@Test
void addPageDoesNotRemovePageFromDelegate() {
IPageStore delegate = mock(IPageStore.class);

IPageContext context = new MockPageContext();
Expand Down

0 comments on commit 1d780e9

Please sign in to comment.