Search in sources :

Example 6 with LotteryTicket

use of com.iluwatar.hexagonal.domain.LotteryTicket in project java-design-patterns by iluwatar.

the class InMemoryTicketRepositoryTest method testCrudOperations.

@Test
public void testCrudOperations() {
    LotteryTicketRepository repository = new InMemoryTicketRepository();
    assertEquals(repository.findAll().size(), 0);
    LotteryTicket ticket = LotteryTestUtils.createLotteryTicket();
    Optional<LotteryTicketId> id = repository.save(ticket);
    assertTrue(id.isPresent());
    assertEquals(repository.findAll().size(), 1);
    Optional<LotteryTicket> optionalTicket = repository.findById(id.get());
    assertTrue(optionalTicket.isPresent());
}
Also used : LotteryTicketId(com.iluwatar.hexagonal.domain.LotteryTicketId) LotteryTicket(com.iluwatar.hexagonal.domain.LotteryTicket) Test(org.junit.jupiter.api.Test)

Example 7 with LotteryTicket

use of com.iluwatar.hexagonal.domain.LotteryTicket in project java-design-patterns by iluwatar.

the class MongoTicketRepositoryTest method testCrudOperations.

@Test
public void testCrudOperations() {
    // create new lottery ticket and save it
    PlayerDetails details = new PlayerDetails("foo@bar.com", "123-123", "07001234");
    LotteryNumbers random = LotteryNumbers.createRandom();
    LotteryTicket original = new LotteryTicket(new LotteryTicketId(), details, random);
    Optional<LotteryTicketId> saved = repository.save(original);
    assertEquals(1, repository.getTicketsCollection().count());
    assertTrue(saved.isPresent());
    // fetch the saved lottery ticket from database and check its contents
    Optional<LotteryTicket> found = repository.findById(saved.get());
    assertTrue(found.isPresent());
    LotteryTicket ticket = found.get();
    assertEquals("foo@bar.com", ticket.getPlayerDetails().getEmail());
    assertEquals("123-123", ticket.getPlayerDetails().getBankAccount());
    assertEquals("07001234", ticket.getPlayerDetails().getPhoneNumber());
    assertEquals(original.getNumbers(), ticket.getNumbers());
    // clear the collection
    repository.deleteAll();
    assertEquals(0, repository.getTicketsCollection().count());
}
Also used : LotteryNumbers(com.iluwatar.hexagonal.domain.LotteryNumbers) LotteryTicketId(com.iluwatar.hexagonal.domain.LotteryTicketId) PlayerDetails(com.iluwatar.hexagonal.domain.PlayerDetails) LotteryTicket(com.iluwatar.hexagonal.domain.LotteryTicket) Test(org.junit.jupiter.api.Test)

Example 8 with LotteryTicket

use of com.iluwatar.hexagonal.domain.LotteryTicket in project java-design-patterns by iluwatar.

the class LotteryTestUtils method createLotteryTicket.

/**
 * @return lottery ticket
 */
public static LotteryTicket createLotteryTicket(String email, String account, String phone, Set<Integer> givenNumbers) {
    PlayerDetails details = new PlayerDetails(email, account, phone);
    LotteryNumbers numbers = LotteryNumbers.create(givenNumbers);
    return new LotteryTicket(new LotteryTicketId(), details, numbers);
}
Also used : LotteryNumbers(com.iluwatar.hexagonal.domain.LotteryNumbers) LotteryTicketId(com.iluwatar.hexagonal.domain.LotteryTicketId) PlayerDetails(com.iluwatar.hexagonal.domain.PlayerDetails) LotteryTicket(com.iluwatar.hexagonal.domain.LotteryTicket)

Aggregations

LotteryTicket (com.iluwatar.hexagonal.domain.LotteryTicket)8 LotteryTicketId (com.iluwatar.hexagonal.domain.LotteryTicketId)7 LotteryNumbers (com.iluwatar.hexagonal.domain.LotteryNumbers)4 PlayerDetails (com.iluwatar.hexagonal.domain.PlayerDetails)4 HashSet (java.util.HashSet)2 Document (org.bson.Document)2 Test (org.junit.jupiter.api.Test)2 HashMap (java.util.HashMap)1