This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new 180e77aa11 Add a test case that confirms a SpotBugs warning is a false
positive
180e77aa11 is described below
commit 180e77aa119bc81016eeb242ca67508965046c99
Author: Mark Thomas <[email protected]>
AuthorDate: Thu Feb 16 15:59:59 2023 +0000
Add a test case that confirms a SpotBugs warning is a false positive
---
.../catalina/ha/session/TestDeltaRequest.java | 73 ++++++++++++++++++++++
1 file changed, 73 insertions(+)
diff --git a/test/org/apache/catalina/ha/session/TestDeltaRequest.java
b/test/org/apache/catalina/ha/session/TestDeltaRequest.java
new file mode 100644
index 0000000000..ba4e874e6f
--- /dev/null
+++ b/test/org/apache/catalina/ha/session/TestDeltaRequest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.catalina.ha.session;
+
+import java.io.ByteArrayInputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.catalina.Manager;
+import org.apache.catalina.session.StandardManager;
+import org.apache.tomcat.unittest.TesterContext;
+import org.apache.tomcat.util.http.fileupload.ByteArrayOutputStream;
+
+public class TestDeltaRequest {
+
+ /*
+ * Mostly interested in whether the attributes transfer correctly as the
AttributeInfo class does not have a public
+ * no-arg constructor. This shouldn't be necessary for a package private
class (CheckStyle flags the use of a public
+ * modifier as redundant) but SpotBugs complains as the class implements
Externalizable. The purpose of this test is
+ * to confirm that the SpotBugs warning is a false positive.
+ */
+ @Test
+ public void testSerialization() throws Exception {
+ // Create original request
+ DeltaRequest original = new DeltaRequest();
+ original.setSessionId("1234");
+ original.setAttribute("A", "One");
+ original.setAttribute("B", "Two");
+
+ // Seralize original request
+ byte[] bytes;
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos)) {
+ oos.writeObject(original);
+ bytes = baos.toByteArray();
+ }
+
+ // Deserialize original request
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ DeltaRequest copyRequest = (DeltaRequest) ois.readObject();
+
+ // Apply DeltaRequest so we can test that the attributes transferred
correctly
+ DeltaSession copySession = new DeltaSession();
+ Manager manager = new StandardManager();
+ manager.setContext(new TesterContext());
+ copySession.setManager(manager);
+ copySession.setId("1234", false);
+ copySession.setValid(true);
+ copyRequest.execute(copySession, false);
+
+ // Test for the attributes
+ Assert.assertEquals("One", copySession.getAttribute("A"));
+ Assert.assertEquals("Two", copySession.getAttribute("B"));
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]