-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added the remaining testing of all commands
- Loading branch information
1 parent
fe39ab4
commit 060cc2e
Showing
7 changed files
with
267 additions
and
18 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
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
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
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
61 changes: 61 additions & 0 deletions
61
services/contracts/src/test/java/com/workup/contracts/GetMilestoneTests.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,61 @@ | ||
package com.workup.contracts; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import com.workup.contracts.models.ContractMilestone; | ||
import com.workup.contracts.repositories.ContractMilestoneRepository; | ||
import com.workup.shared.commands.contracts.requests.GetMilestoneRequest; | ||
import com.workup.shared.commands.contracts.responses.GetMilestoneResponse; | ||
import com.workup.shared.enums.HttpStatusCode; | ||
import com.workup.shared.enums.ServiceQueueNames; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.UUID; | ||
import org.springframework.amqp.core.AmqpTemplate; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class GetMilestoneTests { | ||
|
||
@Autowired ContractMilestoneRepository contractMilestoneRepository; | ||
|
||
public void milestoneNotFoundTest(AmqpTemplate template) { | ||
String milestoneId = UUID.randomUUID().toString(); | ||
GetMilestoneRequest request = | ||
GetMilestoneRequest.builder().withMilestoneId(milestoneId).build(); | ||
|
||
GetMilestoneResponse response = | ||
(GetMilestoneResponse) template.convertSendAndReceive(ServiceQueueNames.CONTRACTS, request); | ||
System.out.println(response); | ||
assertNotNull(response); | ||
assertEquals(HttpStatusCode.NOT_FOUND, response.getStatusCode()); | ||
} | ||
|
||
public void successTest(AmqpTemplate template) throws ParseException { | ||
|
||
String milestoneId = UUID.randomUUID().toString(); | ||
ContractMilestone milestone = | ||
ContractMilestone.builder() | ||
.withMilestoneId(UUID.fromString(milestoneId)) | ||
.withDescription("make sure the students hate your admin system") | ||
.withDueDate(new SimpleDateFormat("yyyy-MM-dd").parse("2025-01-01")) | ||
.withAmount(30000) | ||
.build(); | ||
|
||
try { | ||
contractMilestoneRepository.save(milestone); | ||
|
||
GetMilestoneRequest request = | ||
GetMilestoneRequest.builder().withMilestoneId(milestoneId).build(); | ||
|
||
GetMilestoneResponse response = | ||
(GetMilestoneResponse) | ||
template.convertSendAndReceive(ServiceQueueNames.CONTRACTS, request); | ||
assertNotNull(response); | ||
assertEquals(HttpStatusCode.OK, response.getStatusCode()); | ||
} catch (Exception e) { | ||
fail(); | ||
} | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
services/contracts/src/test/java/com/workup/contracts/InitiateContractTests.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,88 @@ | ||
package com.workup.contracts; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import com.workup.contracts.models.Contract; | ||
import com.workup.contracts.models.ContractMilestone; | ||
import com.workup.contracts.repositories.ContractMilestoneRepository; | ||
import com.workup.contracts.repositories.ContractRepository; | ||
import com.workup.shared.commands.contracts.Milestone; | ||
import com.workup.shared.commands.contracts.requests.InitiateContractRequest; | ||
import com.workup.shared.commands.contracts.responses.InitiateContractResponse; | ||
import com.workup.shared.enums.HttpStatusCode; | ||
import com.workup.shared.enums.ServiceQueueNames; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import org.springframework.amqp.core.AmqpTemplate; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class InitiateContractTests { | ||
|
||
@Autowired ContractRepository contractRepository; | ||
|
||
@Autowired ContractMilestoneRepository contractMilestoneRepository; | ||
|
||
public void successTest(AmqpTemplate template) throws ParseException { | ||
Milestone milestone = | ||
Milestone.builder() | ||
.withDescription("make sure the students hate your admin system") | ||
.withDueDate(new SimpleDateFormat("yyyy-MM-dd").parse("2025-01-01")) | ||
.withAmount(30000) | ||
.build(); | ||
|
||
List<Milestone> 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(); | ||
InitiateContractResponse response = | ||
(InitiateContractResponse) | ||
template.convertSendAndReceive(ServiceQueueNames.CONTRACTS, initiateContractRequest); | ||
|
||
assertNotNull(response); | ||
|
||
// Now make sure that this contract is exactly the one submitted | ||
assertEquals(HttpStatusCode.CREATED, response.getStatusCode()); | ||
|
||
Optional<Contract> contractOptional = | ||
contractRepository.findById(UUID.fromString(response.getContractId())); | ||
if (contractOptional.isEmpty()) fail(); | ||
|
||
Contract contract = contractOptional.get(); | ||
|
||
assertEquals("789", contract.getJobId()); | ||
assertEquals("bruh", contract.getProposalId()); | ||
assertEquals("very happy guc worker :)", contract.getJobTitle()); | ||
assertEquals(clientId, contract.getClientId()); | ||
assertEquals(freelancerId, contract.getFreelancerId()); | ||
|
||
// Now check over the milestone that it was inserted correctly with the contract also | ||
List<String> milestoneIds = contract.getMilestonesIds(); | ||
|
||
Optional<ContractMilestone> optionalContractMilestone = | ||
contractMilestoneRepository.findById(UUID.fromString(milestoneIds.getFirst())); | ||
if (optionalContractMilestone.isEmpty()) | ||
fail("Milestones weren't added with the contract correctly"); | ||
|
||
ContractMilestone addedMilestone = optionalContractMilestone.get(); | ||
assertEquals("make sure the students hate your admin system", addedMilestone.getDescription()); | ||
assertEquals( | ||
new SimpleDateFormat("yyyy-MM-dd").parse("2025-01-01"), addedMilestone.getDueDate()); | ||
assertEquals(30000, addedMilestone.getAmount()); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
services/contracts/src/test/java/com/workup/contracts/ViewContractMilestonesTests.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,63 @@ | ||
package com.workup.contracts; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import com.workup.contracts.models.ContractMilestone; | ||
import com.workup.contracts.repositories.ContractMilestoneRepository; | ||
import com.workup.shared.commands.contracts.Milestone; | ||
import com.workup.shared.commands.contracts.requests.ViewContractMilestonesRequest; | ||
import com.workup.shared.commands.contracts.responses.ViewContractMilestonesResponse; | ||
import com.workup.shared.enums.ServiceQueueNames; | ||
import java.util.*; | ||
import org.springframework.amqp.core.AmqpTemplate; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ViewContractMilestonesTests { | ||
@Autowired ContractMilestoneRepository contractMilestoneRepository; | ||
|
||
public void successTest(AmqpTemplate template) { | ||
String contractId = UUID.randomUUID().toString(); | ||
Random rand = new Random(); | ||
// create some milestones to be added to the db with same contractId | ||
ArrayList<ContractMilestone> milestones = new ArrayList<>(); | ||
for (int i = 0; i < 10; ++i) | ||
milestones.add( | ||
ContractMilestone.builder() | ||
.withDueDate(new Date()) | ||
.withAmount(rand.nextInt()) | ||
.withContractId(contractId) | ||
.withDescription("AISFHAS SAGASV") | ||
.withMilestoneId(UUID.randomUUID()) | ||
.build()); | ||
|
||
contractMilestoneRepository.saveAll(milestones); | ||
|
||
ViewContractMilestonesRequest request = | ||
ViewContractMilestonesRequest.builder().withContractId(contractId).build(); | ||
|
||
ViewContractMilestonesResponse response = | ||
(ViewContractMilestonesResponse) | ||
template.convertSendAndReceive(ServiceQueueNames.CONTRACTS, request); | ||
|
||
assertNotNull(response); | ||
|
||
HashMap<String, ContractMilestone> mapping = new HashMap<>(); | ||
milestones.forEach(m -> mapping.put(m.getMilestoneId().toString(), m)); | ||
|
||
for (int i = 0; i < response.getContractMilestones().size(); ++i) { | ||
Milestone currMilestone = response.getContractMilestones().get(i); | ||
assertEquals( | ||
mapping.get(currMilestone.getMilestoneId()).getAmount(), currMilestone.getAmount()); | ||
assertEquals( | ||
mapping.get(currMilestone.getMilestoneId()).getContractId(), | ||
currMilestone.getContractId()); | ||
assertEquals( | ||
mapping.get(currMilestone.getMilestoneId()).getDescription(), | ||
currMilestone.getDescription()); | ||
assertEquals( | ||
mapping.get(currMilestone.getMilestoneId()).getDueDate(), currMilestone.getDueDate()); | ||
} | ||
} | ||
} |