You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2024/07/30 07:02:51 UTC
(wicket) branch wicket-9.x updated: WICKET-7119 fixed non-idempotent unit tests (#929)
This is an automated email from the ASF dual-hosted git repository.
mgrigorov pushed a commit to branch wicket-9.x
in repository https://gitbox.apache.org/repos/asf/wicket.git
The following commit(s) were added to refs/heads/wicket-9.x by this push:
new dfa5713f9c WICKET-7119 fixed non-idempotent unit tests (#929)
dfa5713f9c is described below
commit dfa5713f9c60d76fb78d68c41df982236315488f
Author: Kaiyao Ke <47...@users.noreply.github.com>
AuthorDate: Tue Jul 30 14:45:17 2024 +0800
WICKET-7119 fixed non-idempotent unit tests (#929)
(cherry picked from commit 1a55391e77e3bc6951a59ac99c6bf23c8b66d40b)
---
.../apache/wicket/ComponentOnConfigureTest.java | 11 ++
.../markup/repeater/AbstractPageableViewTest.java | 199 +++++++++++----------
.../pageStore/AbstractPersistentPageStoreTest.java | 2 +
.../resource/FileSystemResourceReferenceTest.java | 14 +-
.../org/apache/wicket/util/string/Strings.java | 4 +-
.../org/apache/wicket/util/string/StringsTest.java | 3 +-
6 files changed, 133 insertions(+), 100 deletions(-)
diff --git a/wicket-core/src/test/java/org/apache/wicket/ComponentOnConfigureTest.java b/wicket-core/src/test/java/org/apache/wicket/ComponentOnConfigureTest.java
index f1f80aeea3..b6e3444e05 100644
--- a/wicket-core/src/test/java/org/apache/wicket/ComponentOnConfigureTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/ComponentOnConfigureTest.java
@@ -28,6 +28,7 @@ import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.util.resource.IResourceStream;
import org.apache.wicket.util.resource.StringResourceStream;
import org.apache.wicket.util.tester.WicketTestCase;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
@@ -41,6 +42,16 @@ class ComponentOnConfigureTest extends WicketTestCase
private static final AtomicInteger BEHAVIOR = new AtomicInteger(0);
private static final AtomicInteger APPLICATION_LISTENER = new AtomicInteger(0);
+ @BeforeEach
+ void resetCounters()
+ {
+ COUNTER.set(0);
+ PAGE.set(0);
+ COMPONENT.set(0);
+ BEHAVIOR.set(0);
+ APPLICATION_LISTENER.set(0);
+ }
+
/**
* testOrder()
*/
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/repeater/AbstractPageableViewTest.java b/wicket-core/src/test/java/org/apache/wicket/markup/repeater/AbstractPageableViewTest.java
index 36af146512..b85aff8816 100644
--- a/wicket-core/src/test/java/org/apache/wicket/markup/repeater/AbstractPageableViewTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/repeater/AbstractPageableViewTest.java
@@ -1,97 +1,104 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.wicket.markup.repeater;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.model.Model;
-import org.apache.wicket.util.tester.WicketTestCase;
-import org.junit.jupiter.api.Test;
-
-/**
- * Test for {@link AbstractPageableView}.
- */
-public class AbstractPageableViewTest extends WicketTestCase
-{
- private static int count = 5;
-
- /**
- */
- @Test
- public void cachedItemCount()
- {
- View view = new View("f");
-
- assertEquals(5, view.getItemCount());
-
- count = 6;
-
- assertEquals(5, view.getItemCount(), "still 5 cached");
-
- view.beforeRender();
-
- assertEquals(6, view.getItemCount(), "cached cleared before render");
-
- byte[] bytes = tester.getApplication().getFrameworkSettings().getSerializer().serialize(view);
-
- view = (View)tester.getApplication().getFrameworkSettings().getSerializer().deserialize(bytes);
-
- count = 7;
-
- assertEquals(7, view.getItemCount(), "cached cleared when deserialized");
-
- view.detach();
-
- count = 8;
-
- assertEquals(8, view.getItemCount(), "cached cleared when detached");
- }
-
- static class View extends AbstractPageableView<Integer>
- {
- public View(String id)
- {
- super(id);
- }
-
- @Override
- protected void populateItem(Item<Integer> item)
- {
- }
-
- @Override
- protected long internalGetItemCount()
- {
- return count;
- }
-
- @Override
- protected Iterator<IModel<Integer>> getItemModels(long offset, long size)
- {
- List<IModel<Integer>> models = new ArrayList<>();
- for (int m = 0; m < count; m++) {
- models.add(Model.of(m));
- }
- return models.iterator();
- }
- }
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.wicket.markup.repeater;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.util.tester.WicketTestCase;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test for {@link AbstractPageableView}.
+ */
+public class AbstractPageableViewTest extends WicketTestCase
+{
+ private static int count = 5;
+
+ @BeforeEach
+ public void resetCount()
+ {
+ count = 5;
+ }
+
+ /**
+ */
+ @Test
+ public void cachedItemCount()
+ {
+ View view = new View("f");
+
+ assertEquals(5, view.getItemCount());
+
+ count = 6;
+
+ assertEquals(5, view.getItemCount(), "still 5 cached");
+
+ view.beforeRender();
+
+ assertEquals(6, view.getItemCount(), "cached cleared before render");
+
+ byte[] bytes = tester.getApplication().getFrameworkSettings().getSerializer().serialize(view);
+
+ view = (View)tester.getApplication().getFrameworkSettings().getSerializer().deserialize(bytes);
+
+ count = 7;
+
+ assertEquals(7, view.getItemCount(), "cached cleared when deserialized");
+
+ view.detach();
+
+ count = 8;
+
+ assertEquals(8, view.getItemCount(), "cached cleared when detached");
+ }
+
+ static class View extends AbstractPageableView<Integer>
+ {
+ public View(String id)
+ {
+ super(id);
+ }
+
+ @Override
+ protected void populateItem(Item<Integer> item)
+ {
+ }
+
+ @Override
+ protected long internalGetItemCount()
+ {
+ return count;
+ }
+
+ @Override
+ protected Iterator<IModel<Integer>> getItemModels(long offset, long size)
+ {
+ List<IModel<Integer>> models = new ArrayList<>();
+ for (int m = 0; m < count; m++) {
+ models.add(Model.of(m));
+ }
+ return models.iterator();
+ }
+ }
}
\ No newline at end of file
diff --git a/wicket-core/src/test/java/org/apache/wicket/pageStore/AbstractPersistentPageStoreTest.java b/wicket-core/src/test/java/org/apache/wicket/pageStore/AbstractPersistentPageStoreTest.java
index 783b8ec7df..82402d1ff2 100644
--- a/wicket-core/src/test/java/org/apache/wicket/pageStore/AbstractPersistentPageStoreTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/pageStore/AbstractPersistentPageStoreTest.java
@@ -88,6 +88,8 @@ class AbstractPersistentPageStoreTest
};
assertTrue(store.canBeAsynchronous(context));
+ store.destroy();
+
}
}
diff --git a/wicket-core/src/test/java/org/apache/wicket/resource/FileSystemResourceReferenceTest.java b/wicket-core/src/test/java/org/apache/wicket/resource/FileSystemResourceReferenceTest.java
index 0fa16f0c23..56b779b03c 100644
--- a/wicket-core/src/test/java/org/apache/wicket/resource/FileSystemResourceReferenceTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/resource/FileSystemResourceReferenceTest.java
@@ -23,7 +23,11 @@ import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
+import java.nio.file.FileSystem;
+import java.nio.file.FileSystems;
+import java.nio.file.FileSystemAlreadyExistsException;
import java.nio.file.Path;
+import java.util.Collections;
import org.apache.wicket.core.util.lang.WicketObjects;
import org.apache.wicket.util.io.ByteArrayOutputStream;
@@ -55,8 +59,14 @@ class FileSystemResourceReferenceTest extends WicketTestCase
try
{
URL resource = FileSystemResourceReferenceTest.class.getResource("FileSystemResourceReferenceTest.zip");
- Path path = FileSystemResourceReference.getPath(URI.create("jar:" + resource.toURI() +
- "!/folderInZip/FileSystemResourceReference.txt"));
+ URI uri = URI.create("jar:" + resource.toURI() + "!/folderInZip/FileSystemResourceReference.txt");
+ FileSystem fs = null;
+ try {
+ fs = FileSystems.newFileSystem(uri, Collections.emptyMap());
+ } catch (FileSystemAlreadyExistsException e) {
+ fs = FileSystems.getFileSystem(uri);
+ }
+ Path path = fs.getPath("/folderInZip/FileSystemResourceReference.txt");
final FileSystemResource fileSystemResource = new FileSystemResource(path);
FileSystemResourceReference fileSystemResourceReference = new FileSystemResourceReference(
"test", path)
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java b/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java
index c9cc541179..d367b1bf18 100755
--- a/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java
@@ -77,7 +77,9 @@ public final class Strings
* Constructs something like <em>;jsessionid=</em>. This is what {@linkplain Strings#stripJSessionId(String)}
* actually uses.
*/
- private static final String SESSION_ID_PARAM = ';' + SESSION_ID_PARAM_NAME + '=';
+ // the field is not 'final' because we need to modify it in a unit test
+ // see https://github.com/openjdk/jdk/pull/5027#issuecomment-968177213
+ private static String SESSION_ID_PARAM = ';' + SESSION_ID_PARAM_NAME + '=';
/**
* Private constructor prevents construction.
diff --git a/wicket-util/src/test/java/org/apache/wicket/util/string/StringsTest.java b/wicket-util/src/test/java/org/apache/wicket/util/string/StringsTest.java
index 2f0f851e41..4f24f88087 100644
--- a/wicket-util/src/test/java/org/apache/wicket/util/string/StringsTest.java
+++ b/wicket-util/src/test/java/org/apache/wicket/util/string/StringsTest.java
@@ -57,6 +57,7 @@ class StringsTest
sessionIdParamField.setAccessible(true);
Field modifiersField = getModifiersField();
modifiersField.setAccessible(true);
+ String origSessionIdParam = (String) sessionIdParamField.get(null);
try {
final String customSessionIdParam = ";Custom seSsion - ид=";
modifiersField.setInt(sessionIdParamField, sessionIdParamField.getModifiers() & ~Modifier.FINAL );
@@ -64,7 +65,7 @@ class StringsTest
assertEquals(url + ";a=b;c=d?param=a;b",
Strings.stripJSessionId(url + ";a=b;c=d" + customSessionIdParam + "12345?param=a;b"));
} finally {
- sessionIdParamField.set(null, "jsessionid");
+ sessionIdParamField.set(null, origSessionIdParam);
modifiersField.setInt(sessionIdParamField, sessionIdParamField.getModifiers() & Modifier.FINAL );
modifiersField.setAccessible(false);
sessionIdParamField.setAccessible(false);