fixed issues and tests
This commit is contained in:
parent
019bcc6411
commit
e64d4e6434
13
build.gradle
13
build.gradle
@ -6,7 +6,7 @@ plugins {
|
||||
|
||||
group = 'com.kalyshev'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '1.19'
|
||||
sourceCompatibility = '17'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@ -14,11 +14,20 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
||||
implementation 'org.springframework.boot:spring-boot-devtools'
|
||||
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
|
||||
|
||||
implementation 'org.webjars:bootstrap:5.1.3'
|
||||
implementation 'org.webjars:jquery:3.6.0'
|
||||
implementation 'org.webjars:font-awesome:6.1.0'
|
||||
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
implementation 'com.h2database:h2:2.1.210'
|
||||
|
||||
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5'
|
||||
implementation 'org.hibernate.validator:hibernate-validator'
|
||||
|
||||
implementation 'org.springdoc:springdoc-openapi-ui:1.6.5'
|
||||
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public class CabinetService {
|
||||
throw new IllegalArgumentException("Cabinet number is null or empty");
|
||||
}
|
||||
final Cabinet currentCabinet = findCabinet(id);
|
||||
currentCabinet.setnumber(number);
|
||||
currentCabinet.setNumber(number);
|
||||
validatorUtil.validate(currentCabinet);
|
||||
return cabinetRepository.save(currentCabinet);
|
||||
}
|
||||
|
@ -72,10 +72,10 @@ public class ComputerService {
|
||||
}
|
||||
final Computer currentComputer = findComputer(id);
|
||||
if (modelName != null) {
|
||||
currentComputer.setmodelName(modelName);
|
||||
currentComputer.setModelName(modelName);
|
||||
}
|
||||
if (serialNum != null) {
|
||||
currentComputer.setserialNum(serialNum);
|
||||
currentComputer.setSerialNum(serialNum);
|
||||
}
|
||||
if (monitorId != null) {
|
||||
Monitor monitor = monitorRepository.findById(monitorId)
|
||||
|
@ -67,7 +67,9 @@ public class MonitorService {
|
||||
public Monitor deleteMonitor(Long id) {
|
||||
final Monitor currentMonitor = findMonitor(id);
|
||||
Computer computer = getComputer(id);
|
||||
computer.removeMonitor();
|
||||
if (computer != null) {
|
||||
computer.removeMonitor();
|
||||
}
|
||||
monitorRepository.delete(currentMonitor);
|
||||
return currentMonitor;
|
||||
}
|
||||
@ -83,8 +85,10 @@ public class MonitorService {
|
||||
public Computer getComputer(Long id) {
|
||||
List<Computer> computers = computerRepository.findAll();
|
||||
for (Computer computer : computers) {
|
||||
if (Objects.equals(computer.getMonitor().getId(), id)) {
|
||||
return computer;
|
||||
if (computer.getMonitor() != null) {
|
||||
if (Objects.equals(computer.getMonitor().getId(), id)) {
|
||||
return computer;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -1,10 +1,9 @@
|
||||
package com.kalyshev.yan;
|
||||
|
||||
import com.kalyshev.yan.cabinet.model.Cabinet;
|
||||
import com.kalyshev.yan.cabinet.repository.CabinetNotFoundException;
|
||||
import com.kalyshev.yan.cabinet.service.CabinetService;
|
||||
import com.kalyshev.yan.computer.model.Computer;
|
||||
import com.kalyshev.yan.computer.service.ComputerService;
|
||||
import com.kalyshev.yan.monitor.model.Monitor;
|
||||
import com.kalyshev.yan.monitor.service.MonitorService;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
@ -45,7 +44,7 @@ public class JpaCabinetTests {
|
||||
@Test
|
||||
void testCabinetReadNotFound() {
|
||||
cabinetService.deleteAllCabinets();
|
||||
Assertions.assertThrows(EntityNotFoundException.class, () -> cabinetService.findCabinet(-1L));
|
||||
Assertions.assertThrows(CabinetNotFoundException.class, () -> cabinetService.findCabinet(-1L));
|
||||
}
|
||||
@Test
|
||||
void testCabinetReadAll() {
|
||||
|
@ -64,7 +64,7 @@ public class JpaComputerCabinetTests {
|
||||
computer.setCabinet(cabinet);
|
||||
log.info(cabinet.toString());
|
||||
log.info(computer.toString());
|
||||
Assertions.assertEquals(computer.getCabinet().getnumber(), cabinet.getnumber());
|
||||
Assertions.assertEquals(computer.getCabinet().getNumber(), cabinet.getNumber());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -78,7 +78,7 @@ public class JpaComputerCabinetTests {
|
||||
computer.setCabinet(cabinet);
|
||||
log.info(cabinet.toString());
|
||||
log.info(computer.toString());
|
||||
Assertions.assertEquals(computer.getCabinet().getnumber(), cabinet.getnumber());
|
||||
Assertions.assertEquals(computer.getCabinet().getNumber(), cabinet.getNumber());
|
||||
computer.setCabinet(null);
|
||||
Assertions.assertNull(computer.getCabinet());
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.kalyshev.yan;
|
||||
import com.kalyshev.yan.cabinet.model.Cabinet;
|
||||
import com.kalyshev.yan.cabinet.service.CabinetService;
|
||||
import com.kalyshev.yan.computer.model.Computer;
|
||||
import com.kalyshev.yan.computer.repository.ComputerNotFoundException;
|
||||
import com.kalyshev.yan.computer.service.ComputerService;
|
||||
import com.kalyshev.yan.monitor.model.Monitor;
|
||||
import com.kalyshev.yan.monitor.service.MonitorService;
|
||||
@ -52,7 +53,7 @@ public class JpaComputerTests {
|
||||
final Computer computer = computerService.addComputer("Computer", "w7894572", null, null);
|
||||
log.info(computer.toString());
|
||||
computerService.deleteComputer(computer.getId());
|
||||
Assertions.assertThrows(EntityNotFoundException.class, () -> computerService.findComputer(computer.getId()));
|
||||
Assertions.assertThrows(ComputerNotFoundException.class, () -> computerService.findComputer(computer.getId()));
|
||||
}
|
||||
@Test
|
||||
void testComputerRead() {
|
||||
@ -66,7 +67,7 @@ public class JpaComputerTests {
|
||||
@Test
|
||||
void testComputerReadNotFound() {
|
||||
computerService.deleteAllComputers();
|
||||
Assertions.assertThrows(EntityNotFoundException.class, () -> computerService.findComputer(-1L));
|
||||
Assertions.assertThrows(ComputerNotFoundException.class, () -> computerService.findComputer(-1L));
|
||||
}
|
||||
@Test
|
||||
void testComputerReadAll() {
|
||||
|
@ -4,6 +4,7 @@ import com.kalyshev.yan.cabinet.service.CabinetService;
|
||||
import com.kalyshev.yan.computer.model.Computer;
|
||||
import com.kalyshev.yan.computer.service.ComputerService;
|
||||
import com.kalyshev.yan.monitor.model.Monitor;
|
||||
import com.kalyshev.yan.monitor.repository.MonitorNotFoundException;
|
||||
import com.kalyshev.yan.monitor.service.MonitorService;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
@ -44,12 +45,12 @@ public class JpaMonitorTests {
|
||||
final Monitor monitor = monitorService.addMonitor("Asus");
|
||||
log.info(monitor.toString());
|
||||
monitorService.deleteMonitor(monitor.getId());
|
||||
Assertions.assertThrows(EntityNotFoundException.class, () -> monitorService.findMonitor(monitor.getId()));
|
||||
Assertions.assertThrows(MonitorNotFoundException.class, () -> monitorService.findMonitor(monitor.getId()));
|
||||
}
|
||||
@Test
|
||||
void testMonitorReadNotFound() {
|
||||
monitorService.deleteAllMonitors();
|
||||
Assertions.assertThrows(EntityNotFoundException.class, () -> monitorService.findMonitor(-1L));
|
||||
Assertions.assertThrows(MonitorNotFoundException.class, () -> monitorService.findMonitor(-1L));
|
||||
}
|
||||
@Test
|
||||
void testMonitorReadAll() {
|
||||
|
Loading…
Reference in New Issue
Block a user