Skip to content

Commit

Permalink
Created test
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorKhan committed Mar 21, 2024
1 parent 27d60cb commit 391bb20
Showing 1 changed file with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.lucoenergia.conluz.domain.admin.supply.get;

import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.Test;
import org.lucoenergia.conluz.domain.admin.supply.Supply;
import org.lucoenergia.conluz.domain.admin.supply.create.CreateSupplyRepository;
import org.lucoenergia.conluz.domain.admin.supply.get.GetSupplyRepository;
import org.lucoenergia.conluz.domain.admin.supply.get.GetSupplyService;
import org.lucoenergia.conluz.domain.admin.user.User;
import org.lucoenergia.conluz.domain.admin.user.UserMother;
import org.lucoenergia.conluz.domain.admin.user.create.CreateUserRepository;
import org.lucoenergia.conluz.domain.shared.UserId;
import org.lucoenergia.conluz.domain.shared.pagination.PagedRequest;
import org.lucoenergia.conluz.domain.shared.pagination.PagedResult;
import org.lucoenergia.conluz.infrastructure.shared.BaseIntegrationTest;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.Random;
import java.util.UUID;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.when;

@Transactional
class GetSupplyServiceTest extends BaseIntegrationTest {

@Autowired
private CreateUserRepository createUserRepository;
@Autowired
private CreateSupplyRepository createSupplyRepository;
@Autowired
private GetSupplyService getSupplyService;

@Test
void testFindAll() {
// Assemble
String userPersonalId = "987654321S";
User user = UserMother.randomUserWithId(UUID.fromString("e7ab39cd-9250-40a9-b829-f11f65aae27d"));
user.setPersonalId(userPersonalId);
createUserRepository.create(user);

String supplyCode = "ES002100823465";
Supply supply = new Supply.Builder()
.withId(UUID.randomUUID())
.withCode(supplyCode)
.withAddress(RandomStringUtils.random(20, true, true))
.withPartitionCoefficient(new Random().nextFloat())
.withEnabled(true)
.withUser(user)
.build();
createSupplyRepository.create(supply, UserId.of(user.getId()));

// Act
PagedResult<Supply> result = getSupplyService.findAll(PagedRequest.of(0, 10));

// Assert
assertEquals(1, result.getItems().size());
assertEquals("ES002100823465", result.getItems().get(0).getCode());
assertNotNull(result.getItems().get(0).getId());
assertEquals(supply.getAddress(), result.getItems().get(0).getAddress());
assertEquals(supply.getName(), result.getItems().get(0).getName());
assertEquals(supply.getPartitionCoefficient(), result.getItems().get(0).getPartitionCoefficient());
assertEquals(supply.getEnabled(), result.getItems().get(0).getEnabled());
assertEquals("987654321S", result.getItems().get(0).getUser().getPersonalId());
}
}

0 comments on commit 391bb20

Please sign in to comment.