Tests
This commit is contained in:
parent
64bf9c3624
commit
9d3af0e9f6
@ -1,33 +1,33 @@
|
|||||||
package de.szut.lf8_starter.config;
|
package de.szut.lf8_starter.config;
|
||||||
|
|
||||||
|
|
||||||
import de.szut.lf8_starter.hello.HelloEntity;
|
import de.szut.lf8_starter.hello.HelloEntity;
|
||||||
import de.szut.lf8_starter.hello.HelloRepository;
|
import de.szut.lf8_starter.hello.HelloRepository;
|
||||||
import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationArguments;
|
||||||
import org.springframework.boot.ApplicationRunner;
|
import org.springframework.boot.ApplicationRunner;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class SampleDataCreator implements ApplicationRunner {
|
public class SampleDataCreator implements ApplicationRunner {
|
||||||
|
|
||||||
private HelloRepository repository;
|
private HelloRepository repository;
|
||||||
|
|
||||||
public SampleDataCreator(HelloRepository repository) {
|
public SampleDataCreator(HelloRepository repository) {
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run(ApplicationArguments args) {
|
public void run(ApplicationArguments args) {
|
||||||
repository.save(new HelloEntity("Hallo Welt!"));
|
repository.save(new HelloEntity("Hallo Welt!"));
|
||||||
repository.save(new HelloEntity("Schöner Tag heute"));
|
repository.save(new HelloEntity("Schöner Tag heute"));
|
||||||
repository.save(new HelloEntity("FooBar"));
|
repository.save(new HelloEntity("FooBar"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public RestTemplate restTemplate() {
|
public RestTemplate restTemplate() {
|
||||||
return new RestTemplate();
|
return new RestTemplate();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,99 +1,99 @@
|
|||||||
package de.szut.lf8_starter.hello;
|
package de.szut.lf8_starter.hello;
|
||||||
|
|
||||||
|
|
||||||
import de.szut.lf8_starter.exceptionHandling.ResourceNotFoundException;
|
import de.szut.lf8_starter.exceptionHandling.ResourceNotFoundException;
|
||||||
import de.szut.lf8_starter.hello.dto.HelloCreateDto;
|
import de.szut.lf8_starter.hello.dto.HelloCreateDto;
|
||||||
import de.szut.lf8_starter.hello.dto.HelloGetDto;
|
import de.szut.lf8_starter.hello.dto.HelloGetDto;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.media.Content;
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(value = "hello")
|
@RequestMapping(value = "hello")
|
||||||
@PreAuthorize("hasAnyAuthority('user')")
|
@PreAuthorize("hasAnyAuthority('user')")
|
||||||
public class HelloController {
|
public class HelloController {
|
||||||
private final HelloService service;
|
private final HelloService service;
|
||||||
private final HelloMapper helloMapper;
|
private final HelloMapper helloMapper;
|
||||||
|
|
||||||
public HelloController(HelloService service, HelloMapper mappingService) {
|
public HelloController(HelloService service, HelloMapper mappingService) {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
this.helloMapper = mappingService;
|
this.helloMapper = mappingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "creates a new hello with its id and message")
|
@Operation(summary = "creates a new hello with its id and message")
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(responseCode = "201", description = "created hello",
|
@ApiResponse(responseCode = "201", description = "created hello",
|
||||||
content = {@Content(mediaType = "application/json",
|
content = {@Content(mediaType = "application/json",
|
||||||
schema = @Schema(implementation = HelloGetDto.class))}),
|
schema = @Schema(implementation = HelloGetDto.class))}),
|
||||||
@ApiResponse(responseCode = "400", description = "invalid JSON posted",
|
@ApiResponse(responseCode = "400", description = "invalid JSON posted",
|
||||||
content = @Content),
|
content = @Content),
|
||||||
@ApiResponse(responseCode = "401", description = "not authorized",
|
@ApiResponse(responseCode = "401", description = "not authorized",
|
||||||
content = @Content)})
|
content = @Content)})
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public HelloGetDto create(@RequestBody @Valid HelloCreateDto helloCreateDto) {
|
public HelloGetDto create(@RequestBody @Valid HelloCreateDto helloCreateDto) {
|
||||||
HelloEntity helloEntity = this.helloMapper.mapCreateDtoToEntity(helloCreateDto);
|
HelloEntity helloEntity = this.helloMapper.mapCreateDtoToEntity(helloCreateDto);
|
||||||
helloEntity = this.service.create(helloEntity);
|
helloEntity = this.service.create(helloEntity);
|
||||||
return this.helloMapper.mapToGetDto(helloEntity);
|
return this.helloMapper.mapToGetDto(helloEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "delivers a list of hellos")
|
@Operation(summary = "delivers a list of hellos")
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(responseCode = "200", description = "list of hellos",
|
@ApiResponse(responseCode = "200", description = "list of hellos",
|
||||||
content = {@Content(mediaType = "application/json",
|
content = {@Content(mediaType = "application/json",
|
||||||
schema = @Schema(implementation = HelloGetDto.class))}),
|
schema = @Schema(implementation = HelloGetDto.class))}),
|
||||||
@ApiResponse(responseCode = "401", description = "not authorized",
|
@ApiResponse(responseCode = "401", description = "not authorized",
|
||||||
content = @Content)})
|
content = @Content)})
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public List<HelloGetDto> findAll() {
|
public List<HelloGetDto> findAll() {
|
||||||
return this.service
|
return this.service
|
||||||
.readAll()
|
.readAll()
|
||||||
.stream()
|
.stream()
|
||||||
.map(e -> this.helloMapper.mapToGetDto(e))
|
.map(e -> this.helloMapper.mapToGetDto(e))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "deletes a Hello by id")
|
@Operation(summary = "deletes a Hello by id")
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(responseCode = "204", description = "delete successful"),
|
@ApiResponse(responseCode = "204", description = "delete successful"),
|
||||||
@ApiResponse(responseCode = "401", description = "not authorized",
|
@ApiResponse(responseCode = "401", description = "not authorized",
|
||||||
content = @Content),
|
content = @Content),
|
||||||
@ApiResponse(responseCode = "404", description = "resource not found",
|
@ApiResponse(responseCode = "404", description = "resource not found",
|
||||||
content = @Content)})
|
content = @Content)})
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
@ResponseStatus(code = HttpStatus.NO_CONTENT)
|
@ResponseStatus(code = HttpStatus.NO_CONTENT)
|
||||||
public void deleteHelloById(@PathVariable long id) {
|
public void deleteHelloById(@PathVariable long id) {
|
||||||
var entity = this.service.readById(id);
|
var entity = this.service.readById(id);
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
throw new ResourceNotFoundException("HelloEntity not found on id = " + id);
|
throw new ResourceNotFoundException("HelloEntity not found on id = " + id);
|
||||||
} else {
|
} else {
|
||||||
this.service.delete(entity);
|
this.service.delete(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "find hellos by message")
|
@Operation(summary = "find hellos by message")
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(responseCode = "200", description = "List of hellos who have the given message",
|
@ApiResponse(responseCode = "200", description = "List of hellos who have the given message",
|
||||||
content = {@Content(mediaType = "application/json",
|
content = {@Content(mediaType = "application/json",
|
||||||
schema = @Schema(implementation = HelloGetDto.class))}),
|
schema = @Schema(implementation = HelloGetDto.class))}),
|
||||||
@ApiResponse(responseCode = "404", description = "qualification description does not exist",
|
@ApiResponse(responseCode = "404", description = "qualification description does not exist",
|
||||||
content = @Content),
|
content = @Content),
|
||||||
@ApiResponse(responseCode = "401", description = "not authorized",
|
@ApiResponse(responseCode = "401", description = "not authorized",
|
||||||
content = @Content)})
|
content = @Content)})
|
||||||
@GetMapping("/findByMessage")
|
@GetMapping("/findByMessage")
|
||||||
public List<HelloGetDto> findAllEmployeesByQualification(@RequestParam String message) {
|
public List<HelloGetDto> findAllEmployeesByQualification(@RequestParam String message) {
|
||||||
return this.service
|
return this.service
|
||||||
.findByMessage(message)
|
.findByMessage(message)
|
||||||
.stream()
|
.stream()
|
||||||
.map(e -> this.helloMapper.mapToGetDto(e))
|
.map(e -> this.helloMapper.mapToGetDto(e))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,27 @@
|
|||||||
package de.szut.lf8_starter.hello;
|
package de.szut.lf8_starter.hello;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "hello")
|
@Table(name = "hello")
|
||||||
public class HelloEntity {
|
public class HelloEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
public HelloEntity(String message) {
|
public HelloEntity(String message) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
package de.szut.lf8_starter.hello;
|
package de.szut.lf8_starter.hello;
|
||||||
|
|
||||||
|
|
||||||
import de.szut.lf8_starter.hello.dto.HelloCreateDto;
|
import de.szut.lf8_starter.hello.dto.HelloCreateDto;
|
||||||
import de.szut.lf8_starter.hello.dto.HelloGetDto;
|
import de.szut.lf8_starter.hello.dto.HelloGetDto;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class HelloMapper {
|
public class HelloMapper {
|
||||||
|
|
||||||
public HelloGetDto mapToGetDto(HelloEntity entity) {
|
public HelloGetDto mapToGetDto(HelloEntity entity) {
|
||||||
return new HelloGetDto(entity.getId(), entity.getMessage());
|
return new HelloGetDto(entity.getId(), entity.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public HelloEntity mapCreateDtoToEntity(HelloCreateDto dto) {
|
public HelloEntity mapCreateDtoToEntity(HelloCreateDto dto) {
|
||||||
var entity = new HelloEntity();
|
var entity = new HelloEntity();
|
||||||
entity.setMessage(dto.getMessage());
|
entity.setMessage(dto.getMessage());
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package de.szut.lf8_starter.hello;
|
package de.szut.lf8_starter.hello;
|
||||||
|
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface HelloRepository extends JpaRepository<HelloEntity, Long> {
|
public interface HelloRepository extends JpaRepository<HelloEntity, Long> {
|
||||||
|
|
||||||
|
|
||||||
List<HelloEntity> findByMessage(String message);
|
List<HelloEntity> findByMessage(String message);
|
||||||
}
|
}
|
||||||
|
@ -1,40 +1,40 @@
|
|||||||
package de.szut.lf8_starter.hello;
|
package de.szut.lf8_starter.hello;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class HelloService {
|
public class HelloService {
|
||||||
private final HelloRepository repository;
|
private final HelloRepository repository;
|
||||||
|
|
||||||
public HelloService(HelloRepository repository) {
|
public HelloService(HelloRepository repository) {
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HelloEntity create(HelloEntity entity) {
|
public HelloEntity create(HelloEntity entity) {
|
||||||
return this.repository.save(entity);
|
return this.repository.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<HelloEntity> readAll() {
|
public List<HelloEntity> readAll() {
|
||||||
return this.repository.findAll();
|
return this.repository.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public HelloEntity readById(long id) {
|
public HelloEntity readById(long id) {
|
||||||
Optional<HelloEntity> optionalQualification = this.repository.findById(id);
|
Optional<HelloEntity> optionalQualification = this.repository.findById(id);
|
||||||
if (optionalQualification.isEmpty()) {
|
if (optionalQualification.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return optionalQualification.get();
|
return optionalQualification.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void delete(HelloEntity entity) {
|
public void delete(HelloEntity entity) {
|
||||||
this.repository.delete(entity);
|
this.repository.delete(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<HelloEntity> findByMessage(String message) {
|
public List<HelloEntity> findByMessage(String message) {
|
||||||
return this.repository.findByMessage(message);
|
return this.repository.findByMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
package de.szut.lf8_starter.hello.dto;
|
package de.szut.lf8_starter.hello.dto;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class HelloCreateDto {
|
public class HelloCreateDto {
|
||||||
|
|
||||||
@Size(min = 3, message = "at least length of 3")
|
@Size(min = 3, message = "at least length of 3")
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public HelloCreateDto(String message) {
|
public HelloCreateDto(String message) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
package de.szut.lf8_starter.hello.dto;
|
package de.szut.lf8_starter.hello.dto;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class HelloGetDto {
|
public class HelloGetDto {
|
||||||
|
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,11 @@ import de.szut.lf8_starter.project.ProjectMapper;
|
|||||||
import de.szut.lf8_starter.project.ProjectService;
|
import de.szut.lf8_starter.project.ProjectService;
|
||||||
import de.szut.lf8_starter.project.dto.GetProjectDto;
|
import de.szut.lf8_starter.project.dto.GetProjectDto;
|
||||||
import de.szut.lf8_starter.project.dto.UpdateProjectDto;
|
import de.szut.lf8_starter.project.dto.UpdateProjectDto;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@ -23,6 +28,12 @@ public class UpdateProjectAction {
|
|||||||
this.projectMapper = mappingService;
|
this.projectMapper = mappingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "Update a project by ID")
|
||||||
|
@ApiResponses(value = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "Project updated successfully",
|
||||||
|
content = @Content(mediaType = "application/json", schema = @Schema(implementation = GetProjectDto.class))),
|
||||||
|
@ApiResponse(responseCode = "404", description = "Project not found", content = @Content)
|
||||||
|
})
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
public ResponseEntity<GetProjectDto> updateSupplier(@PathVariable Long id, @Valid @RequestBody UpdateProjectDto updateProjectDto) {
|
public ResponseEntity<GetProjectDto> updateSupplier(@PathVariable Long id, @Valid @RequestBody UpdateProjectDto updateProjectDto) {
|
||||||
Optional<ProjectEntity> project = this.projectService.findById(id);
|
Optional<ProjectEntity> project = this.projectService.findById(id);
|
||||||
|
@ -0,0 +1,87 @@
|
|||||||
|
package de.szut.lf8_starter.integration.project;
|
||||||
|
|
||||||
|
import de.szut.lf8_starter.project.ProjectEntity;
|
||||||
|
import de.szut.lf8_starter.project.ProjectRepository;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.hamcrest.Matchers.is;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
@AutoConfigureMockMvc(addFilters = false)
|
||||||
|
class UpdateProjectActionTest {
|
||||||
|
@Autowired
|
||||||
|
private MockMvc mockMvc;
|
||||||
|
@Autowired
|
||||||
|
private ProjectRepository projectRepository;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void updateProjectTest() throws Exception {
|
||||||
|
ProjectEntity project = new ProjectEntity();
|
||||||
|
project.setId(1);
|
||||||
|
project.setComment("comment");
|
||||||
|
project.setContractor(1);
|
||||||
|
project.setContractorName("contractorName");
|
||||||
|
project.setEndDate(LocalDate.of(2024, 1, 1));
|
||||||
|
project.setLeadingEmployee(1);
|
||||||
|
project.setName("name");
|
||||||
|
project.setStartDate(LocalDate.of(2021, 1, 1));
|
||||||
|
project.setEmployees(List.of(1L, 2L, 3L));
|
||||||
|
this.projectRepository.save(project);
|
||||||
|
|
||||||
|
String content = """
|
||||||
|
{
|
||||||
|
"name": "updatedName",
|
||||||
|
"leading_employee": 2,
|
||||||
|
"employees": [3, 4, 5],
|
||||||
|
"contractor": 6,
|
||||||
|
"contractor_name": "Updated Contractor name",
|
||||||
|
"comment": "new goal of project",
|
||||||
|
"start_date": "01.01.2021",
|
||||||
|
"planned_end_date": "01.01.2022"
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
|
final var contentAsString = this.mockMvc.perform(
|
||||||
|
put("/projects/1").content(content).contentType(MediaType.APPLICATION_JSON)
|
||||||
|
)
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("name", is("updatedName")))
|
||||||
|
.andExpect(jsonPath("leading_employee", is(2)))
|
||||||
|
.andExpect(jsonPath("employees", is(Arrays.asList(3, 4, 5))))
|
||||||
|
.andExpect(jsonPath("contractor", is(6)))
|
||||||
|
.andExpect(jsonPath("contractor_name", is("Updated Contractor name")))
|
||||||
|
.andExpect(jsonPath("comment", is("new goal of project")))
|
||||||
|
.andExpect(jsonPath("start_date", is("01.01.2021")))
|
||||||
|
.andExpect(jsonPath("planned_end_date", is("01.01.2022")))
|
||||||
|
.andReturn()
|
||||||
|
.getResponse()
|
||||||
|
.getContentAsString();
|
||||||
|
|
||||||
|
final var id = Long.parseLong(new JSONObject(contentAsString).get("id").toString());
|
||||||
|
|
||||||
|
final var existingProject = this.projectRepository.findById(id);
|
||||||
|
assertThat(existingProject.get().getName()).isEqualTo("updatedName");
|
||||||
|
assertThat(existingProject.get().getLeadingEmployee()).isEqualTo(2);
|
||||||
|
assertThat(existingProject.get().getContractor()).isEqualTo(6);
|
||||||
|
assertThat(existingProject.get().getContractorName()).isEqualTo("Updated Contractor name");
|
||||||
|
assertThat(existingProject.get().getComment()).isEqualTo("new goal of project");
|
||||||
|
assertThat(existingProject.get().getStartDate()).isEqualTo(LocalDate.of(2021, 1, 1));
|
||||||
|
assertThat(existingProject.get().getPlannedEndDate()).isEqualTo(LocalDate.of(2022, 1, 1));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user