-
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 Refactor SitePushHandler and add SiteTestHelper
The SitePushHandler class has been refactored to improve readability and maintainability. Helper methods have been introduced to decide whether a site should be published, archived or unpublished. The push handler now utilizes ScheduledExecutorService to handle potential delays in site status changes. Furthermore, SiteTestHelper has been introduced providing common utility functions for site related tests.
- Loading branch information
1 parent
1f4ae11
commit 9a32d8e
Showing
4 changed files
with
361 additions
and
63 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
86 changes: 86 additions & 0 deletions
86
tools/dotcms-cli/api-data-model/src/test/java/com/dotcms/common/SiteTestHelper.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,86 @@ | ||
package com.dotcms.common; | ||
|
||
import com.dotcms.api.SiteAPI; | ||
import com.dotcms.api.client.model.RestClientFactory; | ||
import com.dotcms.model.site.GetSiteByNameRequest; | ||
import javax.inject.Inject; | ||
import javax.ws.rs.NotFoundException; | ||
|
||
public class SiteTestHelper { | ||
|
||
@Inject | ||
RestClientFactory clientFactory; | ||
|
||
/** | ||
* Checks if a site with the given name exists. | ||
* | ||
* @param siteName the name of the site to check | ||
* @return true if the site exists, false otherwise | ||
*/ | ||
protected Boolean siteExist(final String siteName) { | ||
|
||
long start = System.currentTimeMillis(); | ||
long end = start + 15 * 1000; // 15 seconds * 1000 ms/sec | ||
while (System.currentTimeMillis() < end) { | ||
try { | ||
var response = clientFactory.getClient(SiteAPI.class) | ||
.findByName(GetSiteByNameRequest.builder().siteName(siteName).build()); | ||
if ((response != null && response.entity() != null) && | ||
((response.entity().isLive() != null && | ||
response.entity().isLive()) && | ||
(response.entity().isWorking() != null && | ||
response.entity().isWorking()))) { | ||
return true; | ||
} | ||
} catch (NotFoundException e) { | ||
// Do nothing | ||
} | ||
|
||
try { | ||
Thread.sleep(2000); // Sleep for 2 second | ||
} catch (InterruptedException ex) { | ||
Thread.currentThread().interrupt(); | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* 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. | ||
*/ | ||
protected Boolean checkValidSiteStatus(final String siteName, | ||
final boolean isLive, final boolean archive) { | ||
|
||
long start = System.currentTimeMillis(); | ||
long end = start + 15 * 1000; // 15 seconds * 1000 ms/sec | ||
while (System.currentTimeMillis() < end) { | ||
try { | ||
var response = clientFactory.getClient(SiteAPI.class) | ||
.findByName(GetSiteByNameRequest.builder().siteName(siteName).build()); | ||
if ((response != null && response.entity() != null) && | ||
((response.entity().isLive() != null && | ||
response.entity().isLive().equals(isLive)) && | ||
(response.entity().isArchived() != null && | ||
response.entity().isArchived().equals(archive)))) { | ||
return true; | ||
} | ||
} catch (NotFoundException e) { | ||
// Do nothing | ||
} | ||
|
||
try { | ||
Thread.sleep(2000); // Sleep for 2 second | ||
} catch (InterruptedException ex) { | ||
Thread.currentThread().interrupt(); | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
Oops, something went wrong.