From 4db256b02ecd289e071ec6f723da9a0604cd9bf5 Mon Sep 17 00:00:00 2001 From: fabrizzio-dotCMS Date: Thu, 22 Aug 2024 11:14:24 -0600 Subject: [PATCH 1/2] #28136 --- tools/dotcms-cli/api-data-model/pom.xml | 5 +++ .../java/com/dotcms/api/ContentTypeAPIIT.java | 39 ++++++++++--------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/tools/dotcms-cli/api-data-model/pom.xml b/tools/dotcms-cli/api-data-model/pom.xml index 5420613db1b6..ca550c936cb0 100644 --- a/tools/dotcms-cli/api-data-model/pom.xml +++ b/tools/dotcms-cli/api-data-model/pom.xml @@ -45,6 +45,11 @@ quarkus-junit5 test + + org.awaitility + awaitility + test + org.immutables value diff --git a/tools/dotcms-cli/api-data-model/src/test/java/com/dotcms/api/ContentTypeAPIIT.java b/tools/dotcms-cli/api-data-model/src/test/java/com/dotcms/api/ContentTypeAPIIT.java index f48655c19cf7..f126286a5382 100644 --- a/tools/dotcms-cli/api-data-model/src/test/java/com/dotcms/api/ContentTypeAPIIT.java +++ b/tools/dotcms-cli/api-data-model/src/test/java/com/dotcms/api/ContentTypeAPIIT.java @@ -1,5 +1,7 @@ package com.dotcms.api; +import static org.awaitility.Awaitility.await; + import com.dotcms.DotCMSITProfile; import com.dotcms.api.client.model.RestClientFactory; import com.dotcms.api.client.model.ServiceManager; @@ -34,6 +36,7 @@ import io.quarkus.test.junit.TestProfile; import jakarta.inject.Inject; import jakarta.ws.rs.NotFoundException; +import jakarta.ws.rs.WebApplicationException; import java.io.IOException; import java.net.URL; import java.util.Date; @@ -41,6 +44,7 @@ import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.concurrent.TimeUnit; import org.eclipse.microprofile.config.inject.ConfigProperty; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -237,35 +241,34 @@ void Test_Create_Then_Update_Then_Delete_Content_Type() { ContentType newContentType = contentTypes.get(0); Assertions.assertNotNull(newContentType.id()); Assertions.assertEquals("_var_"+identifier, newContentType.variable()); - //We make sure the CT exists because the following line does not throw 404 + + // We make sure the CT exists because the following line does not throw 404 client.getContentType(newContentType.variable(), 1L, true); - //Now lets test update + + // Now lets test update final ImmutableSimpleContentType updatedContentType = ImmutableSimpleContentType.builder().from(newContentType).description("Updated").build(); final SaveContentTypeRequest request = SaveContentTypeRequest.builder(). from(updatedContentType).build(); final ResponseEntityView responseEntityView = client.updateContentType( request.variable(), request); Assertions.assertEquals("Updated", responseEntityView.entity().description()); - //And finally test delete + + // And finally test delete final ResponseEntityView responseStringEntity = client.delete(updatedContentType.variable()); Assertions.assertTrue(responseStringEntity.entity().contains("deleted")); - try { - //a small wait to make sure the CT is deleted - //a simple Thread.sleep would do the trick but Sonar says it's not a good practice - int count = 0; - while (null != client.getContentType(updatedContentType.variable(), 1L, true)){ - //We wait for the CT to be deleted - System.out.println("Waiting for CT to be deleted"); - count++; - if(count > 10){ - Assertions.fail("CT was not deleted"); - } + // Use Awaitility to wait until the ContentType is actually deleted + await().atMost(20, TimeUnit.SECONDS).until(() -> { + try { + client.getContentType(updatedContentType.variable(), 1L, true); + return false; // If this succeeds, the ContentType still exists + } catch (WebApplicationException e) { + if (e.getResponse().getStatus() == 404) { + return true; // ContentType was successfully deleted + } + throw e; // Rethrow any unexpected exceptions } - //This should throw 404 but under certain circumstances it does throw 400 - }catch(jakarta.ws.rs.WebApplicationException e){ - // Not relevant here - } + }); } /** From 45dd8121feac2f85ac0f7133755158aa02b98e2c Mon Sep 17 00:00:00 2001 From: fabrizzio-dotCMS Date: Fri, 23 Aug 2024 10:42:44 -0600 Subject: [PATCH 2/2] #28136 --- tools/dotcms-cli/api-data-model/pom.xml | 5 ----- .../src/test/java/com/dotcms/api/ContentTypeAPIIT.java | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/tools/dotcms-cli/api-data-model/pom.xml b/tools/dotcms-cli/api-data-model/pom.xml index ca550c936cb0..5420613db1b6 100644 --- a/tools/dotcms-cli/api-data-model/pom.xml +++ b/tools/dotcms-cli/api-data-model/pom.xml @@ -45,11 +45,6 @@ quarkus-junit5 test - - org.awaitility - awaitility - test - org.immutables value diff --git a/tools/dotcms-cli/api-data-model/src/test/java/com/dotcms/api/ContentTypeAPIIT.java b/tools/dotcms-cli/api-data-model/src/test/java/com/dotcms/api/ContentTypeAPIIT.java index f126286a5382..f954386bab3d 100644 --- a/tools/dotcms-cli/api-data-model/src/test/java/com/dotcms/api/ContentTypeAPIIT.java +++ b/tools/dotcms-cli/api-data-model/src/test/java/com/dotcms/api/ContentTypeAPIIT.java @@ -1,6 +1,6 @@ package com.dotcms.api; -import static org.awaitility.Awaitility.await; +import static org.testcontainers.shaded.org.awaitility.Awaitility.await; import com.dotcms.DotCMSITProfile; import com.dotcms.api.client.model.RestClientFactory;