diff --git a/README.md b/README.md
index 18e3296..8c235b5 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,9 @@
-#
W-net Internet
-
-
+# W-net Internet
-
-
## Context
This is an internet provider management system.
@@ -44,7 +40,7 @@ MAIL_PASSWORD=your-app-password
### Steps:
-1. Clone the repository:
+1. Clone repository:
```BASH
git clone git@github.com:mairess/w-net-internet.git
@@ -61,32 +57,34 @@ mvn install -DskipTests
3. Start ZooKeeper:
```BASH
-# Start ZooKeeper:
-
bin/zookeeper-server-start.sh config/zookeeper.properties
```
4. Start Kafka:
```BASH
-# Start Kafka:
-
bin/kafka-server-start.sh config/server.properties
```
-5. Start the database:
+5. Start database:
```BASH
docker compose up database -d --build
```
-6. Run the API:
+6. Run API:
```BASH
mvn spring-boot:run
```
-7. Access the API documentation and available routes on your web browser at:
+7. Run tests:
+
+```BASH
+mvn test
+```
+
+8. Access API documentation and available routes on your web browser at:
```BASH
http://localhost:8080/swagger-ui/index.html
@@ -114,7 +112,7 @@ MAIL_PASSWORD=your-app-password
### Steps:
-1. Clone the repository:
+1. Clone repository:
```BASH
git clone git@github.com:mairess/w-net-internet.git
@@ -122,19 +120,20 @@ git clone git@github.com:mairess/w-net-internet.git
cd w-net-internet
```
-2. Start application:
+2. Run API:
```BASH
docker compose up -d --build
```
-3. Access the API documentation and available routes on your web browser at:
+3. Run tests:
```BASH
-http://localhost:8080/swagger-ui/index.html
+mvn test
```
-# To do
+4. Access API documentation and available routes on your web browser at:
-- [ ] Tests
-- [x] authentication/authorization
\ No newline at end of file
+```BASH
+http://localhost:8080/swagger-ui/index.html
+```
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index d618873..56bbfb3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -36,6 +36,7 @@
true
**/controller/*
+ **/service/*
diff --git a/src/main/java/com/maires/wnet/service/exception/AddressNotFoundException.java b/src/main/java/com/maires/wnet/service/exception/AddressNotFoundException.java
index 1d81ca2..08a6098 100644
--- a/src/main/java/com/maires/wnet/service/exception/AddressNotFoundException.java
+++ b/src/main/java/com/maires/wnet/service/exception/AddressNotFoundException.java
@@ -9,7 +9,7 @@ public class AddressNotFoundException extends NotFoundException {
* Instantiates a new Address not found exception.
*/
public AddressNotFoundException(String identifier) {
- super("Address found with " + identifier + "!");
+ super("Address not found with identifier " + identifier + "!");
}
}
\ No newline at end of file
diff --git a/src/main/java/com/maires/wnet/service/exception/CustomerNotFoundException.java b/src/main/java/com/maires/wnet/service/exception/CustomerNotFoundException.java
index 10b1847..1165bc9 100644
--- a/src/main/java/com/maires/wnet/service/exception/CustomerNotFoundException.java
+++ b/src/main/java/com/maires/wnet/service/exception/CustomerNotFoundException.java
@@ -9,7 +9,7 @@ public class CustomerNotFoundException extends NotFoundException {
* Instantiates a new Customer not found exception.
*/
public CustomerNotFoundException(String identifier) {
- super("Customer not found with " + identifier + "!");
+ super("Customer not found with identifier " + identifier + "!");
}
}
\ No newline at end of file
diff --git a/src/main/java/com/maires/wnet/service/exception/TechnicianCannotBeExcludedException.java b/src/main/java/com/maires/wnet/service/exception/TechnicianCannotBeExcludedException.java
index 4ab4d23..e005c8c 100644
--- a/src/main/java/com/maires/wnet/service/exception/TechnicianCannotBeExcludedException.java
+++ b/src/main/java/com/maires/wnet/service/exception/TechnicianCannotBeExcludedException.java
@@ -9,6 +9,6 @@ public class TechnicianCannotBeExcludedException extends CannotBeExcludedExcepti
* Instantiates a new Technician cannot be excluded exception.
*/
public TechnicianCannotBeExcludedException() {
- super("This technician cannot be excluded because he has an association!");
+ super("This Technician cannot be excluded because he has an association!");
}
}
\ No newline at end of file
diff --git a/src/test/java/com/maires/wnet/integration/AddressIntegrationTest.java b/src/test/java/com/maires/wnet/integration/AddressIntegrationTest.java
index b7cad30..4fc20a8 100644
--- a/src/test/java/com/maires/wnet/integration/AddressIntegrationTest.java
+++ b/src/test/java/com/maires/wnet/integration/AddressIntegrationTest.java
@@ -14,12 +14,14 @@
import com.maires.wnet.entity.Customer;
import com.maires.wnet.entity.Equipment;
import com.maires.wnet.entity.EquipmentType;
+import com.maires.wnet.entity.Installation;
import com.maires.wnet.entity.Plan;
import com.maires.wnet.entity.Technician;
import com.maires.wnet.entity.User;
import com.maires.wnet.repository.AddressRepository;
import com.maires.wnet.repository.CustomerRepository;
import com.maires.wnet.repository.EquipmentRepository;
+import com.maires.wnet.repository.InstallationRepository;
import com.maires.wnet.repository.PlanRepository;
import com.maires.wnet.repository.TechnicianRepository;
import com.maires.wnet.repository.UserRepository;
@@ -67,6 +69,8 @@ public class AddressIntegrationTest {
@Autowired
CustomerRepository customerRepository;
@Autowired
+ InstallationRepository installationRepository;
+ @Autowired
MockMvc mockMvc;
@Autowired
private TokenService tokenService;
@@ -85,6 +89,9 @@ public void cleanUp() {
userRepository.deleteAll();
equipmentRepository.deleteAll();
addressRepository.deleteAll();
+ customerRepository.deleteAll();
+ technicianRepository.deleteAll();
+ planRepository.deleteAll();
User admin = new User(null, "System Manager Administrator", "admin@mail.com", "admin",
"segredo123",
Role.ADMIN);
@@ -161,6 +168,19 @@ public void testAddressRetrievalById() throws Exception {
.andExpect(jsonPath("$.complement").value("Próximo ao Parque Trianon"));
}
+ @Test
+ @DisplayName("Throw addressNotFoundException by id")
+ public void testAddressNotFoundExceptionById() throws Exception {
+
+ String addressUrl = "/addresses/666";
+
+ mockMvc.perform(get(addressUrl)
+ .header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenAdmin)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound())
+ .andExpect(jsonPath("$.message").value("Address not found with identifier 666!"));
+ }
+
@Test
@DisplayName("Create address installation")
public void testCreateAddressInstallation() throws Exception {
@@ -211,6 +231,231 @@ public void testCreateAddressInstallation() throws Exception {
.andExpect(status().isCreated());
}
+ @Test
+ @DisplayName("Throw AddressAlreadyAssociatedException")
+ public void testAddressAlreadyAssociatedException() throws Exception {
+
+ Address address = new Address(
+ "São Paulo", "São Paulo", "01000000", "Avenida Paulista", 1023, "Bela Vista",
+ "Próximo ao Parque Trianon");
+
+ Technician technician = new Technician("João Antônio Benevides Faria", "77011114444",
+ "joao@example.com");
+
+ Plan plan = new Plan("Speed og Thunder", 300, 70.0);
+
+ Equipment router = new Equipment(EquipmentType.ROUTER, "Asus RT-AC88U", "SN035", "Asus");
+ Equipment modem = new Equipment(EquipmentType.MODEM, "Motorola MG7700", "SN036", "Motorola");
+
+ Installation installation = new Installation();
+
+ address.setInstallation(installation);
+ addressRepository.save(address);
+
+ List equipmentList = new ArrayList<>();
+ equipmentList.add(router.getId());
+ equipmentList.add(modem.getId());
+
+ InstallationCreationDto installationDto = new InstallationCreationDto(plan.getId(),
+ technician.getId(), equipmentList);
+
+ ObjectMapper objectMapper = new ObjectMapper();
+ String newInstallationJson = objectMapper.writeValueAsString(installationDto);
+ String addressUrl = "/addresses/%s/installations".formatted(address.getId());
+
+ mockMvc.perform(post(addressUrl)
+ .header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenAdmin)
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON)
+ .content(newInstallationJson))
+ .andExpect(status().isConflict())
+ .andExpect(jsonPath("$.message").value("This address is already associated!"));
+ }
+
+ @Test
+ @DisplayName("Throw EquipmentAlreadyAssociatedException")
+ public void testEquipmentAlreadyAssociatedException() throws Exception {
+
+ Customer customer = new Customer(
+ "Graciliano Ramos de Oliveira",
+ "00011122233",
+ "77011223344",
+ "gracit@example.com"
+ );
+
+ customerRepository.save(customer);
+
+ Address address = new Address(
+ "São Paulo", "São Paulo", "01000000", "Avenida Paulista", 1023, "Bela Vista",
+ "Próximo ao Parque Trianon");
+
+ Technician technician = new Technician("João Antônio Benevides Faria", "77011114444",
+ "joao@example.com");
+ technicianRepository.save(technician);
+
+ Plan plan = new Plan("Speed og Thunder", 300, 70.0);
+ planRepository.save(plan);
+
+ Equipment router = new Equipment(EquipmentType.ROUTER, "Asus RT-AC88U", "SN035", "Asus");
+ Equipment modem = new Equipment(EquipmentType.MODEM, "Motorola MG7700", "SN036", "Motorola");
+
+ address.setCustomer(customer);
+ addressRepository.save(address);
+
+ Installation installation = new Installation();
+
+ installationRepository.save(installation);
+
+ router.setInstallation(installation);
+ modem.setInstallation(installation);
+ equipmentRepository.save(router);
+ equipmentRepository.save(modem);
+
+ List equipmentList = new ArrayList<>();
+ equipmentList.add(router.getId());
+ equipmentList.add(modem.getId());
+
+ InstallationCreationDto installationDto = new InstallationCreationDto(plan.getId(),
+ technician.getId(), equipmentList);
+
+ ObjectMapper objectMapper = new ObjectMapper();
+ String newInstallationJson = objectMapper.writeValueAsString(installationDto);
+ String addressUrl = "/addresses/%s/installations".formatted(address.getId());
+
+ mockMvc.perform(post(addressUrl)
+ .header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenAdmin)
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON)
+ .content(newInstallationJson))
+ .andExpect(status().isConflict())
+ .andExpect(jsonPath("$.message").value("This equipment is already associated!"));
+ }
+
+ @Test
+ @DisplayName("Throw AddressNotFoundException by creating installation")
+ public void testAddressNotFoundExceptionByCreatingInstallation() throws Exception {
+
+ Technician technician = new Technician("João Antônio Benevides Faria", "77011114444",
+ "joao@example.com");
+ technicianRepository.save(technician);
+
+ Plan plan = new Plan("Speed og Thunder", 300, 70.0);
+ planRepository.save(plan);
+
+ List equipmentList = new ArrayList<>();
+
+ InstallationCreationDto installationDto = new InstallationCreationDto(plan.getId(),
+ technician.getId(), equipmentList);
+
+ ObjectMapper objectMapper = new ObjectMapper();
+ String newInstallationJson = objectMapper.writeValueAsString(installationDto);
+ String addressUrl = "/addresses/666/installations";
+
+ mockMvc.perform(post(addressUrl)
+ .header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenAdmin)
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON)
+ .content(newInstallationJson))
+ .andExpect(status().isNotFound())
+ .andExpect(jsonPath("$.message").value("Address not found with identifier 666!"));
+ }
+
+ @Test
+ @DisplayName("Throw PlanNotFoundException by creating installation")
+ public void testPlanNotFoundExceptionByCreatingInstallation() throws Exception {
+
+ Address address = new Address(
+ "São Paulo", "São Paulo", "01000000", "Avenida Paulista", 1023, "Bela Vista",
+ "Próximo ao Parque Trianon");
+ addressRepository.save(address);
+
+ Technician technician = new Technician("João Antônio Benevides Faria", "77011114444",
+ "joao@example.com");
+ technicianRepository.save(technician);
+
+ List equipmentList = new ArrayList<>();
+
+ InstallationCreationDto installationDto = new InstallationCreationDto(666L,
+ technician.getId(), equipmentList);
+
+ ObjectMapper objectMapper = new ObjectMapper();
+ String newInstallationJson = objectMapper.writeValueAsString(installationDto);
+ String addressUrl = "/addresses/%s/installations".formatted(address.getId());
+
+ mockMvc.perform(post(addressUrl)
+ .header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenAdmin)
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON)
+ .content(newInstallationJson))
+ .andExpect(status().isNotFound())
+ .andExpect(jsonPath("$.message").value("Plan not found with identifier 666!"));
+ }
+
+ @Test
+ @DisplayName("Throw TechnicianNotFoundException by creating installation")
+ public void testTechnicianNotFoundExceptionByCreatingInstallation() throws Exception {
+
+ Address address = new Address(
+ "São Paulo", "São Paulo", "01000000", "Avenida Paulista", 1023, "Bela Vista",
+ "Próximo ao Parque Trianon");
+ addressRepository.save(address);
+
+ Plan plan = new Plan("Speed og Thunder", 300, 70.0);
+ planRepository.save(plan);
+
+ List equipmentList = new ArrayList<>();
+
+ InstallationCreationDto installationDto = new InstallationCreationDto(plan.getId(),
+ 666L, equipmentList);
+
+ ObjectMapper objectMapper = new ObjectMapper();
+ String newInstallationJson = objectMapper.writeValueAsString(installationDto);
+ String addressUrl = "/addresses/%s/installations".formatted(address.getId());
+
+ mockMvc.perform(post(addressUrl)
+ .header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenAdmin)
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON)
+ .content(newInstallationJson))
+ .andExpect(status().isNotFound())
+ .andExpect(jsonPath("$.message").value("Technician not found with identifier 666!"));
+ }
+
+ @Test
+ @DisplayName("Throw EquipmentNotFoundException by creating installation")
+ public void testEquipmentNotFoundExceptionByCreatingInstallation() throws Exception {
+
+ Address address = new Address(
+ "São Paulo", "São Paulo", "01000000", "Avenida Paulista", 1023, "Bela Vista",
+ "Próximo ao Parque Trianon");
+ addressRepository.save(address);
+
+ Plan plan = new Plan("Speed og Thunder", 300, 70.0);
+ planRepository.save(plan);
+
+ Technician technician = new Technician("João Antônio Benevides Faria", "77011114444",
+ "joao@example.com");
+ technicianRepository.save(technician);
+
+ List equipmentList = new ArrayList<>();
+ equipmentList.add(666L);
+
+ InstallationCreationDto installationDto = new InstallationCreationDto(plan.getId(),
+ technician.getId(), equipmentList);
+
+ ObjectMapper objectMapper = new ObjectMapper();
+ String newInstallationJson = objectMapper.writeValueAsString(installationDto);
+ String addressUrl = "/addresses/%s/installations".formatted(address.getId());
+
+ mockMvc.perform(post(addressUrl)
+ .header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenAdmin)
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON)
+ .content(newInstallationJson))
+ .andExpect(status().isNotFound())
+ .andExpect(jsonPath("$.message").value("Equipment not found with identifier 666!"));
+ }
+
@Test
@DisplayName("Update address")
public void testUpdateAddress() throws Exception {
@@ -249,25 +494,70 @@ public void testUpdateAddress() throws Exception {
@DisplayName("Delete Address")
public void testDeleteAddress() throws Exception {
+// Address addressToDelete = new Address(
+// "São Paulo", "São Paulo", "01000000", "Avenida Paulista", 1023, "Bela Vista",
+// "Próximo ao Parque Trianon");
+//
+// addressRepository.save(addressToDelete);
+//
+// String addressUrl = "/addresses/%s".formatted(addressToDelete.getId());
+//
+// mockMvc.perform(delete(addressUrl)
+// .header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenAdmin)
+// .accept(MediaType.APPLICATION_JSON))
+// .andExpect(status().isOk())
+// .andExpect(jsonPath("$.id").exists())
+// .andExpect(jsonPath("$.city").value("São Paulo"))
+// .andExpect(jsonPath("$.zipCode").value("01000000"))
+// .andExpect(jsonPath("$.street").value("Avenida Paulista"))
+// .andExpect(jsonPath("$.streetNumber").value(1023))
+// .andExpect(jsonPath("$.neighborhood").value("Bela Vista"))
+// .andExpect(jsonPath("$.complement").value("Próximo ao Parque Trianon"));
+
+ Customer customer = new Customer(
+ "Graciliano Ramos de Oliveira",
+ "00011122233",
+ "77011223344",
+ "gracit@example.com"
+ );
+
Address addressToDelete = new Address(
"São Paulo", "São Paulo", "01000000", "Avenida Paulista", 1023, "Bela Vista",
"Próximo ao Parque Trianon");
+ Technician technician = new Technician("João Antônio Benevides Faria", "77011114444",
+ "joao@example.com");
+
+ Plan plan = new Plan("Speed og Thunder", 300, 70.0);
+
+ Equipment router = new Equipment(EquipmentType.ROUTER, "Asus RT-AC88U", "SN035", "Asus");
+ Equipment modem = new Equipment(EquipmentType.MODEM, "Motorola MG7700", "SN036", "Motorola");
+
+ addressToDelete.setCustomer(customer);
+ customerRepository.save(customer);
addressRepository.save(addressToDelete);
+ technicianRepository.save(technician);
+ planRepository.save(plan);
+ equipmentRepository.save(router);
+ equipmentRepository.save(modem);
+
+ List equipmentList = new ArrayList<>();
+ equipmentList.add(router.getId());
+ equipmentList.add(modem.getId());
+
+ InstallationCreationDto installationDto = new InstallationCreationDto(plan.getId(),
+ technician.getId(), equipmentList);
+ ObjectMapper objectMapper = new ObjectMapper();
+ String newInstallationJson = objectMapper.writeValueAsString(installationDto);
String addressUrl = "/addresses/%s".formatted(addressToDelete.getId());
mockMvc.perform(delete(addressUrl)
.header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenAdmin)
- .accept(MediaType.APPLICATION_JSON))
- .andExpect(status().isOk())
- .andExpect(jsonPath("$.id").exists())
- .andExpect(jsonPath("$.city").value("São Paulo"))
- .andExpect(jsonPath("$.zipCode").value("01000000"))
- .andExpect(jsonPath("$.street").value("Avenida Paulista"))
- .andExpect(jsonPath("$.streetNumber").value(1023))
- .andExpect(jsonPath("$.neighborhood").value("Bela Vista"))
- .andExpect(jsonPath("$.complement").value("Próximo ao Parque Trianon"));
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON)
+ .content(newInstallationJson))
+ .andExpect(status().isOk());
}
}
\ No newline at end of file
diff --git a/src/test/java/com/maires/wnet/integration/CustomerIntegrationTest.java b/src/test/java/com/maires/wnet/integration/CustomerIntegrationTest.java
index f466a21..490f4c5 100644
--- a/src/test/java/com/maires/wnet/integration/CustomerIntegrationTest.java
+++ b/src/test/java/com/maires/wnet/integration/CustomerIntegrationTest.java
@@ -13,6 +13,10 @@
import com.maires.wnet.entity.User;
import com.maires.wnet.repository.AddressRepository;
import com.maires.wnet.repository.CustomerRepository;
+import com.maires.wnet.repository.EquipmentRepository;
+import com.maires.wnet.repository.InstallationRepository;
+import com.maires.wnet.repository.PlanRepository;
+import com.maires.wnet.repository.TechnicianRepository;
import com.maires.wnet.repository.UserRepository;
import com.maires.wnet.security.Role;
import com.maires.wnet.service.TokenService;
@@ -51,6 +55,14 @@ public class CustomerIntegrationTest {
@Autowired
UserRepository userRepository;
@Autowired
+ TechnicianRepository technicianRepository;
+ @Autowired
+ EquipmentRepository equipmentRepository;
+ @Autowired
+ PlanRepository planRepository;
+ @Autowired
+ InstallationRepository installationRepository;
+ @Autowired
MockMvc mockMvc;
@Autowired
private TokenService tokenService;
@@ -121,6 +133,19 @@ public void testCustomerRetrievalById() throws Exception {
.andExpect(jsonPath("$.email").value("machado@mail.com"));
}
+ @Test
+ @DisplayName("Throw customerNotFoundException by id")
+ public void testCustomerNotFoundExceptionById() throws Exception {
+
+ String customerUrl = "/customers/666";
+
+ mockMvc.perform(get(customerUrl)
+ .header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenAdmin)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound())
+ .andExpect(jsonPath("$.message").value("Customer not found with identifier 666!"));
+ }
+
@Test
@DisplayName("Retrieval all addresses by customer")
public void testAddressesRetrievalByCustomer() throws Exception {
@@ -168,6 +193,19 @@ public void testAddressesRetrievalByCustomer() throws Exception {
.andExpect(jsonPath("$[1].streetNumber").value(nullValue()));
}
+ @Test
+ @DisplayName("Throw customerNotFoundException by address")
+ public void testCustomerNotFoundExceptionByAddress() throws Exception {
+
+ String customerUrl = "/customers/666/addresses";
+
+ mockMvc.perform(get(customerUrl)
+ .header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenAdmin)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound())
+ .andExpect(jsonPath("$.message").value("Customer not found with identifier 666!"));
+ }
+
@Test
@DisplayName("Create customer")
public void testCreateCustomer() throws Exception {
@@ -263,6 +301,34 @@ public void testCreateCustomerAddress() throws Exception {
.andExpect(jsonPath("$.complement").value("Próximo ao Parque Trianon"));
}
+ @Test
+ @DisplayName("Throw customerNotFoundException by creating address")
+ public void testCustomerNotFoundExceptionByCreateAddress() throws Exception {
+
+ Address newAddress = new Address(
+ "São Paulo",
+ "São Paulo",
+ "01000000",
+ "Avenida Paulista",
+ 1023,
+ "Bela Vista",
+ "Próximo ao Parque Trianon"
+
+ );
+
+ ObjectMapper objectMapper = new ObjectMapper();
+ String newAddressJson = objectMapper.writeValueAsString(newAddress);
+ String customerUrl = "/customers/666/addresses";
+
+ mockMvc.perform(post(customerUrl)
+ .header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenAdmin)
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON)
+ .content(newAddressJson))
+ .andExpect(status().isNotFound())
+ .andExpect(jsonPath("$.message").value("Customer not found with identifier 666!"));
+ }
+
@Test
@DisplayName("Delete Customer")
public void testDeleteCustomer() throws Exception {
diff --git a/src/test/java/com/maires/wnet/integration/EquipmentIntegrationTest.java b/src/test/java/com/maires/wnet/integration/EquipmentIntegrationTest.java
index e4e065e..caafca0 100644
--- a/src/test/java/com/maires/wnet/integration/EquipmentIntegrationTest.java
+++ b/src/test/java/com/maires/wnet/integration/EquipmentIntegrationTest.java
@@ -9,8 +9,10 @@
import com.maires.wnet.entity.Equipment;
import com.maires.wnet.entity.EquipmentType;
+import com.maires.wnet.entity.Installation;
import com.maires.wnet.entity.User;
import com.maires.wnet.repository.EquipmentRepository;
+import com.maires.wnet.repository.InstallationRepository;
import com.maires.wnet.repository.UserRepository;
import com.maires.wnet.security.Role;
import com.maires.wnet.service.TokenService;
@@ -47,6 +49,8 @@ public class EquipmentIntegrationTest {
@Autowired
UserRepository userRepository;
@Autowired
+ InstallationRepository installationRepository;
+ @Autowired
MockMvc mockMvc;
@Autowired
private TokenService tokenService;
@@ -109,6 +113,19 @@ public void testEquipmentRetrievalById() throws Exception {
.andExpect(jsonPath("$.model").value("TP-Link Deco M4"));
}
+ @Test
+ @DisplayName("Throw equipmentNotFoundException")
+ public void testEquipmentNotFoundExceptionById() throws Exception {
+
+ String equipmentUrl = "/equipments/666";
+
+ mockMvc.perform(get(equipmentUrl)
+ .header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenAdmin)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound())
+ .andExpect(jsonPath("$.message").value("Equipment not found with identifier 666!"));
+ }
+
@Test
@DisplayName("Create equipment")
public void testCreateEquipment() throws Exception {
@@ -183,4 +200,27 @@ public void testDeleteEquipment() throws Exception {
.andExpect(jsonPath("$.manufacturer").value("TP-Link"));
}
+ @Test
+ @DisplayName("Throw equipmentCannotBeExcludedException")
+ public void testEquipmentCannotBeExcludedException() throws Exception {
+
+ Equipment equipmentToDelete = new Equipment(EquipmentType.ROUTER, "TP-Link Deco M4", "SN5332",
+ "TP-Link");
+
+ Installation installation = new Installation();
+ installationRepository.save(installation);
+
+ equipmentToDelete.setInstallation(installation);
+ equipmentRepository.save(equipmentToDelete);
+
+ String equipmentUrl = "/equipments/%s".formatted(equipmentToDelete.getId());
+
+ mockMvc.perform(delete(equipmentUrl)
+ .header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenAdmin)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isConflict())
+ .andExpect(jsonPath("$.message").value(
+ "This equipment cannot be excluded because it has an association!"));
+ }
+
}
\ No newline at end of file
diff --git a/src/test/java/com/maires/wnet/integration/PlanIntegrationTest.java b/src/test/java/com/maires/wnet/integration/PlanIntegrationTest.java
index 6623424..91a1a3c 100644
--- a/src/test/java/com/maires/wnet/integration/PlanIntegrationTest.java
+++ b/src/test/java/com/maires/wnet/integration/PlanIntegrationTest.java
@@ -7,12 +7,25 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import com.maires.wnet.entity.Address;
+import com.maires.wnet.entity.Customer;
+import com.maires.wnet.entity.Equipment;
+import com.maires.wnet.entity.EquipmentType;
+import com.maires.wnet.entity.Installation;
import com.maires.wnet.entity.Plan;
+import com.maires.wnet.entity.Technician;
import com.maires.wnet.entity.User;
+import com.maires.wnet.repository.AddressRepository;
+import com.maires.wnet.repository.CustomerRepository;
+import com.maires.wnet.repository.EquipmentRepository;
+import com.maires.wnet.repository.InstallationRepository;
import com.maires.wnet.repository.PlanRepository;
+import com.maires.wnet.repository.TechnicianRepository;
import com.maires.wnet.repository.UserRepository;
import com.maires.wnet.security.Role;
import com.maires.wnet.service.TokenService;
+import java.util.ArrayList;
+import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@@ -46,6 +59,16 @@ public class PlanIntegrationTest {
@Autowired
UserRepository userRepository;
@Autowired
+ AddressRepository addressRepository;
+ @Autowired
+ TechnicianRepository technicianRepository;
+ @Autowired
+ EquipmentRepository equipmentRepository;
+ @Autowired
+ CustomerRepository customerRepository;
+ @Autowired
+ InstallationRepository installationRepository;
+ @Autowired
MockMvc mockMvc;
@Autowired
private TokenService tokenService;
@@ -108,6 +131,19 @@ public void testPlanRetrievalById() throws Exception {
.andExpect(jsonPath("$.price").value(100.0));
}
+ @Test
+ @DisplayName("Throw planNotFoundException")
+ public void testPlanNotFoundExceptionById() throws Exception {
+
+ String planUrl = "/plans/666";
+
+ mockMvc.perform(get(planUrl)
+ .header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenAdmin)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound())
+ .andExpect(jsonPath("$.message").value("Plan not found with identifier 666!"));
+ }
+
@Test
@DisplayName("Create plan")
public void testCreatePlan() throws Exception {
@@ -176,4 +212,53 @@ public void testDeletePlan() throws Exception {
.andExpect(jsonPath("$.price").value(100.0));
}
+ @Test
+ @DisplayName("Throw planCannotBeExcludedException")
+ public void testPlanCannotBeExcludedException() throws Exception {
+
+ Customer customer = new Customer(
+ "Graciliano Ramos de Oliveira",
+ "00011122233",
+ "77011223344",
+ "gracit@example.com"
+ );
+
+ Address home = new Address(
+ "São Paulo", "São Paulo", "01000000", "Avenida Paulista", 1023, "Bela Vista",
+ "Próximo ao Parque Trianon");
+
+ Technician technician = new Technician("João Antônio Benevides Faria", "77011114444",
+ "joao@example.com");
+
+ Plan plan = new Plan("Speed og Thunder", 300, 70.0);
+
+ Equipment router = new Equipment(EquipmentType.ROUTER, "Asus RT-AC88U", "SN035", "Asus");
+ Equipment modem = new Equipment(EquipmentType.MODEM, "Motorola MG7700", "SN036", "Motorola");
+
+ home.setCustomer(customer);
+ customerRepository.save(customer);
+ addressRepository.save(home);
+ technicianRepository.save(technician);
+ planRepository.save(plan);
+ equipmentRepository.save(router);
+ equipmentRepository.save(modem);
+
+ List equipmentList = new ArrayList<>();
+ equipmentList.add(router);
+ equipmentList.add(modem);
+
+ Installation installation = new Installation(home, plan, technician, equipmentList);
+
+ installationRepository.save(installation);
+
+ String planUrl = "/plans/%s".formatted(plan.getId());
+
+ mockMvc.perform(delete(planUrl)
+ .header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenAdmin)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isConflict())
+ .andExpect(jsonPath("$.message").value(
+ "This Plan cannot be excluded because it has an association!"));
+ }
+
}
\ No newline at end of file
diff --git a/src/test/java/com/maires/wnet/integration/TechnicianIntegrationTest.java b/src/test/java/com/maires/wnet/integration/TechnicianIntegrationTest.java
index ad64382..c3e6c38 100644
--- a/src/test/java/com/maires/wnet/integration/TechnicianIntegrationTest.java
+++ b/src/test/java/com/maires/wnet/integration/TechnicianIntegrationTest.java
@@ -7,12 +7,25 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import com.maires.wnet.entity.Address;
+import com.maires.wnet.entity.Customer;
+import com.maires.wnet.entity.Equipment;
+import com.maires.wnet.entity.EquipmentType;
+import com.maires.wnet.entity.Installation;
+import com.maires.wnet.entity.Plan;
import com.maires.wnet.entity.Technician;
import com.maires.wnet.entity.User;
+import com.maires.wnet.repository.AddressRepository;
+import com.maires.wnet.repository.CustomerRepository;
+import com.maires.wnet.repository.EquipmentRepository;
+import com.maires.wnet.repository.InstallationRepository;
+import com.maires.wnet.repository.PlanRepository;
import com.maires.wnet.repository.TechnicianRepository;
import com.maires.wnet.repository.UserRepository;
import com.maires.wnet.security.Role;
import com.maires.wnet.service.TokenService;
+import java.util.ArrayList;
+import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@@ -46,6 +59,16 @@ public class TechnicianIntegrationTest {
@Autowired
UserRepository userRepository;
@Autowired
+ AddressRepository addressRepository;
+ @Autowired
+ EquipmentRepository equipmentRepository;
+ @Autowired
+ CustomerRepository customerRepository;
+ @Autowired
+ InstallationRepository installationRepository;
+ @Autowired
+ PlanRepository planRepository;
+ @Autowired
MockMvc mockMvc;
@Autowired
private TokenService tokenService;
@@ -63,6 +86,7 @@ public static void overrideProperties(DynamicPropertyRegistry registry) {
@BeforeEach
public void cleanUp() {
userRepository.deleteAll();
+ installationRepository.deleteAll();
technicianRepository.deleteAll();
User admin = new User(null, "System Manager Administrator", "admin@mail.com", "admin",
"segredo123",
@@ -114,6 +138,19 @@ public void testTechnicianRetrievalById() throws Exception {
.andExpect(jsonPath("$.email").value("amarildo@mail.com"));
}
+ @Test
+ @DisplayName("Throw technicianNotFoundException")
+ public void testTechnicianNotFoundExceptionById() throws Exception {
+
+ String technicianUrl = "/technicians/666";
+
+ mockMvc.perform(get(technicianUrl)
+ .header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenAdmin)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound())
+ .andExpect(jsonPath("$.message").value("Technician not found with identifier 666!"));
+ }
+
@Test
@DisplayName("Create technician")
public void testCreateTechnician() throws Exception {
@@ -184,4 +221,53 @@ public void testDeleteTechnician() throws Exception {
.andExpect(jsonPath("$.email").value("amarildo@mail.com"));
}
+ @Test
+ @DisplayName("Throw technicianCannotBeExcludedException")
+ public void testTechnicianCannotBeExcludedException() throws Exception {
+
+ Customer customer = new Customer(
+ "Graciliano Ramos de Oliveira",
+ "00011122233",
+ "77011223344",
+ "gracit@example.com"
+ );
+
+ Address home = new Address(
+ "São Paulo", "São Paulo", "01000000", "Avenida Paulista", 1023, "Bela Vista",
+ "Próximo ao Parque Trianon");
+
+ Technician technician = new Technician("João Antônio Benevides Faria", "77011114444",
+ "joao@example.com");
+
+ Plan plan = new Plan("Speed og Thunder", 300, 70.0);
+
+ Equipment router = new Equipment(EquipmentType.ROUTER, "Asus RT-AC88U", "SN035", "Asus");
+ Equipment modem = new Equipment(EquipmentType.MODEM, "Motorola MG7700", "SN036", "Motorola");
+
+ home.setCustomer(customer);
+ customerRepository.save(customer);
+ addressRepository.save(home);
+ technicianRepository.save(technician);
+ planRepository.save(plan);
+ equipmentRepository.save(router);
+ equipmentRepository.save(modem);
+
+ List equipmentList = new ArrayList<>();
+ equipmentList.add(router);
+ equipmentList.add(modem);
+
+ Installation installation = new Installation(home, plan, technician, equipmentList);
+
+ installationRepository.save(installation);
+
+ String technicianUrl = "/technicians/%s".formatted(technician.getId());
+
+ mockMvc.perform(delete(technicianUrl)
+ .header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenAdmin)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isConflict())
+ .andExpect(jsonPath("$.message").value(
+ "This Technician cannot be excluded because he has an association!"));
+ }
+
}
\ No newline at end of file
diff --git a/src/test/java/com/maires/wnet/integration/UserIntegrationTest.java b/src/test/java/com/maires/wnet/integration/UserIntegrationTest.java
index a62427d..f413441 100644
--- a/src/test/java/com/maires/wnet/integration/UserIntegrationTest.java
+++ b/src/test/java/com/maires/wnet/integration/UserIntegrationTest.java
@@ -112,6 +112,19 @@ public void testUserRetrievalById() throws Exception {
.andExpect(jsonPath("$.role").value("ADMIN"));
}
+ @Test
+ @DisplayName("Throw userNotFoundException by id")
+ public void testUserNotFoundExceptionById() throws Exception {
+
+ String userUrl = "/users/666";
+
+ mockMvc.perform(get(userUrl)
+ .header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenAdmin)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound())
+ .andExpect(jsonPath("$.message").value("User not found with identifier 666!"));
+ }
+
@Test
@DisplayName("Retrieval user by username")
public void testUserRetrievalByUsername() throws Exception {
@@ -129,6 +142,19 @@ public void testUserRetrievalByUsername() throws Exception {
.andExpect(jsonPath("$.role").value("ADMIN"));
}
+ @Test
+ @DisplayName("Throw userNotFoundException by username")
+ public void testUserNotFoundExceptionByUsername() throws Exception {
+
+ String userUrl = "/users/find?username=doesNotExists";
+
+ mockMvc.perform(get(userUrl)
+ .header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenAdmin)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound())
+ .andExpect(jsonPath("$.message").value("User not found with identifier doesNotExists!"));
+ }
+
@Test
@DisplayName("Create user")
public void testCreateUser() throws Exception {