This is an automated email from the ASF dual-hosted git repository. chibenwa pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit fd7a49549c32c9efff7f3ddb29a61cb591770fc2 Author: Quan Tran <[email protected]> AuthorDate: Mon Jul 13 22:58:40 2026 +0700 [BUILD] ThreadChangesContract: isolate using different users --- .../rfc8621/contract/ThreadChangesContract.scala | 31 +++++++++++++++++----- .../memory/MemoryThreadChangesMethodTest.java | 2 +- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/ThreadChangesContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/ThreadChangesContract.scala index 9527e84fb4..19157e28bb 100644 --- a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/ThreadChangesContract.scala +++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/ThreadChangesContract.scala @@ -19,30 +19,49 @@ package org.apache.james.jmap.rfc8621.contract +import java.nio.charset.StandardCharsets +import java.util.UUID + +import com.google.common.hash.Hashing import io.netty.handler.codec.http.HttpHeaderNames.ACCEPT import io.restassured.RestAssured.{`given`, requestSpecification} import io.restassured.http.ContentType.JSON import net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson import org.apache.http.HttpStatus.SC_OK import org.apache.james.GuiceJamesServer +import org.apache.james.core.Username import org.apache.james.jmap.core.ResponseObject.SESSION_STATE import org.apache.james.jmap.core.UuidState.INSTANCE import org.apache.james.jmap.http.UserCredential -import org.apache.james.jmap.rfc8621.contract.Fixture.{ACCEPT_RFC8621_VERSION_HEADER, BOB, BOB_PASSWORD, DOMAIN, authScheme, baseRequestSpecBuilder} +import org.apache.james.jmap.rfc8621.contract.Fixture.{ACCEPT_RFC8621_VERSION_HEADER, BOB_PASSWORD, DOMAIN, authScheme, baseRequestSpecBuilder} import org.apache.james.utils.DataProbeImpl import org.junit.jupiter.api.{BeforeEach, Test} +object ThreadChangesContract { + case class TestContext(bobUsername: Username, bobAccountId: String) + val currentContext: java.util.concurrent.atomic.AtomicReference[TestContext] = new java.util.concurrent.atomic.AtomicReference[TestContext]() +} + trait ThreadChangesContract { + import ThreadChangesContract.currentContext + + def bobUsername: Username = currentContext.get().bobUsername + def bobAccountId: String = currentContext.get().bobAccountId + @BeforeEach def setUp(server: GuiceJamesServer): Unit = { + val uniqueSuffix = UUID.randomUUID().toString.replace("-", "").take(8) + val bob = Username.fromLocalPartWithDomain(s"bob$uniqueSuffix", DOMAIN) + val accountId = Hashing.sha256().hashString(bob.asString(), StandardCharsets.UTF_8).toString + currentContext.set(ThreadChangesContract.TestContext(bob, accountId)) server.getProbe(classOf[DataProbeImpl]) .fluent .addDomain(DOMAIN.asString) .addDomain("domain-alias.tld") - .addUser(BOB.asString, BOB_PASSWORD) + .addUser(bobUsername.asString, BOB_PASSWORD) requestSpecification = baseRequestSpecBuilder(server) - .setAuth(authScheme(UserCredential(BOB, BOB_PASSWORD))) + .setAuth(authScheme(UserCredential(bobUsername, BOB_PASSWORD))) .build } @@ -54,7 +73,7 @@ trait ThreadChangesContract { | "methodCalls": [[ | "Thread/changes", | { - | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", + | "accountId": "$bobAccountId", | "sinceState": "2c9f1b12-b35a-43e6-9af2-0106fb53a941" | }, | "c1"]] @@ -97,7 +116,7 @@ trait ThreadChangesContract { | "methodCalls": [[ | "Thread/changes", | { - | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", + | "accountId": "$bobAccountId", | "sinceState": "${INSTANCE.value}" | }, | "c1"]] @@ -119,7 +138,7 @@ trait ThreadChangesContract { .inPath("methodResponses[0][1]") .isEqualTo( s"""{ - | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", + | "accountId": "$bobAccountId", | "oldState": "${INSTANCE.value}", | "newState": "${INSTANCE.value}", | "hasMoreChanges": false, diff --git a/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryThreadChangesMethodTest.java b/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryThreadChangesMethodTest.java index 733d3f70b3..fbe7608db3 100644 --- a/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryThreadChangesMethodTest.java +++ b/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryThreadChangesMethodTest.java @@ -21,6 +21,6 @@ package org.apache.james.jmap.rfc8621.memory; import org.apache.james.jmap.rfc8621.contract.ThreadChangesContract; -public class MemoryThreadChangesMethodTest extends MemoryBase implements ThreadChangesContract { +public class MemoryThreadChangesMethodTest extends PerClassMemoryBase implements ThreadChangesContract { } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
