Added logs to ClientServiceTest
This commit is contained in:
@@ -29,6 +29,8 @@ public class ClientServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
@DisplayName("Test pobierania wszystkich klientów")
|
@DisplayName("Test pobierania wszystkich klientów")
|
||||||
public void testGetAllClients() {
|
public void testGetAllClients() {
|
||||||
|
System.out.println("Rozpoczęcie testu: testGetAllClients - Test pobierania wszystkich klientów");
|
||||||
|
|
||||||
Client client1 = new Client();
|
Client client1 = new Client();
|
||||||
client1.setId(1L);
|
client1.setId(1L);
|
||||||
client1.setEmail("client1@example.com");
|
client1.setEmail("client1@example.com");
|
||||||
@@ -43,17 +45,20 @@ public class ClientServiceTest {
|
|||||||
|
|
||||||
List<ClientDTO> clients = clientService.getAllClients();
|
List<ClientDTO> clients = clientService.getAllClients();
|
||||||
|
|
||||||
|
System.out.println("Pobrano listę klientów, liczba elementów: " + clients.size());
|
||||||
assertEquals(2, clients.size(), "Lista klientów powinna zawierać 2 elementy");
|
assertEquals(2, clients.size(), "Lista klientów powinna zawierać 2 elementy");
|
||||||
|
System.out.println("Pierwszy klient na liście: " + clients.getFirst().getEmail());
|
||||||
assertEquals("client1@example.com", clients.getFirst().getEmail(), "Email pierwszego klienta powinien być poprawny");
|
assertEquals("client1@example.com", clients.getFirst().getEmail(), "Email pierwszego klienta powinien być poprawny");
|
||||||
|
|
||||||
System.out.println("Test pobierania wszystkich klientów przeszedł pomyślnie.");
|
System.out.println("Test pobierania wszystkich klientów zakończony sukcesem. Zwrócono " + clients.size() + " klientów.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Test pobierania klienta po ID - klient istnieje")
|
@DisplayName("Test pobierania klienta po ID - klient istnieje")
|
||||||
public void testGetClientByIdExists() {
|
public void testGetClientByIdExists() {
|
||||||
// Przygotowanie danych
|
|
||||||
Long clientId = 1L;
|
Long clientId = 1L;
|
||||||
|
System.out.println("Rozpoczęcie testu: testGetClientByIdExists - Test pobierania klienta po ID (ID: " + clientId + ")");
|
||||||
|
|
||||||
Client client = new Client();
|
Client client = new Client();
|
||||||
client.setId(clientId);
|
client.setId(clientId);
|
||||||
client.setEmail("client@example.com");
|
client.setEmail("client@example.com");
|
||||||
@@ -63,29 +68,35 @@ public class ClientServiceTest {
|
|||||||
|
|
||||||
Client retrievedClient = clientService.getClientById(clientId);
|
Client retrievedClient = clientService.getClientById(clientId);
|
||||||
|
|
||||||
|
System.out.println("Pobrano klienta o ID: " + (retrievedClient != null ? retrievedClient.getId() : "null"));
|
||||||
assertNotNull(retrievedClient, "Pobrany klient nie powinien być null");
|
assertNotNull(retrievedClient, "Pobrany klient nie powinien być null");
|
||||||
assertEquals(clientId, retrievedClient.getId(), "ID klienta powinno być zgodne");
|
assertEquals(clientId, retrievedClient.getId(), "ID klienta powinno być zgodne");
|
||||||
|
|
||||||
System.out.println("Test pobierania klienta po ID (klient istnieje) przeszedł pomyślnie.");
|
System.out.println("Test pobierania klienta po ID (ID: " + clientId + ") zakończony sukcesem. Znaleziono klienta: " + retrievedClient.getEmail());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Test pobierania klienta po ID - klient nie istnieje")
|
@DisplayName("Test pobierania klienta po ID - klient nie istnieje")
|
||||||
public void testGetClientByIdNotExists() {
|
public void testGetClientByIdNotExists() {
|
||||||
Long clientId = 1L;
|
Long clientId = 1L;
|
||||||
|
System.out.println("Rozpoczęcie testu: testGetClientByIdNotExists - Test pobierania nieistniejącego klienta (ID: " + clientId + ")");
|
||||||
|
|
||||||
when(clientRepository.findById(clientId)).thenReturn(Optional.empty());
|
when(clientRepository.findById(clientId)).thenReturn(Optional.empty());
|
||||||
|
|
||||||
Client retrievedClient = clientService.getClientById(clientId);
|
Client retrievedClient = clientService.getClientById(clientId);
|
||||||
|
|
||||||
|
System.out.println("Próba pobrania nieistniejącego klienta zwróciła: " + retrievedClient);
|
||||||
assertNull(retrievedClient, "Pobrany klient powinien być null, gdy nie istnieje");
|
assertNull(retrievedClient, "Pobrany klient powinien być null, gdy nie istnieje");
|
||||||
|
|
||||||
System.out.println("Test pobierania klienta po ID (klient nie istnieje) przeszedł pomyślnie.");
|
System.out.println("Test pobierania nieistniejącego klienta (ID: " + clientId + ") zakończony sukcesem. Zwrócono null zgodnie z oczekiwaniami.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Test pobierania klienta po emailu")
|
@DisplayName("Test pobierania klienta po emailu")
|
||||||
public void testGetClientByEmail() {
|
public void testGetClientByEmail() {
|
||||||
String email = "client@example.com";
|
String email = "client@example.com";
|
||||||
|
System.out.println("Rozpoczęcie testu: testGetClientByEmail - Test pobierania klienta po emailu (" + email + ")");
|
||||||
|
|
||||||
Client client = new Client();
|
Client client = new Client();
|
||||||
client.setEmail(email);
|
client.setEmail(email);
|
||||||
|
|
||||||
@@ -93,16 +104,18 @@ public class ClientServiceTest {
|
|||||||
|
|
||||||
Client retrievedClient = clientService.getClientByEmail(email);
|
Client retrievedClient = clientService.getClientByEmail(email);
|
||||||
|
|
||||||
|
System.out.println("Pobrano klienta o emailu: " + (retrievedClient != null ? retrievedClient.getEmail() : "null"));
|
||||||
assertNotNull(retrievedClient, "Pobrany klient nie powinien być null");
|
assertNotNull(retrievedClient, "Pobrany klient nie powinien być null");
|
||||||
assertEquals(email, retrievedClient.getEmail(), "Email klienta powinien być zgodny");
|
assertEquals(email, retrievedClient.getEmail(), "Email klienta powinien być zgodny");
|
||||||
|
|
||||||
System.out.println("Test pobierania klienta po emailu przeszedł pomyślnie.");
|
System.out.println("Test pobierania klienta po emailu (" + email + ") zakończony sukcesem.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Test dodawania klienta")
|
@DisplayName("Test dodawania klienta")
|
||||||
public void testAddClient() {
|
public void testAddClient() {
|
||||||
// Przygotowanie danych
|
System.out.println("Rozpoczęcie testu: testAddClient - Test dodawania nowego klienta");
|
||||||
|
|
||||||
ClientDTO clientDTO = new ClientDTO();
|
ClientDTO clientDTO = new ClientDTO();
|
||||||
clientDTO.setEmail("newclient@example.com");
|
clientDTO.setEmail("newclient@example.com");
|
||||||
clientDTO.setRole("USER");
|
clientDTO.setRole("USER");
|
||||||
@@ -115,16 +128,19 @@ public class ClientServiceTest {
|
|||||||
|
|
||||||
ClientDTO addedClient = clientService.addClient(clientDTO);
|
ClientDTO addedClient = clientService.addClient(clientDTO);
|
||||||
|
|
||||||
|
System.out.println("Dodano nowego klienta: " + (addedClient != null ? addedClient.getEmail() : "null"));
|
||||||
assertNotNull(addedClient, "Dodany klient nie powinien być null");
|
assertNotNull(addedClient, "Dodany klient nie powinien być null");
|
||||||
assertEquals("newclient@example.com", addedClient.getEmail(), "Email dodanego klienta powinien być poprawny");
|
assertEquals("newclient@example.com", addedClient.getEmail(), "Email dodanego klienta powinien być poprawny");
|
||||||
|
|
||||||
System.out.println("Test dodawania klienta przeszedł pomyślnie.");
|
System.out.println("Test dodawania klienta zakończony sukcesem. Dodano klienta: " + addedClient.getEmail());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Test aktualizacji klienta")
|
@DisplayName("Test aktualizacji klienta")
|
||||||
public void testUpdateClient() {
|
public void testUpdateClient() {
|
||||||
Long clientId = 1L;
|
Long clientId = 1L;
|
||||||
|
System.out.println("Rozpoczęcie testu: testUpdateClient - Test aktualizacji klienta (ID: " + clientId + ")");
|
||||||
|
|
||||||
Client existingClient = new Client();
|
Client existingClient = new Client();
|
||||||
existingClient.setId(clientId);
|
existingClient.setId(clientId);
|
||||||
existingClient.setEmail("old@example.com");
|
existingClient.setEmail("old@example.com");
|
||||||
@@ -142,41 +158,49 @@ public class ClientServiceTest {
|
|||||||
|
|
||||||
ClientDTO updatedClient = clientService.updateClient(clientId, updatedDTO);
|
ClientDTO updatedClient = clientService.updateClient(clientId, updatedDTO);
|
||||||
|
|
||||||
|
System.out.println("Zaktualizowano klienta. Nowy email: " + updatedClient.getEmail());
|
||||||
assertEquals("updated@example.com", updatedClient.getEmail(), "Email klienta powinien być zaktualizowany");
|
assertEquals("updated@example.com", updatedClient.getEmail(), "Email klienta powinien być zaktualizowany");
|
||||||
|
|
||||||
System.out.println("Test aktualizacji klienta przeszedł pomyślnie.");
|
System.out.println("Test aktualizacji klienta (ID: " + clientId + ") zakończony sukcesem. Nowy email: " + updatedClient.getEmail());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Test aktualizacji klienta - klient nie istnieje")
|
@DisplayName("Test aktualizacji klienta - klient nie istnieje")
|
||||||
public void testUpdateClientNotExists() {
|
public void testUpdateClientNotExists() {
|
||||||
long clientId = 1L;
|
long clientId = 1L;
|
||||||
|
System.out.println("Rozpoczęcie testu: testUpdateClientNotExists - Test aktualizacji nieistniejącego klienta (ID: " + clientId + ")");
|
||||||
|
|
||||||
ClientDTO updatedDTO = new ClientDTO();
|
ClientDTO updatedDTO = new ClientDTO();
|
||||||
updatedDTO.setEmail("updated@example.com");
|
updatedDTO.setEmail("updated@example.com");
|
||||||
|
|
||||||
when(clientRepository.findById(clientId)).thenReturn(Optional.empty());
|
when(clientRepository.findById(clientId)).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
System.out.println("Oczekiwanie na EntityNotFoundException...");
|
||||||
assertThrows(EntityNotFoundException.class, () -> clientService.updateClient(clientId, updatedDTO),
|
assertThrows(EntityNotFoundException.class, () -> clientService.updateClient(clientId, updatedDTO),
|
||||||
"Powinien zostać rzucony EntityNotFoundException");
|
"Powinien zostać rzucony EntityNotFoundException");
|
||||||
|
|
||||||
System.out.println("Test aktualizacji klienta (klient nie istnieje) przeszedł pomyślnie.");
|
System.out.println("Test aktualizacji nieistniejącego klienta (ID: " + clientId + ") zakończony sukcesem. Rzucono wyjątek EntityNotFoundException zgodnie z oczekiwaniami.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Test usuwania klienta")
|
@DisplayName("Test usuwania klienta")
|
||||||
public void testDeleteClient() {
|
public void testDeleteClient() {
|
||||||
Long clientId = 1L;
|
Long clientId = 1L;
|
||||||
|
System.out.println("Rozpoczęcie testu: testDeleteClient - Test usuwania klienta (ID: " + clientId + ")");
|
||||||
|
|
||||||
clientService.deleteClient(clientId);
|
clientService.deleteClient(clientId);
|
||||||
|
|
||||||
verify(clientRepository, times(1)).deleteById(clientId);
|
verify(clientRepository, times(1)).deleteById(clientId);
|
||||||
|
System.out.println("Weryfikacja: metoda deleteById została wywołana 1 raz z ID: " + clientId);
|
||||||
|
|
||||||
System.out.println("Test usuwania klienta przeszedł pomyślnie.");
|
System.out.println("Test usuwania klienta (ID: " + clientId + ") zakończony sukcesem.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Test konwersji encji do DTO")
|
@DisplayName("Test konwersji encji do DTO")
|
||||||
public void testToDto() {
|
public void testToDto() {
|
||||||
|
System.out.println("Rozpoczęcie testu: testToDto - Test konwersji encji Client do ClientDTO");
|
||||||
|
|
||||||
Client client = new Client();
|
Client client = new Client();
|
||||||
client.setId(1L);
|
client.setId(1L);
|
||||||
client.setEmail("client@example.com");
|
client.setEmail("client@example.com");
|
||||||
@@ -187,8 +211,24 @@ public class ClientServiceTest {
|
|||||||
role.setRole("USER");
|
role.setRole("USER");
|
||||||
client.setRole(role);
|
client.setRole(role);
|
||||||
|
|
||||||
|
System.out.println("Przygotowano encję Client do konwersji:");
|
||||||
|
System.out.println("ID: " + client.getId());
|
||||||
|
System.out.println("Email: " + client.getEmail());
|
||||||
|
System.out.println("Imię: " + client.getFirstName());
|
||||||
|
System.out.println("Nazwisko: " + client.getLastName());
|
||||||
|
System.out.println("Obraz: " + client.getImage());
|
||||||
|
System.out.println("Rola: " + client.getRole().getRole());
|
||||||
|
|
||||||
ClientDTO dto = clientService.toDto(client);
|
ClientDTO dto = clientService.toDto(client);
|
||||||
|
|
||||||
|
System.out.println("Wynik konwersji do DTO:");
|
||||||
|
System.out.println("ID: " + dto.getId());
|
||||||
|
System.out.println("Email: " + dto.getEmail());
|
||||||
|
System.out.println("Imię: " + dto.getFirstName());
|
||||||
|
System.out.println("Nazwisko: " + dto.getLastName());
|
||||||
|
System.out.println("Obraz: " + dto.getImage());
|
||||||
|
System.out.println("Rola: " + dto.getRole());
|
||||||
|
|
||||||
assertEquals(1L, dto.getId(), "ID w DTO powinno być zgodne");
|
assertEquals(1L, dto.getId(), "ID w DTO powinno być zgodne");
|
||||||
assertEquals("client@example.com", dto.getEmail(), "Email w DTO powinien być zgodny");
|
assertEquals("client@example.com", dto.getEmail(), "Email w DTO powinien być zgodny");
|
||||||
assertEquals("Jan", dto.getFirstName(), "Imię w DTO powinno być zgodne");
|
assertEquals("Jan", dto.getFirstName(), "Imię w DTO powinno być zgodne");
|
||||||
@@ -196,7 +236,6 @@ public class ClientServiceTest {
|
|||||||
assertEquals("image.jpg", dto.getImage(), "Obraz w DTO powinien być zgodny");
|
assertEquals("image.jpg", dto.getImage(), "Obraz w DTO powinien być zgodny");
|
||||||
assertEquals("USER", dto.getRole(), "Rola w DTO powinna być zgodna");
|
assertEquals("USER", dto.getRole(), "Rola w DTO powinna być zgodna");
|
||||||
|
|
||||||
System.out.println("Test konwersji encji do DTO przeszedł pomyślnie.");
|
System.out.println("Test konwersji encji do DTO zakończony sukcesem. Wszystkie pola zostały poprawnie zmapowane.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user