-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#26633 Applying feedback removing Thread.sleep from code
- Loading branch information
1 parent
ab9ecf4
commit 970b43c
Showing
8 changed files
with
267 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 0 additions & 99 deletions
99
tools/dotcms-cli/api-data-model/src/test/java/com/dotcms/common/SiteTestHelper.java
This file was deleted.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
tools/dotcms-cli/api-data-model/src/test/java/com/dotcms/common/SiteTestHelperService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.dotcms.common; | ||
|
||
import static org.testcontainers.shaded.org.awaitility.Awaitility.await; | ||
|
||
import com.dotcms.api.SiteAPI; | ||
import com.dotcms.api.client.model.RestClientFactory; | ||
import com.dotcms.model.ResponseEntityView; | ||
import com.dotcms.model.site.GetSiteByNameRequest; | ||
import com.dotcms.model.site.SiteView; | ||
import java.time.Duration; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.context.control.ActivateRequestContext; | ||
import javax.inject.Inject; | ||
import javax.ws.rs.NotFoundException; | ||
import org.testcontainers.shaded.org.awaitility.core.ConditionTimeoutException; | ||
|
||
@ApplicationScoped | ||
public class SiteTestHelperService { | ||
|
||
private static final Duration MAX_WAIT_TIME = Duration.ofSeconds(15); | ||
private static final Duration POLL_INTERVAL = Duration.ofSeconds(2); | ||
|
||
@Inject | ||
RestClientFactory clientFactory; | ||
|
||
/** | ||
* Checks if the site statuses are valid. | ||
* | ||
* @param siteName The name of the site to check. | ||
* @param isLive The expected live status of the site. | ||
* @param archive The expected archive status of the site. | ||
* @return True if the site statuses are valid, false otherwise. | ||
*/ | ||
public Boolean checkValidSiteStatus(final String siteName, | ||
final boolean isLive, final boolean archive) { | ||
|
||
try { | ||
|
||
await() | ||
.atMost(MAX_WAIT_TIME) | ||
.pollInterval(POLL_INTERVAL) | ||
.until(() -> { | ||
try { | ||
var response = findSiteByName(siteName); | ||
return (response != null && response.entity() != null) && | ||
((response.entity().isLive() != null && | ||
response.entity().isLive().equals(isLive)) && | ||
(response.entity().isArchived() != null && | ||
response.entity().isArchived() | ||
.equals(archive))); | ||
} catch (NotFoundException e) { | ||
return false; | ||
} | ||
}); | ||
|
||
return true; | ||
} catch (ConditionTimeoutException ex) { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Retrieves a site by its name. | ||
* | ||
* @param siteName The name of the site. | ||
* @return The ResponseEntityView containing the SiteView object representing the site. | ||
*/ | ||
@ActivateRequestContext | ||
public ResponseEntityView<SiteView> findSiteByName(final String siteName) { | ||
|
||
final SiteAPI siteAPI = clientFactory.getClient(SiteAPI.class); | ||
|
||
// Execute the REST call to retrieve folder contents | ||
return siteAPI.findByName( | ||
GetSiteByNameRequest.builder().siteName(siteName).build() | ||
); | ||
} | ||
|
||
} |
Oops, something went wrong.