From bb4c778fec90d8abf5ccaed9e5186bd40f817ba7 Mon Sep 17 00:00:00 2001 From: Karim Elmosalamy Date: Thu, 16 May 2024 00:22:45 +0300 Subject: [PATCH] added logging to the contracts microservice --- services/contracts/pom.xml | 8 +++ .../contracts/ContractsApplication.java | 4 +- .../workup/contracts/RabbitMQListener.java | 4 +- .../commands/EvaluateMilestoneCommand.java | 7 +-- .../commands/GetContractCommand.java | 7 ++- .../commands/GetMilestoneCommand.java | 4 +- .../GetPendingTerminationsCommand.java | 4 +- .../HandleTerminationRequestCommand.java | 7 ++- .../commands/InitiateContractCommand.java | 7 ++- .../commands/MarkMilestoneAsPaidCommand.java | 5 +- .../commands/ProgressMilestoneCommand.java | 3 +- .../RequestContractTerminationCommand.java | 3 +- .../contracts/logger/ContractsLogger.java | 18 ++++++- .../workup/contracts/logger/LoggingLevel.java | 9 ++++ .../tests/InitiateContractTests.java | 11 ++-- .../src/main/resources/application.properties | 4 +- .../contracts/src/main/resources/log4j2.xml | 52 ++++++++++++++++++ .../contracts/ProgressMilestoneTests.java | 54 +++++++++---------- 18 files changed, 160 insertions(+), 51 deletions(-) create mode 100644 services/contracts/src/main/java/com/workup/contracts/logger/LoggingLevel.java create mode 100644 services/contracts/src/main/resources/log4j2.xml diff --git a/services/contracts/pom.xml b/services/contracts/pom.xml index baa8376c..7c2c4960 100644 --- a/services/contracts/pom.xml +++ b/services/contracts/pom.xml @@ -24,6 +24,10 @@ org.springframework.boot spring-boot-starter-amqp + + org.springframework.boot + spring-boot-starter-log4j2 + com.workup shared @@ -86,6 +90,10 @@ lombok provided + + org.apache.logging.log4j + log4j-core + diff --git a/services/contracts/src/main/java/com/workup/contracts/ContractsApplication.java b/services/contracts/src/main/java/com/workup/contracts/ContractsApplication.java index 5c37c3e0..36cf4084 100644 --- a/services/contracts/src/main/java/com/workup/contracts/ContractsApplication.java +++ b/services/contracts/src/main/java/com/workup/contracts/ContractsApplication.java @@ -2,6 +2,8 @@ import static com.workup.contracts.tests.InitiateContractTests.initiateContractTest1; +import com.workup.contracts.logger.ContractsLogger; +import com.workup.contracts.logger.LoggingLevel; import com.workup.shared.enums.ServiceQueueNames; import org.springframework.amqp.core.AmqpTemplate; import org.springframework.amqp.core.Queue; @@ -26,7 +28,7 @@ public static void main(String[] args) { @Bean public ApplicationRunner runner(AmqpTemplate template) { return args -> { - System.out.println("ApplicationRunner is executing"); + ContractsLogger.print("ApplicationRunner is executing", LoggingLevel.TRACE); // Use below example function to test sending to the queue. initiateContractTest1(template); diff --git a/services/contracts/src/main/java/com/workup/contracts/RabbitMQListener.java b/services/contracts/src/main/java/com/workup/contracts/RabbitMQListener.java index 56a119d6..980d0dfa 100644 --- a/services/contracts/src/main/java/com/workup/contracts/RabbitMQListener.java +++ b/services/contracts/src/main/java/com/workup/contracts/RabbitMQListener.java @@ -1,6 +1,8 @@ package com.workup.contracts; import com.workup.contracts.commands.*; +import com.workup.contracts.logger.ContractsLogger; +import com.workup.contracts.logger.LoggingLevel; import com.workup.shared.commands.contracts.requests.ContractTerminationRequest; import com.workup.shared.commands.contracts.requests.EvaluateMilestoneRequest; import com.workup.shared.commands.contracts.requests.GetContractRequest; @@ -63,7 +65,7 @@ public ViewContractMilestonesResponse receive(ViewContractMilestonesRequest in) @RabbitHandler public GetContractResponse receive(GetContractRequest in) throws Exception { - System.out.println("** ENTERED GET CONTRACT RABBITMQ"); + ContractsLogger.print("** ENTERED GET CONTRACT RABBITMQ", LoggingLevel.TRACE); return ((GetContractCommand) commandMap.getCommand("GetContract")).Run(in); } diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java index f5df099d..f57669b8 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/EvaluateMilestoneCommand.java @@ -1,6 +1,7 @@ package com.workup.contracts.commands; import com.workup.contracts.logger.ContractsLogger; +import com.workup.contracts.logger.LoggingLevel; import com.workup.contracts.models.Contract; import com.workup.contracts.models.ContractMilestone; import com.workup.shared.commands.contracts.requests.EvaluateMilestoneRequest; @@ -42,10 +43,10 @@ public EvaluateMilestoneResponse Run(EvaluateMilestoneRequest request) { try { contractMilestoneRepository.save(updatedMilestone); - ContractsLogger.print(" [x] Milestone evaluated " + updatedMilestone); + ContractsLogger.print(" [x] Milestone evaluated " + updatedMilestone, LoggingLevel.TRACE); if (request.getEvaluatedState() == MilestoneState.ACCEPTED) { - ContractsLogger.print(" [x] Sending payment request "); + ContractsLogger.print(" [x] Sending payment request ", LoggingLevel.TRACE); // Getting the contract as we need to send the freelancer and client id since they are // in the payment request parameters. Optional contractOptional = @@ -63,7 +64,7 @@ public EvaluateMilestoneResponse Run(EvaluateMilestoneRequest request) { .withDescription(updatedMilestone.getMilestoneId().toString()) .build(); rabbitTemplate.convertSendAndReceive(ServiceQueueNames.PAYMENTS, externalRequest); - ContractsLogger.print(" [x] Payment request sent "); + ContractsLogger.print(" [x] Payment request sent ", LoggingLevel.TRACE); } return EvaluateMilestoneResponse.builder() diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java index daf27561..e26f93a2 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/GetContractCommand.java @@ -1,6 +1,7 @@ package com.workup.contracts.commands; import com.workup.contracts.logger.ContractsLogger; +import com.workup.contracts.logger.LoggingLevel; import com.workup.contracts.models.Contract; import com.workup.shared.commands.contracts.requests.GetContractRequest; import com.workup.shared.commands.contracts.responses.GetContractResponse; @@ -18,7 +19,8 @@ public GetContractResponse Run(GetContractRequest request) { (GetContractResponse) redisService.getValue(cachingKey, GetContractResponse.class); if (cachedResponse != null) { ContractsLogger.print( - "[x] Contract request response fetched from cache: " + cachedResponse.toString()); + "[x] Contract request response fetched from cache: " + cachedResponse.toString(), + LoggingLevel.TRACE); return cachedResponse; } @@ -52,7 +54,8 @@ public GetContractResponse Run(GetContractRequest request) { redisService.setValue(cachingKey, response); return response; } catch (Exception ex) { - ContractsLogger.print("[x] Error occurred while fetching contract: " + ex.getMessage()); + ContractsLogger.print( + "[x] Error occurred while fetching contract: " + ex.getMessage(), LoggingLevel.TRACE); ex.printStackTrace(); return GetContractResponse.builder() .withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR) diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java index 53427ceb..ccc9fdaf 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/GetMilestoneCommand.java @@ -1,6 +1,7 @@ package com.workup.contracts.commands; import com.workup.contracts.logger.ContractsLogger; +import com.workup.contracts.logger.LoggingLevel; import com.workup.contracts.models.ContractMilestone; import com.workup.shared.commands.contracts.requests.GetMilestoneRequest; import com.workup.shared.commands.contracts.responses.GetMilestoneResponse; @@ -19,7 +20,8 @@ public GetMilestoneResponse Run(GetMilestoneRequest request) { (GetMilestoneResponse) redisService.getValue(cachingKey, GetMilestoneResponse.class); if (cachedResponse != null) { ContractsLogger.print( - "[x] Milestone request response fetched from cache: " + cachedResponse.toString()); + "[x] Milestone request response fetched from cache: " + cachedResponse.toString(), + LoggingLevel.TRACE); return cachedResponse; } diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java index bfcf3470..c473ff70 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/GetPendingTerminationsCommand.java @@ -1,6 +1,7 @@ package com.workup.contracts.commands; import com.workup.contracts.logger.ContractsLogger; +import com.workup.contracts.logger.LoggingLevel; import com.workup.contracts.models.TerminationRequest; import com.workup.shared.commands.contracts.requests.GetPendingTerminationsRequest; import com.workup.shared.commands.contracts.responses.GetPendingTerminationsResponse; @@ -19,7 +20,8 @@ public GetPendingTerminationsResponse Run(GetPendingTerminationsRequest request) redisService.getValue(cachingKey, GetPendingTerminationsResponse.class); if (cachedResponse != null) { ContractsLogger.print( - "[x] Contract terminations response fetched from cache: " + cachedResponse.toString()); + "[x] Contract terminations response fetched from cache: " + cachedResponse.toString(), + LoggingLevel.TRACE); return cachedResponse; } diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/HandleTerminationRequestCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/HandleTerminationRequestCommand.java index d8fd432d..009e5283 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/HandleTerminationRequestCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/HandleTerminationRequestCommand.java @@ -1,6 +1,7 @@ package com.workup.contracts.commands; import com.workup.contracts.logger.ContractsLogger; +import com.workup.contracts.logger.LoggingLevel; import com.workup.contracts.models.Contract; import com.workup.contracts.models.TerminationRequest; import com.workup.shared.commands.contracts.requests.HandleTerminationRequest; @@ -42,7 +43,8 @@ private HandleTerminationResponse handleTerminationRequest( } try { TerminationRequest updatedRequest = terminationRequestRepository.save(terminationRequest); - ContractsLogger.print(" [x] Updated Termination Request " + updatedRequest); + ContractsLogger.print( + " [x] Updated Termination Request " + updatedRequest, LoggingLevel.TRACE); return HandleTerminationResponse.builder() .withRequestStatus(updatedRequest.getStatus()) .withStatusCode(HttpStatusCode.OK) @@ -68,7 +70,8 @@ private HandleTerminationResponse terminateContract(String contractId) { updatedContract.setStatus(ContractState.TERMINATED); try { updatedContract = contractRepository.save(updatedContract); - ContractsLogger.print(" [x] Updated Contract Status to Terminated " + updatedContract); + ContractsLogger.print( + " [x] Updated Contract Status to Terminated " + updatedContract, LoggingLevel.TRACE); } catch (Exception e) { e.printStackTrace(); return HandleTerminationResponse.builder() diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/InitiateContractCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/InitiateContractCommand.java index c2db2f53..b5be8d7d 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/InitiateContractCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/InitiateContractCommand.java @@ -1,6 +1,7 @@ package com.workup.contracts.commands; import com.workup.contracts.logger.ContractsLogger; +import com.workup.contracts.logger.LoggingLevel; import com.workup.contracts.models.Contract; import com.workup.contracts.models.ContractMilestone; import com.workup.shared.commands.contracts.Milestone; @@ -59,11 +60,13 @@ public InitiateContractResponse Run(InitiateContractRequest request) { try { Contract savedContract = contractRepository.save(contract); - ContractsLogger.print(" [x] Saved Contract '" + savedContract.getJobTitle()); + ContractsLogger.print( + " [x] Saved Contract '" + savedContract.getJobTitle(), LoggingLevel.TRACE); contractMilestoneRepository.saveAll(milestonesToAdd); - ContractsLogger.print(" [x] Saved All Milestones '" + savedContract.getJobTitle()); + ContractsLogger.print( + " [x] Saved All Milestones '" + savedContract.getJobTitle(), LoggingLevel.TRACE); return InitiateContractResponse.builder() .withContractId(savedContract.getContractId().toString()) diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/MarkMilestoneAsPaidCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/MarkMilestoneAsPaidCommand.java index 9922fd13..6bf34939 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/MarkMilestoneAsPaidCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/MarkMilestoneAsPaidCommand.java @@ -1,5 +1,7 @@ package com.workup.contracts.commands; +import com.workup.contracts.logger.ContractsLogger; +import com.workup.contracts.logger.LoggingLevel; import com.workup.contracts.models.ContractMilestone; import com.workup.shared.commands.contracts.requests.MarkPaymentCompletedRequest; import com.workup.shared.commands.contracts.responses.MarkPaymentCompletedResponse; @@ -38,7 +40,8 @@ public MarkPaymentCompletedResponse Run(MarkPaymentCompletedRequest request) { try { contractMilestoneRepository.save(updatedMilestone); - System.out.println(" [x] Marked Milestone as Paid '" + updatedMilestone); + ContractsLogger.print( + " [x] Marked Milestone as Paid '" + updatedMilestone, LoggingLevel.TRACE); return MarkPaymentCompletedResponse.builder().withStatusCode(HttpStatusCode.OK).build(); } catch (Exception e) { e.printStackTrace(); diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java index 3f480e3f..eba73128 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/ProgressMilestoneCommand.java @@ -1,6 +1,7 @@ package com.workup.contracts.commands; import com.workup.contracts.logger.ContractsLogger; +import com.workup.contracts.logger.LoggingLevel; import com.workup.contracts.models.ContractMilestone; import com.workup.shared.commands.contracts.requests.ProgressMilestoneRequest; import com.workup.shared.commands.contracts.responses.ProgressMilestoneResponse; @@ -42,7 +43,7 @@ public ProgressMilestoneResponse Run(ProgressMilestoneRequest request) { try { contractMilestoneRepository.save(updatedMilestone); - ContractsLogger.print(" [x] Milestone Progressed " + updatedMilestone); + ContractsLogger.print(" [x] Milestone Progressed " + updatedMilestone, LoggingLevel.TRACE); return ProgressMilestoneResponse.builder() .withStatusCode(HttpStatusCode.OK) .withErrorMessage("") diff --git a/services/contracts/src/main/java/com/workup/contracts/commands/RequestContractTerminationCommand.java b/services/contracts/src/main/java/com/workup/contracts/commands/RequestContractTerminationCommand.java index 9cd7850d..128b4f57 100644 --- a/services/contracts/src/main/java/com/workup/contracts/commands/RequestContractTerminationCommand.java +++ b/services/contracts/src/main/java/com/workup/contracts/commands/RequestContractTerminationCommand.java @@ -1,6 +1,7 @@ package com.workup.contracts.commands; import com.workup.contracts.logger.ContractsLogger; +import com.workup.contracts.logger.LoggingLevel; import com.workup.contracts.models.Contract; import com.workup.contracts.models.TerminationRequest; import com.workup.shared.commands.contracts.requests.ContractTerminationRequest; @@ -69,7 +70,7 @@ public ContractTerminationResponse Run(ContractTerminationRequest request) { try { TerminationRequest savedRequest = terminationRequestRepository.save(terminationRequest); - ContractsLogger.print(" [x] Saved Termination Request '" + savedRequest); + ContractsLogger.print(" [x] Saved Termination Request '" + savedRequest, LoggingLevel.TRACE); return ContractTerminationResponse.builder() .withRequestId(savedRequest.getRequestId().toString()) diff --git a/services/contracts/src/main/java/com/workup/contracts/logger/ContractsLogger.java b/services/contracts/src/main/java/com/workup/contracts/logger/ContractsLogger.java index 1e2e71d6..c58b2f4c 100644 --- a/services/contracts/src/main/java/com/workup/contracts/logger/ContractsLogger.java +++ b/services/contracts/src/main/java/com/workup/contracts/logger/ContractsLogger.java @@ -1,8 +1,22 @@ package com.workup.contracts.logger; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.config.Configurator; + public class ContractsLogger { + private static final Logger logger = LogManager.getLogger(ContractsLogger.class); + + public static void print(String logMessage, LoggingLevel level) { + Configurator.setRootLevel(Level.ERROR); - public static void print(String logMessage) { - System.out.println(logMessage); + switch (level) { + case TRACE -> logger.trace("Trace level log message: " + logMessage); + case DEBUG -> logger.debug("Debug level log message: " + logMessage); + case INFO -> logger.info("Info level log message: " + logMessage); + case WARN -> logger.warn("Warn level log message: " + logMessage); + case ERROR -> logger.error("Error level log message: " + logMessage); + } } } diff --git a/services/contracts/src/main/java/com/workup/contracts/logger/LoggingLevel.java b/services/contracts/src/main/java/com/workup/contracts/logger/LoggingLevel.java new file mode 100644 index 00000000..9ba341d5 --- /dev/null +++ b/services/contracts/src/main/java/com/workup/contracts/logger/LoggingLevel.java @@ -0,0 +1,9 @@ +package com.workup.contracts.logger; + +public enum LoggingLevel { + TRACE, + DEBUG, + INFO, + WARN, + ERROR +} diff --git a/services/contracts/src/main/java/com/workup/contracts/tests/InitiateContractTests.java b/services/contracts/src/main/java/com/workup/contracts/tests/InitiateContractTests.java index b09f461b..86bc03c7 100644 --- a/services/contracts/src/main/java/com/workup/contracts/tests/InitiateContractTests.java +++ b/services/contracts/src/main/java/com/workup/contracts/tests/InitiateContractTests.java @@ -1,5 +1,7 @@ package com.workup.contracts.tests; +import com.workup.contracts.logger.ContractsLogger; +import com.workup.contracts.logger.LoggingLevel; import com.workup.shared.commands.contracts.Milestone; import com.workup.shared.commands.contracts.requests.InitiateContractRequest; import com.workup.shared.commands.contracts.responses.InitiateContractResponse; @@ -13,7 +15,7 @@ public class InitiateContractTests { public static void initiateContractTest1(AmqpTemplate template) throws ParseException { - System.out.println("[ ] Running InitiateContractTest1..."); + ContractsLogger.print("[ ] Running InitiateContractTest1...", LoggingLevel.TRACE); Milestone milestone = Milestone.builder() @@ -39,8 +41,9 @@ public static void initiateContractTest1(AmqpTemplate template) throws ParseExce template.convertSendAndReceive(ServiceQueueNames.CONTRACTS, initiateContractRequest); assert resp != null : "InitiateContractTest1 Response was null"; - System.out.println( - "Response success output: " + resp.getStatusCode() + " " + resp.getErrorMessage()); - System.out.println("[x] Finished InitiateContractTest1..."); + ContractsLogger.print( + "Response success output: " + resp.getStatusCode() + " " + resp.getErrorMessage(), + LoggingLevel.TRACE); + ContractsLogger.print("[x] Finished InitiateContractTest1...", LoggingLevel.TRACE); } } diff --git a/services/contracts/src/main/resources/application.properties b/services/contracts/src/main/resources/application.properties index 0e7e5fa6..02c508c5 100644 --- a/services/contracts/src/main/resources/application.properties +++ b/services/contracts/src/main/resources/application.properties @@ -12,4 +12,6 @@ spring.cassandra.schema-action=CREATE_IF_NOT_EXISTS spring.cache.type=redis spring.cache.host=service_redis spring.cache.port=6379 -spring.cache.redis.time-to-live=600000 \ No newline at end of file +spring.cache.redis.time-to-live=600000 + +logging.level.root=INFO \ No newline at end of file diff --git a/services/contracts/src/main/resources/log4j2.xml b/services/contracts/src/main/resources/log4j2.xml new file mode 100644 index 00000000..526e0522 --- /dev/null +++ b/services/contracts/src/main/resources/log4j2.xml @@ -0,0 +1,52 @@ + + + logs/contracts + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/contracts/src/test/java/com/workup/contracts/ProgressMilestoneTests.java b/services/contracts/src/test/java/com/workup/contracts/ProgressMilestoneTests.java index f35d862a..2e8609b6 100644 --- a/services/contracts/src/test/java/com/workup/contracts/ProgressMilestoneTests.java +++ b/services/contracts/src/test/java/com/workup/contracts/ProgressMilestoneTests.java @@ -2,7 +2,6 @@ import static org.junit.jupiter.api.Assertions.*; -import com.workup.contracts.models.Contract; import com.workup.contracts.models.ContractMilestone; import com.workup.contracts.repositories.ContractMilestoneRepository; import com.workup.shared.commands.contracts.Milestone; @@ -16,7 +15,6 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; - import org.springframework.amqp.core.AmqpTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -131,7 +129,6 @@ public void wrongMilestoneState3(AmqpTemplate template) { assertEquals("Milestone cannot be progressed through this command", response.getErrorMessage()); } - public void successTest1(AmqpTemplate template) throws ParseException { // create a milestone with it's contract, and evaluate this milestone String milestoneId = UUID.randomUUID().toString(); @@ -175,59 +172,60 @@ public void successTest1(AmqpTemplate template) throws ParseException { // Check same milestone has the right state - Optional milestoneInRepoOptional = contractMilestoneRepository.findById(UUID.fromString(milestoneId)); + Optional milestoneInRepoOptional = + contractMilestoneRepository.findById(UUID.fromString(milestoneId)); ContractMilestone milestoneInRepo = milestoneInRepoOptional.get(); - assertEquals(milestoneInRepo.getStatus(),MilestoneState.IN_PROGRESS); + assertEquals(milestoneInRepo.getStatus(), MilestoneState.IN_PROGRESS); } public void successTest2(AmqpTemplate template) throws ParseException { // create a milestone with it's contract, and evaluate this milestone String milestoneId = UUID.randomUUID().toString(); Milestone milestone = - Milestone.builder() - .withMilestoneId(milestoneId) - .withDescription("make sure the students hate your admin system") - .withDueDate(new SimpleDateFormat("yyyy-MM-dd").parse("2025-01-01")) - .withAmount(30000) - .withStatus(MilestoneState.IN_PROGRESS) - .build(); + Milestone.builder() + .withMilestoneId(milestoneId) + .withDescription("make sure the students hate your admin system") + .withDueDate(new SimpleDateFormat("yyyy-MM-dd").parse("2025-01-01")) + .withAmount(30000) + .withStatus(MilestoneState.IN_PROGRESS) + .build(); List milestones = new ArrayList<>(); milestones.add(milestone); String clientId = UUID.randomUUID().toString(), freelancerId = UUID.randomUUID().toString(); InitiateContractRequest initiateContractRequest = - InitiateContractRequest.builder() - .withClientId(clientId) - .withFreelancerId(freelancerId) - .withJobId("789") - .withProposalId("bruh") - .withJobTitle("very happy guc worker :)") - .withJobMilestones(milestones) - .build(); + InitiateContractRequest.builder() + .withClientId(clientId) + .withFreelancerId(freelancerId) + .withJobId("789") + .withProposalId("bruh") + .withJobTitle("very happy guc worker :)") + .withJobMilestones(milestones) + .build(); InitiateContractResponse contractResponse = - (InitiateContractResponse) - template.convertSendAndReceive(ServiceQueueNames.CONTRACTS, initiateContractRequest); + (InitiateContractResponse) + template.convertSendAndReceive(ServiceQueueNames.CONTRACTS, initiateContractRequest); assertNotNull(contractResponse); ProgressMilestoneRequest request = - ProgressMilestoneRequest.builder().withMilestoneId(milestoneId).build(); + ProgressMilestoneRequest.builder().withMilestoneId(milestoneId).build(); ProgressMilestoneResponse response = - (ProgressMilestoneResponse) - template.convertSendAndReceive(ServiceQueueNames.CONTRACTS, request); + (ProgressMilestoneResponse) + template.convertSendAndReceive(ServiceQueueNames.CONTRACTS, request); assertNotNull(response); assertEquals(HttpStatusCode.OK, response.getStatusCode()); // Check same milestone has the right state - Optional milestoneInRepoOptional = contractMilestoneRepository.findById(UUID.fromString(milestoneId)); + Optional milestoneInRepoOptional = + contractMilestoneRepository.findById(UUID.fromString(milestoneId)); ContractMilestone milestoneInRepo = milestoneInRepoOptional.get(); - assertEquals(milestoneInRepo.getStatus(),MilestoneState.IN_REVIEW); + assertEquals(milestoneInRepo.getStatus(), MilestoneState.IN_REVIEW); } - }