From 7888928be738cbbc941c16913d2246138764e195 Mon Sep 17 00:00:00 2001 From: JHipster Bot Date: Wed, 19 Jun 2019 21:29:29 +0000 Subject: [PATCH 1/3] Add JDL Model `zdar` See https://start.jhipster.tech/jdl-studio/#!/view/e42e2704-0140-4449-8131-0cce595b3409 --- zdar.jh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 zdar.jh diff --git a/zdar.jh b/zdar.jh new file mode 100644 index 0000000..d44963b --- /dev/null +++ b/zdar.jh @@ -0,0 +1,34 @@ + + + +/** + * The Employee entity. + */ +entity Employee { + clientId String, + advisorId String, + appointmentId String, + roomId String, + token String, + endDate Instant, + startDate Instant, + +} + + +enum Language { + FRENCH, ENGLISH, SPANISH +} + + + + + +// Use Data Transfert Objects (DTO) +dto * with mapstruct + +// Set service options to all except few +service all with serviceImpl + +// Set an angular suffix +// angularSuffix * with mySuffix From 678dd30dfc65415c93dff6706b8ee483c279bcff Mon Sep 17 00:00:00 2001 From: JHipster Bot Date: Wed, 19 Jun 2019 21:29:32 +0000 Subject: [PATCH 2/3] Generate entities from JDL Model `zdar` See https://start.jhipster.tech/jdl-studio/#!/view/e42e2704-0140-4449-8131-0cce595b3409 --- .jhipster/Employee.json | 45 +++ .../jhipster/application/domain/Employee.java | 173 +++++++++ .../repository/EmployeeRepository.java | 15 + .../application/service/EmployeeService.java | 43 +++ .../application/service/dto/EmployeeDTO.java | 128 +++++++ .../service/impl/EmployeeServiceImpl.java | 90 +++++ .../service/mapper/EmployeeMapper.java | 24 ++ .../service/mapper/EntityMapper.java | 21 ++ .../web/rest/EmployeeResource.java | 117 ++++++ .../20190619212931_added_entity_Employee.xml | 81 ++++ .../config/liquibase/data/employee.csv | 11 + .../resources/config/liquibase/master.xml | 1 + .../web/rest/EmployeeResourceIT.java | 350 ++++++++++++++++++ 13 files changed, 1099 insertions(+) create mode 100644 .jhipster/Employee.json create mode 100644 src/main/java/io/github/jhipster/application/domain/Employee.java create mode 100644 src/main/java/io/github/jhipster/application/repository/EmployeeRepository.java create mode 100644 src/main/java/io/github/jhipster/application/service/EmployeeService.java create mode 100644 src/main/java/io/github/jhipster/application/service/dto/EmployeeDTO.java create mode 100644 src/main/java/io/github/jhipster/application/service/impl/EmployeeServiceImpl.java create mode 100644 src/main/java/io/github/jhipster/application/service/mapper/EmployeeMapper.java create mode 100644 src/main/java/io/github/jhipster/application/service/mapper/EntityMapper.java create mode 100644 src/main/java/io/github/jhipster/application/web/rest/EmployeeResource.java create mode 100644 src/main/resources/config/liquibase/changelog/20190619212931_added_entity_Employee.xml create mode 100644 src/main/resources/config/liquibase/data/employee.csv create mode 100644 src/test/java/io/github/jhipster/application/web/rest/EmployeeResourceIT.java diff --git a/.jhipster/Employee.json b/.jhipster/Employee.json new file mode 100644 index 0000000..e090139 --- /dev/null +++ b/.jhipster/Employee.json @@ -0,0 +1,45 @@ +{ + "name": "Employee", + "fields": [ + { + "fieldName": "clientId", + "fieldType": "String" + }, + { + "fieldName": "advisorId", + "fieldType": "String" + }, + { + "fieldName": "appointmentId", + "fieldType": "String" + }, + { + "fieldName": "roomId", + "fieldType": "String" + }, + { + "fieldName": "token", + "fieldType": "String" + }, + { + "fieldName": "endDate", + "fieldType": "Instant" + }, + { + "fieldName": "startDate", + "fieldType": "Instant" + } + ], + "relationships": [], + "changelogDate": "20190619212931", + "javadoc": "The Employee entity.", + "entityTableName": "employee", + "dto": "mapstruct", + "pagination": "no", + "service": "serviceImpl", + "jpaMetamodelFiltering": false, + "fluentMethods": true, + "clientRootFolder": "micro", + "applications": "*", + "microserviceName": "micro" +} \ No newline at end of file diff --git a/src/main/java/io/github/jhipster/application/domain/Employee.java b/src/main/java/io/github/jhipster/application/domain/Employee.java new file mode 100644 index 0000000..2b45abe --- /dev/null +++ b/src/main/java/io/github/jhipster/application/domain/Employee.java @@ -0,0 +1,173 @@ +package io.github.jhipster.application.domain; + +import javax.persistence.*; + +import java.io.Serializable; +import java.time.Instant; + +/** + * The Employee entity. + */ +@Entity +@Table(name = "employee") +public class Employee implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator") + @SequenceGenerator(name = "sequenceGenerator") + private Long id; + + @Column(name = "client_id") + private String clientId; + + @Column(name = "advisor_id") + private String advisorId; + + @Column(name = "appointment_id") + private String appointmentId; + + @Column(name = "room_id") + private String roomId; + + @Column(name = "token") + private String token; + + @Column(name = "end_date") + private Instant endDate; + + @Column(name = "start_date") + private Instant startDate; + + // jhipster-needle-entity-add-field - JHipster will add fields here, do not remove + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getClientId() { + return clientId; + } + + public Employee clientId(String clientId) { + this.clientId = clientId; + return this; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getAdvisorId() { + return advisorId; + } + + public Employee advisorId(String advisorId) { + this.advisorId = advisorId; + return this; + } + + public void setAdvisorId(String advisorId) { + this.advisorId = advisorId; + } + + public String getAppointmentId() { + return appointmentId; + } + + public Employee appointmentId(String appointmentId) { + this.appointmentId = appointmentId; + return this; + } + + public void setAppointmentId(String appointmentId) { + this.appointmentId = appointmentId; + } + + public String getRoomId() { + return roomId; + } + + public Employee roomId(String roomId) { + this.roomId = roomId; + return this; + } + + public void setRoomId(String roomId) { + this.roomId = roomId; + } + + public String getToken() { + return token; + } + + public Employee token(String token) { + this.token = token; + return this; + } + + public void setToken(String token) { + this.token = token; + } + + public Instant getEndDate() { + return endDate; + } + + public Employee endDate(Instant endDate) { + this.endDate = endDate; + return this; + } + + public void setEndDate(Instant endDate) { + this.endDate = endDate; + } + + public Instant getStartDate() { + return startDate; + } + + public Employee startDate(Instant startDate) { + this.startDate = startDate; + return this; + } + + public void setStartDate(Instant startDate) { + this.startDate = startDate; + } + // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Employee)) { + return false; + } + return id != null && id.equals(((Employee) o).id); + } + + @Override + public int hashCode() { + return 31; + } + + @Override + public String toString() { + return "Employee{" + + "id=" + getId() + + ", clientId='" + getClientId() + "'" + + ", advisorId='" + getAdvisorId() + "'" + + ", appointmentId='" + getAppointmentId() + "'" + + ", roomId='" + getRoomId() + "'" + + ", token='" + getToken() + "'" + + ", endDate='" + getEndDate() + "'" + + ", startDate='" + getStartDate() + "'" + + "}"; + } +} diff --git a/src/main/java/io/github/jhipster/application/repository/EmployeeRepository.java b/src/main/java/io/github/jhipster/application/repository/EmployeeRepository.java new file mode 100644 index 0000000..f20fae0 --- /dev/null +++ b/src/main/java/io/github/jhipster/application/repository/EmployeeRepository.java @@ -0,0 +1,15 @@ +package io.github.jhipster.application.repository; + +import io.github.jhipster.application.domain.Employee; +import org.springframework.data.jpa.repository.*; +import org.springframework.stereotype.Repository; + + +/** + * Spring Data repository for the Employee entity. + */ +@SuppressWarnings("unused") +@Repository +public interface EmployeeRepository extends JpaRepository { + +} diff --git a/src/main/java/io/github/jhipster/application/service/EmployeeService.java b/src/main/java/io/github/jhipster/application/service/EmployeeService.java new file mode 100644 index 0000000..f95c2ae --- /dev/null +++ b/src/main/java/io/github/jhipster/application/service/EmployeeService.java @@ -0,0 +1,43 @@ +package io.github.jhipster.application.service; + +import io.github.jhipster.application.service.dto.EmployeeDTO; + +import java.util.List; +import java.util.Optional; + +/** + * Service Interface for managing {@link io.github.jhipster.application.domain.Employee}. + */ +public interface EmployeeService { + + /** + * Save a employee. + * + * @param employeeDTO the entity to save. + * @return the persisted entity. + */ + EmployeeDTO save(EmployeeDTO employeeDTO); + + /** + * Get all the employees. + * + * @return the list of entities. + */ + List findAll(); + + + /** + * Get the "id" employee. + * + * @param id the id of the entity. + * @return the entity. + */ + Optional findOne(Long id); + + /** + * Delete the "id" employee. + * + * @param id the id of the entity. + */ + void delete(Long id); +} diff --git a/src/main/java/io/github/jhipster/application/service/dto/EmployeeDTO.java b/src/main/java/io/github/jhipster/application/service/dto/EmployeeDTO.java new file mode 100644 index 0000000..3eed6d7 --- /dev/null +++ b/src/main/java/io/github/jhipster/application/service/dto/EmployeeDTO.java @@ -0,0 +1,128 @@ +package io.github.jhipster.application.service.dto; +import io.swagger.annotations.ApiModel; +import java.time.Instant; +import java.io.Serializable; +import java.util.Objects; + +/** + * A DTO for the {@link io.github.jhipster.application.domain.Employee} entity. + */ +@ApiModel(description = "The Employee entity.") +public class EmployeeDTO implements Serializable { + + private Long id; + + private String clientId; + + private String advisorId; + + private String appointmentId; + + private String roomId; + + private String token; + + private Instant endDate; + + private Instant startDate; + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getClientId() { + return clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getAdvisorId() { + return advisorId; + } + + public void setAdvisorId(String advisorId) { + this.advisorId = advisorId; + } + + public String getAppointmentId() { + return appointmentId; + } + + public void setAppointmentId(String appointmentId) { + this.appointmentId = appointmentId; + } + + public String getRoomId() { + return roomId; + } + + public void setRoomId(String roomId) { + this.roomId = roomId; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + public Instant getEndDate() { + return endDate; + } + + public void setEndDate(Instant endDate) { + this.endDate = endDate; + } + + public Instant getStartDate() { + return startDate; + } + + public void setStartDate(Instant startDate) { + this.startDate = startDate; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + EmployeeDTO employeeDTO = (EmployeeDTO) o; + if (employeeDTO.getId() == null || getId() == null) { + return false; + } + return Objects.equals(getId(), employeeDTO.getId()); + } + + @Override + public int hashCode() { + return Objects.hashCode(getId()); + } + + @Override + public String toString() { + return "EmployeeDTO{" + + "id=" + getId() + + ", clientId='" + getClientId() + "'" + + ", advisorId='" + getAdvisorId() + "'" + + ", appointmentId='" + getAppointmentId() + "'" + + ", roomId='" + getRoomId() + "'" + + ", token='" + getToken() + "'" + + ", endDate='" + getEndDate() + "'" + + ", startDate='" + getStartDate() + "'" + + "}"; + } +} diff --git a/src/main/java/io/github/jhipster/application/service/impl/EmployeeServiceImpl.java b/src/main/java/io/github/jhipster/application/service/impl/EmployeeServiceImpl.java new file mode 100644 index 0000000..00bf26c --- /dev/null +++ b/src/main/java/io/github/jhipster/application/service/impl/EmployeeServiceImpl.java @@ -0,0 +1,90 @@ +package io.github.jhipster.application.service.impl; + +import io.github.jhipster.application.service.EmployeeService; +import io.github.jhipster.application.domain.Employee; +import io.github.jhipster.application.repository.EmployeeRepository; +import io.github.jhipster.application.service.dto.EmployeeDTO; +import io.github.jhipster.application.service.mapper.EmployeeMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * Service Implementation for managing {@link Employee}. + */ +@Service +@Transactional +public class EmployeeServiceImpl implements EmployeeService { + + private final Logger log = LoggerFactory.getLogger(EmployeeServiceImpl.class); + + private final EmployeeRepository employeeRepository; + + private final EmployeeMapper employeeMapper; + + public EmployeeServiceImpl(EmployeeRepository employeeRepository, EmployeeMapper employeeMapper) { + this.employeeRepository = employeeRepository; + this.employeeMapper = employeeMapper; + } + + /** + * Save a employee. + * + * @param employeeDTO the entity to save. + * @return the persisted entity. + */ + @Override + public EmployeeDTO save(EmployeeDTO employeeDTO) { + log.debug("Request to save Employee : {}", employeeDTO); + Employee employee = employeeMapper.toEntity(employeeDTO); + employee = employeeRepository.save(employee); + return employeeMapper.toDto(employee); + } + + /** + * Get all the employees. + * + * @return the list of entities. + */ + @Override + @Transactional(readOnly = true) + public List findAll() { + log.debug("Request to get all Employees"); + return employeeRepository.findAll().stream() + .map(employeeMapper::toDto) + .collect(Collectors.toCollection(LinkedList::new)); + } + + + /** + * Get one employee by id. + * + * @param id the id of the entity. + * @return the entity. + */ + @Override + @Transactional(readOnly = true) + public Optional findOne(Long id) { + log.debug("Request to get Employee : {}", id); + return employeeRepository.findById(id) + .map(employeeMapper::toDto); + } + + /** + * Delete the employee by id. + * + * @param id the id of the entity. + */ + @Override + public void delete(Long id) { + log.debug("Request to delete Employee : {}", id); + employeeRepository.deleteById(id); + } +} diff --git a/src/main/java/io/github/jhipster/application/service/mapper/EmployeeMapper.java b/src/main/java/io/github/jhipster/application/service/mapper/EmployeeMapper.java new file mode 100644 index 0000000..22c9282 --- /dev/null +++ b/src/main/java/io/github/jhipster/application/service/mapper/EmployeeMapper.java @@ -0,0 +1,24 @@ +package io.github.jhipster.application.service.mapper; + +import io.github.jhipster.application.domain.*; +import io.github.jhipster.application.service.dto.EmployeeDTO; + +import org.mapstruct.*; + +/** + * Mapper for the entity {@link Employee} and its DTO {@link EmployeeDTO}. + */ +@Mapper(componentModel = "spring", uses = {}) +public interface EmployeeMapper extends EntityMapper { + + + + default Employee fromId(Long id) { + if (id == null) { + return null; + } + Employee employee = new Employee(); + employee.setId(id); + return employee; + } +} diff --git a/src/main/java/io/github/jhipster/application/service/mapper/EntityMapper.java b/src/main/java/io/github/jhipster/application/service/mapper/EntityMapper.java new file mode 100644 index 0000000..01e7608 --- /dev/null +++ b/src/main/java/io/github/jhipster/application/service/mapper/EntityMapper.java @@ -0,0 +1,21 @@ +package io.github.jhipster.application.service.mapper; + +import java.util.List; + +/** + * Contract for a generic dto to entity mapper. + * + * @param - DTO type parameter. + * @param - Entity type parameter. + */ + +public interface EntityMapper { + + E toEntity(D dto); + + D toDto(E entity); + + List toEntity(List dtoList); + + List toDto(List entityList); +} diff --git a/src/main/java/io/github/jhipster/application/web/rest/EmployeeResource.java b/src/main/java/io/github/jhipster/application/web/rest/EmployeeResource.java new file mode 100644 index 0000000..568c528 --- /dev/null +++ b/src/main/java/io/github/jhipster/application/web/rest/EmployeeResource.java @@ -0,0 +1,117 @@ +package io.github.jhipster.application.web.rest; + +import io.github.jhipster.application.service.EmployeeService; +import io.github.jhipster.application.web.rest.errors.BadRequestAlertException; +import io.github.jhipster.application.service.dto.EmployeeDTO; + +import io.github.jhipster.web.util.HeaderUtil; +import io.github.jhipster.web.util.ResponseUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.net.URI; +import java.net.URISyntaxException; + +import java.util.List; +import java.util.Optional; + +/** + * REST controller for managing {@link io.github.jhipster.application.domain.Employee}. + */ +@RestController +@RequestMapping("/api") +public class EmployeeResource { + + private final Logger log = LoggerFactory.getLogger(EmployeeResource.class); + + private static final String ENTITY_NAME = "microEmployee"; + + @Value("${jhipster.clientApp.name}") + private String applicationName; + + private final EmployeeService employeeService; + + public EmployeeResource(EmployeeService employeeService) { + this.employeeService = employeeService; + } + + /** + * {@code POST /employees} : Create a new employee. + * + * @param employeeDTO the employeeDTO to create. + * @return the {@link ResponseEntity} with status {@code 201 (Created)} and with body the new employeeDTO, or with status {@code 400 (Bad Request)} if the employee has already an ID. + * @throws URISyntaxException if the Location URI syntax is incorrect. + */ + @PostMapping("/employees") + public ResponseEntity createEmployee(@RequestBody EmployeeDTO employeeDTO) throws URISyntaxException { + log.debug("REST request to save Employee : {}", employeeDTO); + if (employeeDTO.getId() != null) { + throw new BadRequestAlertException("A new employee cannot already have an ID", ENTITY_NAME, "idexists"); + } + EmployeeDTO result = employeeService.save(employeeDTO); + return ResponseEntity.created(new URI("/api/employees/" + result.getId())) + .headers(HeaderUtil.createEntityCreationAlert(applicationName, false, ENTITY_NAME, result.getId().toString())) + .body(result); + } + + /** + * {@code PUT /employees} : Updates an existing employee. + * + * @param employeeDTO the employeeDTO to update. + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated employeeDTO, + * or with status {@code 400 (Bad Request)} if the employeeDTO is not valid, + * or with status {@code 500 (Internal Server Error)} if the employeeDTO couldn't be updated. + * @throws URISyntaxException if the Location URI syntax is incorrect. + */ + @PutMapping("/employees") + public ResponseEntity updateEmployee(@RequestBody EmployeeDTO employeeDTO) throws URISyntaxException { + log.debug("REST request to update Employee : {}", employeeDTO); + if (employeeDTO.getId() == null) { + throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull"); + } + EmployeeDTO result = employeeService.save(employeeDTO); + return ResponseEntity.ok() + .headers(HeaderUtil.createEntityUpdateAlert(applicationName, false, ENTITY_NAME, employeeDTO.getId().toString())) + .body(result); + } + + /** + * {@code GET /employees} : get all the employees. + * + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of employees in body. + */ + @GetMapping("/employees") + public List getAllEmployees() { + log.debug("REST request to get all Employees"); + return employeeService.findAll(); + } + + /** + * {@code GET /employees/:id} : get the "id" employee. + * + * @param id the id of the employeeDTO to retrieve. + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the employeeDTO, or with status {@code 404 (Not Found)}. + */ + @GetMapping("/employees/{id}") + public ResponseEntity getEmployee(@PathVariable Long id) { + log.debug("REST request to get Employee : {}", id); + Optional employeeDTO = employeeService.findOne(id); + return ResponseUtil.wrapOrNotFound(employeeDTO); + } + + /** + * {@code DELETE /employees/:id} : delete the "id" employee. + * + * @param id the id of the employeeDTO to delete. + * @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}. + */ + @DeleteMapping("/employees/{id}") + public ResponseEntity deleteEmployee(@PathVariable Long id) { + log.debug("REST request to delete Employee : {}", id); + employeeService.delete(id); + return ResponseEntity.noContent().headers(HeaderUtil.createEntityDeletionAlert(applicationName, false, ENTITY_NAME, id.toString())).build(); + } +} diff --git a/src/main/resources/config/liquibase/changelog/20190619212931_added_entity_Employee.xml b/src/main/resources/config/liquibase/changelog/20190619212931_added_entity_Employee.xml new file mode 100644 index 0000000..825a5b6 --- /dev/null +++ b/src/main/resources/config/liquibase/changelog/20190619212931_added_entity_Employee.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/config/liquibase/data/employee.csv b/src/main/resources/config/liquibase/data/employee.csv new file mode 100644 index 0000000..bc172e3 --- /dev/null +++ b/src/main/resources/config/liquibase/data/employee.csv @@ -0,0 +1,11 @@ +id;client_id;advisor_id;appointment_id;room_id;token;end_date;start_date +1;mobile Fish;Home Loan Account Table Computer;Trace;Savings Account alarm;Tasty Metal Bacon;2019-06-18T22:58:01;2019-06-19T16:23:45 +2;Chips;Money Market Account;Albania web-readiness;Namibia;Steel zero administration;2019-06-19T12:41:58;2019-06-19T15:54:20 +3;Licensed Savings Account;Cambridgeshire Mississippi;HDD;Table Small Frozen Sausages Planner;envisioneer Music Public-key;2019-06-19T15:42:27;2019-06-19T10:55:42 +4;Rubber Buckinghamshire Games;incentivize Tuna copy;Costa Rica Mayotte;Industrial;connect Markets Chief;2019-06-19T07:08:33;2019-06-19T04:02:15 +5;archive Georgia Aruba;software scale interactive;Louisiana Specialist Home Loan Account;Plastic;Car Industrial deliverables;2019-06-19T12:00:54;2019-06-19T16:43:22 +6;Books;magenta monitor 1080p;Unbranded Plastic Tuna Frozen;generating Highway Ergonomic;moratorium moratorium;2019-06-19T03:58:54;2019-06-19T07:18:04 +7;tangible Mississippi;Frozen bus;hard drive Robust Networked;Poland;Small partnerships;2019-06-19T16:39:03;2019-06-19T20:44:16 +8;withdrawal knowledge base Buckinghamshire;Concrete Investment Account Saint Lucia;User-centric;Money Market Account;Salad Web virtual;2019-06-19T06:17:26;2019-06-19T18:57:36 +9;Squares mint green e-business;Ghana back-end National;Direct;Profit-focused;Jewelery cutting-edge;2019-06-19T14:10:38;2019-06-19T21:19:30 +10;Borders;Bedfordshire Bahamian Dollar;24/7;Gloves sky blue Oklahoma;robust Engineer;2019-06-18T22:23:37;2019-06-19T15:34:01 diff --git a/src/main/resources/config/liquibase/master.xml b/src/main/resources/config/liquibase/master.xml index 12f6453..dae6960 100644 --- a/src/main/resources/config/liquibase/master.xml +++ b/src/main/resources/config/liquibase/master.xml @@ -14,6 +14,7 @@ + diff --git a/src/test/java/io/github/jhipster/application/web/rest/EmployeeResourceIT.java b/src/test/java/io/github/jhipster/application/web/rest/EmployeeResourceIT.java new file mode 100644 index 0000000..78fd5d2 --- /dev/null +++ b/src/test/java/io/github/jhipster/application/web/rest/EmployeeResourceIT.java @@ -0,0 +1,350 @@ +package io.github.jhipster.application.web.rest; + +import io.github.jhipster.application.MicroApp; +import io.github.jhipster.application.domain.Employee; +import io.github.jhipster.application.repository.EmployeeRepository; +import io.github.jhipster.application.service.EmployeeService; +import io.github.jhipster.application.service.dto.EmployeeDTO; +import io.github.jhipster.application.service.mapper.EmployeeMapper; +import io.github.jhipster.application.web.rest.errors.ExceptionTranslator; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.web.PageableHandlerMethodArgumentResolver; +import org.springframework.http.MediaType; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.Validator; + +import javax.persistence.EntityManager; +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.List; + +import static io.github.jhipster.application.web.rest.TestUtil.createFormattingConversionService; +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.hasItem; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +/** + * Integration tests for the {@Link EmployeeResource} REST controller. + */ +@SpringBootTest(classes = MicroApp.class) +public class EmployeeResourceIT { + + private static final String DEFAULT_CLIENT_ID = "AAAAAAAAAA"; + private static final String UPDATED_CLIENT_ID = "BBBBBBBBBB"; + + private static final String DEFAULT_ADVISOR_ID = "AAAAAAAAAA"; + private static final String UPDATED_ADVISOR_ID = "BBBBBBBBBB"; + + private static final String DEFAULT_APPOINTMENT_ID = "AAAAAAAAAA"; + private static final String UPDATED_APPOINTMENT_ID = "BBBBBBBBBB"; + + private static final String DEFAULT_ROOM_ID = "AAAAAAAAAA"; + private static final String UPDATED_ROOM_ID = "BBBBBBBBBB"; + + private static final String DEFAULT_TOKEN = "AAAAAAAAAA"; + private static final String UPDATED_TOKEN = "BBBBBBBBBB"; + + private static final Instant DEFAULT_END_DATE = Instant.ofEpochMilli(0L); + private static final Instant UPDATED_END_DATE = Instant.now().truncatedTo(ChronoUnit.MILLIS); + + private static final Instant DEFAULT_START_DATE = Instant.ofEpochMilli(0L); + private static final Instant UPDATED_START_DATE = Instant.now().truncatedTo(ChronoUnit.MILLIS); + + @Autowired + private EmployeeRepository employeeRepository; + + @Autowired + private EmployeeMapper employeeMapper; + + @Autowired + private EmployeeService employeeService; + + @Autowired + private MappingJackson2HttpMessageConverter jacksonMessageConverter; + + @Autowired + private PageableHandlerMethodArgumentResolver pageableArgumentResolver; + + @Autowired + private ExceptionTranslator exceptionTranslator; + + @Autowired + private EntityManager em; + + @Autowired + private Validator validator; + + private MockMvc restEmployeeMockMvc; + + private Employee employee; + + @BeforeEach + public void setup() { + MockitoAnnotations.initMocks(this); + final EmployeeResource employeeResource = new EmployeeResource(employeeService); + this.restEmployeeMockMvc = MockMvcBuilders.standaloneSetup(employeeResource) + .setCustomArgumentResolvers(pageableArgumentResolver) + .setControllerAdvice(exceptionTranslator) + .setConversionService(createFormattingConversionService()) + .setMessageConverters(jacksonMessageConverter) + .setValidator(validator).build(); + } + + /** + * Create an entity for this test. + * + * This is a static method, as tests for other entities might also need it, + * if they test an entity which requires the current entity. + */ + public static Employee createEntity(EntityManager em) { + Employee employee = new Employee() + .clientId(DEFAULT_CLIENT_ID) + .advisorId(DEFAULT_ADVISOR_ID) + .appointmentId(DEFAULT_APPOINTMENT_ID) + .roomId(DEFAULT_ROOM_ID) + .token(DEFAULT_TOKEN) + .endDate(DEFAULT_END_DATE) + .startDate(DEFAULT_START_DATE); + return employee; + } + /** + * Create an updated entity for this test. + * + * This is a static method, as tests for other entities might also need it, + * if they test an entity which requires the current entity. + */ + public static Employee createUpdatedEntity(EntityManager em) { + Employee employee = new Employee() + .clientId(UPDATED_CLIENT_ID) + .advisorId(UPDATED_ADVISOR_ID) + .appointmentId(UPDATED_APPOINTMENT_ID) + .roomId(UPDATED_ROOM_ID) + .token(UPDATED_TOKEN) + .endDate(UPDATED_END_DATE) + .startDate(UPDATED_START_DATE); + return employee; + } + + @BeforeEach + public void initTest() { + employee = createEntity(em); + } + + @Test + @Transactional + public void createEmployee() throws Exception { + int databaseSizeBeforeCreate = employeeRepository.findAll().size(); + + // Create the Employee + EmployeeDTO employeeDTO = employeeMapper.toDto(employee); + restEmployeeMockMvc.perform(post("/api/employees") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(employeeDTO))) + .andExpect(status().isCreated()); + + // Validate the Employee in the database + List employeeList = employeeRepository.findAll(); + assertThat(employeeList).hasSize(databaseSizeBeforeCreate + 1); + Employee testEmployee = employeeList.get(employeeList.size() - 1); + assertThat(testEmployee.getClientId()).isEqualTo(DEFAULT_CLIENT_ID); + assertThat(testEmployee.getAdvisorId()).isEqualTo(DEFAULT_ADVISOR_ID); + assertThat(testEmployee.getAppointmentId()).isEqualTo(DEFAULT_APPOINTMENT_ID); + assertThat(testEmployee.getRoomId()).isEqualTo(DEFAULT_ROOM_ID); + assertThat(testEmployee.getToken()).isEqualTo(DEFAULT_TOKEN); + assertThat(testEmployee.getEndDate()).isEqualTo(DEFAULT_END_DATE); + assertThat(testEmployee.getStartDate()).isEqualTo(DEFAULT_START_DATE); + } + + @Test + @Transactional + public void createEmployeeWithExistingId() throws Exception { + int databaseSizeBeforeCreate = employeeRepository.findAll().size(); + + // Create the Employee with an existing ID + employee.setId(1L); + EmployeeDTO employeeDTO = employeeMapper.toDto(employee); + + // An entity with an existing ID cannot be created, so this API call must fail + restEmployeeMockMvc.perform(post("/api/employees") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(employeeDTO))) + .andExpect(status().isBadRequest()); + + // Validate the Employee in the database + List employeeList = employeeRepository.findAll(); + assertThat(employeeList).hasSize(databaseSizeBeforeCreate); + } + + + @Test + @Transactional + public void getAllEmployees() throws Exception { + // Initialize the database + employeeRepository.saveAndFlush(employee); + + // Get all the employeeList + restEmployeeMockMvc.perform(get("/api/employees?sort=id,desc")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(jsonPath("$.[*].id").value(hasItem(employee.getId().intValue()))) + .andExpect(jsonPath("$.[*].clientId").value(hasItem(DEFAULT_CLIENT_ID.toString()))) + .andExpect(jsonPath("$.[*].advisorId").value(hasItem(DEFAULT_ADVISOR_ID.toString()))) + .andExpect(jsonPath("$.[*].appointmentId").value(hasItem(DEFAULT_APPOINTMENT_ID.toString()))) + .andExpect(jsonPath("$.[*].roomId").value(hasItem(DEFAULT_ROOM_ID.toString()))) + .andExpect(jsonPath("$.[*].token").value(hasItem(DEFAULT_TOKEN.toString()))) + .andExpect(jsonPath("$.[*].endDate").value(hasItem(DEFAULT_END_DATE.toString()))) + .andExpect(jsonPath("$.[*].startDate").value(hasItem(DEFAULT_START_DATE.toString()))); + } + + @Test + @Transactional + public void getEmployee() throws Exception { + // Initialize the database + employeeRepository.saveAndFlush(employee); + + // Get the employee + restEmployeeMockMvc.perform(get("/api/employees/{id}", employee.getId())) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(jsonPath("$.id").value(employee.getId().intValue())) + .andExpect(jsonPath("$.clientId").value(DEFAULT_CLIENT_ID.toString())) + .andExpect(jsonPath("$.advisorId").value(DEFAULT_ADVISOR_ID.toString())) + .andExpect(jsonPath("$.appointmentId").value(DEFAULT_APPOINTMENT_ID.toString())) + .andExpect(jsonPath("$.roomId").value(DEFAULT_ROOM_ID.toString())) + .andExpect(jsonPath("$.token").value(DEFAULT_TOKEN.toString())) + .andExpect(jsonPath("$.endDate").value(DEFAULT_END_DATE.toString())) + .andExpect(jsonPath("$.startDate").value(DEFAULT_START_DATE.toString())); + } + + @Test + @Transactional + public void getNonExistingEmployee() throws Exception { + // Get the employee + restEmployeeMockMvc.perform(get("/api/employees/{id}", Long.MAX_VALUE)) + .andExpect(status().isNotFound()); + } + + @Test + @Transactional + public void updateEmployee() throws Exception { + // Initialize the database + employeeRepository.saveAndFlush(employee); + + int databaseSizeBeforeUpdate = employeeRepository.findAll().size(); + + // Update the employee + Employee updatedEmployee = employeeRepository.findById(employee.getId()).get(); + // Disconnect from session so that the updates on updatedEmployee are not directly saved in db + em.detach(updatedEmployee); + updatedEmployee + .clientId(UPDATED_CLIENT_ID) + .advisorId(UPDATED_ADVISOR_ID) + .appointmentId(UPDATED_APPOINTMENT_ID) + .roomId(UPDATED_ROOM_ID) + .token(UPDATED_TOKEN) + .endDate(UPDATED_END_DATE) + .startDate(UPDATED_START_DATE); + EmployeeDTO employeeDTO = employeeMapper.toDto(updatedEmployee); + + restEmployeeMockMvc.perform(put("/api/employees") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(employeeDTO))) + .andExpect(status().isOk()); + + // Validate the Employee in the database + List employeeList = employeeRepository.findAll(); + assertThat(employeeList).hasSize(databaseSizeBeforeUpdate); + Employee testEmployee = employeeList.get(employeeList.size() - 1); + assertThat(testEmployee.getClientId()).isEqualTo(UPDATED_CLIENT_ID); + assertThat(testEmployee.getAdvisorId()).isEqualTo(UPDATED_ADVISOR_ID); + assertThat(testEmployee.getAppointmentId()).isEqualTo(UPDATED_APPOINTMENT_ID); + assertThat(testEmployee.getRoomId()).isEqualTo(UPDATED_ROOM_ID); + assertThat(testEmployee.getToken()).isEqualTo(UPDATED_TOKEN); + assertThat(testEmployee.getEndDate()).isEqualTo(UPDATED_END_DATE); + assertThat(testEmployee.getStartDate()).isEqualTo(UPDATED_START_DATE); + } + + @Test + @Transactional + public void updateNonExistingEmployee() throws Exception { + int databaseSizeBeforeUpdate = employeeRepository.findAll().size(); + + // Create the Employee + EmployeeDTO employeeDTO = employeeMapper.toDto(employee); + + // If the entity doesn't have an ID, it will throw BadRequestAlertException + restEmployeeMockMvc.perform(put("/api/employees") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(employeeDTO))) + .andExpect(status().isBadRequest()); + + // Validate the Employee in the database + List employeeList = employeeRepository.findAll(); + assertThat(employeeList).hasSize(databaseSizeBeforeUpdate); + } + + @Test + @Transactional + public void deleteEmployee() throws Exception { + // Initialize the database + employeeRepository.saveAndFlush(employee); + + int databaseSizeBeforeDelete = employeeRepository.findAll().size(); + + // Delete the employee + restEmployeeMockMvc.perform(delete("/api/employees/{id}", employee.getId()) + .accept(TestUtil.APPLICATION_JSON_UTF8)) + .andExpect(status().isNoContent()); + + // Validate the database is empty + List employeeList = employeeRepository.findAll(); + assertThat(employeeList).hasSize(databaseSizeBeforeDelete - 1); + } + + @Test + @Transactional + public void equalsVerifier() throws Exception { + TestUtil.equalsVerifier(Employee.class); + Employee employee1 = new Employee(); + employee1.setId(1L); + Employee employee2 = new Employee(); + employee2.setId(employee1.getId()); + assertThat(employee1).isEqualTo(employee2); + employee2.setId(2L); + assertThat(employee1).isNotEqualTo(employee2); + employee1.setId(null); + assertThat(employee1).isNotEqualTo(employee2); + } + + @Test + @Transactional + public void dtoEqualsVerifier() throws Exception { + TestUtil.equalsVerifier(EmployeeDTO.class); + EmployeeDTO employeeDTO1 = new EmployeeDTO(); + employeeDTO1.setId(1L); + EmployeeDTO employeeDTO2 = new EmployeeDTO(); + assertThat(employeeDTO1).isNotEqualTo(employeeDTO2); + employeeDTO2.setId(employeeDTO1.getId()); + assertThat(employeeDTO1).isEqualTo(employeeDTO2); + employeeDTO2.setId(2L); + assertThat(employeeDTO1).isNotEqualTo(employeeDTO2); + employeeDTO1.setId(null); + assertThat(employeeDTO1).isNotEqualTo(employeeDTO2); + } + + @Test + @Transactional + public void testEntityFromId() { + assertThat(employeeMapper.fromId(42L).getId()).isEqualTo(42); + assertThat(employeeMapper.fromId(null)).isNull(); + } +} From 721c258491302603a1d618ad9582d239f26250e4 Mon Sep 17 00:00:00 2001 From: ridris Date: Thu, 20 Jun 2019 17:48:27 +0200 Subject: [PATCH 3/3] bank --- pom.xml | 7 +++++++ .../jhipster/application/config/SecurityConfiguration.java | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2f8e09b..ba31c4d 100644 --- a/pom.xml +++ b/pom.xml @@ -102,6 +102,13 @@ + + + io.springfox + springfox-swagger-ui + 2.9.2 + + io.github.jhipster jhipster-framework diff --git a/src/main/java/io/github/jhipster/application/config/SecurityConfiguration.java b/src/main/java/io/github/jhipster/application/config/SecurityConfiguration.java index f377984..ea72b2a 100644 --- a/src/main/java/io/github/jhipster/application/config/SecurityConfiguration.java +++ b/src/main/java/io/github/jhipster/application/config/SecurityConfiguration.java @@ -34,6 +34,7 @@ public void configure(WebSecurity web) throws Exception { .antMatchers(HttpMethod.OPTIONS, "/**") .antMatchers("/h2-console/**") .antMatchers("/swagger-ui/index.html") + .antMatchers("/swagger-ui.html") .antMatchers("/test/**"); } @@ -62,7 +63,7 @@ public void configure(HttpSecurity http) throws Exception { .and() .authorizeRequests() .antMatchers("/api/authenticate").permitAll() - .antMatchers("/api/**").authenticated() + .antMatchers("/api/**").permitAll() .antMatchers("/management/health").permitAll() .antMatchers("/management/info").permitAll() .antMatchers("/management/prometheus").permitAll()