mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-21 07:15:49 +00:00
format
This commit is contained in:
parent
d88a6e1af5
commit
d927a42681
4 changed files with 57 additions and 44 deletions
|
@ -1,9 +1,11 @@
|
|||
package org.springframework.samples.petclinic.domain;
|
||||
|
||||
import io.opentelemetry.instrumentation.annotations.WithSpan;
|
||||
|
||||
public class DomainValidationService {
|
||||
|
||||
|
||||
// Main method for domain validation logic
|
||||
@WithSpan
|
||||
public boolean validateDomainLogic(String usr) {
|
||||
String domain = normalizeDomainFormat("example.com");
|
||||
|
||||
|
@ -11,14 +13,17 @@ public class DomainValidationService {
|
|||
if (!containsRestrictedWords(domain) && isValidDomainSuffix(domain)) {
|
||||
if (isDomainAvailable(domain)) {
|
||||
saveValidationResults(domain, true, true);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
saveValidationResults(domain, true, false);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
flagDomainForReview(domain);
|
||||
saveValidationResults(domain, false, false);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
saveValidationResults(domain, false, false);
|
||||
}
|
||||
|
||||
|
@ -28,7 +33,8 @@ public class DomainValidationService {
|
|||
|
||||
// Fake method to check if a domain is valid
|
||||
private boolean isValidDomain(String domain) {
|
||||
return domain.matches("^[a-zA-Z0-9.-]+$") && domain.length() >= 3 && !domain.startsWith("-") && !domain.endsWith("-");
|
||||
return domain.matches("^[a-zA-Z0-9.-]+$") && domain.length() >= 3 && !domain.startsWith("-")
|
||||
&& !domain.endsWith("-");
|
||||
}
|
||||
|
||||
// Fake method to check if a domain is available
|
||||
|
@ -49,25 +55,30 @@ public class DomainValidationService {
|
|||
|
||||
// Fake method to simulate saving domain validation results
|
||||
private void saveValidationResults(String domain, boolean isValid, boolean isAvailable) {
|
||||
// Simulated save operation: Creating a fake result object and printing its contents
|
||||
// Simulated save operation: Creating a fake result object and printing its
|
||||
// contents
|
||||
ValidationResult result = new ValidationResult(domain, isValid, isAvailable);
|
||||
System.out.println("Saving results: " + result);
|
||||
}
|
||||
|
||||
// Fake method to flag domain for manual review
|
||||
private void flagDomainForReview(String domain) {
|
||||
// Simulated flagging operation: Creating a fake review request and printing its contents
|
||||
// Simulated flagging operation: Creating a fake review request and printing its
|
||||
// contents
|
||||
ReviewRequest request = new ReviewRequest(domain, "Contains restricted words or invalid suffix");
|
||||
System.out.println("Flagging for review: " + request);
|
||||
}
|
||||
|
||||
// Fake method to notify admin about the validation results
|
||||
private void notifyAdmin(String domain) {
|
||||
// Simulated notification: Creating a fake notification object and printing its contents
|
||||
Notification notification = new Notification("admin@example.com", "Domain Validation Completed", "Validation completed for domain: " + domain);
|
||||
// Simulated notification: Creating a fake notification object and printing its
|
||||
// contents
|
||||
Notification notification = new Notification("admin@example.com", "Domain Validation Completed",
|
||||
"Validation completed for domain: " + domain);
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
System.out.println("Notifying admin: " + notification);
|
||||
|
@ -113,8 +124,11 @@ public class DomainValidationService {
|
|||
|
||||
// Fake class to represent validation results
|
||||
private class ValidationResult {
|
||||
|
||||
String domain;
|
||||
|
||||
boolean isValid;
|
||||
|
||||
boolean isAvailable;
|
||||
|
||||
ValidationResult(String domain, boolean isValid, boolean isAvailable) {
|
||||
|
@ -125,13 +139,17 @@ public class DomainValidationService {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ValidationResult{domain='" + domain + "', isValid=" + isValid + ", isAvailable=" + isAvailable + "}";
|
||||
return "ValidationResult{domain='" + domain + "', isValid=" + isValid + ", isAvailable=" + isAvailable
|
||||
+ "}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Fake class to represent a review request
|
||||
private class ReviewRequest {
|
||||
|
||||
String domain;
|
||||
|
||||
String reason;
|
||||
|
||||
ReviewRequest(String domain, String reason) {
|
||||
|
@ -143,12 +161,16 @@ public class DomainValidationService {
|
|||
public String toString() {
|
||||
return "ReviewRequest{domain='" + domain + "', reason='" + reason + "'}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Fake class to represent a notification
|
||||
private class Notification {
|
||||
|
||||
String recipient;
|
||||
|
||||
String subject;
|
||||
|
||||
String message;
|
||||
|
||||
Notification(String recipient, String subject, String message) {
|
||||
|
@ -161,5 +183,7 @@ public class DomainValidationService {
|
|||
public String toString() {
|
||||
return "Notification{recipient='" + recipient + "', subject='" + subject + "', message='" + message + "'}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ public class OwnerValidation {
|
|||
private UserValidationService usrValSvc;
|
||||
|
||||
private DomainValidationService domainValidation;
|
||||
|
||||
private PasswordUtils pwdUtils;
|
||||
|
||||
private Tracer otelTracer;
|
||||
|
|
|
@ -15,4 +15,5 @@ public class UserValidationService {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -93,7 +93,6 @@ class OwnerControllerTests {
|
|||
@Test
|
||||
void shouldProvideOwnerVaccinationDate() {
|
||||
|
||||
for (int i=0; i<10;i++){
|
||||
Owner owner = CreateOwner();
|
||||
|
||||
var ownerLinkMatcher = String.format("**.findAll { node -> node.@href=='/owners/%s'}", owner.getId());
|
||||
|
@ -106,10 +105,6 @@ class OwnerControllerTests {
|
|||
.statusCode(200)
|
||||
.body(ownerLinkMatcher, Matchers.notNullValue());
|
||||
|
||||
}
|
||||
|
||||
for (int i=0; i<50;i++) {
|
||||
|
||||
given().contentType(ContentType.JSON)
|
||||
.when()
|
||||
.get("/owners")
|
||||
|
@ -117,14 +112,6 @@ class OwnerControllerTests {
|
|||
.contentType(ContentType.HTML)
|
||||
.statusCode(200);
|
||||
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// assertThat(false).isTrue();
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue