From 61f3efbf9cbbec4a4437eec1614fdac948df0ebd Mon Sep 17 00:00:00 2001 From: Julia Seti Date: Mon, 12 Jun 2023 15:18:56 +0300 Subject: [PATCH 01/73] OrderBagMapping created --- .../main/java/greencity/entity/order/Bag.java | 20 +++++- .../java/greencity/entity/order/OrderBag.java | 67 +++++++++++++++++++ .../java/greencity/entity/order/Service.java | 5 ++ .../main/java/greencity/enums/BagStatus.java | 6 ++ .../java/greencity/enums/ServiceStatus.java | 6 ++ .../repository/OrderBagRepository.java | 10 +++ .../db/changelog/db.changelog-master.xml | 2 + ...-status-to-bag-and-service-tables-Seti.xml | 17 +++++ ...olumns-to-order-bag-mapping-table-Seti.xml | 27 ++++++++ 9 files changed, 157 insertions(+), 3 deletions(-) create mode 100644 dao/src/main/java/greencity/entity/order/OrderBag.java create mode 100644 dao/src/main/java/greencity/enums/BagStatus.java create mode 100644 dao/src/main/java/greencity/enums/ServiceStatus.java create mode 100644 dao/src/main/java/greencity/repository/OrderBagRepository.java create mode 100644 dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-and-service-tables-Seti.xml create mode 100644 dao/src/main/resources/db/changelog/logs/ch-add-columns-to-order-bag-mapping-table-Seti.xml diff --git a/dao/src/main/java/greencity/entity/order/Bag.java b/dao/src/main/java/greencity/entity/order/Bag.java index 0103570b1..f0bc0427f 100644 --- a/dao/src/main/java/greencity/entity/order/Bag.java +++ b/dao/src/main/java/greencity/entity/order/Bag.java @@ -1,15 +1,25 @@ package greencity.entity.order; import greencity.entity.user.employee.Employee; +import greencity.enums.BagStatus; import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import lombok.EqualsAndHashCode; import lombok.ToString; -import lombok.Builder; -import javax.persistence.*; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; import java.time.LocalDate; @Entity @@ -70,4 +80,8 @@ public class Bag { @ManyToOne @JoinColumn(nullable = false) private TariffsInfo tariffsInfo; + + @Column(nullable = false) + @Enumerated(EnumType.STRING) + private BagStatus status; } diff --git a/dao/src/main/java/greencity/entity/order/OrderBag.java b/dao/src/main/java/greencity/entity/order/OrderBag.java new file mode 100644 index 000000000..2f87f01b3 --- /dev/null +++ b/dao/src/main/java/greencity/entity/order/OrderBag.java @@ -0,0 +1,67 @@ +package greencity.entity.order; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.validation.constraints.Size; + +@Entity +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode +@ToString +@Getter +@Setter +@Builder +@Table(name = "order_bag_mapping") +public class OrderBag { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "order_id") + private Order order; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "bag_id") + private Bag bag; + + @Column(nullable = false) + private Integer amount; + + @Column + private Integer confirmedQuantity; + + @Column + private Integer exportedQuantity; + + @Column(nullable = false) + private Integer capacity; + + @Column(nullable = false) + private Long price; + + @Size(min = 1, max = 30) + @Column(nullable = false) + private String name; + + @Size(min = 1, max = 30) + @Column(nullable = false) + private String nameEng; +} + diff --git a/dao/src/main/java/greencity/entity/order/Service.java b/dao/src/main/java/greencity/entity/order/Service.java index 0ed06e732..15626c491 100644 --- a/dao/src/main/java/greencity/entity/order/Service.java +++ b/dao/src/main/java/greencity/entity/order/Service.java @@ -1,6 +1,7 @@ package greencity.entity.order; import greencity.entity.user.employee.Employee; +import greencity.enums.ServiceStatus; import lombok.*; import javax.persistence.*; @@ -51,4 +52,8 @@ public class Service { @OneToOne private TariffsInfo tariffsInfo; + + @Column(nullable = false) + @Enumerated(EnumType.STRING) + private ServiceStatus status; } diff --git a/dao/src/main/java/greencity/enums/BagStatus.java b/dao/src/main/java/greencity/enums/BagStatus.java new file mode 100644 index 000000000..f0f3fe1c2 --- /dev/null +++ b/dao/src/main/java/greencity/enums/BagStatus.java @@ -0,0 +1,6 @@ +package greencity.enums; + +public enum BagStatus { + ACTIVE, + DELETED +} diff --git a/dao/src/main/java/greencity/enums/ServiceStatus.java b/dao/src/main/java/greencity/enums/ServiceStatus.java new file mode 100644 index 000000000..10a36ec84 --- /dev/null +++ b/dao/src/main/java/greencity/enums/ServiceStatus.java @@ -0,0 +1,6 @@ +package greencity.enums; + +public enum ServiceStatus { + ACTIVE, + DELETED +} diff --git a/dao/src/main/java/greencity/repository/OrderBagRepository.java b/dao/src/main/java/greencity/repository/OrderBagRepository.java new file mode 100644 index 000000000..ac6c79138 --- /dev/null +++ b/dao/src/main/java/greencity/repository/OrderBagRepository.java @@ -0,0 +1,10 @@ +package greencity.repository; + +import greencity.entity.order.OrderBag; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface OrderBagRepository extends JpaRepository { + +} diff --git a/dao/src/main/resources/db/changelog/db.changelog-master.xml b/dao/src/main/resources/db/changelog/db.changelog-master.xml index 4f6d669b3..871b7ac4b 100644 --- a/dao/src/main/resources/db/changelog/db.changelog-master.xml +++ b/dao/src/main/resources/db/changelog/db.changelog-master.xml @@ -203,4 +203,6 @@ + + \ No newline at end of file diff --git a/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-and-service-tables-Seti.xml b/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-and-service-tables-Seti.xml new file mode 100644 index 000000000..4b353a66a --- /dev/null +++ b/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-and-service-tables-Seti.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/dao/src/main/resources/db/changelog/logs/ch-add-columns-to-order-bag-mapping-table-Seti.xml b/dao/src/main/resources/db/changelog/logs/ch-add-columns-to-order-bag-mapping-table-Seti.xml new file mode 100644 index 000000000..2ef118671 --- /dev/null +++ b/dao/src/main/resources/db/changelog/logs/ch-add-columns-to-order-bag-mapping-table-Seti.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From d9b1d88c07b17b736a473f821637d64764c526e8 Mon Sep 17 00:00:00 2001 From: Julia Seti Date: Tue, 13 Jun 2023 16:07:49 +0300 Subject: [PATCH 02/73] changed bag functionality logic --- .../java/greencity/entity/order/Order.java | 43 +++++++++++-- .../java/greencity/entity/order/OrderBag.java | 18 +++++- .../greencity/repository/BagRepository.java | 12 ++++ .../repository/OrderBagRepository.java | 1 - .../db/changelog/db.changelog-master.xml | 4 +- ...-status-to-bag-and-service-tables-Seti.xml | 2 +- ...olumns-to-order-bag-mapping-table-Seti.xml | 27 -------- ...ch-update-order-bag-mapping-table-Seti.xml | 63 +++++++++++++++++++ .../service/ubs/SuperAdminServiceImpl.java | 4 +- 9 files changed, 134 insertions(+), 40 deletions(-) delete mode 100644 dao/src/main/resources/db/changelog/logs/ch-add-columns-to-order-bag-mapping-table-Seti.xml create mode 100644 dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Seti.xml diff --git a/dao/src/main/java/greencity/entity/order/Order.java b/dao/src/main/java/greencity/entity/order/Order.java index 8215634a9..a238ccfde 100644 --- a/dao/src/main/java/greencity/entity/order/Order.java +++ b/dao/src/main/java/greencity/entity/order/Order.java @@ -1,21 +1,43 @@ package greencity.entity.order; -import greencity.enums.CancellationReason; -import greencity.enums.OrderPaymentStatus; -import greencity.enums.OrderStatus; import greencity.entity.notifications.UserNotification; import greencity.entity.user.User; import greencity.entity.user.employee.Employee; import greencity.entity.user.employee.EmployeeOrderPosition; import greencity.entity.user.employee.ReceivingStation; import greencity.entity.user.ubs.UBSuser; +import greencity.enums.CancellationReason; +import greencity.enums.OrderPaymentStatus; +import greencity.enums.OrderStatus; import greencity.filters.StringListConverter; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; import org.hibernate.annotations.Cascade; -import javax.persistence.*; +import javax.persistence.CascadeType; +import javax.persistence.CollectionTable; +import javax.persistence.Column; +import javax.persistence.Convert; +import javax.persistence.ElementCollection; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.MapKeyColumn; +import javax.persistence.OneToMany; +import javax.persistence.Table; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; @@ -160,4 +182,15 @@ public class Order { @Column(name = "write_off_station_sum") private Long writeOffStationSum; + + @OneToMany( + mappedBy = "order", + cascade = CascadeType.ALL, + orphanRemoval = true) + private List orderBags = new ArrayList<>(); + + public void addOrderBag(OrderBag orderBag) { + this.orderBags.add(orderBag); + orderBag.setOrder(this); + } } diff --git a/dao/src/main/java/greencity/entity/order/OrderBag.java b/dao/src/main/java/greencity/entity/order/OrderBag.java index 2f87f01b3..c305b6740 100644 --- a/dao/src/main/java/greencity/entity/order/OrderBag.java +++ b/dao/src/main/java/greencity/entity/order/OrderBag.java @@ -1,5 +1,6 @@ package greencity.entity.order; +import greencity.enums.BagStatus; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.EqualsAndHashCode; @@ -10,6 +11,8 @@ import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @@ -44,10 +47,10 @@ public class OrderBag { @Column(nullable = false) private Integer amount; - @Column + @Column(name = "confirmed_quantity") private Integer confirmedQuantity; - @Column + @Column(name = "exported_quantity") private Integer exportedQuantity; @Column(nullable = false) @@ -63,5 +66,14 @@ public class OrderBag { @Size(min = 1, max = 30) @Column(nullable = false) private String nameEng; -} + @Column(nullable = false) + private String description; + + @Column(nullable = false) + private String descriptionEng; + + @Column(nullable = false) + @Enumerated(EnumType.STRING) + private BagStatus bagStatus; +} diff --git a/dao/src/main/java/greencity/repository/BagRepository.java b/dao/src/main/java/greencity/repository/BagRepository.java index 18d35c029..84a670af1 100644 --- a/dao/src/main/java/greencity/repository/BagRepository.java +++ b/dao/src/main/java/greencity/repository/BagRepository.java @@ -1,6 +1,7 @@ package greencity.repository; import greencity.entity.order.Bag; +import greencity.enums.BagStatus; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -86,4 +87,15 @@ public interface BagRepository extends JpaRepository { * @author Safarov Renat */ List findBagsByTariffsInfoId(Long tariffInfoId); + + /** + * method, that returns {@link List} of {@link Bag} by tariff id and bag's + * status. + * + * @param tariffsInfoId {@link Long} tariff id + * @param status {@link BagStatus} bag status + * @return {@link List} of {@link Bag} + * @author Julia Seti + */ + List findBagsByTariffsInfoIdAndStatus(Long tariffsInfoId, BagStatus status); } \ No newline at end of file diff --git a/dao/src/main/java/greencity/repository/OrderBagRepository.java b/dao/src/main/java/greencity/repository/OrderBagRepository.java index ac6c79138..10d6f1bc3 100644 --- a/dao/src/main/java/greencity/repository/OrderBagRepository.java +++ b/dao/src/main/java/greencity/repository/OrderBagRepository.java @@ -6,5 +6,4 @@ @Repository public interface OrderBagRepository extends JpaRepository { - } diff --git a/dao/src/main/resources/db/changelog/db.changelog-master.xml b/dao/src/main/resources/db/changelog/db.changelog-master.xml index 15f7cbf4d..a7e971a0c 100644 --- a/dao/src/main/resources/db/changelog/db.changelog-master.xml +++ b/dao/src/main/resources/db/changelog/db.changelog-master.xml @@ -207,6 +207,6 @@ - - + + \ No newline at end of file diff --git a/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-and-service-tables-Seti.xml b/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-and-service-tables-Seti.xml index 4b353a66a..4fcfc4a35 100644 --- a/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-and-service-tables-Seti.xml +++ b/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-and-service-tables-Seti.xml @@ -2,7 +2,7 @@ - + diff --git a/dao/src/main/resources/db/changelog/logs/ch-add-columns-to-order-bag-mapping-table-Seti.xml b/dao/src/main/resources/db/changelog/logs/ch-add-columns-to-order-bag-mapping-table-Seti.xml deleted file mode 100644 index 2ef118671..000000000 --- a/dao/src/main/resources/db/changelog/logs/ch-add-columns-to-order-bag-mapping-table-Seti.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Seti.xml b/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Seti.xml new file mode 100644 index 000000000..91235876f --- /dev/null +++ b/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Seti.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + update order_bag_mapping set + capacity=bag.capacity, + price=bag.full_price, + name=bag.name, + name_eng=bag.name_eng, + description=bag.description, + description_eng=bag.description_eng, + bag_status=bag.status + from bag + where bag_id=bag.id + + + + + + + + + + + + + \ No newline at end of file diff --git a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java index 8e1efef4d..bd5065bd7 100644 --- a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java @@ -34,6 +34,7 @@ import greencity.entity.user.Region; import greencity.entity.user.employee.Employee; import greencity.entity.user.employee.ReceivingStation; +import greencity.enums.BagStatus; import greencity.enums.CourierLimit; import greencity.enums.CourierStatus; import greencity.enums.LocationStatus; @@ -125,6 +126,7 @@ private Bag createBag(long tariffId, TariffServiceDto dto, String employeeUuid) TariffsInfo tariffsInfo = tryToFindTariffById(tariffId); Employee employee = tryToFindEmployeeByUuid(employeeUuid); Bag bag = modelMapper.map(dto, Bag.class); + bag.setStatus(BagStatus.ACTIVE); bag.setTariffsInfo(tariffsInfo); bag.setCreatedBy(employee); return bag; @@ -133,7 +135,7 @@ private Bag createBag(long tariffId, TariffServiceDto dto, String employeeUuid) @Override public List getTariffService(long tariffId) { if (tariffsInfoRepository.existsById(tariffId)) { - return bagRepository.findBagsByTariffsInfoId(tariffId) + return bagRepository.findBagsByTariffsInfoIdAndStatus(tariffId, BagStatus.ACTIVE) .stream() .map(it -> modelMapper.map(it, GetTariffServiceDto.class)) .collect(Collectors.toList()); From eaf1ce0ee221e56b2ac002251549325d32d46222 Mon Sep 17 00:00:00 2001 From: Julia Seti Date: Thu, 15 Jun 2023 19:08:30 +0300 Subject: [PATCH 03/73] added bag status active and deleted --- .../java/greencity/entity/order/Order.java | 16 +- .../java/greencity/entity/order/OrderBag.java | 13 - .../greencity/repository/BagRepository.java | 26 +- .../repository/OrderBagRepository.java | 15 + .../repository/ServiceRepository.java | 20 +- ...ch-update-order-bag-mapping-table-Seti.xml | 17 +- .../service/ubs/SuperAdminServiceImpl.java | 77 ++++-- .../service/ubs/UBSClientServiceImpl.java | 2 +- .../service/ubs/UBSManagementServiceImpl.java | 4 +- .../src/test/java/greencity/ModelUtils.java | 86 +++++- .../ubs/SuperAdminServiceImplTest.java | 257 ++++++++++-------- .../service/ubs/UBSClientServiceImplTest.java | 26 +- .../ubs/UBSManagementServiceImplTest.java | 42 +-- 13 files changed, 378 insertions(+), 223 deletions(-) diff --git a/dao/src/main/java/greencity/entity/order/Order.java b/dao/src/main/java/greencity/entity/order/Order.java index a238ccfde..e3773de3f 100644 --- a/dao/src/main/java/greencity/entity/order/Order.java +++ b/dao/src/main/java/greencity/entity/order/Order.java @@ -50,10 +50,10 @@ @Builder @Table(name = "orders") @EqualsAndHashCode(exclude = {"employeeOrderPositions", "userNotifications", "ubsUser", - "changeOfPointsList", "blockedByEmployee", "certificates", "attachedEmployees", "payment", "employeeOrderPositions", + "changeOfPointsList", "blockedByEmployee", "certificates", "payment", "employeeOrderPositions", "events", "imageReasonNotTakingBags", "additionalOrders"}) @ToString(exclude = {"employeeOrderPositions", "userNotifications", "ubsUser", - "changeOfPointsList", "blockedByEmployee", "certificates", "attachedEmployees", "payment", "employeeOrderPositions", + "changeOfPointsList", "blockedByEmployee", "certificates", "payment", "employeeOrderPositions", "events", "imageReasonNotTakingBags", "additionalOrders"}) public class Order { @Id @@ -184,11 +184,17 @@ public class Order { private Long writeOffStationSum; @OneToMany( - mappedBy = "order", - cascade = CascadeType.ALL, - orphanRemoval = true) + mappedBy = "order", + cascade = CascadeType.ALL, + orphanRemoval = true) private List orderBags = new ArrayList<>(); + /** + * method, that helps to save OrderBag. + * + * @param orderBag {@link OrderBag} + * @author Julia Seti + */ public void addOrderBag(OrderBag orderBag) { this.orderBags.add(orderBag); orderBag.setOrder(this); diff --git a/dao/src/main/java/greencity/entity/order/OrderBag.java b/dao/src/main/java/greencity/entity/order/OrderBag.java index c305b6740..961ea16cc 100644 --- a/dao/src/main/java/greencity/entity/order/OrderBag.java +++ b/dao/src/main/java/greencity/entity/order/OrderBag.java @@ -1,6 +1,5 @@ package greencity.entity.order; -import greencity.enums.BagStatus; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.EqualsAndHashCode; @@ -11,8 +10,6 @@ import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @@ -66,14 +63,4 @@ public class OrderBag { @Size(min = 1, max = 30) @Column(nullable = false) private String nameEng; - - @Column(nullable = false) - private String description; - - @Column(nullable = false) - private String descriptionEng; - - @Column(nullable = false) - @Enumerated(EnumType.STRING) - private BagStatus bagStatus; } diff --git a/dao/src/main/java/greencity/repository/BagRepository.java b/dao/src/main/java/greencity/repository/BagRepository.java index 84a670af1..ff2c85bef 100644 --- a/dao/src/main/java/greencity/repository/BagRepository.java +++ b/dao/src/main/java/greencity/repository/BagRepository.java @@ -1,7 +1,6 @@ package greencity.repository; import greencity.entity.order.Bag; -import greencity.enums.BagStatus; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -9,6 +8,7 @@ import java.util.List; import java.util.Map; +import java.util.Optional; @Repository public interface BagRepository extends JpaRepository { @@ -80,22 +80,26 @@ public interface BagRepository extends JpaRepository { List findAllByOrder(@Param("orderId") Long orderId); /** - * method, that returns {@link List} of {@link Bag} by tariff id. + * method, that returns {@link List} of {@link Bag} by id. * - * @param tariffInfoId tariff id {@link Long} - * @return {@link List} of {@link Bag} by tariffInfoId. - * @author Safarov Renat + * @param bagId {@link Integer} tariff service id + * @return {@link Optional} of {@link Bag} + * @author Julia Seti */ - List findBagsByTariffsInfoId(Long tariffInfoId); + @Query(nativeQuery = true, + value = "SELECT * FROM bag " + + "WHERE id = :bagId AND status = 'ACTIVE'") + Optional findActiveBagById(Integer bagId); /** - * method, that returns {@link List} of {@link Bag} by tariff id and bag's - * status. + * method, that returns {@link List} of active {@link Bag} by tariff id. * - * @param tariffsInfoId {@link Long} tariff id - * @param status {@link BagStatus} bag status + * @param tariffInfoId {@link Long} tariff id * @return {@link List} of {@link Bag} * @author Julia Seti */ - List findBagsByTariffsInfoIdAndStatus(Long tariffsInfoId, BagStatus status); + @Query(nativeQuery = true, + value = "SELECT * FROM bag " + + "WHERE tariffs_info_id = :tariffInfoId AND status = 'ACTIVE'") + List findAllActiveBagsByTariffsInfoId(Long tariffInfoId); } \ No newline at end of file diff --git a/dao/src/main/java/greencity/repository/OrderBagRepository.java b/dao/src/main/java/greencity/repository/OrderBagRepository.java index 10d6f1bc3..df1c69c39 100644 --- a/dao/src/main/java/greencity/repository/OrderBagRepository.java +++ b/dao/src/main/java/greencity/repository/OrderBagRepository.java @@ -2,8 +2,23 @@ import greencity.entity.order.OrderBag; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface OrderBagRepository extends JpaRepository { + /** + * method, that returns {@link List} of {@link OrderBag} by bag id for unpaid + * orders. + * + * @param bagId {@link Integer} bag id + * @return {@link List} of {@link OrderBag} + * @author Julia Seti + */ + @Query(value = "SELECT * FROM order_bag_mapping as obm " + + "JOIN orders o on o.id = obm.order_id " + + "WHERE obm.bag_id = :bagId AND o.order_payment_status = 'UNPAID'", nativeQuery = true) + List findAllOrderBagsForUnpaidOrdersByBagId(Integer bagId); } diff --git a/dao/src/main/java/greencity/repository/ServiceRepository.java b/dao/src/main/java/greencity/repository/ServiceRepository.java index 309cd1e54..704d73e55 100644 --- a/dao/src/main/java/greencity/repository/ServiceRepository.java +++ b/dao/src/main/java/greencity/repository/ServiceRepository.java @@ -2,16 +2,32 @@ import greencity.entity.order.Service; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import java.util.Optional; public interface ServiceRepository extends JpaRepository { /** - * Method that return service by TariffsInfo id. + * Method that returns active service by id. + * + * @param serviceId {@link Long} - service id + * @return {@link Optional} of {@link Service} + * @author Julia Seti + */ + @Query(nativeQuery = true, + value = "SELECT * FROM service " + + "WHERE id = :serviceId AND status = 'ACTIVE'") + Optional findActiveServiceById(Long serviceId); + + /** + * Method that returns active service by TariffsInfo id. * * @param tariffId {@link Long} - TariffsInfo id * @return {@link Optional} of {@link Service} * @author Julia Seti */ - Optional findServiceByTariffsInfoId(Long tariffId); + @Query(nativeQuery = true, + value = "SELECT * FROM service " + + "WHERE tariffs_info_id = :tariffInfoId AND status = 'ACTIVE'") + Optional findActiveServiceByTariffsInfoId(Long tariffId); } diff --git a/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Seti.xml b/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Seti.xml index 91235876f..91e8fd1bc 100644 --- a/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Seti.xml +++ b/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Seti.xml @@ -20,15 +20,6 @@ - - - - - - - - - @@ -55,9 +43,6 @@ - - - \ No newline at end of file diff --git a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java index bd5065bd7..620f05284 100644 --- a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java @@ -14,10 +14,10 @@ import greencity.dto.location.EditLocationDto; import greencity.dto.location.LocationCreateDto; import greencity.dto.location.LocationInfoDto; -import greencity.dto.service.TariffServiceDto; -import greencity.dto.service.ServiceDto; import greencity.dto.service.GetServiceDto; import greencity.dto.service.GetTariffServiceDto; +import greencity.dto.service.ServiceDto; +import greencity.dto.service.TariffServiceDto; import greencity.dto.tariff.AddNewTariffResponseDto; import greencity.dto.tariff.ChangeTariffLocationStatusDto; import greencity.dto.tariff.EditTariffDto; @@ -27,6 +27,7 @@ import greencity.entity.coords.Coordinates; import greencity.entity.order.Bag; import greencity.entity.order.Courier; +import greencity.entity.order.OrderBag; import greencity.entity.order.Service; import greencity.entity.order.TariffLocation; import greencity.entity.order.TariffsInfo; @@ -38,6 +39,7 @@ import greencity.enums.CourierLimit; import greencity.enums.CourierStatus; import greencity.enums.LocationStatus; +import greencity.enums.ServiceStatus; import greencity.enums.StationStatus; import greencity.enums.TariffStatus; import greencity.exceptions.BadRequestException; @@ -53,6 +55,7 @@ import greencity.repository.DeactivateChosenEntityRepository; import greencity.repository.EmployeeRepository; import greencity.repository.LocationRepository; +import greencity.repository.OrderBagRepository; import greencity.repository.ReceivingStationRepository; import greencity.repository.RegionRepository; import greencity.repository.ServiceRepository; @@ -69,6 +72,7 @@ import java.math.RoundingMode; import java.time.LocalDate; import java.util.ArrayList; +import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.List; @@ -76,7 +80,6 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; -import java.util.Collections; @org.springframework.stereotype.Service @Data @@ -93,6 +96,8 @@ public class SuperAdminServiceImpl implements SuperAdminService { private final ModelMapper modelMapper; private final TariffLocationRepository tariffsLocationRepository; private final DeactivateChosenEntityRepository deactivateTariffsForChosenParamRepository; + private final OrderBagRepository orderBagRepository; + private static final String BAD_SIZE_OF_REGIONS_MESSAGE = "Region ids size should be 1 if several params are selected"; private static final String REGIONS_NOT_EXIST_MESSAGE = "Current region doesn't exist: %s"; @@ -135,7 +140,7 @@ private Bag createBag(long tariffId, TariffServiceDto dto, String employeeUuid) @Override public List getTariffService(long tariffId) { if (tariffsInfoRepository.existsById(tariffId)) { - return bagRepository.findBagsByTariffsInfoIdAndStatus(tariffId, BagStatus.ACTIVE) + return bagRepository.findAllActiveBagsByTariffsInfoId(tariffId) .stream() .map(it -> modelMapper.map(it, GetTariffServiceDto.class)) .collect(Collectors.toList()); @@ -145,11 +150,17 @@ public List getTariffService(long tariffId) { } @Override + @Transactional public void deleteTariffService(Integer bagId) { Bag bag = tryToFindBagById(bagId); + bag.setStatus(BagStatus.DELETED); + bagRepository.save(bag); + checkDeletedBagLimitAndUpdateTariffsInfo(bag); + } + + private void checkDeletedBagLimitAndUpdateTariffsInfo(Bag bag) { TariffsInfo tariffsInfo = bag.getTariffsInfo(); - bagRepository.delete(bag); - List bags = bagRepository.findBagsByTariffsInfoId(tariffsInfo.getId()); + List bags = bagRepository.findAllActiveBagsByTariffsInfoId(tariffsInfo.getId()); if (bags.isEmpty() || bags.stream().noneMatch(Bag::getLimitIncluded)) { tariffsInfo.setTariffStatus(TariffStatus.NEW); tariffsInfo.setBags(bags); @@ -162,9 +173,22 @@ public void deleteTariffService(Integer bagId) { } @Override - public GetTariffServiceDto editTariffService(TariffServiceDto dto, Integer id, String employeeUuid) { - Bag bag = tryToFindBagById(id); + @Transactional + public GetTariffServiceDto editTariffService(TariffServiceDto dto, Integer bagId, String employeeUuid) { + Bag bag = tryToFindBagById(bagId); Employee employee = tryToFindEmployeeByUuid(employeeUuid); + updateTariffService(dto, bag); + bag.setEditedBy(employee); + + List orderBags = orderBagRepository.findAllOrderBagsForUnpaidOrdersByBagId(bagId); + if (!orderBags.isEmpty()) { + orderBags.forEach(it -> updateOrderBag(it, bag)); + orderBagRepository.saveAll(orderBags); + } + return modelMapper.map(bagRepository.save(bag), GetTariffServiceDto.class); + } + + private void updateTariffService(TariffServiceDto dto, Bag bag) { bag.setCapacity(dto.getCapacity()); bag.setPrice(convertBillsIntoCoins(dto.getPrice())); bag.setCommission(convertBillsIntoCoins(dto.getCommission())); @@ -174,8 +198,13 @@ public GetTariffServiceDto editTariffService(TariffServiceDto dto, Integer id, S bag.setDescription(dto.getDescription()); bag.setDescriptionEng(dto.getDescriptionEng()); bag.setEditedAt(LocalDate.now()); - bag.setEditedBy(employee); - return modelMapper.map(bagRepository.save(bag), GetTariffServiceDto.class); + } + + private void updateOrderBag(OrderBag orderBag, Bag bag) { + orderBag.setCapacity(bag.getCapacity()); + orderBag.setPrice(bag.getFullPrice()); + orderBag.setName(bag.getName()); + orderBag.setNameEng(bag.getNameEng()); } private Long convertBillsIntoCoins(Double bills) { @@ -188,8 +217,8 @@ private Long convertBillsIntoCoins(Double bills) { } private Bag tryToFindBagById(Integer id) { - return bagRepository.findById(id) - .orElseThrow(() -> new NotFoundException(ErrorMessage.BAG_NOT_FOUND + id)); + return bagRepository.findActiveBagById(id).orElseThrow( + () -> new NotFoundException(ErrorMessage.BAG_NOT_FOUND + id)); } private Long getFullPrice(Double price, Double commission) { @@ -203,13 +232,14 @@ public GetServiceDto addService(Long tariffId, ServiceDto dto, String employeeUu } private Service createService(Long tariffId, ServiceDto dto, String employeeUuid) { - if (tryToFindServiceByTariffsInfoId(tariffId).isEmpty()) { + TariffsInfo tariffsInfo = tryToFindTariffById(tariffId); + if (serviceRepository.findActiveServiceByTariffsInfoId(tariffId).isEmpty()) { Employee employee = tryToFindEmployeeByUuid(employeeUuid); - TariffsInfo tariffsInfo = tryToFindTariffById(tariffId); Service service = modelMapper.map(dto, Service.class); service.setCreatedBy(employee); service.setCreatedAt(LocalDate.now()); service.setTariffsInfo(tariffsInfo); + service.setStatus(ServiceStatus.ACTIVE); return service; } else { throw new ServiceAlreadyExistsException(ErrorMessage.SERVICE_ALREADY_EXISTS + tariffId); @@ -218,14 +248,17 @@ private Service createService(Long tariffId, ServiceDto dto, String employeeUuid @Override public GetServiceDto getService(long tariffId) { - return tryToFindServiceByTariffsInfoId(tariffId) + tryToFindTariffById(tariffId); + return serviceRepository.findActiveServiceByTariffsInfoId(tariffId) .map(it -> modelMapper.map(it, GetServiceDto.class)) - .orElse(null); + .orElseGet(() -> null); } @Override public void deleteService(long id) { - serviceRepository.delete(tryToFindServiceById(id)); + Service service = tryToFindServiceById(id); + service.setStatus(ServiceStatus.DELETED); + serviceRepository.save(service); } @Override @@ -247,16 +280,8 @@ private Employee tryToFindEmployeeByUuid(String employeeUuid) { .orElseThrow(() -> new NotFoundException(ErrorMessage.EMPLOYEE_WITH_UUID_NOT_FOUND + employeeUuid)); } - private Optional tryToFindServiceByTariffsInfoId(long tariffId) { - if (tariffsInfoRepository.existsById(tariffId)) { - return serviceRepository.findServiceByTariffsInfoId(tariffId); - } else { - throw new NotFoundException(ErrorMessage.TARIFF_NOT_FOUND + tariffId); - } - } - private Service tryToFindServiceById(long id) { - return serviceRepository.findById(id) + return serviceRepository.findActiveServiceById(id) .orElseThrow(() -> new NotFoundException(ErrorMessage.SERVICE_IS_NOT_FOUND_BY_ID + id)); } diff --git a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java index 6bd1099c5..eede026d1 100644 --- a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java @@ -351,7 +351,7 @@ private boolean isTariffAvailableForCurrentLocation(TariffsInfo tariffsInfo, Loc private UserPointsAndAllBagsDto getUserPointsAndAllBagsDtoByTariffIdAndUserPoints(Long tariffId, Integer userPoints) { - var bagTranslationDtoList = bagRepository.findBagsByTariffsInfoId(tariffId).stream() + var bagTranslationDtoList = bagRepository.findAllActiveBagsByTariffsInfoId(tariffId).stream() .map(bag -> modelMapper.map(bag, BagTranslationDto.class)) .collect(toList()); return new UserPointsAndAllBagsDto(bagTranslationDtoList, userPoints); diff --git a/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java index 0ca5c52fa..d73a929de 100644 --- a/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java @@ -360,11 +360,11 @@ public OrderStatusPageDto getOrderStatusData(Long orderId, String email) { checkAvailableOrderForEmployee(order, email); CounterOrderDetailsDto prices = getPriceDetails(orderId); - var bagInfoDtoList = bagRepository.findBagsByTariffsInfoId(order.getTariffsInfo().getId()).stream() + var bagInfoDtoList = bagRepository.findAllActiveBagsByTariffsInfoId(order.getTariffsInfo().getId()).stream() .map(bag -> modelMapper.map(bag, BagInfoDto.class)) .collect(Collectors.toList()); - Long servicePriceInCoins = serviceRepository.findServiceByTariffsInfoId(order.getTariffsInfo().getId()) + Long servicePriceInCoins = serviceRepository.findActiveServiceByTariffsInfoId(order.getTariffsInfo().getId()) .map(it -> it.getPrice()) .orElse(0L); diff --git a/service/src/test/java/greencity/ModelUtils.java b/service/src/test/java/greencity/ModelUtils.java index 9b2566b0a..e74d5895f 100644 --- a/service/src/test/java/greencity/ModelUtils.java +++ b/service/src/test/java/greencity/ModelUtils.java @@ -98,6 +98,7 @@ import greencity.entity.order.Courier; import greencity.entity.order.Event; import greencity.entity.order.Order; +import greencity.entity.order.OrderBag; import greencity.entity.order.OrderPaymentStatusTranslation; import greencity.entity.order.OrderStatusTranslation; import greencity.entity.order.Payment; @@ -117,6 +118,7 @@ import greencity.entity.user.ubs.UBSuser; import greencity.entity.viber.ViberBot; import greencity.enums.AddressStatus; +import greencity.enums.BagStatus; import greencity.enums.CancellationReason; import greencity.enums.CertificateStatus; import greencity.enums.CourierLimit; @@ -128,6 +130,7 @@ import greencity.enums.OrderPaymentStatus; import greencity.enums.OrderStatus; import greencity.enums.PaymentStatus; +import greencity.enums.ServiceStatus; import greencity.enums.TariffStatus; import greencity.util.Bot; import org.springframework.data.domain.Page; @@ -2524,6 +2527,17 @@ public static GetTariffServiceDto getGetTariffServiceDto() { .build(); } + public static OrderBag getOrderBag() { + return OrderBag.builder() + .id(1L) + .amount(1) + .price(150_00L) + .capacity(20) + .bag(getBag()) + .order(getOrder()) + .build(); + } + public static Optional getOptionalBag() { return Optional.of(Bag.builder() .id(1) @@ -2541,6 +2555,22 @@ public static Optional getOptionalBag() { } public static Bag getBag() { + return Bag.builder() + .id(1) + .capacity(120) + .commission(50_00L) + .price(120_00L) + .fullPrice(170_00L) + .createdAt(LocalDate.now()) + .createdBy(getEmployee()) + .editedBy(getEmployee()) + .limitIncluded(true) + .status(BagStatus.ACTIVE) + .tariffsInfo(getTariffInfo()) + .build(); + } + + public static Bag getBagDeleted() { return Bag.builder() .id(1) .capacity(120) @@ -2553,20 +2583,54 @@ public static Bag getBag() { .description("Description") .descriptionEng("DescriptionEng") .limitIncluded(true) + .status(BagStatus.DELETED) + .tariffsInfo(getTariffInfo()) .build(); } public static TariffServiceDto getTariffServiceDto() { return TariffServiceDto.builder() .name("Бавовняна сумка") - .capacity(120) - .price(120.0) + .capacity(20) + .price(100.0) .commission(50.0) .description("Description") .build(); } + public static Bag getEditedBag() { + return Bag.builder() + .id(1) + .capacity(20) + .price(100_00L) + .fullPrice(150_00L) + .commission(50_00L) + .name("Бавовняна сумка") + .description("Description") + .createdAt(LocalDate.now()) + .createdBy(getEmployee()) + .editedBy(getEmployee()) + .editedAt(LocalDate.now()) + .limitIncluded(true) + .status(BagStatus.ACTIVE) + .tariffsInfo(getTariffInfo()) + .build(); + + } + + public static OrderBag getEditedOrderBag() { + return OrderBag.builder() + .id(1L) + .amount(1) + .price(150_00L) + .capacity(20) + .name("Бавовняна сумка") + .bag(getBag()) + .order(getOrder()) + .build(); + } + public static Location getLocation() { return Location.builder() .id(1L) @@ -2664,6 +2728,7 @@ public static Bag getNewBag() { .descriptionEng("DescriptionEng") .name("name") .nameEng("nameEng") + .status(BagStatus.ACTIVE) .build(); } @@ -2713,6 +2778,22 @@ public static Service getService() { .descriptionEng("DescriptionEng") .name("Name") .nameEng("NameEng") + .status(ServiceStatus.ACTIVE) + .build(); + } + + public static Service getServiceDeleted() { + Employee employee = ModelUtils.getEmployee(); + return Service.builder() + .id(1L) + .price(100_00L) + .createdAt(LocalDate.now()) + .createdBy(employee) + .description("Description") + .descriptionEng("DescriptionEng") + .name("Name") + .nameEng("NameEng") + .status(ServiceStatus.DELETED) .build(); } @@ -2726,6 +2807,7 @@ public static Service getNewService() { .descriptionEng("DescriptionEng") .name("Name") .nameEng("NameEng") + .status(ServiceStatus.ACTIVE) .build(); } diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index 8b85945f8..220e3d1af 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -24,6 +24,7 @@ import greencity.dto.tariff.SetTariffLimitsDto; import greencity.entity.order.Bag; import greencity.entity.order.Courier; +import greencity.entity.order.OrderBag; import greencity.entity.order.Service; import greencity.entity.order.TariffLocation; import greencity.entity.order.TariffsInfo; @@ -48,6 +49,7 @@ import greencity.repository.DeactivateChosenEntityRepository; import greencity.repository.EmployeeRepository; import greencity.repository.LocationRepository; +import greencity.repository.OrderBagRepository; import greencity.repository.ReceivingStationRepository; import greencity.repository.RegionRepository; import greencity.repository.ServiceRepository; @@ -131,6 +133,8 @@ class SuperAdminServiceImplTest { private TariffLocationRepository tariffsLocationRepository; @Mock private DeactivateChosenEntityRepository deactivateTariffsForChosenParamRepository; + @Mock + private OrderBagRepository orderBagRepository; @AfterEach void afterEach() { @@ -146,7 +150,8 @@ void afterEach() { receivingStationRepository, tariffsInfoRepository, tariffsLocationRepository, - deactivateTariffsForChosenParamRepository); + deactivateTariffsForChosenParamRepository, + orderBagRepository); } @Test @@ -205,20 +210,34 @@ void addTariffServiceIfTariffNotFoundExceptionTest() { @Test void getTariffServiceTest() { - List bags = List.of(ModelUtils.getOptionalBag().get()); + List bags = List.of(ModelUtils.getNewBag()); GetTariffServiceDto dto = ModelUtils.getGetTariffServiceDto(); when(tariffsInfoRepository.existsById(1L)).thenReturn(true); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(bags); + when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(bags); when(modelMapper.map(bags.get(0), GetTariffServiceDto.class)).thenReturn(dto); superAdminService.getTariffService(1); verify(tariffsInfoRepository).existsById(1L); - verify(bagRepository).findBagsByTariffsInfoId(1L); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); verify(modelMapper).map(bags.get(0), GetTariffServiceDto.class); } + @Test + void getTariffServiceIfThereAreNoBags() { + List bags = Collections.emptyList(); + + when(tariffsInfoRepository.existsById(1L)).thenReturn(true); + when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(bags); + + List dtos = superAdminService.getTariffService(1); + + assertEquals(Collections.emptyList(), dtos); + verify(tariffsInfoRepository).existsById(1L); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); + } + @Test void getTariffServiceIfTariffNotFoundException() { when(tariffsInfoRepository.existsById(1L)).thenReturn(false); @@ -227,117 +246,131 @@ void getTariffServiceIfTariffNotFoundException() { () -> superAdminService.getTariffService(1)); verify(tariffsInfoRepository).existsById(1L); - verify(bagRepository, never()).findBagsByTariffsInfoId(1L); + verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(1L); } @Test void deleteTariffServiceWhenTariffBagsWithLimits() { Bag bag = ModelUtils.getBag(); + Bag bagDeleted = ModelUtils.getBagDeleted(); TariffsInfo tariffsInfo = ModelUtils.getTariffInfo(); - bag.setTariffsInfo(tariffsInfo); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); - doNothing().when(bagRepository).delete(bag); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(List.of(bag)); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.save(bag)).thenReturn(bagDeleted); + when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(List.of(bag)); + superAdminService.deleteTariffService(1); - assertEquals(TariffStatus.ACTIVE, tariffsInfo.getTariffStatus()); - verify(bagRepository).findById(1); - verify(bagRepository).delete(bag); - verify(bagRepository).findBagsByTariffsInfoId(1L); + + verify(bagRepository).findActiveBagById(1); + verify(bagRepository).save(bag); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); verify(tariffsInfoRepository, never()).save(tariffsInfo); } @Test void deleteTariffServiceWhenTariffBagsListIsEmpty() { Bag bag = ModelUtils.getBag(); - TariffsInfo tariffsInfo = ModelUtils.getTariffInfo(); - bag.setTariffsInfo(tariffsInfo); + Bag bagDeleted = ModelUtils.getBagDeleted(); TariffsInfo tariffsInfoNew = ModelUtils.getTariffsInfoWithStatusNew(); tariffsInfoNew.setBags(Collections.emptyList()); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); - doNothing().when(bagRepository).delete(bag); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(Collections.emptyList()); - when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfo); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.save(bag)).thenReturn(bagDeleted); + when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(Collections.emptyList()); + when(tariffsInfoRepository.save(tariffsInfoNew)).thenReturn(tariffsInfoNew); + superAdminService.deleteTariffService(1); - assertEquals(TariffStatus.NEW, tariffsInfoNew.getTariffStatus()); - verify(bagRepository).findById(1); - verify(bagRepository).delete(bag); - verify(bagRepository).findBagsByTariffsInfoId(1L); - verify(tariffsInfoRepository).save(tariffsInfo); + + verify(bagRepository).findActiveBagById(1); + verify(bagRepository).save(bag); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); + verify(tariffsInfoRepository).save(tariffsInfoNew); } @Test void deleteTariffServiceWhenTariffBagsWithoutLimits() { Bag bag = ModelUtils.getBag(); - TariffsInfo tariffsInfo = ModelUtils.getTariffInfo(); bag.setLimitIncluded(false); - bag.setTariffsInfo(tariffsInfo); + Bag bagDeleted = ModelUtils.getBagDeleted(); + bagDeleted.setLimitIncluded(false); TariffsInfo tariffsInfoNew = ModelUtils.getTariffsInfoWithStatusNew(); tariffsInfoNew.setBags(Collections.emptyList()); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); - doNothing().when(bagRepository).delete(bag); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(List.of(bag)); - when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfoNew); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.save(bag)).thenReturn(bagDeleted); + when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(List.of(bag)); + when(tariffsInfoRepository.save(tariffsInfoNew)).thenReturn(tariffsInfoNew); + superAdminService.deleteTariffService(1); - assertEquals(TariffStatus.NEW, tariffsInfoNew.getTariffStatus()); - verify(bagRepository).findById(1); - verify(bagRepository).delete(bag); - verify(bagRepository).findBagsByTariffsInfoId(1L); + + verify(bagRepository).findActiveBagById(1); + verify(bagRepository).save(bag); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); verify(tariffsInfoRepository).save(tariffsInfoNew); } @Test - void deleteTariffServiceThrowNotFoundException() { - when(bagRepository.findById(1)).thenReturn(Optional.empty()); + void deleteTariffServiceThrowBagNotFoundException() { + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, () -> superAdminService.deleteTariffService(1)); - verify(bagRepository).findById(1); - verify(bagRepository, never()).delete(any(Bag.class)); + verify(bagRepository).findActiveBagById(1); + verify(bagRepository, never()).save(any(Bag.class)); } @Test void editTariffService() { Bag bag = ModelUtils.getBag(); + Bag editedBag = ModelUtils.getEditedBag(); Employee employee = ModelUtils.getEmployee(); TariffServiceDto dto = ModelUtils.getTariffServiceDto(); GetTariffServiceDto editedDto = ModelUtils.getGetTariffServiceDto(); + OrderBag orderBag = ModelUtils.getOrderBag(); + OrderBag editedOrderBag = ModelUtils.getEditedOrderBag(); String uuid = UUID.randomUUID().toString(); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); - when(bagRepository.save(bag)).thenReturn(bag); - when(modelMapper.map(bag, GetTariffServiceDto.class)).thenReturn(editedDto); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.save(editedBag)).thenReturn(editedBag); + when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); + when(orderBagRepository.findAllOrderBagsForUnpaidOrdersByBagId(1)).thenReturn(List.of(orderBag)); + when(orderBagRepository.saveAll(List.of(editedOrderBag))).thenReturn(List.of(editedOrderBag)); - superAdminService.editTariffService(dto, 1, uuid); + GetTariffServiceDto actual = superAdminService.editTariffService(dto, 1, uuid); + assertEquals(editedDto, actual); verify(employeeRepository).findByUuid(uuid); - verify(bagRepository).findById(1); - verify(bagRepository).save(bag); - verify(modelMapper).map(bag, GetTariffServiceDto.class); + verify(bagRepository).findActiveBagById(1); + verify(bagRepository).save(editedBag); + verify(modelMapper).map(editedBag, GetTariffServiceDto.class); + verify(orderBagRepository).findAllOrderBagsForUnpaidOrdersByBagId(1); + verify(orderBagRepository).saveAll(List.of(editedOrderBag)); } @Test - void editTariffServiceIfCommissionIsNull() { + void editTariffServiceIfOrderBagsListIsEmpty() { Bag bag = ModelUtils.getBag(); + Bag editedBag = ModelUtils.getEditedBag(); Employee employee = ModelUtils.getEmployee(); TariffServiceDto dto = ModelUtils.getTariffServiceDto(); - dto.setCommission(null); GetTariffServiceDto editedDto = ModelUtils.getGetTariffServiceDto(); String uuid = UUID.randomUUID().toString(); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); - when(bagRepository.save(bag)).thenReturn(bag); - when(modelMapper.map(bag, GetTariffServiceDto.class)).thenReturn(editedDto); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.save(editedBag)).thenReturn(editedBag); + when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); + when(orderBagRepository.findAllOrderBagsForUnpaidOrdersByBagId(1)).thenReturn(Collections.emptyList()); - superAdminService.editTariffService(dto, 1, uuid); + GetTariffServiceDto actual = superAdminService.editTariffService(dto, 1, uuid); + assertEquals(editedDto, actual); verify(employeeRepository).findByUuid(uuid); - verify(bagRepository).findById(1); - verify(bagRepository).save(bag); - verify(modelMapper).map(bag, GetTariffServiceDto.class); + verify(bagRepository).findActiveBagById(1); + verify(bagRepository).save(editedBag); + verify(modelMapper).map(editedBag, GetTariffServiceDto.class); + verify(orderBagRepository).findAllOrderBagsForUnpaidOrdersByBagId(1); + verify(orderBagRepository, never()).saveAll(anyList()); } @Test @@ -346,12 +379,12 @@ void editTariffServiceIfEmployeeNotFoundException() { Optional bag = ModelUtils.getOptionalBag(); String uuid = UUID.randomUUID().toString(); - when(bagRepository.findById(1)).thenReturn(bag); + when(bagRepository.findActiveBagById(1)).thenReturn(bag); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, () -> superAdminService.editTariffService(dto, 1, uuid)); - verify(bagRepository).findById(1); + verify(bagRepository).findActiveBagById(1); verify(bagRepository, never()).save(any(Bag.class)); } @@ -360,11 +393,11 @@ void editTariffServiceIfBagNotFoundException() { TariffServiceDto dto = ModelUtils.getTariffServiceDto(); String uuid = UUID.randomUUID().toString(); - when(bagRepository.findById(1)).thenReturn(Optional.empty()); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, () -> superAdminService.editTariffService(dto, 1, uuid)); - verify(bagRepository).findById(1); + verify(bagRepository).findActiveBagById(1); verify(bagRepository, never()).save(any(Bag.class)); } @@ -383,64 +416,66 @@ void getAllCouriersTest() { @Test void deleteService() { Service service = ModelUtils.getService(); + Service deletedService = ModelUtils.getServiceDeleted(); - when(serviceRepository.findById(service.getId())).thenReturn(Optional.of(service)); + when(serviceRepository.findActiveServiceById(service.getId())).thenReturn(Optional.of(service)); + when(serviceRepository.save(deletedService)).thenReturn(deletedService); superAdminService.deleteService(1L); - verify(serviceRepository).findById(1L); - verify(serviceRepository).delete(service); + verify(serviceRepository).findActiveServiceById(1L); + verify(serviceRepository).save(deletedService); } @Test void deleteServiceThrowNotFoundException() { - Service service = ModelUtils.getService(); - - when(serviceRepository.findById(service.getId())).thenReturn(Optional.empty()); + when(serviceRepository.findActiveServiceById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, () -> superAdminService.deleteService(1L)); - verify(serviceRepository).findById(1L); - verify(serviceRepository, never()).delete(service); + verify(serviceRepository).findActiveServiceById(1L); + verify(serviceRepository, never()).save(any(Service.class)); } @Test void getService() { Service service = ModelUtils.getService(); GetServiceDto getServiceDto = ModelUtils.getGetServiceDto(); + TariffsInfo tariffsInfo = ModelUtils.getTariffsInfo(); - when(tariffsInfoRepository.existsById(1L)).thenReturn(true); - when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(service)); + when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); + when(serviceRepository.findActiveServiceByTariffsInfoId(1L)).thenReturn(Optional.of(service)); when(modelMapper.map(service, GetServiceDto.class)).thenReturn(getServiceDto); assertEquals(getServiceDto, superAdminService.getService(1L)); - verify(tariffsInfoRepository).existsById(1L); - verify(serviceRepository).findServiceByTariffsInfoId(1L); + verify(tariffsInfoRepository).findById(1L); + verify(serviceRepository).findActiveServiceByTariffsInfoId(1L); verify(modelMapper).map(service, GetServiceDto.class); } @Test void getServiceIfServiceNotExists() { - when(tariffsInfoRepository.existsById(1L)).thenReturn(true); - when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); + TariffsInfo tariffsInfo = ModelUtils.getTariffsInfo(); + + when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); + when(serviceRepository.findActiveServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); assertNull(superAdminService.getService(1L)); - verify(tariffsInfoRepository).existsById(1L); - verify(serviceRepository).findServiceByTariffsInfoId(1L); - verify(modelMapper, never()).map(any(Service.class), any(GetServiceDto.class)); + verify(tariffsInfoRepository).findById(1L); + verify(serviceRepository).findActiveServiceByTariffsInfoId(1L); } @Test void getServiceThrowTariffNotFoundException() { - when(tariffsInfoRepository.existsById(1L)).thenReturn(false); + when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, () -> superAdminService.getService(1L)); - verify(tariffsInfoRepository).existsById(1L); + verify(tariffsInfoRepository).findById(1L); } @Test @@ -451,14 +486,14 @@ void editService() { GetServiceDto getServiceDto = ModelUtils.getGetServiceDto(); String uuid = UUID.randomUUID().toString(); - when(serviceRepository.findById(1L)).thenReturn(Optional.of(service)); + when(serviceRepository.findActiveServiceById(1L)).thenReturn(Optional.of(service)); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); when(serviceRepository.save(service)).thenReturn(service); when(modelMapper.map(service, GetServiceDto.class)).thenReturn(getServiceDto); assertEquals(getServiceDto, superAdminService.editService(1L, dto, uuid)); - verify(serviceRepository).findById(1L); + verify(serviceRepository).findActiveServiceById(1L); verify(employeeRepository).findByUuid(uuid); verify(serviceRepository).save(service); verify(modelMapper).map(service, GetServiceDto.class); @@ -469,12 +504,12 @@ void editServiceServiceNotFoundException() { ServiceDto dto = ModelUtils.getServiceDto(); String uuid = UUID.randomUUID().toString(); - when(serviceRepository.findById(1L)).thenReturn(Optional.empty()); + when(serviceRepository.findActiveServiceById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, () -> superAdminService.editService(1L, dto, uuid)); - verify(serviceRepository).findById(1L); + verify(serviceRepository).findActiveServiceById(1L); verify(serviceRepository, never()).save(any(Service.class)); verify(modelMapper, never()).map(any(Service.class), any(GetServiceDto.class)); } @@ -485,14 +520,14 @@ void editServiceEmployeeNotFoundException() { ServiceDto dto = ModelUtils.getServiceDto(); String uuid = UUID.randomUUID().toString(); - when(serviceRepository.findById(1L)).thenReturn(Optional.of(service)); + when(serviceRepository.findActiveServiceById(1L)).thenReturn(Optional.of(service)); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, () -> superAdminService.editService(1L, dto, uuid)); verify(employeeRepository).findByUuid(uuid); - verify(serviceRepository).findById(1L); + verify(serviceRepository).findActiveServiceById(1L); verify(serviceRepository, never()).save(any(Service.class)); verify(modelMapper, never()).map(any(Service.class), any(GetServiceDto.class)); } @@ -507,8 +542,7 @@ void addService() { TariffsInfo tariffsInfo = ModelUtils.getTariffsInfo(); String uuid = UUID.randomUUID().toString(); - when(tariffsInfoRepository.existsById(1L)).thenReturn(true); - when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); + when(serviceRepository.findActiveServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); when(serviceRepository.save(service)).thenReturn(createdService); @@ -518,9 +552,8 @@ void addService() { assertEquals(getServiceDto, superAdminService.addService(1L, serviceDto, uuid)); verify(employeeRepository).findByUuid(uuid); - verify(tariffsInfoRepository).existsById(1L); verify(tariffsInfoRepository).findById(1L); - verify(serviceRepository).findServiceByTariffsInfoId(1L); + verify(serviceRepository).findActiveServiceByTariffsInfoId(1L); verify(serviceRepository).save(service); verify(modelMapper).map(createdService, GetServiceDto.class); verify(modelMapper).map(createdService, GetServiceDto.class); @@ -530,32 +563,34 @@ void addService() { void addServiceThrowServiceAlreadyExistsException() { Service createdService = ModelUtils.getService(); ServiceDto serviceDto = ModelUtils.getServiceDto(); + TariffsInfo tariffsInfo = ModelUtils.getTariffsInfo(); String uuid = UUID.randomUUID().toString(); - when(tariffsInfoRepository.existsById(1L)).thenReturn(true); - when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(createdService)); + when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); + when(serviceRepository.findActiveServiceByTariffsInfoId(1L)).thenReturn(Optional.of(createdService)); assertThrows(ServiceAlreadyExistsException.class, () -> superAdminService.addService(1L, serviceDto, uuid)); - verify(tariffsInfoRepository).existsById(1L); - verify(serviceRepository).findServiceByTariffsInfoId(1L); + verify(tariffsInfoRepository).findById(1L); + verify(serviceRepository).findActiveServiceByTariffsInfoId(1L); } @Test void addServiceThrowEmployeeNotFoundException() { ServiceDto serviceDto = ModelUtils.getServiceDto(); + TariffsInfo tariffsInfo = ModelUtils.getTariffsInfo(); String uuid = UUID.randomUUID().toString(); - when(tariffsInfoRepository.existsById(1L)).thenReturn(true); - when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); + when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); + when(serviceRepository.findActiveServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, () -> superAdminService.addService(1L, serviceDto, uuid)); - verify(tariffsInfoRepository).existsById(1L); - verify(serviceRepository).findServiceByTariffsInfoId(1L); + verify(tariffsInfoRepository).findById(1L); + verify(serviceRepository).findActiveServiceByTariffsInfoId(1L); verify(employeeRepository).findByUuid(uuid); } @@ -564,12 +599,12 @@ void addServiceThrowTariffNotFoundException() { ServiceDto serviceDto = ModelUtils.getServiceDto(); String uuid = UUID.randomUUID().toString(); - when(tariffsInfoRepository.existsById(1L)).thenReturn(false); + when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, () -> superAdminService.addService(1L, serviceDto, uuid)); - verify(tariffsInfoRepository).existsById(1L); + verify(tariffsInfoRepository).findById(1L); } @Test @@ -1355,14 +1390,14 @@ void setTariffLimitsWithAmountOfBags() { SetTariffLimitsDto dto = ModelUtils.setTariffLimitsWithAmountOfBags(); when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); when(tariffsInfoRepository.save(tariffInfo)).thenReturn(tariffInfo); when(bagRepository.saveAll(List.of(bag))).thenReturn(List.of(bag)); superAdminService.setTariffLimits(1L, dto); verify(tariffsInfoRepository).findById(1L); - verify(bagRepository).findById(1); + verify(bagRepository).findActiveBagById(1); verify(tariffsInfoRepository).save(any()); verify(bagRepository).saveAll(List.of(bag)); } @@ -1374,14 +1409,14 @@ void setTariffLimitsWithPriceOfOrder() { SetTariffLimitsDto dto = ModelUtils.setTariffLimitsWithPriceOfOrder(); when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); when(tariffsInfoRepository.save(tariffInfo)).thenReturn(tariffInfo); when(bagRepository.saveAll(List.of(bag))).thenReturn(List.of(bag)); superAdminService.setTariffLimits(1L, dto); verify(tariffsInfoRepository).findById(1L); - verify(bagRepository).findById(1); + verify(bagRepository).findActiveBagById(1); verify(tariffsInfoRepository).save(any()); verify(bagRepository).saveAll(List.of(bag)); } @@ -1393,14 +1428,14 @@ void setTariffLimitsWithNullMinAndMaxAndFalseBagLimitIncluded() { SetTariffLimitsDto dto = ModelUtils.setTariffLimitsWithNullMinAndMaxAndFalseBagLimit(); when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); when(tariffsInfoRepository.save(tariffInfo)).thenReturn(tariffInfo); when(bagRepository.saveAll(List.of(bag))).thenReturn(List.of(bag)); superAdminService.setTariffLimits(1L, dto); verify(tariffsInfoRepository).findById(1L); - verify(bagRepository).findById(1); + verify(bagRepository).findActiveBagById(1); verify(tariffsInfoRepository).save(any()); verify(bagRepository).saveAll(List.of(bag)); } @@ -1413,13 +1448,13 @@ void setTariffLimitsIfBagNotBelongToTariff() { tariffInfo.setId(2L); when(tariffsInfoRepository.findById(2L)).thenReturn(Optional.of(tariffInfo)); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, () -> superAdminService.setTariffLimits(2L, dto)); verify(tariffsInfoRepository).findById(2L); - verify(bagRepository).findById(1); + verify(bagRepository).findActiveBagById(1); } @Test @@ -1430,14 +1465,14 @@ void setTariffLimitsWithNullMaxAndTrueBagLimitIncluded() { dto.setMax(null); when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); when(tariffsInfoRepository.save(tariffInfo)).thenReturn(tariffInfo); when(bagRepository.saveAll(List.of(bag))).thenReturn(List.of(bag)); superAdminService.setTariffLimits(1L, dto); verify(tariffsInfoRepository).findById(1L); - verify(bagRepository).findById(1); + verify(bagRepository).findActiveBagById(1); verify(tariffsInfoRepository).save(any()); verify(bagRepository).saveAll(List.of(bag)); } @@ -1450,14 +1485,14 @@ void setTariffLimitsWithNullMinAndTrueBagLimitIncluded() { dto.setMin(null); when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); when(tariffsInfoRepository.save(tariffInfo)).thenReturn(tariffInfo); when(bagRepository.saveAll(List.of(bag))).thenReturn(List.of(bag)); superAdminService.setTariffLimits(1L, dto); verify(tariffsInfoRepository).findById(1L); - verify(bagRepository).findById(1); + verify(bagRepository).findActiveBagById(1); verify(tariffsInfoRepository).save(any()); verify(bagRepository).saveAll(List.of(bag)); } @@ -1563,13 +1598,13 @@ void setTariffLimitsBagThrowBagNotFound() { TariffsInfo tariffInfo = ModelUtils.getTariffInfo(); when(tariffsInfoRepository.findById(anyLong())).thenReturn(Optional.of(tariffInfo)); - when(bagRepository.findById(1)).thenReturn(Optional.empty()); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); - verify(bagRepository).findById(1); + verify(bagRepository).findActiveBagById(1); } @Test diff --git a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java index c28f049cd..c285703dd 100644 --- a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java @@ -367,7 +367,7 @@ void getFirstPageDataByTariffAndLocationIdShouldReturnExpectedData() { when(locationRepository.findById(locationId)).thenReturn(Optional.of(location)); when(tariffLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) .thenReturn(Optional.of(tariffLocation)); - when(bagRepository.findBagsByTariffsInfoId(tariffsInfoId)).thenReturn(bags); + when(bagRepository.findAllActiveBagsByTariffsInfoId(tariffsInfoId)).thenReturn(bags); when(modelMapper.map(bags.get(0), BagTranslationDto.class)).thenReturn(bagTranslationDto); var userPointsAndAllBagsDtoActual = @@ -387,7 +387,7 @@ void getFirstPageDataByTariffAndLocationIdShouldReturnExpectedData() { verify(tariffsInfoRepository).findById(tariffsInfoId); verify(locationRepository).findById(locationId); verify(tariffLocationRepository).findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location); - verify(bagRepository).findBagsByTariffsInfoId(tariffsInfoId); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(tariffsInfoId); verify(modelMapper).map(bags.get(0), BagTranslationDto.class); } @@ -420,7 +420,7 @@ void getFirstPageDataByTariffAndLocationIdShouldThrowExceptionWhenTariffLocation verify(locationRepository).findById(locationId); verify(tariffLocationRepository).findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location); - verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } @@ -451,7 +451,7 @@ void getFirstPageDataByTariffAndLocationIdShouldThrowExceptionWhenLocationDoesNo verify(locationRepository).findById(locationId); verify(tariffLocationRepository, never()).findTariffLocationByTariffsInfoAndLocation(any(), any()); - verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } @@ -481,7 +481,7 @@ void getFirstPageDataByTariffAndLocationIdShouldThrowExceptionWhenTariffDoesNotE verify(locationRepository, never()).findById(anyLong()); verify(tariffLocationRepository, never()).findTariffLocationByTariffsInfoAndLocation(any(), any()); - verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), anyLong()); } @@ -508,7 +508,7 @@ void getFirstPageDataByTariffAndLocationIdShouldThrowExceptionWhenUserDoesNotExi verify(tariffsInfoRepository, never()).findById(anyLong()); verify(locationRepository, never()).findById(anyLong()); verify(tariffLocationRepository, never()).findTariffLocationByTariffsInfoAndLocation(any(), any()); - verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } @@ -538,7 +538,7 @@ void checkIfTariffIsAvailableForCurrentLocationThrowExceptionWhenTariffIsDeactiv verify(locationRepository).findById(locationId); verify(tariffLocationRepository, never()).findTariffLocationByTariffsInfoAndLocation(any(), any()); - verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } @@ -568,7 +568,7 @@ void checkIfTariffIsAvailableForCurrentLocationThrowExceptionWhenLocationIsDeact verify(locationRepository).findById(locationId); verify(tariffLocationRepository, never()).findTariffLocationByTariffsInfoAndLocation(any(), any()); - verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } @@ -605,7 +605,7 @@ void checkIfTariffIsAvailableForCurrentLocationWhenLocationForTariffIsDeactivate verify(locationRepository).findById(locationId); verify(tariffLocationRepository).findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location); - verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } @@ -633,7 +633,7 @@ void getFirstPageDataByOrderIdShouldReturnExpectedData() { when(orderRepository.findById(orderId)).thenReturn(Optional.of(order)); when(tariffLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) .thenReturn(Optional.of(tariffLocation)); - when(bagRepository.findBagsByTariffsInfoId(tariffsInfoId)).thenReturn(bags); + when(bagRepository.findAllActiveBagsByTariffsInfoId(tariffsInfoId)).thenReturn(bags); when(modelMapper.map(bags.get(0), BagTranslationDto.class)).thenReturn(bagTranslationDto); var userPointsAndAllBagsDtoActual = @@ -652,7 +652,7 @@ void getFirstPageDataByOrderIdShouldReturnExpectedData() { verify(userRepository).findUserByUuid(uuid); verify(orderRepository).findById(orderId); verify(tariffLocationRepository).findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location); - verify(bagRepository).findBagsByTariffsInfoId(tariffsInfoId); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(tariffsInfoId); verify(modelMapper).map(bags.get(0), BagTranslationDto.class); } @@ -675,7 +675,7 @@ void getFirstPageDataByOrderIdShouldThrowExceptionWhenUserDoesNotExist() { verify(orderRepository, never()).findById(anyLong()); verify(tariffLocationRepository, never()).findTariffLocationByTariffsInfoAndLocation(any(), any()); - verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } @@ -701,7 +701,7 @@ void getFirstPageDataByOrderIdShouldThrowExceptionWhenOrderDoesNotExist() { verify(orderRepository).findById(orderId); verify(tariffLocationRepository, never()).findTariffLocationByTariffsInfoAndLocation(any(), any()); - verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } diff --git a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java index 36e8e5734..46b2f45e5 100644 --- a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java @@ -1800,10 +1800,10 @@ void getOrderStatusDataTest() { .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); + when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(1L)).thenReturn(ModelUtils.getCertificateList()); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); - when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); + when(serviceRepository.findActiveServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when(orderStatusTranslationRepository.getOrderStatusTranslationById(6L)) .thenReturn(Optional.ofNullable(getStatusTranslation())); @@ -1819,10 +1819,10 @@ void getOrderStatusDataTest() { verify(orderRepository).getOrderDetails(1L); verify(bagRepository).findBagsByOrderId(1L); - verify(bagRepository).findBagsByTariffsInfoId(1L); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); verify(certificateRepository).findCertificate(1L); verify(orderRepository, times(5)).findById(1L); - verify(serviceRepository).findServiceByTariffsInfoId(1L); + verify(serviceRepository).findActiveServiceByTariffsInfoId(1L); verify(modelMapper).map(ModelUtils.getBaglist().get(0), BagInfoDto.class); verify(orderStatusTranslationRepository).getOrderStatusTranslationById(6L); verify(orderPaymentStatusTranslationRepository).getById(1L); @@ -1876,9 +1876,9 @@ void getOrderStatusDataTestEmptyPriceDetails() { .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); + when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag2list()); - when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); + when(serviceRepository.findActiveServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when(orderStatusTranslationRepository.getOrderStatusTranslationById(6L)) .thenReturn(Optional.ofNullable(getStatusTranslation())); @@ -1894,10 +1894,10 @@ void getOrderStatusDataTestEmptyPriceDetails() { verify(orderRepository).getOrderDetails(1L); verify(bagRepository).findBagsByOrderId(1L); - verify(bagRepository).findBagsByTariffsInfoId(1L); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); verify(certificateRepository).findCertificate(1L); verify(orderRepository, times(5)).findById(1L); - verify(serviceRepository).findServiceByTariffsInfoId(1L); + verify(serviceRepository).findActiveServiceByTariffsInfoId(1L); verify(modelMapper).map(ModelUtils.getBaglist().get(0), BagInfoDto.class); verify(orderStatusTranslationRepository).getOrderStatusTranslationById(6L); verify(orderPaymentStatusTranslationRepository).getById(1L); @@ -1919,8 +1919,8 @@ void getOrderStatusDataWithEmptyCertificateTest() { .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); - when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); + when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); + when(serviceRepository.findActiveServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when(orderStatusTranslationRepository.getOrderStatusTranslationById(6L)) @@ -1935,9 +1935,9 @@ void getOrderStatusDataWithEmptyCertificateTest() { verify(orderRepository).getOrderDetails(1L); verify(bagRepository).findBagsByOrderId(1L); - verify(bagRepository).findBagsByTariffsInfoId(1L); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); verify(orderRepository, times(5)).findById(1L); - verify(serviceRepository).findServiceByTariffsInfoId(1L); + verify(serviceRepository).findActiveServiceByTariffsInfoId(1L); verify(modelMapper).map(ModelUtils.getBaglist().get(0), BagInfoDto.class); verify(orderStatusTranslationRepository).getOrderStatusTranslationById(6L); verify(orderPaymentStatusTranslationRepository).getById(1L); @@ -1958,8 +1958,8 @@ void getOrderStatusDataWhenOrderTranslationIsNull() { .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); - when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); + when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); + when(serviceRepository.findActiveServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when( @@ -1972,9 +1972,9 @@ void getOrderStatusDataWhenOrderTranslationIsNull() { verify(orderRepository).getOrderDetails(1L); verify(bagRepository).findBagsByOrderId(1L); - verify(bagRepository).findBagsByTariffsInfoId(1L); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); verify(orderRepository, times(5)).findById(1L); - verify(serviceRepository).findServiceByTariffsInfoId(1L); + verify(serviceRepository).findActiveServiceByTariffsInfoId(1L); verify(modelMapper).map(ModelUtils.getBaglist().get(0), BagInfoDto.class); verify(orderStatusTranslationRepository).getOrderStatusTranslationById(6L); verify(orderPaymentStatusTranslationRepository).getById(1L); @@ -1996,7 +1996,7 @@ void getOrderStatusDataExceptionTest() { when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(bagRepository.findBagsByOrderId(1L)).thenReturn(ModelUtils.getBaglist()); when(certificateRepository.findCertificate(1L)).thenReturn(ModelUtils.getCertificateList()); - when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); + when(serviceRepository.findActiveServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(modelMapper.map(ModelUtils.getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when(orderStatusTranslationRepository.getOrderStatusTranslationById(6L)) @@ -2270,7 +2270,7 @@ void getOrderStatusDataWithNotEmptyLists() { when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); + when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(1L)).thenReturn(getCertificateList()); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); @@ -2289,7 +2289,7 @@ void getOrderStatusDataWithNotEmptyLists() { ubsManagementService.getOrderStatusData(1L, "test@gmail.com"); verify(orderRepository).getOrderDetails(1L); - verify(bagRepository).findBagsByTariffsInfoId(1L); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); verify(bagRepository).findBagsByOrderId(1L); verify(certificateRepository).findCertificate(1L); verify(orderRepository, times(5)).findById(1L); @@ -2317,7 +2317,7 @@ void getOrderStatusesTranslationTest() { .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); + when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(1L)).thenReturn(getCertificateList()); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); @@ -2341,7 +2341,7 @@ void getOrderStatusesTranslationTest() { verify(orderRepository).getOrderDetails(1L); verify(bagRepository).findBagsByOrderId(1L); - verify(bagRepository).findBagsByTariffsInfoId(1L); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); verify(certificateRepository).findCertificate(1L); verify(orderRepository, times(5)).findById(1L); verify(modelMapper).map(getBaglist().get(0), BagInfoDto.class); From 97694be8253144132a45d2b4abeeac2e1e6d94ac Mon Sep 17 00:00:00 2001 From: Maksym Date: Tue, 13 Jun 2023 13:47:16 +0300 Subject: [PATCH 04/73] #5927 [UBS] endpoint that returns deactivated locations (#1133) * add endpoint, update service and repo methods * upd tests * added formatting --- .../configuration/SecurityConfig.java | 1 + .../controller/SuperAdminController.java | 31 ++++++++++-- .../controller/SuperAdminControllerTest.java | 49 ++++++++++++++++++- .../repository/RegionRepository.java | 21 ++++---- .../java/greencity/constant/ErrorMessage.java | 2 + .../greencity/service/SuperAdminService.java | 8 +-- .../service/ubs/SuperAdminServiceImpl.java | 9 ++-- .../ubs/SuperAdminServiceImplTest.java | 25 ++++++++-- 8 files changed, 120 insertions(+), 26 deletions(-) diff --git a/core/src/main/java/greencity/configuration/SecurityConfig.java b/core/src/main/java/greencity/configuration/SecurityConfig.java index 6e2a92eeb..264a82360 100644 --- a/core/src/main/java/greencity/configuration/SecurityConfig.java +++ b/core/src/main/java/greencity/configuration/SecurityConfig.java @@ -99,6 +99,7 @@ protected void configure(HttpSecurity http) throws Exception { SUPER_ADMIN_LINK + "/get-all-receiving-station", SUPER_ADMIN_LINK + "/getLocations", SUPER_ADMIN_LINK + "/getActiveLocations", + SUPER_ADMIN_LINK + "/getDeactivatedLocations", SUPER_ADMIN_LINK + "/getCouriers", SUPER_ADMIN_LINK + "/tariffs", SUPER_ADMIN_LINK + "/{tariffId}/getTariffService", diff --git a/core/src/main/java/greencity/controller/SuperAdminController.java b/core/src/main/java/greencity/controller/SuperAdminController.java index 93751f91f..bf832bac9 100644 --- a/core/src/main/java/greencity/controller/SuperAdminController.java +++ b/core/src/main/java/greencity/controller/SuperAdminController.java @@ -24,6 +24,7 @@ import greencity.dto.tariff.GetTariffsInfoDto; import greencity.dto.tariff.SetTariffLimitsDto; import greencity.entity.order.Courier; +import greencity.enums.LocationStatus; import greencity.exceptions.BadRequestException; import greencity.filters.TariffsInfoFilterCriteria; import greencity.service.SuperAdminService; @@ -282,21 +283,43 @@ public ResponseEntity> getLocations() { } /** - * Get all info about active locations, and min amount of bag for locations. + * Get all info about active locations. * * @return {@link LocationInfoDto} * @author Safarov Renat */ - @ApiOperation(value = "Get info about active locations and min amount of bags for every location") + @ApiOperation(value = "Get all active locations") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK, response = LocationInfoDto.class), @ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED), - @ApiResponse(code = 403, message = HttpStatuses.FORBIDDEN) + @ApiResponse(code = 403, message = HttpStatuses.FORBIDDEN), + @ApiResponse(code = 404, message = HttpStatuses.NOT_FOUND) }) @PreAuthorize("@preAuthorizer.hasAuthority('SEE_TARIFFS', authentication)") @GetMapping("/getActiveLocations") public ResponseEntity> getActiveLocations() { - return ResponseEntity.status(HttpStatus.OK).body(superAdminService.getActiveLocations()); + return ResponseEntity.status(HttpStatus.OK) + .body(superAdminService.getLocationsByStatus(LocationStatus.ACTIVE)); + } + + /** + * Get all deactivated locations. + * + * @return {@link LocationInfoDto} + * @author Maksym Lenets + */ + @ApiOperation(value = "Get all deactivated locations") + @ApiResponses(value = { + @ApiResponse(code = 200, message = HttpStatuses.OK, response = LocationInfoDto.class), + @ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED), + @ApiResponse(code = 403, message = HttpStatuses.FORBIDDEN), + @ApiResponse(code = 404, message = HttpStatuses.NOT_FOUND) + }) + @PreAuthorize("@preAuthorizer.hasAuthority('SEE_TARIFFS', authentication)") + @GetMapping("/getDeactivatedLocations") + public ResponseEntity> getDeactivatedLocations() { + return ResponseEntity.status(HttpStatus.OK) + .body(superAdminService.getLocationsByStatus(LocationStatus.DEACTIVATED)); } /** diff --git a/core/src/test/java/greencity/controller/SuperAdminControllerTest.java b/core/src/test/java/greencity/controller/SuperAdminControllerTest.java index 9d27cf8f1..3329b227f 100644 --- a/core/src/test/java/greencity/controller/SuperAdminControllerTest.java +++ b/core/src/test/java/greencity/controller/SuperAdminControllerTest.java @@ -21,6 +21,7 @@ import greencity.dto.tariff.EditTariffDto; import greencity.dto.tariff.GetTariffsInfoDto; import greencity.dto.tariff.SetTariffLimitsDto; +import greencity.enums.LocationStatus; import greencity.exception.handler.CustomExceptionHandler; import greencity.exceptions.BadRequestException; import greencity.exceptions.NotFoundException; @@ -517,7 +518,53 @@ void getLocations() throws Exception { void getActiveLocations() throws Exception { mockMvc.perform(get((ubsLink + "/getActiveLocations"))).andExpect(status().isOk()); - verify(superAdminService).getActiveLocations(); + verify(superAdminService).getLocationsByStatus(LocationStatus.ACTIVE); + verifyNoMoreInteractions(superAdminService); + } + + @Test + void getActiveLocationsNotFoundTest() throws Exception { + String message = "ErrorMessage"; + + doThrow(new NotFoundException(message)) + .when(superAdminService) + .getLocationsByStatus(LocationStatus.ACTIVE); + + mockMvc.perform(get(ubsLink + "/getActiveLocations") + .principal(principal)) + .andExpect(status().isNotFound()) + .andExpect(result -> assertTrue(result.getResolvedException() instanceof NotFoundException)) + .andExpect( + result -> assertEquals(message, Objects.requireNonNull(result.getResolvedException()).getMessage())); + + verify(superAdminService).getLocationsByStatus(LocationStatus.ACTIVE); + verifyNoMoreInteractions(superAdminService); + } + + @Test + void getDeactivatedLocationsTest() throws Exception { + mockMvc.perform(get(ubsLink + "/getDeactivatedLocations").principal(principal)).andExpect(status().isOk()); + + verify(superAdminService).getLocationsByStatus(LocationStatus.DEACTIVATED); + verifyNoMoreInteractions(superAdminService); + } + + @Test + void getDeactivatedLocationsNotFoundTest() throws Exception { + String message = "ErrorMessage"; + + doThrow(new NotFoundException(message)) + .when(superAdminService) + .getLocationsByStatus(LocationStatus.DEACTIVATED); + + mockMvc.perform(get(ubsLink + "/getDeactivatedLocations") + .principal(principal)) + .andExpect(status().isNotFound()) + .andExpect(result -> assertTrue(result.getResolvedException() instanceof NotFoundException)) + .andExpect( + result -> assertEquals(message, Objects.requireNonNull(result.getResolvedException()).getMessage())); + + verify(superAdminService).getLocationsByStatus(LocationStatus.DEACTIVATED); verifyNoMoreInteractions(superAdminService); } diff --git a/dao/src/main/java/greencity/repository/RegionRepository.java b/dao/src/main/java/greencity/repository/RegionRepository.java index 60c2a37b8..c7c58eeb7 100644 --- a/dao/src/main/java/greencity/repository/RegionRepository.java +++ b/dao/src/main/java/greencity/repository/RegionRepository.java @@ -1,8 +1,9 @@ package greencity.repository; import greencity.entity.user.Region; +import greencity.enums.LocationStatus; +import org.springframework.data.jpa.repository.EntityGraph; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import java.util.List; @@ -22,17 +23,15 @@ Optional findRegionByEnNameAndUkrName(@Param("EnName") String nameEn, @Param("UkrName") String nameUk); /** - * Method for get regions with only active locations. - * - * @return List of {@link Region} if at least one region exists - * @author Safarov Renat + * Method that retrieves regions with locations specified by LocationStatus + * type. + * + * @param locationStatus {@link LocationStatus} - status of searched locations. + * @return List of {@link Region} if at least one region exists. + * @author Maksym Lenets */ - @Query(nativeQuery = true, - value = "select * from regions r " - + "join locations l on r.id = l.region_id " - + "where l.location_status = 'ACTIVE' " - + "group by r.id, l.id") - List findRegionsWithActiveLocations(); + @EntityGraph(attributePaths = "locations") + Optional> findAllByLocationsLocationStatus(LocationStatus locationStatus); /** * Method to check if the region exists by regionId. diff --git a/service-api/src/main/java/greencity/constant/ErrorMessage.java b/service-api/src/main/java/greencity/constant/ErrorMessage.java index 0f33d6e15..1e9783b81 100644 --- a/service-api/src/main/java/greencity/constant/ErrorMessage.java +++ b/service-api/src/main/java/greencity/constant/ErrorMessage.java @@ -150,6 +150,8 @@ public final class ErrorMessage { "Date of export not specified for the order with ID: "; public static final String EMPTY_ORDERS_ID_COLLECTION = "Request should contain at least one order ID"; public static final String ORDER_IS_BLOCKED = "The order has been blocked by employee with ID: "; + public static final String REGIONS_NOT_FOUND_BY_LOCATION_STATUS = + "Regions containing locations with a status: %s, not found"; /** * Constructor. diff --git a/service-api/src/main/java/greencity/service/SuperAdminService.java b/service-api/src/main/java/greencity/service/SuperAdminService.java index a9aa3c08f..df71fd4fb 100644 --- a/service-api/src/main/java/greencity/service/SuperAdminService.java +++ b/service-api/src/main/java/greencity/service/SuperAdminService.java @@ -16,6 +16,7 @@ import greencity.dto.tariff.*; import greencity.dto.service.GetTariffServiceDto; import greencity.entity.order.Courier; +import greencity.enums.LocationStatus; import greencity.filters.TariffsInfoFilterCriteria; import java.util.List; @@ -114,12 +115,13 @@ public interface SuperAdminService { List getAllLocation(); /** - * Method for get all info about active locations. + * Method for getting info about locations by LocationStatus. * + * @param locationStatus {@link LocationStatus} - status of searched locations. * @return {@link LocationInfoDto}. - * @author Safarov Renat. + * @author Maksym Lenets. */ - List getActiveLocations(); + List getLocationsByStatus(LocationStatus locationStatus); /** * Method for adding location. diff --git a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java index 620f05284..7ec165a94 100644 --- a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java @@ -298,9 +298,12 @@ public List getAllLocation() { } @Override - public List getActiveLocations() { - return regionRepository.findRegionsWithActiveLocations().stream() - .distinct() + public List getLocationsByStatus(LocationStatus locationStatus) { + List regionWithDeactivatedLocations = regionRepository + .findAllByLocationsLocationStatus(locationStatus) + .orElseThrow(() -> new NotFoundException( + String.format(ErrorMessage.REGIONS_NOT_FOUND_BY_LOCATION_STATUS, locationStatus.name()))); + return regionWithDeactivatedLocations.stream() .map(region -> modelMapper.map(region, LocationInfoDto.class)) .collect(Collectors.toList()); } diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index 220e3d1af..302f191c2 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -620,15 +620,32 @@ void getAllLocationTest() { } @Test - void getActiveLocationsTest() { + void getLocationsByStatusTest() { List regionList = ModelUtils.getAllRegion(); - when(regionRepository.findRegionsWithActiveLocations()).thenReturn(regionList); + when(regionRepository.findAllByLocationsLocationStatus(LocationStatus.ACTIVE)) + .thenReturn(Optional.of(regionList)); - superAdminService.getActiveLocations(); + var result = superAdminService.getLocationsByStatus(LocationStatus.ACTIVE); - verify(regionRepository).findRegionsWithActiveLocations(); + verify(regionRepository).findAllByLocationsLocationStatus(LocationStatus.ACTIVE); regionList.forEach(region -> verify(modelMapper).map(region, LocationInfoDto.class)); + verify(modelMapper, times(regionList.size())).map(any(Region.class), eq(LocationInfoDto.class)); + assertEquals(regionList.size(), result.size()); + } + + @Test + void getLocationsByStatusNotFoundExceptionTest() { + when(regionRepository.findAllByLocationsLocationStatus(LocationStatus.ACTIVE)) + .thenReturn(Optional.empty()); + + NotFoundException notFoundException = assertThrows(NotFoundException.class, + () -> superAdminService.getLocationsByStatus(LocationStatus.ACTIVE)); + + assertEquals(String.format(ErrorMessage.REGIONS_NOT_FOUND_BY_LOCATION_STATUS, LocationStatus.ACTIVE.name()), + notFoundException.getMessage()); + + verify(regionRepository).findAllByLocationsLocationStatus(LocationStatus.ACTIVE); } @Test From d7ace0efbf4f995e3d0db1d855cac19e357c22e6 Mon Sep 17 00:00:00 2001 From: Anatolii <108548978+Markiro1@users.noreply.github.com> Date: Tue, 13 Jun 2023 18:26:13 +0300 Subject: [PATCH 05/73] - changed redirect.green-city-client url (#1132) --- core/src/main/resources/application-prod.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/resources/application-prod.properties b/core/src/main/resources/application-prod.properties index 41a389560..60023b0f7 100644 --- a/core/src/main/resources/application-prod.properties +++ b/core/src/main/resources/application-prod.properties @@ -39,5 +39,5 @@ greencity.payment.merchant-id=${MERCHANT_ID} greencity.payment.fondy-payment-key=${FONDY_PAYMENT_KEY} #GreenCityClient -greencity.redirect.green-city-client=https://www.testgreencity.ga/GreenCityClient/#/ubs/confirm/ +greencity.redirect.green-city-client=https://www.greencity.social/GreenCityClient/#/ubs/confirm/ From b3cbaa9481313c8cf61533d0fb9d1638c5e11f23 Mon Sep 17 00:00:00 2001 From: Julia Seti <64809431+juseti@users.noreply.github.com> Date: Tue, 13 Jun 2023 20:27:24 +0300 Subject: [PATCH 06/73] [UBS] - bug with manual payment #5940 (#1136) --- .../service/ubs/UBSManagementServiceImpl.java | 28 +---- .../ubs/UBSManagementServiceImplTest.java | 115 +++++++++++++++++- 2 files changed, 113 insertions(+), 30 deletions(-) diff --git a/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java index d73a929de..269c8cac4 100644 --- a/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java @@ -1317,6 +1317,7 @@ private Long calculateUnpaidAmount(Order order, Long sumToPayInCoins, Long paidA * {@inheritDoc} */ @Override + @Transactional public ManualPaymentResponseDto saveNewManualPayment(Long orderId, ManualPaymentRequestDto paymentRequestDto, MultipartFile image, String email) { if (Objects.isNull(image) && StringUtils.isBlank(paymentRequestDto.getReceiptLink())) { @@ -1380,9 +1381,11 @@ private void updateOrderPaymentStatusForManualPayment(Order order) { if (paymentsForCurrentOrder > 0 && totalAmount > totalPaidAmount) { order.setOrderPaymentStatus(OrderPaymentStatus.HALF_PAID); + eventService.save(OrderHistory.ORDER_HALF_PAID, OrderHistory.SYSTEM, order); notificationService.notifyHalfPaidPackage(order); } else if (paymentsForCurrentOrder > 0 && totalAmount <= totalPaidAmount) { order.setOrderPaymentStatus(OrderPaymentStatus.PAID); + eventService.save(OrderHistory.ORDER_PAID, OrderHistory.SYSTEM, order); notificationService.notifyPaidOrder(order); } else if (paymentsForCurrentOrder == 0) { order.setOrderPaymentStatus(OrderPaymentStatus.UNPAID); @@ -1427,7 +1430,7 @@ private Payment buildPaymentEntity(Order order, ManualPaymentRequestDto paymentR Payment payment = Payment.builder() .settlementDate(LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE)) .amount(paymentRequestDto.getAmount()) - .paymentStatus(verifyPaymentStatusOrder(order)) + .paymentStatus(PaymentStatus.PAID) .paymentId(paymentRequestDto.getPaymentId()) .receiptLink(paymentRequestDto.getReceiptLink()) .currency("UAH") @@ -1442,32 +1445,9 @@ private Payment buildPaymentEntity(Order order, ManualPaymentRequestDto paymentR .orElseThrow(() -> new EntityNotFoundException(EMPLOYEE_NOT_FOUND)); eventService.save(OrderHistory.ADD_PAYMENT_MANUALLY + paymentRequestDto.getPaymentId(), employee.getFirstName() + " " + employee.getLastName(), order); - if (order.getOrderPaymentStatus() != null) { - if (order.getOrderPaymentStatus() == OrderPaymentStatus.PAID) { - eventService.save(OrderHistory.ORDER_PAID, OrderHistory.SYSTEM, order); - } else { - eventService.save(OrderHistory.ORDER_HALF_PAID, OrderHistory.SYSTEM, order); - } - } return payment; } - private PaymentStatus verifyPaymentStatusOrder(Order order) { - if (order.getOrderPaymentStatus() == OrderPaymentStatus.PAID) { - return PaymentStatus.PAID; - } - if (order.getOrderPaymentStatus() == OrderPaymentStatus.HALF_PAID) { - return PaymentStatus.HALF_PAID; - } - if (order.getOrderPaymentStatus() == OrderPaymentStatus.UNPAID) { - return PaymentStatus.UNPAID; - } - if (order.getOrderPaymentStatus() == OrderPaymentStatus.PAYMENT_REFUNDED) { - return PaymentStatus.PAYMENT_REFUNDED; - } - return PaymentStatus.UNPAID; - } - @Override public EmployeePositionDtoRequest getAllEmployeesByPosition(Long orderId, String email) { Order order = orderRepository.findById(orderId) diff --git a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java index 46b2f45e5..728568d38 100644 --- a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java @@ -33,13 +33,13 @@ import greencity.dto.user.AddBonusesToUserDto; import greencity.dto.user.AddingPointsToUserDto; import greencity.dto.violation.ViolationsInfoDto; +import greencity.entity.order.Bag; import greencity.entity.order.Certificate; import greencity.entity.order.Order; import greencity.entity.order.OrderPaymentStatusTranslation; import greencity.entity.order.OrderStatusTranslation; import greencity.entity.order.Payment; import greencity.entity.order.TariffsInfo; -import greencity.entity.order.Bag; import greencity.entity.user.User; import greencity.entity.user.employee.Employee; import greencity.entity.user.employee.EmployeeOrderPosition; @@ -48,7 +48,6 @@ import greencity.entity.user.ubs.OrderAddress; import greencity.enums.OrderPaymentStatus; import greencity.enums.OrderStatus; -import greencity.enums.PaymentStatus; import greencity.enums.SortingOrder; import greencity.exceptions.BadRequestException; import greencity.exceptions.NotFoundException; @@ -107,6 +106,7 @@ import static greencity.ModelUtils.*; import static greencity.constant.ErrorMessage.EMPLOYEE_NOT_FOUND; import static greencity.constant.ErrorMessage.ORDER_WITH_CURRENT_ID_DOES_NOT_EXIST; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.any; @@ -355,11 +355,115 @@ void checkUpdateManualPayment() { ubsManagementService.updateManualPayment(1L, getManualPaymentRequestDto(), null, "abc"); verify(paymentRepository, times(1)).findById(1L); verify(paymentRepository, times(1)).save(any()); - verify(eventService, times(1)).save(any(), any(), any()); + verify(eventService, times(2)).save(any(), any(), any()); verify(fileService, times(0)).delete(null); verify(bagRepository).findBagsByOrderId(order.getId()); } + @Test + void saveNewManualPaymentWithZeroAmount() { + User user = ModelUtils.getTestUser(); + user.setRecipientName("Петро"); + user.setRecipientSurname("Петренко"); + Order order = ModelUtils.getFormedOrder(); + order.setPointsToUse(0); + TariffsInfo tariffsInfo = getTariffsInfo(); + order.setTariffsInfo(tariffsInfo); + order.setOrderPaymentStatus(OrderPaymentStatus.UNPAID); + Payment payment = ModelUtils.getManualPayment(); + payment.setAmount(0L); + order.setPayment(singletonList(payment)); + ManualPaymentRequestDto paymentDetails = ManualPaymentRequestDto.builder() + .settlementdate("02-08-2021").amount(0L).receiptLink("link").paymentId("1").build(); + Employee employee = ModelUtils.getEmployee(); + when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); + when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); + when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) + .thenReturn(Optional.of(tariffsInfo)); + when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); + when(paymentRepository.save(any())) + .thenReturn(payment); + doNothing().when(eventService).save(any(), any(), any()); + ubsManagementService.saveNewManualPayment(1L, paymentDetails, null, "test@gmail.com"); + verify(employeeRepository, times(2)).findByEmail(anyString()); + verify(eventService, times(1)).save(OrderHistory.ADD_PAYMENT_MANUALLY + 1, + "Петро Петренко", order); + verify(paymentRepository, times(1)).save(any()); + verify(orderRepository, times(1)).findById(1L); + verify(tariffsInfoRepository).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); + } + + @Test + void saveNewManualPaymentWithHalfPaidAmount() { + User user = ModelUtils.getTestUser(); + user.setRecipientName("Петро"); + user.setRecipientSurname("Петренко"); + Order order = ModelUtils.getFormedOrder(); + order.setPointsToUse(0); + TariffsInfo tariffsInfo = getTariffsInfo(); + order.setTariffsInfo(tariffsInfo); + order.setOrderPaymentStatus(OrderPaymentStatus.HALF_PAID); + Payment payment = ModelUtils.getManualPayment(); + payment.setAmount(50_00L); + order.setPayment(singletonList(payment)); + ManualPaymentRequestDto paymentDetails = ManualPaymentRequestDto.builder() + .settlementdate("02-08-2021").amount(50_00L).receiptLink("link").paymentId("1").build(); + Employee employee = ModelUtils.getEmployee(); + when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); + when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); + when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) + .thenReturn(Optional.of(tariffsInfo)); + when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag1list()); + when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); + when(paymentRepository.save(any())) + .thenReturn(payment); + doNothing().when(eventService).save(any(), any(), any()); + ubsManagementService.saveNewManualPayment(1L, paymentDetails, null, "test@gmail.com"); + verify(employeeRepository, times(2)).findByEmail(anyString()); + verify(eventService, times(1)).save(OrderHistory.ADD_PAYMENT_MANUALLY + 1, + "Петро Петренко", order); + verify(eventService, times(1)) + .save(OrderHistory.ORDER_HALF_PAID, OrderHistory.SYSTEM, order); + verify(paymentRepository, times(1)).save(any()); + verify(orderRepository, times(1)).findById(1L); + verify(tariffsInfoRepository).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); + } + + @Test + void saveNewManualPaymentWithPaidAmount() { + User user = ModelUtils.getTestUser(); + user.setRecipientName("Петро"); + user.setRecipientSurname("Петренко"); + Order order = ModelUtils.getFormedOrder(); + TariffsInfo tariffsInfo = getTariffsInfo(); + order.setTariffsInfo(tariffsInfo); + order.setOrderPaymentStatus(OrderPaymentStatus.PAID); + Payment payment = ModelUtils.getManualPayment(); + payment.setAmount(500_00L); + order.setPayment(singletonList(payment)); + ManualPaymentRequestDto paymentDetails = ManualPaymentRequestDto.builder() + .settlementdate("02-08-2021").amount(500_00L).receiptLink("link").paymentId("1").build(); + Employee employee = ModelUtils.getEmployee(); + when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); + when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); + when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) + .thenReturn(Optional.of(tariffsInfo)); + when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag1list()); + when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); + when(paymentRepository.save(any())) + .thenReturn(payment); + doNothing().when(eventService).save(any(), any(), any()); + ubsManagementService.saveNewManualPayment(1L, paymentDetails, null, "test@gmail.com"); + verify(employeeRepository, times(2)).findByEmail(anyString()); + verify(eventService, times(1)).save(OrderHistory.ADD_PAYMENT_MANUALLY + 1, + "Петро Петренко", order); + verify(eventService, times(1)) + .save(OrderHistory.ORDER_PAID, OrderHistory.SYSTEM, order); + verify(paymentRepository, times(1)).save(any()); + verify(orderRepository, times(1)).findById(1L); + verify(tariffsInfoRepository).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); + } + @Test void saveNewManualPaymentWithPaidOrder() { User user = ModelUtils.getTestUser(); @@ -399,7 +503,6 @@ void saveNewManualPaymentWithPartiallyPaidOrder() { order.setTariffsInfo(tariffsInfo); order.setOrderPaymentStatus(OrderPaymentStatus.HALF_PAID); Payment payment = ModelUtils.getManualPayment(); - payment.setPaymentStatus(PaymentStatus.HALF_PAID); ManualPaymentRequestDto paymentDetails = ManualPaymentRequestDto.builder() .settlementdate("02-08-2021").amount(200L).receiptLink("link").paymentId("1").build(); Employee employee = ModelUtils.getEmployee(); @@ -495,7 +598,7 @@ void checkUpdateManualPaymentWithImage() { ubsManagementService.updateManualPayment(1L, getManualPaymentRequestDto(), file, "abc"); verify(paymentRepository, times(1)).findById(1L); verify(paymentRepository, times(1)).save(any()); - verify(eventService, times(1)).save(any(), any(), any()); + verify(eventService, times(2)).save(any(), any(), any()); } @Test @@ -2116,7 +2219,7 @@ void updateManualPayment() { ubsManagementService.updateManualPayment(payment.getId(), requestDto, file, employee.getUuid()); verify(paymentRepository).save(any(Payment.class)); - verify(eventService).save(any(), any(), any()); + verify(eventService, times(2)).save(any(), any(), any()); } @Test From 6b81ea86692392a8abf37d72a542e13c0516fe89 Mon Sep 17 00:00:00 2001 From: Julia Seti <64809431+juseti@users.noreply.github.com> Date: Fri, 16 Jun 2023 12:31:17 +0300 Subject: [PATCH 07/73] added bag status active and deleted --- .../main/java/greencity/entity/order/Bag.java | 4 +- .../java/greencity/entity/order/Order.java | 13 +- .../java/greencity/entity/order/OrderBag.java | 4 +- .../java/greencity/entity/order/Service.java | 7 - .../java/greencity/enums/ServiceStatus.java | 6 - .../repository/OrderBagRepository.java | 20 ++ .../repository/ServiceRepository.java | 20 +- .../db/changelog/db.changelog-master.xml | 2 +- ...h-add-column-status-to-bag-table-Seti.xml} | 5 - .../java/greencity/constant/ErrorMessage.java | 4 +- .../service/ubs/SuperAdminServiceImpl.java | 27 +- .../service/ubs/UBSClientServiceImpl.java | 18 +- .../service/ubs/UBSManagementServiceImpl.java | 2 +- .../src/test/java/greencity/ModelUtils.java | 34 +-- .../ubs/SuperAdminServiceImplTest.java | 67 +++-- .../service/ubs/UBSClientServiceImplTest.java | 256 ++++++++---------- .../ubs/UBSManagementServiceImplTest.java | 18 +- 17 files changed, 226 insertions(+), 281 deletions(-) delete mode 100644 dao/src/main/java/greencity/enums/ServiceStatus.java rename dao/src/main/resources/db/changelog/logs/{ch-add-column-status-to-bag-and-service-tables-Seti.xml => ch-add-column-status-to-bag-table-Seti.xml} (75%) diff --git a/dao/src/main/java/greencity/entity/order/Bag.java b/dao/src/main/java/greencity/entity/order/Bag.java index 2d763a069..ab2af0f6b 100644 --- a/dao/src/main/java/greencity/entity/order/Bag.java +++ b/dao/src/main/java/greencity/entity/order/Bag.java @@ -14,6 +14,7 @@ import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; +import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @@ -22,7 +23,6 @@ import javax.persistence.Table; import javax.validation.constraints.Max; import javax.validation.constraints.Min; - import java.time.LocalDate; @Entity @@ -87,7 +87,7 @@ public class Bag { @JoinColumn private Employee editedBy; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(nullable = false) private TariffsInfo tariffsInfo; diff --git a/dao/src/main/java/greencity/entity/order/Order.java b/dao/src/main/java/greencity/entity/order/Order.java index e3773de3f..bb41cee50 100644 --- a/dao/src/main/java/greencity/entity/order/Order.java +++ b/dao/src/main/java/greencity/entity/order/Order.java @@ -190,7 +190,7 @@ public class Order { private List orderBags = new ArrayList<>(); /** - * method, that helps to save OrderBag. + * method helps to add OrderBag. * * @param orderBag {@link OrderBag} * @author Julia Seti @@ -199,4 +199,15 @@ public void addOrderBag(OrderBag orderBag) { this.orderBags.add(orderBag); orderBag.setOrder(this); } + + /** + * method helps to delete OrderBag. + * + * @param orderBag {@link OrderBag} + * @author Julia Seti + */ + public void removeOrderBag(OrderBag orderBag) { + this.orderBags.remove(orderBag); + orderBag.setOrder(null); + } } diff --git a/dao/src/main/java/greencity/entity/order/OrderBag.java b/dao/src/main/java/greencity/entity/order/OrderBag.java index 961ea16cc..95230c7e2 100644 --- a/dao/src/main/java/greencity/entity/order/OrderBag.java +++ b/dao/src/main/java/greencity/entity/order/OrderBag.java @@ -22,8 +22,8 @@ @Entity @NoArgsConstructor @AllArgsConstructor -@EqualsAndHashCode -@ToString +@EqualsAndHashCode(exclude = {"order", "bag"}) +@ToString(exclude = {"order", "bag"}) @Getter @Setter @Builder diff --git a/dao/src/main/java/greencity/entity/order/Service.java b/dao/src/main/java/greencity/entity/order/Service.java index fbdf486a2..3e935d336 100644 --- a/dao/src/main/java/greencity/entity/order/Service.java +++ b/dao/src/main/java/greencity/entity/order/Service.java @@ -1,7 +1,6 @@ package greencity.entity.order; import greencity.entity.user.employee.Employee; -import greencity.enums.ServiceStatus; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -11,8 +10,6 @@ import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @@ -71,8 +68,4 @@ public class Service { @OneToOne private TariffsInfo tariffsInfo; - - @Column(nullable = false) - @Enumerated(EnumType.STRING) - private ServiceStatus status; } diff --git a/dao/src/main/java/greencity/enums/ServiceStatus.java b/dao/src/main/java/greencity/enums/ServiceStatus.java deleted file mode 100644 index 10a36ec84..000000000 --- a/dao/src/main/java/greencity/enums/ServiceStatus.java +++ /dev/null @@ -1,6 +0,0 @@ -package greencity.enums; - -public enum ServiceStatus { - ACTIVE, - DELETED -} diff --git a/dao/src/main/java/greencity/repository/OrderBagRepository.java b/dao/src/main/java/greencity/repository/OrderBagRepository.java index df1c69c39..efd798567 100644 --- a/dao/src/main/java/greencity/repository/OrderBagRepository.java +++ b/dao/src/main/java/greencity/repository/OrderBagRepository.java @@ -2,8 +2,10 @@ import greencity.entity.order.OrderBag; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -21,4 +23,22 @@ public interface OrderBagRepository extends JpaRepository { + "JOIN orders o on o.id = obm.order_id " + "WHERE obm.bag_id = :bagId AND o.order_payment_status = 'UNPAID'", nativeQuery = true) List findAllOrderBagsForUnpaidOrdersByBagId(Integer bagId); + + /** + * method updates the bag data of OrderBag for all unpaid orders. + * + * @param bagId {@link Integer} bag id + * @param capacity {@link Integer} bag capacity + * @param price {@link Long} bag full price in coins + * @param name {@link String} bag name + * @param nameEng {@link String} bag english name + * @author Julia Seti + */ + @Transactional + @Modifying + @Query(value = "update order_bag_mapping obm " + + "set capacity = :capacity, price = :price, name = :name, name_eng = :nameEng " + + "from orders o " + + "where o.id = obm.order_id and obm.bag_id = :bagId and o.order_payment_status = 'UNPAID'", nativeQuery = true) + void updateAllByBagIdForUnpaidOrders(Integer bagId, Integer capacity, Long price, String name, String nameEng); } diff --git a/dao/src/main/java/greencity/repository/ServiceRepository.java b/dao/src/main/java/greencity/repository/ServiceRepository.java index 704d73e55..309cd1e54 100644 --- a/dao/src/main/java/greencity/repository/ServiceRepository.java +++ b/dao/src/main/java/greencity/repository/ServiceRepository.java @@ -2,32 +2,16 @@ import greencity.entity.order.Service; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; import java.util.Optional; public interface ServiceRepository extends JpaRepository { /** - * Method that returns active service by id. - * - * @param serviceId {@link Long} - service id - * @return {@link Optional} of {@link Service} - * @author Julia Seti - */ - @Query(nativeQuery = true, - value = "SELECT * FROM service " - + "WHERE id = :serviceId AND status = 'ACTIVE'") - Optional findActiveServiceById(Long serviceId); - - /** - * Method that returns active service by TariffsInfo id. + * Method that return service by TariffsInfo id. * * @param tariffId {@link Long} - TariffsInfo id * @return {@link Optional} of {@link Service} * @author Julia Seti */ - @Query(nativeQuery = true, - value = "SELECT * FROM service " - + "WHERE tariffs_info_id = :tariffInfoId AND status = 'ACTIVE'") - Optional findActiveServiceByTariffsInfoId(Long tariffId); + Optional findServiceByTariffsInfoId(Long tariffId); } diff --git a/dao/src/main/resources/db/changelog/db.changelog-master.xml b/dao/src/main/resources/db/changelog/db.changelog-master.xml index a7e971a0c..823fbc18b 100644 --- a/dao/src/main/resources/db/changelog/db.changelog-master.xml +++ b/dao/src/main/resources/db/changelog/db.changelog-master.xml @@ -207,6 +207,6 @@ - + \ No newline at end of file diff --git a/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-and-service-tables-Seti.xml b/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-table-Seti.xml similarity index 75% rename from dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-and-service-tables-Seti.xml rename to dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-table-Seti.xml index 4fcfc4a35..a24ab6a62 100644 --- a/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-and-service-tables-Seti.xml +++ b/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-table-Seti.xml @@ -8,10 +8,5 @@ - - - - - \ No newline at end of file diff --git a/service-api/src/main/java/greencity/constant/ErrorMessage.java b/service-api/src/main/java/greencity/constant/ErrorMessage.java index 1e9783b81..1345f020c 100644 --- a/service-api/src/main/java/greencity/constant/ErrorMessage.java +++ b/service-api/src/main/java/greencity/constant/ErrorMessage.java @@ -65,7 +65,7 @@ public final class ErrorMessage { public static final String INCOMPATIBLE_ORDER_STATUS_FOR_VIOLATION = "Cannot add a violation to order with this status: "; public static final String EVENTS_NOT_FOUND_EXCEPTION = "Events didn't find in order id: "; - public static final String NOT_ENOUGH_BIG_BAGS_EXCEPTION = "Not enough big bags, minimal amount is:"; + public static final String NOT_ENOUGH_BAGS_EXCEPTION = "Not enough bags, minimal amount is: "; public static final String NOTIFICATION_DOES_NOT_EXIST = "Notification does not exist"; public static final String NOTIFICATION_STATUS_DOES_NOT_EXIST = "Notification status does not exist "; public static final String NOTIFICATION_DOES_NOT_BELONG_TO_USER = "This notification does not belong to user"; @@ -77,7 +77,7 @@ public final class ErrorMessage { public static final String LOCATION_IS_DEACTIVATED_FOR_TARIFF = "Location is deactivated for tariff: "; public static final String COURIER_IS_NOT_FOUND_BY_ID = "Couldn't found courier by id: "; public static final String CANNOT_DEACTIVATE_COURIER = "Courier is already deactivated with id: "; - public static final String TO_MUCH_BIG_BAG_EXCEPTION = "You choose to much big bag's max amount is: "; + public static final String TO_MUCH_BAG_EXCEPTION = "You choose to much bags, maximum amount is: "; public static final String PRICE_OF_ORDER_GREATER_THAN_LIMIT = "The price of you're order without discount is greater than allowable limit: "; public static final String PRICE_OF_ORDER_LOWER_THAN_LIMIT = diff --git a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java index 7ec165a94..b75b947f3 100644 --- a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java @@ -27,7 +27,6 @@ import greencity.entity.coords.Coordinates; import greencity.entity.order.Bag; import greencity.entity.order.Courier; -import greencity.entity.order.OrderBag; import greencity.entity.order.Service; import greencity.entity.order.TariffLocation; import greencity.entity.order.TariffsInfo; @@ -39,7 +38,6 @@ import greencity.enums.CourierLimit; import greencity.enums.CourierStatus; import greencity.enums.LocationStatus; -import greencity.enums.ServiceStatus; import greencity.enums.StationStatus; import greencity.enums.TariffStatus; import greencity.exceptions.BadRequestException; @@ -180,11 +178,9 @@ public GetTariffServiceDto editTariffService(TariffServiceDto dto, Integer bagId updateTariffService(dto, bag); bag.setEditedBy(employee); - List orderBags = orderBagRepository.findAllOrderBagsForUnpaidOrdersByBagId(bagId); - if (!orderBags.isEmpty()) { - orderBags.forEach(it -> updateOrderBag(it, bag)); - orderBagRepository.saveAll(orderBags); - } + orderBagRepository.updateAllByBagIdForUnpaidOrders( + bagId, bag.getCapacity(), bag.getFullPrice(), bag.getName(), bag.getNameEng()); + return modelMapper.map(bagRepository.save(bag), GetTariffServiceDto.class); } @@ -200,13 +196,6 @@ private void updateTariffService(TariffServiceDto dto, Bag bag) { bag.setEditedAt(LocalDate.now()); } - private void updateOrderBag(OrderBag orderBag, Bag bag) { - orderBag.setCapacity(bag.getCapacity()); - orderBag.setPrice(bag.getFullPrice()); - orderBag.setName(bag.getName()); - orderBag.setNameEng(bag.getNameEng()); - } - private Long convertBillsIntoCoins(Double bills) { return bills == null ? 0 @@ -233,13 +222,12 @@ public GetServiceDto addService(Long tariffId, ServiceDto dto, String employeeUu private Service createService(Long tariffId, ServiceDto dto, String employeeUuid) { TariffsInfo tariffsInfo = tryToFindTariffById(tariffId); - if (serviceRepository.findActiveServiceByTariffsInfoId(tariffId).isEmpty()) { + if (serviceRepository.findServiceByTariffsInfoId(tariffId).isEmpty()) { Employee employee = tryToFindEmployeeByUuid(employeeUuid); Service service = modelMapper.map(dto, Service.class); service.setCreatedBy(employee); service.setCreatedAt(LocalDate.now()); service.setTariffsInfo(tariffsInfo); - service.setStatus(ServiceStatus.ACTIVE); return service; } else { throw new ServiceAlreadyExistsException(ErrorMessage.SERVICE_ALREADY_EXISTS + tariffId); @@ -249,7 +237,7 @@ private Service createService(Long tariffId, ServiceDto dto, String employeeUuid @Override public GetServiceDto getService(long tariffId) { tryToFindTariffById(tariffId); - return serviceRepository.findActiveServiceByTariffsInfoId(tariffId) + return serviceRepository.findServiceByTariffsInfoId(tariffId) .map(it -> modelMapper.map(it, GetServiceDto.class)) .orElseGet(() -> null); } @@ -257,8 +245,7 @@ public GetServiceDto getService(long tariffId) { @Override public void deleteService(long id) { Service service = tryToFindServiceById(id); - service.setStatus(ServiceStatus.DELETED); - serviceRepository.save(service); + serviceRepository.delete(service); } @Override @@ -281,7 +268,7 @@ private Employee tryToFindEmployeeByUuid(String employeeUuid) { } private Service tryToFindServiceById(long id) { - return serviceRepository.findActiveServiceById(id) + return serviceRepository.findById(id) .orElseThrow(() -> new NotFoundException(ErrorMessage.SERVICE_IS_NOT_FOUND_BY_ID + id)); } diff --git a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java index eede026d1..91cb0b6b2 100644 --- a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java @@ -166,7 +166,7 @@ import static greencity.constant.ErrorMessage.EVENTS_NOT_FOUND_EXCEPTION; import static greencity.constant.ErrorMessage.LOCATION_DOESNT_FOUND_BY_ID; import static greencity.constant.ErrorMessage.LOCATION_IS_DEACTIVATED_FOR_TARIFF; -import static greencity.constant.ErrorMessage.NOT_ENOUGH_BIG_BAGS_EXCEPTION; +import static greencity.constant.ErrorMessage.NOT_ENOUGH_BAGS_EXCEPTION; import static greencity.constant.ErrorMessage.NOT_FOUND_ADDRESS_ID_FOR_CURRENT_USER; import static greencity.constant.ErrorMessage.NUMBER_OF_ADDRESSES_EXCEEDED; import static greencity.constant.ErrorMessage.ORDER_ALREADY_PAID; @@ -185,7 +185,7 @@ import static greencity.constant.ErrorMessage.THE_SET_OF_UBS_USER_DATA_DOES_NOT_EXIST; import static greencity.constant.ErrorMessage.TOO_MANY_CERTIFICATES; import static greencity.constant.ErrorMessage.TOO_MUCH_POINTS_FOR_ORDER; -import static greencity.constant.ErrorMessage.TO_MUCH_BIG_BAG_EXCEPTION; +import static greencity.constant.ErrorMessage.TO_MUCH_BAG_EXCEPTION; import static greencity.constant.ErrorMessage.USER_DONT_HAVE_ENOUGH_POINTS; import static greencity.constant.ErrorMessage.USER_WITH_CURRENT_ID_DOES_NOT_EXIST; import static greencity.constant.ErrorMessage.USER_WITH_CURRENT_UUID_DOES_NOT_EXIST; @@ -242,7 +242,6 @@ public class UBSClientServiceImpl implements UBSClientService { private String resultUrlForPersonalCabinetOfUser; @Value("${greencity.redirect.result-url-fondy}") private String resultUrlFondy; - private static final Integer BAG_CAPACITY = 120; private static final String FAILED_STATUS = "failure"; private static final String APPROVED_STATUS = "approved"; private static final String TELEGRAM_PART_1_OF_LINK = "https://telegram.me/"; @@ -425,7 +424,6 @@ public FondyOrderResponse saveFullOrderToDB(OrderResponseDto dto, String uuid, L long sumToPayWithoutDiscountInCoins = formBagsToBeSavedAndCalculateOrderSum(amountOfBagsOrderedMap, dto.getBags(), tariffsInfo); - checkSumIfCourierLimitBySumOfOrder(tariffsInfo, sumToPayWithoutDiscountInCoins); checkIfUserHaveEnoughPoints(currentUser.getCurrentPoints(), dto.getPointsToUse()); long sumToPayInCoins = reduceOrderSumDueToUsedPoints(sumToPayWithoutDiscountInCoins, dto.getPointsToUse()); @@ -1193,10 +1191,10 @@ private void checkAmountOfBagsIfCourierLimitByAmountOfBag(TariffsInfo courierLoc if (CourierLimit.LIMIT_BY_AMOUNT_OF_BAG.equals(courierLocation.getCourierLimit()) && courierLocation.getMin() > countOfBigBag) { throw new BadRequestException( - NOT_ENOUGH_BIG_BAGS_EXCEPTION + courierLocation.getMin()); + NOT_ENOUGH_BAGS_EXCEPTION + courierLocation.getMin()); } else if (CourierLimit.LIMIT_BY_AMOUNT_OF_BAG.equals(courierLocation.getCourierLimit()) && courierLocation.getMax() < countOfBigBag) { - throw new BadRequestException(TO_MUCH_BIG_BAG_EXCEPTION + courierLocation.getMax()); + throw new BadRequestException(TO_MUCH_BAG_EXCEPTION + courierLocation.getMax()); } } @@ -1216,18 +1214,16 @@ private long formBagsToBeSavedAndCalculateOrderSumClient( private long formBagsToBeSavedAndCalculateOrderSum( Map map, List bags, TariffsInfo tariffsInfo) { long sumToPayInCoins = 0L; - int bigBagCounter = 0; for (BagDto temp : bags) { Bag bag = tryToGetBagById(temp.getId()); - if (bag.getCapacity() >= BAG_CAPACITY) { - bigBagCounter += temp.getAmount(); + if (bag.getLimitIncluded().booleanValue()) { + checkAmountOfBagsIfCourierLimitByAmountOfBag(tariffsInfo, temp.getAmount()); + checkSumIfCourierLimitBySumOfOrder(tariffsInfo, bag.getFullPrice() * temp.getAmount()); } sumToPayInCoins += bag.getFullPrice() * temp.getAmount(); map.put(temp.getId(), temp.getAmount()); } - - checkAmountOfBagsIfCourierLimitByAmountOfBag(tariffsInfo, bigBagCounter); return sumToPayInCoins; } diff --git a/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java index 269c8cac4..ce35b4700 100644 --- a/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java @@ -364,7 +364,7 @@ public OrderStatusPageDto getOrderStatusData(Long orderId, String email) { .map(bag -> modelMapper.map(bag, BagInfoDto.class)) .collect(Collectors.toList()); - Long servicePriceInCoins = serviceRepository.findActiveServiceByTariffsInfoId(order.getTariffsInfo().getId()) + Long servicePriceInCoins = serviceRepository.findServiceByTariffsInfoId(order.getTariffsInfo().getId()) .map(it -> it.getPrice()) .orElse(0L); diff --git a/service/src/test/java/greencity/ModelUtils.java b/service/src/test/java/greencity/ModelUtils.java index e74d5895f..fd102a2d3 100644 --- a/service/src/test/java/greencity/ModelUtils.java +++ b/service/src/test/java/greencity/ModelUtils.java @@ -130,7 +130,6 @@ import greencity.enums.OrderPaymentStatus; import greencity.enums.OrderStatus; import greencity.enums.PaymentStatus; -import greencity.enums.ServiceStatus; import greencity.enums.TariffStatus; import greencity.util.Bot; import org.springframework.data.domain.Page; @@ -2588,6 +2587,23 @@ public static Bag getBagDeleted() { .build(); } + public static Bag getBagForOrder() { + return Bag.builder() + .id(3) + .capacity(120) + .commission(50_00L) + .price(350_00L) + .fullPrice(400_00L) + .createdAt(LocalDate.now()) + .createdBy(getEmployee()) + .editedBy(getEmployee()) + .description("Description") + .descriptionEng("DescriptionEng") + .limitIncluded(true) + .tariffsInfo(getTariffInfo()) + .build(); + } + public static TariffServiceDto getTariffServiceDto() { return TariffServiceDto.builder() .name("Бавовняна сумка") @@ -2778,24 +2794,9 @@ public static Service getService() { .descriptionEng("DescriptionEng") .name("Name") .nameEng("NameEng") - .status(ServiceStatus.ACTIVE) .build(); } - public static Service getServiceDeleted() { - Employee employee = ModelUtils.getEmployee(); - return Service.builder() - .id(1L) - .price(100_00L) - .createdAt(LocalDate.now()) - .createdBy(employee) - .description("Description") - .descriptionEng("DescriptionEng") - .name("Name") - .nameEng("NameEng") - .status(ServiceStatus.DELETED) - .build(); - } public static Service getNewService() { Employee employee = ModelUtils.getEmployee(); @@ -2807,7 +2808,6 @@ public static Service getNewService() { .descriptionEng("DescriptionEng") .name("Name") .nameEng("NameEng") - .status(ServiceStatus.ACTIVE) .build(); } diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index 302f191c2..49d7aa884 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -24,7 +24,6 @@ import greencity.dto.tariff.SetTariffLimitsDto; import greencity.entity.order.Bag; import greencity.entity.order.Courier; -import greencity.entity.order.OrderBag; import greencity.entity.order.Service; import greencity.entity.order.TariffLocation; import greencity.entity.order.TariffsInfo; @@ -325,16 +324,14 @@ void editTariffService() { Employee employee = ModelUtils.getEmployee(); TariffServiceDto dto = ModelUtils.getTariffServiceDto(); GetTariffServiceDto editedDto = ModelUtils.getGetTariffServiceDto(); - OrderBag orderBag = ModelUtils.getOrderBag(); - OrderBag editedOrderBag = ModelUtils.getEditedOrderBag(); String uuid = UUID.randomUUID().toString(); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); when(bagRepository.save(editedBag)).thenReturn(editedBag); when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); - when(orderBagRepository.findAllOrderBagsForUnpaidOrdersByBagId(1)).thenReturn(List.of(orderBag)); - when(orderBagRepository.saveAll(List.of(editedOrderBag))).thenReturn(List.of(editedOrderBag)); + doNothing().when(orderBagRepository) + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); GetTariffServiceDto actual = superAdminService.editTariffService(dto, 1, uuid); @@ -343,8 +340,8 @@ void editTariffService() { verify(bagRepository).findActiveBagById(1); verify(bagRepository).save(editedBag); verify(modelMapper).map(editedBag, GetTariffServiceDto.class); - verify(orderBagRepository).findAllOrderBagsForUnpaidOrdersByBagId(1); - verify(orderBagRepository).saveAll(List.of(editedOrderBag)); + verify(orderBagRepository) + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); } @Test @@ -360,7 +357,8 @@ void editTariffServiceIfOrderBagsListIsEmpty() { when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); when(bagRepository.save(editedBag)).thenReturn(editedBag); when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); - when(orderBagRepository.findAllOrderBagsForUnpaidOrdersByBagId(1)).thenReturn(Collections.emptyList()); + doNothing().when(orderBagRepository) + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); GetTariffServiceDto actual = superAdminService.editTariffService(dto, 1, uuid); @@ -369,7 +367,8 @@ void editTariffServiceIfOrderBagsListIsEmpty() { verify(bagRepository).findActiveBagById(1); verify(bagRepository).save(editedBag); verify(modelMapper).map(editedBag, GetTariffServiceDto.class); - verify(orderBagRepository).findAllOrderBagsForUnpaidOrdersByBagId(1); + verify(orderBagRepository) + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); verify(orderBagRepository, never()).saveAll(anyList()); } @@ -416,26 +415,26 @@ void getAllCouriersTest() { @Test void deleteService() { Service service = ModelUtils.getService(); - Service deletedService = ModelUtils.getServiceDeleted(); - when(serviceRepository.findActiveServiceById(service.getId())).thenReturn(Optional.of(service)); - when(serviceRepository.save(deletedService)).thenReturn(deletedService); + when(serviceRepository.findById(service.getId())).thenReturn(Optional.of(service)); superAdminService.deleteService(1L); - verify(serviceRepository).findActiveServiceById(1L); - verify(serviceRepository).save(deletedService); + verify(serviceRepository).findById(1L); + verify(serviceRepository).delete(service); } @Test void deleteServiceThrowNotFoundException() { - when(serviceRepository.findActiveServiceById(1L)).thenReturn(Optional.empty()); + Service service = ModelUtils.getService(); + + when(serviceRepository.findById(service.getId())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.deleteService(1L)); + () -> superAdminService.deleteService(1L)); - verify(serviceRepository).findActiveServiceById(1L); - verify(serviceRepository, never()).save(any(Service.class)); + verify(serviceRepository).findById(1L); + verify(serviceRepository, never()).delete(service); } @Test @@ -445,13 +444,13 @@ void getService() { TariffsInfo tariffsInfo = ModelUtils.getTariffsInfo(); when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); - when(serviceRepository.findActiveServiceByTariffsInfoId(1L)).thenReturn(Optional.of(service)); + when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(service)); when(modelMapper.map(service, GetServiceDto.class)).thenReturn(getServiceDto); assertEquals(getServiceDto, superAdminService.getService(1L)); verify(tariffsInfoRepository).findById(1L); - verify(serviceRepository).findActiveServiceByTariffsInfoId(1L); + verify(serviceRepository).findServiceByTariffsInfoId(1L); verify(modelMapper).map(service, GetServiceDto.class); } @@ -460,12 +459,12 @@ void getServiceIfServiceNotExists() { TariffsInfo tariffsInfo = ModelUtils.getTariffsInfo(); when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); - when(serviceRepository.findActiveServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); + when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); assertNull(superAdminService.getService(1L)); verify(tariffsInfoRepository).findById(1L); - verify(serviceRepository).findActiveServiceByTariffsInfoId(1L); + verify(serviceRepository).findServiceByTariffsInfoId(1L); } @Test @@ -486,14 +485,14 @@ void editService() { GetServiceDto getServiceDto = ModelUtils.getGetServiceDto(); String uuid = UUID.randomUUID().toString(); - when(serviceRepository.findActiveServiceById(1L)).thenReturn(Optional.of(service)); + when(serviceRepository.findById(1L)).thenReturn(Optional.of(service)); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); when(serviceRepository.save(service)).thenReturn(service); when(modelMapper.map(service, GetServiceDto.class)).thenReturn(getServiceDto); assertEquals(getServiceDto, superAdminService.editService(1L, dto, uuid)); - verify(serviceRepository).findActiveServiceById(1L); + verify(serviceRepository).findById(1L); verify(employeeRepository).findByUuid(uuid); verify(serviceRepository).save(service); verify(modelMapper).map(service, GetServiceDto.class); @@ -504,12 +503,12 @@ void editServiceServiceNotFoundException() { ServiceDto dto = ModelUtils.getServiceDto(); String uuid = UUID.randomUUID().toString(); - when(serviceRepository.findActiveServiceById(1L)).thenReturn(Optional.empty()); + when(serviceRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, () -> superAdminService.editService(1L, dto, uuid)); - verify(serviceRepository).findActiveServiceById(1L); + verify(serviceRepository).findById(1L); verify(serviceRepository, never()).save(any(Service.class)); verify(modelMapper, never()).map(any(Service.class), any(GetServiceDto.class)); } @@ -520,14 +519,14 @@ void editServiceEmployeeNotFoundException() { ServiceDto dto = ModelUtils.getServiceDto(); String uuid = UUID.randomUUID().toString(); - when(serviceRepository.findActiveServiceById(1L)).thenReturn(Optional.of(service)); + when(serviceRepository.findById(1L)).thenReturn(Optional.of(service)); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, () -> superAdminService.editService(1L, dto, uuid)); verify(employeeRepository).findByUuid(uuid); - verify(serviceRepository).findActiveServiceById(1L); + verify(serviceRepository).findById(1L); verify(serviceRepository, never()).save(any(Service.class)); verify(modelMapper, never()).map(any(Service.class), any(GetServiceDto.class)); } @@ -542,7 +541,7 @@ void addService() { TariffsInfo tariffsInfo = ModelUtils.getTariffsInfo(); String uuid = UUID.randomUUID().toString(); - when(serviceRepository.findActiveServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); + when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); when(serviceRepository.save(service)).thenReturn(createdService); @@ -553,7 +552,7 @@ void addService() { verify(employeeRepository).findByUuid(uuid); verify(tariffsInfoRepository).findById(1L); - verify(serviceRepository).findActiveServiceByTariffsInfoId(1L); + verify(serviceRepository).findServiceByTariffsInfoId(1L); verify(serviceRepository).save(service); verify(modelMapper).map(createdService, GetServiceDto.class); verify(modelMapper).map(createdService, GetServiceDto.class); @@ -567,13 +566,13 @@ void addServiceThrowServiceAlreadyExistsException() { String uuid = UUID.randomUUID().toString(); when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); - when(serviceRepository.findActiveServiceByTariffsInfoId(1L)).thenReturn(Optional.of(createdService)); + when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(createdService)); assertThrows(ServiceAlreadyExistsException.class, () -> superAdminService.addService(1L, serviceDto, uuid)); verify(tariffsInfoRepository).findById(1L); - verify(serviceRepository).findActiveServiceByTariffsInfoId(1L); + verify(serviceRepository).findServiceByTariffsInfoId(1L); } @Test @@ -583,14 +582,14 @@ void addServiceThrowEmployeeNotFoundException() { String uuid = UUID.randomUUID().toString(); when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); - when(serviceRepository.findActiveServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); + when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, () -> superAdminService.addService(1L, serviceDto, uuid)); verify(tariffsInfoRepository).findById(1L); - verify(serviceRepository).findActiveServiceByTariffsInfoId(1L); + verify(serviceRepository).findServiceByTariffsInfoId(1L); verify(employeeRepository).findByUuid(uuid); } diff --git a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java index c285703dd..b50d24001 100644 --- a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java @@ -8,6 +8,7 @@ import greencity.dto.OrderCourierPopUpDto; import greencity.dto.TariffsForLocationDto; import greencity.dto.address.AddressDto; +import greencity.dto.bag.BagDto; import greencity.dto.bag.BagForUserDto; import greencity.dto.bag.BagOrderDto; import greencity.dto.bag.BagTranslationDto; @@ -119,77 +120,8 @@ import java.util.UUID; import java.util.stream.Collectors; -import static greencity.ModelUtils.TEST_BAG_LIST; -import static greencity.ModelUtils.TEST_EMAIL; -import static greencity.ModelUtils.TEST_ORDER_ADDRESS_DTO_REQUEST; -import static greencity.ModelUtils.TEST_PAYMENT_LIST; -import static greencity.ModelUtils.TEST_BAG_FOR_USER_DTO; -import static greencity.ModelUtils.addressDto; -import static greencity.ModelUtils.addressDtoList; -import static greencity.ModelUtils.addressList; -import static greencity.ModelUtils.bagDto; -import static greencity.ModelUtils.botList; -import static greencity.ModelUtils.createCertificateDto; -import static greencity.ModelUtils.getAddress; -import static greencity.ModelUtils.getAddressDtoResponse; -import static greencity.ModelUtils.getAddressRequestDto; -import static greencity.ModelUtils.getBag1list; -import static greencity.ModelUtils.getBag4list; -import static greencity.ModelUtils.getBagTranslationDto; -import static greencity.ModelUtils.getCancellationDto; -import static greencity.ModelUtils.getCertificate; -import static greencity.ModelUtils.getCourier; -import static greencity.ModelUtils.getCourierDto; -import static greencity.ModelUtils.getCourierDtoList; -import static greencity.ModelUtils.getEmployee; -import static greencity.ModelUtils.getGeocodingResult; -import static greencity.ModelUtils.getListOfEvents; -import static greencity.ModelUtils.getLocation; -import static greencity.ModelUtils.getMaximumAmountOfAddresses; -import static greencity.ModelUtils.getOrder; -import static greencity.ModelUtils.getOrderClientDto; -import static greencity.ModelUtils.getOrderCount; -import static greencity.ModelUtils.getOrderCountWithPaymentStatusPaid; -import static greencity.ModelUtils.getOrderDetails; -import static greencity.ModelUtils.getOrderDetailsWithoutSender; -import static greencity.ModelUtils.getOrderDoneByUser; -import static greencity.ModelUtils.getOrderFondyClientDto; -import static greencity.ModelUtils.getOrderPaymentDetailDto; -import static greencity.ModelUtils.getOrderPaymentStatusTranslation; -import static greencity.ModelUtils.getOrderResponseDto; -import static greencity.ModelUtils.getOrderStatusDto; -import static greencity.ModelUtils.getOrderStatusTranslation; -import static greencity.ModelUtils.getOrderTest; -import static greencity.ModelUtils.getOrderWithEvents; -import static greencity.ModelUtils.getOrderWithTariffAndLocation; -import static greencity.ModelUtils.getOrderWithoutPayment; -import static greencity.ModelUtils.getOrdersDto; -import static greencity.ModelUtils.getPayment; -import static greencity.ModelUtils.getPaymentResponseDto; -import static greencity.ModelUtils.getSuccessfulFondyResponse; -import static greencity.ModelUtils.getTariffInfo; -import static greencity.ModelUtils.getTariffInfoWithLimitOfBags; -import static greencity.ModelUtils.getTariffInfoWithLimitOfBagsAndMaxLessThanCountOfBigBag; -import static greencity.ModelUtils.getTariffLocation; -import static greencity.ModelUtils.getTariffsForLocationDto; -import static greencity.ModelUtils.getTelegramBotNotifyTrue; -import static greencity.ModelUtils.getTestOrderAddressDtoRequest; -import static greencity.ModelUtils.getTestOrderAddressLocationDto; -import static greencity.ModelUtils.getTestUser; -import static greencity.ModelUtils.getUBSuser; -import static greencity.ModelUtils.getUBSuserWithoutSender; -import static greencity.ModelUtils.getUbsUsers; -import static greencity.ModelUtils.getUser; -import static greencity.ModelUtils.getUserForCreate; -import static greencity.ModelUtils.getUserInfoDto; -import static greencity.ModelUtils.getUserPointsAndAllBagsDto; -import static greencity.ModelUtils.getUserProfileCreateDto; -import static greencity.ModelUtils.getUserProfileUpdateDto; -import static greencity.ModelUtils.getUserProfileUpdateDtoWithBotsIsNotifyFalse; -import static greencity.ModelUtils.getUserWithBotNotifyTrue; -import static greencity.ModelUtils.getUserWithLastLocation; -import static greencity.ModelUtils.getViberBotNotifyTrue; - +import static greencity.ModelUtils.*; +import static greencity.ModelUtils.getBagForOrder; import static greencity.constant.ErrorMessage.ACTUAL_ADDRESS_NOT_FOUND; import static greencity.constant.ErrorMessage.ADDRESS_ALREADY_EXISTS; import static greencity.constant.ErrorMessage.CANNOT_ACCESS_PERSONAL_INFO; @@ -718,9 +650,8 @@ void testSaveToDB() throws IllegalAccessException { user.getOrders().add(order); user.setChangeOfPointsList(new ArrayList<>()); - Bag bag = new Bag(); - bag.setCapacity(120); - bag.setFullPrice(400_00L); + Bag bag = getBagForOrder(); + TariffsInfo tariffsInfo = getTariffInfo(); UBSuser ubSuser = getUBSuser(); @@ -743,7 +674,7 @@ void testSaveToDB() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); @@ -757,6 +688,63 @@ void testSaveToDB() throws IllegalAccessException { } + @Test + void testSaveToDBWithTwoBags() throws IllegalAccessException { + User user = getUserWithLastLocation(); + user.setAlternateEmail("test@mail.com"); + user.setCurrentPoints(900); + + OrderResponseDto dto = getOrderResponseDto(); + dto.getBags().get(0).setAmount(15); + dto.setBags(List.of(BagDto.builder().id(1).amount(1).build(), BagDto.builder().id(3).amount(15).build())); + + Order order = getOrder(); + user.setOrders(new ArrayList<>()); + user.getOrders().add(order); + user.setChangeOfPointsList(new ArrayList<>()); + + Bag bag1 = getBagForOrder(); + bag1.setId(1); + bag1.setLimitIncluded(false); + Bag bag3 = getBagForOrder(); + TariffsInfo tariffsInfo = getTariffInfo(); + + UBSuser ubSuser = getUBSuser(); + + OrderAddress orderAddress = ubSuser.getOrderAddress(); + orderAddress.setAddressStatus(AddressStatus.NEW); + + Order order1 = getOrder(); + order1.setPayment(new ArrayList<>()); + Payment payment1 = getPayment(); + payment1.setId(1L); + order1.getPayment().add(payment1); + + Field[] fields = UBSClientServiceImpl.class.getDeclaredFields(); + for (Field f : fields) { + if (f.getName().equals("merchantId")) { + f.setAccessible(true); + f.set(ubsService, "1"); + } + } + + when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); + when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) + .thenReturn(Optional.of(tariffsInfo)); + when(bagRepository.findById(1)).thenReturn(Optional.of(bag1)); + when(bagRepository.findById(3)).thenReturn(Optional.of(bag3)); + when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); + when(modelMapper.map(dto, Order.class)).thenReturn(order); + when(modelMapper.map(dto.getPersonalData(), UBSuser.class)).thenReturn(ubSuser); + when(orderRepository.findById(any())).thenReturn(Optional.of(order1)); + when(encryptionUtil.formRequestSignature(any(), eq(null), eq("1"))).thenReturn("TestValue"); + when(fondyClient.getCheckoutResponse(any())).thenReturn(getSuccessfulFondyResponse()); + + FondyOrderResponse result = ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null); + Assertions.assertNotNull(result); + + } + @Test void testSaveToDBWithCertificates() throws IllegalAccessException { User user = getUserWithLastLocation(); @@ -771,9 +759,8 @@ void testSaveToDBWithCertificates() throws IllegalAccessException { user.getOrders().add(order); user.setChangeOfPointsList(new ArrayList<>()); - Bag bag = new Bag(); - bag.setCapacity(120); - bag.setFullPrice(400_00L); + Bag bag = getBagForOrder(); + TariffsInfo tariffsInfo = getTariffInfo(); UBSuser ubSuser = getUBSuser(); @@ -796,7 +783,7 @@ void testSaveToDBWithCertificates() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(certificateRepository.findById(anyString())).thenReturn(Optional.of(getCertificate())); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); @@ -825,9 +812,8 @@ void testSaveToDBWithDontSendLinkToFondy() throws IllegalAccessException { user.getOrders().add(order); user.setChangeOfPointsList(new ArrayList<>()); - Bag bag = new Bag(); - bag.setCapacity(120); - bag.setFullPrice(400_00L); + Bag bag = getBagForOrder(); + TariffsInfo tariffsInfo = getTariffInfo(); Certificate certificate = getCertificate(); certificate.setPoints(1000_00); @@ -853,7 +839,7 @@ void testSaveToDBWithDontSendLinkToFondy() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(certificateRepository.findById(anyString())).thenReturn(Optional.of(certificate)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); @@ -879,9 +865,8 @@ void testSaveToDBWhenSumToPayLessThanPoints() throws IllegalAccessException { user.getOrders().add(order); user.setChangeOfPointsList(new ArrayList<>()); - Bag bag = new Bag(); - bag.setCapacity(120); - bag.setFullPrice(400_00L); + Bag bag = getBagForOrder(); + TariffsInfo tariffsInfo = getTariffInfo(); UBSuser ubSuser = getUBSuser(); @@ -904,7 +889,7 @@ void testSaveToDBWhenSumToPayLessThanPoints() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); @@ -931,9 +916,7 @@ void testSaveToDbThrowBadRequestExceptionPriceLowerThanLimit() throws IllegalAcc user.getOrders().add(order); user.setChangeOfPointsList(new ArrayList<>()); - Bag bag = new Bag(); - bag.setCapacity(120); - bag.setFullPrice(400_00L); + Bag bag = getBagForOrder(); when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) @@ -961,9 +944,7 @@ void testSaveToDbThrowBadRequestExceptionPriceGreaterThanLimit() throws IllegalA user.getOrders().add(order); user.setChangeOfPointsList(new ArrayList<>()); - Bag bag = new Bag(); - bag.setCapacity(120); - bag.setFullPrice(400_00L); + Bag bag = getBagForOrder(); when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) @@ -992,9 +973,9 @@ void testSaveToDBWShouldThrowBadRequestException() throws IllegalAccessException user.getOrders().add(order); user.setChangeOfPointsList(new ArrayList<>()); - Bag bag = new Bag(); - bag.setCapacity(120); - bag.setFullPrice(400_00L); + Bag bag = getBagForOrder(); + TariffsInfo tariffsInfo = getTariffInfoWithLimitOfBagsAndMaxLessThanCountOfBigBag(); + bag.setTariffsInfo(tariffsInfo); UBSuser ubSuser = getUBSuser(); @@ -1009,7 +990,7 @@ void testSaveToDBWShouldThrowBadRequestException() throws IllegalAccessException when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfoWithLimitOfBagsAndMaxLessThanCountOfBigBag())); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, @@ -1034,9 +1015,7 @@ void testSaveToDBWShouldThrowTariffNotFoundExceptionException() { user.getOrders().add(order); user.setChangeOfPointsList(new ArrayList<>()); - Bag bag = new Bag(); - bag.setCapacity(120); - bag.setFullPrice(400_00L); + Bag bag = getBagForOrder(); UBSuser ubSuser = getUBSuser(); @@ -1074,9 +1053,7 @@ void testSaveToDBWShouldThrowBagNotFoundExceptionException() throws IllegalAcces user.getOrders().add(order); user.setChangeOfPointsList(new ArrayList<>()); - Bag bag = new Bag(); - bag.setCapacity(120); - bag.setFullPrice(400_00L); + Bag bag = getBagForOrder(); UBSuser ubSuser = getUBSuser(); @@ -1125,9 +1102,7 @@ void testSaveToDBWithoutOrderUnpaid() throws IllegalAccessException { user.getOrders().add(order); user.setChangeOfPointsList(new ArrayList<>()); - Bag bag = new Bag(); - bag.setCapacity(120); - bag.setFullPrice(400_00L); + Bag bag = getBagForOrder(); UBSuser ubSuser = getUBSuser(); @@ -1168,13 +1143,13 @@ void saveToDBFailPaidOrder() { dto.getBags().get(0).setAmount(5); Order order = getOrder(); order.setOrderPaymentStatus(OrderPaymentStatus.PAID); - Bag bag = new Bag(); - bag.setCapacity(120); - bag.setFullPrice(400_00L); + + Bag bag = getBagForOrder(); + TariffsInfo tariffsInfo = getTariffInfo(); when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(orderRepository.findById(any())).thenReturn(Optional.of(order)); @@ -1194,9 +1169,9 @@ void testSaveToDBThrowsException() throws IllegalAccessException { user.getOrders().add(order); user.setChangeOfPointsList(new ArrayList<>()); - Bag bag = new Bag(); - bag.setCapacity(100); - bag.setFullPrice(400_00L); + Bag bag = getBagForOrder(); + TariffsInfo tariffsInfo = getTariffInfoWithLimitOfBags(); + bag.setTariffsInfo(tariffsInfo); UBSuser ubSuser = getUBSuser(); @@ -1219,7 +1194,7 @@ void testSaveToDBThrowsException() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfoWithLimitOfBags())); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); @@ -2696,9 +2671,11 @@ void saveFullOrderToDBForIF() throws IllegalAccessException { user.getOrders().add(order); user.setChangeOfPointsList(new ArrayList<>()); - Bag bag = new Bag(); - bag.setCapacity(120); + Bag bag = getBag(); + bag.setCapacity(100); bag.setFullPrice(400_00L); + TariffsInfo tariffsInfo = getTariffsInfo(); + bag.setTariffsInfo(tariffsInfo); UBSuser ubSuser = getUBSuser(); @@ -2751,9 +2728,7 @@ void saveFullOrderToDBWhenSumToPayeqNull() throws IllegalAccessException { user.getOrders().add(order); user.setChangeOfPointsList(new ArrayList<>()); - Bag bag = new Bag(); - bag.setCapacity(120); - bag.setFullPrice(400_00L); + Bag bag = getBagForOrder(); UBSuser ubSuser = getUBSuser().setId(null); @@ -2803,9 +2778,8 @@ void testSaveToDBfromIForIFThrowsException() throws IllegalAccessException { user.getOrders().add(order); user.setChangeOfPointsList(new ArrayList<>()); - Bag bag = new Bag(); - bag.setCapacity(100); - bag.setFullPrice(400_00L); + Bag bag = getBagForOrder(); + bag.setTariffsInfo(getTariffInfoWithLimitOfBags()); UBSuser ubSuser = getUBSuser(); @@ -2847,9 +2821,11 @@ void testCheckSumIfCourierLimitBySumOfOrderForIF1() throws IllegalAccessExceptio user.getOrders().add(order); user.setChangeOfPointsList(new ArrayList<>()); - Bag bag = new Bag(); - bag.setCapacity(120); - bag.setFullPrice(400_00L); + Bag bag = getBagForOrder(); + TariffsInfo tariffsInfo = getTariffInfoWithLimitOfBags(); + tariffsInfo.setCourierLimit(CourierLimit.LIMIT_BY_SUM_OF_ORDER); + tariffsInfo.setMin(50000L); + bag.setTariffsInfo(tariffsInfo); UBSuser ubSuser = getUBSuser(); @@ -2866,10 +2842,7 @@ void testCheckSumIfCourierLimitBySumOfOrderForIF1() throws IllegalAccessExceptio when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of( - getTariffInfoWithLimitOfBags() - .setCourierLimit(CourierLimit.LIMIT_BY_SUM_OF_ORDER) - .setMin(50000L))); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); @@ -2892,9 +2865,11 @@ void testCheckSumIfCourierLimitBySumOfOrderForIF2() throws InvocationTargetExcep user.getOrders().add(order); user.setChangeOfPointsList(new ArrayList<>()); - Bag bag = new Bag(); - bag.setCapacity(120); - bag.setFullPrice(400_00L); + Bag bag = getBagForOrder(); + TariffsInfo tariffsInfo = getTariffInfoWithLimitOfBags(); + tariffsInfo.setCourierLimit(CourierLimit.LIMIT_BY_SUM_OF_ORDER); + tariffsInfo.setMax(500L); + bag.setTariffsInfo(tariffsInfo); UBSuser ubSuser = getUBSuser(); @@ -2911,10 +2886,7 @@ void testCheckSumIfCourierLimitBySumOfOrderForIF2() throws InvocationTargetExcep when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of( - getTariffInfoWithLimitOfBags() - .setCourierLimit(CourierLimit.LIMIT_BY_SUM_OF_ORDER) - .setMax(500L))); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, () -> { @@ -3362,9 +3334,7 @@ void checkIfAddressHasBeenDeletedTest() throws IllegalAccessException { user.getOrders().add(order); user.setChangeOfPointsList(new ArrayList<>()); - Bag bag = new Bag(); - bag.setCapacity(120); - bag.setFullPrice(400_00L); + Bag bag = getBagForOrder(); UBSuser ubSuser = getUBSuser(); @@ -3408,9 +3378,7 @@ void checkAddressUserTest() throws IllegalAccessException { user.getOrders().add(order); user.setChangeOfPointsList(new ArrayList<>()); - Bag bag = new Bag(); - bag.setCapacity(120); - bag.setFullPrice(400_00L); + Bag bag = getBagForOrder(); UBSuser ubSuser = getUBSuser(); @@ -3451,9 +3419,7 @@ void checkIfUserHaveEnoughPointsTest() throws IllegalAccessException { user.getOrders().add(order); user.setChangeOfPointsList(new ArrayList<>()); - Bag bag = new Bag(); - bag.setCapacity(120); - bag.setFullPrice(400_00L); + Bag bag = getBagForOrder(); Field[] fields = UBSClientServiceImpl.class.getDeclaredFields(); for (Field f : fields) { diff --git a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java index 728568d38..4c51f15cf 100644 --- a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java @@ -1906,7 +1906,7 @@ void getOrderStatusDataTest() { when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(1L)).thenReturn(ModelUtils.getCertificateList()); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); - when(serviceRepository.findActiveServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); + when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when(orderStatusTranslationRepository.getOrderStatusTranslationById(6L)) .thenReturn(Optional.ofNullable(getStatusTranslation())); @@ -1925,7 +1925,7 @@ void getOrderStatusDataTest() { verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); verify(certificateRepository).findCertificate(1L); verify(orderRepository, times(5)).findById(1L); - verify(serviceRepository).findActiveServiceByTariffsInfoId(1L); + verify(serviceRepository).findServiceByTariffsInfoId(1L); verify(modelMapper).map(ModelUtils.getBaglist().get(0), BagInfoDto.class); verify(orderStatusTranslationRepository).getOrderStatusTranslationById(6L); verify(orderPaymentStatusTranslationRepository).getById(1L); @@ -1981,7 +1981,7 @@ void getOrderStatusDataTestEmptyPriceDetails() { when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag2list()); - when(serviceRepository.findActiveServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); + when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when(orderStatusTranslationRepository.getOrderStatusTranslationById(6L)) .thenReturn(Optional.ofNullable(getStatusTranslation())); @@ -2000,7 +2000,7 @@ void getOrderStatusDataTestEmptyPriceDetails() { verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); verify(certificateRepository).findCertificate(1L); verify(orderRepository, times(5)).findById(1L); - verify(serviceRepository).findActiveServiceByTariffsInfoId(1L); + verify(serviceRepository).findServiceByTariffsInfoId(1L); verify(modelMapper).map(ModelUtils.getBaglist().get(0), BagInfoDto.class); verify(orderStatusTranslationRepository).getOrderStatusTranslationById(6L); verify(orderPaymentStatusTranslationRepository).getById(1L); @@ -2023,7 +2023,7 @@ void getOrderStatusDataWithEmptyCertificateTest() { when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); - when(serviceRepository.findActiveServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); + when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when(orderStatusTranslationRepository.getOrderStatusTranslationById(6L)) @@ -2040,7 +2040,7 @@ void getOrderStatusDataWithEmptyCertificateTest() { verify(bagRepository).findBagsByOrderId(1L); verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); verify(orderRepository, times(5)).findById(1L); - verify(serviceRepository).findActiveServiceByTariffsInfoId(1L); + verify(serviceRepository).findServiceByTariffsInfoId(1L); verify(modelMapper).map(ModelUtils.getBaglist().get(0), BagInfoDto.class); verify(orderStatusTranslationRepository).getOrderStatusTranslationById(6L); verify(orderPaymentStatusTranslationRepository).getById(1L); @@ -2062,7 +2062,7 @@ void getOrderStatusDataWhenOrderTranslationIsNull() { when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); - when(serviceRepository.findActiveServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); + when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when( @@ -2077,7 +2077,7 @@ void getOrderStatusDataWhenOrderTranslationIsNull() { verify(bagRepository).findBagsByOrderId(1L); verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); verify(orderRepository, times(5)).findById(1L); - verify(serviceRepository).findActiveServiceByTariffsInfoId(1L); + verify(serviceRepository).findServiceByTariffsInfoId(1L); verify(modelMapper).map(ModelUtils.getBaglist().get(0), BagInfoDto.class); verify(orderStatusTranslationRepository).getOrderStatusTranslationById(6L); verify(orderPaymentStatusTranslationRepository).getById(1L); @@ -2099,7 +2099,7 @@ void getOrderStatusDataExceptionTest() { when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(bagRepository.findBagsByOrderId(1L)).thenReturn(ModelUtils.getBaglist()); when(certificateRepository.findCertificate(1L)).thenReturn(ModelUtils.getCertificateList()); - when(serviceRepository.findActiveServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); + when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(modelMapper.map(ModelUtils.getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when(orderStatusTranslationRepository.getOrderStatusTranslationById(6L)) From a00b52b7509f3591b22bd805b5ac67109ea8294f Mon Sep 17 00:00:00 2001 From: Julia Seti Date: Wed, 5 Jul 2023 16:50:10 +0300 Subject: [PATCH 08/73] changed tariff service crud methods and some order methods --- .../java/greencity/entity/order/Order.java | 17 +-- .../repository/OrderBagRepository.java | 36 ++--- .../greencity/repository/OrderRepository.java | 18 +++ .../mapping/bag/BagForUserDtoMapper.java | 8 +- .../service/ubs/SuperAdminServiceImpl.java | 43 +++++- .../service/ubs/UBSClientServiceImpl.java | 141 +++++++----------- .../src/test/java/greencity/ModelUtils.java | 67 +++++++-- .../mapping/bag/BagForUserDtoMapperTest.java | 6 +- .../ubs/SuperAdminServiceImplTest.java | 97 ++++++++++-- .../service/ubs/UBSClientServiceImplTest.java | 7 + 10 files changed, 299 insertions(+), 141 deletions(-) diff --git a/dao/src/main/java/greencity/entity/order/Order.java b/dao/src/main/java/greencity/entity/order/Order.java index bb41cee50..e7f63d073 100644 --- a/dao/src/main/java/greencity/entity/order/Order.java +++ b/dao/src/main/java/greencity/entity/order/Order.java @@ -190,24 +190,23 @@ public class Order { private List orderBags = new ArrayList<>(); /** - * method helps to add OrderBag. + * method helps to delete bag from order. * * @param orderBag {@link OrderBag} * @author Julia Seti */ - public void addOrderBag(OrderBag orderBag) { - this.orderBags.add(orderBag); - orderBag.setOrder(this); + public void removeBagFromOrder(OrderBag orderBag) { + this.orderBags.remove(orderBag); } /** - * method helps to delete OrderBag. + * method helps to set bags for order. * - * @param orderBag {@link OrderBag} + * @param orderBags {@link List} of {@link OrderBag} * @author Julia Seti */ - public void removeOrderBag(OrderBag orderBag) { - this.orderBags.remove(orderBag); - orderBag.setOrder(null); + public void setBagsForOrder(List orderBags) { + orderBags.forEach(it -> it.setOrder(this)); + this.setOrderBags(orderBags); } } diff --git a/dao/src/main/java/greencity/repository/OrderBagRepository.java b/dao/src/main/java/greencity/repository/OrderBagRepository.java index efd798567..dc69dfe24 100644 --- a/dao/src/main/java/greencity/repository/OrderBagRepository.java +++ b/dao/src/main/java/greencity/repository/OrderBagRepository.java @@ -11,34 +11,30 @@ @Repository public interface OrderBagRepository extends JpaRepository { - /** - * method, that returns {@link List} of {@link OrderBag} by bag id for unpaid - * orders. - * - * @param bagId {@link Integer} bag id - * @return {@link List} of {@link OrderBag} - * @author Julia Seti - */ - @Query(value = "SELECT * FROM order_bag_mapping as obm " - + "JOIN orders o on o.id = obm.order_id " - + "WHERE obm.bag_id = :bagId AND o.order_payment_status = 'UNPAID'", nativeQuery = true) - List findAllOrderBagsForUnpaidOrdersByBagId(Integer bagId); - /** * method updates the bag data of OrderBag for all unpaid orders. * - * @param bagId {@link Integer} bag id + * @param bagId {@link Integer} bag id * @param capacity {@link Integer} bag capacity - * @param price {@link Long} bag full price in coins - * @param name {@link String} bag name - * @param nameEng {@link String} bag english name + * @param price {@link Long} bag full price in coins + * @param name {@link String} bag name + * @param nameEng {@link String} bag english name * @author Julia Seti */ @Transactional @Modifying @Query(value = "update order_bag_mapping obm " - + "set capacity = :capacity, price = :price, name = :name, name_eng = :nameEng " - + "from orders o " - + "where o.id = obm.order_id and obm.bag_id = :bagId and o.order_payment_status = 'UNPAID'", nativeQuery = true) + + "set capacity = :capacity, price = :price, name = :name, name_eng = :nameEng " + + "from orders o " + + "where o.id = obm.order_id and obm.bag_id = :bagId and o.order_payment_status = 'UNPAID'", nativeQuery = true) void updateAllByBagIdForUnpaidOrders(Integer bagId, Integer capacity, Long price, String name, String nameEng); + + /** + * method returns all OrderBags by bag id. + * + * @param bagId {@link Integer} bag id + * @return {@link List} of {@link OrderBag} + * @author Julia Seti + */ + List findAllByBagId(Integer bagId); } diff --git a/dao/src/main/java/greencity/repository/OrderRepository.java b/dao/src/main/java/greencity/repository/OrderRepository.java index 3011eb235..a4616a199 100644 --- a/dao/src/main/java/greencity/repository/OrderRepository.java +++ b/dao/src/main/java/greencity/repository/OrderRepository.java @@ -251,4 +251,22 @@ void changeReceivingStationForAllOrders(@Param("receiving_station") Long station void updateOrderStatusToExpected(@Param("actual_status") String actualStatus, @Param("expected_status") String expectedStatus, @Param("currentDate") LocalDate currentDate); + + /** + * method returns all unpaid orders that contain a bag with id. + */ + @Query(nativeQuery = true, + value = "select * from orders o " + + "left join order_bag_mapping obm on o.id = obm.order_id " + + "where obm.bag_id = :bagId and o.order_payment_status = 'UNPAID'") + List findAllUnpaidOrdersByBagId(Integer bagId); + + /** + * method returns all orders that contain a bag with id. + */ + @Query(nativeQuery = true, + value = "select * from orders o " + + "left join order_bag_mapping obm on o.id = obm.order_id " + + "where obm.bag_id = :bagId") + List findAllByBagId(Integer bagId); } diff --git a/service/src/main/java/greencity/mapping/bag/BagForUserDtoMapper.java b/service/src/main/java/greencity/mapping/bag/BagForUserDtoMapper.java index fe66bbe7b..68f4bb7b4 100644 --- a/service/src/main/java/greencity/mapping/bag/BagForUserDtoMapper.java +++ b/service/src/main/java/greencity/mapping/bag/BagForUserDtoMapper.java @@ -2,21 +2,21 @@ import greencity.constant.AppConstant; import greencity.dto.bag.BagForUserDto; -import greencity.entity.order.Bag; +import greencity.entity.order.OrderBag; import org.modelmapper.AbstractConverter; import org.springframework.stereotype.Component; import java.math.BigDecimal; @Component -public class BagForUserDtoMapper extends AbstractConverter { +public class BagForUserDtoMapper extends AbstractConverter { @Override - protected BagForUserDto convert(Bag source) { + protected BagForUserDto convert(OrderBag source) { return BagForUserDto.builder() .service(source.getName()) .serviceEng(source.getNameEng()) .capacity(source.getCapacity()) - .fullPrice(BigDecimal.valueOf(source.getFullPrice()) + .fullPrice(BigDecimal.valueOf(source.getPrice()) .movePointLeft(AppConstant.TWO_DECIMALS_AFTER_POINT_IN_CURRENCY) .doubleValue()) .build(); diff --git a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java index b75b947f3..c1fb93bc8 100644 --- a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java @@ -27,6 +27,8 @@ import greencity.entity.coords.Coordinates; import greencity.entity.order.Bag; import greencity.entity.order.Courier; +import greencity.entity.order.Order; +import greencity.entity.order.OrderBag; import greencity.entity.order.Service; import greencity.entity.order.TariffLocation; import greencity.entity.order.TariffsInfo; @@ -38,6 +40,7 @@ import greencity.enums.CourierLimit; import greencity.enums.CourierStatus; import greencity.enums.LocationStatus; +import greencity.enums.OrderPaymentStatus; import greencity.enums.StationStatus; import greencity.enums.TariffStatus; import greencity.exceptions.BadRequestException; @@ -54,6 +57,7 @@ import greencity.repository.EmployeeRepository; import greencity.repository.LocationRepository; import greencity.repository.OrderBagRepository; +import greencity.repository.OrderRepository; import greencity.repository.ReceivingStationRepository; import greencity.repository.RegionRepository; import greencity.repository.ServiceRepository; @@ -74,6 +78,7 @@ import java.util.Comparator; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -95,6 +100,7 @@ public class SuperAdminServiceImpl implements SuperAdminService { private final TariffLocationRepository tariffsLocationRepository; private final DeactivateChosenEntityRepository deactivateTariffsForChosenParamRepository; private final OrderBagRepository orderBagRepository; + private final OrderRepository orderRepository; private static final String BAD_SIZE_OF_REGIONS_MESSAGE = "Region ids size should be 1 if several params are selected"; @@ -154,6 +160,22 @@ public void deleteTariffService(Integer bagId) { bag.setStatus(BagStatus.DELETED); bagRepository.save(bag); checkDeletedBagLimitAndUpdateTariffsInfo(bag); + orderRepository.findAllByBagId(bagId).forEach(it -> deleteBagFromOrder(it, bagId)); + } + + private void deleteBagFromOrder(Order order, Integer bagId) { + Map amount = UBSClientServiceImpl.getActualBagsAmountForOrder(order.getOrderBags()); + Integer totalBagsAmount = amount.values().stream().reduce(0, Integer::sum); + if (amount.get(bagId).equals(0) || order.getOrderPaymentStatus() == OrderPaymentStatus.UNPAID) { + if (totalBagsAmount.equals(amount.get(bagId))) { + order.setOrderBags(new ArrayList<>()); + orderRepository.delete(order); + return; + } + order.getOrderBags().stream().filter(it -> it.getBag().getId().equals(bagId)).findFirst() + .ifPresent(order::removeBagFromOrder); + orderRepository.save(order); + } } private void checkDeletedBagLimitAndUpdateTariffsInfo(Bag bag) { @@ -179,11 +201,30 @@ public GetTariffServiceDto editTariffService(TariffServiceDto dto, Integer bagId bag.setEditedBy(employee); orderBagRepository.updateAllByBagIdForUnpaidOrders( - bagId, bag.getCapacity(), bag.getFullPrice(), bag.getName(), bag.getNameEng()); + bagId, bag.getCapacity(), bag.getFullPrice(), bag.getName(), bag.getNameEng()); + List orders = orderRepository.findAllUnpaidOrdersByBagId(bagId); + if (!orders.isEmpty()) { + orders.forEach(it -> updateOrderSumToPay(it, bag)); + orderRepository.saveAll(orders); + } return modelMapper.map(bagRepository.save(bag), GetTariffServiceDto.class); } + private void updateOrderSumToPay(Order order, Bag bag) { + Map amount = UBSClientServiceImpl.getActualBagsAmountForOrder(order.getOrderBags()); + Long sumToPayInCoins = order.getOrderBags().stream() + .map(it -> amount.get(it.getBag().getId()) * getActualBagPrice(it, bag)) + .reduce(0L, Long::sum); + order.setSumTotalAmountWithoutDiscounts(sumToPayInCoins); + } + + private Long getActualBagPrice(OrderBag orderBag, Bag bag) { + return bag.getId().equals(orderBag.getBag().getId()) + ? bag.getFullPrice() + : orderBag.getPrice(); + } + private void updateTariffService(TariffServiceDto dto, Bag bag) { bag.setCapacity(dto.getCapacity()); bag.setPrice(convertBillsIntoCoins(dto.getPrice())); diff --git a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java index 91cb0b6b2..e0bf4d15d 100644 --- a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java @@ -57,6 +57,7 @@ import greencity.entity.order.ChangeOfPoints; import greencity.entity.order.Event; import greencity.entity.order.Order; +import greencity.entity.order.OrderBag; import greencity.entity.order.OrderPaymentStatusTranslation; import greencity.entity.order.OrderStatusTranslation; import greencity.entity.order.Payment; @@ -70,6 +71,7 @@ import greencity.entity.user.ubs.UBSuser; import greencity.entity.viber.ViberBot; import greencity.enums.AddressStatus; +import greencity.enums.BagStatus; import greencity.enums.BotType; import greencity.enums.CertificateStatus; import greencity.enums.CourierLimit; @@ -92,6 +94,7 @@ import greencity.repository.EventRepository; import greencity.repository.LocationRepository; import greencity.repository.OrderAddressRepository; +import greencity.repository.OrderBagRepository; import greencity.repository.OrderPaymentStatusTranslationRepository; import greencity.repository.OrderRepository; import greencity.repository.OrderStatusTranslationRepository; @@ -111,7 +114,6 @@ import greencity.util.OrderUtils; import lombok.Data; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.MapUtils; import org.json.JSONObject; import org.modelmapper.ModelMapper; import org.springframework.beans.factory.annotation.Autowired; @@ -146,50 +148,7 @@ import java.util.stream.IntStream; import java.util.stream.LongStream; -import static greencity.constant.ErrorMessage.ACTUAL_ADDRESS_NOT_FOUND; -import static greencity.constant.ErrorMessage.ADDRESS_ALREADY_EXISTS; -import static greencity.constant.ErrorMessage.BAD_ORDER_STATUS_REQUEST; -import static greencity.constant.ErrorMessage.BAG_NOT_FOUND; -import static greencity.constant.ErrorMessage.CANNOT_ACCESS_ORDER_CANCELLATION_REASON; -import static greencity.constant.ErrorMessage.CANNOT_ACCESS_PAYMENT_STATUS; -import static greencity.constant.ErrorMessage.CANNOT_ACCESS_PERSONAL_INFO; -import static greencity.constant.ErrorMessage.CANNOT_DELETE_ADDRESS; -import static greencity.constant.ErrorMessage.CANNOT_DELETE_ALREADY_DELETED_ADDRESS; -import static greencity.constant.ErrorMessage.CANNOT_MAKE_ACTUAL_DELETED_ADDRESS; -import static greencity.constant.ErrorMessage.CERTIFICATE_EXPIRED; -import static greencity.constant.ErrorMessage.CERTIFICATE_IS_NOT_ACTIVATED; -import static greencity.constant.ErrorMessage.CERTIFICATE_IS_USED; -import static greencity.constant.ErrorMessage.CERTIFICATE_NOT_FOUND; -import static greencity.constant.ErrorMessage.CERTIFICATE_NOT_FOUND_BY_CODE; -import static greencity.constant.ErrorMessage.COURIER_IS_NOT_FOUND_BY_ID; -import static greencity.constant.ErrorMessage.EMPLOYEE_DOESNT_EXIST; -import static greencity.constant.ErrorMessage.EVENTS_NOT_FOUND_EXCEPTION; -import static greencity.constant.ErrorMessage.LOCATION_DOESNT_FOUND_BY_ID; -import static greencity.constant.ErrorMessage.LOCATION_IS_DEACTIVATED_FOR_TARIFF; -import static greencity.constant.ErrorMessage.NOT_ENOUGH_BAGS_EXCEPTION; -import static greencity.constant.ErrorMessage.NOT_FOUND_ADDRESS_ID_FOR_CURRENT_USER; -import static greencity.constant.ErrorMessage.NUMBER_OF_ADDRESSES_EXCEEDED; -import static greencity.constant.ErrorMessage.ORDER_ALREADY_PAID; -import static greencity.constant.ErrorMessage.ORDER_WITH_CURRENT_ID_DOES_NOT_EXIST; -import static greencity.constant.ErrorMessage.PAYMENT_NOT_FOUND; -import static greencity.constant.ErrorMessage.PAYMENT_VALIDATION_ERROR; -import static greencity.constant.ErrorMessage.PRICE_OF_ORDER_GREATER_THAN_LIMIT; -import static greencity.constant.ErrorMessage.PRICE_OF_ORDER_LOWER_THAN_LIMIT; -import static greencity.constant.ErrorMessage.RECIPIENT_WITH_CURRENT_ID_DOES_NOT_EXIST; -import static greencity.constant.ErrorMessage.SOME_CERTIFICATES_ARE_INVALID; -import static greencity.constant.ErrorMessage.TARIFF_FOR_COURIER_AND_LOCATION_NOT_EXIST; -import static greencity.constant.ErrorMessage.TARIFF_FOR_LOCATION_NOT_EXIST; -import static greencity.constant.ErrorMessage.TARIFF_FOR_ORDER_NOT_EXIST; -import static greencity.constant.ErrorMessage.TARIFF_NOT_FOUND; -import static greencity.constant.ErrorMessage.TARIFF_OR_LOCATION_IS_DEACTIVATED; -import static greencity.constant.ErrorMessage.THE_SET_OF_UBS_USER_DATA_DOES_NOT_EXIST; -import static greencity.constant.ErrorMessage.TOO_MANY_CERTIFICATES; -import static greencity.constant.ErrorMessage.TOO_MUCH_POINTS_FOR_ORDER; -import static greencity.constant.ErrorMessage.TO_MUCH_BAG_EXCEPTION; -import static greencity.constant.ErrorMessage.USER_DONT_HAVE_ENOUGH_POINTS; -import static greencity.constant.ErrorMessage.USER_WITH_CURRENT_ID_DOES_NOT_EXIST; -import static greencity.constant.ErrorMessage.USER_WITH_CURRENT_UUID_DOES_NOT_EXIST; - +import static greencity.constant.ErrorMessage.*; import static java.util.Objects.nonNull; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; @@ -203,6 +162,7 @@ public class UBSClientServiceImpl implements UBSClientService { private final UserRepository userRepository; private final BagRepository bagRepository; + private final OrderBagRepository orderBagRepository; private final UBSuserRepository ubsUserRepository; private final ModelMapper modelMapper; private final CertificateRepository certificateRepository; @@ -415,14 +375,14 @@ private void checkSumIfCourierLimitBySumOfOrder(TariffsInfo tariffsInfo, Long su public FondyOrderResponse saveFullOrderToDB(OrderResponseDto dto, String uuid, Long orderId) { final User currentUser = userRepository.findByUuid(uuid); TariffsInfo tariffsInfo = tryToFindTariffsInfoByBagIds(getBagIds(dto.getBags()), dto.getLocationId()); - Map amountOfBagsOrderedMap = new HashMap<>(); + List bagsOrdered = new ArrayList<>(); if (!dto.isShouldBePaid()) { dto.setCertificates(Collections.emptySet()); dto.setPointsToUse(0); } - long sumToPayWithoutDiscountInCoins = formBagsToBeSavedAndCalculateOrderSum(amountOfBagsOrderedMap, + long sumToPayWithoutDiscountInCoins = formBagsToBeSavedAndCalculateOrderSum(bagsOrdered, dto.getBags(), tariffsInfo); checkIfUserHaveEnoughPoints(currentUser.getCurrentPoints(), dto.getPointsToUse()); long sumToPayInCoins = reduceOrderSumDueToUsedPoints(sumToPayWithoutDiscountInCoins, dto.getPointsToUse()); @@ -435,7 +395,7 @@ public FondyOrderResponse saveFullOrderToDB(OrderResponseDto dto, String uuid, L UBSuser userData = formUserDataToBeSaved(dto.getPersonalData(), dto.getAddressId(), dto.getLocationId(), currentUser); - getOrder(dto, currentUser, amountOfBagsOrderedMap, sumToPayInCoins, order, orderCertificates, userData); + getOrder(dto, currentUser, bagsOrdered, sumToPayInCoins, order, orderCertificates, userData); eventService.save(OrderHistory.ORDER_FORMED, OrderHistory.CLIENT, order); if (sumToPayInCoins <= 0 || !dto.isShouldBePaid()) { @@ -453,8 +413,8 @@ private List getBagIds(List dto) { .collect(Collectors.toList()); } - private Bag tryToGetBagById(Integer id) { - return bagRepository.findById(id) + private Bag tryToGetActiveBagById(Integer id) { + return bagRepository.findActiveBagById(id) .orElseThrow(() -> new NotFoundException(BAG_NOT_FOUND + id)); } @@ -881,31 +841,33 @@ private AddressInfoDto addressInfoDtoBuilder(Order order) { } private List bagForUserDtosBuilder(Order order) { - Map actualBagAmounts = getActualBagAmountsForOrder(order); - List bagsForOrder = bagRepository.findBagsByOrderId(order.getId()); + List bagsForOrder = order.getOrderBags(); + Map actualBagsAmount = getActualBagsAmountForOrder(bagsForOrder); return bagsForOrder.stream() - .filter(bag -> actualBagAmounts.containsKey(bag.getId())) - .map(bag -> buildBagForUserDto(bag, actualBagAmounts.get(bag.getId()))) + .map(orderBag -> buildBagForUserDto(orderBag, actualBagsAmount.get(orderBag.getBag().getId()))) .collect(toList()); } - private Map getActualBagAmountsForOrder(Order order) { - if (MapUtils.isNotEmpty(order.getExportedQuantity())) { - return order.getExportedQuantity(); + static Map getActualBagsAmountForOrder(List bagsForOrder) { + if (bagsForOrder.stream().allMatch(it -> it.getExportedQuantity() != null)) { + return bagsForOrder.stream() + .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getExportedQuantity)); } - if (MapUtils.isNotEmpty(order.getConfirmedQuantity())) { - return order.getConfirmedQuantity(); + if (bagsForOrder.stream().allMatch(it -> it.getConfirmedQuantity() != null)) { + return bagsForOrder.stream() + .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getConfirmedQuantity)); } - if (MapUtils.isNotEmpty(order.getAmountOfBagsOrdered())) { - return order.getAmountOfBagsOrdered(); + if (bagsForOrder.stream().allMatch(it -> it.getAmount() != null)) { + return bagsForOrder.stream() + .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getAmount)); } return new HashMap<>(); } - private BagForUserDto buildBagForUserDto(Bag bag, int count) { - BagForUserDto bagDto = modelMapper.map(bag, BagForUserDto.class); + private BagForUserDto buildBagForUserDto(OrderBag orderBag, int count) { + BagForUserDto bagDto = modelMapper.map(orderBag, BagForUserDto.class); bagDto.setCount(count); - bagDto.setTotalPrice(convertCoinsIntoBills(count * bag.getFullPrice())); + bagDto.setTotalPrice(convertCoinsIntoBills(count * orderBag.getPrice())); return bagDto; } @@ -1034,15 +996,15 @@ private UBSuser updateRecipientDataInOrder(UBSuser ubSuser, UbsCustomersDtoUpdat } private Order formAndSaveOrder(Order order, Set orderCertificates, - Map amountOfBagsOrderedMap, UBSuser userData, + List bagsOrdered, UBSuser userData, User currentUser, long sumToPayInCoins) { order.setOrderStatus(OrderStatus.FORMED); order.setCertificates(orderCertificates); - order.setAmountOfBagsOrdered(amountOfBagsOrderedMap); + order.setBagsForOrder(bagsOrdered); order.setUbsUser(userData); order.setUser(currentUser); order.setSumTotalAmountWithoutDiscounts( - formBagsToBeSavedAndCalculateOrderSumClient(amountOfBagsOrderedMap)); + calculateOrderSumWithoutDiscounts(bagsOrdered)); setOrderPaymentStatus(order, sumToPayInCoins); Payment payment = Payment.builder() @@ -1198,35 +1160,47 @@ private void checkAmountOfBagsIfCourierLimitByAmountOfBag(TariffsInfo courierLoc } } - private long formBagsToBeSavedAndCalculateOrderSumClient( - Map getOrderBagsAndQuantity) { - long sumToPayInCoins = 0L; - - for (Map.Entry temp : getOrderBagsAndQuantity.entrySet()) { - Integer amount = getOrderBagsAndQuantity.get(temp.getKey()); - Bag bag = bagRepository.findById(temp.getKey()) - .orElseThrow(() -> new NotFoundException(BAG_NOT_FOUND + temp.getKey())); - sumToPayInCoins += bag.getFullPrice() * amount; - } - return sumToPayInCoins; + private long calculateOrderSumWithoutDiscounts(List getOrderBagsAndQuantity) { + return getOrderBagsAndQuantity.stream() + .map(it -> it.getPrice() * it.getAmount()) + .reduce(0L, Long::sum); } private long formBagsToBeSavedAndCalculateOrderSum( - Map map, List bags, TariffsInfo tariffsInfo) { + List orderBagList, List bags, TariffsInfo tariffsInfo) { long sumToPayInCoins = 0L; for (BagDto temp : bags) { - Bag bag = tryToGetBagById(temp.getId()); + Bag bag = tryToGetActiveBagById(temp.getId()); if (bag.getLimitIncluded().booleanValue()) { checkAmountOfBagsIfCourierLimitByAmountOfBag(tariffsInfo, temp.getAmount()); checkSumIfCourierLimitBySumOfOrder(tariffsInfo, bag.getFullPrice() * temp.getAmount()); } sumToPayInCoins += bag.getFullPrice() * temp.getAmount(); - map.put(temp.getId(), temp.getAmount()); + OrderBag orderBag = createOrderBag(bag); + orderBag.setAmount(temp.getAmount()); + orderBagList.add(orderBag); } + List orderedBagsIds = bags.stream().map(BagDto::getId).collect(toList()); + List notOrderedBags = tariffsInfo.getBags().stream() + .filter(it -> it.getStatus() == BagStatus.ACTIVE && !orderedBagsIds.contains(it.getId())) + .map(this::createOrderBag).collect(toList()); + notOrderedBags.forEach(it -> it.setAmount(0)); + orderBagList.addAll(notOrderedBags); + return sumToPayInCoins; } + private OrderBag createOrderBag(Bag bag) { + return OrderBag.builder() + .bag(bag) + .capacity(bag.getCapacity()) + .price(bag.getFullPrice()) + .name(bag.getName()) + .nameEng(bag.getNameEng()) + .build(); + } + private void validateCertificate(Certificate certificate) { if (certificate.getCertificateStatus() == CertificateStatus.NEW) { throw new CertificateIsNotActivated(CERTIFICATE_IS_NOT_ACTIVATED + certificate.getCode()); @@ -1380,9 +1354,9 @@ private long reduceOrderSumDueToUsedPoints(long sumToPayInCoins, int pointsToUse return sumToPayInCoins; } - private void getOrder(OrderResponseDto dto, User currentUser, Map amountOfBagsOrderedMap, + private void getOrder(OrderResponseDto dto, User currentUser, List amountOfBagsOrdered, long sumToPayInCoins, Order order, Set orderCertificates, UBSuser userData) { - formAndSaveOrder(order, orderCertificates, amountOfBagsOrderedMap, userData, currentUser, sumToPayInCoins); + formAndSaveOrder(order, orderCertificates, amountOfBagsOrdered, userData, currentUser, sumToPayInCoins); formAndSaveUser(currentUser, dto.getPointsToUse(), order); } @@ -1427,6 +1401,7 @@ public void deleteOrder(String uuid, Long id) { if (order == null) { throw new NotFoundException(ORDER_WITH_CURRENT_ID_DOES_NOT_EXIST); } + order.setOrderBags(new ArrayList<>()); orderRepository.delete(order); } diff --git a/service/src/test/java/greencity/ModelUtils.java b/service/src/test/java/greencity/ModelUtils.java index fd102a2d3..84db71798 100644 --- a/service/src/test/java/greencity/ModelUtils.java +++ b/service/src/test/java/greencity/ModelUtils.java @@ -176,6 +176,7 @@ public class ModelUtils { public static final OrderDetailStatusDto ORDER_DETAIL_STATUS_DTO = createOrderDetailStatusDto(); public static final List TEST_BAG_MAPPING_DTO_LIST = createBagMappingDtoList(); public static final Bag TEST_BAG = createBag(); + public static final OrderBag TEST_ORDER_BAG = createOrderBag(); public static final BagForUserDto TEST_BAG_FOR_USER_DTO = createBagForUserDto(); public static final BagInfoDto TEST_BAG_INFO_DTO = createBagInfoDto(); public static final List TEST_BAG_LIST = singletonList(TEST_BAG); @@ -2152,6 +2153,18 @@ private static Bag createBag() { .build(); } + private static OrderBag createOrderBag() { + return OrderBag.builder() + .id(1L) + .name("Name") + .nameEng("NameEng") + .capacity(20) + .price(100_00L) + .order(createOrder()) + .bag(createBag()) + .build(); + } + private static BagForUserDto createBagForUserDto() { return BagForUserDto.builder() .service("Name") @@ -2526,17 +2539,6 @@ public static GetTariffServiceDto getGetTariffServiceDto() { .build(); } - public static OrderBag getOrderBag() { - return OrderBag.builder() - .id(1L) - .amount(1) - .price(150_00L) - .capacity(20) - .bag(getBag()) - .order(getOrder()) - .build(); - } - public static Optional getOptionalBag() { return Optional.of(Bag.builder() .id(1) @@ -2569,6 +2571,48 @@ public static Bag getBag() { .build(); } + public static OrderBag getOrderBag() { + return OrderBag.builder() + .id(1L) + .capacity(120) + .price(120_00L) + .name("name") + .nameEng("name eng") + .amount(1) + .bag(getBag()) + .order(getOrder()) + .build(); + } + + public static OrderBag getOrderBagWithConfirmedAmount() { + return OrderBag.builder() + .id(1L) + .capacity(120) + .price(120_00L) + .name("name") + .nameEng("name eng") + .amount(1) + .confirmedQuantity(2) + .bag(getBag()) + .order(getOrder()) + .build(); + } + + public static OrderBag getOrderBagWithExportedAmount() { + return OrderBag.builder() + .id(1L) + .capacity(120) + .price(120_00L) + .name("name") + .nameEng("name eng") + .amount(1) + .confirmedQuantity(2) + .exportedQuantity(2) + .bag(getBag()) + .order(getOrder()) + .build(); + } + public static Bag getBagDeleted() { return Bag.builder() .id(1) @@ -2797,7 +2841,6 @@ public static Service getService() { .build(); } - public static Service getNewService() { Employee employee = ModelUtils.getEmployee(); return Service.builder() diff --git a/service/src/test/java/greencity/mapping/bag/BagForUserDtoMapperTest.java b/service/src/test/java/greencity/mapping/bag/BagForUserDtoMapperTest.java index 1f9fcbcdd..033425d77 100644 --- a/service/src/test/java/greencity/mapping/bag/BagForUserDtoMapperTest.java +++ b/service/src/test/java/greencity/mapping/bag/BagForUserDtoMapperTest.java @@ -2,7 +2,7 @@ import greencity.ModelUtils; import greencity.dto.bag.BagForUserDto; -import greencity.entity.order.Bag; +import greencity.entity.order.OrderBag; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -18,8 +18,8 @@ class BagForUserDtoMapperTest { @Test void convert() { BagForUserDto expected = ModelUtils.TEST_BAG_FOR_USER_DTO; - Bag bag = ModelUtils.TEST_BAG; - BagForUserDto actual = bagForUserDtoMapper.convert(bag); + OrderBag orderBag = ModelUtils.TEST_ORDER_BAG; + BagForUserDto actual = bagForUserDtoMapper.convert(orderBag); assertEquals(expected.getService(), actual.getService()); assertEquals(expected.getServiceEng(), actual.getServiceEng()); diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index 49d7aa884..30de2ece2 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -24,6 +24,7 @@ import greencity.dto.tariff.SetTariffLimitsDto; import greencity.entity.order.Bag; import greencity.entity.order.Courier; +import greencity.entity.order.Order; import greencity.entity.order.Service; import greencity.entity.order.TariffLocation; import greencity.entity.order.TariffsInfo; @@ -49,6 +50,7 @@ import greencity.repository.EmployeeRepository; import greencity.repository.LocationRepository; import greencity.repository.OrderBagRepository; +import greencity.repository.OrderRepository; import greencity.repository.ReceivingStationRepository; import greencity.repository.RegionRepository; import greencity.repository.ServiceRepository; @@ -134,6 +136,8 @@ class SuperAdminServiceImplTest { private DeactivateChosenEntityRepository deactivateTariffsForChosenParamRepository; @Mock private OrderBagRepository orderBagRepository; + @Mock + private OrderRepository orderRepository; @AfterEach void afterEach() { @@ -150,7 +154,8 @@ void afterEach() { tariffsInfoRepository, tariffsLocationRepository, deactivateTariffsForChosenParamRepository, - orderBagRepository); + orderBagRepository, + orderRepository); } @Test @@ -318,20 +323,90 @@ void deleteTariffServiceThrowBagNotFoundException() { } @Test - void editTariffService() { + void editTariffServiceWithUnpaidOrder() { + Bag bag = ModelUtils.getBag(); + Bag editedBag = ModelUtils.getEditedBag(); + Employee employee = ModelUtils.getEmployee(); + TariffServiceDto dto = ModelUtils.getTariffServiceDto(); + GetTariffServiceDto editedDto = ModelUtils.getGetTariffServiceDto(); + Order order = ModelUtils.getOrder(); + String uuid = UUID.randomUUID().toString(); + order.setOrderBags(List.of(ModelUtils.getOrderBag())); + + when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.save(editedBag)).thenReturn(editedBag); + when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); + doNothing().when(orderBagRepository) + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + when(orderRepository.findAllUnpaidOrdersByBagId(1)).thenReturn(List.of(order)); + when(orderRepository.saveAll(List.of(order))).thenReturn(List.of(order)); + + GetTariffServiceDto actual = superAdminService.editTariffService(dto, 1, uuid); + + assertEquals(editedDto, actual); + verify(employeeRepository).findByUuid(uuid); + verify(bagRepository).findActiveBagById(1); + verify(bagRepository).save(editedBag); + verify(modelMapper).map(editedBag, GetTariffServiceDto.class); + verify(orderBagRepository) + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + verify(orderRepository).findAllUnpaidOrdersByBagId(1); + verify(orderRepository).saveAll(anyList()); + } + + @Test + void editTariffServiceWithUnpaidOrderAndBagConfirmedAmount() { + Bag bag = ModelUtils.getBag(); + Bag editedBag = ModelUtils.getEditedBag(); + Employee employee = ModelUtils.getEmployee(); + TariffServiceDto dto = ModelUtils.getTariffServiceDto(); + GetTariffServiceDto editedDto = ModelUtils.getGetTariffServiceDto(); + Order order = ModelUtils.getOrder(); + String uuid = UUID.randomUUID().toString(); + order.setOrderBags(List.of(ModelUtils.getOrderBagWithConfirmedAmount())); + + when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.save(editedBag)).thenReturn(editedBag); + when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); + doNothing().when(orderBagRepository) + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + when(orderRepository.findAllUnpaidOrdersByBagId(1)).thenReturn(List.of(order)); + when(orderRepository.saveAll(List.of(order))).thenReturn(List.of(order)); + + GetTariffServiceDto actual = superAdminService.editTariffService(dto, 1, uuid); + + assertEquals(editedDto, actual); + verify(employeeRepository).findByUuid(uuid); + verify(bagRepository).findActiveBagById(1); + verify(bagRepository).save(editedBag); + verify(modelMapper).map(editedBag, GetTariffServiceDto.class); + verify(orderBagRepository) + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + verify(orderRepository).findAllUnpaidOrdersByBagId(1); + verify(orderRepository).saveAll(anyList()); + } + + @Test + void editTariffServiceWithUnpaidOrderAndBagExportedAmount() { Bag bag = ModelUtils.getBag(); Bag editedBag = ModelUtils.getEditedBag(); Employee employee = ModelUtils.getEmployee(); TariffServiceDto dto = ModelUtils.getTariffServiceDto(); GetTariffServiceDto editedDto = ModelUtils.getGetTariffServiceDto(); + Order order = ModelUtils.getOrder(); String uuid = UUID.randomUUID().toString(); + order.setOrderBags(List.of(ModelUtils.getOrderBagWithExportedAmount())); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); when(bagRepository.save(editedBag)).thenReturn(editedBag); when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); doNothing().when(orderBagRepository) - .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + when(orderRepository.findAllUnpaidOrdersByBagId(1)).thenReturn(List.of(order)); + when(orderRepository.saveAll(List.of(order))).thenReturn(List.of(order)); GetTariffServiceDto actual = superAdminService.editTariffService(dto, 1, uuid); @@ -341,11 +416,13 @@ void editTariffService() { verify(bagRepository).save(editedBag); verify(modelMapper).map(editedBag, GetTariffServiceDto.class); verify(orderBagRepository) - .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + verify(orderRepository).findAllUnpaidOrdersByBagId(1); + verify(orderRepository).saveAll(anyList()); } @Test - void editTariffServiceIfOrderBagsListIsEmpty() { + void editTariffServiceWithoutUnpaidOrder() { Bag bag = ModelUtils.getBag(); Bag editedBag = ModelUtils.getEditedBag(); Employee employee = ModelUtils.getEmployee(); @@ -358,7 +435,8 @@ void editTariffServiceIfOrderBagsListIsEmpty() { when(bagRepository.save(editedBag)).thenReturn(editedBag); when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); doNothing().when(orderBagRepository) - .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + when(orderRepository.findAllUnpaidOrdersByBagId(1)).thenReturn(Collections.emptyList()); GetTariffServiceDto actual = superAdminService.editTariffService(dto, 1, uuid); @@ -368,8 +446,9 @@ void editTariffServiceIfOrderBagsListIsEmpty() { verify(bagRepository).save(editedBag); verify(modelMapper).map(editedBag, GetTariffServiceDto.class); verify(orderBagRepository) - .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); - verify(orderBagRepository, never()).saveAll(anyList()); + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + verify(orderRepository).findAllUnpaidOrdersByBagId(1); + verify(orderRepository, never()).saveAll(anyList()); } @Test @@ -431,7 +510,7 @@ void deleteServiceThrowNotFoundException() { when(serviceRepository.findById(service.getId())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.deleteService(1L)); + () -> superAdminService.deleteService(1L)); verify(serviceRepository).findById(1L); verify(serviceRepository, never()).delete(service); diff --git a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java index b50d24001..071a5edb5 100644 --- a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java @@ -75,6 +75,7 @@ import greencity.repository.EventRepository; import greencity.repository.LocationRepository; import greencity.repository.OrderAddressRepository; +import greencity.repository.OrderBagRepository; import greencity.repository.OrderPaymentStatusTranslationRepository; import greencity.repository.OrderRepository; import greencity.repository.OrderStatusTranslationRepository; @@ -146,6 +147,7 @@ import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyList; import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.lenient; @@ -236,6 +238,8 @@ class UBSClientServiceImplTest { private ViberBotRepository viberBotRepository; @Mock private UBSManagementService ubsManagementService; + @Mock + private OrderBagRepository orderBagRepository; @Test @Transactional @@ -2394,12 +2398,15 @@ void testGelAllEventsFromOrderByOrderIdWithThrowingEventsNotFoundException() { @Test void deleteOrder() { Order order = getOrder(); + order.setOrderBags(Collections.emptyList()); when(ordersForUserRepository.getAllByUserUuidAndId(order.getUser().getUuid(), order.getId())) .thenReturn(order); + doNothing().when(orderBagRepository).deleteAll(anyList()); ubsService.deleteOrder(order.getUser().getUuid(), 1L); verify(orderRepository).delete(order); + verify(orderBagRepository).deleteAll(anyList()); } @Test From 059310167f5771efd000527a24a040adf47a016f Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Sun, 23 Jul 2023 14:31:30 +0300 Subject: [PATCH 09/73] removed bagstatus --- .../main/java/greencity/entity/order/Bag.java | 4 ---- .../main/java/greencity/enums/BagStatus.java | 6 ------ .../db/changelog/db.changelog-master.xml | 3 +-- ...ch-add-column-status-to-bag-table-Seti.xml | 12 ----------- ...date-order-bag-mapping-table-Spodaryk.xml} | 14 ++++++------- .../service/ubs/SuperAdminServiceImpl.java | 3 --- .../service/ubs/UBSClientServiceImpl.java | 3 +-- .../src/test/java/greencity/ModelUtils.java | 21 ------------------- 8 files changed, 9 insertions(+), 57 deletions(-) delete mode 100644 dao/src/main/java/greencity/enums/BagStatus.java delete mode 100644 dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-table-Seti.xml rename dao/src/main/resources/db/changelog/logs/{ch-update-order-bag-mapping-table-Seti.xml => ch-update-order-bag-mapping-table-Spodaryk.xml} (83%) diff --git a/dao/src/main/java/greencity/entity/order/Bag.java b/dao/src/main/java/greencity/entity/order/Bag.java index ab2af0f6b..3ab7d2e31 100644 --- a/dao/src/main/java/greencity/entity/order/Bag.java +++ b/dao/src/main/java/greencity/entity/order/Bag.java @@ -1,7 +1,6 @@ package greencity.entity.order; import greencity.entity.user.employee.Employee; -import greencity.enums.BagStatus; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.EqualsAndHashCode; @@ -91,7 +90,4 @@ public class Bag { @JoinColumn(nullable = false) private TariffsInfo tariffsInfo; - @Column(nullable = false) - @Enumerated(EnumType.STRING) - private BagStatus status; } diff --git a/dao/src/main/java/greencity/enums/BagStatus.java b/dao/src/main/java/greencity/enums/BagStatus.java deleted file mode 100644 index f0f3fe1c2..000000000 --- a/dao/src/main/java/greencity/enums/BagStatus.java +++ /dev/null @@ -1,6 +0,0 @@ -package greencity.enums; - -public enum BagStatus { - ACTIVE, - DELETED -} diff --git a/dao/src/main/resources/db/changelog/db.changelog-master.xml b/dao/src/main/resources/db/changelog/db.changelog-master.xml index 6eca80344..6f016ebc8 100644 --- a/dao/src/main/resources/db/changelog/db.changelog-master.xml +++ b/dao/src/main/resources/db/changelog/db.changelog-master.xml @@ -207,8 +207,7 @@ - - + diff --git a/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-table-Seti.xml b/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-table-Seti.xml deleted file mode 100644 index a24ab6a62..000000000 --- a/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-table-Seti.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Seti.xml b/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml similarity index 83% rename from dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Seti.xml rename to dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml index 91e8fd1bc..eba30c3cb 100644 --- a/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Seti.xml +++ b/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml @@ -2,7 +2,7 @@ - + @@ -28,14 +28,14 @@ referencedColumnNames="id"/> - + update order_bag_mapping set - capacity=bag.capacity, - price=bag.full_price, - name=bag.name, - name_eng=bag.name_eng + capacity=bag.capacity, + price=bag.full_price, + name=bag.name, + name_eng=bag.name_eng from bag - where bag_id=bag.id + where bag_id=bag.id diff --git a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java index 13c11bb22..9ca3ac7bc 100644 --- a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java @@ -36,7 +36,6 @@ import greencity.entity.user.Region; import greencity.entity.user.employee.Employee; import greencity.entity.user.employee.ReceivingStation; -import greencity.enums.BagStatus; import greencity.enums.CourierLimit; import greencity.enums.CourierStatus; import greencity.enums.LocationStatus; @@ -135,7 +134,6 @@ private Bag createBag(long tariffId, TariffServiceDto dto, String employeeUuid) TariffsInfo tariffsInfo = tryToFindTariffById(tariffId); Employee employee = tryToFindEmployeeByUuid(employeeUuid); Bag bag = modelMapper.map(dto, Bag.class); - bag.setStatus(BagStatus.ACTIVE); bag.setTariffsInfo(tariffsInfo); bag.setCreatedBy(employee); return bag; @@ -157,7 +155,6 @@ public List getTariffService(long tariffId) { @Transactional public void deleteTariffService(Integer bagId) { Bag bag = tryToFindBagById(bagId); - bag.setStatus(BagStatus.DELETED); bagRepository.save(bag); checkDeletedBagLimitAndUpdateTariffsInfo(bag); orderRepository.findAllByBagId(bagId).forEach(it -> deleteBagFromOrder(it, bagId)); diff --git a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java index ff245185d..cbd112c5b 100644 --- a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java @@ -71,7 +71,6 @@ import greencity.entity.user.ubs.UBSuser; import greencity.entity.viber.ViberBot; import greencity.enums.AddressStatus; -import greencity.enums.BagStatus; import greencity.enums.BotType; import greencity.enums.CertificateStatus; import greencity.enums.CourierLimit; @@ -1226,7 +1225,7 @@ private long formBagsToBeSavedAndCalculateOrderSum( } List orderedBagsIds = bags.stream().map(BagDto::getId).collect(toList()); List notOrderedBags = tariffsInfo.getBags().stream() - .filter(it -> it.getStatus() == BagStatus.ACTIVE && !orderedBagsIds.contains(it.getId())) + .filter(it -> !orderedBagsIds.contains(it.getId())) .map(this::createOrderBag).collect(toList()); notOrderedBags.forEach(it -> it.setAmount(0)); orderBagList.addAll(notOrderedBags); diff --git a/service/src/test/java/greencity/ModelUtils.java b/service/src/test/java/greencity/ModelUtils.java index f4cefd9a7..e65b5085d 100644 --- a/service/src/test/java/greencity/ModelUtils.java +++ b/service/src/test/java/greencity/ModelUtils.java @@ -119,7 +119,6 @@ import greencity.entity.user.ubs.UBSuser; import greencity.entity.viber.ViberBot; import greencity.enums.AddressStatus; -import greencity.enums.BagStatus; import greencity.enums.CancellationReason; import greencity.enums.CertificateStatus; import greencity.enums.CourierLimit; @@ -2583,7 +2582,6 @@ public static Bag getBag() { .createdBy(getEmployee()) .editedBy(getEmployee()) .limitIncluded(true) - .status(BagStatus.ACTIVE) .tariffsInfo(getTariffInfo()) .build(); } @@ -2643,7 +2641,6 @@ public static Bag getBagDeleted() { .description("Description") .descriptionEng("DescriptionEng") .limitIncluded(true) - .status(BagStatus.DELETED) .tariffsInfo(getTariffInfo()) .build(); } @@ -2665,22 +2662,6 @@ public static Bag getBagForOrder() { .build(); } - public static Bag getBagForOrder() { - return Bag.builder() - .id(3) - .capacity(120) - .commission(50_00L) - .price(350_00L) - .fullPrice(400_00L) - .createdAt(LocalDate.now()) - .createdBy(getEmployee()) - .editedBy(getEmployee()) - .description("Description") - .descriptionEng("DescriptionEng") - .limitIncluded(true) - .tariffsInfo(getTariffInfo()) - .build(); - } public static TariffServiceDto getTariffServiceDto() { return TariffServiceDto.builder() @@ -2707,7 +2688,6 @@ public static Bag getEditedBag() { .editedBy(getEmployee()) .editedAt(LocalDate.now()) .limitIncluded(true) - .status(BagStatus.ACTIVE) .tariffsInfo(getTariffInfo()) .build(); @@ -2822,7 +2802,6 @@ public static Bag getNewBag() { .descriptionEng("DescriptionEng") .name("name") .nameEng("nameEng") - .status(BagStatus.ACTIVE) .build(); } From 5fddf16500cc9d1c6927533779c1c242709a73d9 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Sun, 23 Jul 2023 15:12:21 +0300 Subject: [PATCH 10/73] Returned all tests to dev --- .../ubs/SuperAdminServiceImplTest.java | 915 ++++++++---------- .../service/ubs/UBSClientServiceImplTest.java | 557 +++++------ .../ubs/UBSManagementServiceImplTest.java | 589 ++++++----- 3 files changed, 960 insertions(+), 1101 deletions(-) diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index 9ac4fbaf1..6be3ae405 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -23,7 +23,6 @@ import greencity.dto.tariff.SetTariffLimitsDto; import greencity.entity.order.Bag; import greencity.entity.order.Courier; -import greencity.entity.order.Order; import greencity.entity.order.Service; import greencity.entity.order.TariffLocation; import greencity.entity.order.TariffsInfo; @@ -48,8 +47,6 @@ import greencity.repository.DeactivateChosenEntityRepository; import greencity.repository.EmployeeRepository; import greencity.repository.LocationRepository; -import greencity.repository.OrderBagRepository; -import greencity.repository.OrderRepository; import greencity.repository.ReceivingStationRepository; import greencity.repository.RegionRepository; import greencity.repository.ServiceRepository; @@ -134,28 +131,22 @@ class SuperAdminServiceImplTest { private TariffLocationRepository tariffsLocationRepository; @Mock private DeactivateChosenEntityRepository deactivateTariffsForChosenParamRepository; - @Mock - private OrderBagRepository orderBagRepository; - @Mock - private OrderRepository orderRepository; @AfterEach void afterEach() { verifyNoMoreInteractions( - userRepository, - employeeRepository, - bagRepository, - locationRepository, - modelMapper, - serviceRepository, - courierRepository, - regionRepository, - receivingStationRepository, - tariffsInfoRepository, - tariffsLocationRepository, - deactivateTariffsForChosenParamRepository, - orderBagRepository, - orderRepository); + userRepository, + employeeRepository, + bagRepository, + locationRepository, + modelMapper, + serviceRepository, + courierRepository, + regionRepository, + receivingStationRepository, + tariffsInfoRepository, + tariffsLocationRepository, + deactivateTariffsForChosenParamRepository); } @Test @@ -191,7 +182,7 @@ void addTariffServiceIfEmployeeNotFoundExceptionTest() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.addTariffService(1L, dto, uuid)); + () -> superAdminService.addTariffService(1L, dto, uuid)); verify(tariffsInfoRepository).findById(1L); verify(employeeRepository).findByUuid(uuid); @@ -206,7 +197,7 @@ void addTariffServiceIfTariffNotFoundExceptionTest() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.addTariffService(1L, dto, uuid)); + () -> superAdminService.addTariffService(1L, dto, uuid)); verify(tariffsInfoRepository).findById(1L); verify(bagRepository, never()).save(any(Bag.class)); @@ -214,241 +205,139 @@ void addTariffServiceIfTariffNotFoundExceptionTest() { @Test void getTariffServiceTest() { - List bags = List.of(ModelUtils.getNewBag()); + List bags = List.of(ModelUtils.getOptionalBag().get()); GetTariffServiceDto dto = ModelUtils.getGetTariffServiceDto(); when(tariffsInfoRepository.existsById(1L)).thenReturn(true); - when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(bags); + when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(bags); when(modelMapper.map(bags.get(0), GetTariffServiceDto.class)).thenReturn(dto); superAdminService.getTariffService(1); verify(tariffsInfoRepository).existsById(1L); - verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); + verify(bagRepository).findBagsByTariffsInfoId(1L); verify(modelMapper).map(bags.get(0), GetTariffServiceDto.class); } - @Test - void getTariffServiceIfThereAreNoBags() { - List bags = Collections.emptyList(); - - when(tariffsInfoRepository.existsById(1L)).thenReturn(true); - when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(bags); - - List dtos = superAdminService.getTariffService(1); - - assertEquals(Collections.emptyList(), dtos); - verify(tariffsInfoRepository).existsById(1L); - verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); - } - @Test void getTariffServiceIfTariffNotFoundException() { when(tariffsInfoRepository.existsById(1L)).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.getTariffService(1)); + () -> superAdminService.getTariffService(1)); verify(tariffsInfoRepository).existsById(1L); - verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(1L); + verify(bagRepository, never()).findBagsByTariffsInfoId(1L); } @Test void deleteTariffServiceWhenTariffBagsWithLimits() { Bag bag = ModelUtils.getBag(); - Bag bagDeleted = ModelUtils.getBagDeleted(); TariffsInfo tariffsInfo = ModelUtils.getTariffInfo(); + bag.setTariffsInfo(tariffsInfo); - when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); - when(bagRepository.save(bag)).thenReturn(bagDeleted); - when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(List.of(bag)); - + when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + doNothing().when(bagRepository).delete(bag); + when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(List.of(bag)); superAdminService.deleteTariffService(1); - - verify(bagRepository).findActiveBagById(1); - verify(bagRepository).save(bag); - verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); + assertEquals(TariffStatus.ACTIVE, tariffsInfo.getTariffStatus()); + verify(bagRepository).findById(1); + verify(bagRepository).delete(bag); + verify(bagRepository).findBagsByTariffsInfoId(1L); verify(tariffsInfoRepository, never()).save(tariffsInfo); } @Test void deleteTariffServiceWhenTariffBagsListIsEmpty() { Bag bag = ModelUtils.getBag(); - Bag bagDeleted = ModelUtils.getBagDeleted(); + TariffsInfo tariffsInfo = ModelUtils.getTariffInfo(); + bag.setTariffsInfo(tariffsInfo); TariffsInfo tariffsInfoNew = ModelUtils.getTariffsInfoWithStatusNew(); tariffsInfoNew.setBags(Collections.emptyList()); - when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); - when(bagRepository.save(bag)).thenReturn(bagDeleted); - when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(Collections.emptyList()); - when(tariffsInfoRepository.save(tariffsInfoNew)).thenReturn(tariffsInfoNew); - + when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + doNothing().when(bagRepository).delete(bag); + when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(Collections.emptyList()); + when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfo); superAdminService.deleteTariffService(1); - - verify(bagRepository).findActiveBagById(1); - verify(bagRepository).save(bag); - verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); - verify(tariffsInfoRepository).save(tariffsInfoNew); + assertEquals(TariffStatus.NEW, tariffsInfoNew.getTariffStatus()); + verify(bagRepository).findById(1); + verify(bagRepository).delete(bag); + verify(bagRepository).findBagsByTariffsInfoId(1L); + verify(tariffsInfoRepository).save(tariffsInfo); } @Test void deleteTariffServiceWhenTariffBagsWithoutLimits() { Bag bag = ModelUtils.getBag(); + TariffsInfo tariffsInfo = ModelUtils.getTariffInfo(); bag.setLimitIncluded(false); - Bag bagDeleted = ModelUtils.getBagDeleted(); - bagDeleted.setLimitIncluded(false); + bag.setTariffsInfo(tariffsInfo); TariffsInfo tariffsInfoNew = ModelUtils.getTariffsInfoWithStatusNew(); tariffsInfoNew.setBags(Collections.emptyList()); - when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); - when(bagRepository.save(bag)).thenReturn(bagDeleted); - when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(List.of(bag)); - when(tariffsInfoRepository.save(tariffsInfoNew)).thenReturn(tariffsInfoNew); - + when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + doNothing().when(bagRepository).delete(bag); + when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(List.of(bag)); + when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfoNew); superAdminService.deleteTariffService(1); - - verify(bagRepository).findActiveBagById(1); - verify(bagRepository).save(bag); - verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); + assertEquals(TariffStatus.NEW, tariffsInfoNew.getTariffStatus()); + verify(bagRepository).findById(1); + verify(bagRepository).delete(bag); + verify(bagRepository).findBagsByTariffsInfoId(1L); verify(tariffsInfoRepository).save(tariffsInfoNew); } @Test - void deleteTariffServiceThrowBagNotFoundException() { - when(bagRepository.findActiveBagById(1)).thenReturn(Optional.empty()); + void deleteTariffServiceThrowNotFoundException() { + when(bagRepository.findById(1)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.deleteTariffService(1)); - verify(bagRepository).findActiveBagById(1); - verify(bagRepository, never()).save(any(Bag.class)); - } - - @Test - void editTariffServiceWithUnpaidOrder() { - Bag bag = ModelUtils.getBag(); - Bag editedBag = ModelUtils.getEditedBag(); - Employee employee = ModelUtils.getEmployee(); - TariffServiceDto dto = ModelUtils.getTariffServiceDto(); - GetTariffServiceDto editedDto = ModelUtils.getGetTariffServiceDto(); - Order order = ModelUtils.getOrder(); - String uuid = UUID.randomUUID().toString(); - order.setOrderBags(List.of(ModelUtils.getOrderBag())); - - when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); - when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); - when(bagRepository.save(editedBag)).thenReturn(editedBag); - when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); - doNothing().when(orderBagRepository) - .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); - when(orderRepository.findAllUnpaidOrdersByBagId(1)).thenReturn(List.of(order)); - when(orderRepository.saveAll(List.of(order))).thenReturn(List.of(order)); - - GetTariffServiceDto actual = superAdminService.editTariffService(dto, 1, uuid); - - assertEquals(editedDto, actual); - verify(employeeRepository).findByUuid(uuid); - verify(bagRepository).findActiveBagById(1); - verify(bagRepository).save(editedBag); - verify(modelMapper).map(editedBag, GetTariffServiceDto.class); - verify(orderBagRepository) - .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); - verify(orderRepository).findAllUnpaidOrdersByBagId(1); - verify(orderRepository).saveAll(anyList()); - } - - @Test - void editTariffServiceWithUnpaidOrderAndBagConfirmedAmount() { - Bag bag = ModelUtils.getBag(); - Bag editedBag = ModelUtils.getEditedBag(); - Employee employee = ModelUtils.getEmployee(); - TariffServiceDto dto = ModelUtils.getTariffServiceDto(); - GetTariffServiceDto editedDto = ModelUtils.getGetTariffServiceDto(); - Order order = ModelUtils.getOrder(); - String uuid = UUID.randomUUID().toString(); - order.setOrderBags(List.of(ModelUtils.getOrderBagWithConfirmedAmount())); - - when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); - when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); - when(bagRepository.save(editedBag)).thenReturn(editedBag); - when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); - doNothing().when(orderBagRepository) - .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); - when(orderRepository.findAllUnpaidOrdersByBagId(1)).thenReturn(List.of(order)); - when(orderRepository.saveAll(List.of(order))).thenReturn(List.of(order)); - - GetTariffServiceDto actual = superAdminService.editTariffService(dto, 1, uuid); - - assertEquals(editedDto, actual); - verify(employeeRepository).findByUuid(uuid); - verify(bagRepository).findActiveBagById(1); - verify(bagRepository).save(editedBag); - verify(modelMapper).map(editedBag, GetTariffServiceDto.class); - verify(orderBagRepository) - .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); - verify(orderRepository).findAllUnpaidOrdersByBagId(1); - verify(orderRepository).saveAll(anyList()); + () -> superAdminService.deleteTariffService(1)); + verify(bagRepository).findById(1); + verify(bagRepository, never()).delete(any(Bag.class)); } @Test - void editTariffServiceWithUnpaidOrderAndBagExportedAmount() { + void editTariffService() { Bag bag = ModelUtils.getBag(); - Bag editedBag = ModelUtils.getEditedBag(); Employee employee = ModelUtils.getEmployee(); TariffServiceDto dto = ModelUtils.getTariffServiceDto(); GetTariffServiceDto editedDto = ModelUtils.getGetTariffServiceDto(); - Order order = ModelUtils.getOrder(); String uuid = UUID.randomUUID().toString(); - order.setOrderBags(List.of(ModelUtils.getOrderBagWithExportedAmount())); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); - when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); - when(bagRepository.save(editedBag)).thenReturn(editedBag); - when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); - doNothing().when(orderBagRepository) - .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); - when(orderRepository.findAllUnpaidOrdersByBagId(1)).thenReturn(List.of(order)); - when(orderRepository.saveAll(List.of(order))).thenReturn(List.of(order)); + when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.save(bag)).thenReturn(bag); + when(modelMapper.map(bag, GetTariffServiceDto.class)).thenReturn(editedDto); - GetTariffServiceDto actual = superAdminService.editTariffService(dto, 1, uuid); + superAdminService.editTariffService(dto, 1, uuid); - assertEquals(editedDto, actual); verify(employeeRepository).findByUuid(uuid); - verify(bagRepository).findActiveBagById(1); - verify(bagRepository).save(editedBag); - verify(modelMapper).map(editedBag, GetTariffServiceDto.class); - verify(orderBagRepository) - .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); - verify(orderRepository).findAllUnpaidOrdersByBagId(1); - verify(orderRepository).saveAll(anyList()); + verify(bagRepository).findById(1); + verify(bagRepository).save(bag); + verify(modelMapper).map(bag, GetTariffServiceDto.class); } @Test - void editTariffServiceWithoutUnpaidOrder() { + void editTariffServiceIfCommissionIsNull() { Bag bag = ModelUtils.getBag(); - Bag editedBag = ModelUtils.getEditedBag(); Employee employee = ModelUtils.getEmployee(); TariffServiceDto dto = ModelUtils.getTariffServiceDto(); + dto.setCommission(null); GetTariffServiceDto editedDto = ModelUtils.getGetTariffServiceDto(); String uuid = UUID.randomUUID().toString(); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); - when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); - when(bagRepository.save(editedBag)).thenReturn(editedBag); - when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); - doNothing().when(orderBagRepository) - .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); - when(orderRepository.findAllUnpaidOrdersByBagId(1)).thenReturn(Collections.emptyList()); + when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.save(bag)).thenReturn(bag); + when(modelMapper.map(bag, GetTariffServiceDto.class)).thenReturn(editedDto); - GetTariffServiceDto actual = superAdminService.editTariffService(dto, 1, uuid); + superAdminService.editTariffService(dto, 1, uuid); - assertEquals(editedDto, actual); verify(employeeRepository).findByUuid(uuid); - verify(bagRepository).findActiveBagById(1); - verify(bagRepository).save(editedBag); - verify(modelMapper).map(editedBag, GetTariffServiceDto.class); - verify(orderBagRepository) - .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); - verify(orderRepository).findAllUnpaidOrdersByBagId(1); - verify(orderRepository, never()).saveAll(anyList()); + verify(bagRepository).findById(1); + verify(bagRepository).save(bag); + verify(modelMapper).map(bag, GetTariffServiceDto.class); } @Test @@ -457,12 +346,12 @@ void editTariffServiceIfEmployeeNotFoundException() { Optional bag = ModelUtils.getOptionalBag(); String uuid = UUID.randomUUID().toString(); - when(bagRepository.findActiveBagById(1)).thenReturn(bag); + when(bagRepository.findById(1)).thenReturn(bag); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariffService(dto, 1, uuid)); + () -> superAdminService.editTariffService(dto, 1, uuid)); - verify(bagRepository).findActiveBagById(1); + verify(bagRepository).findById(1); verify(bagRepository, never()).save(any(Bag.class)); } @@ -471,11 +360,11 @@ void editTariffServiceIfBagNotFoundException() { TariffServiceDto dto = ModelUtils.getTariffServiceDto(); String uuid = UUID.randomUUID().toString(); - when(bagRepository.findActiveBagById(1)).thenReturn(Optional.empty()); + when(bagRepository.findById(1)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariffService(dto, 1, uuid)); + () -> superAdminService.editTariffService(dto, 1, uuid)); - verify(bagRepository).findActiveBagById(1); + verify(bagRepository).findById(1); verify(bagRepository, never()).save(any(Bag.class)); } @@ -483,7 +372,7 @@ void editTariffServiceIfBagNotFoundException() { void getAllCouriersTest() { when(courierRepository.findAll()).thenReturn(List.of(getCourier())); when(modelMapper.map(getCourier(), CourierDto.class)) - .thenReturn(getCourierDto()); + .thenReturn(getCourierDto()); assertEquals(getCourierDtoList(), superAdminService.getAllCouriers()); @@ -510,7 +399,7 @@ void deleteServiceThrowNotFoundException() { when(serviceRepository.findById(service.getId())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.deleteService(1L)); + () -> superAdminService.deleteService(1L)); verify(serviceRepository).findById(1L); verify(serviceRepository, never()).delete(service); @@ -520,40 +409,38 @@ void deleteServiceThrowNotFoundException() { void getService() { Service service = ModelUtils.getService(); GetServiceDto getServiceDto = ModelUtils.getGetServiceDto(); - TariffsInfo tariffsInfo = ModelUtils.getTariffsInfo(); - when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); + when(tariffsInfoRepository.existsById(1L)).thenReturn(true); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(service)); when(modelMapper.map(service, GetServiceDto.class)).thenReturn(getServiceDto); assertEquals(getServiceDto, superAdminService.getService(1L)); - verify(tariffsInfoRepository).findById(1L); + verify(tariffsInfoRepository).existsById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); verify(modelMapper).map(service, GetServiceDto.class); } @Test void getServiceIfServiceNotExists() { - TariffsInfo tariffsInfo = ModelUtils.getTariffsInfo(); - - when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); + when(tariffsInfoRepository.existsById(1L)).thenReturn(true); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); assertNull(superAdminService.getService(1L)); - verify(tariffsInfoRepository).findById(1L); + verify(tariffsInfoRepository).existsById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); + verify(modelMapper, never()).map(any(Service.class), any(GetServiceDto.class)); } @Test void getServiceThrowTariffNotFoundException() { - when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); + when(tariffsInfoRepository.existsById(1L)).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.getService(1L)); + () -> superAdminService.getService(1L)); - verify(tariffsInfoRepository).findById(1L); + verify(tariffsInfoRepository).existsById(1L); } @Test @@ -585,7 +472,7 @@ void editServiceServiceNotFoundException() { when(serviceRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editService(1L, dto, uuid)); + () -> superAdminService.editService(1L, dto, uuid)); verify(serviceRepository).findById(1L); verify(serviceRepository, never()).save(any(Service.class)); @@ -602,7 +489,7 @@ void editServiceEmployeeNotFoundException() { when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editService(1L, dto, uuid)); + () -> superAdminService.editService(1L, dto, uuid)); verify(employeeRepository).findByUuid(uuid); verify(serviceRepository).findById(1L); @@ -620,6 +507,7 @@ void addService() { TariffsInfo tariffsInfo = ModelUtils.getTariffsInfo(); String uuid = UUID.randomUUID().toString(); + when(tariffsInfoRepository.existsById(1L)).thenReturn(true); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); @@ -630,6 +518,7 @@ void addService() { assertEquals(getServiceDto, superAdminService.addService(1L, serviceDto, uuid)); verify(employeeRepository).findByUuid(uuid); + verify(tariffsInfoRepository).existsById(1L); verify(tariffsInfoRepository).findById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); verify(serviceRepository).save(service); @@ -641,33 +530,31 @@ void addService() { void addServiceThrowServiceAlreadyExistsException() { Service createdService = ModelUtils.getService(); ServiceDto serviceDto = ModelUtils.getServiceDto(); - TariffsInfo tariffsInfo = ModelUtils.getTariffsInfo(); String uuid = UUID.randomUUID().toString(); - when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); + when(tariffsInfoRepository.existsById(1L)).thenReturn(true); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(createdService)); assertThrows(ServiceAlreadyExistsException.class, - () -> superAdminService.addService(1L, serviceDto, uuid)); + () -> superAdminService.addService(1L, serviceDto, uuid)); - verify(tariffsInfoRepository).findById(1L); + verify(tariffsInfoRepository).existsById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); } @Test void addServiceThrowEmployeeNotFoundException() { ServiceDto serviceDto = ModelUtils.getServiceDto(); - TariffsInfo tariffsInfo = ModelUtils.getTariffsInfo(); String uuid = UUID.randomUUID().toString(); - when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); + when(tariffsInfoRepository.existsById(1L)).thenReturn(true); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.addService(1L, serviceDto, uuid)); + () -> superAdminService.addService(1L, serviceDto, uuid)); - verify(tariffsInfoRepository).findById(1L); + verify(tariffsInfoRepository).existsById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); verify(employeeRepository).findByUuid(uuid); } @@ -677,12 +564,12 @@ void addServiceThrowTariffNotFoundException() { ServiceDto serviceDto = ModelUtils.getServiceDto(); String uuid = UUID.randomUUID().toString(); - when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); + when(tariffsInfoRepository.existsById(1L)).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.addService(1L, serviceDto, uuid)); + () -> superAdminService.addService(1L, serviceDto, uuid)); - verify(tariffsInfoRepository).findById(1L); + verify(tariffsInfoRepository).existsById(1L); } @Test @@ -702,7 +589,7 @@ void getLocationsByStatusTest() { List regionList = ModelUtils.getAllRegion(); when(regionRepository.findAllByLocationsLocationStatus(LocationStatus.ACTIVE)) - .thenReturn(Optional.of(regionList)); + .thenReturn(Optional.of(regionList)); var result = superAdminService.getLocationsByStatus(LocationStatus.ACTIVE); @@ -715,13 +602,13 @@ void getLocationsByStatusTest() { @Test void getLocationsByStatusNotFoundExceptionTest() { when(regionRepository.findAllByLocationsLocationStatus(LocationStatus.ACTIVE)) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); NotFoundException notFoundException = assertThrows(NotFoundException.class, - () -> superAdminService.getLocationsByStatus(LocationStatus.ACTIVE)); + () -> superAdminService.getLocationsByStatus(LocationStatus.ACTIVE)); assertEquals(String.format(ErrorMessage.REGIONS_NOT_FOUND_BY_LOCATION_STATUS, LocationStatus.ACTIVE.name()), - notFoundException.getMessage()); + notFoundException.getMessage()); verify(regionRepository).findAllByLocationsLocationStatus(LocationStatus.ACTIVE); } @@ -732,7 +619,7 @@ void addLocationTest() { Region region = ModelUtils.getRegion(); when(regionRepository.findRegionByEnNameAndUkrName("Kyiv region", "Київська область")) - .thenReturn(Optional.of(region)); + .thenReturn(Optional.of(region)); superAdminService.addLocation(locationCreateDtoList); @@ -746,7 +633,7 @@ void addLocationCreateNewRegionTest() { List locationCreateDtoList = ModelUtils.getLocationCreateDtoList(); Location location = ModelUtils.getLocationForCreateRegion(); when(regionRepository.findRegionByEnNameAndUkrName("Kyiv region", "Київська область")) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); when(regionRepository.save(any())).thenReturn(ModelUtils.getRegion()); superAdminService.addLocation(locationCreateDtoList); verify(locationRepository).findLocationByNameAndRegionId("Київ", "Kyiv", 1L); @@ -758,7 +645,7 @@ void addLocationCreateNewRegionTest() { void deleteLocationTest() { Location location = ModelUtils.getLocationDto(); location - .setTariffLocations(Set.of(TariffLocation.builder().location(Location.builder().id(2L).build()).build())); + .setTariffLocations(Set.of(TariffLocation.builder().location(Location.builder().id(2L).build()).build())); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); superAdminService.deleteLocation(1L); verify(locationRepository).findById(1L); @@ -769,7 +656,7 @@ void deleteLocationTest() { void deleteLocationThrowsBadRequestExceptionTest() { Location location = ModelUtils.getLocationDto(); location - .setTariffLocations(Set.of(TariffLocation.builder().location(Location.builder().id(1L).build()).build())); + .setTariffLocations(Set.of(TariffLocation.builder().location(Location.builder().id(1L).build()).build())); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); assertThrows(BadRequestException.class, () -> superAdminService.deleteLocation(1L)); verify(locationRepository).findById(1L); @@ -792,7 +679,7 @@ void addLocationThrowLocationAlreadyCreatedExceptionTest() { List locationCreateDtoList = ModelUtils.getLocationCreateDtoList(); Location location = ModelUtils.getLocation(); when(regionRepository.findRegionByEnNameAndUkrName("Kyiv region", "Київська область")) - .thenReturn(Optional.of(ModelUtils.getRegion())); + .thenReturn(Optional.of(ModelUtils.getRegion())); when(locationRepository.findLocationByNameAndRegionId("Київ", "Kyiv", 1L)).thenReturn(Optional.of(location)); assertThrows(NotFoundException.class, () -> superAdminService.addLocation(locationCreateDtoList)); @@ -835,17 +722,17 @@ void deactivateCourierThrowBadRequestException() { when(courierRepository.findById(anyLong())).thenReturn(Optional.of(courier)); courier.setCourierStatus(CourierStatus.DEACTIVATED); assertThrows(BadRequestException.class, - () -> superAdminService.deactivateCourier(1L)); + () -> superAdminService.deactivateCourier(1L)); verify(courierRepository).findById(1L); } @Test void deactivateCourierThrowNotFoundException() { when(courierRepository.findById(anyLong())) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); Exception thrownNotFoundEx = assertThrows(NotFoundException.class, - () -> superAdminService.deactivateCourier(1L)); + () -> superAdminService.deactivateCourier(1L)); assertEquals(ErrorMessage.COURIER_IS_NOT_FOUND_BY_ID + 1L, thrownNotFoundEx.getMessage()); verify(courierRepository).findById(1L); @@ -859,14 +746,14 @@ void createCourier() { when(employeeRepository.findByUuid(anyString())).thenReturn(Optional.ofNullable(getEmployee())); when(courierRepository.findAll()).thenReturn(List.of(Courier.builder() - .nameEn("Test1") - .nameUk("Тест1") - .build())); + .nameEn("Test1") + .nameUk("Тест1") + .build())); when(courierRepository.save(any())).thenReturn(courier); when(modelMapper.map(any(), eq(CreateCourierDto.class))).thenReturn(createCourierDto); assertEquals(createCourierDto, - superAdminService.createCourier(createCourierDto, ModelUtils.TEST_USER.getUuid())); + superAdminService.createCourier(createCourierDto, ModelUtils.TEST_USER.getUuid())); verify(courierRepository).save(any()); verify(modelMapper).map(any(), eq(CreateCourierDto.class)); @@ -883,7 +770,7 @@ void createCourierAlreadyExists() { when(courierRepository.findAll()).thenReturn(List.of(getCourier(), getCourier())); Throwable throwable = assertThrows(CourierAlreadyExists.class, - () -> superAdminService.createCourier(createCourierDto, uuid)); + () -> superAdminService.createCourier(createCourierDto, uuid)); assertEquals(ErrorMessage.COURIER_ALREADY_EXISTS, throwable.getMessage()); verify(employeeRepository).findByUuid(anyString()); verify(courierRepository).findAll(); @@ -894,24 +781,24 @@ void updateCourierTest() { Courier courier = getCourier(); CourierUpdateDto dto = CourierUpdateDto.builder() - .courierId(1L) - .nameUk("УБС") - .nameEn("UBS") - .build(); + .courierId(1L) + .nameUk("УБС") + .nameEn("UBS") + .build(); Courier courierToSave = Courier.builder() - .id(courier.getId()) - .courierStatus(courier.getCourierStatus()) - .nameUk("УБС") - .nameEn("UBS") - .build(); + .id(courier.getId()) + .courierStatus(courier.getCourierStatus()) + .nameUk("УБС") + .nameEn("UBS") + .build(); CourierDto courierDto = CourierDto.builder() - .courierId(courier.getId()) - .courierStatus("Active") - .nameUk("УБС") - .nameEn("UBS") - .build(); + .courierId(courier.getId()) + .courierStatus("Active") + .nameUk("УБС") + .nameEn("UBS") + .build(); when(courierRepository.findById(dto.getCourierId())).thenReturn(Optional.of(courier)); when(courierRepository.save(courier)).thenReturn(courierToSave); @@ -919,11 +806,11 @@ void updateCourierTest() { CourierDto actual = superAdminService.updateCourier(dto); CourierDto expected = CourierDto.builder() - .courierId(getCourier().getId()) - .courierStatus("Active") - .nameUk("УБС") - .nameEn("UBS") - .build(); + .courierId(getCourier().getId()) + .courierStatus("Active") + .nameUk("УБС") + .nameEn("UBS") + .build(); assertEquals(expected, actual); } @@ -933,20 +820,20 @@ void updateCourierNotFound() { Courier courier = getCourier(); CourierUpdateDto dto = CourierUpdateDto.builder() - .courierId(1L) - .nameUk("УБС") - .nameEn("UBS") - .build(); + .courierId(1L) + .nameUk("УБС") + .nameEn("UBS") + .build(); when(courierRepository.findById(courier.getId())) - .thenThrow(new NotFoundException(ErrorMessage.COURIER_IS_NOT_FOUND_BY_ID)); + .thenThrow(new NotFoundException(ErrorMessage.COURIER_IS_NOT_FOUND_BY_ID)); assertThrows(NotFoundException.class, () -> superAdminService.updateCourier(dto)); } @Test void getAllTariffsInfoTest() { when(tariffsInfoRepository.findAll(any(TariffsInfoSpecification.class))) - .thenReturn(List.of(ModelUtils.getTariffsInfo())); + .thenReturn(List.of(ModelUtils.getTariffsInfo())); when(modelMapper.map(any(TariffsInfo.class), eq(GetTariffsInfoDto.class))).thenReturn(getAllTariffsInfoDto()); superAdminService.getAllTariffsInfo(TariffsInfoFilterCriteria.builder().build()); @@ -960,7 +847,7 @@ void CreateReceivingStation() { AddingReceivingStationDto stationDto = AddingReceivingStationDto.builder().name("Петрівка").build(); when(receivingStationRepository.existsReceivingStationByName(any())).thenReturn(false, true); lenient().when(modelMapper.map(any(ReceivingStation.class), eq(ReceivingStationDto.class))) - .thenReturn(getReceivingStationDto()); + .thenReturn(getReceivingStationDto()); when(receivingStationRepository.save(any())).thenReturn(getReceivingStation(), getReceivingStation()); when(employeeRepository.findByUuid(test)).thenReturn(Optional.ofNullable(getEmployee())); superAdminService.createReceivingStation(stationDto, test); @@ -968,12 +855,12 @@ void CreateReceivingStation() { verify(receivingStationRepository, times(1)).existsReceivingStationByName(any()); verify(receivingStationRepository, times(1)).save(any()); verify(modelMapper, times(1)) - .map(any(ReceivingStation.class), eq(ReceivingStationDto.class)); + .map(any(ReceivingStation.class), eq(ReceivingStationDto.class)); Exception thrown = assertThrows(UnprocessableEntityException.class, - () -> superAdminService.createReceivingStation(stationDto, test)); + () -> superAdminService.createReceivingStation(stationDto, test)); assertEquals(thrown.getMessage(), ErrorMessage.RECEIVING_STATION_ALREADY_EXISTS - + stationDto.getName()); + + stationDto.getName()); verify(employeeRepository).findByUuid(any()); } @@ -982,13 +869,13 @@ void createReceivingStationSaveCorrectValue() { String receivingStationName = "Петрівка"; Employee employee = getEmployee(); AddingReceivingStationDto addingReceivingStationDto = - AddingReceivingStationDto.builder().name(receivingStationName).build(); + AddingReceivingStationDto.builder().name(receivingStationName).build(); ReceivingStation activatedReceivingStation = ReceivingStation.builder() - .name(receivingStationName) - .createdBy(employee) - .createDate(LocalDate.now()) - .stationStatus(StationStatus.ACTIVE) - .build(); + .name(receivingStationName) + .createdBy(employee) + .createDate(LocalDate.now()) + .stationStatus(StationStatus.ACTIVE) + .build(); ReceivingStationDto receivingStationDto = getReceivingStationDto(); @@ -996,7 +883,7 @@ void createReceivingStationSaveCorrectValue() { when(receivingStationRepository.existsReceivingStationByName(any())).thenReturn(false); when(receivingStationRepository.save(any())).thenReturn(activatedReceivingStation); when(modelMapper.map(any(), eq(ReceivingStationDto.class))) - .thenReturn(receivingStationDto); + .thenReturn(receivingStationDto); superAdminService.createReceivingStation(addingReceivingStationDto, employee.getUuid()); @@ -1004,7 +891,7 @@ void createReceivingStationSaveCorrectValue() { verify(receivingStationRepository).existsReceivingStationByName(any()); verify(receivingStationRepository).save(activatedReceivingStation); verify(modelMapper) - .map(any(ReceivingStation.class), eq(ReceivingStationDto.class)); + .map(any(ReceivingStation.class), eq(ReceivingStationDto.class)); } @@ -1056,7 +943,7 @@ void deleteReceivingStation() { when(receivingStationRepository.findById(2L)).thenReturn(Optional.empty()); Exception thrown1 = assertThrows(NotFoundException.class, - () -> superAdminService.deleteReceivingStation(2L)); + () -> superAdminService.deleteReceivingStation(2L)); assertEquals(ErrorMessage.RECEIVING_STATION_NOT_FOUND_BY_ID + 2L, thrown1.getMessage()); } @@ -1065,12 +952,12 @@ void deleteReceivingStation() { void editNewTariffSuccess() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); when(locationRepository.findAllByIdAndRegionId(dto.getLocationIdList(), dto.getRegionId())) - .thenReturn(ModelUtils.getLocationList()); + .thenReturn(ModelUtils.getLocationList()); when(employeeRepository.findByUuid(any())).thenReturn(Optional.ofNullable(getEmployee())); when(receivingStationRepository.findAllById(List.of(1L))).thenReturn(ModelUtils.getReceivingList()); when(courierRepository.findById(anyLong())).thenReturn(Optional.of(ModelUtils.getCourier())); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(Collections.emptyList()); + .thenReturn(Collections.emptyList()); when(tariffsInfoRepository.save(any())).thenReturn(ModelUtils.getTariffInfo()); when(employeeRepository.findAllByEmployeePositionId(6L)).thenReturn(ModelUtils.getEmployeeList()); when(tariffsLocationRepository.saveAll(anySet())).thenReturn(anyList()); @@ -1090,13 +977,13 @@ void addNewTariffThrowsExceptionWhenListOfLocationsIsEmptyTest() { when(employeeRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(Optional.ofNullable(getEmployee())); when(tariffsInfoRepository.save(any())).thenReturn(ModelUtils.getTariffInfo()); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(Collections.emptyList()); + .thenReturn(Collections.emptyList()); when(receivingStationRepository.findAllById(List.of(1L))).thenReturn(ModelUtils.getReceivingList()); when(locationRepository.findAllByIdAndRegionId(dto.getLocationIdList(), - dto.getRegionId())).thenReturn(Collections.emptyList()); + dto.getRegionId())).thenReturn(Collections.emptyList()); assertThrows(NotFoundException.class, - () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); + () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); verify(courierRepository).findById(1L); verify(employeeRepository).findByUuid("35467585763t4sfgchjfuyetf"); @@ -1111,20 +998,20 @@ void addNewTariffThrowsExceptionWhenListOfLocationsIsEmptyTest() { void addNewTariffThrowsExceptionWhenSuchTariffIsAlreadyExistsTest() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); TariffLocation tariffLocation = TariffLocation - .builder() - .id(1L) - .location(ModelUtils.getLocation()) - .build(); + .builder() + .id(1L) + .location(ModelUtils.getLocation()) + .build(); when(courierRepository.findById(1L)).thenReturn(Optional.of(ModelUtils.getCourier())); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(dto.getCourierId(), - dto.getLocationIdList())).thenReturn(List.of(tariffLocation)); + dto.getLocationIdList())).thenReturn(List.of(tariffLocation)); assertThrows(TariffAlreadyExistsException.class, - () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); + () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); verify(courierRepository).findById(1L); verify(tariffsLocationRepository).findAllByCourierIdAndLocationIds(dto.getCourierId(), - dto.getLocationIdList()); + dto.getLocationIdList()); verifyNoMoreInteractions(courierRepository, tariffsLocationRepository); verify(employeeRepository, never()).findAllByEmployeePositionId(6L); } @@ -1140,12 +1027,12 @@ void addNewTariffThrowsExceptionWhenCourierHasStatusDeactivated() { // Perform the test assertThrows(BadRequestException.class, - () -> superAdminService.addNewTariff(addNewTariffDto, userUUID)); + () -> superAdminService.addNewTariff(addNewTariffDto, userUUID)); // Verify the interactions verify(courierRepository).findById(addNewTariffDto.getCourierId()); verifyNoMoreInteractions(courierRepository, tariffsLocationRepository, tariffsInfoRepository, - employeeRepository); + employeeRepository); } @Test @@ -1157,12 +1044,12 @@ void addNewTariffThrowsExceptionWhenListOfReceivingStationIsEmpty() { when(employeeRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(Optional.ofNullable(getEmployee())); when(tariffsInfoRepository.save(any())).thenReturn(ModelUtils.getTariffInfo()); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(Collections.emptyList()); + .thenReturn(Collections.emptyList()); when(locationRepository.findAllByIdAndRegionId(dto.getLocationIdList(), - dto.getRegionId())).thenReturn(Collections.emptyList()); + dto.getRegionId())).thenReturn(Collections.emptyList()); assertThrows(NotFoundException.class, - () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); + () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); verify(courierRepository).findById(1L); verify(employeeRepository).findByUuid("35467585763t4sfgchjfuyetf"); @@ -1177,7 +1064,7 @@ void addNewTariffThrowsException2() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); when(courierRepository.findById(anyLong())).thenReturn(Optional.of(ModelUtils.getCourier())); assertThrows(NotFoundException.class, - () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); + () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); verify(courierRepository).findById(anyLong()); verify(receivingStationRepository).findAllById(any()); verify(tariffsLocationRepository).findAllByCourierIdAndLocationIds(anyLong(), anyList()); @@ -1189,7 +1076,7 @@ void addNewTariffThrowsException3() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); when(courierRepository.findById(anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); + () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); verify(employeeRepository, never()).findAllByEmployeePositionId(6L); } @@ -1206,10 +1093,10 @@ void editTariffTest() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); when(tariffsLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) - .thenReturn(Optional.of(tariffLocation)); + .thenReturn(Optional.of(tariffLocation)); when(tariffsLocationRepository.findAllByTariffsInfo(tariffsInfo)).thenReturn(List.of(tariffLocation)); when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfo); @@ -1239,10 +1126,10 @@ void editTariffWithDeleteTariffLocation() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); when(tariffsLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) - .thenReturn(Optional.of(tariffLocation)); + .thenReturn(Optional.of(tariffLocation)); when(tariffsLocationRepository.findAllByTariffsInfo(tariffsInfo)).thenReturn(tariffLocations); doNothing().when(tariffsLocationRepository).delete(tariffLocations.get(1)); when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfo); @@ -1266,7 +1153,7 @@ void editTariffThrowTariffNotFoundException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1279,7 +1166,7 @@ void editTariffThrowLocationNotFoundException() { when(locationRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(locationRepository).findById(1L); @@ -1296,7 +1183,7 @@ void editTariffThrowLocationBadRequestException() { when(locationRepository.findById(2L)).thenReturn(Optional.of(locations.get(1))); assertThrows(BadRequestException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(locationRepository).findById(1L); @@ -1315,10 +1202,10 @@ void editTariffThrowTariffAlreadyExistsException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); assertThrows(TariffAlreadyExistsException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(locationRepository).findById(1L); @@ -1338,11 +1225,11 @@ void editTariffThrowReceivingStationNotFoundException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); when(receivingStationRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(locationRepository).findById(1L); @@ -1362,7 +1249,7 @@ void editTariffThrowsCourierNotFoundException() { when(courierRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(courierRepository).findById(1L); @@ -1380,11 +1267,11 @@ void editTariffWithoutCourier() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); when(receivingStationRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(locationRepository).findById(1L); @@ -1404,7 +1291,7 @@ void editTariffThrowsCourierHasStatusDeactivatedException() { when(courierRepository.findById(1L)).thenReturn(Optional.of(courier)); assertThrows(BadRequestException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(courierRepository).findById(1L); @@ -1424,10 +1311,10 @@ void editTariffWithBuildTariffLocation() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); when(tariffsLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); when(tariffsLocationRepository.findAllByTariffsInfo(tariffsInfo)).thenReturn(List.of(tariffLocation)); when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfo); @@ -1447,7 +1334,7 @@ void editTariffWithBuildTariffLocation() { void checkIfTariffDoesNotExistsTest() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(anyLong(), any())) - .thenReturn(Collections.emptyList()); + .thenReturn(Collections.emptyList()); boolean actual = superAdminService.checkIfTariffExists(dto); assertFalse(actual); verify(tariffsLocationRepository).findAllByCourierIdAndLocationIds(anyLong(), any()); @@ -1457,14 +1344,14 @@ void checkIfTariffDoesNotExistsTest() { void checkIfTariffExistsTest() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); TariffLocation tariffLocation = TariffLocation - .builder() - .id(1L) - .tariffsInfo(ModelUtils.getTariffsInfo()) - .location(ModelUtils.getLocation()) - .locationStatus(LocationStatus.ACTIVE) - .build(); + .builder() + .id(1L) + .tariffsInfo(ModelUtils.getTariffsInfo()) + .location(ModelUtils.getLocation()) + .locationStatus(LocationStatus.ACTIVE) + .build(); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(anyLong(), any())) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); boolean actual = superAdminService.checkIfTariffExists(dto); assertTrue(actual); verify(tariffsLocationRepository).findAllByCourierIdAndLocationIds(anyLong(), any()); @@ -1477,14 +1364,14 @@ void setTariffLimitsWithAmountOfBags() { SetTariffLimitsDto dto = ModelUtils.setTariffLimitsWithAmountOfBags(); when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); - when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); when(tariffsInfoRepository.save(tariffInfo)).thenReturn(tariffInfo); when(bagRepository.saveAll(List.of(bag))).thenReturn(List.of(bag)); superAdminService.setTariffLimits(1L, dto); verify(tariffsInfoRepository).findById(1L); - verify(bagRepository).findActiveBagById(1); + verify(bagRepository).findById(1); verify(tariffsInfoRepository).save(any()); verify(bagRepository).saveAll(List.of(bag)); } @@ -1496,14 +1383,14 @@ void setTariffLimitsWithPriceOfOrder() { SetTariffLimitsDto dto = ModelUtils.setTariffLimitsWithPriceOfOrder(); when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); - when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); when(tariffsInfoRepository.save(tariffInfo)).thenReturn(tariffInfo); when(bagRepository.saveAll(List.of(bag))).thenReturn(List.of(bag)); superAdminService.setTariffLimits(1L, dto); verify(tariffsInfoRepository).findById(1L); - verify(bagRepository).findActiveBagById(1); + verify(bagRepository).findById(1); verify(tariffsInfoRepository).save(any()); verify(bagRepository).saveAll(List.of(bag)); } @@ -1515,14 +1402,14 @@ void setTariffLimitsWithNullMinAndMaxAndFalseBagLimitIncluded() { SetTariffLimitsDto dto = ModelUtils.setTariffLimitsWithNullMinAndMaxAndFalseBagLimit(); when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); - when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); when(tariffsInfoRepository.save(tariffInfo)).thenReturn(tariffInfo); when(bagRepository.saveAll(List.of(bag))).thenReturn(List.of(bag)); superAdminService.setTariffLimits(1L, dto); verify(tariffsInfoRepository).findById(1L); - verify(bagRepository).findActiveBagById(1); + verify(bagRepository).findById(1); verify(tariffsInfoRepository).save(any()); verify(bagRepository).saveAll(List.of(bag)); } @@ -1535,13 +1422,13 @@ void setTariffLimitsIfBagNotBelongToTariff() { tariffInfo.setId(2L); when(tariffsInfoRepository.findById(2L)).thenReturn(Optional.of(tariffInfo)); - when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(2L, dto)); + () -> superAdminService.setTariffLimits(2L, dto)); verify(tariffsInfoRepository).findById(2L); - verify(bagRepository).findActiveBagById(1); + verify(bagRepository).findById(1); } @Test @@ -1552,14 +1439,14 @@ void setTariffLimitsWithNullMaxAndTrueBagLimitIncluded() { dto.setMax(null); when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); - when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); when(tariffsInfoRepository.save(tariffInfo)).thenReturn(tariffInfo); when(bagRepository.saveAll(List.of(bag))).thenReturn(List.of(bag)); superAdminService.setTariffLimits(1L, dto); verify(tariffsInfoRepository).findById(1L); - verify(bagRepository).findActiveBagById(1); + verify(bagRepository).findById(1); verify(tariffsInfoRepository).save(any()); verify(bagRepository).saveAll(List.of(bag)); } @@ -1572,14 +1459,14 @@ void setTariffLimitsWithNullMinAndTrueBagLimitIncluded() { dto.setMin(null); when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); - when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); when(tariffsInfoRepository.save(tariffInfo)).thenReturn(tariffInfo); when(bagRepository.saveAll(List.of(bag))).thenReturn(List.of(bag)); superAdminService.setTariffLimits(1L, dto); verify(tariffsInfoRepository).findById(1L); - verify(bagRepository).findActiveBagById(1); + verify(bagRepository).findById(1); verify(tariffsInfoRepository).save(any()); verify(bagRepository).saveAll(List.of(bag)); } @@ -1593,7 +1480,7 @@ void setTariffLimitsWithNullCourierLimitAndTrueBagLimitIncluded() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1608,7 +1495,7 @@ void setTariffLimitsWithNullAllParamsAndTrueBagLimitIncluded() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1623,7 +1510,7 @@ void setTariffLimitsWithNotNullAllParamsAndFalseBagLimitIncluded() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1636,7 +1523,7 @@ void setTariffsLimitWithSameMinAndMaxValue() { when(tariffsInfoRepository.findById(anyLong())).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1649,7 +1536,7 @@ void setTariffLimitsWithPriceOfOrderMaxValueIsGreaterThanMin() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1662,7 +1549,7 @@ void setTariffLimitsWithAmountOfBigBagMaxValueIsGreaterThanMin() { when(tariffsInfoRepository.findById(anyLong())).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1674,7 +1561,7 @@ void setTariffLimitsBagThrowTariffsInfoNotFound() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1685,13 +1572,13 @@ void setTariffLimitsBagThrowBagNotFound() { TariffsInfo tariffInfo = ModelUtils.getTariffInfo(); when(tariffsInfoRepository.findById(anyLong())).thenReturn(Optional.of(tariffInfo)); - when(bagRepository.findActiveBagById(1)).thenReturn(Optional.empty()); + when(bagRepository.findById(1)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); - verify(bagRepository).findActiveBagById(1); + verify(bagRepository).findById(1); } @Test @@ -1713,7 +1600,7 @@ void getTariffLimitsThrowNotFoundException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.getTariffLimits(1L)); + () -> superAdminService.getTariffLimits(1L)); verify(tariffsInfoRepository).findById(1L); } @@ -1766,10 +1653,10 @@ void switchTariffStatusFromWhenCourierDeactivatedThrowBadRequestException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); Throwable t = assertThrows(BadRequestException.class, - () -> superAdminService.switchTariffStatus(1L, "Active")); + () -> superAdminService.switchTariffStatus(1L, "Active")); assertEquals(String.format(ErrorMessage.TARIFF_ACTIVATION_RESTRICTION_DUE_TO_DEACTIVATED_COURIER + - tariffInfo.getCourier().getId()), - t.getMessage()); + tariffInfo.getCourier().getId()), + t.getMessage()); verify(tariffsInfoRepository).findById(1L); verify(tariffsInfoRepository, never()).save(tariffInfo); @@ -1794,7 +1681,7 @@ void switchTariffStatusThrowNotFoundException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.switchTariffStatus(1L, "Active")); + () -> superAdminService.switchTariffStatus(1L, "Active")); verify(tariffsInfoRepository).findById(1L); verify(tariffsInfoRepository, never()).save(any(TariffsInfo.class)); @@ -1807,9 +1694,9 @@ void switchTariffStatusFromActiveToActiveThrowBadRequestException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); Throwable t = assertThrows(BadRequestException.class, - () -> superAdminService.switchTariffStatus(1L, "Active")); + () -> superAdminService.switchTariffStatus(1L, "Active")); assertEquals(String.format(ErrorMessage.TARIFF_ALREADY_HAS_THIS_STATUS, 1L, TariffStatus.ACTIVE), - t.getMessage()); + t.getMessage()); verify(tariffsInfoRepository).findById(1L); verify(tariffsInfoRepository, never()).save(tariffInfo); @@ -1823,9 +1710,9 @@ void switchTariffStatusToActiveWithoutBagThrowBadRequestException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); Throwable t = assertThrows(BadRequestException.class, - () -> superAdminService.switchTariffStatus(1L, "Active")); + () -> superAdminService.switchTariffStatus(1L, "Active")); assertEquals(ErrorMessage.TARIFF_ACTIVATION_RESTRICTION_DUE_TO_UNSPECIFIED_BAGS, - t.getMessage()); + t.getMessage()); verify(tariffsInfoRepository).findById(1L); verify(tariffsInfoRepository, never()).save(tariffInfo); @@ -1839,7 +1726,7 @@ void switchTariffStatusWithUnresolvableStatusThrowBadRequestException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); Throwable t = assertThrows(BadRequestException.class, - () -> superAdminService.switchTariffStatus(1L, "new")); + () -> superAdminService.switchTariffStatus(1L, "new")); assertEquals(ErrorMessage.UNRESOLVABLE_TARIFF_STATUS, t.getMessage()); verify(tariffsInfoRepository).findById(1L); @@ -1855,9 +1742,9 @@ void switchTariffStatusToActiveWithMinAndMaxNullThrowBadRequestException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); Throwable t = assertThrows(BadRequestException.class, - () -> superAdminService.switchTariffStatus(1L, "Active")); + () -> superAdminService.switchTariffStatus(1L, "Active")); assertEquals(ErrorMessage.TARIFF_ACTIVATION_RESTRICTION_DUE_TO_UNSPECIFIED_LIMITS, - t.getMessage()); + t.getMessage()); verify(tariffsInfoRepository).findById(1L); verify(tariffsInfoRepository, never()).save(tariffInfo); @@ -1919,7 +1806,7 @@ void changeTariffLocationsStatusParamUnresolvable() { when(tariffsInfoRepository.findById(anyLong())).thenReturn(Optional.of(tariffsInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.changeTariffLocationsStatus(1L, dto, "unresolvable")); + () -> superAdminService.changeTariffLocationsStatus(1L, dto, "unresolvable")); } @Test @@ -1927,7 +1814,7 @@ void switchActivationStatusByChosenParamsBadRequestExceptionUnresolvableStatus() DetailsOfDeactivateTariffsDto details = ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegion(); details.setActivationStatus("Test"); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test @@ -1946,7 +1833,7 @@ void switchActivationStatusByAllValidParams() { when(receivingStationRepository.findById(anyLong())).thenReturn(Optional.of(receivingStation)); when(receivingStationRepository.saveAll(List.of(receivingStation))).thenReturn(List.of(receivingStation)); doNothing().when(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); superAdminService.switchActivationStatusByChosenParams(details); @@ -1954,7 +1841,7 @@ void switchActivationStatusByAllValidParams() { verify(locationRepository).findLocationByIdAndRegionId(1L, 1L); verify(locationRepository).saveAll(List.of(location)); verify(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); verify(courierRepository).findById(1L); verify(courierRepository).save(courier); verify(receivingStationRepository).findById(anyLong()); @@ -1983,13 +1870,13 @@ void switchLocationStatusToActiveByOneRegion() { when(locationRepository.findLocationsByRegionId(1L)).thenReturn(List.of(locationDeactivated)); when(locationRepository.saveAll(List.of(locationActive))).thenReturn(List.of(locationActive)); doNothing().when(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); superAdminService.switchActivationStatusByChosenParams(details); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(List.of(1L)); verify(locationRepository).findLocationsByRegionId(1L); verify(locationRepository).saveAll(List.of(locationActive)); verify(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); } @Test @@ -2016,13 +1903,13 @@ void switchLocationStatusToActiveByTwoRegions() { when(locationRepository.findLocationsByRegionId(2L)).thenReturn(List.of(locationDeactivated)); when(locationRepository.saveAll(List.of(locationActive))).thenReturn(List.of(locationActive)); doNothing().when(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); superAdminService.switchActivationStatusByChosenParams(details); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(anyList()); verify(locationRepository, times(2)).findLocationsByRegionId(anyLong()); verify(locationRepository, times(2)).saveAll(List.of(locationActive)); verify(tariffsLocationRepository, times(2)) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); } @Test @@ -2044,7 +1931,7 @@ void deactivateTariffByNotExistingRegionThrows() { when(deactivateTariffsForChosenParamRepository.isRegionsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(List.of(1L)); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByRegions(anyList()); } @@ -2056,7 +1943,7 @@ void switchLocationStatusToActiveByNotExistingRegionThrows() { when(deactivateTariffsForChosenParamRepository.isRegionsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(List.of(1L)); } @@ -2085,19 +1972,19 @@ void switchLocationStatusToActiveByRegionAndCities() { when(deactivateTariffsForChosenParamRepository.isRegionsExists(anyList())).thenReturn(true); when(locationRepository.findLocationByIdAndRegionId(1L, 1L)) - .thenReturn(Optional.of(locationDeactivated1)); + .thenReturn(Optional.of(locationDeactivated1)); when(locationRepository.findLocationByIdAndRegionId(11L, 1L)) - .thenReturn(Optional.of(locationDeactivated2)); + .thenReturn(Optional.of(locationDeactivated2)); when(locationRepository.saveAll(List.of(locationActive1, locationActive2))) - .thenReturn(List.of(locationActive1, locationActive2)); + .thenReturn(List.of(locationActive1, locationActive2)); doNothing().when(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L, 11L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L, 11L), LocationStatus.ACTIVE.name()); superAdminService.switchActivationStatusByChosenParams(details); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(anyList()); verify(locationRepository, times(2)).findLocationByIdAndRegionId(anyLong(), anyLong()); verify(locationRepository).saveAll(List.of(locationActive1, locationActive2)); verify(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L, 11L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L, 11L), LocationStatus.ACTIVE.name()); } @Test @@ -2107,11 +1994,11 @@ void deactivateTariffByOneRegionAndNotExistingCitiesThrows() { when(regionRepository.existsRegionById(anyLong())).thenReturn(true); when(deactivateTariffsForChosenParamRepository.isCitiesExistForRegion(anyList(), anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(regionRepository).existsRegionById(1L); verify(deactivateTariffsForChosenParamRepository).isCitiesExistForRegion(List.of(1L, 11L), 1L); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByRegionsAndCities(anyList(), - anyLong()); + anyLong()); } @Test @@ -2122,7 +2009,7 @@ void switchLocationStatusToActiveByRegionAndNotExistingCitiesThrows() { when(deactivateTariffsForChosenParamRepository.isRegionsExists(anyList())).thenReturn(true); when(locationRepository.findLocationByIdAndRegionId(anyLong(), anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(anyList()); verify(locationRepository).findLocationByIdAndRegionId(anyLong(), anyLong()); } @@ -2134,7 +2021,7 @@ void switchLocationStatusToActiveByCitiesAndNotExistingRegionBadRequestException details.setActivationStatus("Active"); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test @@ -2144,7 +2031,7 @@ void switchLocationStatusToActiveByCitiesAndTwoRegionsBadRequestException() { details.setActivationStatus("Active"); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test @@ -2153,10 +2040,10 @@ void deactivateTariffByOneNotExistingRegionAndCitiesThrows() { when(regionRepository.existsRegionById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(regionRepository).existsRegionById(1L); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByRegionsAndCities(anyList(), - anyLong()); + anyLong()); } @Test @@ -2166,7 +2053,7 @@ void switchLocationStatusToActiveExistingRegionAndCitiesThrows() { when(deactivateTariffsForChosenParamRepository.isRegionsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(anyList()); } @@ -2199,7 +2086,7 @@ void deactivateTariffByNotExistingCourierThrows() { when(courierRepository.existsCourierById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(courierRepository).existsCourierById(1L); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByCourier(anyLong()); } @@ -2211,7 +2098,7 @@ void switchCourierStatusToActiveNotExistingCourierThrows() { when(courierRepository.findById(anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(courierRepository).findById(anyLong()); } @@ -2236,7 +2123,7 @@ void switchReceivingStationsStatusToActive() { when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation1)); when(receivingStationRepository.findById(12L)).thenReturn(Optional.of(receivingStation2)); when(receivingStationRepository.saveAll(List.of(receivingStation1, receivingStation2))) - .thenReturn(List.of(receivingStation1, receivingStation2)); + .thenReturn(List.of(receivingStation1, receivingStation2)); superAdminService.switchActivationStatusByChosenParams(details); verify(receivingStationRepository, times(2)).findById(anyLong()); verify(receivingStationRepository).saveAll(anyList()); @@ -2248,7 +2135,7 @@ void deactivateTariffByNotExistingReceivingStationsThrows() { when(deactivateTariffsForChosenParamRepository.isReceivingStationsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByReceivingStations(anyList()); } @@ -2260,14 +2147,14 @@ void switchReceivingStationsStatusToActiveNotExistingReceivingStationsThrows() { when(receivingStationRepository.findById(anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(receivingStationRepository).findById(anyLong()); } @Test void deactivateTariffByCourierAndReceivingStations() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); when(courierRepository.existsCourierById(anyLong())).thenReturn(true); when(deactivateTariffsForChosenParamRepository.isReceivingStationsExists(anyList())).thenReturn(true); @@ -2275,35 +2162,35 @@ void deactivateTariffByCourierAndReceivingStations() { verify(courierRepository).existsCourierById(1L); verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); verify(deactivateTariffsForChosenParamRepository) - .deactivateTariffsByCourierAndReceivingStations(1L, List.of(1L, 12L)); + .deactivateTariffsByCourierAndReceivingStations(1L, List.of(1L, 12L)); } @Test void deactivateTariffByNotExistingCourierAndReceivingStationsTrows() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); when(courierRepository.existsCourierById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(courierRepository).existsCourierById(1L); verify(deactivateTariffsForChosenParamRepository, never()) - .deactivateTariffsByCourierAndReceivingStations(anyLong(), anyList()); + .deactivateTariffsByCourierAndReceivingStations(anyLong(), anyList()); } @Test void deactivateTariffByCourierAndNotExistingReceivingStationsTrows() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); when(courierRepository.existsCourierById(anyLong())).thenReturn(true); when(deactivateTariffsForChosenParamRepository.isReceivingStationsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(courierRepository).existsCourierById(1L); verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); verify(deactivateTariffsForChosenParamRepository, never()) - .deactivateTariffsByCourierAndReceivingStations(anyLong(), anyList()); + .deactivateTariffsByCourierAndReceivingStations(anyLong(), anyList()); } @Test @@ -2325,11 +2212,11 @@ void deactivateTariffByNotExistingCourierAndOneRegionThrows() { when(regionRepository.existsRegionById(anyLong())).thenReturn(true); when(courierRepository.existsCourierById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(regionRepository).existsRegionById(1L); verify(courierRepository).existsCourierById(1L); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByCourierAndRegion(anyLong(), - anyLong()); + anyLong()); } @Test @@ -2338,16 +2225,16 @@ void deactivateTariffByCourierAndNotExistingRegionThrows() { when(regionRepository.existsRegionById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(regionRepository).existsRegionById(1L); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByCourierAndRegion(anyLong(), - anyLong()); + anyLong()); } @Test void deactivateTariffByOneRegionAndCityAndStation() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation(); doMockForTariffWithRegionAndCityAndStation(true, true, true); superAdminService.switchActivationStatusByChosenParams(details); @@ -2357,29 +2244,29 @@ void deactivateTariffByOneRegionAndCityAndStation() { @ParameterizedTest @MethodSource("deactivateTariffByNotExistingSomeOfTreeParameters") void deactivateTariffByNotExistingRegionAndCityAndStationThrows( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists) { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation(); doMockForTariffWithRegionAndCityAndStation(isRegionExists, isCitiesExistForRegion, isReceivingStationsExists); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verifyForTariffWithRegionAndCityAndStation(isRegionExists, isCitiesExistForRegion, isReceivingStationsExists); verify(deactivateTariffsForChosenParamRepository, never()) - .deactivateTariffsByRegionAndCitiesAndStations(anyLong(), anyList(), anyList()); + .deactivateTariffsByRegionAndCitiesAndStations(anyLong(), anyList(), anyList()); } static Stream deactivateTariffByNotExistingSomeOfTreeParameters() { return Stream.of( - arguments(false, true, true), - arguments(false, false, true), - arguments(false, true, false), - arguments(true, false, true), - arguments(true, false, false), - arguments(true, true, false), - arguments(false, false, false)); + arguments(false, true, true), + arguments(false, false, true), + arguments(false, true, false), + arguments(true, false, true), + arguments(true, false, false), + arguments(true, true, false), + arguments(false, false, false)); } @Test @@ -2394,39 +2281,39 @@ void deactivateTariffByAllValidParams() { @ParameterizedTest @MethodSource("deactivateTariffByAllWithNotExistingParamProvider") void deactivateTariffByAllWithNotExistingParamThrows( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists, + boolean isCourierExists) { DetailsOfDeactivateTariffsDto details = ModelUtils.getDetailsOfDeactivateTariffsDtoWithAllParams(); doMockForTariffWithAllParams(isRegionExists, isCitiesExistForRegion, isReceivingStationsExists, - isCourierExists); + isCourierExists); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verifyForTariffWithAllParams(isRegionExists, isCitiesExistForRegion, isReceivingStationsExists, - isCourierExists); + isCourierExists); verify(deactivateTariffsForChosenParamRepository, never()) - .deactivateTariffsByAllParam(anyLong(), anyList(), anyList(), anyLong()); + .deactivateTariffsByAllParam(anyLong(), anyList(), anyList(), anyLong()); } private static Stream deactivateTariffByAllWithNotExistingParamProvider() { return Stream.of( - arguments(false, true, true, true), - arguments(true, false, true, true), - arguments(true, true, false, true), - arguments(true, true, true, false), - arguments(false, false, true, true), - arguments(false, true, false, true), - arguments(false, true, true, false), - arguments(false, true, false, false), - arguments(true, false, false, true), - arguments(true, false, true, false), - arguments(true, true, false, false), - arguments(false, false, false, true), - arguments(false, false, true, false), - arguments(true, false, false, false), - arguments(false, false, false, false)); + arguments(false, true, true, true), + arguments(true, false, true, true), + arguments(true, true, false, true), + arguments(true, true, true, false), + arguments(false, false, true, true), + arguments(false, true, false, true), + arguments(false, true, true, false), + arguments(false, true, false, false), + arguments(true, false, false, true), + arguments(true, false, true, false), + arguments(true, true, false, false), + arguments(false, false, false, true), + arguments(false, false, true, false), + arguments(true, false, false, false), + arguments(false, false, false, false)); } @Test @@ -2434,7 +2321,7 @@ void deactivateTariffByAllEmptyParams() { DetailsOfDeactivateTariffsDto details = ModelUtils.getDetailsOfDeactivateTariffsDtoWithEmptyParams(); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test @@ -2442,7 +2329,7 @@ void deactivateTariffByCities() { DetailsOfDeactivateTariffsDto details = ModelUtils.getDetailsOfDeactivateTariffsDtoWithCities(); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test @@ -2450,71 +2337,71 @@ void deactivateTariffByCitiesAndCourier() { DetailsOfDeactivateTariffsDto details = ModelUtils.getDetailsOfDeactivateTariffsDtoWithCitiesAndCourier(); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test void deactivateTariffByCitiesAndReceivingStations() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCitiesAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCitiesAndReceivingStations(); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test void deactivateTariffByCitiesAndCourierAndReceivingStations() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCitiesAndCourierAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCitiesAndCourierAndReceivingStations(); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @ParameterizedTest @MethodSource("deactivateTariffByDifferentParamWithTwoRegionsProvider") void deactivateTariffByDifferentParamWithTwoRegionsThrows(DetailsOfDeactivateTariffsDto details) { assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } private static Stream deactivateTariffByDifferentParamWithTwoRegionsProvider() { return Stream.of( - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegion() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCities() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithAllParams() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations() - .setRegionsIds(Optional.of(List.of(1L, 2L))))); + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegion() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCities() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithAllParams() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations() + .setRegionsIds(Optional.of(List.of(1L, 2L))))); } private void doMockForTariffWithRegionAndCityAndStation( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists) { when(regionRepository.existsRegionById(anyLong())).thenReturn(isRegionExists); if (isRegionExists) { when(deactivateTariffsForChosenParamRepository - .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistForRegion); + .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistForRegion); if (isCitiesExistForRegion) { when(deactivateTariffsForChosenParamRepository - .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); + .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); } } } private void verifyForTariffWithRegionAndCityAndStation( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists) { verify(regionRepository).existsRegionById(1L); if (isRegionExists) { verify(deactivateTariffsForChosenParamRepository).isCitiesExistForRegion(List.of(1L, 11L), 1L); @@ -2522,24 +2409,24 @@ private void verifyForTariffWithRegionAndCityAndStation( verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); if (isReceivingStationsExists) { verify(deactivateTariffsForChosenParamRepository) - .deactivateTariffsByRegionAndCitiesAndStations(1L, List.of(1L, 11L), List.of(1L, 12L)); + .deactivateTariffsByRegionAndCitiesAndStations(1L, List.of(1L, 11L), List.of(1L, 12L)); } } } } private void doMockForTariffWithAllParams( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists, + boolean isCourierExists) { when(regionRepository.existsRegionById(anyLong())).thenReturn(isRegionExists); if (isRegionExists) { when(deactivateTariffsForChosenParamRepository - .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistForRegion); + .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistForRegion); if (isCitiesExistForRegion) { when(deactivateTariffsForChosenParamRepository - .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); + .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); if (isReceivingStationsExists) { when(courierRepository.existsCourierById(anyLong())).thenReturn(isCourierExists); } @@ -2548,10 +2435,10 @@ private void doMockForTariffWithAllParams( } private void verifyForTariffWithAllParams( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists, + boolean isCourierExists) { verify(regionRepository).existsRegionById(1L); if (isRegionExists) { verify(deactivateTariffsForChosenParamRepository).isCitiesExistForRegion(List.of(1L, 11L), 1L); @@ -2561,7 +2448,7 @@ private void verifyForTariffWithAllParams( verify(courierRepository).existsCourierById(1L); if (isCourierExists) { verify(deactivateTariffsForChosenParamRepository) - .deactivateTariffsByAllParam(1L, List.of(1L, 11L), List.of(1L, 12L), 1L); + .deactivateTariffsByAllParam(1L, List.of(1L, 11L), List.of(1L, 12L), 1L); } } } @@ -2571,7 +2458,7 @@ private void verifyForTariffWithAllParams( @Test void deactivateTariffByRegionsAndReceivingStations() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); doMockForTariffWithRegionAndStation(true, true); superAdminService.switchActivationStatusByChosenParams(details); @@ -2579,24 +2466,24 @@ void deactivateTariffByRegionsAndReceivingStations() { } private void doMockForTariffWithRegionAndStation( - boolean isRegionExists, - boolean isReceivingStationsExists) { + boolean isRegionExists, + boolean isReceivingStationsExists) { when(regionRepository.existsRegionById(anyLong())).thenReturn(isRegionExists); if (isRegionExists) { when(deactivateTariffsForChosenParamRepository - .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); + .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); } } private void verifyForTariffWithRegionAndStation( - boolean isRegionExists, - boolean isReceivingStationsExists) { + boolean isRegionExists, + boolean isReceivingStationsExists) { verify(regionRepository).existsRegionById(1L); if (isRegionExists) { verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); if (isReceivingStationsExists) { verify(tariffsInfoRepository) - .deactivateTariffsByRegionAndReceivingStations(1L, List.of(1L, 12L)); + .deactivateTariffsByRegionAndReceivingStations(1L, List.of(1L, 12L)); } } } @@ -2604,37 +2491,37 @@ private void verifyForTariffWithRegionAndStation( @Test void deactivateTariffByNotExistingRegionsAndReceivingStationsTrows() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); when(regionRepository.existsRegionById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(regionRepository).existsRegionById(1L); verify(tariffsInfoRepository, never()).deactivateTariffsByRegionAndReceivingStations( - anyLong(), - anyList()); + anyLong(), + anyList()); } @Test void deactivateTariffByRegionsAndNotExistingReceivingStationsTrows() { DetailsOfDeactivateTariffsDto details1 = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); when(regionRepository.existsRegionById(anyLong())).thenReturn(true); when(deactivateTariffsForChosenParamRepository.isReceivingStationsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details1)); + () -> superAdminService.switchActivationStatusByChosenParams(details1)); verify(regionRepository).existsRegionById(1L); verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); verify(tariffsInfoRepository, never()).deactivateTariffsByRegionAndReceivingStations( - anyLong(), - anyList()); + anyLong(), + anyList()); } @Test void deactivateTariffByCourierAndRegionAndCities() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities(); doMockForTariffWithCourierAndRegionAndCities(true, true, true); superAdminService.switchActivationStatusByChosenParams(details); @@ -2642,13 +2529,13 @@ void deactivateTariffByCourierAndRegionAndCities() { } private void doMockForTariffWithCourierAndRegionAndCities( - boolean isRegionExists, - boolean isCitiesExistsForRegion, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistsForRegion, + boolean isCourierExists) { when(regionRepository.existsRegionById(anyLong())).thenReturn(isRegionExists); if (isRegionExists) { when(deactivateTariffsForChosenParamRepository - .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistsForRegion); + .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistsForRegion); if (isCitiesExistsForRegion) { when(courierRepository.existsCourierById(anyLong())).thenReturn(isCourierExists); } @@ -2656,9 +2543,9 @@ private void doMockForTariffWithCourierAndRegionAndCities( } private void verifyForTariffWithCourierAndRegionAndCities( - boolean isRegionExists, - boolean isCitiesExistsForRegion, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistsForRegion, + boolean isCourierExists) { verify(regionRepository).existsRegionById(1L); if (isRegionExists) { verify(deactivateTariffsForChosenParamRepository).isCitiesExistForRegion(List.of(1L, 11L), 1L); @@ -2666,7 +2553,7 @@ private void verifyForTariffWithCourierAndRegionAndCities( verify(courierRepository).existsCourierById(1L); if (isCourierExists) { verify(tariffsInfoRepository) - .deactivateTariffsByCourierAndRegionAndCities(1L, List.of(1L, 11L), 1L); + .deactivateTariffsByCourierAndRegionAndCities(1L, List.of(1L, 11L), 1L); } } } @@ -2675,26 +2562,26 @@ private void verifyForTariffWithCourierAndRegionAndCities( @ParameterizedTest @MethodSource("deactivateTariffByNotExistingSomeOfTreeParameters") void deactivateTariffByCourierAndRegionsAndCitiesWithNotExistingParamThrows( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isCourierExists) { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities(); doMockForTariffWithCourierAndRegionAndCities(isRegionExists, isCitiesExistForRegion, - isCourierExists); + isCourierExists); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verifyForTariffWithCourierAndRegionAndCities(isRegionExists, isCitiesExistForRegion, - isCourierExists); + isCourierExists); verify(tariffsInfoRepository, never()) - .deactivateTariffsByCourierAndRegionAndCities(anyLong(), anyList(), anyLong()); + .deactivateTariffsByCourierAndRegionAndCities(anyLong(), anyList(), anyLong()); } @Test void deactivateTariffByCourierAndRegionAndReceivingStation() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations(); doMockForTariffWithCourierAndRegionAndReceivingStation(true, true, true); superAdminService.switchActivationStatusByChosenParams(details); @@ -2702,13 +2589,13 @@ void deactivateTariffByCourierAndRegionAndReceivingStation() { } private void doMockForTariffWithCourierAndRegionAndReceivingStation( - boolean isRegionExists, - boolean isCourierExists, - boolean isReceivingStationExists) { + boolean isRegionExists, + boolean isCourierExists, + boolean isReceivingStationExists) { when(regionRepository.existsRegionById(anyLong())).thenReturn(isRegionExists); if (isRegionExists) { when(deactivateTariffsForChosenParamRepository - .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationExists); + .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationExists); if (isReceivingStationExists) { when(courierRepository.existsCourierById(anyLong())).thenReturn(isCourierExists); } @@ -2716,9 +2603,9 @@ private void doMockForTariffWithCourierAndRegionAndReceivingStation( } private void verifyForTariffWithCourierAndRegionAndReceivingStation( - boolean isRegionExists, - boolean isCourierExists, - boolean isReceivingStationExists) { + boolean isRegionExists, + boolean isCourierExists, + boolean isReceivingStationExists) { verify(regionRepository).existsRegionById(1L); if (isRegionExists) { verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); @@ -2726,7 +2613,7 @@ private void verifyForTariffWithCourierAndRegionAndReceivingStation( verify(courierRepository).existsCourierById(1L); if (isCourierExists) { verify(tariffsInfoRepository) - .deactivateTariffsByCourierAndRegionAndReceivingStations(1L, List.of(1L, 12L), 1L); + .deactivateTariffsByCourierAndRegionAndReceivingStations(1L, List.of(1L, 12L), 1L); } } } @@ -2735,19 +2622,19 @@ private void verifyForTariffWithCourierAndRegionAndReceivingStation( @ParameterizedTest @MethodSource("deactivateTariffByNotExistingSomeOfTreeParameters") void deactivateTariffByCourierAndRegionsAndReceivingStationWithNotExistingParamThrows( - boolean isRegionExists, - boolean isCourierExists, - boolean isReceivingStationExists) { + boolean isRegionExists, + boolean isCourierExists, + boolean isReceivingStationExists) { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations(); doMockForTariffWithCourierAndRegionAndReceivingStation(isRegionExists, isReceivingStationExists, - isCourierExists); + isCourierExists); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verifyForTariffWithCourierAndRegionAndReceivingStation(isRegionExists, isReceivingStationExists, - isCourierExists); + isCourierExists); verify(tariffsInfoRepository, never()) - .deactivateTariffsByCourierAndRegionAndCities(anyLong(), anyList(), anyLong()); + .deactivateTariffsByCourierAndRegionAndCities(anyLong(), anyList(), anyLong()); } } \ No newline at end of file diff --git a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java index 2938b9c9c..6466498f6 100644 --- a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java @@ -77,7 +77,6 @@ import greencity.repository.EventRepository; import greencity.repository.LocationRepository; import greencity.repository.OrderAddressRepository; -import greencity.repository.OrderBagRepository; import greencity.repository.OrderPaymentStatusTranslationRepository; import greencity.repository.OrderRepository; import greencity.repository.OrderStatusTranslationRepository; @@ -230,19 +229,6 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -<<<<<<< HEAD -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.lenient; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.anyString; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.anyList; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.spy; -======= ->>>>>>> dev @ExtendWith({MockitoExtension.class}) class UBSClientServiceImplTest { @@ -325,13 +311,7 @@ class UBSClientServiceImplTest { private ViberBotRepository viberBotRepository; @Mock private UBSManagementService ubsManagementService; -<<<<<<< HEAD - @Mock - private OrderBagRepository orderBagRepository; - @Mock -======= @InjectMocks ->>>>>>> dev private UBSClientServiceImpl ubsClientService; @Mock @@ -373,7 +353,7 @@ void testValidatePayment() { when(orderRepository.findById(anyLong())).thenReturn(Optional.of(order)); ubsService.validatePayment(dto); verify(eventService, times(1)) - .save("Замовлення Оплачено", "Система", order); + .save("Замовлення Оплачено", "Система", order); verify(paymentRepository, times(1)).save(payment); } @@ -416,28 +396,28 @@ void getFirstPageDataByTariffAndLocationIdShouldReturnExpectedData() { when(tariffsInfoRepository.findById(tariffsInfoId)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(locationId)).thenReturn(Optional.of(location)); when(tariffLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) - .thenReturn(Optional.of(tariffLocation)); - when(bagRepository.findAllActiveBagsByTariffsInfoId(tariffsInfoId)).thenReturn(bags); + .thenReturn(Optional.of(tariffLocation)); + when(bagRepository.findBagsByTariffsInfoId(tariffsInfoId)).thenReturn(bags); when(modelMapper.map(bags.get(0), BagTranslationDto.class)).thenReturn(bagTranslationDto); var userPointsAndAllBagsDtoActual = - ubsService.getFirstPageDataByTariffAndLocationId(uuid, tariffsInfoId, locationId); + ubsService.getFirstPageDataByTariffAndLocationId(uuid, tariffsInfoId, locationId); assertEquals( - userPointsAndAllBagsDtoExpected.getBags(), - userPointsAndAllBagsDtoActual.getBags()); + userPointsAndAllBagsDtoExpected.getBags(), + userPointsAndAllBagsDtoActual.getBags()); assertEquals( - userPointsAndAllBagsDtoExpected.getBags().get(0).getId(), - userPointsAndAllBagsDtoActual.getBags().get(0).getId()); + userPointsAndAllBagsDtoExpected.getBags().get(0).getId(), + userPointsAndAllBagsDtoActual.getBags().get(0).getId()); assertEquals( - userPointsAndAllBagsDtoExpected.getPoints(), - userPointsAndAllBagsDtoActual.getPoints()); + userPointsAndAllBagsDtoExpected.getPoints(), + userPointsAndAllBagsDtoActual.getPoints()); verify(userRepository).findUserByUuid(uuid); verify(tariffsInfoRepository).findById(tariffsInfoId); verify(locationRepository).findById(locationId); verify(tariffLocationRepository).findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location); - verify(bagRepository).findAllActiveBagsByTariffsInfoId(tariffsInfoId); + verify(bagRepository).findBagsByTariffsInfoId(tariffsInfoId); verify(modelMapper).map(bags.get(0), BagTranslationDto.class); } @@ -458,10 +438,10 @@ void getFirstPageDataByTariffAndLocationIdShouldThrowExceptionWhenTariffLocation when(tariffsInfoRepository.findById(tariffsInfoId)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(locationId)).thenReturn(Optional.of(location)); when(tariffLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); var exception = assertThrows(NotFoundException.class, () -> ubsService.getFirstPageDataByTariffAndLocationId( - uuid, tariffsInfoId, locationId)); + uuid, tariffsInfoId, locationId)); assertEquals(expectedErrorMessage, exception.getMessage()); @@ -470,7 +450,7 @@ void getFirstPageDataByTariffAndLocationIdShouldThrowExceptionWhenTariffLocation verify(locationRepository).findById(locationId); verify(tariffLocationRepository).findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location); - verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } @@ -492,7 +472,7 @@ void getFirstPageDataByTariffAndLocationIdShouldThrowExceptionWhenLocationDoesNo when(locationRepository.findById(locationId)).thenReturn(Optional.empty()); var exception = assertThrows(NotFoundException.class, () -> ubsService.getFirstPageDataByTariffAndLocationId( - uuid, tariffsInfoId, locationId)); + uuid, tariffsInfoId, locationId)); assertEquals(expectedErrorMessage, exception.getMessage()); @@ -501,7 +481,7 @@ void getFirstPageDataByTariffAndLocationIdShouldThrowExceptionWhenLocationDoesNo verify(locationRepository).findById(locationId); verify(tariffLocationRepository, never()).findTariffLocationByTariffsInfoAndLocation(any(), any()); - verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } @@ -522,7 +502,7 @@ void getFirstPageDataByTariffAndLocationIdShouldThrowExceptionWhenTariffDoesNotE when(tariffsInfoRepository.findById(tariffId)).thenReturn(Optional.empty()); var exception = assertThrows(NotFoundException.class, () -> ubsService.getFirstPageDataByTariffAndLocationId( - uuid, tariffId, locationId)); + uuid, tariffId, locationId)); assertEquals(expectedErrorMessage, exception.getMessage()); @@ -531,7 +511,7 @@ void getFirstPageDataByTariffAndLocationIdShouldThrowExceptionWhenTariffDoesNotE verify(locationRepository, never()).findById(anyLong()); verify(tariffLocationRepository, never()).findTariffLocationByTariffsInfoAndLocation(any(), any()); - verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), anyLong()); } @@ -549,7 +529,7 @@ void getFirstPageDataByTariffAndLocationIdShouldThrowExceptionWhenUserDoesNotExi when(userRepository.findUserByUuid(uuid)).thenReturn(Optional.empty()); var exception = assertThrows(NotFoundException.class, () -> ubsService.getFirstPageDataByTariffAndLocationId( - uuid, tariffsInfoId, locationId)); + uuid, tariffsInfoId, locationId)); assertEquals(USER_WITH_CURRENT_UUID_DOES_NOT_EXIST, exception.getMessage()); @@ -558,7 +538,7 @@ void getFirstPageDataByTariffAndLocationIdShouldThrowExceptionWhenUserDoesNotExi verify(tariffsInfoRepository, never()).findById(anyLong()); verify(locationRepository, never()).findById(anyLong()); verify(tariffLocationRepository, never()).findTariffLocationByTariffsInfoAndLocation(any(), any()); - verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } @@ -579,7 +559,7 @@ void checkIfTariffIsAvailableForCurrentLocationThrowExceptionWhenTariffIsDeactiv when(locationRepository.findById(locationId)).thenReturn(Optional.of(location)); var exception = assertThrows(BadRequestException.class, () -> ubsService.getFirstPageDataByTariffAndLocationId( - uuid, tariffsInfoId, locationId)); + uuid, tariffsInfoId, locationId)); assertEquals(TARIFF_OR_LOCATION_IS_DEACTIVATED, exception.getMessage()); @@ -588,7 +568,7 @@ void checkIfTariffIsAvailableForCurrentLocationThrowExceptionWhenTariffIsDeactiv verify(locationRepository).findById(locationId); verify(tariffLocationRepository, never()).findTariffLocationByTariffsInfoAndLocation(any(), any()); - verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } @@ -609,7 +589,7 @@ void checkIfTariffIsAvailableForCurrentLocationThrowExceptionWhenLocationIsDeact when(locationRepository.findById(locationId)).thenReturn(Optional.of(location)); var exception = assertThrows(BadRequestException.class, () -> ubsService.getFirstPageDataByTariffAndLocationId( - uuid, tariffsInfoId, locationId)); + uuid, tariffsInfoId, locationId)); assertEquals(TARIFF_OR_LOCATION_IS_DEACTIVATED, exception.getMessage()); @@ -618,7 +598,7 @@ void checkIfTariffIsAvailableForCurrentLocationThrowExceptionWhenLocationIsDeact verify(locationRepository).findById(locationId); verify(tariffLocationRepository, never()).findTariffLocationByTariffsInfoAndLocation(any(), any()); - verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } @@ -643,10 +623,10 @@ void checkIfTariffIsAvailableForCurrentLocationWhenLocationForTariffIsDeactivate when(tariffsInfoRepository.findById(tariffsInfoId)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(locationId)).thenReturn(Optional.of(location)); when(tariffLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) - .thenReturn(Optional.of(tariffLocation)); + .thenReturn(Optional.of(tariffLocation)); var exception = assertThrows(BadRequestException.class, () -> ubsService.getFirstPageDataByTariffAndLocationId( - uuid, tariffsInfoId, locationId)); + uuid, tariffsInfoId, locationId)); assertEquals(expectedErrorMessage, exception.getMessage()); @@ -655,7 +635,7 @@ void checkIfTariffIsAvailableForCurrentLocationWhenLocationForTariffIsDeactivate verify(locationRepository).findById(locationId); verify(tariffLocationRepository).findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location); - verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } @@ -670,9 +650,9 @@ void getFirstPageDataByOrderIdShouldReturnExpectedData() { var tariffsInfo = order.getTariffsInfo(); var tariffsInfoId = tariffsInfo.getId(); var location = order - .getUbsUser() - .getOrderAddress() - .getLocation(); + .getUbsUser() + .getOrderAddress() + .getLocation(); var tariffLocation = getTariffLocation(); var bags = getBag1list(); @@ -682,27 +662,27 @@ void getFirstPageDataByOrderIdShouldReturnExpectedData() { when(userRepository.findUserByUuid(uuid)).thenReturn(Optional.of(user)); when(orderRepository.findById(orderId)).thenReturn(Optional.of(order)); when(tariffLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) - .thenReturn(Optional.of(tariffLocation)); - when(bagRepository.findAllActiveBagsByTariffsInfoId(tariffsInfoId)).thenReturn(bags); + .thenReturn(Optional.of(tariffLocation)); + when(bagRepository.findBagsByTariffsInfoId(tariffsInfoId)).thenReturn(bags); when(modelMapper.map(bags.get(0), BagTranslationDto.class)).thenReturn(bagTranslationDto); var userPointsAndAllBagsDtoActual = - ubsService.getFirstPageDataByOrderId(uuid, orderId); + ubsService.getFirstPageDataByOrderId(uuid, orderId); assertEquals( - userPointsAndAllBagsDtoExpected.getBags(), - userPointsAndAllBagsDtoActual.getBags()); + userPointsAndAllBagsDtoExpected.getBags(), + userPointsAndAllBagsDtoActual.getBags()); assertEquals( - userPointsAndAllBagsDtoExpected.getBags().get(0).getId(), - userPointsAndAllBagsDtoActual.getBags().get(0).getId()); + userPointsAndAllBagsDtoExpected.getBags().get(0).getId(), + userPointsAndAllBagsDtoActual.getBags().get(0).getId()); assertEquals( - userPointsAndAllBagsDtoExpected.getPoints(), - userPointsAndAllBagsDtoActual.getPoints()); + userPointsAndAllBagsDtoExpected.getPoints(), + userPointsAndAllBagsDtoActual.getPoints()); verify(userRepository).findUserByUuid(uuid); verify(orderRepository).findById(orderId); verify(tariffLocationRepository).findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location); - verify(bagRepository).findAllActiveBagsByTariffsInfoId(tariffsInfoId); + verify(bagRepository).findBagsByTariffsInfoId(tariffsInfoId); verify(modelMapper).map(bags.get(0), BagTranslationDto.class); } @@ -717,7 +697,7 @@ void getFirstPageDataByOrderIdShouldThrowExceptionWhenUserDoesNotExist() { when(userRepository.findUserByUuid(uuid)).thenReturn(Optional.empty()); var exception = assertThrows(NotFoundException.class, () -> ubsService.getFirstPageDataByOrderId( - uuid, orderId)); + uuid, orderId)); assertEquals(USER_WITH_CURRENT_UUID_DOES_NOT_EXIST, exception.getMessage()); @@ -725,7 +705,7 @@ void getFirstPageDataByOrderIdShouldThrowExceptionWhenUserDoesNotExist() { verify(orderRepository, never()).findById(anyLong()); verify(tariffLocationRepository, never()).findTariffLocationByTariffsInfoAndLocation(any(), any()); - verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } @@ -743,7 +723,7 @@ void getFirstPageDataByOrderIdShouldThrowExceptionWhenOrderDoesNotExist() { when(orderRepository.findById(orderId)).thenReturn(Optional.empty()); var exception = assertThrows(NotFoundException.class, () -> ubsService.getFirstPageDataByOrderId( - uuid, orderId)); + uuid, orderId)); assertEquals(expectedErrorMessage, exception.getMessage()); @@ -751,7 +731,7 @@ void getFirstPageDataByOrderIdShouldThrowExceptionWhenOrderDoesNotExist() { verify(orderRepository).findById(orderId); verify(tariffLocationRepository, never()).findTariffLocationByTariffsInfoAndLocation(any(), any()); - verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } @@ -792,7 +772,7 @@ void testSaveToDB() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); @@ -848,7 +828,7 @@ void testSaveToDBWithTwoBags() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(1)).thenReturn(Optional.of(bag1)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag3)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); @@ -901,7 +881,7 @@ void testSaveToDBWithCertificates() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(certificateRepository.findById(anyString())).thenReturn(Optional.of(getCertificate())); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); @@ -957,7 +937,7 @@ void testSaveToDBWithDontSendLinkToFondy() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(certificateRepository.findById(anyString())).thenReturn(Optional.of(certificate)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); @@ -1007,7 +987,7 @@ void testSaveToDBWhenSumToPayLessThanPoints() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); @@ -1038,15 +1018,15 @@ void testSaveToDbThrowBadRequestExceptionPriceLowerThanLimit() throws IllegalAcc when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(getTariffInfo())); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, - () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); + () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); verify(userRepository, times(1)).findByUuid(anyString()); verify(tariffsInfoRepository, times(1)) - .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); + .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); verify(bagRepository, times(1)).findById(anyInt()); } @@ -1066,15 +1046,15 @@ void testSaveToDbThrowBadRequestExceptionPriceGreaterThanLimit() throws IllegalA when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(getTariffInfo())); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, - () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); + () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); verify(userRepository, times(1)).findByUuid(anyString()); verify(tariffsInfoRepository, times(1)) - .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); + .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); verify(bagRepository, times(1)).findById(anyInt()); } @@ -1108,15 +1088,15 @@ void testSaveToDBWShouldThrowBadRequestException() throws IllegalAccessException when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, - () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); + () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); verify(userRepository, times(1)).findByUuid(anyString()); verify(tariffsInfoRepository, times(1)) - .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); + .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); verify(bagRepository, times(1)).findById(any()); } @@ -1148,14 +1128,14 @@ void testSaveToDBWShouldThrowTariffNotFoundExceptionException() { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); + () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); verify(userRepository, times(1)).findByUuid(anyString()); verify(tariffsInfoRepository, times(1)) - .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); + .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); } @Test @@ -1194,15 +1174,15 @@ void testSaveToDBWShouldThrowBagNotFoundExceptionException() throws IllegalAcces when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(getTariffInfo())); when(bagRepository.findById(3)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); + () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); verify(userRepository, times(1)).findByUuid(anyString()); verify(tariffsInfoRepository, times(1)) - .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); + .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); verify(bagRepository).findById(3); } @@ -1235,7 +1215,7 @@ void testSaveToDBWithoutOrderUnpaid() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(getTariffInfo())); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto.getPersonalData(), UBSuser.class)).thenReturn(ubSuser); @@ -1246,7 +1226,7 @@ void testSaveToDBWithoutOrderUnpaid() throws IllegalAccessException { verify(userRepository, times(1)).findByUuid("35467585763t4sfgchjfuyetf"); verify(tariffsInfoRepository, times(1)) - .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); + .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); verify(bagRepository, times(2)).findById(any()); verify(ubsUserRepository, times(1)).findById(anyLong()); verify(modelMapper, times(1)).map(dto.getPersonalData(), UBSuser.class); @@ -1267,12 +1247,12 @@ void saveToDBFailPaidOrder() { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(orderRepository.findById(any())).thenReturn(Optional.of(order)); assertThrows(BadRequestException.class, - () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", 1L)); + () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", 1L)); } @Test @@ -1312,10 +1292,10 @@ void testSaveToDBThrowsException() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, - () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); + () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); } @Test @@ -1324,10 +1304,10 @@ void getSecondPageData() { PersonalDataDto expected = getOrderResponseDto().getPersonalData(); User user = getTestUser() - .setUuid(uuid) - .setRecipientEmail("mail@mail.ua") - .setRecipientPhone("067894522") - .setAlternateEmail("my@email.com"); + .setUuid(uuid) + .setRecipientEmail("mail@mail.ua") + .setRecipientPhone("067894522") + .setAlternateEmail("my@email.com"); List ubsUser = Arrays.asList(getUBSuser()); when(userRepository.findByUuid(uuid)).thenReturn(user); when(ubsUserRepository.findUBSuserByUser(user)).thenReturn(ubsUser); @@ -1344,10 +1324,10 @@ void getSecondPageDataWithUserFounded() { PersonalDataDto expected = getOrderResponseDto().getPersonalData(); User user = getTestUser() - .setUuid(uuid) - .setRecipientEmail("mail@mail.ua") - .setRecipientPhone("067894522") - .setAlternateEmail("my@email.com"); + .setUuid(uuid) + .setRecipientEmail("mail@mail.ua") + .setRecipientPhone("067894522") + .setAlternateEmail("my@email.com"); List ubsUser = Collections.singletonList(getUBSuser()); when(userRepository.findByUuid(uuid)).thenReturn(user); when(ubsUserRepository.findUBSuserByUser(user)).thenReturn(ubsUser); @@ -1366,12 +1346,12 @@ void checkCertificate() { Certificate certificate = getCertificate(); when(certificateRepository.findById("1111-1234")).thenReturn(Optional.of(certificate)); when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(CertificateDto.builder() - .code("1111-1234") - .certificateStatus("ACTIVE") - .creationDate(LocalDate.now()) - .dateOfUse(LocalDate.now().plusMonths(1)) - .points(10) - .build()); + .code("1111-1234") + .certificateStatus("ACTIVE") + .creationDate(LocalDate.now()) + .dateOfUse(LocalDate.now().plusMonths(1)) + .points(10) + .build()); assertEquals("ACTIVE", ubsService.checkCertificate("1111-1234").getCertificateStatus()); } @@ -1382,12 +1362,12 @@ void checkCertificateUSED() { certificate.setCertificateStatus(CertificateStatus.USED); when(certificateRepository.findById("1111-1234")).thenReturn(Optional.of(certificate)); when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(CertificateDto.builder() - .code("1111-1234") - .certificateStatus("USED") - .creationDate(LocalDate.now()) - .dateOfUse(LocalDate.now().plusMonths(1)) - .points(10) - .build()); + .code("1111-1234") + .certificateStatus("USED") + .creationDate(LocalDate.now()) + .dateOfUse(LocalDate.now().plusMonths(1)) + .points(10) + .build()); assertEquals("USED", ubsService.checkCertificate("1111-1234").getCertificateStatus()); } @@ -1415,26 +1395,26 @@ void getAllOrdersDoneByUser() { @Test void makeOrderAgain() { MakeOrderAgainDto dto = MakeOrderAgainDto.builder() - .orderId(1L) - .orderAmount(350L) - .bagOrderDtoList( - Arrays.asList( - BagOrderDto.builder() - .bagId(1) - .capacity(10) - .price(100.) - .bagAmount(1) - .name("name") - .nameEng("nameEng") - .build(), - BagOrderDto.builder() - .bagId(2) - .capacity(10) - .price(100.) - .name("name") - .nameEng("nameEng") - .build())) - .build(); + .orderId(1L) + .orderAmount(350L) + .bagOrderDtoList( + Arrays.asList( + BagOrderDto.builder() + .bagId(1) + .capacity(10) + .price(100.) + .bagAmount(1) + .name("name") + .nameEng("nameEng") + .build(), + BagOrderDto.builder() + .bagId(2) + .capacity(10) + .price(100.) + .name("name") + .nameEng("nameEng") + .build())) + .build(); Order order = getOrderDoneByUser(); order.setAmountOfBagsOrdered(Collections.singletonMap(1, 1)); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); @@ -1450,7 +1430,7 @@ void makeOrderAgain() { void makeOrderAgainShouldThrowOrderNotFoundException() { Locale locale = new Locale("en"); Exception thrown = assertThrows(NotFoundException.class, - () -> ubsService.makeOrderAgain(locale, 1L)); + () -> ubsService.makeOrderAgain(locale, 1L)); assertEquals(ORDER_WITH_CURRENT_ID_DOES_NOT_EXIST, thrown.getMessage()); } @@ -1461,9 +1441,9 @@ void makeOrderAgainShouldThrowBadOrderStatusException() { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); Locale locale = new Locale("en"); Exception thrown = assertThrows(BadRequestException.class, - () -> ubsService.makeOrderAgain(locale, 1L)); + () -> ubsService.makeOrderAgain(locale, 1L)); assertEquals(thrown.getMessage(), ErrorMessage.BAD_ORDER_STATUS_REQUEST - + order.getOrderStatus()); + + order.getOrderStatus()); } @Test @@ -1477,14 +1457,14 @@ void findUserByUuid() { @Test void findUserNotFoundException() { Exception thrown = assertThrows(UserNotFoundException.class, - () -> ubsService.findAllCurrentPointsForUser("87df9ad5-6393-441f-8423-8b2e770b01a8")); + () -> ubsService.findAllCurrentPointsForUser("87df9ad5-6393-441f-8423-8b2e770b01a8")); assertEquals(ErrorMessage.USER_WITH_CURRENT_ID_DOES_NOT_EXIST, thrown.getMessage()); } @Test void markUserAsDeactivatedByIdThrowsNotFoundException() { Exception thrown = assertThrows(NotFoundException.class, - () -> ubsService.markUserAsDeactivated(1L)); + () -> ubsService.markUserAsDeactivated(1L)); assertEquals(USER_WITH_CURRENT_UUID_DOES_NOT_EXIST, thrown.getMessage()); } @@ -1505,7 +1485,7 @@ void getsUserAndUserUbsAndViolationsInfoByOrderId() { when(userRepository.findByUuid(anyString())).thenReturn(getOrderDetails().getUser()); when(userRepository.countTotalUsersViolations(1L)).thenReturn(expectedResult.getTotalUserViolations()); when(userRepository.checkIfUserHasViolationForCurrentOrder(1L, 1L)) - .thenReturn(expectedResult.getUserViolationForCurrentOrder()); + .thenReturn(expectedResult.getUserViolationForCurrentOrder()); UserInfoDto actual = ubsService.getUserAndUserUbsAndViolationsInfoByOrderId(1L, anyString()); verify(orderRepository, times(1)).findById(1L); @@ -1523,7 +1503,7 @@ void getsUserAndUserUbsAndViolationsInfoByOrderIdWithoutSender() { when(userRepository.findByUuid(anyString())).thenReturn(getOrderDetailsWithoutSender().getUser()); when(userRepository.countTotalUsersViolations(1L)).thenReturn(expectedResult.getTotalUserViolations()); when(userRepository.checkIfUserHasViolationForCurrentOrder(1L, 1L)) - .thenReturn(expectedResult.getUserViolationForCurrentOrder()); + .thenReturn(expectedResult.getUserViolationForCurrentOrder()); UserInfoDto actual = ubsService.getUserAndUserUbsAndViolationsInfoByOrderId(1L, anyString()); verify(orderRepository, times(1)).findById(1L); @@ -1537,7 +1517,7 @@ void getsUserAndUserUbsAndViolationsInfoByOrderIdWithoutSender() { void getUserAndUserUbsAndViolationsInfoByOrderIdOrderNotFoundException() { when(orderRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsService.getUserAndUserUbsAndViolationsInfoByOrderId(1L, "abc")); + () -> ubsService.getUserAndUserUbsAndViolationsInfoByOrderId(1L, "abc")); } @Test @@ -1545,7 +1525,7 @@ void getUserAndUserUbsAndViolationsInfoByOrderIdAccessDeniedException() { when(orderRepository.findById(1L)).thenReturn(Optional.of(getOrder())); when(userRepository.findByUuid(anyString())).thenReturn(getTestUser()); assertThrows(AccessDeniedException.class, - () -> ubsService.getUserAndUserUbsAndViolationsInfoByOrderId(1L, "abc")); + () -> ubsService.getUserAndUserUbsAndViolationsInfoByOrderId(1L, "abc")); } @Test @@ -1555,28 +1535,28 @@ void updateUbsUserInfoInOrderThrowUBSuserNotFoundExceptionTest() { when(ubsUserRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(UBSuserNotFoundException.class, - () -> ubsService.updateUbsUserInfoInOrder(request, "abc")); + () -> ubsService.updateUbsUserInfoInOrder(request, "abc")); verify(ubsUserRepository).findById(1L); } @Test void updateUbsUserInfoInOrderTest() { UbsCustomersDtoUpdate request = UbsCustomersDtoUpdate.builder() - .recipientId(1L) - .recipientName("Anatolii") - .recipientSurName("Anatolii") - .recipientEmail("anatolii.andr@gmail.com") - .recipientPhoneNumber("095123456").build(); + .recipientId(1L) + .recipientName("Anatolii") + .recipientSurName("Anatolii") + .recipientEmail("anatolii.andr@gmail.com") + .recipientPhoneNumber("095123456").build(); Optional user = Optional.of(getUBSuser()); when(ubsUserRepository.findById(1L)).thenReturn(user); when(ubsUserRepository.save(user.get())).thenReturn(user.get()); UbsCustomersDto expected = UbsCustomersDto.builder() - .name("Anatolii Anatolii") - .email("anatolii.andr@gmail.com") - .phoneNumber("095123456") - .build(); + .name("Anatolii Anatolii") + .email("anatolii.andr@gmail.com") + .phoneNumber("095123456") + .build(); UbsCustomersDto actual = ubsService.updateUbsUserInfoInOrder(request, "abc"); assertEquals(expected, actual); @@ -1604,7 +1584,7 @@ void updateProfileData() { when(modelMapper.map(addressDto.get(0), OrderAddressDtoRequest.class)).thenReturn(updateAddressRequestDto); when(modelMapper.map(addressDto.get(1), OrderAddressDtoRequest.class)).thenReturn(updateAddressRequestDto); doReturn(new OrderWithAddressesResponseDto()) - .when(ubsClientService).updateCurrentAddressForOrder(updateAddressRequestDto, uuid); + .when(ubsClientService).updateCurrentAddressForOrder(updateAddressRequestDto, uuid); when(userRepository.save(user)).thenReturn(user); when(modelMapper.map(user, UserProfileUpdateDto.class)).thenReturn(userProfileUpdateDto); @@ -1636,7 +1616,7 @@ void updateProfileDataThrowNotFoundException() { when(userRepository.findUserByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsService.updateProfileData(uuid, userProfileUpdateDto)); + () -> ubsService.updateProfileData(uuid, userProfileUpdateDto)); verify(userRepository).findUserByUuid(uuid); } @@ -1686,7 +1666,7 @@ void updateProfileDataIfTelegramBotNotExists() { when(modelMapper.map(addressDto.get(0), OrderAddressDtoRequest.class)).thenReturn(updateAddressRequestDto); when(modelMapper.map(addressDto.get(1), OrderAddressDtoRequest.class)).thenReturn(updateAddressRequestDto); doReturn(new OrderWithAddressesResponseDto()) - .when(ubsClientService).updateCurrentAddressForOrder(updateAddressRequestDto, uuid); + .when(ubsClientService).updateCurrentAddressForOrder(updateAddressRequestDto, uuid); when(userRepository.save(user)).thenReturn(user); when(modelMapper.map(user, UserProfileUpdateDto.class)).thenReturn(userProfileUpdateDto); @@ -1732,7 +1712,7 @@ void getProfileDataNotFoundException() { when(userRepository.findUserByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsService.getProfileData(uuid)); + () -> ubsService.getProfileData(uuid)); verify(userRepository).findUserByUuid(uuid); } @@ -1762,28 +1742,28 @@ void testFindAllAddressesForCurrentOrder() { private List
getTestAddresses(User user) { Address address1 = Address.builder() - .addressStatus(AddressStatus.NEW).id(13L).city("Kyiv").district("Svyatoshyn") - .entranceNumber("1").houseCorpus("1").houseNumber("55").street("Peremohy av.") - .user(user).actual(true).coordinates(new Coordinates(12.5, 34.5)) - .build(); + .addressStatus(AddressStatus.NEW).id(13L).city("Kyiv").district("Svyatoshyn") + .entranceNumber("1").houseCorpus("1").houseNumber("55").street("Peremohy av.") + .user(user).actual(true).coordinates(new Coordinates(12.5, 34.5)) + .build(); Address address2 = Address.builder() - .addressStatus(AddressStatus.NEW).id(42L).city("Lviv").district("Syhiv") - .entranceNumber("1").houseCorpus("1").houseNumber("55").street("Lvivska st.") - .user(user).actual(true).coordinates(new Coordinates(13.5, 36.5)) - .build(); + .addressStatus(AddressStatus.NEW).id(42L).city("Lviv").district("Syhiv") + .entranceNumber("1").houseCorpus("1").houseNumber("55").street("Lvivska st.") + .user(user).actual(true).coordinates(new Coordinates(13.5, 36.5)) + .build(); return Arrays.asList(address1, address2); } private List getTestAddressesDto() { AddressDto addressDto1 = AddressDto.builder().actual(true).id(13L).city("Kyiv").district("Svyatoshyn") - .entranceNumber("1").houseCorpus("1").houseNumber("55").street("Peremohy av.") - .coordinates(new Coordinates(12.5, 34.5)).build(); + .entranceNumber("1").houseCorpus("1").houseNumber("55").street("Peremohy av.") + .coordinates(new Coordinates(12.5, 34.5)).build(); AddressDto addressDto2 = AddressDto.builder().actual(true).id(42L).city("Lviv").district("Syhiv") - .entranceNumber("1").houseCorpus("1").houseNumber("55").street("Lvivska st.") - .coordinates(new Coordinates(13.5, 36.5)).build(); + .entranceNumber("1").houseCorpus("1").houseNumber("55").street("Lvivska st.") + .coordinates(new Coordinates(13.5, 36.5)).build(); return Arrays.asList(addressDto1, addressDto2); } @@ -1802,18 +1782,18 @@ void testSaveCurrentAddressForOrder() { when(userRepository.findByUuid(user.getUuid())).thenReturn(user); when(addressRepository.findAllNonDeletedAddressesByUserId(user.getId())).thenReturn(addresses); when(googleApiService.getResultFromGeoCode(eq(dtoRequest.getPlaceId()), anyInt())) - .thenReturn(getGeocodingResult().get(0)); + .thenReturn(getGeocodingResult().get(0)); when(modelMapper.map(any(), - eq(OrderAddressDtoRequest.class))) + eq(OrderAddressDtoRequest.class))) .thenReturn(TEST_ORDER_ADDRESS_DTO_REQUEST); when(modelMapper.map(any(), - eq(Address.class))).thenReturn(addressToSave); + eq(Address.class))).thenReturn(addressToSave); when(modelMapper.map(addresses.get(0), - AddressDto.class)) + AddressDto.class)) .thenReturn(addressDto()); OrderWithAddressesResponseDto actualWithSearchAddress = - ubsService.saveCurrentAddressForOrder(createAddressRequestDto, uuid); + ubsService.saveCurrentAddressForOrder(createAddressRequestDto, uuid); assertEquals(getAddressDtoResponse(), actualWithSearchAddress); verify(addressRepository).save(addressToSave); @@ -1834,14 +1814,14 @@ void testSaveCurrentAddressForOrderAlreadyExistException() { when(userRepository.findByUuid(user.getUuid())).thenReturn(user); when(addressRepository.findAllNonDeletedAddressesByUserId(user.getId())).thenReturn(addresses); when(googleApiService.getResultFromGeoCode(eq(dtoRequest.getPlaceId()), anyInt())) - .thenReturn(getGeocodingResult().get(0)); + .thenReturn(getGeocodingResult().get(0)); dtoRequest.setPlaceId(null); when(modelMapper.map(any(), - eq(OrderAddressDtoRequest.class))) + eq(OrderAddressDtoRequest.class))) .thenReturn(dtoRequest); BadRequestException exception = assertThrows(BadRequestException.class, - () -> ubsService.saveCurrentAddressForOrder(createAddressRequestDto, uuid)); + () -> ubsService.saveCurrentAddressForOrder(createAddressRequestDto, uuid)); assertEquals(ADDRESS_ALREADY_EXISTS, exception.getMessage()); } @@ -1857,7 +1837,7 @@ void testSaveCurrentAddressForMaximumNumbersOfOrdersAddressesException() { when(addressRepository.findAllNonDeletedAddressesByUserId(user.getId())).thenReturn(addresses); BadRequestException exception = assertThrows(BadRequestException.class, - () -> ubsService.saveCurrentAddressForOrder(createAddressRequestDto, uuid)); + () -> ubsService.saveCurrentAddressForOrder(createAddressRequestDto, uuid)); assertEquals(ErrorMessage.NUMBER_OF_ADDRESSES_EXCEEDED, exception.getMessage()); } @@ -1878,33 +1858,33 @@ void testUpdateCurrentAddressForOrder() { when(userRepository.findByUuid(user.getUuid())).thenReturn(user); when(addressRepository.findAllNonDeletedAddressesByUserId(user.getId())).thenReturn(addresses); when(googleApiService.getResultFromGeoCode(eq(updateAddressRequestDto.getPlaceId()), anyInt())) - .thenReturn(getGeocodingResult().get(0)); + .thenReturn(getGeocodingResult().get(0)); when(modelMapper.map(any(), - eq(OrderAddressDtoRequest.class))) + eq(OrderAddressDtoRequest.class))) .thenReturn(TEST_ORDER_ADDRESS_DTO_REQUEST); when(addressRepository.findById(updateAddressRequestDto.getId())) - .thenReturn(Optional.ofNullable(addresses.get(0))); + .thenReturn(Optional.ofNullable(addresses.get(0))); when(modelMapper.map(any(), - eq(Address.class))).thenReturn(addresses.get(0)); + eq(Address.class))).thenReturn(addresses.get(0)); when(addressRepository.save(addresses.get(0))).thenReturn(addresses.get(0)); when(modelMapper.map(addresses.get(0), - AddressDto.class)) + AddressDto.class)) .thenReturn(addressDto()); OrderWithAddressesResponseDto actualWithSearchAddress = - ubsService.updateCurrentAddressForOrder(updateAddressRequestDto, uuid); + ubsService.updateCurrentAddressForOrder(updateAddressRequestDto, uuid); Assertions.assertNotNull(updateAddressRequestDto.getSearchAddress()); Assertions.assertNull(dtoRequest.getSearchAddress()); assertEquals(getAddressDtoResponse(), actualWithSearchAddress); verify(googleApiService, times(2)).getResultFromGeoCode(eq(updateAddressRequestDto.getPlaceId()), - anyInt()); + anyInt()); updateAddressRequestDto.setSearchAddress(null); OrderWithAddressesResponseDto actualWithoutSearchAddress = - ubsService.updateCurrentAddressForOrder(updateAddressRequestDto, uuid); + ubsService.updateCurrentAddressForOrder(updateAddressRequestDto, uuid); assertEquals(getAddressDtoResponse(), actualWithoutSearchAddress); verify(addressRepository, times(2)).save(addresses.get(0)); } @@ -1923,27 +1903,27 @@ void testUpdateCurrentAddressForOrderWithNoAddress() { when(userRepository.findByUuid(user.getUuid())).thenReturn(user); when(addressRepository.findById(updateAddressRequestDto.getId())) - .thenReturn(Optional.ofNullable(addresses.get(0))); + .thenReturn(Optional.ofNullable(addresses.get(0))); when(googleApiService.getResultFromGeoCode(eq(updateAddressRequestDto.getPlaceId()), anyInt())) - .thenReturn(getGeocodingResult().get(0)); + .thenReturn(getGeocodingResult().get(0)); when(addressRepository.findById(updateAddressRequestDto.getId())) - .thenReturn(Optional.ofNullable(addresses.get(0))); + .thenReturn(Optional.ofNullable(addresses.get(0))); when(modelMapper.map(any(), - eq(Address.class))).thenReturn(addresses.get(0)); + eq(Address.class))).thenReturn(addresses.get(0)); when(addressRepository.save(addresses.get(0))).thenReturn(addresses.get(0)); OrderWithAddressesResponseDto actualWithSearchAddress = - ubsService.updateCurrentAddressForOrder(updateAddressRequestDto, uuid); + ubsService.updateCurrentAddressForOrder(updateAddressRequestDto, uuid); Assertions.assertNotNull(updateAddressRequestDto.getSearchAddress()); Assertions.assertNull(dtoRequest.getSearchAddress()); assertEquals(OrderWithAddressesResponseDto.builder().addressList(Collections.emptyList()).build(), - actualWithSearchAddress); + actualWithSearchAddress); verify(googleApiService, times(2)).getResultFromGeoCode(eq(updateAddressRequestDto.getPlaceId()), - anyInt()); + anyInt()); verify(addressRepository, times(1)).save(addresses.get(0)); verify(addressRepository, times(1)).findById(anyLong()); verify(modelMapper, times(1)).map(any(), eq(Address.class)); @@ -1965,16 +1945,16 @@ void testUpdateCurrentAddressForOrderAlreadyExistException() { when(userRepository.findByUuid(user.getUuid())).thenReturn(user); when(addressRepository.findById(updateAddressRequestDto.getId())) - .thenReturn(Optional.ofNullable(addresses.get(0))); + .thenReturn(Optional.ofNullable(addresses.get(0))); when(addressRepository.findAllNonDeletedAddressesByUserId(user.getId())).thenReturn(addresses); when(googleApiService.getResultFromGeoCode(eq(updateAddressRequestDto.getPlaceId()), anyInt())) - .thenReturn(getGeocodingResult().get(0)); + .thenReturn(getGeocodingResult().get(0)); when(modelMapper.map(any(), - eq(OrderAddressDtoRequest.class))) + eq(OrderAddressDtoRequest.class))) .thenReturn(dtoRequest); BadRequestException exception = assertThrows(BadRequestException.class, - () -> ubsService.updateCurrentAddressForOrder(updateAddressRequestDto, uuid)); + () -> ubsService.updateCurrentAddressForOrder(updateAddressRequestDto, uuid)); assertEquals(ADDRESS_ALREADY_EXISTS, exception.getMessage()); } @@ -1996,7 +1976,7 @@ void testUpdateCurrentAddressForOrderNotFoundOrderAddressException() { when(addressRepository.findById(updateAddressRequestDto.getId())).thenReturn(Optional.empty()); NotFoundException exception = assertThrows(NotFoundException.class, - () -> ubsService.updateCurrentAddressForOrder(updateAddressRequestDto, uuid)); + () -> ubsService.updateCurrentAddressForOrder(updateAddressRequestDto, uuid)); assertEquals(NOT_FOUND_ADDRESS_ID_FOR_CURRENT_USER + updateAddressRequestDto.getId(), exception.getMessage()); } @@ -2022,7 +2002,7 @@ void testUpdateCurrentAddressForOrderThrowsAccessDeniedException() { when(userRepository.findByUuid(user.getUuid())).thenReturn(user); AccessDeniedException exception = assertThrows(AccessDeniedException.class, - () -> ubsService.updateCurrentAddressForOrder(dtoRequest, uuid)); + () -> ubsService.updateCurrentAddressForOrder(dtoRequest, uuid)); assertEquals(CANNOT_ACCESS_PERSONAL_INFO, exception.getMessage()); } @@ -2079,7 +2059,7 @@ void testDeleteCurrentAddressForOrderWhenAddressIsActual() { when(addressRepository.findById(firstAddressId)).thenReturn(Optional.of(firstAddress)); when(addressRepository.findAnyByUserIdAndAddressStatusNotDeleted(user.getId())) - .thenReturn(Optional.of(secondAddress)); + .thenReturn(Optional.of(secondAddress)); doReturn(new OrderWithAddressesResponseDto()).when(ubsClientService).findAllAddressesForCurrentOrder(uuid); ubsClientService.deleteCurrentAddressForOrder(firstAddressId, uuid); @@ -2126,7 +2106,7 @@ void testDeleteCurrentAddressForOrderWithUnexistingAddress() { when(addressRepository.findById(addressId)).thenReturn(Optional.empty()); NotFoundException exception = assertThrows(NotFoundException.class, - () -> ubsClientService.deleteCurrentAddressForOrder(addressId, "qwe")); + () -> ubsClientService.deleteCurrentAddressForOrder(addressId, "qwe")); assertEquals(NOT_FOUND_ADDRESS_ID_FOR_CURRENT_USER + addressId, exception.getMessage()); @@ -2149,7 +2129,7 @@ void testDeleteCurrentAddressForOrderForWrongUser() { when(addressRepository.findById(firstAddressId)).thenReturn(Optional.of(firstAddress)); AccessDeniedException exception = assertThrows(AccessDeniedException.class, - () -> ubsClientService.deleteCurrentAddressForOrder(firstAddressId, uuid)); + () -> ubsClientService.deleteCurrentAddressForOrder(firstAddressId, uuid)); assertEquals(CANNOT_DELETE_ADDRESS, exception.getMessage()); @@ -2173,7 +2153,7 @@ void testDeleteCurrentAddressForOrderWhenAddressAlreadyDeleted() { when(addressRepository.findById(firstAddressId)).thenReturn(Optional.of(firstAddress)); BadRequestException exception = assertThrows(BadRequestException.class, - () -> ubsClientService.deleteCurrentAddressForOrder(firstAddressId, uuid)); + () -> ubsClientService.deleteCurrentAddressForOrder(firstAddressId, uuid)); assertEquals(CANNOT_DELETE_ALREADY_DELETED_ADDRESS, exception.getMessage()); @@ -2247,7 +2227,7 @@ void testMakeAddressActualWhereUserNotHaveActualAddress() { when(addressRepository.findByUserIdAndActualTrue(user.getId())).thenReturn(Optional.empty()); NotFoundException exception = assertThrows(NotFoundException.class, - () -> ubsService.makeAddressActual(firstAddressId, uuid)); + () -> ubsService.makeAddressActual(firstAddressId, uuid)); assertEquals(ACTUAL_ADDRESS_NOT_FOUND, exception.getMessage()); @@ -2286,7 +2266,7 @@ void testMakeAddressActualWhenAddressNotFound() { when(addressRepository.findById(firstAddressId)).thenReturn(Optional.empty()); NotFoundException exception = assertThrows(NotFoundException.class, - () -> ubsService.makeAddressActual(firstAddressId, uuid)); + () -> ubsService.makeAddressActual(firstAddressId, uuid)); assertEquals(NOT_FOUND_ADDRESS_ID_FOR_CURRENT_USER + firstAddressId, exception.getMessage()); @@ -2311,7 +2291,7 @@ void testMakeAddressActualWhenAddressNotBelongsToUser() { when(addressRepository.findById(firstAddressId)).thenReturn(Optional.of(firstAddress)); AccessDeniedException exception = assertThrows(AccessDeniedException.class, - () -> ubsService.makeAddressActual(firstAddressId, uuid)); + () -> ubsService.makeAddressActual(firstAddressId, uuid)); assertEquals(CANNOT_ACCESS_PERSONAL_INFO, exception.getMessage()); @@ -2334,7 +2314,7 @@ void testMakeAddressActualWhenAddressIdDeleted() { when(addressRepository.findById(firstAddressId)).thenReturn(Optional.of(firstAddress)); BadRequestException exception = assertThrows(BadRequestException.class, - () -> ubsService.makeAddressActual(firstAddressId, uuid)); + () -> ubsService.makeAddressActual(firstAddressId, uuid)); assertEquals(CANNOT_MAKE_ACTUAL_DELETED_ADDRESS, exception.getMessage()); @@ -2398,7 +2378,7 @@ void getOrderPaymentDetailIfPaymentIsEmpty() { void getOrderPaymentDetailShouldThrowOrderNotFoundException() { when(orderRepository.findById(any())).thenReturn(Optional.empty()); Exception thrown = assertThrows(NotFoundException.class, - () -> ubsService.getOrderPaymentDetail(null)); + () -> ubsService.getOrderPaymentDetail(null)); assertEquals(ORDER_WITH_CURRENT_ID_DOES_NOT_EXIST, thrown.getMessage()); } @@ -2419,7 +2399,7 @@ void testGetOrderCancellationReason() { void getOrderCancellationReasonOrderNotFoundException() { when(orderRepository.findById(anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsService.getOrderCancellationReason(1L, "abc")); + () -> ubsService.getOrderCancellationReason(1L, "abc")); } @Test @@ -2427,7 +2407,7 @@ void getOrderCancellationReasonAccessDeniedException() { when(orderRepository.findById(anyLong())).thenReturn(Optional.ofNullable(getOrderTest())); when(userRepository.findByUuid(anyString())).thenReturn(getTestUser()); assertThrows(AccessDeniedException.class, - () -> ubsService.getOrderCancellationReason(1L, "abc")); + () -> ubsService.getOrderCancellationReason(1L, "abc")); } @Test @@ -2441,7 +2421,7 @@ void testUpdateOrderCancellationReason() { OrderCancellationReasonDto result = ubsService.updateOrderCancellationReason(1L, dto, anyString()); verify(eventService, times(1)) - .saveEvent("Статус Замовлення - Скасовано", "", orderDto); + .saveEvent("Статус Замовлення - Скасовано", "", orderDto); assertEquals(dto.getCancellationReason(), result.getCancellationReason()); assertEquals(dto.getCancellationComment(), result.getCancellationComment()); verify(orderRepository).save(orderDto); @@ -2452,7 +2432,7 @@ void testUpdateOrderCancellationReason() { void updateOrderCancellationReasonOrderNotFoundException() { when(orderRepository.findById(anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsService.updateOrderCancellationReason(1L, null, "abc")); + () -> ubsService.updateOrderCancellationReason(1L, null, "abc")); } @Test @@ -2460,7 +2440,7 @@ void updateOrderCancellationReasonAccessDeniedException() { when(orderRepository.findById(anyLong())).thenReturn(Optional.ofNullable(getOrderTest())); when(userRepository.findByUuid(anyString())).thenReturn(getTestUser()); assertThrows(AccessDeniedException.class, - () -> ubsService.updateOrderCancellationReason(1L, null, "abc")); + () -> ubsService.updateOrderCancellationReason(1L, null, "abc")); } @Test @@ -2469,8 +2449,8 @@ void testGelAllEventsFromOrderByOrderId() { when(orderRepository.findById(1L)).thenReturn(getOrderWithEvents()); when(eventRepository.findAllEventsByOrderId(1L)).thenReturn(orderEvents); List eventDTOS = orderEvents.stream() - .map(event -> modelMapper.map(event, EventDto.class)) - .collect(Collectors.toList()); + .map(event -> modelMapper.map(event, EventDto.class)) + .collect(Collectors.toList()); assertEquals(eventDTOS, ubsService.getAllEventsForOrder(1L, anyString())); } @@ -2478,7 +2458,7 @@ void testGelAllEventsFromOrderByOrderId() { void testGelAllEventsFromOrderByOrderIdWithThrowingOrderNotFindException() { when(orderRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsService.getAllEventsForOrder(1L, "abc")); + () -> ubsService.getAllEventsForOrder(1L, "abc")); } @Test @@ -2486,28 +2466,25 @@ void testGelAllEventsFromOrderByOrderIdWithThrowingEventsNotFoundException() { when(orderRepository.findById(1L)).thenReturn(getOrderWithEvents()); when(eventRepository.findAllEventsByOrderId(1L)).thenReturn(Collections.emptyList()); assertThrows(NotFoundException.class, - () -> ubsService.getAllEventsForOrder(1L, "abc")); + () -> ubsService.getAllEventsForOrder(1L, "abc")); } @Test void deleteOrder() { Order order = getOrder(); - order.setOrderBags(Collections.emptyList()); when(ordersForUserRepository.getAllByUserUuidAndId(order.getUser().getUuid(), order.getId())) - .thenReturn(order); - doNothing().when(orderBagRepository).deleteAll(anyList()); + .thenReturn(order); ubsService.deleteOrder(order.getUser().getUuid(), 1L); verify(orderRepository).delete(order); - verify(orderBagRepository).deleteAll(anyList()); } @Test void deleteOrderFail() { Order order = getOrder(); when(ordersForUserRepository.getAllByUserUuidAndId(order.getUser().getUuid(), order.getId())) - .thenReturn(null); + .thenReturn(null); assertThrows(NotFoundException.class, () -> { ubsService.deleteOrder("UUID", 1L); @@ -2591,7 +2568,7 @@ void processOrderFondyClient2() throws Exception { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(userRepository.findUserByUuid("uuid")).thenReturn(Optional.of(user)); when(certificateRepository.findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), - CertificateStatus.ACTIVE)).thenReturn(Set.of(certificate)); + CertificateStatus.ACTIVE)).thenReturn(Set.of(certificate)); when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(TEST_BAG_LIST); when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(certificateDto); when(modelMapper.map(any(Bag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); @@ -2601,7 +2578,7 @@ void processOrderFondyClient2() throws Exception { verify(orderRepository).findById(1L); verify(userRepository).findUserByUuid("uuid"); verify(certificateRepository).findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), - CertificateStatus.ACTIVE); + CertificateStatus.ACTIVE); verify(bagRepository).findBagsByOrderId(order.getId()); verify(modelMapper).map(certificate, CertificateDto.class); verify(modelMapper).map(any(Bag.class), eq(BagForUserDto.class)); @@ -2641,7 +2618,7 @@ void processOrderFondyClientCertificeteNotFoundExeption() throws Exception { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(userRepository.findUserByUuid("uuid")).thenReturn(Optional.of(user)); when(certificateRepository.findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), - CertificateStatus.ACTIVE)).thenReturn(Collections.emptySet()); + CertificateStatus.ACTIVE)).thenReturn(Collections.emptySet()); when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(TEST_BAG_LIST); when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(certificateDto); when(modelMapper.map(any(Bag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); @@ -2651,7 +2628,7 @@ void processOrderFondyClientCertificeteNotFoundExeption() throws Exception { verify(orderRepository).findById(1L); verify(userRepository).findUserByUuid("uuid"); verify(certificateRepository).findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), - CertificateStatus.ACTIVE); + CertificateStatus.ACTIVE); verify(bagRepository).findBagsByOrderId(order.getId()); verify(modelMapper).map(certificate, CertificateDto.class); verify(modelMapper).map(any(Bag.class), eq(BagForUserDto.class)); @@ -2691,7 +2668,7 @@ void processOrderFondyClientCertificeteNotFoundExeption2() throws Exception { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(userRepository.findUserByUuid("uuid")).thenReturn(Optional.of(user)); when(certificateRepository.findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), - CertificateStatus.ACTIVE)).thenReturn(Set.of(certificate)); + CertificateStatus.ACTIVE)).thenReturn(Set.of(certificate)); when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(TEST_BAG_LIST); when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(certificateDto); when(modelMapper.map(any(Bag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); @@ -2701,7 +2678,7 @@ void processOrderFondyClientCertificeteNotFoundExeption2() throws Exception { verify(orderRepository).findById(1L); verify(userRepository).findUserByUuid("uuid"); verify(certificateRepository).findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), - CertificateStatus.ACTIVE); + CertificateStatus.ACTIVE); verify(bagRepository).findBagsByOrderId(order.getId()); verify(modelMapper).map(certificate, CertificateDto.class); verify(modelMapper).map(any(Bag.class), eq(BagForUserDto.class)); @@ -2799,7 +2776,7 @@ void saveFullOrderToDBForIF() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(getTariffInfo())); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); @@ -2854,7 +2831,7 @@ void saveFullOrderToDBWhenSumToPayeqNull() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(getTariffInfo())); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(addressRepository.findById(any())).thenReturn(Optional.of(address)); @@ -2902,7 +2879,7 @@ void testSaveToDBfromIForIFThrowsException() throws IllegalAccessException { } when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfoWithLimitOfBags())); + .thenReturn(Optional.of(getTariffInfoWithLimitOfBags())); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, () -> { ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null); @@ -2943,7 +2920,7 @@ void testCheckSumIfCourierLimitBySumOfOrderForIF1() throws IllegalAccessExceptio when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); @@ -2987,7 +2964,7 @@ void testCheckSumIfCourierLimitBySumOfOrderForIF2() throws InvocationTargetExcep when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, () -> { @@ -3015,7 +2992,7 @@ void validatePaymentClientExceptionTest() { PaymentResponseDto dto = getPaymentResponseDto(); when(orderRepository.findById(1L)) - .thenReturn(Optional.ofNullable(getOrdersDto())); + .thenReturn(Optional.ofNullable(getOrdersDto())); assertThrows(BadRequestException.class, () -> ubsService.validatePaymentClient(dto)); } @@ -3053,8 +3030,8 @@ void findAllCurrentPointsForUser() { void getPaymentResponseFromFondy() { Order order = getOrder(); FondyPaymentResponse expected = FondyPaymentResponse.builder() - .paymentStatus(order.getPayment().get(0).getResponseStatus()) - .build(); + .paymentStatus(order.getPayment().get(0).getResponseStatus()) + .build(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(userRepository.findByUuid(order.getUser().getUuid())).thenReturn(order.getUser()); @@ -3117,14 +3094,14 @@ void getOrderForUserTest() { orderList.add(order); when(ordersForUserRepository.getAllByUserUuidAndId(user.getUuid(), order.getId())) - .thenReturn(order); + .thenReturn(order); when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(bags); when(modelMapper.map(bag, BagForUserDto.class)).thenReturn(bagForUserDto); when(orderStatusTranslationRepository - .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) + .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) .thenReturn(Optional.of(orderStatusTranslation)); when(orderPaymentStatusTranslationRepository.getById( - (long) order.getOrderPaymentStatus().getStatusValue())) + (long) order.getOrderPaymentStatus().getStatusValue())) .thenReturn(orderPaymentStatusTranslation); ubsService.getOrderForUser(user.getUuid(), 1L); @@ -3132,10 +3109,10 @@ void getOrderForUserTest() { verify(modelMapper, times(bags.size())).map(bag, BagForUserDto.class); verify(bagRepository).findBagsByOrderId(order.getId()); verify(orderStatusTranslationRepository, times(orderList.size())) - .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); + .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); verify(orderPaymentStatusTranslationRepository, times(orderList.size())) - .getById( - (long) order.getOrderPaymentStatus().getStatusValue()); + .getById( + (long) order.getOrderPaymentStatus().getStatusValue()); } @Test @@ -3144,7 +3121,7 @@ void getOrderForUserFail() { User user = getTestUser(); when(ordersForUserRepository.getAllByUserUuidAndId("UUID", order.getId())) - .thenReturn(null); + .thenReturn(null); assertThrows(NotFoundException.class, () -> { ubsService.getOrderForUser("UUID", 1L); @@ -3175,14 +3152,14 @@ void getOrdersForUserTest() { Page page = new PageImpl<>(orderList, pageable, 1); when(ordersForUserRepository.getAllByUserUuid(pageable, user.getUuid())) - .thenReturn(page); + .thenReturn(page); when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(bags); when(modelMapper.map(bag, BagForUserDto.class)).thenReturn(bagForUserDto); when(orderStatusTranslationRepository - .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) + .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) .thenReturn(Optional.of(orderStatusTranslation)); when(orderPaymentStatusTranslationRepository.getById( - (long) order.getOrderPaymentStatus().getStatusValue())) + (long) order.getOrderPaymentStatus().getStatusValue())) .thenReturn(orderPaymentStatusTranslation); PageableDto dto = ubsService.getOrdersForUser(user.getUuid(), pageable, null); @@ -3193,10 +3170,10 @@ void getOrdersForUserTest() { verify(modelMapper, times(bags.size())).map(bag, BagForUserDto.class); verify(bagRepository).findBagsByOrderId(order.getId()); verify(orderStatusTranslationRepository, times(orderList.size())) - .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); + .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); verify(orderPaymentStatusTranslationRepository, times(orderList.size())) - .getById( - (long) order.getOrderPaymentStatus().getStatusValue()); + .getById( + (long) order.getOrderPaymentStatus().getStatusValue()); verify(ordersForUserRepository).getAllByUserUuid(pageable, user.getUuid()); } @@ -3224,14 +3201,14 @@ void testOrdersForUserWithExportedQuantity() { Page page = new PageImpl<>(orderList, pageable, 1); when(ordersForUserRepository.getAllByUserUuid(pageable, user.getUuid())) - .thenReturn(page); + .thenReturn(page); when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(bags); when(modelMapper.map(bag, BagForUserDto.class)).thenReturn(bagForUserDto); when(orderStatusTranslationRepository - .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) + .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) .thenReturn(Optional.of(orderStatusTranslation)); when(orderPaymentStatusTranslationRepository.getById( - (long) order.getOrderPaymentStatus().getStatusValue())) + (long) order.getOrderPaymentStatus().getStatusValue())) .thenReturn(orderPaymentStatusTranslation); PageableDto dto = ubsService.getOrdersForUser(user.getUuid(), pageable, null); @@ -3242,10 +3219,10 @@ void testOrdersForUserWithExportedQuantity() { verify(modelMapper, times(bags.size())).map(bag, BagForUserDto.class); verify(bagRepository).findBagsByOrderId(order.getId()); verify(orderStatusTranslationRepository, times(orderList.size())) - .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); + .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); verify(orderPaymentStatusTranslationRepository, times(orderList.size())) - .getById( - (long) order.getOrderPaymentStatus().getStatusValue()); + .getById( + (long) order.getOrderPaymentStatus().getStatusValue()); verify(ordersForUserRepository).getAllByUserUuid(pageable, user.getUuid()); } @@ -3273,14 +3250,14 @@ void testOrdersForUserWithConfirmedQuantity() { Page page = new PageImpl<>(orderList, pageable, 1); when(ordersForUserRepository.getAllByUserUuid(pageable, user.getUuid())) - .thenReturn(page); + .thenReturn(page); when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(bags); when(modelMapper.map(bag, BagForUserDto.class)).thenReturn(bagForUserDto); when(orderStatusTranslationRepository - .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) + .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) .thenReturn(Optional.of(orderStatusTranslation)); when(orderPaymentStatusTranslationRepository.getById( - (long) order.getOrderPaymentStatus().getStatusValue())) + (long) order.getOrderPaymentStatus().getStatusValue())) .thenReturn(orderPaymentStatusTranslation); PageableDto dto = ubsService.getOrdersForUser(user.getUuid(), pageable, null); @@ -3291,10 +3268,10 @@ void testOrdersForUserWithConfirmedQuantity() { verify(modelMapper, times(bags.size())).map(bag, BagForUserDto.class); verify(bagRepository).findBagsByOrderId(order.getId()); verify(orderStatusTranslationRepository, times(orderList.size())) - .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); + .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); verify(orderPaymentStatusTranslationRepository, times(orderList.size())) - .getById( - (long) order.getOrderPaymentStatus().getStatusValue()); + .getById( + (long) order.getOrderPaymentStatus().getStatusValue()); verify(ordersForUserRepository).getAllByUserUuid(pageable, user.getUuid()); } @@ -3314,12 +3291,12 @@ void senderInfoDtoBuilderTest() { Page page = new PageImpl<>(orderList, pageable, 1); when(ordersForUserRepository.getAllByUserUuid(pageable, user.getUuid())) - .thenReturn(page); + .thenReturn(page); when(orderStatusTranslationRepository - .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) + .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) .thenReturn(Optional.of(orderStatusTranslation)); when(orderPaymentStatusTranslationRepository.getById( - (long) order.getOrderPaymentStatus().getStatusValue())) + (long) order.getOrderPaymentStatus().getStatusValue())) .thenReturn(orderPaymentStatusTranslation); PageableDto dto = ubsService.getOrdersForUser(user.getUuid(), pageable, null); @@ -3332,7 +3309,7 @@ void getTariffInfoForLocationTest() { var tariff = getTariffInfo(); when(courierRepository.existsCourierById(1L)).thenReturn(true); when(tariffsInfoRepository.findTariffsInfoLimitsByCourierIdAndLocationId(anyLong(), anyLong())) - .thenReturn(Optional.of(tariff)); + .thenReturn(Optional.of(tariff)); OrderCourierPopUpDto dto = ubsService.getTariffInfoForLocation(1L, 1L); assertTrue(dto.getOrderIsPresent()); verify(courierRepository).existsCourierById(1L); @@ -3344,7 +3321,7 @@ void getTariffInfoForLocationTest() { void getTariffInfoForLocationWhenCourierNotFoundTest() { when(courierRepository.existsCourierById(1L)).thenReturn(false); assertThrows(NotFoundException.class, () -> ubsService - .getTariffInfoForLocation(1L, 1L)); + .getTariffInfoForLocation(1L, 1L)); verify(courierRepository).existsCourierById(1L); } @@ -3353,7 +3330,7 @@ void getTariffInfoForLocationWhenTariffForCourierAndLocationNotFoundTest() { var expectedErrorMessage = String.format(TARIFF_FOR_COURIER_AND_LOCATION_NOT_EXIST, 1L, 1L); when(courierRepository.existsCourierById(1L)).thenReturn(true); var exception = assertThrows(NotFoundException.class, - () -> ubsService.getTariffInfoForLocation(1L, 1L)); + () -> ubsService.getTariffInfoForLocation(1L, 1L)); assertEquals(expectedErrorMessage, exception.getMessage()); verify(courierRepository).existsCourierById(1L); @@ -3365,11 +3342,11 @@ void getInfoForCourierOrderingByCourierIdTest() { when(courierRepository.existsCourierById(1L)).thenReturn(true); when(orderRepository.getLastOrderOfUserByUUIDIfExists(anyString())) - .thenReturn(Optional.of(getOrder())); + .thenReturn(Optional.of(getOrder())); when(tariffsInfoRepository.findTariffsInfoByOrdersId(anyLong())).thenReturn(tariff); OrderCourierPopUpDto dto = ubsService.getInfoForCourierOrderingByCourierId("35467585763t4sfgchjfuyetf", - Optional.empty(), 1L); + Optional.empty(), 1L); assertTrue(dto.getOrderIsPresent()); verify(courierRepository).existsCourierById(1L); @@ -3383,7 +3360,7 @@ void getInfoForCourierOrderingByCourierIdWhenCourierNotFoundTest() { Optional changeLoc = Optional.empty(); when(courierRepository.existsCourierById(1L)).thenReturn(false); assertThrows(NotFoundException.class, () -> ubsService - .getInfoForCourierOrderingByCourierId("35467585763t4sfgchjfuyetf", changeLoc, 1L)); + .getInfoForCourierOrderingByCourierId("35467585763t4sfgchjfuyetf", changeLoc, 1L)); verify(courierRepository).existsCourierById(1L); } @@ -3391,10 +3368,10 @@ void getInfoForCourierOrderingByCourierIdWhenCourierNotFoundTest() { void getInfoForCourierOrderingByCourierIdWhenOrderIsEmptyTest() { when(courierRepository.existsCourierById(1L)).thenReturn(true); when(orderRepository.getLastOrderOfUserByUUIDIfExists(anyString())) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); OrderCourierPopUpDto dto = ubsService.getInfoForCourierOrderingByCourierId("35467585763t4sfgchjfuyetf", - Optional.empty(), 1L); + Optional.empty(), 1L); assertFalse(dto.getOrderIsPresent()); verify(courierRepository).existsCourierById(1L); @@ -3405,7 +3382,7 @@ void getInfoForCourierOrderingByCourierIdWhenOrderIsEmptyTest() { void getInfoForCourierOrderingByCourierIdWhenChangeLocIsPresentTest() { when(courierRepository.existsCourierById(1L)).thenReturn(true); var dto = ubsService.getInfoForCourierOrderingByCourierId( - "35467585763t4sfgchjfuyetf", Optional.of("w"), 1L); + "35467585763t4sfgchjfuyetf", Optional.of("w"), 1L); assertEquals(0, dto.getAllActiveLocationsDtos().size()); verify(courierRepository).existsCourierById(1L); } @@ -3414,7 +3391,7 @@ void getInfoForCourierOrderingByCourierIdWhenChangeLocIsPresentTest() { void getAllActiveCouriersTest() { when(courierRepository.getAllActiveCouriers()).thenReturn(List.of(getCourier())); when(modelMapper.map(getCourier(), CourierDto.class)) - .thenReturn(getCourierDto()); + .thenReturn(getCourierDto()); assertEquals(getCourierDtoList(), ubsService.getAllActiveCouriers()); @@ -3452,7 +3429,7 @@ void checkIfAddressHasBeenDeletedTest() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(getTariffInfo())); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); @@ -3496,14 +3473,14 @@ void checkAddressUserTest() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(getTariffInfo())); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); when(modelMapper.map(dto.getPersonalData(), UBSuser.class)).thenReturn(ubSuser); assertThrows(NotFoundException.class, - () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); + () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); } @@ -3532,11 +3509,11 @@ void checkIfUserHaveEnoughPointsTest() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(getTariffInfo())); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, - () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); + () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); } @Test @@ -3544,7 +3521,7 @@ void getTariffForOrderTest() { TariffsInfo tariffsInfo = getTariffInfo(); when(tariffsInfoRepository.findByOrdersId(anyLong())).thenReturn(Optional.of(tariffsInfo)); when(modelMapper.map(tariffsInfo, TariffsForLocationDto.class)) - .thenReturn(getTariffsForLocationDto()); + .thenReturn(getTariffsForLocationDto()); var dto = ubsService.getTariffForOrder(1L); verify(tariffsInfoRepository, times(1)).findByOrdersId(anyLong()); verify(modelMapper).map(tariffsInfo, TariffsForLocationDto.class); @@ -3576,7 +3553,7 @@ void getAllAuthoritiesService() { Optional employeeOptional = Optional.ofNullable(getEmployee()); when(employeeRepository.findByEmail(anyString())).thenReturn(employeeOptional); when(userRemoteClient.getAllAuthorities(employeeOptional.get().getEmail())) - .thenReturn(Set.copyOf(ModelUtils.getAllAuthorities())); + .thenReturn(Set.copyOf(ModelUtils.getAllAuthorities())); Set authoritiesResult = ubsService.getAllAuthorities(employeeOptional.get().getEmail()); Set authExpected = Set.of("SEE_CLIENTS_PAGE"); assertEquals(authExpected, authoritiesResult); @@ -3606,12 +3583,12 @@ void testOrdersForUserWithQuantity() { Page page = new PageImpl<>(orderList, pageable, 1); when(ordersForUserRepository.getAllByUserUuid(pageable, user.getUuid())) - .thenReturn(page); + .thenReturn(page); when(orderStatusTranslationRepository - .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) + .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) .thenReturn(Optional.of(orderStatusTranslation)); when(orderPaymentStatusTranslationRepository.getById( - (long) order.getOrderPaymentStatus().getStatusValue())) + (long) order.getOrderPaymentStatus().getStatusValue())) .thenReturn(orderPaymentStatusTranslation); PageableDto dto = ubsService.getOrdersForUser(user.getUuid(), pageable, null); @@ -3619,10 +3596,10 @@ void testOrdersForUserWithQuantity() { assertEquals(dto.getTotalElements(), orderList.size()); assertEquals(dto.getPage().get(0).getId(), order.getId()); verify(orderStatusTranslationRepository, times(orderList.size())) - .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); + .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); verify(orderPaymentStatusTranslationRepository, times(orderList.size())) - .getById( - (long) order.getOrderPaymentStatus().getStatusValue()); + .getById( + (long) order.getOrderPaymentStatus().getStatusValue()); verify(ordersForUserRepository).getAllByUserUuid(pageable, user.getUuid()); } @@ -3630,12 +3607,12 @@ void testOrdersForUserWithQuantity() { void testCreateUserProfileIfProfileDoesNotExist() { UserProfileCreateDto userProfileCreateDto = getUserProfileCreateDto(); User userForSave = User.builder() - .uuid(userProfileCreateDto.getUuid()) - .recipientEmail(userProfileCreateDto.getEmail()) - .recipientName(userProfileCreateDto.getName()) - .currentPoints(0) - .violations(0) - .dateOfRegistration(LocalDate.now()).build(); + .uuid(userProfileCreateDto.getUuid()) + .recipientEmail(userProfileCreateDto.getEmail()) + .recipientName(userProfileCreateDto.getName()) + .currentPoints(0) + .violations(0) + .dateOfRegistration(LocalDate.now()).build(); User user = getUser(); when(userRemoteClient.checkIfUserExistsByUuid(userProfileCreateDto.getUuid())).thenReturn(true); when(userRepository.findByUuid(userProfileCreateDto.getUuid())).thenReturn(null); @@ -3669,7 +3646,7 @@ void testCreateUserProfileIfUserByUuidDoesNotExist() { void getPositionsAndRelatedAuthoritiesTest() { when(employeeRepository.findByEmail(TEST_EMAIL)).thenReturn(Optional.ofNullable(getEmployee())); when(userRemoteClient.getPositionsAndRelatedAuthorities(TEST_EMAIL)) - .thenReturn(ModelUtils.getPositionAuthoritiesDto()); + .thenReturn(ModelUtils.getPositionAuthoritiesDto()); PositionAuthoritiesDto actual = ubsService.getPositionsAndRelatedAuthorities(TEST_EMAIL); assertEquals(ModelUtils.getPositionAuthoritiesDto(), actual); diff --git a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java index dabad4c97..13aff7638 100644 --- a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java @@ -271,27 +271,27 @@ class UBSManagementServiceImplTest { @Test void getAllCertificates() { Pageable pageable = - PageRequest.of(0, 5, Sort.by(Sort.Direction.fromString(SortingOrder.DESC.toString()), "points")); + PageRequest.of(0, 5, Sort.by(Sort.Direction.fromString(SortingOrder.DESC.toString()), "points")); CertificateDtoForSearching certificateDtoForSearching = ModelUtils.getCertificateDtoForSearching(); List certificates = - Collections.singletonList(ModelUtils.getCertificate()); + Collections.singletonList(ModelUtils.getCertificate()); List certificateDtoForSearchings = - Collections.singletonList(certificateDtoForSearching); + Collections.singletonList(certificateDtoForSearching); PageableDto certificateDtoForSearchingPageableDto = - new PageableDto<>(certificateDtoForSearchings, certificateDtoForSearchings.size(), 0, 1); + new PageableDto<>(certificateDtoForSearchings, certificateDtoForSearchings.size(), 0, 1); Page certificates1 = new PageImpl<>(certificates, pageable, certificates.size()); when(modelMapper.map(certificates.get(0), CertificateDtoForSearching.class)) - .thenReturn(certificateDtoForSearching); + .thenReturn(certificateDtoForSearching); when(certificateRepository.findAll(pageable)).thenReturn(certificates1); PageableDto actual = - ubsManagementService.getAllCertificates(pageable, "points", SortingOrder.DESC); + ubsManagementService.getAllCertificates(pageable, "points", SortingOrder.DESC); assertEquals(certificateDtoForSearchingPageableDto, actual); } @Test void checkOrderNotFound() { assertThrows(NotFoundException.class, - () -> ubsManagementService.getAddressByOrderId(10000000L)); + () -> ubsManagementService.getAddressByOrderId(10000000L)); } @Test @@ -315,7 +315,7 @@ void returnExportDetailsByOrderId() { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); List stations = - Arrays.asList(ReceivingStation.builder().name("a").build(), ReceivingStation.builder().name("b").build()); + Arrays.asList(ReceivingStation.builder().name("a").build(), ReceivingStation.builder().name("b").build()); when(receivingStationRepository.findAll()).thenReturn(stations); assertEquals(expected, ubsManagementService.getOrderExportDetails(1L)); @@ -371,15 +371,15 @@ void saveNewManualPayment(ManualPaymentRequestDto paymentDetails, MultipartFile when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.save(any())) - .thenReturn(payment); + .thenReturn(payment); doNothing().when(eventService).save(OrderHistory.ADD_PAYMENT_MANUALLY + 1, "Петро" + " " + "Петренко", order); ubsManagementService.saveNewManualPayment(1L, paymentDetails, image, "test@gmail.com"); verify(eventService, times(1)) - .save("Додано оплату №1", "Петро Петренко", order); + .save("Додано оплату №1", "Петро Петренко", order); verify(paymentRepository, times(1)).save(any()); verify(orderRepository, times(1)).findById(1L); verify(tariffsInfoRepository).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -387,10 +387,10 @@ void saveNewManualPayment(ManualPaymentRequestDto paymentDetails, MultipartFile private static Stream provideManualPaymentRequestDto() { return Stream.of(Arguments.of(ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021").amount(500L).receiptLink("link").paymentId("1").build(), null), - Arguments.of(ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021").amount(500L).imagePath("path").paymentId("1").build(), - Mockito.mock(MultipartFile.class))); + .settlementdate("02-08-2021").amount(500L).receiptLink("link").paymentId("1").build(), null), + Arguments.of(ManualPaymentRequestDto.builder() + .settlementdate("02-08-2021").amount(500L).imagePath("path").paymentId("1").build(), + Mockito.mock(MultipartFile.class))); } @Test @@ -403,8 +403,8 @@ void checkDeleteManualPayment() { doNothing().when(paymentRepository).deletePaymentById(1L); doNothing().when(fileService).delete(""); doNothing().when(eventService).save(OrderHistory.DELETE_PAYMENT_MANUALLY + getManualPayment().getPaymentId(), - employee.getFirstName() + " " + employee.getLastName(), - getOrder()); + employee.getFirstName() + " " + employee.getLastName(), + getOrder()); ubsManagementService.deleteManualPayment(1L, "abc"); verify(paymentRepository, times(1)).findById(1L); verify(paymentRepository, times(1)).deletePaymentById(1L); @@ -420,8 +420,8 @@ void checkUpdateManualPayment() { when(paymentRepository.save(any())).thenReturn(getManualPayment()); when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(getBaglist()); doNothing().when(eventService).save(OrderHistory.UPDATE_PAYMENT_MANUALLY + 1, - employee.getFirstName() + " " + employee.getLastName(), - getOrder()); + employee.getFirstName() + " " + employee.getLastName(), + getOrder()); ubsManagementService.updateManualPayment(1L, getManualPaymentRequestDto(), null, "abc"); verify(paymentRepository, times(1)).findById(1L); verify(paymentRepository, times(1)).save(any()); @@ -444,20 +444,20 @@ void saveNewManualPaymentWithZeroAmount() { payment.setAmount(0L); order.setPayment(singletonList(payment)); ManualPaymentRequestDto paymentDetails = ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021").amount(0L).receiptLink("link").paymentId("1").build(); + .settlementdate("02-08-2021").amount(0L).receiptLink("link").paymentId("1").build(); Employee employee = getEmployee(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.save(any())) - .thenReturn(payment); + .thenReturn(payment); doNothing().when(eventService).save(any(), any(), any()); ubsManagementService.saveNewManualPayment(1L, paymentDetails, null, "test@gmail.com"); verify(employeeRepository, times(2)).findByEmail(anyString()); verify(eventService, times(1)).save(OrderHistory.ADD_PAYMENT_MANUALLY + 1, - "Петро Петренко", order); + "Петро Петренко", order); verify(paymentRepository, times(1)).save(any()); verify(orderRepository, times(1)).findById(1L); verify(tariffsInfoRepository).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -477,23 +477,23 @@ void saveNewManualPaymentWithHalfPaidAmount() { payment.setAmount(50_00L); order.setPayment(singletonList(payment)); ManualPaymentRequestDto paymentDetails = ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021").amount(50_00L).receiptLink("link").paymentId("1").build(); + .settlementdate("02-08-2021").amount(50_00L).receiptLink("link").paymentId("1").build(); Employee employee = getEmployee(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag1list()); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.save(any())) - .thenReturn(payment); + .thenReturn(payment); doNothing().when(eventService).save(any(), any(), any()); ubsManagementService.saveNewManualPayment(1L, paymentDetails, null, "test@gmail.com"); verify(employeeRepository, times(2)).findByEmail(anyString()); verify(eventService, times(1)).save(OrderHistory.ADD_PAYMENT_MANUALLY + 1, - "Петро Петренко", order); + "Петро Петренко", order); verify(eventService, times(1)) - .save(OrderHistory.ORDER_HALF_PAID, OrderHistory.SYSTEM, order); + .save(OrderHistory.ORDER_HALF_PAID, OrderHistory.SYSTEM, order); verify(paymentRepository, times(1)).save(any()); verify(orderRepository, times(1)).findById(1L); verify(tariffsInfoRepository).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -512,23 +512,23 @@ void saveNewManualPaymentWithPaidAmount() { payment.setAmount(500_00L); order.setPayment(singletonList(payment)); ManualPaymentRequestDto paymentDetails = ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021").amount(500_00L).receiptLink("link").paymentId("1").build(); + .settlementdate("02-08-2021").amount(500_00L).receiptLink("link").paymentId("1").build(); Employee employee = getEmployee(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag1list()); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.save(any())) - .thenReturn(payment); + .thenReturn(payment); doNothing().when(eventService).save(any(), any(), any()); ubsManagementService.saveNewManualPayment(1L, paymentDetails, null, "test@gmail.com"); verify(employeeRepository, times(2)).findByEmail(anyString()); verify(eventService, times(1)).save(OrderHistory.ADD_PAYMENT_MANUALLY + 1, - "Петро Петренко", order); + "Петро Петренко", order); verify(eventService, times(1)) - .save(OrderHistory.ORDER_PAID, OrderHistory.SYSTEM, order); + .save(OrderHistory.ORDER_PAID, OrderHistory.SYSTEM, order); verify(paymentRepository, times(1)).save(any()); verify(orderRepository, times(1)).findById(1L); verify(tariffsInfoRepository).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -545,19 +545,19 @@ void saveNewManualPaymentWithPaidOrder() { order.setOrderPaymentStatus(OrderPaymentStatus.PAID); Payment payment = getManualPayment(); ManualPaymentRequestDto paymentDetails = ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021").amount(500L).receiptLink("link").paymentId("1").build(); + .settlementdate("02-08-2021").amount(500L).receiptLink("link").paymentId("1").build(); Employee employee = getEmployee(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.save(any())) - .thenReturn(payment); + .thenReturn(payment); doNothing().when(eventService).save(OrderHistory.ADD_PAYMENT_MANUALLY + 1, "Петро" + " " + "Петренко", order); ubsManagementService.saveNewManualPayment(1L, paymentDetails, null, "test@gmail.com"); verify(eventService, times(1)) - .save("Додано оплату №1", "Петро Петренко", order); + .save("Додано оплату №1", "Петро Петренко", order); verify(paymentRepository, times(1)).save(any()); verify(orderRepository, times(1)).findById(1L); verify(tariffsInfoRepository).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -574,19 +574,19 @@ void saveNewManualPaymentWithPartiallyPaidOrder() { order.setOrderPaymentStatus(OrderPaymentStatus.HALF_PAID); Payment payment = getManualPayment(); ManualPaymentRequestDto paymentDetails = ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021").amount(200L).receiptLink("link").paymentId("1").build(); + .settlementdate("02-08-2021").amount(200L).receiptLink("link").paymentId("1").build(); Employee employee = getEmployee(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.save(any())) - .thenReturn(payment); + .thenReturn(payment); doNothing().when(eventService).save(OrderHistory.ADD_PAYMENT_MANUALLY + 1, "Петро" + " " + "Петренко", order); ubsManagementService.saveNewManualPayment(1L, paymentDetails, null, "test@gmail.com"); verify(eventService, times(1)) - .save("Додано оплату №1", "Петро Петренко", order); + .save("Додано оплату №1", "Петро Петренко", order); verify(paymentRepository, times(1)).save(any()); verify(orderRepository, times(1)).findById(1L); verify(tariffsInfoRepository).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -603,19 +603,19 @@ void saveNewManualPaymentWithUnpaidOrder() { order.setOrderPaymentStatus(OrderPaymentStatus.UNPAID); Payment payment = getManualPayment(); ManualPaymentRequestDto paymentDetails = ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021").amount(500L).receiptLink("link").paymentId("1").build(); + .settlementdate("02-08-2021").amount(500L).receiptLink("link").paymentId("1").build(); Employee employee = getEmployee(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.save(any())) - .thenReturn(payment); + .thenReturn(payment); doNothing().when(eventService).save(OrderHistory.ADD_PAYMENT_MANUALLY + 1, "Петро" + " " + "Петренко", order); ubsManagementService.saveNewManualPayment(1L, paymentDetails, null, "test@gmail.com"); verify(eventService, times(1)) - .save("Додано оплату №1", "Петро Петренко", order); + .save("Додано оплату №1", "Петро Петренко", order); verify(paymentRepository, times(1)).save(any()); verify(orderRepository, times(1)).findById(1L); verify(tariffsInfoRepository).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -632,19 +632,19 @@ void saveNewManualPaymentWithPaymentRefundedOrder() { order.setOrderPaymentStatus(OrderPaymentStatus.PAYMENT_REFUNDED); Payment payment = getManualPayment(); ManualPaymentRequestDto paymentDetails = ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021").amount(500L).receiptLink("link").paymentId("1").build(); + .settlementdate("02-08-2021").amount(500L).receiptLink("link").paymentId("1").build(); Employee employee = getEmployee(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.save(any())) - .thenReturn(payment); + .thenReturn(payment); doNothing().when(eventService).save(OrderHistory.ADD_PAYMENT_MANUALLY + 1, "Петро" + " " + "Петренко", order); ubsManagementService.saveNewManualPayment(1L, paymentDetails, null, "test@gmail.com"); verify(eventService, times(1)) - .save("Додано оплату №1", "Петро Петренко", order); + .save("Додано оплату №1", "Петро Петренко", order); verify(paymentRepository, times(1)).save(any()); verify(orderRepository, times(1)).findById(1L); verify(tariffsInfoRepository).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -659,12 +659,12 @@ void checkUpdateManualPaymentWithImage() { when(employeeRepository.findByUuid("abc")).thenReturn(Optional.of(employee)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); MockMultipartFile file = new MockMultipartFile("manualPaymentDto", - "", "application/json", "random Bytes".getBytes()); + "", "application/json", "random Bytes".getBytes()); when(paymentRepository.findById(1L)).thenReturn(Optional.of(getManualPayment())); when(paymentRepository.save(any())).thenReturn(getManualPayment()); when(fileService.upload(file)).thenReturn("path"); doNothing().when(eventService).save(OrderHistory.UPDATE_PAYMENT_MANUALLY + 1, "Yuriy" + " " + "Gerasum", - getOrder()); + getOrder()); ubsManagementService.updateManualPayment(1L, getManualPaymentRequestDto(), file, "abc"); verify(paymentRepository, times(1)).findById(1L); verify(paymentRepository, times(1)).save(any()); @@ -678,7 +678,7 @@ void checkManualPaymentNotFound() { ManualPaymentRequestDto manualPaymentRequestDto = getManualPaymentRequestDto(); when(paymentRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsManagementService.updateManualPayment(1L, manualPaymentRequestDto, null, "abc")); + () -> ubsManagementService.updateManualPayment(1L, manualPaymentRequestDto, null, "abc")); verify(paymentRepository, times(1)).findById(1L); } @@ -693,19 +693,19 @@ void checkReturnOverpaymentInfo() { Double sumToPay = 0.; assertEquals("Зарахування на бонусний рахунок", ubsManagementService.returnOverpaymentInfo(1L, sumToPay, 0L) - .getPaymentInfoDtos().get(1).getComment()); + .getPaymentInfoDtos().get(1).getComment()); assertEquals(0L, ubsManagementService.returnOverpaymentInfo(1L, sumToPay, 1L) - .getOverpayment()); + .getOverpayment()); assertEquals(AppConstant.PAYMENT_REFUND, - ubsManagementService.returnOverpaymentInfo(order.getId(), sumToPay, 1L).getPaymentInfoDtos().get(1) - .getComment()); + ubsManagementService.returnOverpaymentInfo(order.getId(), sumToPay, 1L).getPaymentInfoDtos().get(1) + .getComment()); } @Test void checkReturnOverpaymentThroweException() { Assertions.assertThrows(NotFoundException.class, - () -> ubsManagementService.returnOverpaymentInfo(100L, 1., 1L)); + () -> ubsManagementService.returnOverpaymentInfo(100L, 1., 1L)); } @Test @@ -752,7 +752,7 @@ void updateOrderDetailStatusThrowException() { when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrder())); OrderDetailStatusRequestDto requestDto = getTestOrderDetailStatusRequestDto(); assertThrows(NotFoundException.class, - () -> ubsManagementService.updateOrderDetailStatus(1L, requestDto, "uuid")); + () -> ubsManagementService.updateOrderDetailStatus(1L, requestDto, "uuid")); } @Test @@ -776,14 +776,14 @@ void updateOrderDetailStatusFirst() { OrderDetailStatusRequestDto testOrderDetail = getTestOrderDetailStatusRequestDto(); OrderDetailStatusDto expectedObject = ModelUtils.getTestOrderDetailStatusDto(); OrderDetailStatusDto producedObject = ubsManagementService - .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); + .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); assertEquals(expectedObject.getOrderStatus(), producedObject.getOrderStatus()); assertEquals(expectedObject.getPaymentStatus(), producedObject.getPaymentStatus()); assertEquals(expectedObject.getDate(), producedObject.getDate()); testOrderDetail.setOrderStatus(OrderStatus.FORMED.toString()); expectedObject.setOrderStatus(OrderStatus.FORMED.toString()); OrderDetailStatusDto producedObjectAdjustment = ubsManagementService - .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); + .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); assertEquals(expectedObject.getOrderStatus(), producedObjectAdjustment.getOrderStatus()); assertEquals(expectedObject.getPaymentStatus(), producedObjectAdjustment.getPaymentStatus()); @@ -792,7 +792,7 @@ void updateOrderDetailStatusFirst() { testOrderDetail.setOrderStatus(OrderStatus.ADJUSTMENT.toString()); expectedObject.setOrderStatus(OrderStatus.ADJUSTMENT.toString()); OrderDetailStatusDto producedObjectConfirmed = ubsManagementService - .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); + .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); assertEquals(expectedObject.getOrderStatus(), producedObjectConfirmed.getOrderStatus()); assertEquals(expectedObject.getPaymentStatus(), producedObjectConfirmed.getPaymentStatus()); @@ -801,7 +801,7 @@ void updateOrderDetailStatusFirst() { testOrderDetail.setOrderStatus(OrderStatus.CONFIRMED.toString()); expectedObject.setOrderStatus(OrderStatus.CONFIRMED.toString()); OrderDetailStatusDto producedObjectNotTakenOut = ubsManagementService - .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); + .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); assertEquals(expectedObject.getOrderStatus(), producedObjectNotTakenOut.getOrderStatus()); assertEquals(expectedObject.getPaymentStatus(), producedObjectNotTakenOut.getPaymentStatus()); @@ -811,7 +811,7 @@ void updateOrderDetailStatusFirst() { testOrderDetail.setOrderStatus(OrderStatus.CANCELED.toString()); expectedObject.setOrderStatus(OrderStatus.CANCELED.toString()); OrderDetailStatusDto producedObjectCancelled = ubsManagementService - .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); + .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); assertEquals(expectedObject.getOrderStatus(), producedObjectCancelled.getOrderStatus()); assertEquals(expectedObject.getPaymentStatus(), producedObjectCancelled.getPaymentStatus()); @@ -822,7 +822,7 @@ void updateOrderDetailStatusFirst() { testOrderDetail.setOrderStatus(OrderStatus.DONE.toString()); expectedObject.setOrderStatus(OrderStatus.DONE.toString()); OrderDetailStatusDto producedObjectDone = ubsManagementService - .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); + .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); assertEquals(expectedObject.getOrderStatus(), producedObjectDone.getOrderStatus()); assertEquals(expectedObject.getPaymentStatus(), producedObjectDone.getPaymentStatus()); @@ -833,7 +833,7 @@ void updateOrderDetailStatusFirst() { testOrderDetail.setOrderStatus(OrderStatus.CANCELED.toString()); expectedObject.setOrderStatus(OrderStatus.CANCELED.toString()); OrderDetailStatusDto producedObjectCancelled2 = ubsManagementService - .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); + .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); assertEquals(expectedObject.getOrderStatus(), producedObjectCancelled2.getOrderStatus()); assertEquals(expectedObject.getPaymentStatus(), producedObjectCancelled2.getPaymentStatus()); @@ -844,7 +844,7 @@ void updateOrderDetailStatusFirst() { testOrderDetail.setOrderStatus(OrderStatus.BROUGHT_IT_HIMSELF.toString()); expectedObject.setOrderStatus(OrderStatus.BROUGHT_IT_HIMSELF.toString()); OrderDetailStatusDto producedObjectBroughtItHimself = ubsManagementService - .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); + .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); assertEquals(expectedObject.getOrderStatus(), producedObjectBroughtItHimself.getOrderStatus()); assertEquals(expectedObject.getPaymentStatus(), producedObjectBroughtItHimself.getPaymentStatus()); @@ -854,7 +854,7 @@ void updateOrderDetailStatusFirst() { testOrderDetail.setOrderStatus(OrderStatus.CANCELED.toString()); expectedObject.setOrderStatus(OrderStatus.CANCELED.toString()); OrderDetailStatusDto producedObjectCancelled3 = ubsManagementService - .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); + .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); assertEquals(expectedObject.getOrderStatus(), producedObjectCancelled3.getOrderStatus()); assertEquals(expectedObject.getPaymentStatus(), producedObjectCancelled3.getPaymentStatus()); @@ -862,17 +862,17 @@ void updateOrderDetailStatusFirst() { assertEquals(0, order.getPointsToUse()); verify(eventService, times(1)) - .saveEvent("Статус Замовлення - Узгодження", - "test@gmail.com", order); + .saveEvent("Статус Замовлення - Узгодження", + "test@gmail.com", order); verify(eventService, times(1)) - .saveEvent("Статус Замовлення - Підтверджено", - "test@gmail.com", order); + .saveEvent("Статус Замовлення - Підтверджено", + "test@gmail.com", order); verify(eventService, times(3)) - .saveEvent("Статус Замовлення - Скасовано", - "test@gmail.com", order); + .saveEvent("Статус Замовлення - Скасовано", + "test@gmail.com", order); verify(eventService, times(1)) - .saveEvent("Невикористані бонуси повернено на бонусний рахунок клієнта" + ". Всього " + 700, - "test@gmail.com", order); + .saveEvent("Невикористані бонуси повернено на бонусний рахунок клієнта" + ". Всього " + 700, + "test@gmail.com", order); } @Test @@ -898,7 +898,7 @@ void updateOrderDetailStatusSecond() { testOrderDetail.setOrderStatus(OrderStatus.ON_THE_ROUTE.toString()); expectedObject.setOrderStatus(OrderStatus.ON_THE_ROUTE.toString()); OrderDetailStatusDto producedObjectOnTheRoute = ubsManagementService - .updateOrderDetailStatus(order.getId(), testOrderDetail, "abc"); + .updateOrderDetailStatus(order.getId(), testOrderDetail, "abc"); assertEquals(expectedObject.getOrderStatus(), producedObjectOnTheRoute.getOrderStatus()); assertEquals(expectedObject.getPaymentStatus(), producedObjectOnTheRoute.getPaymentStatus()); @@ -921,7 +921,7 @@ void getAllEmployeesByPosition() { when(orderRepository.findById(anyLong())).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(employeeOrderPositionRepository.findAllByOrderId(anyLong())).thenReturn(newList); when(positionRepository.findAll()).thenReturn(positionList); when(employeeRepository.findAllByEmployeePositionId(anyLong())).thenReturn(employeeList); @@ -943,9 +943,9 @@ void getAllEmployeesByPositionThrowBadRequestException() { when(orderRepository.findById(anyLong())).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); assertThrows(BadRequestException.class, - () -> ubsManagementService.getAllEmployeesByPosition(1L, "test@gmail.com")); + () -> ubsManagementService.getAllEmployeesByPosition(1L, "test@gmail.com")); verify(orderRepository).findById(anyLong()); verify(employeeRepository).findByEmail("test@gmail.com"); verify(tariffsInfoRepository, atLeastOnce()).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -962,7 +962,7 @@ void testUpdateAddress() { when(orderAddressRepository.save(orderAddress)).thenReturn(orderAddress); when(modelMapper.map(orderAddress, OrderAddressDtoResponse.class)).thenReturn(TEST_ORDER_ADDRESS_DTO_RESPONSE); Optional actual = - ubsManagementService.updateAddress(TEST_ORDER_ADDRESS_DTO_UPDATE, 1L, "test@gmail.com"); + ubsManagementService.updateAddress(TEST_ORDER_ADDRESS_DTO_UPDATE, 1L, "test@gmail.com"); assertEquals(Optional.of(TEST_ORDER_ADDRESS_DTO_RESPONSE), actual); verify(orderRepository).findById(1L); verify(orderAddressRepository).save(orderAddress); @@ -975,7 +975,7 @@ void testUpdateAddressThrowsOrderNotFoundException() { when(orderRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsManagementService.updateAddress(TEST_ORDER_ADDRESS_DTO_UPDATE, 1L, "abc")); + () -> ubsManagementService.updateAddress(TEST_ORDER_ADDRESS_DTO_UPDATE, 1L, "abc")); } @Test @@ -983,7 +983,7 @@ void testUpdateAddressThrowsNotFoundOrderAddressException() { when(orderRepository.findById(1L)).thenReturn(Optional.of(ModelUtils.getOrderWithoutAddress())); assertThrows(NotFoundException.class, - () -> ubsManagementService.updateAddress(TEST_ORDER_ADDRESS_DTO_UPDATE, 1L, "abc")); + () -> ubsManagementService.updateAddress(TEST_ORDER_ADDRESS_DTO_UPDATE, 1L, "abc")); } @Test @@ -1006,7 +1006,7 @@ void testGetOrderDetailStatusThrowsUnExistingOrderException() { when(orderRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsManagementService.getOrderDetailStatus(1L)); + () -> ubsManagementService.getOrderDetailStatus(1L)); } @Test @@ -1015,7 +1015,7 @@ void testGetOrderDetailStatusThrowsPaymentNotFoundException() { when(paymentRepository.findAllByOrderId(1)).thenReturn(Collections.emptyList()); assertThrows(NotFoundException.class, - () -> ubsManagementService.getOrderDetailStatus(1L)); + () -> ubsManagementService.getOrderDetailStatus(1L)); } @Test @@ -1055,18 +1055,18 @@ void testGetOrdersBagsDetails() { detailsOrderInfoDtoList.add(getTestDetailsOrderInfoDto()); } assertEquals(detailsOrderInfoDtoList.toString(), - ubsManagementService.getOrderBagsDetails(1L).toString()); + ubsManagementService.getOrderBagsDetails(1L).toString()); } @Test void testGetOrderExportDetailsReceivingStationNotFoundExceptionThrown() { when(orderRepository.findById(1L)) - .thenReturn(Optional.of(getOrder())); + .thenReturn(Optional.of(getOrder())); List receivingStations = new ArrayList<>(); when(receivingStationRepository.findAll()) - .thenReturn(receivingStations); + .thenReturn(receivingStations); assertThrows(NotFoundException.class, - () -> ubsManagementService.getOrderExportDetails(1L)); + () -> ubsManagementService.getOrderExportDetails(1L)); } @Test @@ -1074,7 +1074,7 @@ void testGetOrderDetailsThrowsException() { when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsManagementService.getOrderDetails(1L, "ua")); + () -> ubsManagementService.getOrderDetails(1L, "ua")); } @Test @@ -1098,7 +1098,7 @@ void testAddPointToUserThrowsException() { user.setUuid(null); AddingPointsToUserDto addingPointsToUserDto = - AddingPointsToUserDto.builder().additionalPoints(anyInt()).build(); + AddingPointsToUserDto.builder().additionalPoints(anyInt()).build(); assertThrows(NotFoundException.class, () -> ubsManagementService.addPointsToUser(addingPointsToUserDto)); } @@ -1120,9 +1120,9 @@ void testAddPointsToUser() { void testGetAdditionalBagsInfo() { when(userRepository.findUserByOrderId(1L)).thenReturn(Optional.of(TEST_USER)); when(bagRepository.getAdditionalBagInfo(1L, TEST_USER.getRecipientEmail())) - .thenReturn(TEST_MAP_ADDITIONAL_BAG_LIST); + .thenReturn(TEST_MAP_ADDITIONAL_BAG_LIST); when(objectMapper.convertValue(any(), eq(AdditionalBagInfoDto.class))) - .thenReturn(TEST_ADDITIONAL_BAG_INFO_DTO); + .thenReturn(TEST_ADDITIONAL_BAG_INFO_DTO); List actual = ubsManagementService.getAdditionalBagsInfo(1L); @@ -1138,7 +1138,7 @@ void testGetAdditionalBagsInfoThrowsException() { when(userRepository.findUserByOrderId(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsManagementService.getAdditionalBagsInfo(1L)); + () -> ubsManagementService.getAdditionalBagsInfo(1L)); } @Test @@ -1148,14 +1148,14 @@ void testSetOrderDetail() { doNothing().when(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag1list()); when(paymentRepository.selectSumPaid(1L)).thenReturn(5000L); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); verify(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); @@ -1168,15 +1168,15 @@ void testSetOrderDetailNeedToChangeStatusToHALF_PAID() { doNothing().when(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag1list()); when(paymentRepository.selectSumPaid(1L)).thenReturn(5000L); doNothing().when(orderRepository).updateOrderPaymentStatus(1L, OrderPaymentStatus.HALF_PAID.name()); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); verify(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); @@ -1191,15 +1191,15 @@ void testSetOrderDetailNeedToChangeStatusToUNPAID() { doNothing().when(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag1list()); when(paymentRepository.selectSumPaid(1L)).thenReturn(null); doNothing().when(orderRepository).updateOrderPaymentStatus(1L, OrderPaymentStatus.UNPAID.name()); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); verify(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); @@ -1213,13 +1213,13 @@ void testSetOrderDetailWhenSumPaidIsNull() { doNothing().when(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); when(paymentRepository.selectSumPaid(1L)).thenReturn(null); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); verify(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); @@ -1229,17 +1229,17 @@ void testSetOrderDetailWhenSumPaidIsNull() { void testSetOrderDetailWhenOrderNotFound() { when(orderRepository.findById(1L)).thenReturn(Optional.empty()); Map amountOfBagsConfirmed = UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto() - .getAmountOfBagsConfirmed(); + .getAmountOfBagsConfirmed(); Map amountOfBagsExported = UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto() - .getAmountOfBagsExported(); + .getAmountOfBagsExported(); NotFoundException exception = assertThrows(NotFoundException.class, - () -> ubsManagementService.setOrderDetail( - 1L, - amountOfBagsConfirmed, - amountOfBagsExported, - "abc"), - ORDER_WITH_CURRENT_ID_DOES_NOT_EXIST); + () -> ubsManagementService.setOrderDetail( + 1L, + amountOfBagsConfirmed, + amountOfBagsExported, + "abc"), + ORDER_WITH_CURRENT_ID_DOES_NOT_EXIST); assertEquals(ORDER_WITH_CURRENT_ID_DOES_NOT_EXIST, exception.getMessage()); @@ -1261,8 +1261,8 @@ void testSetOrderDetailIfHalfPaid() { when(orderRepository.findSumOfCertificatesByOrderId(1L)).thenReturn(0L); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); verify(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); verify(orderRepository).updateOrderPaymentStatus(1L, OrderPaymentStatus.UNPAID.name()); @@ -1275,13 +1275,13 @@ void testSetOrderDetailIfPaidAndPriceLessThanDiscount() { when(certificateRepository.findCertificate(order.getId())).thenReturn(List.of(ModelUtils.getCertificate2())); when(orderRepository.findSumOfCertificatesByOrderId(order.getId())).thenReturn(600L); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusFormedDto2())); + .thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusFormedDto2())); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(order.getId(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); verify(certificateRepository).save(ModelUtils.getCertificate2().setPoints(20)); verify(userRepository).updateUserCurrentPoints(1L, 100); @@ -1296,13 +1296,13 @@ void testSetOrderDetailIfPaidAndPriceLessThanPaidSum() { when(certificateRepository.findCertificate(order.getId())).thenReturn(List.of(ModelUtils.getCertificate2())); when(orderRepository.findSumOfCertificatesByOrderId(order.getId())).thenReturn(600L); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusFormedDto2())); + .thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusFormedDto2())); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(order.getId(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); verify(certificateRepository).save(ModelUtils.getCertificate2().setPoints(0)); verify(userRepository).updateUserCurrentPoints(1L, 100); @@ -1315,13 +1315,13 @@ void testSetOrderDetailConfirmed() { when(bagRepository.findCapacityById(1)).thenReturn(1); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), - "test@gmail.com"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), + "test@gmail.com"); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); verify(orderDetailRepository, times(0)).updateExporter(anyInt(), anyLong(), anyLong()); @@ -1332,14 +1332,14 @@ void testSetOrderDetailConfirmed2() { when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusConfirmedDto())); when(bagRepository.findCapacityById(1)).thenReturn(1); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); when(orderDetailRepository.ifRecordExist(any(), any())).thenReturn(1L); when(orderDetailRepository.getAmount(any(), any())).thenReturn(1L); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), - "test@gmail.com"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), + "test@gmail.com"); verify(orderRepository, times(2)).findById(1L); verify(bagRepository, times(2)).findCapacityById(1); verify(bagRepository, times(2)).findById(1); @@ -1356,13 +1356,13 @@ void testSetOrderDetailWithExportedWaste() { doNothing().when(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); when(orderDetailRepository.ifRecordExist(any(), any())).thenReturn(1L); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), - "test@gmail.com"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), + "test@gmail.com"); verify(orderRepository, times(2)).findById(1L); verify(bagRepository, times(2)).findCapacityById(1); verify(bagRepository, times(2)).findById(1); @@ -1377,12 +1377,12 @@ void testSetOrderDetailFormed() { when(bagRepository.findCapacityById(1)).thenReturn(1); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "test@gmail.com"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "test@gmail.com"); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); } @@ -1395,8 +1395,8 @@ void testSetOrderDetailFormedWithBagNoPresent() { when(bagRepository.findById(1)).thenReturn(Optional.empty()); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "test@gmail.com"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "test@gmail.com"); verify(orderDetailRepository, times(0)).updateExporter(anyInt(), anyLong(), anyLong()); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); @@ -1410,14 +1410,14 @@ void testSetOrderDetailNotTakenOut() { doNothing().when(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), - "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), + "abc"); verify(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); @@ -1429,13 +1429,13 @@ void testSetOrderDetailOnTheRoute() { when(bagRepository.findCapacityById(1)).thenReturn(1); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), - "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), + "abc"); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); verify(orderDetailRepository, times(0)).updateExporter(anyInt(), anyLong(), anyLong()); @@ -1448,12 +1448,12 @@ void testSetOrderDetailsDone() { doNothing().when(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), - "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), + "abc"); verify(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); @@ -1462,16 +1462,16 @@ void testSetOrderDetailsDone() { @Test void testSetOrderBroughtItHimself() { when(orderRepository.findById(1L)) - .thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusBROUGHT_IT_HIMSELFDto())); + .thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusBROUGHT_IT_HIMSELFDto())); when(bagRepository.findCapacityById(1)).thenReturn(1); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), - "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), + "abc"); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); verify(orderDetailRepository, times(0)).updateExporter(anyInt(), anyLong(), anyLong()); @@ -1484,13 +1484,13 @@ void testSetOrderDetailsCanseled() { doNothing().when(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), - "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), + "abc"); verify(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); } @@ -1501,7 +1501,7 @@ void setOrderDetailExceptionTest() { Map exported = UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(); assertThrows(NotFoundException.class, - () -> ubsManagementService.setOrderDetail(1L, confirm, exported, "test@gmail.com")); + () -> ubsManagementService.setOrderDetail(1L, confirm, exported, "test@gmail.com")); } @Test @@ -1510,7 +1510,7 @@ void testSetOrderDetailThrowsUserNotFoundException() { Map exported = UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(); assertThrows(NotFoundException.class, - () -> ubsManagementService.setOrderDetail(1L, confirm, exported, "test@gmail.com")); + () -> ubsManagementService.setOrderDetail(1L, confirm, exported, "test@gmail.com")); } @Test @@ -1522,7 +1522,7 @@ void testSaveAdminToOrder() { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); ubsManagementService.saveAdminCommentToOrder(getAdminCommentDto(), "test@gmail.com"); verify(orderRepository, times(1)).save(order); verify(eventService, times(1)).save(any(), any(), any()); @@ -1541,7 +1541,7 @@ void testUpdateEcoNumberThrowOrderNotFoundException() { EcoNumberDto dto = getEcoNumberDto(); when(orderRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsManagementService.updateEcoNumberForOrder(dto, 1L, "test@gmail.com")); + () -> ubsManagementService.updateEcoNumberForOrder(dto, 1L, "test@gmail.com")); } @Test @@ -1550,7 +1550,7 @@ void updateEcoNumberTrowsException() { EcoNumberDto ecoNumberDto = getEcoNumberDto(); assertThrows(NotFoundException.class, - () -> ubsManagementService.updateEcoNumberForOrder(ecoNumberDto, 1L, "abc")); + () -> ubsManagementService.updateEcoNumberForOrder(ecoNumberDto, 1L, "abc")); } @Test @@ -1560,7 +1560,7 @@ void updateEcoNumberTrowsIncorrectEcoNumberFormatException() { EcoNumberDto ecoNumberDto = getEcoNumberDto(); ecoNumberDto.setEcoNumber(new HashSet<>(List.of("1234a"))); assertThrows(BadRequestException.class, - () -> ubsManagementService.updateEcoNumberForOrder(ecoNumberDto, 1L, "abc")); + () -> ubsManagementService.updateEcoNumberForOrder(ecoNumberDto, 1L, "abc")); } @Test @@ -1568,7 +1568,7 @@ void saveAdminCommentThrowsException() { when(orderRepository.findById(1L)).thenReturn(Optional.empty()); AdminCommentDto adminCommentDto = getAdminCommentDto(); assertThrows(NotFoundException.class, - () -> ubsManagementService.saveAdminCommentToOrder(adminCommentDto, "abc")); + () -> ubsManagementService.saveAdminCommentToOrder(adminCommentDto, "abc")); } @Test @@ -1608,23 +1608,23 @@ void updateOrderAdminPageInfoTest() { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(paymentRepository.findAllByOrderId(1L)) - .thenReturn(List.of(getPayment())); + .thenReturn(List.of(getPayment())); lenient().when(ubsManagementServiceMock.updateOrderDetailStatus(1L, orderDetailStatusRequestDto, "abc")) - .thenReturn(ModelUtils.getTestOrderDetailStatusDto()); + .thenReturn(ModelUtils.getTestOrderDetailStatusDto()); when(ubsClientService.updateUbsUserInfoInOrder(ModelUtils.getUbsCustomersDtoUpdate(), - "test@gmail.com")).thenReturn(ModelUtils.getUbsCustomersDto()); + "test@gmail.com")).thenReturn(ModelUtils.getUbsCustomersDto()); UpdateOrderPageAdminDto updateOrderPageAdminDto = updateOrderPageAdminDto(); updateOrderPageAdminDto.setUserInfoDto(ModelUtils.getUbsCustomersDtoUpdate()); when(orderAddressRepository.findById(1L)) - .thenReturn(Optional.of(getOrderAddress())); + .thenReturn(Optional.of(getOrderAddress())); when(receivingStationRepository.findAll()) - .thenReturn(List.of(getReceivingStation())); + .thenReturn(List.of(getReceivingStation())); var receivingStation = getReceivingStation(); when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.updateOrderAdminPageInfo(updateOrderPageAdminDto, 1L, "en", "test@gmail.com"); @@ -1632,7 +1632,7 @@ void updateOrderAdminPageInfoTest() { ubsManagementService.updateOrderAdminPageInfo(emptyDto, 1L, "en", "test@gmail.com"); verify(ubsClientService, times(1)) - .updateUbsUserInfoInOrder(ModelUtils.getUbsCustomersDtoUpdate(), "test@gmail.com"); + .updateUbsUserInfoInOrder(ModelUtils.getUbsCustomersDtoUpdate(), "test@gmail.com"); verify(tariffsInfoRepository, atLeastOnce()).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); } @@ -1646,25 +1646,25 @@ void updateOrderAdminPageInfoWithUbsCourierSumAndWriteOffStationSum() { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(paymentRepository.findAllByOrderId(1L)) - .thenReturn(List.of(getPayment())); + .thenReturn(List.of(getPayment())); lenient().when(ubsManagementServiceMock.updateOrderDetailStatus(1L, orderDetailStatusRequestDto, "abc")) - .thenReturn(ModelUtils.getTestOrderDetailStatusDto()); + .thenReturn(ModelUtils.getTestOrderDetailStatusDto()); when(ubsClientService.updateUbsUserInfoInOrder(ModelUtils.getUbsCustomersDtoUpdate(), - "test@gmail.com")).thenReturn(ModelUtils.getUbsCustomersDto()); + "test@gmail.com")).thenReturn(ModelUtils.getUbsCustomersDto()); UpdateOrderPageAdminDto updateOrderPageAdminDto = updateOrderPageAdminDto(); updateOrderPageAdminDto.setUserInfoDto(ModelUtils.getUbsCustomersDtoUpdate()); updateOrderPageAdminDto.setUbsCourierSum(50.); updateOrderPageAdminDto.setWriteOffStationSum(100.); when(orderAddressRepository.findById(1L)) - .thenReturn(Optional.of(getOrderAddress())); + .thenReturn(Optional.of(getOrderAddress())); when(receivingStationRepository.findAll()) - .thenReturn(List.of(getReceivingStation())); + .thenReturn(List.of(getReceivingStation())); var receivingStation = getReceivingStation(); when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.updateOrderAdminPageInfo(updateOrderPageAdminDto, 1L, "en", "test@gmail.com"); @@ -1672,7 +1672,7 @@ void updateOrderAdminPageInfoWithUbsCourierSumAndWriteOffStationSum() { ubsManagementService.updateOrderAdminPageInfo(emptyDto, 1L, "en", "test@gmail.com"); verify(ubsClientService, times(1)) - .updateUbsUserInfoInOrder(ModelUtils.getUbsCustomersDtoUpdate(), "test@gmail.com"); + .updateUbsUserInfoInOrder(ModelUtils.getUbsCustomersDtoUpdate(), "test@gmail.com"); verify(tariffsInfoRepository, atLeastOnce()).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); } @@ -1690,7 +1690,7 @@ void updateOrderAdminPageInfoWithStatusFormedTest() { when(orderRepository.save(order)).thenReturn(order); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(paymentRepository.findAllByOrderId(1L)).thenReturn(List.of(getPayment())); when(receivingStationRepository.findAll()).thenReturn(List.of(getReceivingStation())); when(employeeOrderPositionRepository.findAllByOrderId(1L)).thenReturn(List.of(employeeOrderPosition)); @@ -1707,7 +1707,7 @@ void updateOrderAdminPageInfoWithStatusFormedTest() { verify(employeeOrderPositionRepository).deleteAll(List.of(employeeOrderPosition)); verify(tariffsInfoRepository, atLeastOnce()).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); verifyNoMoreInteractions(orderRepository, employeeRepository, paymentRepository, receivingStationRepository, - employeeOrderPositionRepository, tariffsInfoRepository); + employeeOrderPositionRepository, tariffsInfoRepository); } @Test @@ -1721,7 +1721,7 @@ void updateOrderAdminPageInfoWithStatusCanceledTest() { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); IllegalStateException exception = assertThrows(IllegalStateException.class, - () -> ubsManagementService.updateOrderAdminPageInfo(updateOrderPageAdminDto, 1L, "en", "test@gmail.com")); + () -> ubsManagementService.updateOrderAdminPageInfo(updateOrderPageAdminDto, 1L, "en", "test@gmail.com")); assertEquals(String.format(ORDER_CAN_NOT_BE_UPDATED, OrderStatus.CANCELED), exception.getMessage()); @@ -1740,7 +1740,7 @@ void updateOrderAdminPageInfoWithStatusDoneTest() { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); IllegalStateException exception = assertThrows(IllegalStateException.class, - () -> ubsManagementService.updateOrderAdminPageInfo(updateOrderPageAdminDto, 1L, "en", "test@gmail.com")); + () -> ubsManagementService.updateOrderAdminPageInfo(updateOrderPageAdminDto, 1L, "en", "test@gmail.com")); assertEquals(String.format(ORDER_CAN_NOT_BE_UPDATED, OrderStatus.DONE), exception.getMessage()); @@ -1763,13 +1763,13 @@ void updateOrderAdminPageInfoWithStatusBroughtItHimselfTest() { order.setOrderStatus(OrderStatus.BROUGHT_IT_HIMSELF); Employee employee = getEmployee(); UpdateOrderPageAdminDto updateOrderPageAdminDto = - ModelUtils.updateOrderPageAdminDtoWithStatusBroughtItHimself(); + ModelUtils.updateOrderPageAdminDtoWithStatusBroughtItHimself(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(orderRepository.save(order)).thenReturn(order); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(paymentRepository.findAllByOrderId(1L)).thenReturn(List.of(getPayment())); ubsManagementService.updateOrderAdminPageInfo(updateOrderPageAdminDto, 1L, "en", "test@gmail.com"); @@ -1794,13 +1794,13 @@ void updateOrderAdminPageInfoWithNullFieldsTest() { order.setOrderStatus(OrderStatus.ON_THE_ROUTE); Employee employee = getEmployee(); UpdateOrderPageAdminDto updateOrderPageAdminDto = - ModelUtils.updateOrderPageAdminDtoWithNullFields(); + ModelUtils.updateOrderPageAdminDtoWithNullFields(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(orderRepository.save(order)).thenReturn(order); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(paymentRepository.findAllByOrderId(1L)).thenReturn(List.of(getPayment())); when(receivingStationRepository.findAll()).thenReturn(List.of(getReceivingStation())); @@ -1814,7 +1814,7 @@ void updateOrderAdminPageInfoWithNullFieldsTest() { verify(receivingStationRepository).findAll(); verify(tariffsInfoRepository, atLeastOnce()).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); verifyNoMoreInteractions(orderRepository, employeeRepository, paymentRepository, receivingStationRepository, - tariffsInfoRepository); + tariffsInfoRepository); } @Test @@ -1827,10 +1827,10 @@ void updateOrderAdminPageInfoTestThrowsException() { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); assertThrows(BadRequestException.class, - () -> ubsManagementService.updateOrderAdminPageInfo( - updateOrderPageAdminDto, 1L, "en", "test@gmail.com")); + () -> ubsManagementService.updateOrderAdminPageInfo( + updateOrderPageAdminDto, 1L, "en", "test@gmail.com")); verify(orderRepository, atLeastOnce()).findById(1L); verify(employeeRepository).findByEmail("test@gmail.com"); verify(tariffsInfoRepository, atLeastOnce()).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -1840,9 +1840,9 @@ void updateOrderAdminPageInfoTestThrowsException() { void updateOrderAdminPageInfoForOrderWithStatusBroughtItHimselfTest() { UpdateOrderPageAdminDto updateOrderPageAdminDto = updateOrderPageAdminDto(); updateOrderPageAdminDto.setGeneralOrderInfo(OrderDetailStatusRequestDto - .builder() - .orderStatus(String.valueOf(OrderStatus.DONE)) - .build()); + .builder() + .orderStatus(String.valueOf(OrderStatus.DONE)) + .build()); LocalDateTime orderDate = LocalDateTime.now(); TariffsInfo tariffsInfo = getTariffsInfo(); @@ -1859,7 +1859,7 @@ void updateOrderAdminPageInfoForOrderWithStatusBroughtItHimselfTest() { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(paymentRepository.findAllByOrderId(1L)).thenReturn(List.of(getPayment())); ubsManagementService.updateOrderAdminPageInfo(updateOrderPageAdminDto, 1L, "en", "test@gmail.com"); @@ -2013,24 +2013,19 @@ void getOrderStatusDataTest() { when(orderRepository.findById(order.getId())).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); -<<<<<<< HEAD - when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); - when(certificateRepository.findCertificate(1L)).thenReturn(ModelUtils.getCertificateList()); -======= when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(1L)).thenReturn(getCertificateList()); ->>>>>>> dev when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when(orderStatusTranslationRepository.getOrderStatusTranslationById(6L)) - .thenReturn(Optional.ofNullable(getStatusTranslation())); + .thenReturn(Optional.ofNullable(getStatusTranslation())); when(orderStatusTranslationRepository.findAllBy()).thenReturn(getOrderStatusTranslations()); when( - orderPaymentStatusTranslationRepository.getById(1L)) + orderPaymentStatusTranslationRepository.getById(1L)) .thenReturn(OrderPaymentStatusTranslation.builder().translationValue("name").build()); when(orderPaymentStatusTranslationRepository.getAllBy()).thenReturn(getOrderStatusPaymentTranslations()); when(orderRepository.findById(6L)).thenReturn(Optional.of(order)); @@ -2040,7 +2035,7 @@ void getOrderStatusDataTest() { verify(orderRepository).getOrderDetails(1L); verify(bagRepository).findBagsByOrderId(1L); - verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); + verify(bagRepository).findBagsByTariffsInfoId(1L); verify(certificateRepository).findCertificate(1L); verify(orderRepository, times(5)).findById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); @@ -2064,21 +2059,21 @@ void saveNewManualPaymentWhenImageNotNull() { order.setOrderPaymentStatus(OrderPaymentStatus.PAID); Payment payment = getManualPayment(); ManualPaymentRequestDto paymentDetails = ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021").amount(500L).receiptLink("link").paymentId("1").build(); + .settlementdate("02-08-2021").amount(500L).receiptLink("link").paymentId("1").build(); Employee employee = getEmployee(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.save(any())) - .thenReturn(payment); + .thenReturn(payment); doNothing().when(eventService).save(OrderHistory.ADD_PAYMENT_MANUALLY + 1, "Петро" + " " + "Петренко", order); ubsManagementService.saveNewManualPayment(1L, paymentDetails, Mockito.mock(MultipartFile.class), - "test@gmail.com"); + "test@gmail.com"); verify(eventService, times(1)) - .save("Замовлення Оплачено", "Система", order); + .save("Замовлення Оплачено", "Система", order); verify(paymentRepository, times(1)).save(any()); verify(orderRepository, times(1)).findById(1L); verify(tariffsInfoRepository, atLeastOnce()).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -2094,28 +2089,28 @@ void getOrderStatusDataTestEmptyPriceDetails() { when(orderRepository.findById(order.getId())).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); - when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); + when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag2list()); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when(orderStatusTranslationRepository.getOrderStatusTranslationById(6L)) - .thenReturn(Optional.ofNullable(getStatusTranslation())); + .thenReturn(Optional.ofNullable(getStatusTranslation())); when( - orderPaymentStatusTranslationRepository.getById(1L)) + orderPaymentStatusTranslationRepository.getById(1L)) .thenReturn(OrderPaymentStatusTranslation.builder().translationValue("name").build()); when(orderRepository.findById(6L)).thenReturn(Optional.of(order)); when(receivingStationRepository.findAll()).thenReturn(getReceivingList()); when(modelMapper.map(getOrderForGetOrderStatusData2Test().getPayment().get(0), PaymentInfoDto.class)) - .thenReturn(getInfoPayment()); + .thenReturn(getInfoPayment()); ubsManagementService.getOrderStatusData(1L, "test@gmail.com"); verify(orderRepository).getOrderDetails(1L); verify(bagRepository).findBagsByOrderId(1L); - verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); + verify(bagRepository).findBagsByTariffsInfoId(1L); verify(certificateRepository).findCertificate(1L); verify(orderRepository, times(5)).findById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); @@ -2137,17 +2132,17 @@ void getOrderStatusDataWithEmptyCertificateTest() { when(orderRepository.findById(order.getId())).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); - when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); + when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when(orderStatusTranslationRepository.getOrderStatusTranslationById(6L)) - .thenReturn(Optional.ofNullable(getStatusTranslation())); + .thenReturn(Optional.ofNullable(getStatusTranslation())); when( - orderPaymentStatusTranslationRepository.getById(1L)) + orderPaymentStatusTranslationRepository.getById(1L)) .thenReturn(OrderPaymentStatusTranslation.builder().translationValue("name").build()); when(orderRepository.findById(6L)).thenReturn(Optional.of(order)); when(receivingStationRepository.findAll()).thenReturn(getReceivingList()); @@ -2156,7 +2151,7 @@ void getOrderStatusDataWithEmptyCertificateTest() { verify(orderRepository).getOrderDetails(1L); verify(bagRepository).findBagsByOrderId(1L); - verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); + verify(bagRepository).findBagsByTariffsInfoId(1L); verify(orderRepository, times(5)).findById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); verify(modelMapper).map(getBaglist().get(0), BagInfoDto.class); @@ -2176,15 +2171,15 @@ void getOrderStatusDataWhenOrderTranslationIsNull() { when(orderRepository.findById(order.getId())).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); - when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); + when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when( - orderPaymentStatusTranslationRepository.getById(1L)) + orderPaymentStatusTranslationRepository.getById(1L)) .thenReturn(OrderPaymentStatusTranslation.builder().translationValue("name").build()); when(orderRepository.findById(6L)).thenReturn(Optional.of(order)); when(receivingStationRepository.findAll()).thenReturn(getReceivingList()); @@ -2193,7 +2188,7 @@ void getOrderStatusDataWhenOrderTranslationIsNull() { verify(orderRepository).getOrderDetails(1L); verify(bagRepository).findBagsByOrderId(1L); - verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); + verify(bagRepository).findBagsByTariffsInfoId(1L); verify(orderRepository, times(5)).findById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); verify(modelMapper).map(getBaglist().get(0), BagInfoDto.class); @@ -2213,7 +2208,7 @@ void getOrderStatusDataExceptionTest() { when(orderRepository.findById(order.getId())).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(1L)).thenReturn(getCertificateList()); @@ -2221,9 +2216,9 @@ void getOrderStatusDataExceptionTest() { when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when(orderStatusTranslationRepository.getOrderStatusTranslationById(6L)) - .thenReturn(Optional.ofNullable(getStatusTranslation())); + .thenReturn(Optional.ofNullable(getStatusTranslation())); when( - orderPaymentStatusTranslationRepository.getById(1L)) + orderPaymentStatusTranslationRepository.getById(1L)) .thenReturn(OrderPaymentStatusTranslation.builder().translationValue("name").build()); assertThrows(NotFoundException.class, () -> ubsManagementService.getOrderStatusData(1L, "test@gmail.com")); } @@ -2267,7 +2262,7 @@ void updateOrderExportDetailsEmptyDetailsTest() { void updateOrderExportDetailsUserNotFoundExceptionTest() { ExportDetailsDtoUpdate testDetails = getExportDetailsRequest(); assertThrows(NotFoundException.class, - () -> ubsManagementService.updateOrderExportDetails(1L, testDetails, "test@gmail.com")); + () -> ubsManagementService.updateOrderExportDetails(1L, testDetails, "test@gmail.com")); } @Test @@ -2275,7 +2270,7 @@ void updateOrderExportDetailsUnexistingOrderExceptionTest() { ExportDetailsDtoUpdate testDetails = getExportDetailsRequest(); when(orderRepository.findById(anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsManagementService.updateOrderExportDetails(1L, testDetails, "abc")); + () -> ubsManagementService.updateOrderExportDetails(1L, testDetails, "abc")); } @Test @@ -2286,7 +2281,7 @@ void updateOrderExportDetailsReceivingStationNotFoundExceptionTest() { when(orderRepository.findById(anyLong())).thenReturn(Optional.of(order)); when(receivingStationRepository.findAll()).thenReturn(Collections.emptyList()); assertThrows(NotFoundException.class, - () -> ubsManagementService.updateOrderExportDetails(1L, testDetails, "abc")); + () -> ubsManagementService.updateOrderExportDetails(1L, testDetails, "abc")); } @Test @@ -2315,7 +2310,7 @@ void getPaymentInfoWithoutPayment() { void getPaymentInfoExceptionTest() { when(orderRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsManagementService.getPaymentInfo(1L, 100.)); + () -> ubsManagementService.getPaymentInfo(1L, 100.)); } @Test @@ -2327,7 +2322,7 @@ void updateManualPayment() { requestDto.setImagePath(""); payment.setImagePath("abc"); MockMultipartFile file = new MockMultipartFile("manualPaymentDto", - "", "application/json", "random Bytes".getBytes()); + "", "application/json", "random Bytes".getBytes()); when(employeeRepository.findByUuid(employee.getUuid())).thenReturn(Optional.of(employee)); when(paymentRepository.findById(payment.getId())).thenReturn(Optional.of(payment)); @@ -2344,7 +2339,7 @@ void updateManualPayment() { void updateManualPaymentUserNotFoundExceptionTest() { when(employeeRepository.findByUuid(anyString())).thenReturn(Optional.empty()); assertThrows(EntityNotFoundException.class, - () -> ubsManagementService.updateManualPayment(1L, null, null, "abc")); + () -> ubsManagementService.updateManualPayment(1L, null, null, "abc")); } @Test @@ -2352,7 +2347,7 @@ void updateManualPaymentPaymentNotFoundExceptionTest() { when(employeeRepository.findByUuid(anyString())).thenReturn(Optional.of(getEmployee())); when(paymentRepository.findById(anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsManagementService.updateManualPayment(1L, null, null, "abc")); + () -> ubsManagementService.updateManualPayment(1L, null, null, "abc")); } @Test @@ -2361,7 +2356,7 @@ void updateAllOrderAdminPageInfoUnexistingOrderExceptionTest() { UpdateAllOrderPageDto updateAllOrderPageDto = updateAllOrderPageDto(); when(orderRepository.findById(4L)).thenReturn(Optional.ofNullable(order)); assertThrows(NotFoundException.class, - () -> ubsManagementService.updateAllOrderAdminPageInfo(updateAllOrderPageDto, "uuid", "ua")); + () -> ubsManagementService.updateAllOrderAdminPageInfo(updateAllOrderPageDto, "uuid", "ua")); } @Test @@ -2369,7 +2364,7 @@ void updateAllOrderAdminPageInfoUpdateAdminPageInfoExceptionTest() { UpdateAllOrderPageDto updateAllOrderPageDto = updateAllOrderPageDto(); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(Order.builder().build())); assertThrows(BadRequestException.class, - () -> ubsManagementService.updateAllOrderAdminPageInfo(updateAllOrderPageDto, "uuid", "ua")); + () -> ubsManagementService.updateAllOrderAdminPageInfo(updateAllOrderPageDto, "uuid", "ua")); } @Test @@ -2384,49 +2379,49 @@ void updateAllOrderAdminPageInfoStatusConfirmedTest() { UpdateAllOrderPageDto expectedObject = updateAllOrderPageDto(); UpdateAllOrderPageDto actual = updateAllOrderPageDto(); assertEquals(expectedObject.getExportDetailsDto().getDateExport(), - actual.getExportDetailsDto().getDateExport()); + actual.getExportDetailsDto().getDateExport()); ubsManagementService.updateAllOrderAdminPageInfo(expectedObject, "uuid", "ua"); expectedObject = updateAllOrderPageDto(); actual = updateAllOrderPageDto(); assertEquals(expectedObject.getExportDetailsDto().getDateExport(), - actual.getExportDetailsDto().getDateExport()); + actual.getExportDetailsDto().getDateExport()); ubsManagementService.updateAllOrderAdminPageInfo(expectedObject, "uuid", "ua"); expectedObject = updateAllOrderPageDto(); actual = updateAllOrderPageDto(); assertEquals(expectedObject.getExportDetailsDto().getDateExport(), - actual.getExportDetailsDto().getDateExport()); + actual.getExportDetailsDto().getDateExport()); ubsManagementService.updateAllOrderAdminPageInfo(expectedObject, "uuid", "ua"); expectedObject = updateAllOrderPageDto(); actual = updateAllOrderPageDto(); assertEquals(expectedObject.getExportDetailsDto().getDateExport(), - actual.getExportDetailsDto().getDateExport()); + actual.getExportDetailsDto().getDateExport()); ubsManagementService.updateAllOrderAdminPageInfo(expectedObject, "uuid", "ua"); expectedObject = updateAllOrderPageDto(); actual = updateAllOrderPageDto(); assertEquals(expectedObject.getExportDetailsDto().getDateExport(), - actual.getExportDetailsDto().getDateExport()); + actual.getExportDetailsDto().getDateExport()); ubsManagementService.updateAllOrderAdminPageInfo(expectedObject, "uuid", "ua"); expectedObject = updateAllOrderPageDto(); actual = updateAllOrderPageDto(); assertEquals(expectedObject.getExportDetailsDto().getDateExport(), - actual.getExportDetailsDto().getDateExport()); + actual.getExportDetailsDto().getDateExport()); ubsManagementService.updateAllOrderAdminPageInfo(expectedObject, "uuid", "ua"); expectedObject = updateAllOrderPageDto(); actual = updateAllOrderPageDto(); assertEquals(expectedObject.getExportDetailsDto().getDateExport(), - actual.getExportDetailsDto().getDateExport()); + actual.getExportDetailsDto().getDateExport()); ubsManagementService.updateAllOrderAdminPageInfo(expectedObject, "uuid", "ua"); } @@ -2473,7 +2468,7 @@ void saveReasonWhenListElementsAreNotNulls() { when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(order)); ubsManagementService.saveReason(1L, "uu", new MultipartFile[] { - new MockMultipartFile("Name", new byte[2]), new MockMultipartFile("Name", new byte[2])}); + new MockMultipartFile("Name", new byte[2]), new MockMultipartFile("Name", new byte[2])}); verify(orderRepository).findById(1L); } @@ -2489,20 +2484,20 @@ void getOrderStatusDataWithNotEmptyLists() { when(orderRepository.findById(order.getId())).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); + when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(1L)).thenReturn(getCertificateList()); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when(orderStatusTranslationRepository.getOrderStatusTranslationById(6L)) - .thenReturn(Optional.ofNullable(getStatusTranslation())); + .thenReturn(Optional.ofNullable(getStatusTranslation())); when( - orderPaymentStatusTranslationRepository.getById(1L)) + orderPaymentStatusTranslationRepository.getById(1L)) .thenReturn(OrderPaymentStatusTranslation.builder().translationValue("name").build()); when( - orderPaymentStatusTranslationRepository.getAllBy()) + orderPaymentStatusTranslationRepository.getAllBy()) .thenReturn(List.of(orderPaymentStatusTranslation)); when(orderRepository.findById(6L)).thenReturn(Optional.of(order)); @@ -2510,14 +2505,14 @@ void getOrderStatusDataWithNotEmptyLists() { ubsManagementService.getOrderStatusData(1L, "test@gmail.com"); verify(orderRepository).getOrderDetails(1L); - verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); + verify(bagRepository).findBagsByTariffsInfoId(1L); verify(bagRepository).findBagsByOrderId(1L); verify(certificateRepository).findCertificate(1L); verify(orderRepository, times(5)).findById(1L); verify(modelMapper).map(getBaglist().get(0), BagInfoDto.class); verify(orderStatusTranslationRepository).getOrderStatusTranslationById(6L); verify(orderPaymentStatusTranslationRepository).getById( - 1L); + 1L); verify(receivingStationRepository).findAll(); verify(tariffsInfoRepository, atLeastOnce()).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); } @@ -2535,24 +2530,24 @@ void getOrderStatusesTranslationTest() { when(orderRepository.findById(order.getId())).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); - when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); + when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(1L)).thenReturn(getCertificateList()); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when(orderStatusTranslationRepository.getOrderStatusTranslationById(6L)) - .thenReturn(Optional.ofNullable(getStatusTranslation())); + .thenReturn(Optional.ofNullable(getStatusTranslation())); when( - orderPaymentStatusTranslationRepository.getById(1L)) + orderPaymentStatusTranslationRepository.getById(1L)) .thenReturn(OrderPaymentStatusTranslation.builder().translationValue("name").build()); when(orderStatusTranslationRepository.findAllBy()) - .thenReturn(list); + .thenReturn(list); when( - orderPaymentStatusTranslationRepository.getAllBy()) + orderPaymentStatusTranslationRepository.getAllBy()) .thenReturn(List.of(orderPaymentStatusTranslation)); when(orderRepository.findById(6L)).thenReturn(Optional.of(order)); @@ -2562,13 +2557,13 @@ void getOrderStatusesTranslationTest() { verify(orderRepository).getOrderDetails(1L); verify(bagRepository).findBagsByOrderId(1L); - verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); + verify(bagRepository).findBagsByTariffsInfoId(1L); verify(certificateRepository).findCertificate(1L); verify(orderRepository, times(5)).findById(1L); verify(modelMapper).map(getBaglist().get(0), BagInfoDto.class); verify(orderStatusTranslationRepository).getOrderStatusTranslationById(6L); verify(orderPaymentStatusTranslationRepository).getById( - 1L); + 1L); verify(receivingStationRepository).findAll(); verify(tariffsInfoRepository, atLeastOnce()).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -2591,7 +2586,7 @@ void deleteManualPaymentTest() { verify(paymentRepository).deletePaymentById(1L); verify(fileService).delete(payment.getImagePath()); verify(eventService).save(OrderHistory.DELETE_PAYMENT_MANUALLY + payment.getPaymentId(), - employee.getFirstName() + " " + employee.getLastName(), payment.getOrder()); + employee.getFirstName() + " " + employee.getLastName(), payment.getOrder()); } @@ -2613,14 +2608,14 @@ void deleteManualTestWithoutImage() { verify(paymentRepository).deletePaymentById(1L); verify(fileService, times(0)).delete(payment.getImagePath()); verify(eventService).save(OrderHistory.DELETE_PAYMENT_MANUALLY + payment.getPaymentId(), - employee.getFirstName() + " " + employee.getLastName(), payment.getOrder()); + employee.getFirstName() + " " + employee.getLastName(), payment.getOrder()); } @Test void deleteManualTestWithoutUser() { when(employeeRepository.findByUuid("uuid25")).thenReturn(Optional.empty()); EntityNotFoundException ex = - assertThrows(EntityNotFoundException.class, () -> ubsManagementService.deleteManualPayment(1L, "uuid25")); + assertThrows(EntityNotFoundException.class, () -> ubsManagementService.deleteManualPayment(1L, "uuid25")); assertEquals(EMPLOYEE_NOT_FOUND, ex.getMessage()); } @@ -2709,7 +2704,7 @@ void addBonusesToUserWithNoOverpaymentTest() { AddBonusesToUserDto addBonusesToUserDto = getAddBonusesToUserDto(); assertThrows(BadRequestException.class, - () -> ubsManagementService.addBonusesToUser(addBonusesToUserDto, 1L, email)); + () -> ubsManagementService.addBonusesToUser(addBonusesToUserDto, 1L, email)); } @Test @@ -2730,8 +2725,8 @@ void checkEmployeeForOrderTest() { void updateOrderStatusToExpected() { ubsManagementService.updateOrderStatusToExpected(); verify(orderRepository).updateOrderStatusToExpected(OrderStatus.CONFIRMED.name(), - OrderStatus.ON_THE_ROUTE.name(), - LocalDate.now()); + OrderStatus.ON_THE_ROUTE.name(), + LocalDate.now()); } @ParameterizedTest @@ -2757,28 +2752,28 @@ private static Stream provideOrdersWithDifferentInitialExportDetailsF orderWithoutDeliverFromTo.setDeliverFrom(null); orderWithoutDeliverFromTo.setDeliverTo(null); String updateExportDetails = String.format(OrderHistory.UPDATE_EXPORT_DATA, - LocalDate.of(1997, 12, 4)) + - String.format(OrderHistory.UPDATE_DELIVERY_TIME, - LocalTime.of(15, 40, 24), LocalTime.of(19, 30, 30)) - + - String.format(OrderHistory.UPDATE_RECEIVING_STATION, "Петрівка"); + LocalDate.of(1997, 12, 4)) + + String.format(OrderHistory.UPDATE_DELIVERY_TIME, + LocalTime.of(15, 40, 24), LocalTime.of(19, 30, 30)) + + + String.format(OrderHistory.UPDATE_RECEIVING_STATION, "Петрівка"); return Stream.of( - Arguments.of(getOrderExportDetailsWithNullValues(), - OrderHistory.SET_EXPORT_DETAILS + updateExportDetails), - Arguments.of(getOrderExportDetailsWithExportDate(), - OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), - Arguments.of(getOrderExportDetailsWithExportDateDeliverFrom(), - OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), - Arguments.of(getOrderExportDetailsWithExportDateDeliverFromTo(), - OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), - Arguments.of(getOrderExportDetails(), - OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), - Arguments.of(getOrderExportDetailsWithDeliverFromTo(), - OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), - Arguments.of(orderWithoutExportDate, - OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), - Arguments.of(orderWithoutDeliverFromTo, - OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails)); + Arguments.of(getOrderExportDetailsWithNullValues(), + OrderHistory.SET_EXPORT_DETAILS + updateExportDetails), + Arguments.of(getOrderExportDetailsWithExportDate(), + OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), + Arguments.of(getOrderExportDetailsWithExportDateDeliverFrom(), + OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), + Arguments.of(getOrderExportDetailsWithExportDateDeliverFromTo(), + OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), + Arguments.of(getOrderExportDetails(), + OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), + Arguments.of(getOrderExportDetailsWithDeliverFromTo(), + OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), + Arguments.of(orderWithoutExportDate, + OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), + Arguments.of(orderWithoutDeliverFromTo, + OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails)); } @Test @@ -2791,10 +2786,10 @@ void updateOrderExportDetailsWhenDeliverFromIsNull() { order.setDeliverFrom(null); testDetails.setTimeDeliveryFrom(null); String expectedHistoryEvent = OrderHistory.UPDATE_EXPORT_DETAILS - + String.format(OrderHistory.UPDATE_EXPORT_DATA, + + String.format(OrderHistory.UPDATE_EXPORT_DATA, LocalDate.of(1997, 12, 4)) - + - String.format(OrderHistory.UPDATE_RECEIVING_STATION, "Петрівка"); + + + String.format(OrderHistory.UPDATE_RECEIVING_STATION, "Петрівка"); when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); when(orderRepository.findById(anyLong())).thenReturn(Optional.of(order)); @@ -2815,10 +2810,10 @@ void updateOrderExportDetailsWhenDeliverToIsNull() { order.setDeliverTo(null); testDetails.setTimeDeliveryTo(null); String expectedHistoryEvent = OrderHistory.UPDATE_EXPORT_DETAILS - + String.format(OrderHistory.UPDATE_EXPORT_DATA, + + String.format(OrderHistory.UPDATE_EXPORT_DATA, LocalDate.of(1997, 12, 4)) - + - String.format(OrderHistory.UPDATE_RECEIVING_STATION, "Петрівка"); + + + String.format(OrderHistory.UPDATE_RECEIVING_STATION, "Петрівка"); when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); when(orderRepository.findById(anyLong())).thenReturn(Optional.of(order)); @@ -2869,9 +2864,9 @@ void getNotTakenOrderReasonWithoutOrderTest() { @Test void saveNewManualPaymentWithoutLinkAndImageTest() { ManualPaymentRequestDto paymentDetails = ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021").amount(500L).paymentId("1").build(); + .settlementdate("02-08-2021").amount(500L).paymentId("1").build(); assertThrows(BadRequestException.class, - () -> ubsManagementService.saveNewManualPayment(1L, paymentDetails, null, "test@gmail.com")); + () -> ubsManagementService.saveNewManualPayment(1L, paymentDetails, null, "test@gmail.com")); } @Test From 5ef962f63c47409a4847c2d683625e9351efc1df Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Sun, 23 Jul 2023 15:14:12 +0300 Subject: [PATCH 11/73] Formatted --- .../src/test/java/greencity/ModelUtils.java | 1 - .../ubs/SuperAdminServiceImplTest.java | 628 +++++++++--------- .../service/ubs/UBSClientServiceImplTest.java | 508 +++++++------- .../ubs/UBSManagementServiceImplTest.java | 562 ++++++++-------- 4 files changed, 849 insertions(+), 850 deletions(-) diff --git a/service/src/test/java/greencity/ModelUtils.java b/service/src/test/java/greencity/ModelUtils.java index a4cc5900f..32d7fb7eb 100644 --- a/service/src/test/java/greencity/ModelUtils.java +++ b/service/src/test/java/greencity/ModelUtils.java @@ -2773,7 +2773,6 @@ public static Bag getBagForOrder() { .build(); } - public static TariffServiceDto getTariffServiceDto() { return TariffServiceDto.builder() .name("Бавовняна сумка") diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index 6be3ae405..49327a86e 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -135,18 +135,18 @@ class SuperAdminServiceImplTest { @AfterEach void afterEach() { verifyNoMoreInteractions( - userRepository, - employeeRepository, - bagRepository, - locationRepository, - modelMapper, - serviceRepository, - courierRepository, - regionRepository, - receivingStationRepository, - tariffsInfoRepository, - tariffsLocationRepository, - deactivateTariffsForChosenParamRepository); + userRepository, + employeeRepository, + bagRepository, + locationRepository, + modelMapper, + serviceRepository, + courierRepository, + regionRepository, + receivingStationRepository, + tariffsInfoRepository, + tariffsLocationRepository, + deactivateTariffsForChosenParamRepository); } @Test @@ -182,7 +182,7 @@ void addTariffServiceIfEmployeeNotFoundExceptionTest() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.addTariffService(1L, dto, uuid)); + () -> superAdminService.addTariffService(1L, dto, uuid)); verify(tariffsInfoRepository).findById(1L); verify(employeeRepository).findByUuid(uuid); @@ -197,7 +197,7 @@ void addTariffServiceIfTariffNotFoundExceptionTest() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.addTariffService(1L, dto, uuid)); + () -> superAdminService.addTariffService(1L, dto, uuid)); verify(tariffsInfoRepository).findById(1L); verify(bagRepository, never()).save(any(Bag.class)); @@ -224,7 +224,7 @@ void getTariffServiceIfTariffNotFoundException() { when(tariffsInfoRepository.existsById(1L)).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.getTariffService(1)); + () -> superAdminService.getTariffService(1)); verify(tariffsInfoRepository).existsById(1L); verify(bagRepository, never()).findBagsByTariffsInfoId(1L); @@ -292,7 +292,7 @@ void deleteTariffServiceWhenTariffBagsWithoutLimits() { void deleteTariffServiceThrowNotFoundException() { when(bagRepository.findById(1)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.deleteTariffService(1)); + () -> superAdminService.deleteTariffService(1)); verify(bagRepository).findById(1); verify(bagRepository, never()).delete(any(Bag.class)); } @@ -349,7 +349,7 @@ void editTariffServiceIfEmployeeNotFoundException() { when(bagRepository.findById(1)).thenReturn(bag); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariffService(dto, 1, uuid)); + () -> superAdminService.editTariffService(dto, 1, uuid)); verify(bagRepository).findById(1); verify(bagRepository, never()).save(any(Bag.class)); @@ -362,7 +362,7 @@ void editTariffServiceIfBagNotFoundException() { when(bagRepository.findById(1)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariffService(dto, 1, uuid)); + () -> superAdminService.editTariffService(dto, 1, uuid)); verify(bagRepository).findById(1); verify(bagRepository, never()).save(any(Bag.class)); @@ -372,7 +372,7 @@ void editTariffServiceIfBagNotFoundException() { void getAllCouriersTest() { when(courierRepository.findAll()).thenReturn(List.of(getCourier())); when(modelMapper.map(getCourier(), CourierDto.class)) - .thenReturn(getCourierDto()); + .thenReturn(getCourierDto()); assertEquals(getCourierDtoList(), superAdminService.getAllCouriers()); @@ -399,7 +399,7 @@ void deleteServiceThrowNotFoundException() { when(serviceRepository.findById(service.getId())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.deleteService(1L)); + () -> superAdminService.deleteService(1L)); verify(serviceRepository).findById(1L); verify(serviceRepository, never()).delete(service); @@ -438,7 +438,7 @@ void getServiceThrowTariffNotFoundException() { when(tariffsInfoRepository.existsById(1L)).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.getService(1L)); + () -> superAdminService.getService(1L)); verify(tariffsInfoRepository).existsById(1L); } @@ -472,7 +472,7 @@ void editServiceServiceNotFoundException() { when(serviceRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editService(1L, dto, uuid)); + () -> superAdminService.editService(1L, dto, uuid)); verify(serviceRepository).findById(1L); verify(serviceRepository, never()).save(any(Service.class)); @@ -489,7 +489,7 @@ void editServiceEmployeeNotFoundException() { when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editService(1L, dto, uuid)); + () -> superAdminService.editService(1L, dto, uuid)); verify(employeeRepository).findByUuid(uuid); verify(serviceRepository).findById(1L); @@ -536,7 +536,7 @@ void addServiceThrowServiceAlreadyExistsException() { when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(createdService)); assertThrows(ServiceAlreadyExistsException.class, - () -> superAdminService.addService(1L, serviceDto, uuid)); + () -> superAdminService.addService(1L, serviceDto, uuid)); verify(tariffsInfoRepository).existsById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); @@ -552,7 +552,7 @@ void addServiceThrowEmployeeNotFoundException() { when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.addService(1L, serviceDto, uuid)); + () -> superAdminService.addService(1L, serviceDto, uuid)); verify(tariffsInfoRepository).existsById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); @@ -567,7 +567,7 @@ void addServiceThrowTariffNotFoundException() { when(tariffsInfoRepository.existsById(1L)).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.addService(1L, serviceDto, uuid)); + () -> superAdminService.addService(1L, serviceDto, uuid)); verify(tariffsInfoRepository).existsById(1L); } @@ -589,7 +589,7 @@ void getLocationsByStatusTest() { List regionList = ModelUtils.getAllRegion(); when(regionRepository.findAllByLocationsLocationStatus(LocationStatus.ACTIVE)) - .thenReturn(Optional.of(regionList)); + .thenReturn(Optional.of(regionList)); var result = superAdminService.getLocationsByStatus(LocationStatus.ACTIVE); @@ -602,13 +602,13 @@ void getLocationsByStatusTest() { @Test void getLocationsByStatusNotFoundExceptionTest() { when(regionRepository.findAllByLocationsLocationStatus(LocationStatus.ACTIVE)) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); NotFoundException notFoundException = assertThrows(NotFoundException.class, - () -> superAdminService.getLocationsByStatus(LocationStatus.ACTIVE)); + () -> superAdminService.getLocationsByStatus(LocationStatus.ACTIVE)); assertEquals(String.format(ErrorMessage.REGIONS_NOT_FOUND_BY_LOCATION_STATUS, LocationStatus.ACTIVE.name()), - notFoundException.getMessage()); + notFoundException.getMessage()); verify(regionRepository).findAllByLocationsLocationStatus(LocationStatus.ACTIVE); } @@ -619,7 +619,7 @@ void addLocationTest() { Region region = ModelUtils.getRegion(); when(regionRepository.findRegionByEnNameAndUkrName("Kyiv region", "Київська область")) - .thenReturn(Optional.of(region)); + .thenReturn(Optional.of(region)); superAdminService.addLocation(locationCreateDtoList); @@ -633,7 +633,7 @@ void addLocationCreateNewRegionTest() { List locationCreateDtoList = ModelUtils.getLocationCreateDtoList(); Location location = ModelUtils.getLocationForCreateRegion(); when(regionRepository.findRegionByEnNameAndUkrName("Kyiv region", "Київська область")) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); when(regionRepository.save(any())).thenReturn(ModelUtils.getRegion()); superAdminService.addLocation(locationCreateDtoList); verify(locationRepository).findLocationByNameAndRegionId("Київ", "Kyiv", 1L); @@ -645,7 +645,7 @@ void addLocationCreateNewRegionTest() { void deleteLocationTest() { Location location = ModelUtils.getLocationDto(); location - .setTariffLocations(Set.of(TariffLocation.builder().location(Location.builder().id(2L).build()).build())); + .setTariffLocations(Set.of(TariffLocation.builder().location(Location.builder().id(2L).build()).build())); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); superAdminService.deleteLocation(1L); verify(locationRepository).findById(1L); @@ -656,7 +656,7 @@ void deleteLocationTest() { void deleteLocationThrowsBadRequestExceptionTest() { Location location = ModelUtils.getLocationDto(); location - .setTariffLocations(Set.of(TariffLocation.builder().location(Location.builder().id(1L).build()).build())); + .setTariffLocations(Set.of(TariffLocation.builder().location(Location.builder().id(1L).build()).build())); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); assertThrows(BadRequestException.class, () -> superAdminService.deleteLocation(1L)); verify(locationRepository).findById(1L); @@ -679,7 +679,7 @@ void addLocationThrowLocationAlreadyCreatedExceptionTest() { List locationCreateDtoList = ModelUtils.getLocationCreateDtoList(); Location location = ModelUtils.getLocation(); when(regionRepository.findRegionByEnNameAndUkrName("Kyiv region", "Київська область")) - .thenReturn(Optional.of(ModelUtils.getRegion())); + .thenReturn(Optional.of(ModelUtils.getRegion())); when(locationRepository.findLocationByNameAndRegionId("Київ", "Kyiv", 1L)).thenReturn(Optional.of(location)); assertThrows(NotFoundException.class, () -> superAdminService.addLocation(locationCreateDtoList)); @@ -722,17 +722,17 @@ void deactivateCourierThrowBadRequestException() { when(courierRepository.findById(anyLong())).thenReturn(Optional.of(courier)); courier.setCourierStatus(CourierStatus.DEACTIVATED); assertThrows(BadRequestException.class, - () -> superAdminService.deactivateCourier(1L)); + () -> superAdminService.deactivateCourier(1L)); verify(courierRepository).findById(1L); } @Test void deactivateCourierThrowNotFoundException() { when(courierRepository.findById(anyLong())) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); Exception thrownNotFoundEx = assertThrows(NotFoundException.class, - () -> superAdminService.deactivateCourier(1L)); + () -> superAdminService.deactivateCourier(1L)); assertEquals(ErrorMessage.COURIER_IS_NOT_FOUND_BY_ID + 1L, thrownNotFoundEx.getMessage()); verify(courierRepository).findById(1L); @@ -746,14 +746,14 @@ void createCourier() { when(employeeRepository.findByUuid(anyString())).thenReturn(Optional.ofNullable(getEmployee())); when(courierRepository.findAll()).thenReturn(List.of(Courier.builder() - .nameEn("Test1") - .nameUk("Тест1") - .build())); + .nameEn("Test1") + .nameUk("Тест1") + .build())); when(courierRepository.save(any())).thenReturn(courier); when(modelMapper.map(any(), eq(CreateCourierDto.class))).thenReturn(createCourierDto); assertEquals(createCourierDto, - superAdminService.createCourier(createCourierDto, ModelUtils.TEST_USER.getUuid())); + superAdminService.createCourier(createCourierDto, ModelUtils.TEST_USER.getUuid())); verify(courierRepository).save(any()); verify(modelMapper).map(any(), eq(CreateCourierDto.class)); @@ -770,7 +770,7 @@ void createCourierAlreadyExists() { when(courierRepository.findAll()).thenReturn(List.of(getCourier(), getCourier())); Throwable throwable = assertThrows(CourierAlreadyExists.class, - () -> superAdminService.createCourier(createCourierDto, uuid)); + () -> superAdminService.createCourier(createCourierDto, uuid)); assertEquals(ErrorMessage.COURIER_ALREADY_EXISTS, throwable.getMessage()); verify(employeeRepository).findByUuid(anyString()); verify(courierRepository).findAll(); @@ -781,24 +781,24 @@ void updateCourierTest() { Courier courier = getCourier(); CourierUpdateDto dto = CourierUpdateDto.builder() - .courierId(1L) - .nameUk("УБС") - .nameEn("UBS") - .build(); + .courierId(1L) + .nameUk("УБС") + .nameEn("UBS") + .build(); Courier courierToSave = Courier.builder() - .id(courier.getId()) - .courierStatus(courier.getCourierStatus()) - .nameUk("УБС") - .nameEn("UBS") - .build(); + .id(courier.getId()) + .courierStatus(courier.getCourierStatus()) + .nameUk("УБС") + .nameEn("UBS") + .build(); CourierDto courierDto = CourierDto.builder() - .courierId(courier.getId()) - .courierStatus("Active") - .nameUk("УБС") - .nameEn("UBS") - .build(); + .courierId(courier.getId()) + .courierStatus("Active") + .nameUk("УБС") + .nameEn("UBS") + .build(); when(courierRepository.findById(dto.getCourierId())).thenReturn(Optional.of(courier)); when(courierRepository.save(courier)).thenReturn(courierToSave); @@ -806,11 +806,11 @@ void updateCourierTest() { CourierDto actual = superAdminService.updateCourier(dto); CourierDto expected = CourierDto.builder() - .courierId(getCourier().getId()) - .courierStatus("Active") - .nameUk("УБС") - .nameEn("UBS") - .build(); + .courierId(getCourier().getId()) + .courierStatus("Active") + .nameUk("УБС") + .nameEn("UBS") + .build(); assertEquals(expected, actual); } @@ -820,20 +820,20 @@ void updateCourierNotFound() { Courier courier = getCourier(); CourierUpdateDto dto = CourierUpdateDto.builder() - .courierId(1L) - .nameUk("УБС") - .nameEn("UBS") - .build(); + .courierId(1L) + .nameUk("УБС") + .nameEn("UBS") + .build(); when(courierRepository.findById(courier.getId())) - .thenThrow(new NotFoundException(ErrorMessage.COURIER_IS_NOT_FOUND_BY_ID)); + .thenThrow(new NotFoundException(ErrorMessage.COURIER_IS_NOT_FOUND_BY_ID)); assertThrows(NotFoundException.class, () -> superAdminService.updateCourier(dto)); } @Test void getAllTariffsInfoTest() { when(tariffsInfoRepository.findAll(any(TariffsInfoSpecification.class))) - .thenReturn(List.of(ModelUtils.getTariffsInfo())); + .thenReturn(List.of(ModelUtils.getTariffsInfo())); when(modelMapper.map(any(TariffsInfo.class), eq(GetTariffsInfoDto.class))).thenReturn(getAllTariffsInfoDto()); superAdminService.getAllTariffsInfo(TariffsInfoFilterCriteria.builder().build()); @@ -847,7 +847,7 @@ void CreateReceivingStation() { AddingReceivingStationDto stationDto = AddingReceivingStationDto.builder().name("Петрівка").build(); when(receivingStationRepository.existsReceivingStationByName(any())).thenReturn(false, true); lenient().when(modelMapper.map(any(ReceivingStation.class), eq(ReceivingStationDto.class))) - .thenReturn(getReceivingStationDto()); + .thenReturn(getReceivingStationDto()); when(receivingStationRepository.save(any())).thenReturn(getReceivingStation(), getReceivingStation()); when(employeeRepository.findByUuid(test)).thenReturn(Optional.ofNullable(getEmployee())); superAdminService.createReceivingStation(stationDto, test); @@ -855,12 +855,12 @@ void CreateReceivingStation() { verify(receivingStationRepository, times(1)).existsReceivingStationByName(any()); verify(receivingStationRepository, times(1)).save(any()); verify(modelMapper, times(1)) - .map(any(ReceivingStation.class), eq(ReceivingStationDto.class)); + .map(any(ReceivingStation.class), eq(ReceivingStationDto.class)); Exception thrown = assertThrows(UnprocessableEntityException.class, - () -> superAdminService.createReceivingStation(stationDto, test)); + () -> superAdminService.createReceivingStation(stationDto, test)); assertEquals(thrown.getMessage(), ErrorMessage.RECEIVING_STATION_ALREADY_EXISTS - + stationDto.getName()); + + stationDto.getName()); verify(employeeRepository).findByUuid(any()); } @@ -869,13 +869,13 @@ void createReceivingStationSaveCorrectValue() { String receivingStationName = "Петрівка"; Employee employee = getEmployee(); AddingReceivingStationDto addingReceivingStationDto = - AddingReceivingStationDto.builder().name(receivingStationName).build(); + AddingReceivingStationDto.builder().name(receivingStationName).build(); ReceivingStation activatedReceivingStation = ReceivingStation.builder() - .name(receivingStationName) - .createdBy(employee) - .createDate(LocalDate.now()) - .stationStatus(StationStatus.ACTIVE) - .build(); + .name(receivingStationName) + .createdBy(employee) + .createDate(LocalDate.now()) + .stationStatus(StationStatus.ACTIVE) + .build(); ReceivingStationDto receivingStationDto = getReceivingStationDto(); @@ -883,7 +883,7 @@ void createReceivingStationSaveCorrectValue() { when(receivingStationRepository.existsReceivingStationByName(any())).thenReturn(false); when(receivingStationRepository.save(any())).thenReturn(activatedReceivingStation); when(modelMapper.map(any(), eq(ReceivingStationDto.class))) - .thenReturn(receivingStationDto); + .thenReturn(receivingStationDto); superAdminService.createReceivingStation(addingReceivingStationDto, employee.getUuid()); @@ -891,7 +891,7 @@ void createReceivingStationSaveCorrectValue() { verify(receivingStationRepository).existsReceivingStationByName(any()); verify(receivingStationRepository).save(activatedReceivingStation); verify(modelMapper) - .map(any(ReceivingStation.class), eq(ReceivingStationDto.class)); + .map(any(ReceivingStation.class), eq(ReceivingStationDto.class)); } @@ -943,7 +943,7 @@ void deleteReceivingStation() { when(receivingStationRepository.findById(2L)).thenReturn(Optional.empty()); Exception thrown1 = assertThrows(NotFoundException.class, - () -> superAdminService.deleteReceivingStation(2L)); + () -> superAdminService.deleteReceivingStation(2L)); assertEquals(ErrorMessage.RECEIVING_STATION_NOT_FOUND_BY_ID + 2L, thrown1.getMessage()); } @@ -952,12 +952,12 @@ void deleteReceivingStation() { void editNewTariffSuccess() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); when(locationRepository.findAllByIdAndRegionId(dto.getLocationIdList(), dto.getRegionId())) - .thenReturn(ModelUtils.getLocationList()); + .thenReturn(ModelUtils.getLocationList()); when(employeeRepository.findByUuid(any())).thenReturn(Optional.ofNullable(getEmployee())); when(receivingStationRepository.findAllById(List.of(1L))).thenReturn(ModelUtils.getReceivingList()); when(courierRepository.findById(anyLong())).thenReturn(Optional.of(ModelUtils.getCourier())); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(Collections.emptyList()); + .thenReturn(Collections.emptyList()); when(tariffsInfoRepository.save(any())).thenReturn(ModelUtils.getTariffInfo()); when(employeeRepository.findAllByEmployeePositionId(6L)).thenReturn(ModelUtils.getEmployeeList()); when(tariffsLocationRepository.saveAll(anySet())).thenReturn(anyList()); @@ -977,13 +977,13 @@ void addNewTariffThrowsExceptionWhenListOfLocationsIsEmptyTest() { when(employeeRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(Optional.ofNullable(getEmployee())); when(tariffsInfoRepository.save(any())).thenReturn(ModelUtils.getTariffInfo()); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(Collections.emptyList()); + .thenReturn(Collections.emptyList()); when(receivingStationRepository.findAllById(List.of(1L))).thenReturn(ModelUtils.getReceivingList()); when(locationRepository.findAllByIdAndRegionId(dto.getLocationIdList(), - dto.getRegionId())).thenReturn(Collections.emptyList()); + dto.getRegionId())).thenReturn(Collections.emptyList()); assertThrows(NotFoundException.class, - () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); + () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); verify(courierRepository).findById(1L); verify(employeeRepository).findByUuid("35467585763t4sfgchjfuyetf"); @@ -998,20 +998,20 @@ void addNewTariffThrowsExceptionWhenListOfLocationsIsEmptyTest() { void addNewTariffThrowsExceptionWhenSuchTariffIsAlreadyExistsTest() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); TariffLocation tariffLocation = TariffLocation - .builder() - .id(1L) - .location(ModelUtils.getLocation()) - .build(); + .builder() + .id(1L) + .location(ModelUtils.getLocation()) + .build(); when(courierRepository.findById(1L)).thenReturn(Optional.of(ModelUtils.getCourier())); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(dto.getCourierId(), - dto.getLocationIdList())).thenReturn(List.of(tariffLocation)); + dto.getLocationIdList())).thenReturn(List.of(tariffLocation)); assertThrows(TariffAlreadyExistsException.class, - () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); + () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); verify(courierRepository).findById(1L); verify(tariffsLocationRepository).findAllByCourierIdAndLocationIds(dto.getCourierId(), - dto.getLocationIdList()); + dto.getLocationIdList()); verifyNoMoreInteractions(courierRepository, tariffsLocationRepository); verify(employeeRepository, never()).findAllByEmployeePositionId(6L); } @@ -1027,12 +1027,12 @@ void addNewTariffThrowsExceptionWhenCourierHasStatusDeactivated() { // Perform the test assertThrows(BadRequestException.class, - () -> superAdminService.addNewTariff(addNewTariffDto, userUUID)); + () -> superAdminService.addNewTariff(addNewTariffDto, userUUID)); // Verify the interactions verify(courierRepository).findById(addNewTariffDto.getCourierId()); verifyNoMoreInteractions(courierRepository, tariffsLocationRepository, tariffsInfoRepository, - employeeRepository); + employeeRepository); } @Test @@ -1044,12 +1044,12 @@ void addNewTariffThrowsExceptionWhenListOfReceivingStationIsEmpty() { when(employeeRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(Optional.ofNullable(getEmployee())); when(tariffsInfoRepository.save(any())).thenReturn(ModelUtils.getTariffInfo()); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(Collections.emptyList()); + .thenReturn(Collections.emptyList()); when(locationRepository.findAllByIdAndRegionId(dto.getLocationIdList(), - dto.getRegionId())).thenReturn(Collections.emptyList()); + dto.getRegionId())).thenReturn(Collections.emptyList()); assertThrows(NotFoundException.class, - () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); + () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); verify(courierRepository).findById(1L); verify(employeeRepository).findByUuid("35467585763t4sfgchjfuyetf"); @@ -1064,7 +1064,7 @@ void addNewTariffThrowsException2() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); when(courierRepository.findById(anyLong())).thenReturn(Optional.of(ModelUtils.getCourier())); assertThrows(NotFoundException.class, - () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); + () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); verify(courierRepository).findById(anyLong()); verify(receivingStationRepository).findAllById(any()); verify(tariffsLocationRepository).findAllByCourierIdAndLocationIds(anyLong(), anyList()); @@ -1076,7 +1076,7 @@ void addNewTariffThrowsException3() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); when(courierRepository.findById(anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); + () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); verify(employeeRepository, never()).findAllByEmployeePositionId(6L); } @@ -1093,10 +1093,10 @@ void editTariffTest() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); when(tariffsLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) - .thenReturn(Optional.of(tariffLocation)); + .thenReturn(Optional.of(tariffLocation)); when(tariffsLocationRepository.findAllByTariffsInfo(tariffsInfo)).thenReturn(List.of(tariffLocation)); when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfo); @@ -1126,10 +1126,10 @@ void editTariffWithDeleteTariffLocation() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); when(tariffsLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) - .thenReturn(Optional.of(tariffLocation)); + .thenReturn(Optional.of(tariffLocation)); when(tariffsLocationRepository.findAllByTariffsInfo(tariffsInfo)).thenReturn(tariffLocations); doNothing().when(tariffsLocationRepository).delete(tariffLocations.get(1)); when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfo); @@ -1153,7 +1153,7 @@ void editTariffThrowTariffNotFoundException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1166,7 +1166,7 @@ void editTariffThrowLocationNotFoundException() { when(locationRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(locationRepository).findById(1L); @@ -1183,7 +1183,7 @@ void editTariffThrowLocationBadRequestException() { when(locationRepository.findById(2L)).thenReturn(Optional.of(locations.get(1))); assertThrows(BadRequestException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(locationRepository).findById(1L); @@ -1202,10 +1202,10 @@ void editTariffThrowTariffAlreadyExistsException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); assertThrows(TariffAlreadyExistsException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(locationRepository).findById(1L); @@ -1225,11 +1225,11 @@ void editTariffThrowReceivingStationNotFoundException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); when(receivingStationRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(locationRepository).findById(1L); @@ -1249,7 +1249,7 @@ void editTariffThrowsCourierNotFoundException() { when(courierRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(courierRepository).findById(1L); @@ -1267,11 +1267,11 @@ void editTariffWithoutCourier() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); when(receivingStationRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(locationRepository).findById(1L); @@ -1291,7 +1291,7 @@ void editTariffThrowsCourierHasStatusDeactivatedException() { when(courierRepository.findById(1L)).thenReturn(Optional.of(courier)); assertThrows(BadRequestException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(courierRepository).findById(1L); @@ -1311,10 +1311,10 @@ void editTariffWithBuildTariffLocation() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); when(tariffsLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); when(tariffsLocationRepository.findAllByTariffsInfo(tariffsInfo)).thenReturn(List.of(tariffLocation)); when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfo); @@ -1334,7 +1334,7 @@ void editTariffWithBuildTariffLocation() { void checkIfTariffDoesNotExistsTest() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(anyLong(), any())) - .thenReturn(Collections.emptyList()); + .thenReturn(Collections.emptyList()); boolean actual = superAdminService.checkIfTariffExists(dto); assertFalse(actual); verify(tariffsLocationRepository).findAllByCourierIdAndLocationIds(anyLong(), any()); @@ -1344,14 +1344,14 @@ void checkIfTariffDoesNotExistsTest() { void checkIfTariffExistsTest() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); TariffLocation tariffLocation = TariffLocation - .builder() - .id(1L) - .tariffsInfo(ModelUtils.getTariffsInfo()) - .location(ModelUtils.getLocation()) - .locationStatus(LocationStatus.ACTIVE) - .build(); + .builder() + .id(1L) + .tariffsInfo(ModelUtils.getTariffsInfo()) + .location(ModelUtils.getLocation()) + .locationStatus(LocationStatus.ACTIVE) + .build(); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(anyLong(), any())) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); boolean actual = superAdminService.checkIfTariffExists(dto); assertTrue(actual); verify(tariffsLocationRepository).findAllByCourierIdAndLocationIds(anyLong(), any()); @@ -1425,7 +1425,7 @@ void setTariffLimitsIfBagNotBelongToTariff() { when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(2L, dto)); + () -> superAdminService.setTariffLimits(2L, dto)); verify(tariffsInfoRepository).findById(2L); verify(bagRepository).findById(1); @@ -1480,7 +1480,7 @@ void setTariffLimitsWithNullCourierLimitAndTrueBagLimitIncluded() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1495,7 +1495,7 @@ void setTariffLimitsWithNullAllParamsAndTrueBagLimitIncluded() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1510,7 +1510,7 @@ void setTariffLimitsWithNotNullAllParamsAndFalseBagLimitIncluded() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1523,7 +1523,7 @@ void setTariffsLimitWithSameMinAndMaxValue() { when(tariffsInfoRepository.findById(anyLong())).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1536,7 +1536,7 @@ void setTariffLimitsWithPriceOfOrderMaxValueIsGreaterThanMin() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1549,7 +1549,7 @@ void setTariffLimitsWithAmountOfBigBagMaxValueIsGreaterThanMin() { when(tariffsInfoRepository.findById(anyLong())).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1561,7 +1561,7 @@ void setTariffLimitsBagThrowTariffsInfoNotFound() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1575,7 +1575,7 @@ void setTariffLimitsBagThrowBagNotFound() { when(bagRepository.findById(1)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(bagRepository).findById(1); @@ -1600,7 +1600,7 @@ void getTariffLimitsThrowNotFoundException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.getTariffLimits(1L)); + () -> superAdminService.getTariffLimits(1L)); verify(tariffsInfoRepository).findById(1L); } @@ -1653,10 +1653,10 @@ void switchTariffStatusFromWhenCourierDeactivatedThrowBadRequestException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); Throwable t = assertThrows(BadRequestException.class, - () -> superAdminService.switchTariffStatus(1L, "Active")); + () -> superAdminService.switchTariffStatus(1L, "Active")); assertEquals(String.format(ErrorMessage.TARIFF_ACTIVATION_RESTRICTION_DUE_TO_DEACTIVATED_COURIER + - tariffInfo.getCourier().getId()), - t.getMessage()); + tariffInfo.getCourier().getId()), + t.getMessage()); verify(tariffsInfoRepository).findById(1L); verify(tariffsInfoRepository, never()).save(tariffInfo); @@ -1681,7 +1681,7 @@ void switchTariffStatusThrowNotFoundException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.switchTariffStatus(1L, "Active")); + () -> superAdminService.switchTariffStatus(1L, "Active")); verify(tariffsInfoRepository).findById(1L); verify(tariffsInfoRepository, never()).save(any(TariffsInfo.class)); @@ -1694,9 +1694,9 @@ void switchTariffStatusFromActiveToActiveThrowBadRequestException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); Throwable t = assertThrows(BadRequestException.class, - () -> superAdminService.switchTariffStatus(1L, "Active")); + () -> superAdminService.switchTariffStatus(1L, "Active")); assertEquals(String.format(ErrorMessage.TARIFF_ALREADY_HAS_THIS_STATUS, 1L, TariffStatus.ACTIVE), - t.getMessage()); + t.getMessage()); verify(tariffsInfoRepository).findById(1L); verify(tariffsInfoRepository, never()).save(tariffInfo); @@ -1710,9 +1710,9 @@ void switchTariffStatusToActiveWithoutBagThrowBadRequestException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); Throwable t = assertThrows(BadRequestException.class, - () -> superAdminService.switchTariffStatus(1L, "Active")); + () -> superAdminService.switchTariffStatus(1L, "Active")); assertEquals(ErrorMessage.TARIFF_ACTIVATION_RESTRICTION_DUE_TO_UNSPECIFIED_BAGS, - t.getMessage()); + t.getMessage()); verify(tariffsInfoRepository).findById(1L); verify(tariffsInfoRepository, never()).save(tariffInfo); @@ -1726,7 +1726,7 @@ void switchTariffStatusWithUnresolvableStatusThrowBadRequestException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); Throwable t = assertThrows(BadRequestException.class, - () -> superAdminService.switchTariffStatus(1L, "new")); + () -> superAdminService.switchTariffStatus(1L, "new")); assertEquals(ErrorMessage.UNRESOLVABLE_TARIFF_STATUS, t.getMessage()); verify(tariffsInfoRepository).findById(1L); @@ -1742,9 +1742,9 @@ void switchTariffStatusToActiveWithMinAndMaxNullThrowBadRequestException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); Throwable t = assertThrows(BadRequestException.class, - () -> superAdminService.switchTariffStatus(1L, "Active")); + () -> superAdminService.switchTariffStatus(1L, "Active")); assertEquals(ErrorMessage.TARIFF_ACTIVATION_RESTRICTION_DUE_TO_UNSPECIFIED_LIMITS, - t.getMessage()); + t.getMessage()); verify(tariffsInfoRepository).findById(1L); verify(tariffsInfoRepository, never()).save(tariffInfo); @@ -1806,7 +1806,7 @@ void changeTariffLocationsStatusParamUnresolvable() { when(tariffsInfoRepository.findById(anyLong())).thenReturn(Optional.of(tariffsInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.changeTariffLocationsStatus(1L, dto, "unresolvable")); + () -> superAdminService.changeTariffLocationsStatus(1L, dto, "unresolvable")); } @Test @@ -1814,7 +1814,7 @@ void switchActivationStatusByChosenParamsBadRequestExceptionUnresolvableStatus() DetailsOfDeactivateTariffsDto details = ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegion(); details.setActivationStatus("Test"); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test @@ -1833,7 +1833,7 @@ void switchActivationStatusByAllValidParams() { when(receivingStationRepository.findById(anyLong())).thenReturn(Optional.of(receivingStation)); when(receivingStationRepository.saveAll(List.of(receivingStation))).thenReturn(List.of(receivingStation)); doNothing().when(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); superAdminService.switchActivationStatusByChosenParams(details); @@ -1841,7 +1841,7 @@ void switchActivationStatusByAllValidParams() { verify(locationRepository).findLocationByIdAndRegionId(1L, 1L); verify(locationRepository).saveAll(List.of(location)); verify(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); verify(courierRepository).findById(1L); verify(courierRepository).save(courier); verify(receivingStationRepository).findById(anyLong()); @@ -1870,13 +1870,13 @@ void switchLocationStatusToActiveByOneRegion() { when(locationRepository.findLocationsByRegionId(1L)).thenReturn(List.of(locationDeactivated)); when(locationRepository.saveAll(List.of(locationActive))).thenReturn(List.of(locationActive)); doNothing().when(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); superAdminService.switchActivationStatusByChosenParams(details); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(List.of(1L)); verify(locationRepository).findLocationsByRegionId(1L); verify(locationRepository).saveAll(List.of(locationActive)); verify(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); } @Test @@ -1903,13 +1903,13 @@ void switchLocationStatusToActiveByTwoRegions() { when(locationRepository.findLocationsByRegionId(2L)).thenReturn(List.of(locationDeactivated)); when(locationRepository.saveAll(List.of(locationActive))).thenReturn(List.of(locationActive)); doNothing().when(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); superAdminService.switchActivationStatusByChosenParams(details); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(anyList()); verify(locationRepository, times(2)).findLocationsByRegionId(anyLong()); verify(locationRepository, times(2)).saveAll(List.of(locationActive)); verify(tariffsLocationRepository, times(2)) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); } @Test @@ -1931,7 +1931,7 @@ void deactivateTariffByNotExistingRegionThrows() { when(deactivateTariffsForChosenParamRepository.isRegionsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(List.of(1L)); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByRegions(anyList()); } @@ -1943,7 +1943,7 @@ void switchLocationStatusToActiveByNotExistingRegionThrows() { when(deactivateTariffsForChosenParamRepository.isRegionsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(List.of(1L)); } @@ -1972,19 +1972,19 @@ void switchLocationStatusToActiveByRegionAndCities() { when(deactivateTariffsForChosenParamRepository.isRegionsExists(anyList())).thenReturn(true); when(locationRepository.findLocationByIdAndRegionId(1L, 1L)) - .thenReturn(Optional.of(locationDeactivated1)); + .thenReturn(Optional.of(locationDeactivated1)); when(locationRepository.findLocationByIdAndRegionId(11L, 1L)) - .thenReturn(Optional.of(locationDeactivated2)); + .thenReturn(Optional.of(locationDeactivated2)); when(locationRepository.saveAll(List.of(locationActive1, locationActive2))) - .thenReturn(List.of(locationActive1, locationActive2)); + .thenReturn(List.of(locationActive1, locationActive2)); doNothing().when(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L, 11L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L, 11L), LocationStatus.ACTIVE.name()); superAdminService.switchActivationStatusByChosenParams(details); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(anyList()); verify(locationRepository, times(2)).findLocationByIdAndRegionId(anyLong(), anyLong()); verify(locationRepository).saveAll(List.of(locationActive1, locationActive2)); verify(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L, 11L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L, 11L), LocationStatus.ACTIVE.name()); } @Test @@ -1994,11 +1994,11 @@ void deactivateTariffByOneRegionAndNotExistingCitiesThrows() { when(regionRepository.existsRegionById(anyLong())).thenReturn(true); when(deactivateTariffsForChosenParamRepository.isCitiesExistForRegion(anyList(), anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(regionRepository).existsRegionById(1L); verify(deactivateTariffsForChosenParamRepository).isCitiesExistForRegion(List.of(1L, 11L), 1L); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByRegionsAndCities(anyList(), - anyLong()); + anyLong()); } @Test @@ -2009,7 +2009,7 @@ void switchLocationStatusToActiveByRegionAndNotExistingCitiesThrows() { when(deactivateTariffsForChosenParamRepository.isRegionsExists(anyList())).thenReturn(true); when(locationRepository.findLocationByIdAndRegionId(anyLong(), anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(anyList()); verify(locationRepository).findLocationByIdAndRegionId(anyLong(), anyLong()); } @@ -2021,7 +2021,7 @@ void switchLocationStatusToActiveByCitiesAndNotExistingRegionBadRequestException details.setActivationStatus("Active"); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test @@ -2031,7 +2031,7 @@ void switchLocationStatusToActiveByCitiesAndTwoRegionsBadRequestException() { details.setActivationStatus("Active"); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test @@ -2040,10 +2040,10 @@ void deactivateTariffByOneNotExistingRegionAndCitiesThrows() { when(regionRepository.existsRegionById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(regionRepository).existsRegionById(1L); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByRegionsAndCities(anyList(), - anyLong()); + anyLong()); } @Test @@ -2053,7 +2053,7 @@ void switchLocationStatusToActiveExistingRegionAndCitiesThrows() { when(deactivateTariffsForChosenParamRepository.isRegionsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(anyList()); } @@ -2086,7 +2086,7 @@ void deactivateTariffByNotExistingCourierThrows() { when(courierRepository.existsCourierById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(courierRepository).existsCourierById(1L); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByCourier(anyLong()); } @@ -2098,7 +2098,7 @@ void switchCourierStatusToActiveNotExistingCourierThrows() { when(courierRepository.findById(anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(courierRepository).findById(anyLong()); } @@ -2123,7 +2123,7 @@ void switchReceivingStationsStatusToActive() { when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation1)); when(receivingStationRepository.findById(12L)).thenReturn(Optional.of(receivingStation2)); when(receivingStationRepository.saveAll(List.of(receivingStation1, receivingStation2))) - .thenReturn(List.of(receivingStation1, receivingStation2)); + .thenReturn(List.of(receivingStation1, receivingStation2)); superAdminService.switchActivationStatusByChosenParams(details); verify(receivingStationRepository, times(2)).findById(anyLong()); verify(receivingStationRepository).saveAll(anyList()); @@ -2135,7 +2135,7 @@ void deactivateTariffByNotExistingReceivingStationsThrows() { when(deactivateTariffsForChosenParamRepository.isReceivingStationsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByReceivingStations(anyList()); } @@ -2147,14 +2147,14 @@ void switchReceivingStationsStatusToActiveNotExistingReceivingStationsThrows() { when(receivingStationRepository.findById(anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(receivingStationRepository).findById(anyLong()); } @Test void deactivateTariffByCourierAndReceivingStations() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); when(courierRepository.existsCourierById(anyLong())).thenReturn(true); when(deactivateTariffsForChosenParamRepository.isReceivingStationsExists(anyList())).thenReturn(true); @@ -2162,35 +2162,35 @@ void deactivateTariffByCourierAndReceivingStations() { verify(courierRepository).existsCourierById(1L); verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); verify(deactivateTariffsForChosenParamRepository) - .deactivateTariffsByCourierAndReceivingStations(1L, List.of(1L, 12L)); + .deactivateTariffsByCourierAndReceivingStations(1L, List.of(1L, 12L)); } @Test void deactivateTariffByNotExistingCourierAndReceivingStationsTrows() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); when(courierRepository.existsCourierById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(courierRepository).existsCourierById(1L); verify(deactivateTariffsForChosenParamRepository, never()) - .deactivateTariffsByCourierAndReceivingStations(anyLong(), anyList()); + .deactivateTariffsByCourierAndReceivingStations(anyLong(), anyList()); } @Test void deactivateTariffByCourierAndNotExistingReceivingStationsTrows() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); when(courierRepository.existsCourierById(anyLong())).thenReturn(true); when(deactivateTariffsForChosenParamRepository.isReceivingStationsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(courierRepository).existsCourierById(1L); verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); verify(deactivateTariffsForChosenParamRepository, never()) - .deactivateTariffsByCourierAndReceivingStations(anyLong(), anyList()); + .deactivateTariffsByCourierAndReceivingStations(anyLong(), anyList()); } @Test @@ -2212,11 +2212,11 @@ void deactivateTariffByNotExistingCourierAndOneRegionThrows() { when(regionRepository.existsRegionById(anyLong())).thenReturn(true); when(courierRepository.existsCourierById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(regionRepository).existsRegionById(1L); verify(courierRepository).existsCourierById(1L); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByCourierAndRegion(anyLong(), - anyLong()); + anyLong()); } @Test @@ -2225,16 +2225,16 @@ void deactivateTariffByCourierAndNotExistingRegionThrows() { when(regionRepository.existsRegionById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(regionRepository).existsRegionById(1L); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByCourierAndRegion(anyLong(), - anyLong()); + anyLong()); } @Test void deactivateTariffByOneRegionAndCityAndStation() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation(); doMockForTariffWithRegionAndCityAndStation(true, true, true); superAdminService.switchActivationStatusByChosenParams(details); @@ -2244,29 +2244,29 @@ void deactivateTariffByOneRegionAndCityAndStation() { @ParameterizedTest @MethodSource("deactivateTariffByNotExistingSomeOfTreeParameters") void deactivateTariffByNotExistingRegionAndCityAndStationThrows( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists) { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation(); doMockForTariffWithRegionAndCityAndStation(isRegionExists, isCitiesExistForRegion, isReceivingStationsExists); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verifyForTariffWithRegionAndCityAndStation(isRegionExists, isCitiesExistForRegion, isReceivingStationsExists); verify(deactivateTariffsForChosenParamRepository, never()) - .deactivateTariffsByRegionAndCitiesAndStations(anyLong(), anyList(), anyList()); + .deactivateTariffsByRegionAndCitiesAndStations(anyLong(), anyList(), anyList()); } static Stream deactivateTariffByNotExistingSomeOfTreeParameters() { return Stream.of( - arguments(false, true, true), - arguments(false, false, true), - arguments(false, true, false), - arguments(true, false, true), - arguments(true, false, false), - arguments(true, true, false), - arguments(false, false, false)); + arguments(false, true, true), + arguments(false, false, true), + arguments(false, true, false), + arguments(true, false, true), + arguments(true, false, false), + arguments(true, true, false), + arguments(false, false, false)); } @Test @@ -2281,39 +2281,39 @@ void deactivateTariffByAllValidParams() { @ParameterizedTest @MethodSource("deactivateTariffByAllWithNotExistingParamProvider") void deactivateTariffByAllWithNotExistingParamThrows( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists, + boolean isCourierExists) { DetailsOfDeactivateTariffsDto details = ModelUtils.getDetailsOfDeactivateTariffsDtoWithAllParams(); doMockForTariffWithAllParams(isRegionExists, isCitiesExistForRegion, isReceivingStationsExists, - isCourierExists); + isCourierExists); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verifyForTariffWithAllParams(isRegionExists, isCitiesExistForRegion, isReceivingStationsExists, - isCourierExists); + isCourierExists); verify(deactivateTariffsForChosenParamRepository, never()) - .deactivateTariffsByAllParam(anyLong(), anyList(), anyList(), anyLong()); + .deactivateTariffsByAllParam(anyLong(), anyList(), anyList(), anyLong()); } private static Stream deactivateTariffByAllWithNotExistingParamProvider() { return Stream.of( - arguments(false, true, true, true), - arguments(true, false, true, true), - arguments(true, true, false, true), - arguments(true, true, true, false), - arguments(false, false, true, true), - arguments(false, true, false, true), - arguments(false, true, true, false), - arguments(false, true, false, false), - arguments(true, false, false, true), - arguments(true, false, true, false), - arguments(true, true, false, false), - arguments(false, false, false, true), - arguments(false, false, true, false), - arguments(true, false, false, false), - arguments(false, false, false, false)); + arguments(false, true, true, true), + arguments(true, false, true, true), + arguments(true, true, false, true), + arguments(true, true, true, false), + arguments(false, false, true, true), + arguments(false, true, false, true), + arguments(false, true, true, false), + arguments(false, true, false, false), + arguments(true, false, false, true), + arguments(true, false, true, false), + arguments(true, true, false, false), + arguments(false, false, false, true), + arguments(false, false, true, false), + arguments(true, false, false, false), + arguments(false, false, false, false)); } @Test @@ -2321,7 +2321,7 @@ void deactivateTariffByAllEmptyParams() { DetailsOfDeactivateTariffsDto details = ModelUtils.getDetailsOfDeactivateTariffsDtoWithEmptyParams(); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test @@ -2329,7 +2329,7 @@ void deactivateTariffByCities() { DetailsOfDeactivateTariffsDto details = ModelUtils.getDetailsOfDeactivateTariffsDtoWithCities(); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test @@ -2337,71 +2337,71 @@ void deactivateTariffByCitiesAndCourier() { DetailsOfDeactivateTariffsDto details = ModelUtils.getDetailsOfDeactivateTariffsDtoWithCitiesAndCourier(); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test void deactivateTariffByCitiesAndReceivingStations() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCitiesAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCitiesAndReceivingStations(); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test void deactivateTariffByCitiesAndCourierAndReceivingStations() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCitiesAndCourierAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCitiesAndCourierAndReceivingStations(); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @ParameterizedTest @MethodSource("deactivateTariffByDifferentParamWithTwoRegionsProvider") void deactivateTariffByDifferentParamWithTwoRegionsThrows(DetailsOfDeactivateTariffsDto details) { assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } private static Stream deactivateTariffByDifferentParamWithTwoRegionsProvider() { return Stream.of( - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegion() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCities() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithAllParams() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations() - .setRegionsIds(Optional.of(List.of(1L, 2L))))); + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegion() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCities() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithAllParams() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations() + .setRegionsIds(Optional.of(List.of(1L, 2L))))); } private void doMockForTariffWithRegionAndCityAndStation( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists) { when(regionRepository.existsRegionById(anyLong())).thenReturn(isRegionExists); if (isRegionExists) { when(deactivateTariffsForChosenParamRepository - .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistForRegion); + .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistForRegion); if (isCitiesExistForRegion) { when(deactivateTariffsForChosenParamRepository - .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); + .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); } } } private void verifyForTariffWithRegionAndCityAndStation( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists) { verify(regionRepository).existsRegionById(1L); if (isRegionExists) { verify(deactivateTariffsForChosenParamRepository).isCitiesExistForRegion(List.of(1L, 11L), 1L); @@ -2409,24 +2409,24 @@ private void verifyForTariffWithRegionAndCityAndStation( verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); if (isReceivingStationsExists) { verify(deactivateTariffsForChosenParamRepository) - .deactivateTariffsByRegionAndCitiesAndStations(1L, List.of(1L, 11L), List.of(1L, 12L)); + .deactivateTariffsByRegionAndCitiesAndStations(1L, List.of(1L, 11L), List.of(1L, 12L)); } } } } private void doMockForTariffWithAllParams( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists, + boolean isCourierExists) { when(regionRepository.existsRegionById(anyLong())).thenReturn(isRegionExists); if (isRegionExists) { when(deactivateTariffsForChosenParamRepository - .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistForRegion); + .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistForRegion); if (isCitiesExistForRegion) { when(deactivateTariffsForChosenParamRepository - .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); + .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); if (isReceivingStationsExists) { when(courierRepository.existsCourierById(anyLong())).thenReturn(isCourierExists); } @@ -2435,10 +2435,10 @@ private void doMockForTariffWithAllParams( } private void verifyForTariffWithAllParams( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists, + boolean isCourierExists) { verify(regionRepository).existsRegionById(1L); if (isRegionExists) { verify(deactivateTariffsForChosenParamRepository).isCitiesExistForRegion(List.of(1L, 11L), 1L); @@ -2448,7 +2448,7 @@ private void verifyForTariffWithAllParams( verify(courierRepository).existsCourierById(1L); if (isCourierExists) { verify(deactivateTariffsForChosenParamRepository) - .deactivateTariffsByAllParam(1L, List.of(1L, 11L), List.of(1L, 12L), 1L); + .deactivateTariffsByAllParam(1L, List.of(1L, 11L), List.of(1L, 12L), 1L); } } } @@ -2458,7 +2458,7 @@ private void verifyForTariffWithAllParams( @Test void deactivateTariffByRegionsAndReceivingStations() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); doMockForTariffWithRegionAndStation(true, true); superAdminService.switchActivationStatusByChosenParams(details); @@ -2466,24 +2466,24 @@ void deactivateTariffByRegionsAndReceivingStations() { } private void doMockForTariffWithRegionAndStation( - boolean isRegionExists, - boolean isReceivingStationsExists) { + boolean isRegionExists, + boolean isReceivingStationsExists) { when(regionRepository.existsRegionById(anyLong())).thenReturn(isRegionExists); if (isRegionExists) { when(deactivateTariffsForChosenParamRepository - .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); + .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); } } private void verifyForTariffWithRegionAndStation( - boolean isRegionExists, - boolean isReceivingStationsExists) { + boolean isRegionExists, + boolean isReceivingStationsExists) { verify(regionRepository).existsRegionById(1L); if (isRegionExists) { verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); if (isReceivingStationsExists) { verify(tariffsInfoRepository) - .deactivateTariffsByRegionAndReceivingStations(1L, List.of(1L, 12L)); + .deactivateTariffsByRegionAndReceivingStations(1L, List.of(1L, 12L)); } } } @@ -2491,37 +2491,37 @@ private void verifyForTariffWithRegionAndStation( @Test void deactivateTariffByNotExistingRegionsAndReceivingStationsTrows() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); when(regionRepository.existsRegionById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(regionRepository).existsRegionById(1L); verify(tariffsInfoRepository, never()).deactivateTariffsByRegionAndReceivingStations( - anyLong(), - anyList()); + anyLong(), + anyList()); } @Test void deactivateTariffByRegionsAndNotExistingReceivingStationsTrows() { DetailsOfDeactivateTariffsDto details1 = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); when(regionRepository.existsRegionById(anyLong())).thenReturn(true); when(deactivateTariffsForChosenParamRepository.isReceivingStationsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details1)); + () -> superAdminService.switchActivationStatusByChosenParams(details1)); verify(regionRepository).existsRegionById(1L); verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); verify(tariffsInfoRepository, never()).deactivateTariffsByRegionAndReceivingStations( - anyLong(), - anyList()); + anyLong(), + anyList()); } @Test void deactivateTariffByCourierAndRegionAndCities() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities(); doMockForTariffWithCourierAndRegionAndCities(true, true, true); superAdminService.switchActivationStatusByChosenParams(details); @@ -2529,13 +2529,13 @@ void deactivateTariffByCourierAndRegionAndCities() { } private void doMockForTariffWithCourierAndRegionAndCities( - boolean isRegionExists, - boolean isCitiesExistsForRegion, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistsForRegion, + boolean isCourierExists) { when(regionRepository.existsRegionById(anyLong())).thenReturn(isRegionExists); if (isRegionExists) { when(deactivateTariffsForChosenParamRepository - .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistsForRegion); + .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistsForRegion); if (isCitiesExistsForRegion) { when(courierRepository.existsCourierById(anyLong())).thenReturn(isCourierExists); } @@ -2543,9 +2543,9 @@ private void doMockForTariffWithCourierAndRegionAndCities( } private void verifyForTariffWithCourierAndRegionAndCities( - boolean isRegionExists, - boolean isCitiesExistsForRegion, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistsForRegion, + boolean isCourierExists) { verify(regionRepository).existsRegionById(1L); if (isRegionExists) { verify(deactivateTariffsForChosenParamRepository).isCitiesExistForRegion(List.of(1L, 11L), 1L); @@ -2553,7 +2553,7 @@ private void verifyForTariffWithCourierAndRegionAndCities( verify(courierRepository).existsCourierById(1L); if (isCourierExists) { verify(tariffsInfoRepository) - .deactivateTariffsByCourierAndRegionAndCities(1L, List.of(1L, 11L), 1L); + .deactivateTariffsByCourierAndRegionAndCities(1L, List.of(1L, 11L), 1L); } } } @@ -2562,26 +2562,26 @@ private void verifyForTariffWithCourierAndRegionAndCities( @ParameterizedTest @MethodSource("deactivateTariffByNotExistingSomeOfTreeParameters") void deactivateTariffByCourierAndRegionsAndCitiesWithNotExistingParamThrows( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isCourierExists) { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities(); doMockForTariffWithCourierAndRegionAndCities(isRegionExists, isCitiesExistForRegion, - isCourierExists); + isCourierExists); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verifyForTariffWithCourierAndRegionAndCities(isRegionExists, isCitiesExistForRegion, - isCourierExists); + isCourierExists); verify(tariffsInfoRepository, never()) - .deactivateTariffsByCourierAndRegionAndCities(anyLong(), anyList(), anyLong()); + .deactivateTariffsByCourierAndRegionAndCities(anyLong(), anyList(), anyLong()); } @Test void deactivateTariffByCourierAndRegionAndReceivingStation() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations(); doMockForTariffWithCourierAndRegionAndReceivingStation(true, true, true); superAdminService.switchActivationStatusByChosenParams(details); @@ -2589,13 +2589,13 @@ void deactivateTariffByCourierAndRegionAndReceivingStation() { } private void doMockForTariffWithCourierAndRegionAndReceivingStation( - boolean isRegionExists, - boolean isCourierExists, - boolean isReceivingStationExists) { + boolean isRegionExists, + boolean isCourierExists, + boolean isReceivingStationExists) { when(regionRepository.existsRegionById(anyLong())).thenReturn(isRegionExists); if (isRegionExists) { when(deactivateTariffsForChosenParamRepository - .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationExists); + .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationExists); if (isReceivingStationExists) { when(courierRepository.existsCourierById(anyLong())).thenReturn(isCourierExists); } @@ -2603,9 +2603,9 @@ private void doMockForTariffWithCourierAndRegionAndReceivingStation( } private void verifyForTariffWithCourierAndRegionAndReceivingStation( - boolean isRegionExists, - boolean isCourierExists, - boolean isReceivingStationExists) { + boolean isRegionExists, + boolean isCourierExists, + boolean isReceivingStationExists) { verify(regionRepository).existsRegionById(1L); if (isRegionExists) { verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); @@ -2613,7 +2613,7 @@ private void verifyForTariffWithCourierAndRegionAndReceivingStation( verify(courierRepository).existsCourierById(1L); if (isCourierExists) { verify(tariffsInfoRepository) - .deactivateTariffsByCourierAndRegionAndReceivingStations(1L, List.of(1L, 12L), 1L); + .deactivateTariffsByCourierAndRegionAndReceivingStations(1L, List.of(1L, 12L), 1L); } } } @@ -2622,19 +2622,19 @@ private void verifyForTariffWithCourierAndRegionAndReceivingStation( @ParameterizedTest @MethodSource("deactivateTariffByNotExistingSomeOfTreeParameters") void deactivateTariffByCourierAndRegionsAndReceivingStationWithNotExistingParamThrows( - boolean isRegionExists, - boolean isCourierExists, - boolean isReceivingStationExists) { + boolean isRegionExists, + boolean isCourierExists, + boolean isReceivingStationExists) { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations(); doMockForTariffWithCourierAndRegionAndReceivingStation(isRegionExists, isReceivingStationExists, - isCourierExists); + isCourierExists); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verifyForTariffWithCourierAndRegionAndReceivingStation(isRegionExists, isReceivingStationExists, - isCourierExists); + isCourierExists); verify(tariffsInfoRepository, never()) - .deactivateTariffsByCourierAndRegionAndCities(anyLong(), anyList(), anyLong()); + .deactivateTariffsByCourierAndRegionAndCities(anyLong(), anyList(), anyLong()); } } \ No newline at end of file diff --git a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java index 6466498f6..c36b12eed 100644 --- a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java @@ -353,7 +353,7 @@ void testValidatePayment() { when(orderRepository.findById(anyLong())).thenReturn(Optional.of(order)); ubsService.validatePayment(dto); verify(eventService, times(1)) - .save("Замовлення Оплачено", "Система", order); + .save("Замовлення Оплачено", "Система", order); verify(paymentRepository, times(1)).save(payment); } @@ -396,22 +396,22 @@ void getFirstPageDataByTariffAndLocationIdShouldReturnExpectedData() { when(tariffsInfoRepository.findById(tariffsInfoId)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(locationId)).thenReturn(Optional.of(location)); when(tariffLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) - .thenReturn(Optional.of(tariffLocation)); + .thenReturn(Optional.of(tariffLocation)); when(bagRepository.findBagsByTariffsInfoId(tariffsInfoId)).thenReturn(bags); when(modelMapper.map(bags.get(0), BagTranslationDto.class)).thenReturn(bagTranslationDto); var userPointsAndAllBagsDtoActual = - ubsService.getFirstPageDataByTariffAndLocationId(uuid, tariffsInfoId, locationId); + ubsService.getFirstPageDataByTariffAndLocationId(uuid, tariffsInfoId, locationId); assertEquals( - userPointsAndAllBagsDtoExpected.getBags(), - userPointsAndAllBagsDtoActual.getBags()); + userPointsAndAllBagsDtoExpected.getBags(), + userPointsAndAllBagsDtoActual.getBags()); assertEquals( - userPointsAndAllBagsDtoExpected.getBags().get(0).getId(), - userPointsAndAllBagsDtoActual.getBags().get(0).getId()); + userPointsAndAllBagsDtoExpected.getBags().get(0).getId(), + userPointsAndAllBagsDtoActual.getBags().get(0).getId()); assertEquals( - userPointsAndAllBagsDtoExpected.getPoints(), - userPointsAndAllBagsDtoActual.getPoints()); + userPointsAndAllBagsDtoExpected.getPoints(), + userPointsAndAllBagsDtoActual.getPoints()); verify(userRepository).findUserByUuid(uuid); verify(tariffsInfoRepository).findById(tariffsInfoId); @@ -438,10 +438,10 @@ void getFirstPageDataByTariffAndLocationIdShouldThrowExceptionWhenTariffLocation when(tariffsInfoRepository.findById(tariffsInfoId)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(locationId)).thenReturn(Optional.of(location)); when(tariffLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); var exception = assertThrows(NotFoundException.class, () -> ubsService.getFirstPageDataByTariffAndLocationId( - uuid, tariffsInfoId, locationId)); + uuid, tariffsInfoId, locationId)); assertEquals(expectedErrorMessage, exception.getMessage()); @@ -472,7 +472,7 @@ void getFirstPageDataByTariffAndLocationIdShouldThrowExceptionWhenLocationDoesNo when(locationRepository.findById(locationId)).thenReturn(Optional.empty()); var exception = assertThrows(NotFoundException.class, () -> ubsService.getFirstPageDataByTariffAndLocationId( - uuid, tariffsInfoId, locationId)); + uuid, tariffsInfoId, locationId)); assertEquals(expectedErrorMessage, exception.getMessage()); @@ -502,7 +502,7 @@ void getFirstPageDataByTariffAndLocationIdShouldThrowExceptionWhenTariffDoesNotE when(tariffsInfoRepository.findById(tariffId)).thenReturn(Optional.empty()); var exception = assertThrows(NotFoundException.class, () -> ubsService.getFirstPageDataByTariffAndLocationId( - uuid, tariffId, locationId)); + uuid, tariffId, locationId)); assertEquals(expectedErrorMessage, exception.getMessage()); @@ -529,7 +529,7 @@ void getFirstPageDataByTariffAndLocationIdShouldThrowExceptionWhenUserDoesNotExi when(userRepository.findUserByUuid(uuid)).thenReturn(Optional.empty()); var exception = assertThrows(NotFoundException.class, () -> ubsService.getFirstPageDataByTariffAndLocationId( - uuid, tariffsInfoId, locationId)); + uuid, tariffsInfoId, locationId)); assertEquals(USER_WITH_CURRENT_UUID_DOES_NOT_EXIST, exception.getMessage()); @@ -559,7 +559,7 @@ void checkIfTariffIsAvailableForCurrentLocationThrowExceptionWhenTariffIsDeactiv when(locationRepository.findById(locationId)).thenReturn(Optional.of(location)); var exception = assertThrows(BadRequestException.class, () -> ubsService.getFirstPageDataByTariffAndLocationId( - uuid, tariffsInfoId, locationId)); + uuid, tariffsInfoId, locationId)); assertEquals(TARIFF_OR_LOCATION_IS_DEACTIVATED, exception.getMessage()); @@ -589,7 +589,7 @@ void checkIfTariffIsAvailableForCurrentLocationThrowExceptionWhenLocationIsDeact when(locationRepository.findById(locationId)).thenReturn(Optional.of(location)); var exception = assertThrows(BadRequestException.class, () -> ubsService.getFirstPageDataByTariffAndLocationId( - uuid, tariffsInfoId, locationId)); + uuid, tariffsInfoId, locationId)); assertEquals(TARIFF_OR_LOCATION_IS_DEACTIVATED, exception.getMessage()); @@ -623,10 +623,10 @@ void checkIfTariffIsAvailableForCurrentLocationWhenLocationForTariffIsDeactivate when(tariffsInfoRepository.findById(tariffsInfoId)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(locationId)).thenReturn(Optional.of(location)); when(tariffLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) - .thenReturn(Optional.of(tariffLocation)); + .thenReturn(Optional.of(tariffLocation)); var exception = assertThrows(BadRequestException.class, () -> ubsService.getFirstPageDataByTariffAndLocationId( - uuid, tariffsInfoId, locationId)); + uuid, tariffsInfoId, locationId)); assertEquals(expectedErrorMessage, exception.getMessage()); @@ -650,9 +650,9 @@ void getFirstPageDataByOrderIdShouldReturnExpectedData() { var tariffsInfo = order.getTariffsInfo(); var tariffsInfoId = tariffsInfo.getId(); var location = order - .getUbsUser() - .getOrderAddress() - .getLocation(); + .getUbsUser() + .getOrderAddress() + .getLocation(); var tariffLocation = getTariffLocation(); var bags = getBag1list(); @@ -662,22 +662,22 @@ void getFirstPageDataByOrderIdShouldReturnExpectedData() { when(userRepository.findUserByUuid(uuid)).thenReturn(Optional.of(user)); when(orderRepository.findById(orderId)).thenReturn(Optional.of(order)); when(tariffLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) - .thenReturn(Optional.of(tariffLocation)); + .thenReturn(Optional.of(tariffLocation)); when(bagRepository.findBagsByTariffsInfoId(tariffsInfoId)).thenReturn(bags); when(modelMapper.map(bags.get(0), BagTranslationDto.class)).thenReturn(bagTranslationDto); var userPointsAndAllBagsDtoActual = - ubsService.getFirstPageDataByOrderId(uuid, orderId); + ubsService.getFirstPageDataByOrderId(uuid, orderId); assertEquals( - userPointsAndAllBagsDtoExpected.getBags(), - userPointsAndAllBagsDtoActual.getBags()); + userPointsAndAllBagsDtoExpected.getBags(), + userPointsAndAllBagsDtoActual.getBags()); assertEquals( - userPointsAndAllBagsDtoExpected.getBags().get(0).getId(), - userPointsAndAllBagsDtoActual.getBags().get(0).getId()); + userPointsAndAllBagsDtoExpected.getBags().get(0).getId(), + userPointsAndAllBagsDtoActual.getBags().get(0).getId()); assertEquals( - userPointsAndAllBagsDtoExpected.getPoints(), - userPointsAndAllBagsDtoActual.getPoints()); + userPointsAndAllBagsDtoExpected.getPoints(), + userPointsAndAllBagsDtoActual.getPoints()); verify(userRepository).findUserByUuid(uuid); verify(orderRepository).findById(orderId); @@ -697,7 +697,7 @@ void getFirstPageDataByOrderIdShouldThrowExceptionWhenUserDoesNotExist() { when(userRepository.findUserByUuid(uuid)).thenReturn(Optional.empty()); var exception = assertThrows(NotFoundException.class, () -> ubsService.getFirstPageDataByOrderId( - uuid, orderId)); + uuid, orderId)); assertEquals(USER_WITH_CURRENT_UUID_DOES_NOT_EXIST, exception.getMessage()); @@ -723,7 +723,7 @@ void getFirstPageDataByOrderIdShouldThrowExceptionWhenOrderDoesNotExist() { when(orderRepository.findById(orderId)).thenReturn(Optional.empty()); var exception = assertThrows(NotFoundException.class, () -> ubsService.getFirstPageDataByOrderId( - uuid, orderId)); + uuid, orderId)); assertEquals(expectedErrorMessage, exception.getMessage()); @@ -772,7 +772,7 @@ void testSaveToDB() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); @@ -828,7 +828,7 @@ void testSaveToDBWithTwoBags() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(1)).thenReturn(Optional.of(bag1)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag3)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); @@ -881,7 +881,7 @@ void testSaveToDBWithCertificates() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(certificateRepository.findById(anyString())).thenReturn(Optional.of(getCertificate())); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); @@ -937,7 +937,7 @@ void testSaveToDBWithDontSendLinkToFondy() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(certificateRepository.findById(anyString())).thenReturn(Optional.of(certificate)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); @@ -987,7 +987,7 @@ void testSaveToDBWhenSumToPayLessThanPoints() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); @@ -1018,15 +1018,15 @@ void testSaveToDbThrowBadRequestExceptionPriceLowerThanLimit() throws IllegalAcc when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(getTariffInfo())); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, - () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); + () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); verify(userRepository, times(1)).findByUuid(anyString()); verify(tariffsInfoRepository, times(1)) - .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); + .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); verify(bagRepository, times(1)).findById(anyInt()); } @@ -1046,15 +1046,15 @@ void testSaveToDbThrowBadRequestExceptionPriceGreaterThanLimit() throws IllegalA when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(getTariffInfo())); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, - () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); + () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); verify(userRepository, times(1)).findByUuid(anyString()); verify(tariffsInfoRepository, times(1)) - .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); + .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); verify(bagRepository, times(1)).findById(anyInt()); } @@ -1088,15 +1088,15 @@ void testSaveToDBWShouldThrowBadRequestException() throws IllegalAccessException when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, - () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); + () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); verify(userRepository, times(1)).findByUuid(anyString()); verify(tariffsInfoRepository, times(1)) - .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); + .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); verify(bagRepository, times(1)).findById(any()); } @@ -1128,14 +1128,14 @@ void testSaveToDBWShouldThrowTariffNotFoundExceptionException() { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); + () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); verify(userRepository, times(1)).findByUuid(anyString()); verify(tariffsInfoRepository, times(1)) - .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); + .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); } @Test @@ -1174,15 +1174,15 @@ void testSaveToDBWShouldThrowBagNotFoundExceptionException() throws IllegalAcces when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(getTariffInfo())); when(bagRepository.findById(3)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); + () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); verify(userRepository, times(1)).findByUuid(anyString()); verify(tariffsInfoRepository, times(1)) - .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); + .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); verify(bagRepository).findById(3); } @@ -1215,7 +1215,7 @@ void testSaveToDBWithoutOrderUnpaid() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(getTariffInfo())); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto.getPersonalData(), UBSuser.class)).thenReturn(ubSuser); @@ -1226,7 +1226,7 @@ void testSaveToDBWithoutOrderUnpaid() throws IllegalAccessException { verify(userRepository, times(1)).findByUuid("35467585763t4sfgchjfuyetf"); verify(tariffsInfoRepository, times(1)) - .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); + .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); verify(bagRepository, times(2)).findById(any()); verify(ubsUserRepository, times(1)).findById(anyLong()); verify(modelMapper, times(1)).map(dto.getPersonalData(), UBSuser.class); @@ -1247,12 +1247,12 @@ void saveToDBFailPaidOrder() { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(orderRepository.findById(any())).thenReturn(Optional.of(order)); assertThrows(BadRequestException.class, - () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", 1L)); + () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", 1L)); } @Test @@ -1292,10 +1292,10 @@ void testSaveToDBThrowsException() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, - () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); + () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); } @Test @@ -1304,10 +1304,10 @@ void getSecondPageData() { PersonalDataDto expected = getOrderResponseDto().getPersonalData(); User user = getTestUser() - .setUuid(uuid) - .setRecipientEmail("mail@mail.ua") - .setRecipientPhone("067894522") - .setAlternateEmail("my@email.com"); + .setUuid(uuid) + .setRecipientEmail("mail@mail.ua") + .setRecipientPhone("067894522") + .setAlternateEmail("my@email.com"); List ubsUser = Arrays.asList(getUBSuser()); when(userRepository.findByUuid(uuid)).thenReturn(user); when(ubsUserRepository.findUBSuserByUser(user)).thenReturn(ubsUser); @@ -1324,10 +1324,10 @@ void getSecondPageDataWithUserFounded() { PersonalDataDto expected = getOrderResponseDto().getPersonalData(); User user = getTestUser() - .setUuid(uuid) - .setRecipientEmail("mail@mail.ua") - .setRecipientPhone("067894522") - .setAlternateEmail("my@email.com"); + .setUuid(uuid) + .setRecipientEmail("mail@mail.ua") + .setRecipientPhone("067894522") + .setAlternateEmail("my@email.com"); List ubsUser = Collections.singletonList(getUBSuser()); when(userRepository.findByUuid(uuid)).thenReturn(user); when(ubsUserRepository.findUBSuserByUser(user)).thenReturn(ubsUser); @@ -1346,12 +1346,12 @@ void checkCertificate() { Certificate certificate = getCertificate(); when(certificateRepository.findById("1111-1234")).thenReturn(Optional.of(certificate)); when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(CertificateDto.builder() - .code("1111-1234") - .certificateStatus("ACTIVE") - .creationDate(LocalDate.now()) - .dateOfUse(LocalDate.now().plusMonths(1)) - .points(10) - .build()); + .code("1111-1234") + .certificateStatus("ACTIVE") + .creationDate(LocalDate.now()) + .dateOfUse(LocalDate.now().plusMonths(1)) + .points(10) + .build()); assertEquals("ACTIVE", ubsService.checkCertificate("1111-1234").getCertificateStatus()); } @@ -1362,12 +1362,12 @@ void checkCertificateUSED() { certificate.setCertificateStatus(CertificateStatus.USED); when(certificateRepository.findById("1111-1234")).thenReturn(Optional.of(certificate)); when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(CertificateDto.builder() - .code("1111-1234") - .certificateStatus("USED") - .creationDate(LocalDate.now()) - .dateOfUse(LocalDate.now().plusMonths(1)) - .points(10) - .build()); + .code("1111-1234") + .certificateStatus("USED") + .creationDate(LocalDate.now()) + .dateOfUse(LocalDate.now().plusMonths(1)) + .points(10) + .build()); assertEquals("USED", ubsService.checkCertificate("1111-1234").getCertificateStatus()); } @@ -1395,26 +1395,26 @@ void getAllOrdersDoneByUser() { @Test void makeOrderAgain() { MakeOrderAgainDto dto = MakeOrderAgainDto.builder() - .orderId(1L) - .orderAmount(350L) - .bagOrderDtoList( - Arrays.asList( - BagOrderDto.builder() - .bagId(1) - .capacity(10) - .price(100.) - .bagAmount(1) - .name("name") - .nameEng("nameEng") - .build(), - BagOrderDto.builder() - .bagId(2) - .capacity(10) - .price(100.) - .name("name") - .nameEng("nameEng") - .build())) - .build(); + .orderId(1L) + .orderAmount(350L) + .bagOrderDtoList( + Arrays.asList( + BagOrderDto.builder() + .bagId(1) + .capacity(10) + .price(100.) + .bagAmount(1) + .name("name") + .nameEng("nameEng") + .build(), + BagOrderDto.builder() + .bagId(2) + .capacity(10) + .price(100.) + .name("name") + .nameEng("nameEng") + .build())) + .build(); Order order = getOrderDoneByUser(); order.setAmountOfBagsOrdered(Collections.singletonMap(1, 1)); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); @@ -1430,7 +1430,7 @@ void makeOrderAgain() { void makeOrderAgainShouldThrowOrderNotFoundException() { Locale locale = new Locale("en"); Exception thrown = assertThrows(NotFoundException.class, - () -> ubsService.makeOrderAgain(locale, 1L)); + () -> ubsService.makeOrderAgain(locale, 1L)); assertEquals(ORDER_WITH_CURRENT_ID_DOES_NOT_EXIST, thrown.getMessage()); } @@ -1441,9 +1441,9 @@ void makeOrderAgainShouldThrowBadOrderStatusException() { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); Locale locale = new Locale("en"); Exception thrown = assertThrows(BadRequestException.class, - () -> ubsService.makeOrderAgain(locale, 1L)); + () -> ubsService.makeOrderAgain(locale, 1L)); assertEquals(thrown.getMessage(), ErrorMessage.BAD_ORDER_STATUS_REQUEST - + order.getOrderStatus()); + + order.getOrderStatus()); } @Test @@ -1457,14 +1457,14 @@ void findUserByUuid() { @Test void findUserNotFoundException() { Exception thrown = assertThrows(UserNotFoundException.class, - () -> ubsService.findAllCurrentPointsForUser("87df9ad5-6393-441f-8423-8b2e770b01a8")); + () -> ubsService.findAllCurrentPointsForUser("87df9ad5-6393-441f-8423-8b2e770b01a8")); assertEquals(ErrorMessage.USER_WITH_CURRENT_ID_DOES_NOT_EXIST, thrown.getMessage()); } @Test void markUserAsDeactivatedByIdThrowsNotFoundException() { Exception thrown = assertThrows(NotFoundException.class, - () -> ubsService.markUserAsDeactivated(1L)); + () -> ubsService.markUserAsDeactivated(1L)); assertEquals(USER_WITH_CURRENT_UUID_DOES_NOT_EXIST, thrown.getMessage()); } @@ -1485,7 +1485,7 @@ void getsUserAndUserUbsAndViolationsInfoByOrderId() { when(userRepository.findByUuid(anyString())).thenReturn(getOrderDetails().getUser()); when(userRepository.countTotalUsersViolations(1L)).thenReturn(expectedResult.getTotalUserViolations()); when(userRepository.checkIfUserHasViolationForCurrentOrder(1L, 1L)) - .thenReturn(expectedResult.getUserViolationForCurrentOrder()); + .thenReturn(expectedResult.getUserViolationForCurrentOrder()); UserInfoDto actual = ubsService.getUserAndUserUbsAndViolationsInfoByOrderId(1L, anyString()); verify(orderRepository, times(1)).findById(1L); @@ -1503,7 +1503,7 @@ void getsUserAndUserUbsAndViolationsInfoByOrderIdWithoutSender() { when(userRepository.findByUuid(anyString())).thenReturn(getOrderDetailsWithoutSender().getUser()); when(userRepository.countTotalUsersViolations(1L)).thenReturn(expectedResult.getTotalUserViolations()); when(userRepository.checkIfUserHasViolationForCurrentOrder(1L, 1L)) - .thenReturn(expectedResult.getUserViolationForCurrentOrder()); + .thenReturn(expectedResult.getUserViolationForCurrentOrder()); UserInfoDto actual = ubsService.getUserAndUserUbsAndViolationsInfoByOrderId(1L, anyString()); verify(orderRepository, times(1)).findById(1L); @@ -1517,7 +1517,7 @@ void getsUserAndUserUbsAndViolationsInfoByOrderIdWithoutSender() { void getUserAndUserUbsAndViolationsInfoByOrderIdOrderNotFoundException() { when(orderRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsService.getUserAndUserUbsAndViolationsInfoByOrderId(1L, "abc")); + () -> ubsService.getUserAndUserUbsAndViolationsInfoByOrderId(1L, "abc")); } @Test @@ -1525,7 +1525,7 @@ void getUserAndUserUbsAndViolationsInfoByOrderIdAccessDeniedException() { when(orderRepository.findById(1L)).thenReturn(Optional.of(getOrder())); when(userRepository.findByUuid(anyString())).thenReturn(getTestUser()); assertThrows(AccessDeniedException.class, - () -> ubsService.getUserAndUserUbsAndViolationsInfoByOrderId(1L, "abc")); + () -> ubsService.getUserAndUserUbsAndViolationsInfoByOrderId(1L, "abc")); } @Test @@ -1535,28 +1535,28 @@ void updateUbsUserInfoInOrderThrowUBSuserNotFoundExceptionTest() { when(ubsUserRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(UBSuserNotFoundException.class, - () -> ubsService.updateUbsUserInfoInOrder(request, "abc")); + () -> ubsService.updateUbsUserInfoInOrder(request, "abc")); verify(ubsUserRepository).findById(1L); } @Test void updateUbsUserInfoInOrderTest() { UbsCustomersDtoUpdate request = UbsCustomersDtoUpdate.builder() - .recipientId(1L) - .recipientName("Anatolii") - .recipientSurName("Anatolii") - .recipientEmail("anatolii.andr@gmail.com") - .recipientPhoneNumber("095123456").build(); + .recipientId(1L) + .recipientName("Anatolii") + .recipientSurName("Anatolii") + .recipientEmail("anatolii.andr@gmail.com") + .recipientPhoneNumber("095123456").build(); Optional user = Optional.of(getUBSuser()); when(ubsUserRepository.findById(1L)).thenReturn(user); when(ubsUserRepository.save(user.get())).thenReturn(user.get()); UbsCustomersDto expected = UbsCustomersDto.builder() - .name("Anatolii Anatolii") - .email("anatolii.andr@gmail.com") - .phoneNumber("095123456") - .build(); + .name("Anatolii Anatolii") + .email("anatolii.andr@gmail.com") + .phoneNumber("095123456") + .build(); UbsCustomersDto actual = ubsService.updateUbsUserInfoInOrder(request, "abc"); assertEquals(expected, actual); @@ -1584,7 +1584,7 @@ void updateProfileData() { when(modelMapper.map(addressDto.get(0), OrderAddressDtoRequest.class)).thenReturn(updateAddressRequestDto); when(modelMapper.map(addressDto.get(1), OrderAddressDtoRequest.class)).thenReturn(updateAddressRequestDto); doReturn(new OrderWithAddressesResponseDto()) - .when(ubsClientService).updateCurrentAddressForOrder(updateAddressRequestDto, uuid); + .when(ubsClientService).updateCurrentAddressForOrder(updateAddressRequestDto, uuid); when(userRepository.save(user)).thenReturn(user); when(modelMapper.map(user, UserProfileUpdateDto.class)).thenReturn(userProfileUpdateDto); @@ -1616,7 +1616,7 @@ void updateProfileDataThrowNotFoundException() { when(userRepository.findUserByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsService.updateProfileData(uuid, userProfileUpdateDto)); + () -> ubsService.updateProfileData(uuid, userProfileUpdateDto)); verify(userRepository).findUserByUuid(uuid); } @@ -1666,7 +1666,7 @@ void updateProfileDataIfTelegramBotNotExists() { when(modelMapper.map(addressDto.get(0), OrderAddressDtoRequest.class)).thenReturn(updateAddressRequestDto); when(modelMapper.map(addressDto.get(1), OrderAddressDtoRequest.class)).thenReturn(updateAddressRequestDto); doReturn(new OrderWithAddressesResponseDto()) - .when(ubsClientService).updateCurrentAddressForOrder(updateAddressRequestDto, uuid); + .when(ubsClientService).updateCurrentAddressForOrder(updateAddressRequestDto, uuid); when(userRepository.save(user)).thenReturn(user); when(modelMapper.map(user, UserProfileUpdateDto.class)).thenReturn(userProfileUpdateDto); @@ -1712,7 +1712,7 @@ void getProfileDataNotFoundException() { when(userRepository.findUserByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsService.getProfileData(uuid)); + () -> ubsService.getProfileData(uuid)); verify(userRepository).findUserByUuid(uuid); } @@ -1742,28 +1742,28 @@ void testFindAllAddressesForCurrentOrder() { private List
getTestAddresses(User user) { Address address1 = Address.builder() - .addressStatus(AddressStatus.NEW).id(13L).city("Kyiv").district("Svyatoshyn") - .entranceNumber("1").houseCorpus("1").houseNumber("55").street("Peremohy av.") - .user(user).actual(true).coordinates(new Coordinates(12.5, 34.5)) - .build(); + .addressStatus(AddressStatus.NEW).id(13L).city("Kyiv").district("Svyatoshyn") + .entranceNumber("1").houseCorpus("1").houseNumber("55").street("Peremohy av.") + .user(user).actual(true).coordinates(new Coordinates(12.5, 34.5)) + .build(); Address address2 = Address.builder() - .addressStatus(AddressStatus.NEW).id(42L).city("Lviv").district("Syhiv") - .entranceNumber("1").houseCorpus("1").houseNumber("55").street("Lvivska st.") - .user(user).actual(true).coordinates(new Coordinates(13.5, 36.5)) - .build(); + .addressStatus(AddressStatus.NEW).id(42L).city("Lviv").district("Syhiv") + .entranceNumber("1").houseCorpus("1").houseNumber("55").street("Lvivska st.") + .user(user).actual(true).coordinates(new Coordinates(13.5, 36.5)) + .build(); return Arrays.asList(address1, address2); } private List getTestAddressesDto() { AddressDto addressDto1 = AddressDto.builder().actual(true).id(13L).city("Kyiv").district("Svyatoshyn") - .entranceNumber("1").houseCorpus("1").houseNumber("55").street("Peremohy av.") - .coordinates(new Coordinates(12.5, 34.5)).build(); + .entranceNumber("1").houseCorpus("1").houseNumber("55").street("Peremohy av.") + .coordinates(new Coordinates(12.5, 34.5)).build(); AddressDto addressDto2 = AddressDto.builder().actual(true).id(42L).city("Lviv").district("Syhiv") - .entranceNumber("1").houseCorpus("1").houseNumber("55").street("Lvivska st.") - .coordinates(new Coordinates(13.5, 36.5)).build(); + .entranceNumber("1").houseCorpus("1").houseNumber("55").street("Lvivska st.") + .coordinates(new Coordinates(13.5, 36.5)).build(); return Arrays.asList(addressDto1, addressDto2); } @@ -1782,18 +1782,18 @@ void testSaveCurrentAddressForOrder() { when(userRepository.findByUuid(user.getUuid())).thenReturn(user); when(addressRepository.findAllNonDeletedAddressesByUserId(user.getId())).thenReturn(addresses); when(googleApiService.getResultFromGeoCode(eq(dtoRequest.getPlaceId()), anyInt())) - .thenReturn(getGeocodingResult().get(0)); + .thenReturn(getGeocodingResult().get(0)); when(modelMapper.map(any(), - eq(OrderAddressDtoRequest.class))) + eq(OrderAddressDtoRequest.class))) .thenReturn(TEST_ORDER_ADDRESS_DTO_REQUEST); when(modelMapper.map(any(), - eq(Address.class))).thenReturn(addressToSave); + eq(Address.class))).thenReturn(addressToSave); when(modelMapper.map(addresses.get(0), - AddressDto.class)) + AddressDto.class)) .thenReturn(addressDto()); OrderWithAddressesResponseDto actualWithSearchAddress = - ubsService.saveCurrentAddressForOrder(createAddressRequestDto, uuid); + ubsService.saveCurrentAddressForOrder(createAddressRequestDto, uuid); assertEquals(getAddressDtoResponse(), actualWithSearchAddress); verify(addressRepository).save(addressToSave); @@ -1814,14 +1814,14 @@ void testSaveCurrentAddressForOrderAlreadyExistException() { when(userRepository.findByUuid(user.getUuid())).thenReturn(user); when(addressRepository.findAllNonDeletedAddressesByUserId(user.getId())).thenReturn(addresses); when(googleApiService.getResultFromGeoCode(eq(dtoRequest.getPlaceId()), anyInt())) - .thenReturn(getGeocodingResult().get(0)); + .thenReturn(getGeocodingResult().get(0)); dtoRequest.setPlaceId(null); when(modelMapper.map(any(), - eq(OrderAddressDtoRequest.class))) + eq(OrderAddressDtoRequest.class))) .thenReturn(dtoRequest); BadRequestException exception = assertThrows(BadRequestException.class, - () -> ubsService.saveCurrentAddressForOrder(createAddressRequestDto, uuid)); + () -> ubsService.saveCurrentAddressForOrder(createAddressRequestDto, uuid)); assertEquals(ADDRESS_ALREADY_EXISTS, exception.getMessage()); } @@ -1837,7 +1837,7 @@ void testSaveCurrentAddressForMaximumNumbersOfOrdersAddressesException() { when(addressRepository.findAllNonDeletedAddressesByUserId(user.getId())).thenReturn(addresses); BadRequestException exception = assertThrows(BadRequestException.class, - () -> ubsService.saveCurrentAddressForOrder(createAddressRequestDto, uuid)); + () -> ubsService.saveCurrentAddressForOrder(createAddressRequestDto, uuid)); assertEquals(ErrorMessage.NUMBER_OF_ADDRESSES_EXCEEDED, exception.getMessage()); } @@ -1858,33 +1858,33 @@ void testUpdateCurrentAddressForOrder() { when(userRepository.findByUuid(user.getUuid())).thenReturn(user); when(addressRepository.findAllNonDeletedAddressesByUserId(user.getId())).thenReturn(addresses); when(googleApiService.getResultFromGeoCode(eq(updateAddressRequestDto.getPlaceId()), anyInt())) - .thenReturn(getGeocodingResult().get(0)); + .thenReturn(getGeocodingResult().get(0)); when(modelMapper.map(any(), - eq(OrderAddressDtoRequest.class))) + eq(OrderAddressDtoRequest.class))) .thenReturn(TEST_ORDER_ADDRESS_DTO_REQUEST); when(addressRepository.findById(updateAddressRequestDto.getId())) - .thenReturn(Optional.ofNullable(addresses.get(0))); + .thenReturn(Optional.ofNullable(addresses.get(0))); when(modelMapper.map(any(), - eq(Address.class))).thenReturn(addresses.get(0)); + eq(Address.class))).thenReturn(addresses.get(0)); when(addressRepository.save(addresses.get(0))).thenReturn(addresses.get(0)); when(modelMapper.map(addresses.get(0), - AddressDto.class)) + AddressDto.class)) .thenReturn(addressDto()); OrderWithAddressesResponseDto actualWithSearchAddress = - ubsService.updateCurrentAddressForOrder(updateAddressRequestDto, uuid); + ubsService.updateCurrentAddressForOrder(updateAddressRequestDto, uuid); Assertions.assertNotNull(updateAddressRequestDto.getSearchAddress()); Assertions.assertNull(dtoRequest.getSearchAddress()); assertEquals(getAddressDtoResponse(), actualWithSearchAddress); verify(googleApiService, times(2)).getResultFromGeoCode(eq(updateAddressRequestDto.getPlaceId()), - anyInt()); + anyInt()); updateAddressRequestDto.setSearchAddress(null); OrderWithAddressesResponseDto actualWithoutSearchAddress = - ubsService.updateCurrentAddressForOrder(updateAddressRequestDto, uuid); + ubsService.updateCurrentAddressForOrder(updateAddressRequestDto, uuid); assertEquals(getAddressDtoResponse(), actualWithoutSearchAddress); verify(addressRepository, times(2)).save(addresses.get(0)); } @@ -1903,27 +1903,27 @@ void testUpdateCurrentAddressForOrderWithNoAddress() { when(userRepository.findByUuid(user.getUuid())).thenReturn(user); when(addressRepository.findById(updateAddressRequestDto.getId())) - .thenReturn(Optional.ofNullable(addresses.get(0))); + .thenReturn(Optional.ofNullable(addresses.get(0))); when(googleApiService.getResultFromGeoCode(eq(updateAddressRequestDto.getPlaceId()), anyInt())) - .thenReturn(getGeocodingResult().get(0)); + .thenReturn(getGeocodingResult().get(0)); when(addressRepository.findById(updateAddressRequestDto.getId())) - .thenReturn(Optional.ofNullable(addresses.get(0))); + .thenReturn(Optional.ofNullable(addresses.get(0))); when(modelMapper.map(any(), - eq(Address.class))).thenReturn(addresses.get(0)); + eq(Address.class))).thenReturn(addresses.get(0)); when(addressRepository.save(addresses.get(0))).thenReturn(addresses.get(0)); OrderWithAddressesResponseDto actualWithSearchAddress = - ubsService.updateCurrentAddressForOrder(updateAddressRequestDto, uuid); + ubsService.updateCurrentAddressForOrder(updateAddressRequestDto, uuid); Assertions.assertNotNull(updateAddressRequestDto.getSearchAddress()); Assertions.assertNull(dtoRequest.getSearchAddress()); assertEquals(OrderWithAddressesResponseDto.builder().addressList(Collections.emptyList()).build(), - actualWithSearchAddress); + actualWithSearchAddress); verify(googleApiService, times(2)).getResultFromGeoCode(eq(updateAddressRequestDto.getPlaceId()), - anyInt()); + anyInt()); verify(addressRepository, times(1)).save(addresses.get(0)); verify(addressRepository, times(1)).findById(anyLong()); verify(modelMapper, times(1)).map(any(), eq(Address.class)); @@ -1945,16 +1945,16 @@ void testUpdateCurrentAddressForOrderAlreadyExistException() { when(userRepository.findByUuid(user.getUuid())).thenReturn(user); when(addressRepository.findById(updateAddressRequestDto.getId())) - .thenReturn(Optional.ofNullable(addresses.get(0))); + .thenReturn(Optional.ofNullable(addresses.get(0))); when(addressRepository.findAllNonDeletedAddressesByUserId(user.getId())).thenReturn(addresses); when(googleApiService.getResultFromGeoCode(eq(updateAddressRequestDto.getPlaceId()), anyInt())) - .thenReturn(getGeocodingResult().get(0)); + .thenReturn(getGeocodingResult().get(0)); when(modelMapper.map(any(), - eq(OrderAddressDtoRequest.class))) + eq(OrderAddressDtoRequest.class))) .thenReturn(dtoRequest); BadRequestException exception = assertThrows(BadRequestException.class, - () -> ubsService.updateCurrentAddressForOrder(updateAddressRequestDto, uuid)); + () -> ubsService.updateCurrentAddressForOrder(updateAddressRequestDto, uuid)); assertEquals(ADDRESS_ALREADY_EXISTS, exception.getMessage()); } @@ -1976,7 +1976,7 @@ void testUpdateCurrentAddressForOrderNotFoundOrderAddressException() { when(addressRepository.findById(updateAddressRequestDto.getId())).thenReturn(Optional.empty()); NotFoundException exception = assertThrows(NotFoundException.class, - () -> ubsService.updateCurrentAddressForOrder(updateAddressRequestDto, uuid)); + () -> ubsService.updateCurrentAddressForOrder(updateAddressRequestDto, uuid)); assertEquals(NOT_FOUND_ADDRESS_ID_FOR_CURRENT_USER + updateAddressRequestDto.getId(), exception.getMessage()); } @@ -2002,7 +2002,7 @@ void testUpdateCurrentAddressForOrderThrowsAccessDeniedException() { when(userRepository.findByUuid(user.getUuid())).thenReturn(user); AccessDeniedException exception = assertThrows(AccessDeniedException.class, - () -> ubsService.updateCurrentAddressForOrder(dtoRequest, uuid)); + () -> ubsService.updateCurrentAddressForOrder(dtoRequest, uuid)); assertEquals(CANNOT_ACCESS_PERSONAL_INFO, exception.getMessage()); } @@ -2059,7 +2059,7 @@ void testDeleteCurrentAddressForOrderWhenAddressIsActual() { when(addressRepository.findById(firstAddressId)).thenReturn(Optional.of(firstAddress)); when(addressRepository.findAnyByUserIdAndAddressStatusNotDeleted(user.getId())) - .thenReturn(Optional.of(secondAddress)); + .thenReturn(Optional.of(secondAddress)); doReturn(new OrderWithAddressesResponseDto()).when(ubsClientService).findAllAddressesForCurrentOrder(uuid); ubsClientService.deleteCurrentAddressForOrder(firstAddressId, uuid); @@ -2106,7 +2106,7 @@ void testDeleteCurrentAddressForOrderWithUnexistingAddress() { when(addressRepository.findById(addressId)).thenReturn(Optional.empty()); NotFoundException exception = assertThrows(NotFoundException.class, - () -> ubsClientService.deleteCurrentAddressForOrder(addressId, "qwe")); + () -> ubsClientService.deleteCurrentAddressForOrder(addressId, "qwe")); assertEquals(NOT_FOUND_ADDRESS_ID_FOR_CURRENT_USER + addressId, exception.getMessage()); @@ -2129,7 +2129,7 @@ void testDeleteCurrentAddressForOrderForWrongUser() { when(addressRepository.findById(firstAddressId)).thenReturn(Optional.of(firstAddress)); AccessDeniedException exception = assertThrows(AccessDeniedException.class, - () -> ubsClientService.deleteCurrentAddressForOrder(firstAddressId, uuid)); + () -> ubsClientService.deleteCurrentAddressForOrder(firstAddressId, uuid)); assertEquals(CANNOT_DELETE_ADDRESS, exception.getMessage()); @@ -2153,7 +2153,7 @@ void testDeleteCurrentAddressForOrderWhenAddressAlreadyDeleted() { when(addressRepository.findById(firstAddressId)).thenReturn(Optional.of(firstAddress)); BadRequestException exception = assertThrows(BadRequestException.class, - () -> ubsClientService.deleteCurrentAddressForOrder(firstAddressId, uuid)); + () -> ubsClientService.deleteCurrentAddressForOrder(firstAddressId, uuid)); assertEquals(CANNOT_DELETE_ALREADY_DELETED_ADDRESS, exception.getMessage()); @@ -2227,7 +2227,7 @@ void testMakeAddressActualWhereUserNotHaveActualAddress() { when(addressRepository.findByUserIdAndActualTrue(user.getId())).thenReturn(Optional.empty()); NotFoundException exception = assertThrows(NotFoundException.class, - () -> ubsService.makeAddressActual(firstAddressId, uuid)); + () -> ubsService.makeAddressActual(firstAddressId, uuid)); assertEquals(ACTUAL_ADDRESS_NOT_FOUND, exception.getMessage()); @@ -2266,7 +2266,7 @@ void testMakeAddressActualWhenAddressNotFound() { when(addressRepository.findById(firstAddressId)).thenReturn(Optional.empty()); NotFoundException exception = assertThrows(NotFoundException.class, - () -> ubsService.makeAddressActual(firstAddressId, uuid)); + () -> ubsService.makeAddressActual(firstAddressId, uuid)); assertEquals(NOT_FOUND_ADDRESS_ID_FOR_CURRENT_USER + firstAddressId, exception.getMessage()); @@ -2291,7 +2291,7 @@ void testMakeAddressActualWhenAddressNotBelongsToUser() { when(addressRepository.findById(firstAddressId)).thenReturn(Optional.of(firstAddress)); AccessDeniedException exception = assertThrows(AccessDeniedException.class, - () -> ubsService.makeAddressActual(firstAddressId, uuid)); + () -> ubsService.makeAddressActual(firstAddressId, uuid)); assertEquals(CANNOT_ACCESS_PERSONAL_INFO, exception.getMessage()); @@ -2314,7 +2314,7 @@ void testMakeAddressActualWhenAddressIdDeleted() { when(addressRepository.findById(firstAddressId)).thenReturn(Optional.of(firstAddress)); BadRequestException exception = assertThrows(BadRequestException.class, - () -> ubsService.makeAddressActual(firstAddressId, uuid)); + () -> ubsService.makeAddressActual(firstAddressId, uuid)); assertEquals(CANNOT_MAKE_ACTUAL_DELETED_ADDRESS, exception.getMessage()); @@ -2378,7 +2378,7 @@ void getOrderPaymentDetailIfPaymentIsEmpty() { void getOrderPaymentDetailShouldThrowOrderNotFoundException() { when(orderRepository.findById(any())).thenReturn(Optional.empty()); Exception thrown = assertThrows(NotFoundException.class, - () -> ubsService.getOrderPaymentDetail(null)); + () -> ubsService.getOrderPaymentDetail(null)); assertEquals(ORDER_WITH_CURRENT_ID_DOES_NOT_EXIST, thrown.getMessage()); } @@ -2399,7 +2399,7 @@ void testGetOrderCancellationReason() { void getOrderCancellationReasonOrderNotFoundException() { when(orderRepository.findById(anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsService.getOrderCancellationReason(1L, "abc")); + () -> ubsService.getOrderCancellationReason(1L, "abc")); } @Test @@ -2407,7 +2407,7 @@ void getOrderCancellationReasonAccessDeniedException() { when(orderRepository.findById(anyLong())).thenReturn(Optional.ofNullable(getOrderTest())); when(userRepository.findByUuid(anyString())).thenReturn(getTestUser()); assertThrows(AccessDeniedException.class, - () -> ubsService.getOrderCancellationReason(1L, "abc")); + () -> ubsService.getOrderCancellationReason(1L, "abc")); } @Test @@ -2421,7 +2421,7 @@ void testUpdateOrderCancellationReason() { OrderCancellationReasonDto result = ubsService.updateOrderCancellationReason(1L, dto, anyString()); verify(eventService, times(1)) - .saveEvent("Статус Замовлення - Скасовано", "", orderDto); + .saveEvent("Статус Замовлення - Скасовано", "", orderDto); assertEquals(dto.getCancellationReason(), result.getCancellationReason()); assertEquals(dto.getCancellationComment(), result.getCancellationComment()); verify(orderRepository).save(orderDto); @@ -2432,7 +2432,7 @@ void testUpdateOrderCancellationReason() { void updateOrderCancellationReasonOrderNotFoundException() { when(orderRepository.findById(anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsService.updateOrderCancellationReason(1L, null, "abc")); + () -> ubsService.updateOrderCancellationReason(1L, null, "abc")); } @Test @@ -2440,7 +2440,7 @@ void updateOrderCancellationReasonAccessDeniedException() { when(orderRepository.findById(anyLong())).thenReturn(Optional.ofNullable(getOrderTest())); when(userRepository.findByUuid(anyString())).thenReturn(getTestUser()); assertThrows(AccessDeniedException.class, - () -> ubsService.updateOrderCancellationReason(1L, null, "abc")); + () -> ubsService.updateOrderCancellationReason(1L, null, "abc")); } @Test @@ -2449,8 +2449,8 @@ void testGelAllEventsFromOrderByOrderId() { when(orderRepository.findById(1L)).thenReturn(getOrderWithEvents()); when(eventRepository.findAllEventsByOrderId(1L)).thenReturn(orderEvents); List eventDTOS = orderEvents.stream() - .map(event -> modelMapper.map(event, EventDto.class)) - .collect(Collectors.toList()); + .map(event -> modelMapper.map(event, EventDto.class)) + .collect(Collectors.toList()); assertEquals(eventDTOS, ubsService.getAllEventsForOrder(1L, anyString())); } @@ -2458,7 +2458,7 @@ void testGelAllEventsFromOrderByOrderId() { void testGelAllEventsFromOrderByOrderIdWithThrowingOrderNotFindException() { when(orderRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsService.getAllEventsForOrder(1L, "abc")); + () -> ubsService.getAllEventsForOrder(1L, "abc")); } @Test @@ -2466,14 +2466,14 @@ void testGelAllEventsFromOrderByOrderIdWithThrowingEventsNotFoundException() { when(orderRepository.findById(1L)).thenReturn(getOrderWithEvents()); when(eventRepository.findAllEventsByOrderId(1L)).thenReturn(Collections.emptyList()); assertThrows(NotFoundException.class, - () -> ubsService.getAllEventsForOrder(1L, "abc")); + () -> ubsService.getAllEventsForOrder(1L, "abc")); } @Test void deleteOrder() { Order order = getOrder(); when(ordersForUserRepository.getAllByUserUuidAndId(order.getUser().getUuid(), order.getId())) - .thenReturn(order); + .thenReturn(order); ubsService.deleteOrder(order.getUser().getUuid(), 1L); @@ -2484,7 +2484,7 @@ void deleteOrder() { void deleteOrderFail() { Order order = getOrder(); when(ordersForUserRepository.getAllByUserUuidAndId(order.getUser().getUuid(), order.getId())) - .thenReturn(null); + .thenReturn(null); assertThrows(NotFoundException.class, () -> { ubsService.deleteOrder("UUID", 1L); @@ -2568,7 +2568,7 @@ void processOrderFondyClient2() throws Exception { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(userRepository.findUserByUuid("uuid")).thenReturn(Optional.of(user)); when(certificateRepository.findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), - CertificateStatus.ACTIVE)).thenReturn(Set.of(certificate)); + CertificateStatus.ACTIVE)).thenReturn(Set.of(certificate)); when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(TEST_BAG_LIST); when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(certificateDto); when(modelMapper.map(any(Bag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); @@ -2578,7 +2578,7 @@ void processOrderFondyClient2() throws Exception { verify(orderRepository).findById(1L); verify(userRepository).findUserByUuid("uuid"); verify(certificateRepository).findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), - CertificateStatus.ACTIVE); + CertificateStatus.ACTIVE); verify(bagRepository).findBagsByOrderId(order.getId()); verify(modelMapper).map(certificate, CertificateDto.class); verify(modelMapper).map(any(Bag.class), eq(BagForUserDto.class)); @@ -2618,7 +2618,7 @@ void processOrderFondyClientCertificeteNotFoundExeption() throws Exception { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(userRepository.findUserByUuid("uuid")).thenReturn(Optional.of(user)); when(certificateRepository.findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), - CertificateStatus.ACTIVE)).thenReturn(Collections.emptySet()); + CertificateStatus.ACTIVE)).thenReturn(Collections.emptySet()); when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(TEST_BAG_LIST); when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(certificateDto); when(modelMapper.map(any(Bag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); @@ -2628,7 +2628,7 @@ void processOrderFondyClientCertificeteNotFoundExeption() throws Exception { verify(orderRepository).findById(1L); verify(userRepository).findUserByUuid("uuid"); verify(certificateRepository).findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), - CertificateStatus.ACTIVE); + CertificateStatus.ACTIVE); verify(bagRepository).findBagsByOrderId(order.getId()); verify(modelMapper).map(certificate, CertificateDto.class); verify(modelMapper).map(any(Bag.class), eq(BagForUserDto.class)); @@ -2668,7 +2668,7 @@ void processOrderFondyClientCertificeteNotFoundExeption2() throws Exception { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(userRepository.findUserByUuid("uuid")).thenReturn(Optional.of(user)); when(certificateRepository.findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), - CertificateStatus.ACTIVE)).thenReturn(Set.of(certificate)); + CertificateStatus.ACTIVE)).thenReturn(Set.of(certificate)); when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(TEST_BAG_LIST); when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(certificateDto); when(modelMapper.map(any(Bag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); @@ -2678,7 +2678,7 @@ void processOrderFondyClientCertificeteNotFoundExeption2() throws Exception { verify(orderRepository).findById(1L); verify(userRepository).findUserByUuid("uuid"); verify(certificateRepository).findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), - CertificateStatus.ACTIVE); + CertificateStatus.ACTIVE); verify(bagRepository).findBagsByOrderId(order.getId()); verify(modelMapper).map(certificate, CertificateDto.class); verify(modelMapper).map(any(Bag.class), eq(BagForUserDto.class)); @@ -2776,7 +2776,7 @@ void saveFullOrderToDBForIF() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(getTariffInfo())); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); @@ -2831,7 +2831,7 @@ void saveFullOrderToDBWhenSumToPayeqNull() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(getTariffInfo())); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(addressRepository.findById(any())).thenReturn(Optional.of(address)); @@ -2879,7 +2879,7 @@ void testSaveToDBfromIForIFThrowsException() throws IllegalAccessException { } when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfoWithLimitOfBags())); + .thenReturn(Optional.of(getTariffInfoWithLimitOfBags())); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, () -> { ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null); @@ -2920,7 +2920,7 @@ void testCheckSumIfCourierLimitBySumOfOrderForIF1() throws IllegalAccessExceptio when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); @@ -2964,7 +2964,7 @@ void testCheckSumIfCourierLimitBySumOfOrderForIF2() throws InvocationTargetExcep when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, () -> { @@ -2992,7 +2992,7 @@ void validatePaymentClientExceptionTest() { PaymentResponseDto dto = getPaymentResponseDto(); when(orderRepository.findById(1L)) - .thenReturn(Optional.ofNullable(getOrdersDto())); + .thenReturn(Optional.ofNullable(getOrdersDto())); assertThrows(BadRequestException.class, () -> ubsService.validatePaymentClient(dto)); } @@ -3030,8 +3030,8 @@ void findAllCurrentPointsForUser() { void getPaymentResponseFromFondy() { Order order = getOrder(); FondyPaymentResponse expected = FondyPaymentResponse.builder() - .paymentStatus(order.getPayment().get(0).getResponseStatus()) - .build(); + .paymentStatus(order.getPayment().get(0).getResponseStatus()) + .build(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(userRepository.findByUuid(order.getUser().getUuid())).thenReturn(order.getUser()); @@ -3094,14 +3094,14 @@ void getOrderForUserTest() { orderList.add(order); when(ordersForUserRepository.getAllByUserUuidAndId(user.getUuid(), order.getId())) - .thenReturn(order); + .thenReturn(order); when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(bags); when(modelMapper.map(bag, BagForUserDto.class)).thenReturn(bagForUserDto); when(orderStatusTranslationRepository - .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) + .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) .thenReturn(Optional.of(orderStatusTranslation)); when(orderPaymentStatusTranslationRepository.getById( - (long) order.getOrderPaymentStatus().getStatusValue())) + (long) order.getOrderPaymentStatus().getStatusValue())) .thenReturn(orderPaymentStatusTranslation); ubsService.getOrderForUser(user.getUuid(), 1L); @@ -3109,10 +3109,10 @@ void getOrderForUserTest() { verify(modelMapper, times(bags.size())).map(bag, BagForUserDto.class); verify(bagRepository).findBagsByOrderId(order.getId()); verify(orderStatusTranslationRepository, times(orderList.size())) - .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); + .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); verify(orderPaymentStatusTranslationRepository, times(orderList.size())) - .getById( - (long) order.getOrderPaymentStatus().getStatusValue()); + .getById( + (long) order.getOrderPaymentStatus().getStatusValue()); } @Test @@ -3121,7 +3121,7 @@ void getOrderForUserFail() { User user = getTestUser(); when(ordersForUserRepository.getAllByUserUuidAndId("UUID", order.getId())) - .thenReturn(null); + .thenReturn(null); assertThrows(NotFoundException.class, () -> { ubsService.getOrderForUser("UUID", 1L); @@ -3152,14 +3152,14 @@ void getOrdersForUserTest() { Page page = new PageImpl<>(orderList, pageable, 1); when(ordersForUserRepository.getAllByUserUuid(pageable, user.getUuid())) - .thenReturn(page); + .thenReturn(page); when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(bags); when(modelMapper.map(bag, BagForUserDto.class)).thenReturn(bagForUserDto); when(orderStatusTranslationRepository - .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) + .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) .thenReturn(Optional.of(orderStatusTranslation)); when(orderPaymentStatusTranslationRepository.getById( - (long) order.getOrderPaymentStatus().getStatusValue())) + (long) order.getOrderPaymentStatus().getStatusValue())) .thenReturn(orderPaymentStatusTranslation); PageableDto dto = ubsService.getOrdersForUser(user.getUuid(), pageable, null); @@ -3170,10 +3170,10 @@ void getOrdersForUserTest() { verify(modelMapper, times(bags.size())).map(bag, BagForUserDto.class); verify(bagRepository).findBagsByOrderId(order.getId()); verify(orderStatusTranslationRepository, times(orderList.size())) - .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); + .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); verify(orderPaymentStatusTranslationRepository, times(orderList.size())) - .getById( - (long) order.getOrderPaymentStatus().getStatusValue()); + .getById( + (long) order.getOrderPaymentStatus().getStatusValue()); verify(ordersForUserRepository).getAllByUserUuid(pageable, user.getUuid()); } @@ -3201,14 +3201,14 @@ void testOrdersForUserWithExportedQuantity() { Page page = new PageImpl<>(orderList, pageable, 1); when(ordersForUserRepository.getAllByUserUuid(pageable, user.getUuid())) - .thenReturn(page); + .thenReturn(page); when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(bags); when(modelMapper.map(bag, BagForUserDto.class)).thenReturn(bagForUserDto); when(orderStatusTranslationRepository - .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) + .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) .thenReturn(Optional.of(orderStatusTranslation)); when(orderPaymentStatusTranslationRepository.getById( - (long) order.getOrderPaymentStatus().getStatusValue())) + (long) order.getOrderPaymentStatus().getStatusValue())) .thenReturn(orderPaymentStatusTranslation); PageableDto dto = ubsService.getOrdersForUser(user.getUuid(), pageable, null); @@ -3219,10 +3219,10 @@ void testOrdersForUserWithExportedQuantity() { verify(modelMapper, times(bags.size())).map(bag, BagForUserDto.class); verify(bagRepository).findBagsByOrderId(order.getId()); verify(orderStatusTranslationRepository, times(orderList.size())) - .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); + .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); verify(orderPaymentStatusTranslationRepository, times(orderList.size())) - .getById( - (long) order.getOrderPaymentStatus().getStatusValue()); + .getById( + (long) order.getOrderPaymentStatus().getStatusValue()); verify(ordersForUserRepository).getAllByUserUuid(pageable, user.getUuid()); } @@ -3250,14 +3250,14 @@ void testOrdersForUserWithConfirmedQuantity() { Page page = new PageImpl<>(orderList, pageable, 1); when(ordersForUserRepository.getAllByUserUuid(pageable, user.getUuid())) - .thenReturn(page); + .thenReturn(page); when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(bags); when(modelMapper.map(bag, BagForUserDto.class)).thenReturn(bagForUserDto); when(orderStatusTranslationRepository - .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) + .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) .thenReturn(Optional.of(orderStatusTranslation)); when(orderPaymentStatusTranslationRepository.getById( - (long) order.getOrderPaymentStatus().getStatusValue())) + (long) order.getOrderPaymentStatus().getStatusValue())) .thenReturn(orderPaymentStatusTranslation); PageableDto dto = ubsService.getOrdersForUser(user.getUuid(), pageable, null); @@ -3268,10 +3268,10 @@ void testOrdersForUserWithConfirmedQuantity() { verify(modelMapper, times(bags.size())).map(bag, BagForUserDto.class); verify(bagRepository).findBagsByOrderId(order.getId()); verify(orderStatusTranslationRepository, times(orderList.size())) - .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); + .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); verify(orderPaymentStatusTranslationRepository, times(orderList.size())) - .getById( - (long) order.getOrderPaymentStatus().getStatusValue()); + .getById( + (long) order.getOrderPaymentStatus().getStatusValue()); verify(ordersForUserRepository).getAllByUserUuid(pageable, user.getUuid()); } @@ -3291,12 +3291,12 @@ void senderInfoDtoBuilderTest() { Page page = new PageImpl<>(orderList, pageable, 1); when(ordersForUserRepository.getAllByUserUuid(pageable, user.getUuid())) - .thenReturn(page); + .thenReturn(page); when(orderStatusTranslationRepository - .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) + .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) .thenReturn(Optional.of(orderStatusTranslation)); when(orderPaymentStatusTranslationRepository.getById( - (long) order.getOrderPaymentStatus().getStatusValue())) + (long) order.getOrderPaymentStatus().getStatusValue())) .thenReturn(orderPaymentStatusTranslation); PageableDto dto = ubsService.getOrdersForUser(user.getUuid(), pageable, null); @@ -3309,7 +3309,7 @@ void getTariffInfoForLocationTest() { var tariff = getTariffInfo(); when(courierRepository.existsCourierById(1L)).thenReturn(true); when(tariffsInfoRepository.findTariffsInfoLimitsByCourierIdAndLocationId(anyLong(), anyLong())) - .thenReturn(Optional.of(tariff)); + .thenReturn(Optional.of(tariff)); OrderCourierPopUpDto dto = ubsService.getTariffInfoForLocation(1L, 1L); assertTrue(dto.getOrderIsPresent()); verify(courierRepository).existsCourierById(1L); @@ -3321,7 +3321,7 @@ void getTariffInfoForLocationTest() { void getTariffInfoForLocationWhenCourierNotFoundTest() { when(courierRepository.existsCourierById(1L)).thenReturn(false); assertThrows(NotFoundException.class, () -> ubsService - .getTariffInfoForLocation(1L, 1L)); + .getTariffInfoForLocation(1L, 1L)); verify(courierRepository).existsCourierById(1L); } @@ -3330,7 +3330,7 @@ void getTariffInfoForLocationWhenTariffForCourierAndLocationNotFoundTest() { var expectedErrorMessage = String.format(TARIFF_FOR_COURIER_AND_LOCATION_NOT_EXIST, 1L, 1L); when(courierRepository.existsCourierById(1L)).thenReturn(true); var exception = assertThrows(NotFoundException.class, - () -> ubsService.getTariffInfoForLocation(1L, 1L)); + () -> ubsService.getTariffInfoForLocation(1L, 1L)); assertEquals(expectedErrorMessage, exception.getMessage()); verify(courierRepository).existsCourierById(1L); @@ -3342,11 +3342,11 @@ void getInfoForCourierOrderingByCourierIdTest() { when(courierRepository.existsCourierById(1L)).thenReturn(true); when(orderRepository.getLastOrderOfUserByUUIDIfExists(anyString())) - .thenReturn(Optional.of(getOrder())); + .thenReturn(Optional.of(getOrder())); when(tariffsInfoRepository.findTariffsInfoByOrdersId(anyLong())).thenReturn(tariff); OrderCourierPopUpDto dto = ubsService.getInfoForCourierOrderingByCourierId("35467585763t4sfgchjfuyetf", - Optional.empty(), 1L); + Optional.empty(), 1L); assertTrue(dto.getOrderIsPresent()); verify(courierRepository).existsCourierById(1L); @@ -3360,7 +3360,7 @@ void getInfoForCourierOrderingByCourierIdWhenCourierNotFoundTest() { Optional changeLoc = Optional.empty(); when(courierRepository.existsCourierById(1L)).thenReturn(false); assertThrows(NotFoundException.class, () -> ubsService - .getInfoForCourierOrderingByCourierId("35467585763t4sfgchjfuyetf", changeLoc, 1L)); + .getInfoForCourierOrderingByCourierId("35467585763t4sfgchjfuyetf", changeLoc, 1L)); verify(courierRepository).existsCourierById(1L); } @@ -3368,10 +3368,10 @@ void getInfoForCourierOrderingByCourierIdWhenCourierNotFoundTest() { void getInfoForCourierOrderingByCourierIdWhenOrderIsEmptyTest() { when(courierRepository.existsCourierById(1L)).thenReturn(true); when(orderRepository.getLastOrderOfUserByUUIDIfExists(anyString())) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); OrderCourierPopUpDto dto = ubsService.getInfoForCourierOrderingByCourierId("35467585763t4sfgchjfuyetf", - Optional.empty(), 1L); + Optional.empty(), 1L); assertFalse(dto.getOrderIsPresent()); verify(courierRepository).existsCourierById(1L); @@ -3382,7 +3382,7 @@ void getInfoForCourierOrderingByCourierIdWhenOrderIsEmptyTest() { void getInfoForCourierOrderingByCourierIdWhenChangeLocIsPresentTest() { when(courierRepository.existsCourierById(1L)).thenReturn(true); var dto = ubsService.getInfoForCourierOrderingByCourierId( - "35467585763t4sfgchjfuyetf", Optional.of("w"), 1L); + "35467585763t4sfgchjfuyetf", Optional.of("w"), 1L); assertEquals(0, dto.getAllActiveLocationsDtos().size()); verify(courierRepository).existsCourierById(1L); } @@ -3391,7 +3391,7 @@ void getInfoForCourierOrderingByCourierIdWhenChangeLocIsPresentTest() { void getAllActiveCouriersTest() { when(courierRepository.getAllActiveCouriers()).thenReturn(List.of(getCourier())); when(modelMapper.map(getCourier(), CourierDto.class)) - .thenReturn(getCourierDto()); + .thenReturn(getCourierDto()); assertEquals(getCourierDtoList(), ubsService.getAllActiveCouriers()); @@ -3429,7 +3429,7 @@ void checkIfAddressHasBeenDeletedTest() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(getTariffInfo())); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); @@ -3473,14 +3473,14 @@ void checkAddressUserTest() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(getTariffInfo())); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); when(modelMapper.map(dto.getPersonalData(), UBSuser.class)).thenReturn(ubSuser); assertThrows(NotFoundException.class, - () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); + () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); } @@ -3509,11 +3509,11 @@ void checkIfUserHaveEnoughPointsTest() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(getTariffInfo())); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, - () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); + () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); } @Test @@ -3521,7 +3521,7 @@ void getTariffForOrderTest() { TariffsInfo tariffsInfo = getTariffInfo(); when(tariffsInfoRepository.findByOrdersId(anyLong())).thenReturn(Optional.of(tariffsInfo)); when(modelMapper.map(tariffsInfo, TariffsForLocationDto.class)) - .thenReturn(getTariffsForLocationDto()); + .thenReturn(getTariffsForLocationDto()); var dto = ubsService.getTariffForOrder(1L); verify(tariffsInfoRepository, times(1)).findByOrdersId(anyLong()); verify(modelMapper).map(tariffsInfo, TariffsForLocationDto.class); @@ -3553,7 +3553,7 @@ void getAllAuthoritiesService() { Optional employeeOptional = Optional.ofNullable(getEmployee()); when(employeeRepository.findByEmail(anyString())).thenReturn(employeeOptional); when(userRemoteClient.getAllAuthorities(employeeOptional.get().getEmail())) - .thenReturn(Set.copyOf(ModelUtils.getAllAuthorities())); + .thenReturn(Set.copyOf(ModelUtils.getAllAuthorities())); Set authoritiesResult = ubsService.getAllAuthorities(employeeOptional.get().getEmail()); Set authExpected = Set.of("SEE_CLIENTS_PAGE"); assertEquals(authExpected, authoritiesResult); @@ -3583,12 +3583,12 @@ void testOrdersForUserWithQuantity() { Page page = new PageImpl<>(orderList, pageable, 1); when(ordersForUserRepository.getAllByUserUuid(pageable, user.getUuid())) - .thenReturn(page); + .thenReturn(page); when(orderStatusTranslationRepository - .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) + .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) .thenReturn(Optional.of(orderStatusTranslation)); when(orderPaymentStatusTranslationRepository.getById( - (long) order.getOrderPaymentStatus().getStatusValue())) + (long) order.getOrderPaymentStatus().getStatusValue())) .thenReturn(orderPaymentStatusTranslation); PageableDto dto = ubsService.getOrdersForUser(user.getUuid(), pageable, null); @@ -3596,10 +3596,10 @@ void testOrdersForUserWithQuantity() { assertEquals(dto.getTotalElements(), orderList.size()); assertEquals(dto.getPage().get(0).getId(), order.getId()); verify(orderStatusTranslationRepository, times(orderList.size())) - .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); + .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); verify(orderPaymentStatusTranslationRepository, times(orderList.size())) - .getById( - (long) order.getOrderPaymentStatus().getStatusValue()); + .getById( + (long) order.getOrderPaymentStatus().getStatusValue()); verify(ordersForUserRepository).getAllByUserUuid(pageable, user.getUuid()); } @@ -3607,12 +3607,12 @@ void testOrdersForUserWithQuantity() { void testCreateUserProfileIfProfileDoesNotExist() { UserProfileCreateDto userProfileCreateDto = getUserProfileCreateDto(); User userForSave = User.builder() - .uuid(userProfileCreateDto.getUuid()) - .recipientEmail(userProfileCreateDto.getEmail()) - .recipientName(userProfileCreateDto.getName()) - .currentPoints(0) - .violations(0) - .dateOfRegistration(LocalDate.now()).build(); + .uuid(userProfileCreateDto.getUuid()) + .recipientEmail(userProfileCreateDto.getEmail()) + .recipientName(userProfileCreateDto.getName()) + .currentPoints(0) + .violations(0) + .dateOfRegistration(LocalDate.now()).build(); User user = getUser(); when(userRemoteClient.checkIfUserExistsByUuid(userProfileCreateDto.getUuid())).thenReturn(true); when(userRepository.findByUuid(userProfileCreateDto.getUuid())).thenReturn(null); @@ -3646,7 +3646,7 @@ void testCreateUserProfileIfUserByUuidDoesNotExist() { void getPositionsAndRelatedAuthoritiesTest() { when(employeeRepository.findByEmail(TEST_EMAIL)).thenReturn(Optional.ofNullable(getEmployee())); when(userRemoteClient.getPositionsAndRelatedAuthorities(TEST_EMAIL)) - .thenReturn(ModelUtils.getPositionAuthoritiesDto()); + .thenReturn(ModelUtils.getPositionAuthoritiesDto()); PositionAuthoritiesDto actual = ubsService.getPositionsAndRelatedAuthorities(TEST_EMAIL); assertEquals(ModelUtils.getPositionAuthoritiesDto(), actual); diff --git a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java index 13aff7638..208fefea9 100644 --- a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java @@ -271,27 +271,27 @@ class UBSManagementServiceImplTest { @Test void getAllCertificates() { Pageable pageable = - PageRequest.of(0, 5, Sort.by(Sort.Direction.fromString(SortingOrder.DESC.toString()), "points")); + PageRequest.of(0, 5, Sort.by(Sort.Direction.fromString(SortingOrder.DESC.toString()), "points")); CertificateDtoForSearching certificateDtoForSearching = ModelUtils.getCertificateDtoForSearching(); List certificates = - Collections.singletonList(ModelUtils.getCertificate()); + Collections.singletonList(ModelUtils.getCertificate()); List certificateDtoForSearchings = - Collections.singletonList(certificateDtoForSearching); + Collections.singletonList(certificateDtoForSearching); PageableDto certificateDtoForSearchingPageableDto = - new PageableDto<>(certificateDtoForSearchings, certificateDtoForSearchings.size(), 0, 1); + new PageableDto<>(certificateDtoForSearchings, certificateDtoForSearchings.size(), 0, 1); Page certificates1 = new PageImpl<>(certificates, pageable, certificates.size()); when(modelMapper.map(certificates.get(0), CertificateDtoForSearching.class)) - .thenReturn(certificateDtoForSearching); + .thenReturn(certificateDtoForSearching); when(certificateRepository.findAll(pageable)).thenReturn(certificates1); PageableDto actual = - ubsManagementService.getAllCertificates(pageable, "points", SortingOrder.DESC); + ubsManagementService.getAllCertificates(pageable, "points", SortingOrder.DESC); assertEquals(certificateDtoForSearchingPageableDto, actual); } @Test void checkOrderNotFound() { assertThrows(NotFoundException.class, - () -> ubsManagementService.getAddressByOrderId(10000000L)); + () -> ubsManagementService.getAddressByOrderId(10000000L)); } @Test @@ -315,7 +315,7 @@ void returnExportDetailsByOrderId() { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); List stations = - Arrays.asList(ReceivingStation.builder().name("a").build(), ReceivingStation.builder().name("b").build()); + Arrays.asList(ReceivingStation.builder().name("a").build(), ReceivingStation.builder().name("b").build()); when(receivingStationRepository.findAll()).thenReturn(stations); assertEquals(expected, ubsManagementService.getOrderExportDetails(1L)); @@ -371,15 +371,15 @@ void saveNewManualPayment(ManualPaymentRequestDto paymentDetails, MultipartFile when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.save(any())) - .thenReturn(payment); + .thenReturn(payment); doNothing().when(eventService).save(OrderHistory.ADD_PAYMENT_MANUALLY + 1, "Петро" + " " + "Петренко", order); ubsManagementService.saveNewManualPayment(1L, paymentDetails, image, "test@gmail.com"); verify(eventService, times(1)) - .save("Додано оплату №1", "Петро Петренко", order); + .save("Додано оплату №1", "Петро Петренко", order); verify(paymentRepository, times(1)).save(any()); verify(orderRepository, times(1)).findById(1L); verify(tariffsInfoRepository).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -387,10 +387,10 @@ void saveNewManualPayment(ManualPaymentRequestDto paymentDetails, MultipartFile private static Stream provideManualPaymentRequestDto() { return Stream.of(Arguments.of(ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021").amount(500L).receiptLink("link").paymentId("1").build(), null), - Arguments.of(ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021").amount(500L).imagePath("path").paymentId("1").build(), - Mockito.mock(MultipartFile.class))); + .settlementdate("02-08-2021").amount(500L).receiptLink("link").paymentId("1").build(), null), + Arguments.of(ManualPaymentRequestDto.builder() + .settlementdate("02-08-2021").amount(500L).imagePath("path").paymentId("1").build(), + Mockito.mock(MultipartFile.class))); } @Test @@ -403,8 +403,8 @@ void checkDeleteManualPayment() { doNothing().when(paymentRepository).deletePaymentById(1L); doNothing().when(fileService).delete(""); doNothing().when(eventService).save(OrderHistory.DELETE_PAYMENT_MANUALLY + getManualPayment().getPaymentId(), - employee.getFirstName() + " " + employee.getLastName(), - getOrder()); + employee.getFirstName() + " " + employee.getLastName(), + getOrder()); ubsManagementService.deleteManualPayment(1L, "abc"); verify(paymentRepository, times(1)).findById(1L); verify(paymentRepository, times(1)).deletePaymentById(1L); @@ -420,8 +420,8 @@ void checkUpdateManualPayment() { when(paymentRepository.save(any())).thenReturn(getManualPayment()); when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(getBaglist()); doNothing().when(eventService).save(OrderHistory.UPDATE_PAYMENT_MANUALLY + 1, - employee.getFirstName() + " " + employee.getLastName(), - getOrder()); + employee.getFirstName() + " " + employee.getLastName(), + getOrder()); ubsManagementService.updateManualPayment(1L, getManualPaymentRequestDto(), null, "abc"); verify(paymentRepository, times(1)).findById(1L); verify(paymentRepository, times(1)).save(any()); @@ -444,20 +444,20 @@ void saveNewManualPaymentWithZeroAmount() { payment.setAmount(0L); order.setPayment(singletonList(payment)); ManualPaymentRequestDto paymentDetails = ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021").amount(0L).receiptLink("link").paymentId("1").build(); + .settlementdate("02-08-2021").amount(0L).receiptLink("link").paymentId("1").build(); Employee employee = getEmployee(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.save(any())) - .thenReturn(payment); + .thenReturn(payment); doNothing().when(eventService).save(any(), any(), any()); ubsManagementService.saveNewManualPayment(1L, paymentDetails, null, "test@gmail.com"); verify(employeeRepository, times(2)).findByEmail(anyString()); verify(eventService, times(1)).save(OrderHistory.ADD_PAYMENT_MANUALLY + 1, - "Петро Петренко", order); + "Петро Петренко", order); verify(paymentRepository, times(1)).save(any()); verify(orderRepository, times(1)).findById(1L); verify(tariffsInfoRepository).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -477,23 +477,23 @@ void saveNewManualPaymentWithHalfPaidAmount() { payment.setAmount(50_00L); order.setPayment(singletonList(payment)); ManualPaymentRequestDto paymentDetails = ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021").amount(50_00L).receiptLink("link").paymentId("1").build(); + .settlementdate("02-08-2021").amount(50_00L).receiptLink("link").paymentId("1").build(); Employee employee = getEmployee(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag1list()); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.save(any())) - .thenReturn(payment); + .thenReturn(payment); doNothing().when(eventService).save(any(), any(), any()); ubsManagementService.saveNewManualPayment(1L, paymentDetails, null, "test@gmail.com"); verify(employeeRepository, times(2)).findByEmail(anyString()); verify(eventService, times(1)).save(OrderHistory.ADD_PAYMENT_MANUALLY + 1, - "Петро Петренко", order); + "Петро Петренко", order); verify(eventService, times(1)) - .save(OrderHistory.ORDER_HALF_PAID, OrderHistory.SYSTEM, order); + .save(OrderHistory.ORDER_HALF_PAID, OrderHistory.SYSTEM, order); verify(paymentRepository, times(1)).save(any()); verify(orderRepository, times(1)).findById(1L); verify(tariffsInfoRepository).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -512,23 +512,23 @@ void saveNewManualPaymentWithPaidAmount() { payment.setAmount(500_00L); order.setPayment(singletonList(payment)); ManualPaymentRequestDto paymentDetails = ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021").amount(500_00L).receiptLink("link").paymentId("1").build(); + .settlementdate("02-08-2021").amount(500_00L).receiptLink("link").paymentId("1").build(); Employee employee = getEmployee(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag1list()); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.save(any())) - .thenReturn(payment); + .thenReturn(payment); doNothing().when(eventService).save(any(), any(), any()); ubsManagementService.saveNewManualPayment(1L, paymentDetails, null, "test@gmail.com"); verify(employeeRepository, times(2)).findByEmail(anyString()); verify(eventService, times(1)).save(OrderHistory.ADD_PAYMENT_MANUALLY + 1, - "Петро Петренко", order); + "Петро Петренко", order); verify(eventService, times(1)) - .save(OrderHistory.ORDER_PAID, OrderHistory.SYSTEM, order); + .save(OrderHistory.ORDER_PAID, OrderHistory.SYSTEM, order); verify(paymentRepository, times(1)).save(any()); verify(orderRepository, times(1)).findById(1L); verify(tariffsInfoRepository).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -545,19 +545,19 @@ void saveNewManualPaymentWithPaidOrder() { order.setOrderPaymentStatus(OrderPaymentStatus.PAID); Payment payment = getManualPayment(); ManualPaymentRequestDto paymentDetails = ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021").amount(500L).receiptLink("link").paymentId("1").build(); + .settlementdate("02-08-2021").amount(500L).receiptLink("link").paymentId("1").build(); Employee employee = getEmployee(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.save(any())) - .thenReturn(payment); + .thenReturn(payment); doNothing().when(eventService).save(OrderHistory.ADD_PAYMENT_MANUALLY + 1, "Петро" + " " + "Петренко", order); ubsManagementService.saveNewManualPayment(1L, paymentDetails, null, "test@gmail.com"); verify(eventService, times(1)) - .save("Додано оплату №1", "Петро Петренко", order); + .save("Додано оплату №1", "Петро Петренко", order); verify(paymentRepository, times(1)).save(any()); verify(orderRepository, times(1)).findById(1L); verify(tariffsInfoRepository).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -574,19 +574,19 @@ void saveNewManualPaymentWithPartiallyPaidOrder() { order.setOrderPaymentStatus(OrderPaymentStatus.HALF_PAID); Payment payment = getManualPayment(); ManualPaymentRequestDto paymentDetails = ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021").amount(200L).receiptLink("link").paymentId("1").build(); + .settlementdate("02-08-2021").amount(200L).receiptLink("link").paymentId("1").build(); Employee employee = getEmployee(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.save(any())) - .thenReturn(payment); + .thenReturn(payment); doNothing().when(eventService).save(OrderHistory.ADD_PAYMENT_MANUALLY + 1, "Петро" + " " + "Петренко", order); ubsManagementService.saveNewManualPayment(1L, paymentDetails, null, "test@gmail.com"); verify(eventService, times(1)) - .save("Додано оплату №1", "Петро Петренко", order); + .save("Додано оплату №1", "Петро Петренко", order); verify(paymentRepository, times(1)).save(any()); verify(orderRepository, times(1)).findById(1L); verify(tariffsInfoRepository).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -603,19 +603,19 @@ void saveNewManualPaymentWithUnpaidOrder() { order.setOrderPaymentStatus(OrderPaymentStatus.UNPAID); Payment payment = getManualPayment(); ManualPaymentRequestDto paymentDetails = ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021").amount(500L).receiptLink("link").paymentId("1").build(); + .settlementdate("02-08-2021").amount(500L).receiptLink("link").paymentId("1").build(); Employee employee = getEmployee(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.save(any())) - .thenReturn(payment); + .thenReturn(payment); doNothing().when(eventService).save(OrderHistory.ADD_PAYMENT_MANUALLY + 1, "Петро" + " " + "Петренко", order); ubsManagementService.saveNewManualPayment(1L, paymentDetails, null, "test@gmail.com"); verify(eventService, times(1)) - .save("Додано оплату №1", "Петро Петренко", order); + .save("Додано оплату №1", "Петро Петренко", order); verify(paymentRepository, times(1)).save(any()); verify(orderRepository, times(1)).findById(1L); verify(tariffsInfoRepository).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -632,19 +632,19 @@ void saveNewManualPaymentWithPaymentRefundedOrder() { order.setOrderPaymentStatus(OrderPaymentStatus.PAYMENT_REFUNDED); Payment payment = getManualPayment(); ManualPaymentRequestDto paymentDetails = ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021").amount(500L).receiptLink("link").paymentId("1").build(); + .settlementdate("02-08-2021").amount(500L).receiptLink("link").paymentId("1").build(); Employee employee = getEmployee(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.save(any())) - .thenReturn(payment); + .thenReturn(payment); doNothing().when(eventService).save(OrderHistory.ADD_PAYMENT_MANUALLY + 1, "Петро" + " " + "Петренко", order); ubsManagementService.saveNewManualPayment(1L, paymentDetails, null, "test@gmail.com"); verify(eventService, times(1)) - .save("Додано оплату №1", "Петро Петренко", order); + .save("Додано оплату №1", "Петро Петренко", order); verify(paymentRepository, times(1)).save(any()); verify(orderRepository, times(1)).findById(1L); verify(tariffsInfoRepository).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -659,12 +659,12 @@ void checkUpdateManualPaymentWithImage() { when(employeeRepository.findByUuid("abc")).thenReturn(Optional.of(employee)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); MockMultipartFile file = new MockMultipartFile("manualPaymentDto", - "", "application/json", "random Bytes".getBytes()); + "", "application/json", "random Bytes".getBytes()); when(paymentRepository.findById(1L)).thenReturn(Optional.of(getManualPayment())); when(paymentRepository.save(any())).thenReturn(getManualPayment()); when(fileService.upload(file)).thenReturn("path"); doNothing().when(eventService).save(OrderHistory.UPDATE_PAYMENT_MANUALLY + 1, "Yuriy" + " " + "Gerasum", - getOrder()); + getOrder()); ubsManagementService.updateManualPayment(1L, getManualPaymentRequestDto(), file, "abc"); verify(paymentRepository, times(1)).findById(1L); verify(paymentRepository, times(1)).save(any()); @@ -678,7 +678,7 @@ void checkManualPaymentNotFound() { ManualPaymentRequestDto manualPaymentRequestDto = getManualPaymentRequestDto(); when(paymentRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsManagementService.updateManualPayment(1L, manualPaymentRequestDto, null, "abc")); + () -> ubsManagementService.updateManualPayment(1L, manualPaymentRequestDto, null, "abc")); verify(paymentRepository, times(1)).findById(1L); } @@ -693,19 +693,19 @@ void checkReturnOverpaymentInfo() { Double sumToPay = 0.; assertEquals("Зарахування на бонусний рахунок", ubsManagementService.returnOverpaymentInfo(1L, sumToPay, 0L) - .getPaymentInfoDtos().get(1).getComment()); + .getPaymentInfoDtos().get(1).getComment()); assertEquals(0L, ubsManagementService.returnOverpaymentInfo(1L, sumToPay, 1L) - .getOverpayment()); + .getOverpayment()); assertEquals(AppConstant.PAYMENT_REFUND, - ubsManagementService.returnOverpaymentInfo(order.getId(), sumToPay, 1L).getPaymentInfoDtos().get(1) - .getComment()); + ubsManagementService.returnOverpaymentInfo(order.getId(), sumToPay, 1L).getPaymentInfoDtos().get(1) + .getComment()); } @Test void checkReturnOverpaymentThroweException() { Assertions.assertThrows(NotFoundException.class, - () -> ubsManagementService.returnOverpaymentInfo(100L, 1., 1L)); + () -> ubsManagementService.returnOverpaymentInfo(100L, 1., 1L)); } @Test @@ -752,7 +752,7 @@ void updateOrderDetailStatusThrowException() { when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrder())); OrderDetailStatusRequestDto requestDto = getTestOrderDetailStatusRequestDto(); assertThrows(NotFoundException.class, - () -> ubsManagementService.updateOrderDetailStatus(1L, requestDto, "uuid")); + () -> ubsManagementService.updateOrderDetailStatus(1L, requestDto, "uuid")); } @Test @@ -776,14 +776,14 @@ void updateOrderDetailStatusFirst() { OrderDetailStatusRequestDto testOrderDetail = getTestOrderDetailStatusRequestDto(); OrderDetailStatusDto expectedObject = ModelUtils.getTestOrderDetailStatusDto(); OrderDetailStatusDto producedObject = ubsManagementService - .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); + .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); assertEquals(expectedObject.getOrderStatus(), producedObject.getOrderStatus()); assertEquals(expectedObject.getPaymentStatus(), producedObject.getPaymentStatus()); assertEquals(expectedObject.getDate(), producedObject.getDate()); testOrderDetail.setOrderStatus(OrderStatus.FORMED.toString()); expectedObject.setOrderStatus(OrderStatus.FORMED.toString()); OrderDetailStatusDto producedObjectAdjustment = ubsManagementService - .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); + .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); assertEquals(expectedObject.getOrderStatus(), producedObjectAdjustment.getOrderStatus()); assertEquals(expectedObject.getPaymentStatus(), producedObjectAdjustment.getPaymentStatus()); @@ -792,7 +792,7 @@ void updateOrderDetailStatusFirst() { testOrderDetail.setOrderStatus(OrderStatus.ADJUSTMENT.toString()); expectedObject.setOrderStatus(OrderStatus.ADJUSTMENT.toString()); OrderDetailStatusDto producedObjectConfirmed = ubsManagementService - .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); + .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); assertEquals(expectedObject.getOrderStatus(), producedObjectConfirmed.getOrderStatus()); assertEquals(expectedObject.getPaymentStatus(), producedObjectConfirmed.getPaymentStatus()); @@ -801,7 +801,7 @@ void updateOrderDetailStatusFirst() { testOrderDetail.setOrderStatus(OrderStatus.CONFIRMED.toString()); expectedObject.setOrderStatus(OrderStatus.CONFIRMED.toString()); OrderDetailStatusDto producedObjectNotTakenOut = ubsManagementService - .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); + .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); assertEquals(expectedObject.getOrderStatus(), producedObjectNotTakenOut.getOrderStatus()); assertEquals(expectedObject.getPaymentStatus(), producedObjectNotTakenOut.getPaymentStatus()); @@ -811,7 +811,7 @@ void updateOrderDetailStatusFirst() { testOrderDetail.setOrderStatus(OrderStatus.CANCELED.toString()); expectedObject.setOrderStatus(OrderStatus.CANCELED.toString()); OrderDetailStatusDto producedObjectCancelled = ubsManagementService - .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); + .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); assertEquals(expectedObject.getOrderStatus(), producedObjectCancelled.getOrderStatus()); assertEquals(expectedObject.getPaymentStatus(), producedObjectCancelled.getPaymentStatus()); @@ -822,7 +822,7 @@ void updateOrderDetailStatusFirst() { testOrderDetail.setOrderStatus(OrderStatus.DONE.toString()); expectedObject.setOrderStatus(OrderStatus.DONE.toString()); OrderDetailStatusDto producedObjectDone = ubsManagementService - .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); + .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); assertEquals(expectedObject.getOrderStatus(), producedObjectDone.getOrderStatus()); assertEquals(expectedObject.getPaymentStatus(), producedObjectDone.getPaymentStatus()); @@ -833,7 +833,7 @@ void updateOrderDetailStatusFirst() { testOrderDetail.setOrderStatus(OrderStatus.CANCELED.toString()); expectedObject.setOrderStatus(OrderStatus.CANCELED.toString()); OrderDetailStatusDto producedObjectCancelled2 = ubsManagementService - .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); + .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); assertEquals(expectedObject.getOrderStatus(), producedObjectCancelled2.getOrderStatus()); assertEquals(expectedObject.getPaymentStatus(), producedObjectCancelled2.getPaymentStatus()); @@ -844,7 +844,7 @@ void updateOrderDetailStatusFirst() { testOrderDetail.setOrderStatus(OrderStatus.BROUGHT_IT_HIMSELF.toString()); expectedObject.setOrderStatus(OrderStatus.BROUGHT_IT_HIMSELF.toString()); OrderDetailStatusDto producedObjectBroughtItHimself = ubsManagementService - .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); + .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); assertEquals(expectedObject.getOrderStatus(), producedObjectBroughtItHimself.getOrderStatus()); assertEquals(expectedObject.getPaymentStatus(), producedObjectBroughtItHimself.getPaymentStatus()); @@ -854,7 +854,7 @@ void updateOrderDetailStatusFirst() { testOrderDetail.setOrderStatus(OrderStatus.CANCELED.toString()); expectedObject.setOrderStatus(OrderStatus.CANCELED.toString()); OrderDetailStatusDto producedObjectCancelled3 = ubsManagementService - .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); + .updateOrderDetailStatus(order.getId(), testOrderDetail, "test@gmail.com"); assertEquals(expectedObject.getOrderStatus(), producedObjectCancelled3.getOrderStatus()); assertEquals(expectedObject.getPaymentStatus(), producedObjectCancelled3.getPaymentStatus()); @@ -862,17 +862,17 @@ void updateOrderDetailStatusFirst() { assertEquals(0, order.getPointsToUse()); verify(eventService, times(1)) - .saveEvent("Статус Замовлення - Узгодження", - "test@gmail.com", order); + .saveEvent("Статус Замовлення - Узгодження", + "test@gmail.com", order); verify(eventService, times(1)) - .saveEvent("Статус Замовлення - Підтверджено", - "test@gmail.com", order); + .saveEvent("Статус Замовлення - Підтверджено", + "test@gmail.com", order); verify(eventService, times(3)) - .saveEvent("Статус Замовлення - Скасовано", - "test@gmail.com", order); + .saveEvent("Статус Замовлення - Скасовано", + "test@gmail.com", order); verify(eventService, times(1)) - .saveEvent("Невикористані бонуси повернено на бонусний рахунок клієнта" + ". Всього " + 700, - "test@gmail.com", order); + .saveEvent("Невикористані бонуси повернено на бонусний рахунок клієнта" + ". Всього " + 700, + "test@gmail.com", order); } @Test @@ -898,7 +898,7 @@ void updateOrderDetailStatusSecond() { testOrderDetail.setOrderStatus(OrderStatus.ON_THE_ROUTE.toString()); expectedObject.setOrderStatus(OrderStatus.ON_THE_ROUTE.toString()); OrderDetailStatusDto producedObjectOnTheRoute = ubsManagementService - .updateOrderDetailStatus(order.getId(), testOrderDetail, "abc"); + .updateOrderDetailStatus(order.getId(), testOrderDetail, "abc"); assertEquals(expectedObject.getOrderStatus(), producedObjectOnTheRoute.getOrderStatus()); assertEquals(expectedObject.getPaymentStatus(), producedObjectOnTheRoute.getPaymentStatus()); @@ -921,7 +921,7 @@ void getAllEmployeesByPosition() { when(orderRepository.findById(anyLong())).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(employeeOrderPositionRepository.findAllByOrderId(anyLong())).thenReturn(newList); when(positionRepository.findAll()).thenReturn(positionList); when(employeeRepository.findAllByEmployeePositionId(anyLong())).thenReturn(employeeList); @@ -943,9 +943,9 @@ void getAllEmployeesByPositionThrowBadRequestException() { when(orderRepository.findById(anyLong())).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); assertThrows(BadRequestException.class, - () -> ubsManagementService.getAllEmployeesByPosition(1L, "test@gmail.com")); + () -> ubsManagementService.getAllEmployeesByPosition(1L, "test@gmail.com")); verify(orderRepository).findById(anyLong()); verify(employeeRepository).findByEmail("test@gmail.com"); verify(tariffsInfoRepository, atLeastOnce()).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -962,7 +962,7 @@ void testUpdateAddress() { when(orderAddressRepository.save(orderAddress)).thenReturn(orderAddress); when(modelMapper.map(orderAddress, OrderAddressDtoResponse.class)).thenReturn(TEST_ORDER_ADDRESS_DTO_RESPONSE); Optional actual = - ubsManagementService.updateAddress(TEST_ORDER_ADDRESS_DTO_UPDATE, 1L, "test@gmail.com"); + ubsManagementService.updateAddress(TEST_ORDER_ADDRESS_DTO_UPDATE, 1L, "test@gmail.com"); assertEquals(Optional.of(TEST_ORDER_ADDRESS_DTO_RESPONSE), actual); verify(orderRepository).findById(1L); verify(orderAddressRepository).save(orderAddress); @@ -975,7 +975,7 @@ void testUpdateAddressThrowsOrderNotFoundException() { when(orderRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsManagementService.updateAddress(TEST_ORDER_ADDRESS_DTO_UPDATE, 1L, "abc")); + () -> ubsManagementService.updateAddress(TEST_ORDER_ADDRESS_DTO_UPDATE, 1L, "abc")); } @Test @@ -983,7 +983,7 @@ void testUpdateAddressThrowsNotFoundOrderAddressException() { when(orderRepository.findById(1L)).thenReturn(Optional.of(ModelUtils.getOrderWithoutAddress())); assertThrows(NotFoundException.class, - () -> ubsManagementService.updateAddress(TEST_ORDER_ADDRESS_DTO_UPDATE, 1L, "abc")); + () -> ubsManagementService.updateAddress(TEST_ORDER_ADDRESS_DTO_UPDATE, 1L, "abc")); } @Test @@ -1006,7 +1006,7 @@ void testGetOrderDetailStatusThrowsUnExistingOrderException() { when(orderRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsManagementService.getOrderDetailStatus(1L)); + () -> ubsManagementService.getOrderDetailStatus(1L)); } @Test @@ -1015,7 +1015,7 @@ void testGetOrderDetailStatusThrowsPaymentNotFoundException() { when(paymentRepository.findAllByOrderId(1)).thenReturn(Collections.emptyList()); assertThrows(NotFoundException.class, - () -> ubsManagementService.getOrderDetailStatus(1L)); + () -> ubsManagementService.getOrderDetailStatus(1L)); } @Test @@ -1055,18 +1055,18 @@ void testGetOrdersBagsDetails() { detailsOrderInfoDtoList.add(getTestDetailsOrderInfoDto()); } assertEquals(detailsOrderInfoDtoList.toString(), - ubsManagementService.getOrderBagsDetails(1L).toString()); + ubsManagementService.getOrderBagsDetails(1L).toString()); } @Test void testGetOrderExportDetailsReceivingStationNotFoundExceptionThrown() { when(orderRepository.findById(1L)) - .thenReturn(Optional.of(getOrder())); + .thenReturn(Optional.of(getOrder())); List receivingStations = new ArrayList<>(); when(receivingStationRepository.findAll()) - .thenReturn(receivingStations); + .thenReturn(receivingStations); assertThrows(NotFoundException.class, - () -> ubsManagementService.getOrderExportDetails(1L)); + () -> ubsManagementService.getOrderExportDetails(1L)); } @Test @@ -1074,7 +1074,7 @@ void testGetOrderDetailsThrowsException() { when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsManagementService.getOrderDetails(1L, "ua")); + () -> ubsManagementService.getOrderDetails(1L, "ua")); } @Test @@ -1098,7 +1098,7 @@ void testAddPointToUserThrowsException() { user.setUuid(null); AddingPointsToUserDto addingPointsToUserDto = - AddingPointsToUserDto.builder().additionalPoints(anyInt()).build(); + AddingPointsToUserDto.builder().additionalPoints(anyInt()).build(); assertThrows(NotFoundException.class, () -> ubsManagementService.addPointsToUser(addingPointsToUserDto)); } @@ -1120,9 +1120,9 @@ void testAddPointsToUser() { void testGetAdditionalBagsInfo() { when(userRepository.findUserByOrderId(1L)).thenReturn(Optional.of(TEST_USER)); when(bagRepository.getAdditionalBagInfo(1L, TEST_USER.getRecipientEmail())) - .thenReturn(TEST_MAP_ADDITIONAL_BAG_LIST); + .thenReturn(TEST_MAP_ADDITIONAL_BAG_LIST); when(objectMapper.convertValue(any(), eq(AdditionalBagInfoDto.class))) - .thenReturn(TEST_ADDITIONAL_BAG_INFO_DTO); + .thenReturn(TEST_ADDITIONAL_BAG_INFO_DTO); List actual = ubsManagementService.getAdditionalBagsInfo(1L); @@ -1138,7 +1138,7 @@ void testGetAdditionalBagsInfoThrowsException() { when(userRepository.findUserByOrderId(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsManagementService.getAdditionalBagsInfo(1L)); + () -> ubsManagementService.getAdditionalBagsInfo(1L)); } @Test @@ -1148,14 +1148,14 @@ void testSetOrderDetail() { doNothing().when(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag1list()); when(paymentRepository.selectSumPaid(1L)).thenReturn(5000L); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); verify(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); @@ -1168,15 +1168,15 @@ void testSetOrderDetailNeedToChangeStatusToHALF_PAID() { doNothing().when(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag1list()); when(paymentRepository.selectSumPaid(1L)).thenReturn(5000L); doNothing().when(orderRepository).updateOrderPaymentStatus(1L, OrderPaymentStatus.HALF_PAID.name()); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); verify(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); @@ -1191,15 +1191,15 @@ void testSetOrderDetailNeedToChangeStatusToUNPAID() { doNothing().when(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag1list()); when(paymentRepository.selectSumPaid(1L)).thenReturn(null); doNothing().when(orderRepository).updateOrderPaymentStatus(1L, OrderPaymentStatus.UNPAID.name()); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); verify(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); @@ -1213,13 +1213,13 @@ void testSetOrderDetailWhenSumPaidIsNull() { doNothing().when(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); when(paymentRepository.selectSumPaid(1L)).thenReturn(null); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); verify(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); @@ -1229,17 +1229,17 @@ void testSetOrderDetailWhenSumPaidIsNull() { void testSetOrderDetailWhenOrderNotFound() { when(orderRepository.findById(1L)).thenReturn(Optional.empty()); Map amountOfBagsConfirmed = UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto() - .getAmountOfBagsConfirmed(); + .getAmountOfBagsConfirmed(); Map amountOfBagsExported = UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto() - .getAmountOfBagsExported(); + .getAmountOfBagsExported(); NotFoundException exception = assertThrows(NotFoundException.class, - () -> ubsManagementService.setOrderDetail( - 1L, - amountOfBagsConfirmed, - amountOfBagsExported, - "abc"), - ORDER_WITH_CURRENT_ID_DOES_NOT_EXIST); + () -> ubsManagementService.setOrderDetail( + 1L, + amountOfBagsConfirmed, + amountOfBagsExported, + "abc"), + ORDER_WITH_CURRENT_ID_DOES_NOT_EXIST); assertEquals(ORDER_WITH_CURRENT_ID_DOES_NOT_EXIST, exception.getMessage()); @@ -1261,8 +1261,8 @@ void testSetOrderDetailIfHalfPaid() { when(orderRepository.findSumOfCertificatesByOrderId(1L)).thenReturn(0L); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); verify(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); verify(orderRepository).updateOrderPaymentStatus(1L, OrderPaymentStatus.UNPAID.name()); @@ -1275,13 +1275,13 @@ void testSetOrderDetailIfPaidAndPriceLessThanDiscount() { when(certificateRepository.findCertificate(order.getId())).thenReturn(List.of(ModelUtils.getCertificate2())); when(orderRepository.findSumOfCertificatesByOrderId(order.getId())).thenReturn(600L); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusFormedDto2())); + .thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusFormedDto2())); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(order.getId(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); verify(certificateRepository).save(ModelUtils.getCertificate2().setPoints(20)); verify(userRepository).updateUserCurrentPoints(1L, 100); @@ -1296,13 +1296,13 @@ void testSetOrderDetailIfPaidAndPriceLessThanPaidSum() { when(certificateRepository.findCertificate(order.getId())).thenReturn(List.of(ModelUtils.getCertificate2())); when(orderRepository.findSumOfCertificatesByOrderId(order.getId())).thenReturn(600L); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusFormedDto2())); + .thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusFormedDto2())); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(order.getId(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); verify(certificateRepository).save(ModelUtils.getCertificate2().setPoints(0)); verify(userRepository).updateUserCurrentPoints(1L, 100); @@ -1315,13 +1315,13 @@ void testSetOrderDetailConfirmed() { when(bagRepository.findCapacityById(1)).thenReturn(1); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), - "test@gmail.com"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), + "test@gmail.com"); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); verify(orderDetailRepository, times(0)).updateExporter(anyInt(), anyLong(), anyLong()); @@ -1332,14 +1332,14 @@ void testSetOrderDetailConfirmed2() { when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusConfirmedDto())); when(bagRepository.findCapacityById(1)).thenReturn(1); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); when(orderDetailRepository.ifRecordExist(any(), any())).thenReturn(1L); when(orderDetailRepository.getAmount(any(), any())).thenReturn(1L); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), - "test@gmail.com"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), + "test@gmail.com"); verify(orderRepository, times(2)).findById(1L); verify(bagRepository, times(2)).findCapacityById(1); verify(bagRepository, times(2)).findById(1); @@ -1356,13 +1356,13 @@ void testSetOrderDetailWithExportedWaste() { doNothing().when(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); when(orderDetailRepository.ifRecordExist(any(), any())).thenReturn(1L); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), - "test@gmail.com"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), + "test@gmail.com"); verify(orderRepository, times(2)).findById(1L); verify(bagRepository, times(2)).findCapacityById(1); verify(bagRepository, times(2)).findById(1); @@ -1377,12 +1377,12 @@ void testSetOrderDetailFormed() { when(bagRepository.findCapacityById(1)).thenReturn(1); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "test@gmail.com"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "test@gmail.com"); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); } @@ -1395,8 +1395,8 @@ void testSetOrderDetailFormedWithBagNoPresent() { when(bagRepository.findById(1)).thenReturn(Optional.empty()); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "test@gmail.com"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "test@gmail.com"); verify(orderDetailRepository, times(0)).updateExporter(anyInt(), anyLong(), anyLong()); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); @@ -1410,14 +1410,14 @@ void testSetOrderDetailNotTakenOut() { doNothing().when(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), - "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), + "abc"); verify(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); @@ -1429,13 +1429,13 @@ void testSetOrderDetailOnTheRoute() { when(bagRepository.findCapacityById(1)).thenReturn(1); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), - "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), + "abc"); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); verify(orderDetailRepository, times(0)).updateExporter(anyInt(), anyLong(), anyLong()); @@ -1448,12 +1448,12 @@ void testSetOrderDetailsDone() { doNothing().when(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), - "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), + "abc"); verify(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); @@ -1462,16 +1462,16 @@ void testSetOrderDetailsDone() { @Test void testSetOrderBroughtItHimself() { when(orderRepository.findById(1L)) - .thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusBROUGHT_IT_HIMSELFDto())); + .thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusBROUGHT_IT_HIMSELFDto())); when(bagRepository.findCapacityById(1)).thenReturn(1); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), - "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), + "abc"); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); verify(orderDetailRepository, times(0)).updateExporter(anyInt(), anyLong(), anyLong()); @@ -1484,13 +1484,13 @@ void testSetOrderDetailsCanseled() { doNothing().when(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(1L, - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), - UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), - "abc"); + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), + UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), + "abc"); verify(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); } @@ -1501,7 +1501,7 @@ void setOrderDetailExceptionTest() { Map exported = UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(); assertThrows(NotFoundException.class, - () -> ubsManagementService.setOrderDetail(1L, confirm, exported, "test@gmail.com")); + () -> ubsManagementService.setOrderDetail(1L, confirm, exported, "test@gmail.com")); } @Test @@ -1510,7 +1510,7 @@ void testSetOrderDetailThrowsUserNotFoundException() { Map exported = UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(); assertThrows(NotFoundException.class, - () -> ubsManagementService.setOrderDetail(1L, confirm, exported, "test@gmail.com")); + () -> ubsManagementService.setOrderDetail(1L, confirm, exported, "test@gmail.com")); } @Test @@ -1522,7 +1522,7 @@ void testSaveAdminToOrder() { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); ubsManagementService.saveAdminCommentToOrder(getAdminCommentDto(), "test@gmail.com"); verify(orderRepository, times(1)).save(order); verify(eventService, times(1)).save(any(), any(), any()); @@ -1541,7 +1541,7 @@ void testUpdateEcoNumberThrowOrderNotFoundException() { EcoNumberDto dto = getEcoNumberDto(); when(orderRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsManagementService.updateEcoNumberForOrder(dto, 1L, "test@gmail.com")); + () -> ubsManagementService.updateEcoNumberForOrder(dto, 1L, "test@gmail.com")); } @Test @@ -1550,7 +1550,7 @@ void updateEcoNumberTrowsException() { EcoNumberDto ecoNumberDto = getEcoNumberDto(); assertThrows(NotFoundException.class, - () -> ubsManagementService.updateEcoNumberForOrder(ecoNumberDto, 1L, "abc")); + () -> ubsManagementService.updateEcoNumberForOrder(ecoNumberDto, 1L, "abc")); } @Test @@ -1560,7 +1560,7 @@ void updateEcoNumberTrowsIncorrectEcoNumberFormatException() { EcoNumberDto ecoNumberDto = getEcoNumberDto(); ecoNumberDto.setEcoNumber(new HashSet<>(List.of("1234a"))); assertThrows(BadRequestException.class, - () -> ubsManagementService.updateEcoNumberForOrder(ecoNumberDto, 1L, "abc")); + () -> ubsManagementService.updateEcoNumberForOrder(ecoNumberDto, 1L, "abc")); } @Test @@ -1568,7 +1568,7 @@ void saveAdminCommentThrowsException() { when(orderRepository.findById(1L)).thenReturn(Optional.empty()); AdminCommentDto adminCommentDto = getAdminCommentDto(); assertThrows(NotFoundException.class, - () -> ubsManagementService.saveAdminCommentToOrder(adminCommentDto, "abc")); + () -> ubsManagementService.saveAdminCommentToOrder(adminCommentDto, "abc")); } @Test @@ -1608,23 +1608,23 @@ void updateOrderAdminPageInfoTest() { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(paymentRepository.findAllByOrderId(1L)) - .thenReturn(List.of(getPayment())); + .thenReturn(List.of(getPayment())); lenient().when(ubsManagementServiceMock.updateOrderDetailStatus(1L, orderDetailStatusRequestDto, "abc")) - .thenReturn(ModelUtils.getTestOrderDetailStatusDto()); + .thenReturn(ModelUtils.getTestOrderDetailStatusDto()); when(ubsClientService.updateUbsUserInfoInOrder(ModelUtils.getUbsCustomersDtoUpdate(), - "test@gmail.com")).thenReturn(ModelUtils.getUbsCustomersDto()); + "test@gmail.com")).thenReturn(ModelUtils.getUbsCustomersDto()); UpdateOrderPageAdminDto updateOrderPageAdminDto = updateOrderPageAdminDto(); updateOrderPageAdminDto.setUserInfoDto(ModelUtils.getUbsCustomersDtoUpdate()); when(orderAddressRepository.findById(1L)) - .thenReturn(Optional.of(getOrderAddress())); + .thenReturn(Optional.of(getOrderAddress())); when(receivingStationRepository.findAll()) - .thenReturn(List.of(getReceivingStation())); + .thenReturn(List.of(getReceivingStation())); var receivingStation = getReceivingStation(); when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.updateOrderAdminPageInfo(updateOrderPageAdminDto, 1L, "en", "test@gmail.com"); @@ -1632,7 +1632,7 @@ void updateOrderAdminPageInfoTest() { ubsManagementService.updateOrderAdminPageInfo(emptyDto, 1L, "en", "test@gmail.com"); verify(ubsClientService, times(1)) - .updateUbsUserInfoInOrder(ModelUtils.getUbsCustomersDtoUpdate(), "test@gmail.com"); + .updateUbsUserInfoInOrder(ModelUtils.getUbsCustomersDtoUpdate(), "test@gmail.com"); verify(tariffsInfoRepository, atLeastOnce()).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); } @@ -1646,25 +1646,25 @@ void updateOrderAdminPageInfoWithUbsCourierSumAndWriteOffStationSum() { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(paymentRepository.findAllByOrderId(1L)) - .thenReturn(List.of(getPayment())); + .thenReturn(List.of(getPayment())); lenient().when(ubsManagementServiceMock.updateOrderDetailStatus(1L, orderDetailStatusRequestDto, "abc")) - .thenReturn(ModelUtils.getTestOrderDetailStatusDto()); + .thenReturn(ModelUtils.getTestOrderDetailStatusDto()); when(ubsClientService.updateUbsUserInfoInOrder(ModelUtils.getUbsCustomersDtoUpdate(), - "test@gmail.com")).thenReturn(ModelUtils.getUbsCustomersDto()); + "test@gmail.com")).thenReturn(ModelUtils.getUbsCustomersDto()); UpdateOrderPageAdminDto updateOrderPageAdminDto = updateOrderPageAdminDto(); updateOrderPageAdminDto.setUserInfoDto(ModelUtils.getUbsCustomersDtoUpdate()); updateOrderPageAdminDto.setUbsCourierSum(50.); updateOrderPageAdminDto.setWriteOffStationSum(100.); when(orderAddressRepository.findById(1L)) - .thenReturn(Optional.of(getOrderAddress())); + .thenReturn(Optional.of(getOrderAddress())); when(receivingStationRepository.findAll()) - .thenReturn(List.of(getReceivingStation())); + .thenReturn(List.of(getReceivingStation())); var receivingStation = getReceivingStation(); when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); when(orderRepository.getOrderDetails(anyLong())) - .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); + .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.updateOrderAdminPageInfo(updateOrderPageAdminDto, 1L, "en", "test@gmail.com"); @@ -1672,7 +1672,7 @@ void updateOrderAdminPageInfoWithUbsCourierSumAndWriteOffStationSum() { ubsManagementService.updateOrderAdminPageInfo(emptyDto, 1L, "en", "test@gmail.com"); verify(ubsClientService, times(1)) - .updateUbsUserInfoInOrder(ModelUtils.getUbsCustomersDtoUpdate(), "test@gmail.com"); + .updateUbsUserInfoInOrder(ModelUtils.getUbsCustomersDtoUpdate(), "test@gmail.com"); verify(tariffsInfoRepository, atLeastOnce()).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); } @@ -1690,7 +1690,7 @@ void updateOrderAdminPageInfoWithStatusFormedTest() { when(orderRepository.save(order)).thenReturn(order); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(paymentRepository.findAllByOrderId(1L)).thenReturn(List.of(getPayment())); when(receivingStationRepository.findAll()).thenReturn(List.of(getReceivingStation())); when(employeeOrderPositionRepository.findAllByOrderId(1L)).thenReturn(List.of(employeeOrderPosition)); @@ -1707,7 +1707,7 @@ void updateOrderAdminPageInfoWithStatusFormedTest() { verify(employeeOrderPositionRepository).deleteAll(List.of(employeeOrderPosition)); verify(tariffsInfoRepository, atLeastOnce()).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); verifyNoMoreInteractions(orderRepository, employeeRepository, paymentRepository, receivingStationRepository, - employeeOrderPositionRepository, tariffsInfoRepository); + employeeOrderPositionRepository, tariffsInfoRepository); } @Test @@ -1721,7 +1721,7 @@ void updateOrderAdminPageInfoWithStatusCanceledTest() { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); IllegalStateException exception = assertThrows(IllegalStateException.class, - () -> ubsManagementService.updateOrderAdminPageInfo(updateOrderPageAdminDto, 1L, "en", "test@gmail.com")); + () -> ubsManagementService.updateOrderAdminPageInfo(updateOrderPageAdminDto, 1L, "en", "test@gmail.com")); assertEquals(String.format(ORDER_CAN_NOT_BE_UPDATED, OrderStatus.CANCELED), exception.getMessage()); @@ -1740,7 +1740,7 @@ void updateOrderAdminPageInfoWithStatusDoneTest() { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); IllegalStateException exception = assertThrows(IllegalStateException.class, - () -> ubsManagementService.updateOrderAdminPageInfo(updateOrderPageAdminDto, 1L, "en", "test@gmail.com")); + () -> ubsManagementService.updateOrderAdminPageInfo(updateOrderPageAdminDto, 1L, "en", "test@gmail.com")); assertEquals(String.format(ORDER_CAN_NOT_BE_UPDATED, OrderStatus.DONE), exception.getMessage()); @@ -1763,13 +1763,13 @@ void updateOrderAdminPageInfoWithStatusBroughtItHimselfTest() { order.setOrderStatus(OrderStatus.BROUGHT_IT_HIMSELF); Employee employee = getEmployee(); UpdateOrderPageAdminDto updateOrderPageAdminDto = - ModelUtils.updateOrderPageAdminDtoWithStatusBroughtItHimself(); + ModelUtils.updateOrderPageAdminDtoWithStatusBroughtItHimself(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(orderRepository.save(order)).thenReturn(order); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(paymentRepository.findAllByOrderId(1L)).thenReturn(List.of(getPayment())); ubsManagementService.updateOrderAdminPageInfo(updateOrderPageAdminDto, 1L, "en", "test@gmail.com"); @@ -1794,13 +1794,13 @@ void updateOrderAdminPageInfoWithNullFieldsTest() { order.setOrderStatus(OrderStatus.ON_THE_ROUTE); Employee employee = getEmployee(); UpdateOrderPageAdminDto updateOrderPageAdminDto = - ModelUtils.updateOrderPageAdminDtoWithNullFields(); + ModelUtils.updateOrderPageAdminDtoWithNullFields(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(orderRepository.save(order)).thenReturn(order); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(paymentRepository.findAllByOrderId(1L)).thenReturn(List.of(getPayment())); when(receivingStationRepository.findAll()).thenReturn(List.of(getReceivingStation())); @@ -1814,7 +1814,7 @@ void updateOrderAdminPageInfoWithNullFieldsTest() { verify(receivingStationRepository).findAll(); verify(tariffsInfoRepository, atLeastOnce()).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); verifyNoMoreInteractions(orderRepository, employeeRepository, paymentRepository, receivingStationRepository, - tariffsInfoRepository); + tariffsInfoRepository); } @Test @@ -1827,10 +1827,10 @@ void updateOrderAdminPageInfoTestThrowsException() { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); assertThrows(BadRequestException.class, - () -> ubsManagementService.updateOrderAdminPageInfo( - updateOrderPageAdminDto, 1L, "en", "test@gmail.com")); + () -> ubsManagementService.updateOrderAdminPageInfo( + updateOrderPageAdminDto, 1L, "en", "test@gmail.com")); verify(orderRepository, atLeastOnce()).findById(1L); verify(employeeRepository).findByEmail("test@gmail.com"); verify(tariffsInfoRepository, atLeastOnce()).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -1840,9 +1840,9 @@ void updateOrderAdminPageInfoTestThrowsException() { void updateOrderAdminPageInfoForOrderWithStatusBroughtItHimselfTest() { UpdateOrderPageAdminDto updateOrderPageAdminDto = updateOrderPageAdminDto(); updateOrderPageAdminDto.setGeneralOrderInfo(OrderDetailStatusRequestDto - .builder() - .orderStatus(String.valueOf(OrderStatus.DONE)) - .build()); + .builder() + .orderStatus(String.valueOf(OrderStatus.DONE)) + .build()); LocalDateTime orderDate = LocalDateTime.now(); TariffsInfo tariffsInfo = getTariffsInfo(); @@ -1859,7 +1859,7 @@ void updateOrderAdminPageInfoForOrderWithStatusBroughtItHimselfTest() { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(paymentRepository.findAllByOrderId(1L)).thenReturn(List.of(getPayment())); ubsManagementService.updateOrderAdminPageInfo(updateOrderPageAdminDto, 1L, "en", "test@gmail.com"); @@ -2013,7 +2013,7 @@ void getOrderStatusDataTest() { when(orderRepository.findById(order.getId())).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); @@ -2022,10 +2022,10 @@ void getOrderStatusDataTest() { when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when(orderStatusTranslationRepository.getOrderStatusTranslationById(6L)) - .thenReturn(Optional.ofNullable(getStatusTranslation())); + .thenReturn(Optional.ofNullable(getStatusTranslation())); when(orderStatusTranslationRepository.findAllBy()).thenReturn(getOrderStatusTranslations()); when( - orderPaymentStatusTranslationRepository.getById(1L)) + orderPaymentStatusTranslationRepository.getById(1L)) .thenReturn(OrderPaymentStatusTranslation.builder().translationValue("name").build()); when(orderPaymentStatusTranslationRepository.getAllBy()).thenReturn(getOrderStatusPaymentTranslations()); when(orderRepository.findById(6L)).thenReturn(Optional.of(order)); @@ -2059,21 +2059,21 @@ void saveNewManualPaymentWhenImageNotNull() { order.setOrderPaymentStatus(OrderPaymentStatus.PAID); Payment payment = getManualPayment(); ManualPaymentRequestDto paymentDetails = ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021").amount(500L).receiptLink("link").paymentId("1").build(); + .settlementdate("02-08-2021").amount(500L).receiptLink("link").paymentId("1").build(); Employee employee = getEmployee(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.save(any())) - .thenReturn(payment); + .thenReturn(payment); doNothing().when(eventService).save(OrderHistory.ADD_PAYMENT_MANUALLY + 1, "Петро" + " " + "Петренко", order); ubsManagementService.saveNewManualPayment(1L, paymentDetails, Mockito.mock(MultipartFile.class), - "test@gmail.com"); + "test@gmail.com"); verify(eventService, times(1)) - .save("Замовлення Оплачено", "Система", order); + .save("Замовлення Оплачено", "Система", order); verify(paymentRepository, times(1)).save(any()); verify(orderRepository, times(1)).findById(1L); verify(tariffsInfoRepository, atLeastOnce()).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -2089,7 +2089,7 @@ void getOrderStatusDataTestEmptyPriceDetails() { when(orderRepository.findById(order.getId())).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); @@ -2097,14 +2097,14 @@ void getOrderStatusDataTestEmptyPriceDetails() { when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when(orderStatusTranslationRepository.getOrderStatusTranslationById(6L)) - .thenReturn(Optional.ofNullable(getStatusTranslation())); + .thenReturn(Optional.ofNullable(getStatusTranslation())); when( - orderPaymentStatusTranslationRepository.getById(1L)) + orderPaymentStatusTranslationRepository.getById(1L)) .thenReturn(OrderPaymentStatusTranslation.builder().translationValue("name").build()); when(orderRepository.findById(6L)).thenReturn(Optional.of(order)); when(receivingStationRepository.findAll()).thenReturn(getReceivingList()); when(modelMapper.map(getOrderForGetOrderStatusData2Test().getPayment().get(0), PaymentInfoDto.class)) - .thenReturn(getInfoPayment()); + .thenReturn(getInfoPayment()); ubsManagementService.getOrderStatusData(1L, "test@gmail.com"); @@ -2132,7 +2132,7 @@ void getOrderStatusDataWithEmptyCertificateTest() { when(orderRepository.findById(order.getId())).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); @@ -2140,9 +2140,9 @@ void getOrderStatusDataWithEmptyCertificateTest() { when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when(orderStatusTranslationRepository.getOrderStatusTranslationById(6L)) - .thenReturn(Optional.ofNullable(getStatusTranslation())); + .thenReturn(Optional.ofNullable(getStatusTranslation())); when( - orderPaymentStatusTranslationRepository.getById(1L)) + orderPaymentStatusTranslationRepository.getById(1L)) .thenReturn(OrderPaymentStatusTranslation.builder().translationValue("name").build()); when(orderRepository.findById(6L)).thenReturn(Optional.of(order)); when(receivingStationRepository.findAll()).thenReturn(getReceivingList()); @@ -2171,7 +2171,7 @@ void getOrderStatusDataWhenOrderTranslationIsNull() { when(orderRepository.findById(order.getId())).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); @@ -2179,7 +2179,7 @@ void getOrderStatusDataWhenOrderTranslationIsNull() { when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when( - orderPaymentStatusTranslationRepository.getById(1L)) + orderPaymentStatusTranslationRepository.getById(1L)) .thenReturn(OrderPaymentStatusTranslation.builder().translationValue("name").build()); when(orderRepository.findById(6L)).thenReturn(Optional.of(order)); when(receivingStationRepository.findAll()).thenReturn(getReceivingList()); @@ -2208,7 +2208,7 @@ void getOrderStatusDataExceptionTest() { when(orderRepository.findById(order.getId())).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(1L)).thenReturn(getCertificateList()); @@ -2216,9 +2216,9 @@ void getOrderStatusDataExceptionTest() { when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when(orderStatusTranslationRepository.getOrderStatusTranslationById(6L)) - .thenReturn(Optional.ofNullable(getStatusTranslation())); + .thenReturn(Optional.ofNullable(getStatusTranslation())); when( - orderPaymentStatusTranslationRepository.getById(1L)) + orderPaymentStatusTranslationRepository.getById(1L)) .thenReturn(OrderPaymentStatusTranslation.builder().translationValue("name").build()); assertThrows(NotFoundException.class, () -> ubsManagementService.getOrderStatusData(1L, "test@gmail.com")); } @@ -2262,7 +2262,7 @@ void updateOrderExportDetailsEmptyDetailsTest() { void updateOrderExportDetailsUserNotFoundExceptionTest() { ExportDetailsDtoUpdate testDetails = getExportDetailsRequest(); assertThrows(NotFoundException.class, - () -> ubsManagementService.updateOrderExportDetails(1L, testDetails, "test@gmail.com")); + () -> ubsManagementService.updateOrderExportDetails(1L, testDetails, "test@gmail.com")); } @Test @@ -2270,7 +2270,7 @@ void updateOrderExportDetailsUnexistingOrderExceptionTest() { ExportDetailsDtoUpdate testDetails = getExportDetailsRequest(); when(orderRepository.findById(anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsManagementService.updateOrderExportDetails(1L, testDetails, "abc")); + () -> ubsManagementService.updateOrderExportDetails(1L, testDetails, "abc")); } @Test @@ -2281,7 +2281,7 @@ void updateOrderExportDetailsReceivingStationNotFoundExceptionTest() { when(orderRepository.findById(anyLong())).thenReturn(Optional.of(order)); when(receivingStationRepository.findAll()).thenReturn(Collections.emptyList()); assertThrows(NotFoundException.class, - () -> ubsManagementService.updateOrderExportDetails(1L, testDetails, "abc")); + () -> ubsManagementService.updateOrderExportDetails(1L, testDetails, "abc")); } @Test @@ -2310,7 +2310,7 @@ void getPaymentInfoWithoutPayment() { void getPaymentInfoExceptionTest() { when(orderRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsManagementService.getPaymentInfo(1L, 100.)); + () -> ubsManagementService.getPaymentInfo(1L, 100.)); } @Test @@ -2322,7 +2322,7 @@ void updateManualPayment() { requestDto.setImagePath(""); payment.setImagePath("abc"); MockMultipartFile file = new MockMultipartFile("manualPaymentDto", - "", "application/json", "random Bytes".getBytes()); + "", "application/json", "random Bytes".getBytes()); when(employeeRepository.findByUuid(employee.getUuid())).thenReturn(Optional.of(employee)); when(paymentRepository.findById(payment.getId())).thenReturn(Optional.of(payment)); @@ -2339,7 +2339,7 @@ void updateManualPayment() { void updateManualPaymentUserNotFoundExceptionTest() { when(employeeRepository.findByUuid(anyString())).thenReturn(Optional.empty()); assertThrows(EntityNotFoundException.class, - () -> ubsManagementService.updateManualPayment(1L, null, null, "abc")); + () -> ubsManagementService.updateManualPayment(1L, null, null, "abc")); } @Test @@ -2347,7 +2347,7 @@ void updateManualPaymentPaymentNotFoundExceptionTest() { when(employeeRepository.findByUuid(anyString())).thenReturn(Optional.of(getEmployee())); when(paymentRepository.findById(anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> ubsManagementService.updateManualPayment(1L, null, null, "abc")); + () -> ubsManagementService.updateManualPayment(1L, null, null, "abc")); } @Test @@ -2356,7 +2356,7 @@ void updateAllOrderAdminPageInfoUnexistingOrderExceptionTest() { UpdateAllOrderPageDto updateAllOrderPageDto = updateAllOrderPageDto(); when(orderRepository.findById(4L)).thenReturn(Optional.ofNullable(order)); assertThrows(NotFoundException.class, - () -> ubsManagementService.updateAllOrderAdminPageInfo(updateAllOrderPageDto, "uuid", "ua")); + () -> ubsManagementService.updateAllOrderAdminPageInfo(updateAllOrderPageDto, "uuid", "ua")); } @Test @@ -2364,7 +2364,7 @@ void updateAllOrderAdminPageInfoUpdateAdminPageInfoExceptionTest() { UpdateAllOrderPageDto updateAllOrderPageDto = updateAllOrderPageDto(); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(Order.builder().build())); assertThrows(BadRequestException.class, - () -> ubsManagementService.updateAllOrderAdminPageInfo(updateAllOrderPageDto, "uuid", "ua")); + () -> ubsManagementService.updateAllOrderAdminPageInfo(updateAllOrderPageDto, "uuid", "ua")); } @Test @@ -2379,49 +2379,49 @@ void updateAllOrderAdminPageInfoStatusConfirmedTest() { UpdateAllOrderPageDto expectedObject = updateAllOrderPageDto(); UpdateAllOrderPageDto actual = updateAllOrderPageDto(); assertEquals(expectedObject.getExportDetailsDto().getDateExport(), - actual.getExportDetailsDto().getDateExport()); + actual.getExportDetailsDto().getDateExport()); ubsManagementService.updateAllOrderAdminPageInfo(expectedObject, "uuid", "ua"); expectedObject = updateAllOrderPageDto(); actual = updateAllOrderPageDto(); assertEquals(expectedObject.getExportDetailsDto().getDateExport(), - actual.getExportDetailsDto().getDateExport()); + actual.getExportDetailsDto().getDateExport()); ubsManagementService.updateAllOrderAdminPageInfo(expectedObject, "uuid", "ua"); expectedObject = updateAllOrderPageDto(); actual = updateAllOrderPageDto(); assertEquals(expectedObject.getExportDetailsDto().getDateExport(), - actual.getExportDetailsDto().getDateExport()); + actual.getExportDetailsDto().getDateExport()); ubsManagementService.updateAllOrderAdminPageInfo(expectedObject, "uuid", "ua"); expectedObject = updateAllOrderPageDto(); actual = updateAllOrderPageDto(); assertEquals(expectedObject.getExportDetailsDto().getDateExport(), - actual.getExportDetailsDto().getDateExport()); + actual.getExportDetailsDto().getDateExport()); ubsManagementService.updateAllOrderAdminPageInfo(expectedObject, "uuid", "ua"); expectedObject = updateAllOrderPageDto(); actual = updateAllOrderPageDto(); assertEquals(expectedObject.getExportDetailsDto().getDateExport(), - actual.getExportDetailsDto().getDateExport()); + actual.getExportDetailsDto().getDateExport()); ubsManagementService.updateAllOrderAdminPageInfo(expectedObject, "uuid", "ua"); expectedObject = updateAllOrderPageDto(); actual = updateAllOrderPageDto(); assertEquals(expectedObject.getExportDetailsDto().getDateExport(), - actual.getExportDetailsDto().getDateExport()); + actual.getExportDetailsDto().getDateExport()); ubsManagementService.updateAllOrderAdminPageInfo(expectedObject, "uuid", "ua"); expectedObject = updateAllOrderPageDto(); actual = updateAllOrderPageDto(); assertEquals(expectedObject.getExportDetailsDto().getDateExport(), - actual.getExportDetailsDto().getDateExport()); + actual.getExportDetailsDto().getDateExport()); ubsManagementService.updateAllOrderAdminPageInfo(expectedObject, "uuid", "ua"); } @@ -2468,7 +2468,7 @@ void saveReasonWhenListElementsAreNotNulls() { when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(order)); ubsManagementService.saveReason(1L, "uu", new MultipartFile[] { - new MockMultipartFile("Name", new byte[2]), new MockMultipartFile("Name", new byte[2])}); + new MockMultipartFile("Name", new byte[2]), new MockMultipartFile("Name", new byte[2])}); verify(orderRepository).findById(1L); } @@ -2484,7 +2484,7 @@ void getOrderStatusDataWithNotEmptyLists() { when(orderRepository.findById(order.getId())).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); @@ -2492,12 +2492,12 @@ void getOrderStatusDataWithNotEmptyLists() { when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when(orderStatusTranslationRepository.getOrderStatusTranslationById(6L)) - .thenReturn(Optional.ofNullable(getStatusTranslation())); + .thenReturn(Optional.ofNullable(getStatusTranslation())); when( - orderPaymentStatusTranslationRepository.getById(1L)) + orderPaymentStatusTranslationRepository.getById(1L)) .thenReturn(OrderPaymentStatusTranslation.builder().translationValue("name").build()); when( - orderPaymentStatusTranslationRepository.getAllBy()) + orderPaymentStatusTranslationRepository.getAllBy()) .thenReturn(List.of(orderPaymentStatusTranslation)); when(orderRepository.findById(6L)).thenReturn(Optional.of(order)); @@ -2512,7 +2512,7 @@ void getOrderStatusDataWithNotEmptyLists() { verify(modelMapper).map(getBaglist().get(0), BagInfoDto.class); verify(orderStatusTranslationRepository).getOrderStatusTranslationById(6L); verify(orderPaymentStatusTranslationRepository).getById( - 1L); + 1L); verify(receivingStationRepository).findAll(); verify(tariffsInfoRepository, atLeastOnce()).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); } @@ -2530,7 +2530,7 @@ void getOrderStatusesTranslationTest() { when(orderRepository.findById(order.getId())).thenReturn(Optional.of(order)); when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); @@ -2538,16 +2538,16 @@ void getOrderStatusesTranslationTest() { when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when(orderStatusTranslationRepository.getOrderStatusTranslationById(6L)) - .thenReturn(Optional.ofNullable(getStatusTranslation())); + .thenReturn(Optional.ofNullable(getStatusTranslation())); when( - orderPaymentStatusTranslationRepository.getById(1L)) + orderPaymentStatusTranslationRepository.getById(1L)) .thenReturn(OrderPaymentStatusTranslation.builder().translationValue("name").build()); when(orderStatusTranslationRepository.findAllBy()) - .thenReturn(list); + .thenReturn(list); when( - orderPaymentStatusTranslationRepository.getAllBy()) + orderPaymentStatusTranslationRepository.getAllBy()) .thenReturn(List.of(orderPaymentStatusTranslation)); when(orderRepository.findById(6L)).thenReturn(Optional.of(order)); @@ -2563,7 +2563,7 @@ void getOrderStatusesTranslationTest() { verify(modelMapper).map(getBaglist().get(0), BagInfoDto.class); verify(orderStatusTranslationRepository).getOrderStatusTranslationById(6L); verify(orderPaymentStatusTranslationRepository).getById( - 1L); + 1L); verify(receivingStationRepository).findAll(); verify(tariffsInfoRepository, atLeastOnce()).findTariffsInfoByIdForEmployee(anyLong(), anyLong()); @@ -2586,7 +2586,7 @@ void deleteManualPaymentTest() { verify(paymentRepository).deletePaymentById(1L); verify(fileService).delete(payment.getImagePath()); verify(eventService).save(OrderHistory.DELETE_PAYMENT_MANUALLY + payment.getPaymentId(), - employee.getFirstName() + " " + employee.getLastName(), payment.getOrder()); + employee.getFirstName() + " " + employee.getLastName(), payment.getOrder()); } @@ -2608,14 +2608,14 @@ void deleteManualTestWithoutImage() { verify(paymentRepository).deletePaymentById(1L); verify(fileService, times(0)).delete(payment.getImagePath()); verify(eventService).save(OrderHistory.DELETE_PAYMENT_MANUALLY + payment.getPaymentId(), - employee.getFirstName() + " " + employee.getLastName(), payment.getOrder()); + employee.getFirstName() + " " + employee.getLastName(), payment.getOrder()); } @Test void deleteManualTestWithoutUser() { when(employeeRepository.findByUuid("uuid25")).thenReturn(Optional.empty()); EntityNotFoundException ex = - assertThrows(EntityNotFoundException.class, () -> ubsManagementService.deleteManualPayment(1L, "uuid25")); + assertThrows(EntityNotFoundException.class, () -> ubsManagementService.deleteManualPayment(1L, "uuid25")); assertEquals(EMPLOYEE_NOT_FOUND, ex.getMessage()); } @@ -2704,7 +2704,7 @@ void addBonusesToUserWithNoOverpaymentTest() { AddBonusesToUserDto addBonusesToUserDto = getAddBonusesToUserDto(); assertThrows(BadRequestException.class, - () -> ubsManagementService.addBonusesToUser(addBonusesToUserDto, 1L, email)); + () -> ubsManagementService.addBonusesToUser(addBonusesToUserDto, 1L, email)); } @Test @@ -2725,8 +2725,8 @@ void checkEmployeeForOrderTest() { void updateOrderStatusToExpected() { ubsManagementService.updateOrderStatusToExpected(); verify(orderRepository).updateOrderStatusToExpected(OrderStatus.CONFIRMED.name(), - OrderStatus.ON_THE_ROUTE.name(), - LocalDate.now()); + OrderStatus.ON_THE_ROUTE.name(), + LocalDate.now()); } @ParameterizedTest @@ -2752,28 +2752,28 @@ private static Stream provideOrdersWithDifferentInitialExportDetailsF orderWithoutDeliverFromTo.setDeliverFrom(null); orderWithoutDeliverFromTo.setDeliverTo(null); String updateExportDetails = String.format(OrderHistory.UPDATE_EXPORT_DATA, - LocalDate.of(1997, 12, 4)) + - String.format(OrderHistory.UPDATE_DELIVERY_TIME, - LocalTime.of(15, 40, 24), LocalTime.of(19, 30, 30)) - + - String.format(OrderHistory.UPDATE_RECEIVING_STATION, "Петрівка"); + LocalDate.of(1997, 12, 4)) + + String.format(OrderHistory.UPDATE_DELIVERY_TIME, + LocalTime.of(15, 40, 24), LocalTime.of(19, 30, 30)) + + + String.format(OrderHistory.UPDATE_RECEIVING_STATION, "Петрівка"); return Stream.of( - Arguments.of(getOrderExportDetailsWithNullValues(), - OrderHistory.SET_EXPORT_DETAILS + updateExportDetails), - Arguments.of(getOrderExportDetailsWithExportDate(), - OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), - Arguments.of(getOrderExportDetailsWithExportDateDeliverFrom(), - OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), - Arguments.of(getOrderExportDetailsWithExportDateDeliverFromTo(), - OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), - Arguments.of(getOrderExportDetails(), - OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), - Arguments.of(getOrderExportDetailsWithDeliverFromTo(), - OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), - Arguments.of(orderWithoutExportDate, - OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), - Arguments.of(orderWithoutDeliverFromTo, - OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails)); + Arguments.of(getOrderExportDetailsWithNullValues(), + OrderHistory.SET_EXPORT_DETAILS + updateExportDetails), + Arguments.of(getOrderExportDetailsWithExportDate(), + OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), + Arguments.of(getOrderExportDetailsWithExportDateDeliverFrom(), + OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), + Arguments.of(getOrderExportDetailsWithExportDateDeliverFromTo(), + OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), + Arguments.of(getOrderExportDetails(), + OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), + Arguments.of(getOrderExportDetailsWithDeliverFromTo(), + OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), + Arguments.of(orderWithoutExportDate, + OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails), + Arguments.of(orderWithoutDeliverFromTo, + OrderHistory.UPDATE_EXPORT_DETAILS + updateExportDetails)); } @Test @@ -2786,10 +2786,10 @@ void updateOrderExportDetailsWhenDeliverFromIsNull() { order.setDeliverFrom(null); testDetails.setTimeDeliveryFrom(null); String expectedHistoryEvent = OrderHistory.UPDATE_EXPORT_DETAILS - + String.format(OrderHistory.UPDATE_EXPORT_DATA, + + String.format(OrderHistory.UPDATE_EXPORT_DATA, LocalDate.of(1997, 12, 4)) - + - String.format(OrderHistory.UPDATE_RECEIVING_STATION, "Петрівка"); + + + String.format(OrderHistory.UPDATE_RECEIVING_STATION, "Петрівка"); when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); when(orderRepository.findById(anyLong())).thenReturn(Optional.of(order)); @@ -2810,10 +2810,10 @@ void updateOrderExportDetailsWhenDeliverToIsNull() { order.setDeliverTo(null); testDetails.setTimeDeliveryTo(null); String expectedHistoryEvent = OrderHistory.UPDATE_EXPORT_DETAILS - + String.format(OrderHistory.UPDATE_EXPORT_DATA, + + String.format(OrderHistory.UPDATE_EXPORT_DATA, LocalDate.of(1997, 12, 4)) - + - String.format(OrderHistory.UPDATE_RECEIVING_STATION, "Петрівка"); + + + String.format(OrderHistory.UPDATE_RECEIVING_STATION, "Петрівка"); when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); when(orderRepository.findById(anyLong())).thenReturn(Optional.of(order)); @@ -2864,9 +2864,9 @@ void getNotTakenOrderReasonWithoutOrderTest() { @Test void saveNewManualPaymentWithoutLinkAndImageTest() { ManualPaymentRequestDto paymentDetails = ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021").amount(500L).paymentId("1").build(); + .settlementdate("02-08-2021").amount(500L).paymentId("1").build(); assertThrows(BadRequestException.class, - () -> ubsManagementService.saveNewManualPayment(1L, paymentDetails, null, "test@gmail.com")); + () -> ubsManagementService.saveNewManualPayment(1L, paymentDetails, null, "test@gmail.com")); } @Test From b6bea9664d2095bca3e89de347f7a2fa43cdc576 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Sun, 23 Jul 2023 15:19:22 +0300 Subject: [PATCH 12/73] Formatted --- .../main/java/greencity/entity/order/Bag.java | 1 - .../greencity/repository/BagRepository.java | 26 ++++--------------- .../service/ubs/SuperAdminServiceImpl.java | 6 ++--- .../service/ubs/UBSClientServiceImpl.java | 6 ++--- .../service/ubs/UBSManagementServiceImpl.java | 2 +- 5 files changed, 12 insertions(+), 29 deletions(-) diff --git a/dao/src/main/java/greencity/entity/order/Bag.java b/dao/src/main/java/greencity/entity/order/Bag.java index 3ab7d2e31..4e357fd7a 100644 --- a/dao/src/main/java/greencity/entity/order/Bag.java +++ b/dao/src/main/java/greencity/entity/order/Bag.java @@ -89,5 +89,4 @@ public class Bag { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(nullable = false) private TariffsInfo tariffsInfo; - } diff --git a/dao/src/main/java/greencity/repository/BagRepository.java b/dao/src/main/java/greencity/repository/BagRepository.java index 10d1e2d7a..18d35c029 100644 --- a/dao/src/main/java/greencity/repository/BagRepository.java +++ b/dao/src/main/java/greencity/repository/BagRepository.java @@ -8,7 +8,6 @@ import java.util.List; import java.util.Map; -import java.util.Optional; @Repository public interface BagRepository extends JpaRepository { @@ -80,26 +79,11 @@ public interface BagRepository extends JpaRepository { List findAllByOrder(@Param("orderId") Long orderId); /** - * method, that returns {@link List} of {@link Bag} by id. + * method, that returns {@link List} of {@link Bag} by tariff id. * - * @param bagId {@link Integer} tariff service id - * @return {@link Optional} of {@link Bag} - * @author Julia Seti + * @param tariffInfoId tariff id {@link Long} + * @return {@link List} of {@link Bag} by tariffInfoId. + * @author Safarov Renat */ - @Query(nativeQuery = true, - value = "SELECT * FROM bag " - + "WHERE id = :bagId") - Optional findActiveBagById(Integer bagId); - - /** - * method, that returns {@link List} of active {@link Bag} by tariff id. - * - * @param tariffInfoId {@link Long} tariff id - * @return {@link List} of {@link Bag} - * @author Julia Seti - */ - @Query(nativeQuery = true, - value = "SELECT * FROM bag " - + "WHERE tariffs_info_id = :tariffInfoId") - List findAllActiveBagsByTariffsInfoId(Long tariffInfoId); + List findBagsByTariffsInfoId(Long tariffInfoId); } \ No newline at end of file diff --git a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java index f1837d95d..56ef4fa7e 100644 --- a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java @@ -141,7 +141,7 @@ private Bag createBag(long tariffId, TariffServiceDto dto, String employeeUuid) @Override public List getTariffService(long tariffId) { if (tariffsInfoRepository.existsById(tariffId)) { - return bagRepository.findAllActiveBagsByTariffsInfoId(tariffId) + return bagRepository.findBagsByTariffsInfoId(tariffId) .stream() .map(it -> modelMapper.map(it, GetTariffServiceDto.class)) .collect(Collectors.toList()); @@ -176,7 +176,7 @@ private void deleteBagFromOrder(Order order, Integer bagId) { private void checkDeletedBagLimitAndUpdateTariffsInfo(Bag bag) { TariffsInfo tariffsInfo = bag.getTariffsInfo(); - List bags = bagRepository.findAllActiveBagsByTariffsInfoId(tariffsInfo.getId()); + List bags = bagRepository.findBagsByTariffsInfoId(tariffsInfo.getId()); if (bags.isEmpty() || bags.stream().noneMatch(Bag::getLimitIncluded)) { tariffsInfo.setTariffStatus(TariffStatus.NEW); tariffsInfo.setBags(bags); @@ -243,7 +243,7 @@ private Long convertBillsIntoCoins(Double bills) { } private Bag tryToFindBagById(Integer id) { - return bagRepository.findActiveBagById(id).orElseThrow( + return bagRepository.findById(id).orElseThrow( () -> new NotFoundException(ErrorMessage.BAG_NOT_FOUND + id)); } diff --git a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java index 638f1c7c2..4f5596003 100644 --- a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java @@ -356,7 +356,7 @@ private boolean isTariffAvailableForCurrentLocation(TariffsInfo tariffsInfo, Loc private UserPointsAndAllBagsDto getUserPointsAndAllBagsDtoByTariffIdAndUserPoints(Long tariffId, Integer userPoints) { - var bagTranslationDtoList = bagRepository.findAllActiveBagsByTariffsInfoId(tariffId).stream() + var bagTranslationDtoList = bagRepository.findBagsByTariffsInfoId(tariffId).stream() .map(bag -> modelMapper.map(bag, BagTranslationDto.class)) .collect(toList()); return new UserPointsAndAllBagsDto(bagTranslationDtoList, userPoints); @@ -460,7 +460,7 @@ private List getBagIds(List dto) { } private Bag tryToGetActiveBagById(Integer id) { - return bagRepository.findActiveBagById(id) + return bagRepository.findById(id) .orElseThrow(() -> new NotFoundException(BAG_NOT_FOUND + id)); } @@ -1229,7 +1229,7 @@ private long formBagsToBeSavedAndCalculateOrderSum( } List orderedBagsIds = bags.stream().map(BagDto::getId).collect(toList()); List notOrderedBags = tariffsInfo.getBags().stream() - .filter(it -> !orderedBagsIds.contains(it.getId())) + .filter(it -> !orderedBagsIds.contains(it.getId())) .map(this::createOrderBag).collect(toList()); notOrderedBags.forEach(it -> it.setAmount(0)); orderBagList.addAll(notOrderedBags); diff --git a/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java index bff797fb4..5864a7320 100644 --- a/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java @@ -366,7 +366,7 @@ public OrderStatusPageDto getOrderStatusData(Long orderId, String email) { checkAvailableOrderForEmployee(order, email); CounterOrderDetailsDto prices = getPriceDetails(orderId); - var bagInfoDtoList = bagRepository.findAllActiveBagsByTariffsInfoId(order.getTariffsInfo().getId()).stream() + var bagInfoDtoList = bagRepository.findBagsByTariffsInfoId(order.getTariffsInfo().getId()).stream() .map(bag -> modelMapper.map(bag, BagInfoDto.class)) .collect(Collectors.toList()); From 2de11a18dc97ff949ee59f9fc88e73f093cad4bb Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Sun, 23 Jul 2023 15:37:35 +0300 Subject: [PATCH 13/73] Returned by maximum to dev --- .../main/java/greencity/entity/order/Bag.java | 4 +- .../service/ubs/OrderBagService.java | 108 ++++++++++++++++++ .../service/ubs/SuperAdminServiceImpl.java | 19 ++- 3 files changed, 119 insertions(+), 12 deletions(-) create mode 100644 service/src/main/java/greencity/service/ubs/OrderBagService.java diff --git a/dao/src/main/java/greencity/entity/order/Bag.java b/dao/src/main/java/greencity/entity/order/Bag.java index 4e357fd7a..2b48e1321 100644 --- a/dao/src/main/java/greencity/entity/order/Bag.java +++ b/dao/src/main/java/greencity/entity/order/Bag.java @@ -2,12 +2,12 @@ import greencity.entity.user.employee.Employee; import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.EqualsAndHashCode; import lombok.ToString; +import lombok.Builder; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/service/src/main/java/greencity/service/ubs/OrderBagService.java b/service/src/main/java/greencity/service/ubs/OrderBagService.java new file mode 100644 index 000000000..fc16956dd --- /dev/null +++ b/service/src/main/java/greencity/service/ubs/OrderBagService.java @@ -0,0 +1,108 @@ +//package greencity.service.ubs; +// +//import greencity.entity.order.Bag; +//import greencity.entity.order.OrderBag; +//import greencity.exceptions.NotFoundException; +//import greencity.repository.OrderBagRepository; +//import greencity.repository.OrderRepository; +//import lombok.AllArgsConstructor; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.stereotype.Service; +// +//import java.util.HashMap; +//import java.util.List; +//import java.util.Map; +//import java.util.stream.Collectors; +// +//import static greencity.constant.ErrorMessage.BAG_NOT_FOUND; +// +//@Service +//@AllArgsConstructor +//@Slf4j +//public class OrderBagService { +// private final OrderBagRepository orderBagRepository; +// private final OrderRepository orderRepository; +// +// private Long getActualPrice(List orderBags, Integer id) { +// return orderBags.stream() +// .filter(ob -> ob.getBag().getId().equals(id)) +// .map(OrderBag::getPrice) +// .findFirst() +// .orElseThrow(() -> new NotFoundException(BAG_NOT_FOUND + id)); +// } +// +// /** +// * Finds all bags belonging to a specific list of OrderBag instances. +// * +// * @param orderBags A list of OrderBag instances to search within. +// * @return A list of Bag instances associated with the provided OrderBag +// * instances. +// */ +// public List findAllBagsInOrderBagsList(List orderBags) { +// return orderBags.stream() +// .map(OrderBag::getBag) +// .map(b -> { +// b.setFullPrice(getActualPrice(orderBags, b.getId())); +// return b; +// }) +// .collect(Collectors.toList()); +// } +// +// /** +// * Finds all bags belonging to a specific OrderBag based on the provided ID. +// * +// * @param id The ID of the OrderBag to search for. +// * @return A list of Bag instances associated with the provided OrderBag ID. +// */ +// public List findBagsByOrderId(Long id) { +// List orderBags = orderBagRepository.findOrderBagsByOrderId(id); +// return findAllBagsInOrderBagsList(orderBags); +// } +// +// /** +// * Calculates the actual bags' amounts for the given list of OrderBags and +// * returns the result as a Map. This method checks the OrderBags in the input +// * list and calculates the actual amount for each bag based on the availability +// * of different quantity attributes in the OrderBag objects. It prioritizes the +// * following quantities in descending order: 1. Exported Quantity: If all +// * OrderBags have the 'exportedQuantity' attribute set, the method will use it. +// * 2. Confirmed Quantity: If 'exportedQuantity' is not available for all +// * OrderBags but 'confirmedQuantity' is, the method will use it. 3. Regular +// * Amount: If neither 'exportedQuantity' nor 'confirmedQuantity' are available +// * for all OrderBags, the method will use the 'amount' attribute. +// * +// * @param bagsForOrder The list of OrderBag objects for which the actual amounts +// * need to be calculated. +// * @return A Map containing the bag ID as the key and the corresponding actual +// * amount as the value. If any OrderBag in the input list lacks all +// * three attributes (exportedQuantity, confirmedQuantity, and amount), +// * the corresponding entry will not be included in the result map. +// * @throws NullPointerException if 'bagsForOrder' is null. +// */ +// public Map getActualBagsAmountForOrder(List bagsForOrder) { +// if (bagsForOrder.stream().allMatch(it -> it.getExportedQuantity() != null)) { +// return bagsForOrder.stream() +// .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getExportedQuantity)); +// } +// if (bagsForOrder.stream().allMatch(it -> it.getConfirmedQuantity() != null)) { +// return bagsForOrder.stream() +// .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getConfirmedQuantity)); +// } +// if (bagsForOrder.stream().allMatch(it -> it.getAmount() != null)) { +// return bagsForOrder.stream() +// .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getAmount)); +// } +// return new HashMap<>(); +// } +// /** +// * method helps to delete bag from order. +// * +// * @param orderBag {@link OrderBag} +// * @author Julia Seti +// */ +// public void removeBagFromOrder(OrderBag orderBag) { +// +////todo +//// orderBag.get.remove(orderBag); +// } +//} diff --git a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java index 56ef4fa7e..3718d2cb3 100644 --- a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java @@ -13,10 +13,10 @@ import greencity.dto.location.AddLocationTranslationDto; import greencity.dto.location.LocationCreateDto; import greencity.dto.location.LocationInfoDto; +import greencity.dto.service.TariffServiceDto; +import greencity.dto.service.ServiceDto; import greencity.dto.service.GetServiceDto; import greencity.dto.service.GetTariffServiceDto; -import greencity.dto.service.ServiceDto; -import greencity.dto.service.TariffServiceDto; import greencity.dto.tariff.AddNewTariffResponseDto; import greencity.dto.tariff.ChangeTariffLocationStatusDto; import greencity.dto.tariff.EditTariffDto; @@ -24,10 +24,10 @@ import greencity.dto.tariff.GetTariffsInfoDto; import greencity.dto.tariff.SetTariffLimitsDto; import greencity.entity.coords.Coordinates; -import greencity.entity.order.Bag; -import greencity.entity.order.Courier; import greencity.entity.order.Order; import greencity.entity.order.OrderBag; +import greencity.entity.order.Bag; +import greencity.entity.order.Courier; import greencity.entity.order.Service; import greencity.entity.order.TariffLocation; import greencity.entity.order.TariffsInfo; @@ -36,9 +36,9 @@ import greencity.entity.user.employee.Employee; import greencity.entity.user.employee.ReceivingStation; import greencity.enums.CourierLimit; +import greencity.enums.OrderPaymentStatus; import greencity.enums.CourierStatus; import greencity.enums.LocationStatus; -import greencity.enums.OrderPaymentStatus; import greencity.enums.StationStatus; import greencity.enums.TariffStatus; import greencity.exceptions.BadRequestException; @@ -51,11 +51,11 @@ import greencity.filters.TariffsInfoSpecification; import greencity.repository.BagRepository; import greencity.repository.CourierRepository; +import greencity.repository.OrderBagRepository; +import greencity.repository.OrderRepository; import greencity.repository.DeactivateChosenEntityRepository; import greencity.repository.EmployeeRepository; import greencity.repository.LocationRepository; -import greencity.repository.OrderBagRepository; -import greencity.repository.OrderRepository; import greencity.repository.ReceivingStationRepository; import greencity.repository.RegionRepository; import greencity.repository.ServiceRepository; @@ -97,9 +97,6 @@ public class SuperAdminServiceImpl implements SuperAdminService { private final ModelMapper modelMapper; private final TariffLocationRepository tariffsLocationRepository; private final DeactivateChosenEntityRepository deactivateTariffsForChosenParamRepository; - private final OrderBagRepository orderBagRepository; - private final OrderRepository orderRepository; - private static final String BAD_SIZE_OF_REGIONS_MESSAGE = "Region ids size should be 1 if several params are selected"; private static final String REGIONS_NOT_EXIST_MESSAGE = "Current region doesn't exist: %s"; @@ -122,6 +119,8 @@ public class SuperAdminServiceImpl implements SuperAdminService { "Current region: %s or cities: %s or receiving stations: %s don't exist."; private static final String REGION_OR_CITIES_OR_RECEIVING_STATIONS_OR_COURIER_NOT_EXIST_MESSAGE = "Current region: %s or cities: %s or receiving stations: %s or courier: %s don't exist."; + private final OrderBagRepository orderBagRepository; + private final OrderRepository orderRepository; @Override public GetTariffServiceDto addTariffService(long tariffId, TariffServiceDto dto, String employeeUuid) { From ec214cfe4d9919984e6536e92d6f969beed9175e Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Sun, 23 Jul 2023 15:57:54 +0300 Subject: [PATCH 14/73] Removed unnesesary methods from entity --- .../java/greencity/entity/order/Order.java | 21 -- .../java/greencity/constant/ErrorMessage.java | 2 +- .../service/ubs/OrderBagService.java | 227 ++++++++++-------- .../service/ubs/SuperAdminServiceImpl.java | 9 +- .../service/ubs/UBSClientServiceImpl.java | 5 +- 5 files changed, 132 insertions(+), 132 deletions(-) diff --git a/dao/src/main/java/greencity/entity/order/Order.java b/dao/src/main/java/greencity/entity/order/Order.java index e7f63d073..af48dfe0b 100644 --- a/dao/src/main/java/greencity/entity/order/Order.java +++ b/dao/src/main/java/greencity/entity/order/Order.java @@ -188,25 +188,4 @@ public class Order { cascade = CascadeType.ALL, orphanRemoval = true) private List orderBags = new ArrayList<>(); - - /** - * method helps to delete bag from order. - * - * @param orderBag {@link OrderBag} - * @author Julia Seti - */ - public void removeBagFromOrder(OrderBag orderBag) { - this.orderBags.remove(orderBag); - } - - /** - * method helps to set bags for order. - * - * @param orderBags {@link List} of {@link OrderBag} - * @author Julia Seti - */ - public void setBagsForOrder(List orderBags) { - orderBags.forEach(it -> it.setOrder(this)); - this.setOrderBags(orderBags); - } } diff --git a/service-api/src/main/java/greencity/constant/ErrorMessage.java b/service-api/src/main/java/greencity/constant/ErrorMessage.java index 5793d2a82..ed4636238 100644 --- a/service-api/src/main/java/greencity/constant/ErrorMessage.java +++ b/service-api/src/main/java/greencity/constant/ErrorMessage.java @@ -163,7 +163,7 @@ public final class ErrorMessage { public static final String INVALID_URL = "Invalid URL: "; public static final String LOCATION_CAN_NOT_BE_DELETED = "Such location cannot be deleted as it is linked to the tariff"; - + public static final String ORDER_NOT_FOUND = "Order not found with id: "; /** * Constructor. */ diff --git a/service/src/main/java/greencity/service/ubs/OrderBagService.java b/service/src/main/java/greencity/service/ubs/OrderBagService.java index fc16956dd..73430a769 100644 --- a/service/src/main/java/greencity/service/ubs/OrderBagService.java +++ b/service/src/main/java/greencity/service/ubs/OrderBagService.java @@ -1,108 +1,123 @@ -//package greencity.service.ubs; -// -//import greencity.entity.order.Bag; -//import greencity.entity.order.OrderBag; -//import greencity.exceptions.NotFoundException; -//import greencity.repository.OrderBagRepository; -//import greencity.repository.OrderRepository; -//import lombok.AllArgsConstructor; -//import lombok.extern.slf4j.Slf4j; -//import org.springframework.stereotype.Service; -// -//import java.util.HashMap; -//import java.util.List; -//import java.util.Map; -//import java.util.stream.Collectors; -// -//import static greencity.constant.ErrorMessage.BAG_NOT_FOUND; -// -//@Service -//@AllArgsConstructor -//@Slf4j -//public class OrderBagService { -// private final OrderBagRepository orderBagRepository; -// private final OrderRepository orderRepository; -// -// private Long getActualPrice(List orderBags, Integer id) { -// return orderBags.stream() -// .filter(ob -> ob.getBag().getId().equals(id)) -// .map(OrderBag::getPrice) -// .findFirst() -// .orElseThrow(() -> new NotFoundException(BAG_NOT_FOUND + id)); -// } -// -// /** -// * Finds all bags belonging to a specific list of OrderBag instances. -// * -// * @param orderBags A list of OrderBag instances to search within. -// * @return A list of Bag instances associated with the provided OrderBag -// * instances. -// */ -// public List findAllBagsInOrderBagsList(List orderBags) { -// return orderBags.stream() -// .map(OrderBag::getBag) -// .map(b -> { -// b.setFullPrice(getActualPrice(orderBags, b.getId())); -// return b; -// }) -// .collect(Collectors.toList()); -// } -// -// /** -// * Finds all bags belonging to a specific OrderBag based on the provided ID. -// * -// * @param id The ID of the OrderBag to search for. -// * @return A list of Bag instances associated with the provided OrderBag ID. -// */ -// public List findBagsByOrderId(Long id) { +package greencity.service.ubs; + +import greencity.constant.ErrorMessage; +import greencity.entity.order.Bag; +import greencity.entity.order.Order; +import greencity.entity.order.OrderBag; +import greencity.exceptions.NotFoundException; +import greencity.repository.OrderBagRepository; +import greencity.repository.OrderRepository; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static greencity.constant.ErrorMessage.BAG_NOT_FOUND; + +@Service +@AllArgsConstructor +@Slf4j +public class OrderBagService { + private final OrderBagRepository orderBagRepository; + private final OrderRepository orderRepository; + + private Long getActualPrice(List orderBags, Integer id) { + return orderBags.stream() + .filter(ob -> ob.getBag().getId().equals(id)) + .map(OrderBag::getPrice) + .findFirst() + .orElseThrow(() -> new NotFoundException(BAG_NOT_FOUND + id)); + } + + /** + * Finds all bags belonging to a specific list of OrderBag instances. + * + * @param orderBags A list of OrderBag instances to search within. + * @return A list of Bag instances associated with the provided OrderBag + * instances. + */ + public List findAllBagsInOrderBagsList(List orderBags) { + return orderBags.stream() + .map(OrderBag::getBag) + .map(b -> { + b.setFullPrice(getActualPrice(orderBags, b.getId())); + return b; + }) + .collect(Collectors.toList()); + } + + /** + * Finds all bags belonging to a specific OrderBag based on the provided ID. + * + * @param id The ID of the OrderBag to search for. + * @return A list of Bag instances associated with the provided OrderBag ID. + */ + public List findBagsByOrderId(Long id) { // List orderBags = orderBagRepository.findOrderBagsByOrderId(id); // return findAllBagsInOrderBagsList(orderBags); -// } -// -// /** -// * Calculates the actual bags' amounts for the given list of OrderBags and -// * returns the result as a Map. This method checks the OrderBags in the input -// * list and calculates the actual amount for each bag based on the availability -// * of different quantity attributes in the OrderBag objects. It prioritizes the -// * following quantities in descending order: 1. Exported Quantity: If all -// * OrderBags have the 'exportedQuantity' attribute set, the method will use it. -// * 2. Confirmed Quantity: If 'exportedQuantity' is not available for all -// * OrderBags but 'confirmedQuantity' is, the method will use it. 3. Regular -// * Amount: If neither 'exportedQuantity' nor 'confirmedQuantity' are available -// * for all OrderBags, the method will use the 'amount' attribute. -// * -// * @param bagsForOrder The list of OrderBag objects for which the actual amounts -// * need to be calculated. -// * @return A Map containing the bag ID as the key and the corresponding actual -// * amount as the value. If any OrderBag in the input list lacks all -// * three attributes (exportedQuantity, confirmedQuantity, and amount), -// * the corresponding entry will not be included in the result map. -// * @throws NullPointerException if 'bagsForOrder' is null. -// */ -// public Map getActualBagsAmountForOrder(List bagsForOrder) { -// if (bagsForOrder.stream().allMatch(it -> it.getExportedQuantity() != null)) { -// return bagsForOrder.stream() -// .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getExportedQuantity)); -// } -// if (bagsForOrder.stream().allMatch(it -> it.getConfirmedQuantity() != null)) { -// return bagsForOrder.stream() -// .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getConfirmedQuantity)); -// } -// if (bagsForOrder.stream().allMatch(it -> it.getAmount() != null)) { -// return bagsForOrder.stream() -// .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getAmount)); -// } -// return new HashMap<>(); -// } -// /** -// * method helps to delete bag from order. -// * -// * @param orderBag {@link OrderBag} -// * @author Julia Seti -// */ -// public void removeBagFromOrder(OrderBag orderBag) { -// -////todo -//// orderBag.get.remove(orderBag); -// } -//} + return null; + } + + /** + * Calculates the actual bags' amounts for the given list of OrderBags and + * returns the result as a Map. This method checks the OrderBags in the input + * list and calculates the actual amount for each bag based on the availability + * of different quantity attributes in the OrderBag objects. It prioritizes the + * following quantities in descending order: 1. Exported Quantity: If all + * OrderBags have the 'exportedQuantity' attribute set, the method will use it. + * 2. Confirmed Quantity: If 'exportedQuantity' is not available for all + * OrderBags but 'confirmedQuantity' is, the method will use it. 3. Regular + * Amount: If neither 'exportedQuantity' nor 'confirmedQuantity' are available + * for all OrderBags, the method will use the 'amount' attribute. + * + * @param bagsForOrder The list of OrderBag objects for which the actual amounts + * need to be calculated. + * @return A Map containing the bag ID as the key and the corresponding actual + * amount as the value. If any OrderBag in the input list lacks all + * three attributes (exportedQuantity, confirmedQuantity, and amount), + * the corresponding entry will not be included in the result map. + * @throws NullPointerException if 'bagsForOrder' is null. + */ + public Map getActualBagsAmountForOrder(List bagsForOrder) { + if (bagsForOrder.stream().allMatch(it -> it.getExportedQuantity() != null)) { + return bagsForOrder.stream() + .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getExportedQuantity)); + } + if (bagsForOrder.stream().allMatch(it -> it.getConfirmedQuantity() != null)) { + return bagsForOrder.stream() + .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getConfirmedQuantity)); + } + if (bagsForOrder.stream().allMatch(it -> it.getAmount() != null)) { + return bagsForOrder.stream() + .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getAmount)); + } + return new HashMap<>(); + } + /** + * method helps to delete bag from order. + * + * @param orderBag {@link OrderBag} + * @author Oksana Spodaryk + */ + public void removeBagFromOrder(Long orderId,OrderBag orderBag) { + Order order= orderRepository.findById(orderId) + .orElseThrow(() -> new NotFoundException(ErrorMessage.ORDER_NOT_FOUND + orderId)); + order.getOrderBags().remove(orderBag); + orderRepository.save(order); + } + + /** + * method helps to set bags for order. + * + * @param orderBags {@link List} of {@link OrderBag} + * @author Oksana Spodaryk + */ + public void setBagsForOrder(Order order,List orderBags) { + orderBags.forEach(it -> it.setOrder(order)); + order.setOrderBags(orderBags); + } +} diff --git a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java index 3718d2cb3..cd610586d 100644 --- a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java @@ -66,6 +66,7 @@ import lombok.Data; import org.apache.commons.collections4.CollectionUtils; import org.modelmapper.ModelMapper; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; @@ -121,7 +122,8 @@ public class SuperAdminServiceImpl implements SuperAdminService { "Current region: %s or cities: %s or receiving stations: %s or courier: %s don't exist."; private final OrderBagRepository orderBagRepository; private final OrderRepository orderRepository; - + @Autowired + private OrderBagService orderBagService; @Override public GetTariffServiceDto addTariffService(long tariffId, TariffServiceDto dto, String employeeUuid) { Bag bag = bagRepository.save(createBag(tariffId, dto, employeeUuid)); @@ -167,8 +169,9 @@ private void deleteBagFromOrder(Order order, Integer bagId) { orderRepository.delete(order); return; } - order.getOrderBags().stream().filter(it -> it.getBag().getId().equals(bagId)).findFirst() - .ifPresent(order::removeBagFromOrder); + order.getOrderBags().stream().filter(it -> it.getBag().getId().equals(bagId)) + .findFirst() + .ifPresent(obj->orderBagService.removeBagFromOrder(order.getId(),obj)); orderRepository.save(order); } } diff --git a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java index 4f5596003..3de5fb772 100644 --- a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java @@ -236,6 +236,8 @@ public class UBSClientServiceImpl implements UBSClientService { @Lazy @Autowired private UBSManagementService ubsManagementService; + @Autowired + private OrderBagService orderBagService; @Value("${greencity.payment.fondy-payment-key}") private String fondyPaymentKey; @Value("${greencity.payment.merchant-id}") @@ -1046,7 +1048,7 @@ private Order formAndSaveOrder(Order order, Set orderCertificates, User currentUser, long sumToPayInCoins) { order.setOrderStatus(OrderStatus.FORMED); order.setCertificates(orderCertificates); - order.setBagsForOrder(bagsOrdered); + orderBagService.setBagsForOrder(order,bagsOrdered); order.setUbsUser(userData); order.setUser(currentUser); order.setSumTotalAmountWithoutDiscounts( @@ -1067,6 +1069,7 @@ private Order formAndSaveOrder(Order order, Set orderCertificates, order.getPayment().add(payment); orderRepository.save(order); + return order; } From 52d73a9b7eb433e5c3b5cb03813a137bb6922913 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Sun, 23 Jul 2023 16:09:47 +0300 Subject: [PATCH 15/73] fixed code --- .../main/java/greencity/entity/order/Bag.java | 2 -- .../repository/OrderBagRepository.java | 10 +++++++ .../notification/NotificationServiceImpl.java | 5 +++- .../service/ubs/OrderBagService.java | 5 ++-- .../service/ubs/UBSClientServiceImpl.java | 3 --- .../service/ubs/UBSManagementServiceImpl.java | 26 +++++-------------- 6 files changed, 23 insertions(+), 28 deletions(-) diff --git a/dao/src/main/java/greencity/entity/order/Bag.java b/dao/src/main/java/greencity/entity/order/Bag.java index 2b48e1321..321739e54 100644 --- a/dao/src/main/java/greencity/entity/order/Bag.java +++ b/dao/src/main/java/greencity/entity/order/Bag.java @@ -11,8 +11,6 @@ import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; diff --git a/dao/src/main/java/greencity/repository/OrderBagRepository.java b/dao/src/main/java/greencity/repository/OrderBagRepository.java index dc69dfe24..4f536296c 100644 --- a/dao/src/main/java/greencity/repository/OrderBagRepository.java +++ b/dao/src/main/java/greencity/repository/OrderBagRepository.java @@ -4,6 +4,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -11,6 +12,15 @@ @Repository public interface OrderBagRepository extends JpaRepository { + /** + * Retrieves a list of order bags based on the given order ID. + * + * @param id the ID of the order + * @return a list of order bags matching the order ID + */ + @Query(value = "SELECT * FROM ORDER_BAG_MAPPING as OBM " + + "where OBM.ORDER_ID = :orderId", nativeQuery = true) + List findOrderBagsByOrderId(@Param("orderId") Long id); /** * method updates the bag data of OrderBag for all unpaid orders. * diff --git a/service/src/main/java/greencity/service/notification/NotificationServiceImpl.java b/service/src/main/java/greencity/service/notification/NotificationServiceImpl.java index 56d7aec6a..293297990 100644 --- a/service/src/main/java/greencity/service/notification/NotificationServiceImpl.java +++ b/service/src/main/java/greencity/service/notification/NotificationServiceImpl.java @@ -20,6 +20,7 @@ import greencity.exceptions.http.AccessDeniedException; import greencity.repository.*; import greencity.service.ubs.NotificationService; +import greencity.service.ubs.OrderBagService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.MapUtils; @@ -75,6 +76,8 @@ public class NotificationServiceImpl implements NotificationService { private static final String ORDER_NUMBER_KEY = "orderNumber"; private static final String AMOUNT_TO_PAY_KEY = "amountToPay"; private static final String PAY_BUTTON = "payButton"; +@Autowired +private final OrderBagService orderBagService; /** * {@inheritDoc} @@ -239,7 +242,7 @@ private Double getAmountToPay(Order order) { long ubsCourierSumInCoins = order.getUbsCourierSum() == null ? 0L : order.getUbsCourierSum(); long writeStationSumInCoins = order.getWriteOffStationSum() == null ? 0L : order.getWriteOffStationSum(); - List bagsType = bagRepository.findBagsByOrderId(order.getId()); + List bagsType = orderBagService.findBagsByOrderId(order.getId()); Map bagsAmount; if (MapUtils.isNotEmpty(order.getExportedQuantity())) { bagsAmount = order.getExportedQuantity(); diff --git a/service/src/main/java/greencity/service/ubs/OrderBagService.java b/service/src/main/java/greencity/service/ubs/OrderBagService.java index 73430a769..8496314e6 100644 --- a/service/src/main/java/greencity/service/ubs/OrderBagService.java +++ b/service/src/main/java/greencity/service/ubs/OrderBagService.java @@ -57,9 +57,8 @@ public List findAllBagsInOrderBagsList(List orderBags) { * @return A list of Bag instances associated with the provided OrderBag ID. */ public List findBagsByOrderId(Long id) { -// List orderBags = orderBagRepository.findOrderBagsByOrderId(id); -// return findAllBagsInOrderBagsList(orderBags); - return null; + List orderBags = orderBagRepository.findOrderBagsByOrderId(id); + return findAllBagsInOrderBagsList(orderBags); } /** diff --git a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java index 3de5fb772..424ae7985 100644 --- a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java @@ -149,8 +149,6 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.LongStream; - -import static greencity.constant.ErrorMessage.*; import static greencity.constant.ErrorMessage.ACTUAL_ADDRESS_NOT_FOUND; import static greencity.constant.ErrorMessage.ADDRESS_ALREADY_EXISTS; import static greencity.constant.ErrorMessage.BAD_ORDER_STATUS_REQUEST; @@ -1069,7 +1067,6 @@ private Order formAndSaveOrder(Order order, Set orderCertificates, order.getPayment().add(payment); orderRepository.save(order); - return order; } diff --git a/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java index 5864a7320..712b75da8 100644 --- a/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java @@ -73,22 +73,7 @@ import greencity.enums.SortingOrder; import greencity.exceptions.BadRequestException; import greencity.exceptions.NotFoundException; -import greencity.repository.BagRepository; -import greencity.repository.CertificateRepository; -import greencity.repository.EmployeeOrderPositionRepository; -import greencity.repository.EmployeeRepository; -import greencity.repository.OrderAddressRepository; -import greencity.repository.OrderDetailRepository; -import greencity.repository.OrderPaymentStatusTranslationRepository; -import greencity.repository.OrderRepository; -import greencity.repository.OrderStatusTranslationRepository; -import greencity.repository.PaymentRepository; -import greencity.repository.PositionRepository; -import greencity.repository.ReceivingStationRepository; -import greencity.repository.RefundRepository; -import greencity.repository.ServiceRepository; -import greencity.repository.TariffsInfoRepository; -import greencity.repository.UserRepository; +import greencity.repository.*; import greencity.service.locations.LocationApiService; import greencity.service.notification.NotificationServiceImpl; import lombok.AllArgsConstructor; @@ -109,7 +94,6 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.server.ResponseStatusException; - import javax.persistence.EntityNotFoundException; import java.math.BigDecimal; import java.math.RoundingMode; @@ -179,6 +163,10 @@ public class UBSManagementServiceImpl implements UBSManagementService { @Lazy @Autowired private UBSClientService ubsClientService; +@Autowired +private final OrderBagService orderBagService; +@Autowired +private OrderBagRepository orderBagRepository; /** * Method gets all order payments, count paid amount, amount which user should @@ -821,7 +809,7 @@ private CounterOrderDetailsDto getPriceDetails(Long id) { CounterOrderDetailsDto dto = new CounterOrderDetailsDto(); Order order = orderRepository.getOrderDetails(id) .orElseThrow(() -> new NotFoundException(ORDER_WITH_CURRENT_ID_DOES_NOT_EXIST + id)); - List bag = bagRepository.findBagsByOrderId(id); + List bag = orderBagService.findAllBagsInOrderBagsList(orderBagRepository.findOrderBagsByOrderId(id)); final List currentCertificate = certificateRepository.findCertificate(id); long sumAmountInCoins = 0; @@ -1060,7 +1048,7 @@ private void setOrderDetailDto(OrderDetailDto dto, Order order) { dto.setAmount(modelMapper.map(order, new TypeToken>() { }.getType())); - dto.setCapacityAndPrice(bagRepository.findBagsByOrderId(order.getId()) + dto.setCapacityAndPrice(orderBagService.findBagsByOrderId(order.getId()) .stream() .map(b -> modelMapper.map(b, BagInfoDto.class)) .collect(Collectors.toList())); From 8869fca597f1135d34d9c738cd60a1c0791a1a09 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Sun, 23 Jul 2023 23:05:20 +0300 Subject: [PATCH 16/73] Added to tariff when delete status DEACTIVATED --- .../greencity/service/ubs/SuperAdminServiceImpl.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java index cd610586d..d61ba5768 100644 --- a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java @@ -124,6 +124,7 @@ public class SuperAdminServiceImpl implements SuperAdminService { private final OrderRepository orderRepository; @Autowired private OrderBagService orderBagService; + @Override public GetTariffServiceDto addTariffService(long tariffId, TariffServiceDto dto, String employeeUuid) { Bag bag = bagRepository.save(createBag(tariffId, dto, employeeUuid)); @@ -155,9 +156,11 @@ public List getTariffService(long tariffId) { @Transactional public void deleteTariffService(Integer bagId) { Bag bag = tryToFindBagById(bagId); - bagRepository.save(bag); checkDeletedBagLimitAndUpdateTariffsInfo(bag); orderRepository.findAllByBagId(bagId).forEach(it -> deleteBagFromOrder(it, bagId)); + TariffsInfo tariffsInfo = bag.getTariffsInfo(); + tariffsInfo.setTariffStatus(TariffStatus.DEACTIVATED); + tariffsInfoRepository.save(tariffsInfo); } private void deleteBagFromOrder(Order order, Integer bagId) { @@ -170,8 +173,8 @@ private void deleteBagFromOrder(Order order, Integer bagId) { return; } order.getOrderBags().stream().filter(it -> it.getBag().getId().equals(bagId)) - .findFirst() - .ifPresent(obj->orderBagService.removeBagFromOrder(order.getId(),obj)); + .findFirst() + .ifPresent(obj -> orderBagService.removeBagFromOrder(order.getId(), obj)); orderRepository.save(order); } } From 363e338b33d7c01234485e044d405bd95b92740e Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Sun, 23 Jul 2023 23:05:33 +0300 Subject: [PATCH 17/73] Formatted --- .../greencity/repository/OrderBagRepository.java | 3 ++- .../main/java/greencity/constant/ErrorMessage.java | 1 + .../notification/NotificationServiceImpl.java | 4 ++-- .../java/greencity/service/ubs/OrderBagService.java | 13 +++++++------ .../greencity/service/ubs/UBSClientServiceImpl.java | 2 +- .../service/ubs/UBSManagementServiceImpl.java | 8 ++++---- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/dao/src/main/java/greencity/repository/OrderBagRepository.java b/dao/src/main/java/greencity/repository/OrderBagRepository.java index 4f536296c..5fa604b23 100644 --- a/dao/src/main/java/greencity/repository/OrderBagRepository.java +++ b/dao/src/main/java/greencity/repository/OrderBagRepository.java @@ -19,8 +19,9 @@ public interface OrderBagRepository extends JpaRepository { * @return a list of order bags matching the order ID */ @Query(value = "SELECT * FROM ORDER_BAG_MAPPING as OBM " - + "where OBM.ORDER_ID = :orderId", nativeQuery = true) + + "where OBM.ORDER_ID = :orderId", nativeQuery = true) List findOrderBagsByOrderId(@Param("orderId") Long id); + /** * method updates the bag data of OrderBag for all unpaid orders. * diff --git a/service-api/src/main/java/greencity/constant/ErrorMessage.java b/service-api/src/main/java/greencity/constant/ErrorMessage.java index ed4636238..06bfd0479 100644 --- a/service-api/src/main/java/greencity/constant/ErrorMessage.java +++ b/service-api/src/main/java/greencity/constant/ErrorMessage.java @@ -164,6 +164,7 @@ public final class ErrorMessage { public static final String LOCATION_CAN_NOT_BE_DELETED = "Such location cannot be deleted as it is linked to the tariff"; public static final String ORDER_NOT_FOUND = "Order not found with id: "; + /** * Constructor. */ diff --git a/service/src/main/java/greencity/service/notification/NotificationServiceImpl.java b/service/src/main/java/greencity/service/notification/NotificationServiceImpl.java index 293297990..e123ce2d3 100644 --- a/service/src/main/java/greencity/service/notification/NotificationServiceImpl.java +++ b/service/src/main/java/greencity/service/notification/NotificationServiceImpl.java @@ -76,8 +76,8 @@ public class NotificationServiceImpl implements NotificationService { private static final String ORDER_NUMBER_KEY = "orderNumber"; private static final String AMOUNT_TO_PAY_KEY = "amountToPay"; private static final String PAY_BUTTON = "payButton"; -@Autowired -private final OrderBagService orderBagService; + @Autowired + private final OrderBagService orderBagService; /** * {@inheritDoc} diff --git a/service/src/main/java/greencity/service/ubs/OrderBagService.java b/service/src/main/java/greencity/service/ubs/OrderBagService.java index 8496314e6..c35d9f05e 100644 --- a/service/src/main/java/greencity/service/ubs/OrderBagService.java +++ b/service/src/main/java/greencity/service/ubs/OrderBagService.java @@ -96,16 +96,17 @@ public Map getActualBagsAmountForOrder(List bagsForO } return new HashMap<>(); } + /** * method helps to delete bag from order. * * @param orderBag {@link OrderBag} * @author Oksana Spodaryk */ - public void removeBagFromOrder(Long orderId,OrderBag orderBag) { - Order order= orderRepository.findById(orderId) - .orElseThrow(() -> new NotFoundException(ErrorMessage.ORDER_NOT_FOUND + orderId)); - order.getOrderBags().remove(orderBag); + public void removeBagFromOrder(Long orderId, OrderBag orderBag) { + Order order = orderRepository.findById(orderId) + .orElseThrow(() -> new NotFoundException(ErrorMessage.ORDER_NOT_FOUND + orderId)); + order.getOrderBags().remove(orderBag); orderRepository.save(order); } @@ -115,8 +116,8 @@ public void removeBagFromOrder(Long orderId,OrderBag orderBag) { * @param orderBags {@link List} of {@link OrderBag} * @author Oksana Spodaryk */ - public void setBagsForOrder(Order order,List orderBags) { - orderBags.forEach(it -> it.setOrder(order)); + public void setBagsForOrder(Order order, List orderBags) { + orderBags.forEach(it -> it.setOrder(order)); order.setOrderBags(orderBags); } } diff --git a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java index 424ae7985..28200390e 100644 --- a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java @@ -1046,7 +1046,7 @@ private Order formAndSaveOrder(Order order, Set orderCertificates, User currentUser, long sumToPayInCoins) { order.setOrderStatus(OrderStatus.FORMED); order.setCertificates(orderCertificates); - orderBagService.setBagsForOrder(order,bagsOrdered); + orderBagService.setBagsForOrder(order, bagsOrdered); order.setUbsUser(userData); order.setUser(currentUser); order.setSumTotalAmountWithoutDiscounts( diff --git a/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java index 712b75da8..853e34342 100644 --- a/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java @@ -163,10 +163,10 @@ public class UBSManagementServiceImpl implements UBSManagementService { @Lazy @Autowired private UBSClientService ubsClientService; -@Autowired -private final OrderBagService orderBagService; -@Autowired -private OrderBagRepository orderBagRepository; + @Autowired + private final OrderBagService orderBagService; + @Autowired + private OrderBagRepository orderBagRepository; /** * Method gets all order payments, count paid amount, amount which user should From ef8beeb2d3d1dff3238f97ef2a6ec4822c1b65a3 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Sun, 23 Jul 2023 23:13:23 +0300 Subject: [PATCH 18/73] Fixed tests --- .../greencity/repository/BagRepository.java | 11 --- .../NotificationServiceImplTest.java | 18 ++-- .../service/ubs/UBSClientServiceImplTest.java | 57 +++++------- .../ubs/UBSManagementServiceImplTest.java | 88 ++++++++----------- 4 files changed, 69 insertions(+), 105 deletions(-) diff --git a/dao/src/main/java/greencity/repository/BagRepository.java b/dao/src/main/java/greencity/repository/BagRepository.java index 18d35c029..270e42790 100644 --- a/dao/src/main/java/greencity/repository/BagRepository.java +++ b/dao/src/main/java/greencity/repository/BagRepository.java @@ -11,17 +11,6 @@ @Repository public interface BagRepository extends JpaRepository { - /** - * method, that returns {@link List}of{@link Bag} that have bags by order id. - * - * @param id order id - * @return {@link List}of{@link Bag} by it's language and orderId. - * @author Mahdziak Orest - */ - @Query(value = "SELECT * FROM ORDER_BAG_MAPPING as OBM " - + "JOIN BAG AS B ON OBM.ORDER_ID = :orderId and OBM.BAG_ID = B.ID " - + "ORDER BY B.ID", nativeQuery = true) - List findBagsByOrderId(@Param("orderId") Long id); /** * This is method which find capacity by id. diff --git a/service/src/test/java/greencity/service/notification/NotificationServiceImplTest.java b/service/src/test/java/greencity/service/notification/NotificationServiceImplTest.java index bebf741f7..93deee5aa 100644 --- a/service/src/test/java/greencity/service/notification/NotificationServiceImplTest.java +++ b/service/src/test/java/greencity/service/notification/NotificationServiceImplTest.java @@ -23,6 +23,7 @@ import greencity.exceptions.NotFoundException; import greencity.exceptions.http.AccessDeniedException; import greencity.repository.*; +import greencity.service.ubs.OrderBagService; import lombok.SneakyThrows; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; @@ -84,7 +85,8 @@ class NotificationServiceImplTest { private Clock fixedClock; ExecutorService mockExecutor = MoreExecutors.newDirectExecutorService(); - +@Mock +private OrderBagService orderBagService; @Nested class ClockNotification { @BeforeEach @@ -301,7 +303,7 @@ void testNotifyInactiveAccounts() { List.of(abstractNotificationProvider), templateRepository, mockExecutor, - internalUrlConfigProp); + internalUrlConfigProp,orderBagService); User user = User.builder().id(42L).build(); User user1 = User.builder().id(43L).build(); UserNotification notification = new UserNotification(); @@ -409,7 +411,7 @@ void testNotifyAllHalfPaidPackages() { parameters.add(NotificationParameter.builder().key("orderNumber") .value(orders.get(0).getId().toString()).build()); - when(bagRepository.findBagsByOrderId(any())).thenReturn(getBag1list()); + when(orderBagService.findBagsByOrderId(any())).thenReturn(getBag1list()); when(userNotificationRepository.save(any())).thenReturn(notification); when(notificationParameterRepository.saveAll(any())).thenReturn(new ArrayList<>(parameters)); @@ -510,7 +512,7 @@ void testNotifyUnpaidOrderForBroughtByHimself() { when(userNotificationRepository.save(any())).thenReturn(notification); when(notificationParameterRepository.saveAll(any())).thenReturn(new ArrayList<>(parameters)); - when(bagRepository.findBagsByOrderId(any())).thenReturn(getBag4list()); + when(orderBagService.findBagsByOrderId(any())).thenReturn(getBag4list()); notificationService.notifyUnpaidOrder(order); @@ -541,7 +543,7 @@ void testNotifyUnpaidOrderForDone() { when(userNotificationRepository.save(any())).thenReturn(notification); when(notificationParameterRepository.saveAll(any())).thenReturn(new ArrayList<>(parameters)); - when(bagRepository.findBagsByOrderId(any())).thenReturn(getBag4list()); + when(orderBagService.findBagsByOrderId(any())).thenReturn(getBag4list()); notificationService.notifyUnpaidOrder(order); verify(userNotificationRepository).save(any()); @@ -572,7 +574,7 @@ void testNotifyUnpaidOrderForCancel() { when(userNotificationRepository.save(any())).thenReturn(notification); when(notificationParameterRepository.saveAll(any())).thenReturn(new ArrayList<>(parameters)); - when(bagRepository.findBagsByOrderId(any())).thenReturn(getBag4list()); + when(orderBagService.findBagsByOrderId(any())).thenReturn(getBag4list()); notificationService.notifyUnpaidOrder(order); @@ -603,7 +605,7 @@ void testNotifyHalfPaidOrderForDone() { when(userNotificationRepository.save(any())).thenReturn(notification); when(notificationParameterRepository.saveAll(any())).thenReturn(new ArrayList<>(parameters)); - when(bagRepository.findBagsByOrderId(any())).thenReturn(getBag4list()); + when(orderBagService.findBagsByOrderId(any())).thenReturn(getBag4list()); notificationService.notifyHalfPaidPackage(order); @@ -630,7 +632,7 @@ void testNotifyHalfPaidOrderForBroughtByHimself() { when(userNotificationRepository.save(any())).thenReturn(notification); when(notificationParameterRepository.saveAll(any())).thenReturn(new ArrayList<>(parameters)); - when(bagRepository.findBagsByOrderId(any())).thenReturn(getBag4list()); + when(orderBagService.findBagsByOrderId(any())).thenReturn(getBag4list()); notificationService.notifyHalfPaidPackage(order); diff --git a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java index c36b12eed..7204e9919 100644 --- a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java @@ -69,25 +69,7 @@ import greencity.exceptions.http.AccessDeniedException; import greencity.exceptions.user.UBSuserNotFoundException; import greencity.exceptions.user.UserNotFoundException; -import greencity.repository.AddressRepository; -import greencity.repository.BagRepository; -import greencity.repository.CertificateRepository; -import greencity.repository.CourierRepository; -import greencity.repository.EmployeeRepository; -import greencity.repository.EventRepository; -import greencity.repository.LocationRepository; -import greencity.repository.OrderAddressRepository; -import greencity.repository.OrderPaymentStatusTranslationRepository; -import greencity.repository.OrderRepository; -import greencity.repository.OrderStatusTranslationRepository; -import greencity.repository.OrdersForUserRepository; -import greencity.repository.PaymentRepository; -import greencity.repository.TariffLocationRepository; -import greencity.repository.TariffsInfoRepository; -import greencity.repository.TelegramBotRepository; -import greencity.repository.UBSuserRepository; -import greencity.repository.UserRepository; -import greencity.repository.ViberBotRepository; +import greencity.repository.*; import greencity.service.google.GoogleApiService; import greencity.service.locations.LocationApiService; import greencity.util.Bot; @@ -316,7 +298,10 @@ class UBSClientServiceImplTest { @Mock private LocationApiService locationApiService; - + @Mock + private OrderBagService orderBagService; + @Mock + private OrderBagRepository orderBagRepository; @Test void testGetAllDistricts() { @@ -2523,7 +2508,7 @@ void processOrderFondyClient() throws Exception { when(encryptionUtil.formRequestSignature(any(), eq(null), eq("1"))).thenReturn("TestValue"); when(fondyClient.getCheckoutResponse(any())).thenReturn(getSuccessfulFondyResponse()); - when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(TEST_BAG_LIST); + when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(TEST_BAG_LIST); when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(certificateDto); when(modelMapper.map(any(Bag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); @@ -2569,7 +2554,7 @@ void processOrderFondyClient2() throws Exception { when(userRepository.findUserByUuid("uuid")).thenReturn(Optional.of(user)); when(certificateRepository.findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), CertificateStatus.ACTIVE)).thenReturn(Set.of(certificate)); - when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(TEST_BAG_LIST); + when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(TEST_BAG_LIST); when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(certificateDto); when(modelMapper.map(any(Bag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); @@ -2579,7 +2564,7 @@ void processOrderFondyClient2() throws Exception { verify(userRepository).findUserByUuid("uuid"); verify(certificateRepository).findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), CertificateStatus.ACTIVE); - verify(bagRepository).findBagsByOrderId(order.getId()); + verify(orderBagService).findBagsByOrderId(order.getId()); verify(modelMapper).map(certificate, CertificateDto.class); verify(modelMapper).map(any(Bag.class), eq(BagForUserDto.class)); } @@ -2619,7 +2604,7 @@ void processOrderFondyClientCertificeteNotFoundExeption() throws Exception { when(userRepository.findUserByUuid("uuid")).thenReturn(Optional.of(user)); when(certificateRepository.findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), CertificateStatus.ACTIVE)).thenReturn(Collections.emptySet()); - when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(TEST_BAG_LIST); + when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(TEST_BAG_LIST); when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(certificateDto); when(modelMapper.map(any(Bag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); @@ -2629,7 +2614,7 @@ void processOrderFondyClientCertificeteNotFoundExeption() throws Exception { verify(userRepository).findUserByUuid("uuid"); verify(certificateRepository).findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), CertificateStatus.ACTIVE); - verify(bagRepository).findBagsByOrderId(order.getId()); + verify(orderBagService).findBagsByOrderId(order.getId()); verify(modelMapper).map(certificate, CertificateDto.class); verify(modelMapper).map(any(Bag.class), eq(BagForUserDto.class)); } @@ -2669,7 +2654,7 @@ void processOrderFondyClientCertificeteNotFoundExeption2() throws Exception { when(userRepository.findUserByUuid("uuid")).thenReturn(Optional.of(user)); when(certificateRepository.findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), CertificateStatus.ACTIVE)).thenReturn(Set.of(certificate)); - when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(TEST_BAG_LIST); + when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(TEST_BAG_LIST); when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(certificateDto); when(modelMapper.map(any(Bag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); @@ -2679,7 +2664,7 @@ void processOrderFondyClientCertificeteNotFoundExeption2() throws Exception { verify(userRepository).findUserByUuid("uuid"); verify(certificateRepository).findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), CertificateStatus.ACTIVE); - verify(bagRepository).findBagsByOrderId(order.getId()); + verify(orderBagService).findBagsByOrderId(order.getId()); verify(modelMapper).map(certificate, CertificateDto.class); verify(modelMapper).map(any(Bag.class), eq(BagForUserDto.class)); } @@ -2717,7 +2702,7 @@ void processOrderFondyClientIfSumToPayLessThanPoints() throws Exception { when(encryptionUtil.formRequestSignature(any(), eq(null), eq("1"))).thenReturn("TestValue"); when(fondyClient.getCheckoutResponse(any())).thenReturn(getSuccessfulFondyResponse()); - when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(TEST_BAG_LIST); + when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(TEST_BAG_LIST); when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(certificateDto); when(modelMapper.map(any(Bag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); @@ -3095,7 +3080,7 @@ void getOrderForUserTest() { when(ordersForUserRepository.getAllByUserUuidAndId(user.getUuid(), order.getId())) .thenReturn(order); - when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(bags); + when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(bags); when(modelMapper.map(bag, BagForUserDto.class)).thenReturn(bagForUserDto); when(orderStatusTranslationRepository .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) @@ -3107,7 +3092,7 @@ void getOrderForUserTest() { ubsService.getOrderForUser(user.getUuid(), 1L); verify(modelMapper, times(bags.size())).map(bag, BagForUserDto.class); - verify(bagRepository).findBagsByOrderId(order.getId()); + verify(orderBagService).findBagsByOrderId(order.getId()); verify(orderStatusTranslationRepository, times(orderList.size())) .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); verify(orderPaymentStatusTranslationRepository, times(orderList.size())) @@ -3153,7 +3138,7 @@ void getOrdersForUserTest() { when(ordersForUserRepository.getAllByUserUuid(pageable, user.getUuid())) .thenReturn(page); - when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(bags); + when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(bags); when(modelMapper.map(bag, BagForUserDto.class)).thenReturn(bagForUserDto); when(orderStatusTranslationRepository .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) @@ -3168,7 +3153,7 @@ void getOrdersForUserTest() { assertEquals(dto.getPage().get(0).getId(), order.getId()); verify(modelMapper, times(bags.size())).map(bag, BagForUserDto.class); - verify(bagRepository).findBagsByOrderId(order.getId()); + verify(orderBagService).findBagsByOrderId(order.getId()); verify(orderStatusTranslationRepository, times(orderList.size())) .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); verify(orderPaymentStatusTranslationRepository, times(orderList.size())) @@ -3202,7 +3187,7 @@ void testOrdersForUserWithExportedQuantity() { when(ordersForUserRepository.getAllByUserUuid(pageable, user.getUuid())) .thenReturn(page); - when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(bags); + when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(bags); when(modelMapper.map(bag, BagForUserDto.class)).thenReturn(bagForUserDto); when(orderStatusTranslationRepository .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) @@ -3217,7 +3202,7 @@ void testOrdersForUserWithExportedQuantity() { assertEquals(dto.getPage().get(0).getId(), order.getId()); verify(modelMapper, times(bags.size())).map(bag, BagForUserDto.class); - verify(bagRepository).findBagsByOrderId(order.getId()); + verify(orderBagService).findBagsByOrderId(order.getId()); verify(orderStatusTranslationRepository, times(orderList.size())) .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); verify(orderPaymentStatusTranslationRepository, times(orderList.size())) @@ -3251,7 +3236,7 @@ void testOrdersForUserWithConfirmedQuantity() { when(ordersForUserRepository.getAllByUserUuid(pageable, user.getUuid())) .thenReturn(page); - when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(bags); + when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(bags); when(modelMapper.map(bag, BagForUserDto.class)).thenReturn(bagForUserDto); when(orderStatusTranslationRepository .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) @@ -3266,7 +3251,7 @@ void testOrdersForUserWithConfirmedQuantity() { assertEquals(dto.getPage().get(0).getId(), order.getId()); verify(modelMapper, times(bags.size())).map(bag, BagForUserDto.class); - verify(bagRepository).findBagsByOrderId(order.getId()); + verify(orderBagService).findBagsByOrderId(order.getId()); verify(orderStatusTranslationRepository, times(orderList.size())) .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); verify(orderPaymentStatusTranslationRepository, times(orderList.size())) diff --git a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java index 208fefea9..3c975eb71 100644 --- a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java @@ -52,22 +52,7 @@ import greencity.enums.SortingOrder; import greencity.exceptions.BadRequestException; import greencity.exceptions.NotFoundException; -import greencity.repository.BagRepository; -import greencity.repository.CertificateRepository; -import greencity.repository.EmployeeOrderPositionRepository; -import greencity.repository.EmployeeRepository; -import greencity.repository.OrderAddressRepository; -import greencity.repository.OrderDetailRepository; -import greencity.repository.OrderPaymentStatusTranslationRepository; -import greencity.repository.OrderRepository; -import greencity.repository.OrderStatusTranslationRepository; -import greencity.repository.PaymentRepository; -import greencity.repository.PositionRepository; -import greencity.repository.ReceivingStationRepository; -import greencity.repository.RefundRepository; -import greencity.repository.ServiceRepository; -import greencity.repository.TariffsInfoRepository; -import greencity.repository.UserRepository; +import greencity.repository.*; import greencity.service.locations.LocationApiService; import greencity.service.notification.NotificationServiceImpl; import org.junit.jupiter.api.Assertions; @@ -267,7 +252,10 @@ class UBSManagementServiceImplTest { @Mock RefundRepository refundRepository; - + @Mock + private OrderBagService orderBagService; + @Mock + private OrderBagRepository orderBagRepository; @Test void getAllCertificates() { Pageable pageable = @@ -418,7 +406,7 @@ void checkUpdateManualPayment() { when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.findById(1L)).thenReturn(Optional.of(getManualPayment())); when(paymentRepository.save(any())).thenReturn(getManualPayment()); - when(bagRepository.findBagsByOrderId(order.getId())).thenReturn(getBaglist()); + when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(getBaglist()); doNothing().when(eventService).save(OrderHistory.UPDATE_PAYMENT_MANUALLY + 1, employee.getFirstName() + " " + employee.getLastName(), getOrder()); @@ -427,7 +415,7 @@ void checkUpdateManualPayment() { verify(paymentRepository, times(1)).save(any()); verify(eventService, times(2)).save(any(), any(), any()); verify(fileService, times(0)).delete(null); - verify(bagRepository).findBagsByOrderId(order.getId()); + verify(orderBagService).findBagsByOrderId(order.getId()); } @Test @@ -483,7 +471,7 @@ void saveNewManualPaymentWithHalfPaidAmount() { when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag1list()); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag1list()); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.save(any())) .thenReturn(payment); @@ -518,7 +506,7 @@ void saveNewManualPaymentWithPaidAmount() { when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag1list()); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag1list()); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.save(any())) .thenReturn(payment); @@ -1023,7 +1011,7 @@ void testGetOrderDetails() { when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(TEST_ORDER)); when(modelMapper.map(TEST_ORDER, new TypeToken>() { }.getType())).thenReturn(TEST_BAG_MAPPING_DTO_LIST); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(TEST_BAG_LIST); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(TEST_BAG_LIST); when(modelMapper.map(TEST_BAG, BagInfoDto.class)).thenReturn(TEST_BAG_INFO_DTO); when(bagRepository.findAllByOrder(1L)).thenReturn(TEST_BAG_LIST); when(modelMapper.map(any(), eq(new TypeToken>() { @@ -1036,7 +1024,7 @@ void testGetOrderDetails() { verify(orderRepository).getOrderDetails(1L); verify(modelMapper).map(TEST_ORDER, new TypeToken>() { }.getType()); - verify(bagRepository).findBagsByOrderId(1L); + verify(orderBagService).findBagsByOrderId(1L); verify(bagRepository, times(1)).findAllByOrder(anyLong()); verify(modelMapper).map(TEST_BAG, BagInfoDto.class); verify(modelMapper).map(any(), eq(new TypeToken>() { @@ -1150,7 +1138,7 @@ void testSetOrderDetail() { when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag1list()); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag1list()); when(paymentRepository.selectSumPaid(1L)).thenReturn(5000L); ubsManagementService.setOrderDetail(1L, @@ -1170,7 +1158,7 @@ void testSetOrderDetailNeedToChangeStatusToHALF_PAID() { when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag1list()); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag1list()); when(paymentRepository.selectSumPaid(1L)).thenReturn(5000L); doNothing().when(orderRepository).updateOrderPaymentStatus(1L, OrderPaymentStatus.HALF_PAID.name()); @@ -1193,7 +1181,7 @@ void testSetOrderDetailNeedToChangeStatusToUNPAID() { when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag1list()); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag1list()); when(paymentRepository.selectSumPaid(1L)).thenReturn(null); doNothing().when(orderRepository).updateOrderPaymentStatus(1L, OrderPaymentStatus.UNPAID.name()); @@ -1256,7 +1244,7 @@ void testSetOrderDetailIfHalfPaid() { when(bagRepository.findCapacityById(1)).thenReturn(1); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.ofNullable(orderDetailDto)); when(bagRepository.findById(1)).thenReturn(Optional.ofNullable(tariffBagDto)); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(bagList); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(bagList); when(paymentRepository.selectSumPaid(1L)).thenReturn(0L); when(orderRepository.findSumOfCertificatesByOrderId(1L)).thenReturn(0L); @@ -1276,7 +1264,7 @@ void testSetOrderDetailIfPaidAndPriceLessThanDiscount() { when(orderRepository.findSumOfCertificatesByOrderId(order.getId())).thenReturn(600L); when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusFormedDto2())); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(order.getId(), @@ -1297,7 +1285,7 @@ void testSetOrderDetailIfPaidAndPriceLessThanPaidSum() { when(orderRepository.findSumOfCertificatesByOrderId(order.getId())).thenReturn(600L); when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusFormedDto2())); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(order.getId(), @@ -1930,7 +1918,7 @@ void getOrderSumDetailsForCanceledPaidOrderWithBags() { Order order = ModelUtils.getCanceledPaidOrder(); order.setOrderDate(LocalDateTime.now()); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag3list()); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag3list()); doNothing().when(notificationService).notifyPaidOrder(order); doNothing().when(notificationService).notifyHalfPaidPackage(order); @@ -1959,7 +1947,7 @@ void getOrderSumDetailsForFormedHalfPaidOrder() { Order order = ModelUtils.getFormedHalfPaidOrder(); order.setOrderDate(LocalDateTime.now()); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); doNothing().when(notificationService).notifyPaidOrder(order); doNothing().when(notificationService).notifyHalfPaidPackage(order); @@ -1974,7 +1962,7 @@ void getOrderSumDetailsForFormedHalfPaidOrderWithDiffBags() { Order order = ModelUtils.getFormedHalfPaidOrder(); order.setOrderDate(LocalDateTime.now()); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag3list()); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag3list()); doNothing().when(notificationService).notifyPaidOrder(order); doNothing().when(notificationService).notifyHalfPaidPackage(order); @@ -1989,7 +1977,7 @@ void getOrderSumDetailsForCanceledHalfPaidOrder() { Order order = ModelUtils.getCanceledHalfPaidOrder(); order.setOrderDate(LocalDateTime.now()); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); doNothing().when(notificationService).notifyPaidOrder(order); doNothing().when(notificationService).notifyHalfPaidPackage(order); @@ -2015,7 +2003,7 @@ void getOrderStatusDataTest() { when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(1L)).thenReturn(getCertificateList()); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); @@ -2034,7 +2022,7 @@ void getOrderStatusDataTest() { ubsManagementService.getOrderStatusData(1L, "test@gmail.com"); verify(orderRepository).getOrderDetails(1L); - verify(bagRepository).findBagsByOrderId(1L); + verify(orderBagService).findBagsByOrderId(1L); verify(bagRepository).findBagsByTariffsInfoId(1L); verify(certificateRepository).findCertificate(1L); verify(orderRepository, times(5)).findById(1L); @@ -2093,7 +2081,7 @@ void getOrderStatusDataTestEmptyPriceDetails() { when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag2list()); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag2list()); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when(orderStatusTranslationRepository.getOrderStatusTranslationById(6L)) @@ -2109,7 +2097,7 @@ void getOrderStatusDataTestEmptyPriceDetails() { ubsManagementService.getOrderStatusData(1L, "test@gmail.com"); verify(orderRepository).getOrderDetails(1L); - verify(bagRepository).findBagsByOrderId(1L); + verify(orderBagService).findBagsByOrderId(1L); verify(bagRepository).findBagsByTariffsInfoId(1L); verify(certificateRepository).findCertificate(1L); verify(orderRepository, times(5)).findById(1L); @@ -2134,7 +2122,7 @@ void getOrderStatusDataWithEmptyCertificateTest() { when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); @@ -2150,7 +2138,7 @@ void getOrderStatusDataWithEmptyCertificateTest() { ubsManagementService.getOrderStatusData(1L, "test@gmail.com"); verify(orderRepository).getOrderDetails(1L); - verify(bagRepository).findBagsByOrderId(1L); + verify(orderBagService).findBagsByOrderId(1L); verify(bagRepository).findBagsByTariffsInfoId(1L); verify(orderRepository, times(5)).findById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); @@ -2173,7 +2161,7 @@ void getOrderStatusDataWhenOrderTranslationIsNull() { when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); @@ -2187,7 +2175,7 @@ void getOrderStatusDataWhenOrderTranslationIsNull() { ubsManagementService.getOrderStatusData(1L, "test@gmail.com"); verify(orderRepository).getOrderDetails(1L); - verify(bagRepository).findBagsByOrderId(1L); + verify(orderBagService).findBagsByOrderId(1L); verify(bagRepository).findBagsByTariffsInfoId(1L); verify(orderRepository, times(5)).findById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); @@ -2210,7 +2198,7 @@ void getOrderStatusDataExceptionTest() { when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(1L)).thenReturn(getCertificateList()); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); @@ -2487,7 +2475,7 @@ void getOrderStatusDataWithNotEmptyLists() { .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(1L)).thenReturn(getCertificateList()); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); @@ -2506,7 +2494,7 @@ void getOrderStatusDataWithNotEmptyLists() { verify(orderRepository).getOrderDetails(1L); verify(bagRepository).findBagsByTariffsInfoId(1L); - verify(bagRepository).findBagsByOrderId(1L); + verify(orderBagService).findBagsByOrderId(1L); verify(certificateRepository).findCertificate(1L); verify(orderRepository, times(5)).findById(1L); verify(modelMapper).map(getBaglist().get(0), BagInfoDto.class); @@ -2532,7 +2520,7 @@ void getOrderStatusesTranslationTest() { when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(1L)).thenReturn(getCertificateList()); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); @@ -2556,7 +2544,7 @@ void getOrderStatusesTranslationTest() { ubsManagementService.getOrderStatusData(1L, "test@gmail.com"); verify(orderRepository).getOrderDetails(1L); - verify(bagRepository).findBagsByOrderId(1L); + verify(orderBagService).findBagsByOrderId(1L); verify(bagRepository).findBagsByTariffsInfoId(1L); verify(certificateRepository).findCertificate(1L); verify(orderRepository, times(5)).findById(1L); @@ -2634,7 +2622,7 @@ void addBonusesToUserTest() { Employee employee = getEmployee(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(order.getId())).thenReturn(getCertificateList()); ubsManagementService.addBonusesToUser(getAddBonusesToUserDto(), 1L, employee.getEmail()); @@ -2654,7 +2642,7 @@ void addBonusesToUserIfOrderStatusIsCanceled() { Employee employee = getEmployee(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(order.getId())).thenReturn(getCertificateList()); ubsManagementService.addBonusesToUser(getAddBonusesToUserDto(), 1L, employee.getEmail()); @@ -2673,7 +2661,7 @@ void addBonusesToUserWithoutExportedBagsTest() { Employee employee = getEmployee(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBaglist()); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(order.getId())).thenReturn(getCertificateList()); ubsManagementService.addBonusesToUser(getAddBonusesToUserDto(), 1L, employee.getEmail()); @@ -2699,7 +2687,7 @@ void addBonusesToUserWithNoOverpaymentTest() { String email = getEmployee().getEmail(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(bagRepository.findBagsByOrderId(1L)).thenReturn(getBag3list()); + when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag3list()); when(certificateRepository.findCertificate(order.getId())).thenReturn(getCertificateList()); AddBonusesToUserDto addBonusesToUserDto = getAddBonusesToUserDto(); From b541d815146d5c46d399ba146f62f4558800fb98 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 24 Jul 2023 00:06:21 +0300 Subject: [PATCH 19/73] Unworking only 1 test in SuperAdminServiceImpl --- .../service/ubs/SuperAdminServiceImpl.java | 18 +- .../src/test/java/greencity/ModelUtils.java | 6159 +++++++++-------- .../ubs/SuperAdminServiceImplTest.java | 880 ++- 3 files changed, 3619 insertions(+), 3438 deletions(-) diff --git a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java index d61ba5768..e397ec0da 100644 --- a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java @@ -156,11 +156,8 @@ public List getTariffService(long tariffId) { @Transactional public void deleteTariffService(Integer bagId) { Bag bag = tryToFindBagById(bagId); - checkDeletedBagLimitAndUpdateTariffsInfo(bag); + checkDeletedBagLimitAndDeleteTariffsInfo(bag); orderRepository.findAllByBagId(bagId).forEach(it -> deleteBagFromOrder(it, bagId)); - TariffsInfo tariffsInfo = bag.getTariffsInfo(); - tariffsInfo.setTariffStatus(TariffStatus.DEACTIVATED); - tariffsInfoRepository.save(tariffsInfo); } private void deleteBagFromOrder(Order order, Integer bagId) { @@ -193,6 +190,19 @@ private void checkDeletedBagLimitAndUpdateTariffsInfo(Bag bag) { } } + private void checkDeletedBagLimitAndDeleteTariffsInfo(Bag bag) { + TariffsInfo tariffsInfo = bag.getTariffsInfo(); + List bags = bagRepository.findBagsByTariffsInfoId(tariffsInfo.getId()); + if (bags.isEmpty() || bags.stream().noneMatch(Bag::getLimitIncluded)) { + tariffsInfo.setTariffStatus(TariffStatus.DEACTIVATED); + tariffsInfo.setBags(bags); + tariffsInfo.setMax(null); + tariffsInfo.setMin(null); + tariffsInfo.setLimitDescription(null); + tariffsInfo.setCourierLimit(CourierLimit.LIMIT_BY_SUM_OF_ORDER); + tariffsInfoRepository.save(tariffsInfo); + } + } @Override @Transactional public GetTariffServiceDto editTariffService(TariffServiceDto dto, Integer bagId, String employeeUuid) { diff --git a/service/src/test/java/greencity/ModelUtils.java b/service/src/test/java/greencity/ModelUtils.java index 32d7fb7eb..e2634af0b 100644 --- a/service/src/test/java/greencity/ModelUtils.java +++ b/service/src/test/java/greencity/ModelUtils.java @@ -140,7 +140,6 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; - import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; @@ -156,7 +155,6 @@ import java.util.Map; import java.util.Optional; import java.util.Set; - import static greencity.enums.NotificationReceiverType.EMAIL; import static greencity.enums.NotificationReceiverType.MOBILE; import static greencity.enums.NotificationReceiverType.SITE; @@ -174,7 +172,7 @@ public class ModelUtils { public static final Order TEST_ORDER = createOrder(); public static final OrderAddressDtoResponse TEST_ORDER_ADDRESS_DTO_RESPONSE = createOrderAddressDtoResponse(); public static final OrderAddressExportDetailsDtoUpdate TEST_ORDER_ADDRESS_DTO_UPDATE = - createOrderAddressDtoUpdate(); + createOrderAddressDtoUpdate(); public static final List TEST_PAYMENT_LIST = createPaymentList(); public static final OrderDetailStatusDto ORDER_DETAIL_STATUS_DTO = createOrderDetailStatusDto(); public static final List TEST_BAG_MAPPING_DTO_LIST = createBagMappingDtoList(); @@ -184,7 +182,7 @@ public class ModelUtils { public static final BagInfoDto TEST_BAG_INFO_DTO = createBagInfoDto(); public static final List TEST_BAG_LIST = singletonList(TEST_BAG); public static final List TEST_ORDER_DETAILS_INFO_DTO_LIST = - singletonList(createOrderDetailInfoDto()); + singletonList(createOrderDetailInfoDto()); public static final OrderAddressDtoRequest TEST_ORDER_ADDRESS_DTO_REQUEST = createOrderDtoRequest(); public static final Order TEST_ORDER_2 = createTestOrder2(); public static final Order TEST_ORDER_3 = createTestOrder3(); @@ -203,80 +201,84 @@ public class ModelUtils { public static final NotificationTemplateDto TEST_NOTIFICATION_TEMPLATE_DTO = createNotificationTemplateDto(); public static final NotificationTemplateWithPlatformsUpdateDto TEST_NOTIFICATION_TEMPLATE_UPDATE_DTO = - createNotificationTemplateWithPlatformsUpdateDto(); + createNotificationTemplateWithPlatformsUpdateDto(); public static final NotificationTemplateWithPlatformsDto TEST_NOTIFICATION_TEMPLATE_WITH_PLATFORMS_DTO = - createNotificationTemplateWithPlatformsDto(); + createNotificationTemplateWithPlatformsDto(); public static final Pageable TEST_PAGEABLE = PageRequest.of(0, 5, Sort.by("notificationTime").descending()); public static final Pageable TEST_NOTIFICATION_PAGEABLE = PageRequest.of(0, 5, Sort.by("id").descending()); public static final NotificationShortDto TEST_NOTIFICATION_SHORT_DTO = createNotificationShortDto(); public static final List TEST_NOTIFICATION_SHORT_DTO_LIST = - List.of(TEST_NOTIFICATION_SHORT_DTO); + List.of(TEST_NOTIFICATION_SHORT_DTO); public static final PageableDto TEST_DTO = createPageableDto(); public static final Employee TEST_EMPLOYEE = createEmployee(); public static final User TEST_USER = createUser(); public static final List TEST_USER_NOTIFICATION_LIST = createUserNotificationList(); public static final Page TEST_PAGE = - new PageImpl<>(TEST_USER_NOTIFICATION_LIST, TEST_PAGEABLE, TEST_USER_NOTIFICATION_LIST.size()); + new PageImpl<>(TEST_USER_NOTIFICATION_LIST, TEST_PAGEABLE, TEST_USER_NOTIFICATION_LIST.size()); public static final Page TEMPLATE_PAGE = - new PageImpl<>(List.of(TEST_NOTIFICATION_TEMPLATE), TEST_PAGEABLE, 1L); + new PageImpl<>(List.of(TEST_NOTIFICATION_TEMPLATE), TEST_PAGEABLE, 1L); public static final AdditionalBagInfoDto TEST_ADDITIONAL_BAG_INFO_DTO = createAdditionalBagInfoDto(); public static final List TEST_ADDITIONAL_BAG_INFO_DTO_LIST = createAdditionalBagInfoDtoList(); public static final Map TEST_MAP_ADDITIONAL_BAG = createMap(); public static final List> TEST_MAP_ADDITIONAL_BAG_LIST = - Collections.singletonList(TEST_MAP_ADDITIONAL_BAG); + Collections.singletonList(TEST_MAP_ADDITIONAL_BAG); public static final NotificationDto TEST_NOTIFICATION_DTO = createNotificationDto(); public static final UpdateOrderPageAdminDto UPDATE_ORDER_PAGE_ADMIN_DTO = updateOrderPageAdminDto(); public static final CourierUpdateDto UPDATE_COURIER_DTO = getUpdateCourierDto(); + public static final Bag TEST_BAG2 = createBag().setFullPrice(100000L); + public static final Bag TEST_BAG2_2 = createBag().setFullPrice(100000L).setId(2); + public static final Bag TEST_BAG2_3 = createBag().setFullPrice(100000L).setId(3); + public static final List TEST_BAG_LIST2 = Arrays.asList(TEST_BAG2, TEST_BAG2, TEST_BAG2_2, TEST_BAG2_3); public static EmployeeFilterView getEmployeeFilterView() { return getEmployeeFilterViewWithPassedIds(1L, 5L, 10L); } public static EmployeeFilterView getEmployeeFilterViewWithPassedIds( - Long employeeId, Long positionId, Long tariffsInfoId) { + Long employeeId, Long positionId, Long tariffsInfoId) { return EmployeeFilterView.builder() - .employeeId(employeeId) - .positionId(positionId) - .positionName("Водій") - .positionNameEn("Driver") - .tariffsInfoId(tariffsInfoId) - .firstName("First Name") - .lastName("Last Name") - .phoneNumber("Phone Number") - .email("employee@gmail.com") - .employeeStatus("ACTIVE") - .image("Image") - .regionId(15L) - .regionNameEn("Kyiv region") - .regionNameUk("Київська область") - .courierId(20L) - .receivingStationId(25L) - .receivingStationName("Receiving station") - .courierNameEn("Test") - .courierNameUk("Тест") - .locationId(30L) - .locationNameEn("Kyiv") - .locationNameUk("Київ") - .build(); + .employeeId(employeeId) + .positionId(positionId) + .positionName("Водій") + .positionNameEn("Driver") + .tariffsInfoId(tariffsInfoId) + .firstName("First Name") + .lastName("Last Name") + .phoneNumber("Phone Number") + .email("employee@gmail.com") + .employeeStatus("ACTIVE") + .image("Image") + .regionId(15L) + .regionNameEn("Kyiv region") + .regionNameUk("Київська область") + .courierId(20L) + .receivingStationId(25L) + .receivingStationName("Receiving station") + .courierNameEn("Test") + .courierNameUk("Тест") + .locationId(30L) + .locationNameEn("Kyiv") + .locationNameUk("Київ") + .build(); } public static List getEmployeeFilterViewListForOneEmployeeWithDifferentPositions( - Long employeeId, Long tariffsInfoId) { + Long employeeId, Long tariffsInfoId) { return List.of( - getEmployeeFilterViewWithPassedIds(employeeId, 3L, tariffsInfoId), - getEmployeeFilterViewWithPassedIds(employeeId, 5L, tariffsInfoId), - getEmployeeFilterViewWithPassedIds(employeeId, 7L, tariffsInfoId)); + getEmployeeFilterViewWithPassedIds(employeeId, 3L, tariffsInfoId), + getEmployeeFilterViewWithPassedIds(employeeId, 5L, tariffsInfoId), + getEmployeeFilterViewWithPassedIds(employeeId, 7L, tariffsInfoId)); } public static GetEmployeeDto getEmployeeDtoWithPositionsAndTariffs() { var getEmployeeDto = getEmployeeDto(); getEmployeeDto.setEmployeePositions(List.of( - getPositionDto(3L), - getPositionDto(5L), - getPositionDto(7L))); + getPositionDto(3L), + getPositionDto(5L), + getPositionDto(7L))); var getTariffInfoForEmployeeDto = getTariffInfoForEmployeeDto2(); getTariffInfoForEmployeeDto.setLocationsDtos(List.of(getLocationsDtos(30L))); @@ -288,93 +290,93 @@ public static GetEmployeeDto getEmployeeDtoWithPositionsAndTariffs() { public static GetEmployeeDto getEmployeeDto() { return GetEmployeeDto.builder() - .id(1L) - .firstName("First Name") - .lastName("Last Name") - .phoneNumber("Phone Number") - .email("employee@gmail.com") - .employeeStatus("ACTIVE") - .image("Image") - .build(); + .id(1L) + .firstName("First Name") + .lastName("Last Name") + .phoneNumber("Phone Number") + .email("employee@gmail.com") + .employeeStatus("ACTIVE") + .image("Image") + .build(); } public static GetReceivingStationDto getReceivingStationDto2() { return GetReceivingStationDto.builder() - .stationId(25L) - .name("Receiving station") - .build(); + .stationId(25L) + .name("Receiving station") + .build(); } public static GetTariffInfoForEmployeeDto getTariffInfoForEmployeeDto2() { return GetTariffInfoForEmployeeDto.builder() - .id(10L) - .region(getRegionDto(15L)) - .courier(getCourierTranslationDto(20L)) - .build(); + .id(10L) + .region(getRegionDto(15L)) + .courier(getCourierTranslationDto(20L)) + .build(); } public static CourierUpdateDto getUpdateCourierDto() { return CourierUpdateDto.builder() - .courierId(1L) - .nameUk("Тест") - .nameEn("Test") - .build(); + .courierId(1L) + .nameUk("Тест") + .nameEn("Test") + .build(); } public static DetailsOrderInfoDto getTestDetailsOrderInfoDto() { return DetailsOrderInfoDto.builder() - .capacity("One") - .sum("Two") - .build(); + .capacity("One") + .sum("Two") + .build(); } public static Optional getOrderWithEvents() { return Optional.of(Order.builder() - .id(1L) - .events(List.of(Event.builder() .id(1L) - .authorName("Igor") - .eventDate(LocalDateTime.now()) - .authorName("Igor") - .build(), - Event.builder() - .id(1L) - .authorName("Igor") - .eventDate(LocalDateTime.now()) - .authorName("Igor") - .build(), - Event.builder() - .id(1L) - .authorName("Igor") - .eventDate(LocalDateTime.now()) - .authorName("Igor") - .build())) - .user(getTestUser()) - .build()); + .events(List.of(Event.builder() + .id(1L) + .authorName("Igor") + .eventDate(LocalDateTime.now()) + .authorName("Igor") + .build(), + Event.builder() + .id(1L) + .authorName("Igor") + .eventDate(LocalDateTime.now()) + .authorName("Igor") + .build(), + Event.builder() + .id(1L) + .authorName("Igor") + .eventDate(LocalDateTime.now()) + .authorName("Igor") + .build())) + .user(getTestUser()) + .build()); } public static List getListOfEvents() { return List.of(Event.builder() - .id(1L) - .authorName("Igor") - .eventDate(LocalDateTime.now()) - .authorName("Igor") - .order(new Order()) - .build(), - Event.builder() - .id(1L) - .authorName("Igor") - .eventDate(LocalDateTime.now()) - .authorName("Igor") - .order(new Order()) - .build(), - Event.builder() - .id(1L) - .authorName("Igor") - .eventDate(LocalDateTime.now()) - .authorName("Igor") - .order(new Order()) - .build()); + .id(1L) + .authorName("Igor") + .eventDate(LocalDateTime.now()) + .authorName("Igor") + .order(new Order()) + .build(), + Event.builder() + .id(1L) + .authorName("Igor") + .eventDate(LocalDateTime.now()) + .authorName("Igor") + .order(new Order()) + .build(), + Event.builder() + .id(1L) + .authorName("Igor") + .eventDate(LocalDateTime.now()) + .authorName("Igor") + .order(new Order()) + .build()); } public static OrderResponseDto getOrderResponseDto() { @@ -383,373 +385,373 @@ public static OrderResponseDto getOrderResponseDto() { public static OrderResponseDto getOrderResponseDto(boolean shouldBePaid) { return OrderResponseDto.builder() - .additionalOrders(new HashSet<>(List.of("232-534-634"))) - .bags(Collections.singletonList(new BagDto(3, 999))) - .locationId(1L) - .orderComment("comment") - .certificates(Collections.emptySet()) - .pointsToUse(700) - .shouldBePaid(shouldBePaid) - .personalData(PersonalDataDto.builder() - .senderEmail("test@email.ua") - .senderPhoneNumber("+380974563223") - .senderLastName("TestLast") - .senderFirstName("TestFirst") - .firstName("oleh") - .lastName("ivanov") - .id(13L) - .email("mail@mail.ua") - .phoneNumber("067894522") - .ubsUserId(1L) - .build()) - .build(); + .additionalOrders(new HashSet<>(List.of("232-534-634"))) + .bags(Collections.singletonList(new BagDto(3, 999))) + .locationId(1L) + .orderComment("comment") + .certificates(Collections.emptySet()) + .pointsToUse(700) + .shouldBePaid(shouldBePaid) + .personalData(PersonalDataDto.builder() + .senderEmail("test@email.ua") + .senderPhoneNumber("+380974563223") + .senderLastName("TestLast") + .senderFirstName("TestFirst") + .firstName("oleh") + .lastName("ivanov") + .id(13L) + .email("mail@mail.ua") + .phoneNumber("067894522") + .ubsUserId(1L) + .build()) + .build(); } public static UBSuser getUBSuser() { return UBSuser.builder() - .firstName("oleh") - .lastName("ivanov") - .email("mail@mail.ua") - .id(1L) - .phoneNumber("067894522") - .senderEmail("test@email.ua") - .senderPhoneNumber("+380974563223") - .senderLastName("TestLast") - .senderFirstName("TestFirst") - .orderAddress(OrderAddress.builder() + .firstName("oleh") + .lastName("ivanov") + .email("mail@mail.ua") .id(1L) - .houseNumber("1a") - .actual(true) - .entranceNumber("str") - .district("3a") - .houseCorpus("2a") - .city("Kiev") - .street("Gorodotska") - .coordinates(Coordinates.builder() - .longitude(2.2) - .latitude(3.2) - .build()) - .addressComment(null).build()) - .orders(List.of(Order.builder().id(1L).build())) - .build(); + .phoneNumber("067894522") + .senderEmail("test@email.ua") + .senderPhoneNumber("+380974563223") + .senderLastName("TestLast") + .senderFirstName("TestFirst") + .orderAddress(OrderAddress.builder() + .id(1L) + .houseNumber("1a") + .actual(true) + .entranceNumber("str") + .district("3a") + .houseCorpus("2a") + .city("Kiev") + .street("Gorodotska") + .coordinates(Coordinates.builder() + .longitude(2.2) + .latitude(3.2) + .build()) + .addressComment(null).build()) + .orders(List.of(Order.builder().id(1L).build())) + .build(); } public static UBSuser getUBSuserWtihoutOrderAddress() { return UBSuser.builder() - .firstName("oleh") - .lastName("ivanov") - .email("mail@mail.ua") - .id(1L) - .phoneNumber("067894522") - .senderEmail("test@email.ua") - .senderPhoneNumber("+380974563223") - .senderLastName("TestLast") - .senderFirstName("TestFirst") - .orders(List.of(Order.builder().id(1L).build())) - .build(); + .firstName("oleh") + .lastName("ivanov") + .email("mail@mail.ua") + .id(1L) + .phoneNumber("067894522") + .senderEmail("test@email.ua") + .senderPhoneNumber("+380974563223") + .senderLastName("TestLast") + .senderFirstName("TestFirst") + .orders(List.of(Order.builder().id(1L).build())) + .build(); } public static UBSuser getUBSuserWithoutSender() { return UBSuser.builder() - .firstName("oleh") - .lastName("ivanov") - .email("mail@mail.ua") - .id(1L) - .phoneNumber("067894522") - .orderAddress(OrderAddress.builder() + .firstName("oleh") + .lastName("ivanov") + .email("mail@mail.ua") .id(1L) - .houseNumber("1a") - .actual(true) - .entranceNumber("str") - .district("3a") - .houseCorpus("2a") - .city("Kiev") - .street("Gorodotska") - .coordinates(Coordinates.builder() - .longitude(2.2) - .latitude(3.2) - .build()) - .addressComment(null).build()) - .orders(List.of(Order.builder().id(1L).build())) - .build(); + .phoneNumber("067894522") + .orderAddress(OrderAddress.builder() + .id(1L) + .houseNumber("1a") + .actual(true) + .entranceNumber("str") + .district("3a") + .houseCorpus("2a") + .city("Kiev") + .street("Gorodotska") + .coordinates(Coordinates.builder() + .longitude(2.2) + .latitude(3.2) + .build()) + .addressComment(null).build()) + .orders(List.of(Order.builder().id(1L).build())) + .build(); } public static User getTestUser() { return User.builder() - .id(1L) - .orders(Lists.newArrayList(getOrder())) - .changeOfPointsList(Lists.newArrayList(getChangeOfPoints())) - .currentPoints(getChangeOfPoints().getAmount()) - .orders(Lists.newArrayList(getOrder())) - .recipientName("Alan") - .recipientSurname("Po") - .uuid("abc") - .build(); + .id(1L) + .orders(Lists.newArrayList(getOrder())) + .changeOfPointsList(Lists.newArrayList(getChangeOfPoints())) + .currentPoints(getChangeOfPoints().getAmount()) + .orders(Lists.newArrayList(getOrder())) + .recipientName("Alan") + .recipientSurname("Po") + .uuid("abc") + .build(); } public static ChangeOfPoints getChangeOfPoints() { return ChangeOfPoints.builder() - .id(1L) - .amount(0) - .order(getOrder()) - .date(LocalDateTime.now()) - .build(); + .id(1L) + .amount(0) + .order(getOrder()) + .date(LocalDateTime.now()) + .build(); } public static Order getOrder() { return Order.builder() - .id(1L) - .payment(Lists.newArrayList(Payment.builder() .id(1L) - .paymentId("1") - .amount(20000L) - .currency("UAH") - .comment("avb") - .paymentStatus(PaymentStatus.PAID) - .build())) - .ubsUser(UBSuser.builder() - .firstName("oleh") - .lastName("ivanov") - .email("mail@mail.ua") - .id(1L) - .phoneNumber("067894522") - .orderAddress(OrderAddress.builder() - .id(1L) - .city("Lviv") - .street("Levaya") - .district("frankivskiy") - .entranceNumber("5") - .addressComment("near mall") - .houseCorpus("1") - .houseNumber("4") - .coordinates(Coordinates.builder() - .latitude(49.83) - .longitude(23.88) + .payment(Lists.newArrayList(Payment.builder() + .id(1L) + .paymentId("1") + .amount(20000L) + .currency("UAH") + .comment("avb") + .paymentStatus(PaymentStatus.PAID) + .build())) + .ubsUser(UBSuser.builder() + .firstName("oleh") + .lastName("ivanov") + .email("mail@mail.ua") + .id(1L) + .phoneNumber("067894522") + .orderAddress(OrderAddress.builder() + .id(1L) + .city("Lviv") + .street("Levaya") + .district("frankivskiy") + .entranceNumber("5") + .addressComment("near mall") + .houseCorpus("1") + .houseNumber("4") + .coordinates(Coordinates.builder() + .latitude(49.83) + .longitude(23.88) + .build()) + .build()) .build()) - .build()) - .build()) - .user(User.builder() - .id(1L) - .recipientName("Yuriy") - .recipientSurname("Gerasum") - .uuid("UUID") - .build()) - .certificates(Collections.emptySet()) - .pointsToUse(700) - .adminComment("Admin") - .cancellationComment("cancelled") - .receivingStation(ReceivingStation.builder() - .id(1L) - .name("Саперно-Слобідська") - .build()) - .cancellationReason(CancellationReason.OUT_OF_CITY) - .imageReasonNotTakingBags(List.of("foto")) - .orderPaymentStatus(OrderPaymentStatus.UNPAID) - .additionalOrders(new HashSet<>(Arrays.asList("1111111111", "2222222222"))) - .events(new ArrayList<>()) - .build(); + .user(User.builder() + .id(1L) + .recipientName("Yuriy") + .recipientSurname("Gerasum") + .uuid("UUID") + .build()) + .certificates(Collections.emptySet()) + .pointsToUse(700) + .adminComment("Admin") + .cancellationComment("cancelled") + .receivingStation(ReceivingStation.builder() + .id(1L) + .name("Саперно-Слобідська") + .build()) + .cancellationReason(CancellationReason.OUT_OF_CITY) + .imageReasonNotTakingBags(List.of("foto")) + .orderPaymentStatus(OrderPaymentStatus.UNPAID) + .additionalOrders(new HashSet<>(Arrays.asList("1111111111", "2222222222"))) + .events(new ArrayList<>()) + .build(); } public static Order getOrderWithTariffAndLocation() { return Order.builder() - .id(1L) - .payment(Lists.newArrayList(Payment.builder() - .id(1L) - .paymentId("1") - .amount(20000L) - .currency("UAH") - .comment("avb") - .paymentStatus(PaymentStatus.PAID) - .build())) - .ubsUser(UBSuser.builder() - .firstName("oleh") - .lastName("ivanov") - .email("mail@mail.ua") .id(1L) - .phoneNumber("067894522") - .orderAddress(OrderAddress.builder() - .id(1L) - .city("Lviv") - .street("Levaya") - .district("frankivskiy") - .entranceNumber("5") - .addressComment("near mall") - .houseCorpus("1") - .houseNumber("4") - .location(getLocation()) - .coordinates(Coordinates.builder() - .latitude(49.83) - .longitude(23.88) + .payment(Lists.newArrayList(Payment.builder() + .id(1L) + .paymentId("1") + .amount(20000L) + .currency("UAH") + .comment("avb") + .paymentStatus(PaymentStatus.PAID) + .build())) + .ubsUser(UBSuser.builder() + .firstName("oleh") + .lastName("ivanov") + .email("mail@mail.ua") + .id(1L) + .phoneNumber("067894522") + .orderAddress(OrderAddress.builder() + .id(1L) + .city("Lviv") + .street("Levaya") + .district("frankivskiy") + .entranceNumber("5") + .addressComment("near mall") + .houseCorpus("1") + .houseNumber("4") + .location(getLocation()) + .coordinates(Coordinates.builder() + .latitude(49.83) + .longitude(23.88) + .build()) + .build()) .build()) - .build()) - .build()) - .tariffsInfo(getTariffInfo()) - .user(User.builder() - .id(1L) - .recipientName("Yuriy") - .recipientSurname("Gerasum") - .uuid("UUID") - .build()) - .certificates(Collections.emptySet()) - .pointsToUse(700) - .adminComment("Admin") - .cancellationComment("cancelled") - .receivingStation(ReceivingStation.builder() - .id(1L) - .name("Саперно-Слобідська") - .build()) - .cancellationReason(CancellationReason.OUT_OF_CITY) - .imageReasonNotTakingBags(List.of("foto")) - .orderPaymentStatus(OrderPaymentStatus.UNPAID) - .additionalOrders(new HashSet<>(Arrays.asList("1111111111", "2222222222"))) - .build(); + .tariffsInfo(getTariffInfo()) + .user(User.builder() + .id(1L) + .recipientName("Yuriy") + .recipientSurname("Gerasum") + .uuid("UUID") + .build()) + .certificates(Collections.emptySet()) + .pointsToUse(700) + .adminComment("Admin") + .cancellationComment("cancelled") + .receivingStation(ReceivingStation.builder() + .id(1L) + .name("Саперно-Слобідська") + .build()) + .cancellationReason(CancellationReason.OUT_OF_CITY) + .imageReasonNotTakingBags(List.of("foto")) + .orderPaymentStatus(OrderPaymentStatus.UNPAID) + .additionalOrders(new HashSet<>(Arrays.asList("1111111111", "2222222222"))) + .build(); } public static Order getOrderWithoutAddress() { return Order.builder() - .id(1L) - .counterOrderPaymentId(0L) - .ubsUser(UBSuser.builder() - .firstName("oleh") - .lastName("ivanov") - .email("mail@mail.ua") .id(1L) - .phoneNumber("067894522") - .build()) - .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").build()) - .build(); + .counterOrderPaymentId(0L) + .ubsUser(UBSuser.builder() + .firstName("oleh") + .lastName("ivanov") + .email("mail@mail.ua") + .id(1L) + .phoneNumber("067894522") + .build()) + .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").build()) + .build(); } public static Order getOrderExportDetails() { return Order.builder() - .id(1L) - .deliverFrom(LocalDateTime.of(1997, 12, 4, 15, 40, 24)) - .dateOfExport(LocalDate.of(1997, 12, 4)) - .deliverTo(LocalDateTime.of(1990, 12, 11, 19, 30, 30)) - .receivingStation(ReceivingStation.builder() .id(1L) - .name("Саперно-Слобідська") - .build()) - .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").build()) - .build(); + .deliverFrom(LocalDateTime.of(1997, 12, 4, 15, 40, 24)) + .dateOfExport(LocalDate.of(1997, 12, 4)) + .deliverTo(LocalDateTime.of(1990, 12, 11, 19, 30, 30)) + .receivingStation(ReceivingStation.builder() + .id(1L) + .name("Саперно-Слобідська") + .build()) + .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").build()) + .build(); } public static Order getOrderExportDetailsWithNullValues() { return Order.builder() - .id(1L) - .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").build()) - .build(); + .id(1L) + .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").build()) + .build(); } public static Order getOrderWithoutPayment() { return Order.builder() - .id(1L) - .payment(Collections.emptyList()) - .certificates(Collections.emptySet()) - .pointsToUse(500) - .build(); + .id(1L) + .payment(Collections.emptyList()) + .certificates(Collections.emptySet()) + .pointsToUse(500) + .build(); } public static OrderDto getOrderDto() { return OrderDto.builder() - .firstName("oleh") - .lastName("ivanov") - .address("frankivskiy Levaya 4") - .addressComment("near mall") - .phoneNumber("067894522") - .latitude(49.83) - .longitude(23.88) - .build(); + .firstName("oleh") + .lastName("ivanov") + .address("frankivskiy Levaya 4") + .addressComment("near mall") + .phoneNumber("067894522") + .latitude(49.83) + .longitude(23.88) + .build(); } public static Coordinates getCoordinates() { return Coordinates.builder() - .latitude(49.83) - .longitude(23.88) - .build(); + .latitude(49.83) + .longitude(23.88) + .build(); } public static CoordinatesDto getCoordinatesDto() { return CoordinatesDto.builder() - .latitude(49.83) - .longitude(23.88) - .build(); + .latitude(49.83) + .longitude(23.88) + .build(); } public static ExportDetailsDto getExportDetails() { return ExportDetailsDto.builder() - .dateExport("1997-12-04T15:40:24") - .timeDeliveryFrom("1997-12-04T15:40:24") - .timeDeliveryTo("1990-12-11T19:30:30") - .receivingStationId(1L) - .allReceivingStations(List.of(getReceivingStationDto(), getReceivingStationDto())) - .build(); + .dateExport("1997-12-04T15:40:24") + .timeDeliveryFrom("1997-12-04T15:40:24") + .timeDeliveryTo("1990-12-11T19:30:30") + .receivingStationId(1L) + .allReceivingStations(List.of(getReceivingStationDto(), getReceivingStationDto())) + .build(); } public static ExportDetailsDtoUpdate getExportDetailsRequestToday() { return ExportDetailsDtoUpdate.builder() - .dateExport(String.valueOf(LocalDate.now())) - .timeDeliveryFrom(String.valueOf(LocalDateTime.now())) - .timeDeliveryTo(String.valueOf(LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT))) - .receivingStationId(1L) - .build(); + .dateExport(String.valueOf(LocalDate.now())) + .timeDeliveryFrom(String.valueOf(LocalDateTime.now())) + .timeDeliveryTo(String.valueOf(LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT))) + .receivingStationId(1L) + .build(); } public static ExportDetailsDtoUpdate getExportDetailsRequest() { return ExportDetailsDtoUpdate.builder() - .dateExport("1997-12-04T15:40:24") - .timeDeliveryFrom("1997-12-04T15:40:24") - .timeDeliveryTo("1990-12-11T19:30:30") - .receivingStationId(1L) - .build(); + .dateExport("1997-12-04T15:40:24") + .timeDeliveryFrom("1997-12-04T15:40:24") + .timeDeliveryTo("1990-12-11T19:30:30") + .receivingStationId(1L) + .build(); } public static Set getCoordinatesSet() { Set set = new HashSet<>(); set.add(Coordinates.builder() - .latitude(49.894) - .longitude(24.107) - .build()); + .latitude(49.894) + .longitude(24.107) + .build()); set.add(Coordinates.builder() - .latitude(49.771) - .longitude(23.909) - .build()); + .latitude(49.771) + .longitude(23.909) + .build()); set.add(Coordinates.builder() - .latitude(49.801) - .longitude(24.164) - .build()); + .latitude(49.801) + .longitude(24.164) + .build()); set.add(Coordinates.builder() - .latitude(49.854) - .longitude(24.069) - .build()); + .latitude(49.854) + .longitude(24.069) + .build()); set.add(Coordinates.builder() - .latitude(49.796) - .longitude(24.931) - .build()); + .latitude(49.796) + .longitude(24.931) + .build()); set.add(Coordinates.builder() - .latitude(49.812) - .longitude(24.035) - .build()); + .latitude(49.812) + .longitude(24.035) + .build()); set.add(Coordinates.builder() - .latitude(49.871) - .longitude(24.029) - .build()); + .latitude(49.871) + .longitude(24.029) + .build()); set.add(Coordinates.builder() - .latitude(49.666) - .longitude(24.013) - .build()); + .latitude(49.666) + .longitude(24.013) + .build()); set.add(Coordinates.builder() - .latitude(49.795) - .longitude(24.052) - .build()); + .latitude(49.795) + .longitude(24.052) + .build()); set.add(Coordinates.builder() - .latitude(49.856) - .longitude(24.049) - .build()); + .latitude(49.856) + .longitude(24.049) + .build()); set.add(Coordinates.builder() - .latitude(49.862) - .longitude(24.039) - .build()); + .latitude(49.862) + .longitude(24.039) + .build()); return set; } @@ -759,14 +761,14 @@ public static List getOrdersToGroupThem() { long userId = 10L; for (Coordinates coordinates : getCoordinatesSet()) { orders.add(Order.builder() - .id(++id) - .ubsUser(UBSuser.builder() - .id(++userId) - .orderAddress(OrderAddress.builder() - .coordinates(coordinates) - .build()) - .build()) - .build()); + .id(++id) + .ubsUser(UBSuser.builder() + .id(++userId) + .orderAddress(OrderAddress.builder() + .coordinates(coordinates) + .build()) + .build()) + .build()); } return orders; } @@ -774,442 +776,422 @@ public static List getOrdersToGroupThem() { public static List getGroupedOrders() { List list = new ArrayList<>(); list.add(GroupedOrderDto.builder() - .amountOfLitres(75) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.854) - .longitude(24.069) - .build(), - OrderDto.builder() - .latitude(49.856) - .longitude(24.049) - .build(), - OrderDto.builder() - .latitude(49.862) - .longitude(24.039) - .build())) - .build()); + .amountOfLitres(75) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.854) + .longitude(24.069) + .build(), + OrderDto.builder() + .latitude(49.856) + .longitude(24.049) + .build(), + OrderDto.builder() + .latitude(49.862) + .longitude(24.039) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.812) - .longitude(24.035) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.812) + .longitude(24.035) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.795) - .longitude(24.052) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.795) + .longitude(24.052) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.796) - .longitude(24.931) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.796) + .longitude(24.931) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.871) - .longitude(24.029) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.871) + .longitude(24.029) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.894) - .longitude(24.107) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.894) + .longitude(24.107) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.666) - .longitude(24.013) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.666) + .longitude(24.013) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.771) - .longitude(23.909) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.771) + .longitude(23.909) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.801) - .longitude(24.164) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.801) + .longitude(24.164) + .build())) + .build()); return list; } public static List getGroupedOrdersWithLiters() { List list = new ArrayList<>(); list.add(GroupedOrderDto.builder() - .amountOfLitres(75) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.854) - .longitude(24.069) - .build())) - .build()); + .amountOfLitres(75) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.854) + .longitude(24.069) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.812) - .longitude(24.035) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.812) + .longitude(24.035) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.795) - .longitude(24.052) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.795) + .longitude(24.052) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.796) - .longitude(24.931) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.796) + .longitude(24.931) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.871) - .longitude(24.029) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.871) + .longitude(24.029) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.894) - .longitude(24.107) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.894) + .longitude(24.107) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.666) - .longitude(24.013) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.666) + .longitude(24.013) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.856) - .longitude(24.049) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.856) + .longitude(24.049) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.862) - .longitude(24.039) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.862) + .longitude(24.039) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.771) - .longitude(23.909) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.771) + .longitude(23.909) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.801) - .longitude(24.164) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.801) + .longitude(24.164) + .build())) + .build()); return list; } public static List getGroupedOrdersFor60LitresLimit() { List list = new ArrayList<>(); list.add(GroupedOrderDto.builder() - .amountOfLitres(50) - .groupOfOrders(List.of( - OrderDto.builder() - .latitude(49.856) - .longitude(24.049) - .build(), - OrderDto.builder() - .latitude(49.862) - .longitude(24.039) - .build())) - .build()); + .amountOfLitres(50) + .groupOfOrders(List.of( + OrderDto.builder() + .latitude(49.856) + .longitude(24.049) + .build(), + OrderDto.builder() + .latitude(49.862) + .longitude(24.039) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.854) - .longitude(24.069) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.854) + .longitude(24.069) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.812) - .longitude(24.035) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.812) + .longitude(24.035) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.795) - .longitude(24.052) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.795) + .longitude(24.052) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.796) - .longitude(24.931) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.796) + .longitude(24.931) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.871) - .longitude(24.029) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.871) + .longitude(24.029) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.894) - .longitude(24.107) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.894) + .longitude(24.107) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.666) - .longitude(24.013) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.666) + .longitude(24.013) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.771) - .longitude(23.909) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.771) + .longitude(23.909) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.801) - .longitude(24.164) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.801) + .longitude(24.164) + .build())) + .build()); return list; } public static CertificateDtoForSearching getCertificateDtoForSearching() { return CertificateDtoForSearching.builder() - .code("1111-1234") - .certificateStatus(CertificateStatus.ACTIVE) - .points(10) - .expirationDate(LocalDate.now().plusMonths(1)) - .creationDate(LocalDate.now()) - .orderId(1L) - .build(); + .code("1111-1234") + .certificateStatus(CertificateStatus.ACTIVE) + .points(10) + .expirationDate(LocalDate.now().plusMonths(1)) + .creationDate(LocalDate.now()) + .orderId(1L) + .build(); } public static CertificateDtoForAdding getCertificateDtoForAdding() { return CertificateDtoForAdding.builder() - .code("1111-1234") - .monthCount(0) - .initialPointsValue(10) - .points(0) - .build(); + .code("1111-1234") + .monthCount(0) + .initialPointsValue(10) + .points(0) + .build(); } public static Certificate getCertificate() { return Certificate.builder() - .code("1111-1234") - .certificateStatus(CertificateStatus.ACTIVE) - .points(10) - .expirationDate(LocalDate.now().plusMonths(1)) - .creationDate(LocalDate.now()) - .order(null) - .build(); + .code("1111-1234") + .certificateStatus(CertificateStatus.ACTIVE) + .points(10) + .expirationDate(LocalDate.now().plusMonths(1)) + .creationDate(LocalDate.now()) + .order(null) + .build(); } public static Certificate getCertificate2() { return Certificate.builder() - .code("1111-1234") - .certificateStatus(CertificateStatus.ACTIVE) - .points(600) - .expirationDate(LocalDate.now().plusMonths(1)) - .creationDate(LocalDate.now()) - .order(null) - .build(); + .code("1111-1234") + .certificateStatus(CertificateStatus.ACTIVE) + .points(600) + .expirationDate(LocalDate.now().plusMonths(1)) + .creationDate(LocalDate.now()) + .order(null) + .build(); } public static AddingViolationsToUserDto getAddingViolationsToUserDto() { return AddingViolationsToUserDto.builder() - .orderID(1L) - .violationDescription("String string string") - .violationLevel("low") - .build(); + .orderID(1L) + .violationDescription("String string string") + .violationLevel("low") + .build(); } public static UpdateViolationToUserDto getUpdateViolationToUserDto() { List listImages = new ArrayList<>(); listImages.add(""); return UpdateViolationToUserDto.builder() - .orderID(1L) - .violationDescription("String1 string1 string1") - .violationLevel("low") - .imagesToDelete(listImages) - .build(); + .orderID(1L) + .violationDescription("String1 string1 string1") + .violationLevel("low") + .imagesToDelete(listImages) + .build(); } public static OrderClientDto getOrderClientDto() { return OrderClientDto.builder() - .id(1L) - .orderStatus(OrderStatus.DONE) - .amount(350L) - .build(); + .id(1L) + .orderStatus(OrderStatus.DONE) + .amount(350L) + .build(); } public static Order getOrderDoneByUser() { return Order.builder() - .id(1L) - .orderStatus(OrderStatus.CONFIRMED) - .payment(singletonList(Payment.builder() .id(1L) - .amount(350L) - .build())) - .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) - .amountOfBagsOrdered(Collections.singletonMap(1, 2)) - .build(); + .orderStatus(OrderStatus.CONFIRMED) + .payment(singletonList(Payment.builder() + .id(1L) + .amount(350L) + .build())) + .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) + .amountOfBagsOrdered(Collections.singletonMap(1, 2)) + .build(); } public static AddEmployeeDto getAddEmployeeDto() { return AddEmployeeDto.builder() - .firstName("Петро") - .lastName("Петренко") - .phoneNumber("+380935577455") - .email("test@gmail.com") - .employeePositions(List.of(PositionDto.builder() - .id(1L) - .name("Водій") - .nameEn("Driver") - .build())) - .receivingStations(List.of(ReceivingStationDto.builder() - .id(1L) - .name("Петрівка") - .build())) - .build(); - } - - public static EmployeeWithTariffsDto getEmployeeWithTariffsDto() { - return EmployeeWithTariffsDto.builder() - .employeeDto(EmployeeDto.builder() - .id(1L) .firstName("Петро") .lastName("Петренко") .phoneNumber("+380935577455") .email("test@gmail.com") - .image("path") .employeePositions(List.of(PositionDto.builder() - .id(1L) - .name("Водій") - .nameEn("Driver") - .build())) - .build()) - .tariffs(List.of(getTariffInfoForEmployeeDto())) - .build(); + .id(1L) + .name("Водій") + .nameEn("Driver") + .build())) + .receivingStations(List.of(ReceivingStationDto.builder() + .id(1L) + .name("Петрівка") + .build())) + .build(); + } + + public static EmployeeWithTariffsDto getEmployeeWithTariffsDto() { + return EmployeeWithTariffsDto.builder() + .employeeDto(EmployeeDto.builder() + .id(1L) + .firstName("Петро") + .lastName("Петренко") + .phoneNumber("+380935577455") + .email("test@gmail.com") + .image("path") + .employeePositions(List.of(PositionDto.builder() + .id(1L) + .name("Водій") + .nameEn("Driver") + .build())) + .build()) + .tariffs(List.of(getTariffInfoForEmployeeDto())) + .build(); } public static GetTariffInfoForEmployeeDto getTariffInfoForEmployeeDto() { return GetTariffInfoForEmployeeDto - .builder() - .id(1L) - .region(RegionDto.builder() - .regionId(1L) - .nameEn("Kyiv region") - .nameUk("Київська область") - .build()) - .locationsDtos(List.of(getLocationsDtos(1L))) - .receivingStationDtos(List.of(getGetReceivingStationDto())) - .courier(getCourierTranslationDto(1L)) - .build(); + .builder() + .id(1L) + .region(RegionDto.builder() + .regionId(1L) + .nameEn("Kyiv region") + .nameUk("Київська область") + .build()) + .locationsDtos(List.of(getLocationsDtos(1L))) + .receivingStationDtos(List.of(getGetReceivingStationDto())) + .courier(getCourierTranslationDto(1L)) + .build(); } public static LocationsDtos getLocationsDtos(Long id) { return LocationsDtos.builder() - .locationId(id) - .nameUk("Київ") - .nameEn("Kyiv") - .build(); + .locationId(id) + .nameUk("Київ") + .nameEn("Kyiv") + .build(); } public static GetReceivingStationDto getGetReceivingStationDto() { return GetReceivingStationDto - .builder() - .stationId(1L) - .name("Петрівка") - .build(); + .builder() + .stationId(1L) + .name("Петрівка") + .build(); } public static Employee getEmployee() { return Employee.builder() - .id(1L) - .firstName("Петро") - .lastName("Петренко") - .phoneNumber("+380935577455") - .email("test@gmail.com") - .uuid("Test") - .employeeStatus(EmployeeStatus.ACTIVE) - .employeePosition(Set.of(Position.builder() - .id(1L) - .name("Водій") - .nameEn("Driver") - .build())) - .tariffInfos(Set.of(TariffsInfo.builder() .id(1L) - .service(new Service()) - .build())) - .imagePath("path") - .build(); + .firstName("Петро") + .lastName("Петренко") + .phoneNumber("+380935577455") + .email("test@gmail.com") + .uuid("Test") + .employeeStatus(EmployeeStatus.ACTIVE) + .employeePosition(Set.of(Position.builder() + .id(1L) + .name("Водій") + .nameEn("Driver") + .build())) + .tariffInfos(Set.of(TariffsInfo.builder() + .id(1L) + .service(new Service()) + .build())) + .imagePath("path") + .build(); } public static Employee getEmployeeWithTariffs() { return Employee.builder() - .id(1L) - .firstName("Петро") - .lastName("Петренко") - .phoneNumber("+380935577455") - .email("test@gmail.com") - .employeeStatus(EmployeeStatus.ACTIVE) - .employeePosition(Set.of(Position.builder() - .id(1L) - .name("Водій") - .nameEn("Driver") - .build())) - .tariffInfos(Set.of(getTariffsInfo())) - .imagePath("path") - .tariffs(List.of(getTariffInfo())) - .build(); - } - - public static List getEmployeeList() { - return List.of( - Employee.builder() .id(1L) .firstName("Петро") .lastName("Петренко") @@ -1217,103 +1199,142 @@ public static List getEmployeeList() { .email("test@gmail.com") .employeeStatus(EmployeeStatus.ACTIVE) .employeePosition(Set.of(Position.builder() - .id(6L) - .name("Супер адмін") - .nameEn("Super admin") - .build())) - .tariffInfos(new HashSet<>()) + .id(1L) + .name("Водій") + .nameEn("Driver") + .build())) + .tariffInfos(Set.of(getTariffsInfo())) .imagePath("path") .tariffs(List.of(getTariffInfo())) - .build()); + .build(); + } + + public static List getEmployeeList() { + return List.of( + Employee.builder() + .id(1L) + .firstName("Петро") + .lastName("Петренко") + .phoneNumber("+380935577455") + .email("test@gmail.com") + .employeeStatus(EmployeeStatus.ACTIVE) + .employeePosition(Set.of(Position.builder() + .id(6L) + .name("Супер адмін") + .nameEn("Super admin") + .build())) + .tariffInfos(new HashSet<>()) + .imagePath("path") + .tariffs(List.of(getTariffInfo())) + .build()); } public static Employee getEmployeeForUpdateEmailCheck() { return Employee.builder() - .id(1L) - .firstName("Петро") - .lastName("Петренко") - .phoneNumber("+380935577455") - .email("test1@gmail.com") - .employeeStatus(EmployeeStatus.ACTIVE) - .employeePosition(Set.of(Position.builder() - .id(1L) - .name("Водій") - .nameEn("Driver") - .build())) - .tariffInfos(Set.of(TariffsInfo.builder() .id(1L) - .service(new Service()) - .build())) - .imagePath("path") - .build(); + .firstName("Петро") + .lastName("Петренко") + .phoneNumber("+380935577455") + .email("test1@gmail.com") + .employeeStatus(EmployeeStatus.ACTIVE) + .employeePosition(Set.of(Position.builder() + .id(1L) + .name("Водій") + .nameEn("Driver") + .build())) + .tariffInfos(Set.of(TariffsInfo.builder() + .id(1L) + .service(new Service()) + .build())) + .imagePath("path") + .build(); } public static Employee getFullEmployee() { return Employee.builder() - .id(1L) - .firstName("Петро") - .lastName("Петренко") - .phoneNumber("+380935577455") - .email("test@gmail.com") - .imagePath("path") - .employeeStatus(EmployeeStatus.ACTIVE) - .employeePosition(Set.of(Position.builder() - .id(1L) - .name("Водій") - .nameEn("Driver") - .build())) - .tariffInfos(Set.of(TariffsInfo.builder() - .id(1L) - .service(getService()) - .courier(getCourier()) - .tariffLocations(Set.of(getTariffLocation())) - .receivingStationList(Set.of(getReceivingStation())) - .build())) - .tariffs(List.of(TariffsInfo.builder() .id(1L) - .service(getService()) - .courier(getCourier()) - .tariffLocations(Set.of(getTariffLocation())) - .build())) - .build(); + .firstName("Петро") + .lastName("Петренко") + .phoneNumber("+380935577455") + .email("test@gmail.com") + .imagePath("path") + .employeeStatus(EmployeeStatus.ACTIVE) + .employeePosition(Set.of(Position.builder() + .id(1L) + .name("Водій") + .nameEn("Driver") + .build())) + .tariffInfos(Set.of(TariffsInfo.builder() + .id(1L) + .service(getService()) + .courier(getCourier()) + .tariffLocations(Set.of(getTariffLocation())) + .receivingStationList(Set.of(getReceivingStation())) + .build())) + .tariffs(List.of(TariffsInfo.builder() + .id(1L) + .service(getService()) + .courier(getCourier()) + .tariffLocations(Set.of(getTariffLocation())) + .build())) + .build(); } public static TariffLocation getTariffLocation() { return TariffLocation - .builder() - .id(1L) - .tariffsInfo(getTariffsInfo()) - .location(getLocation()) - .locationStatus(LocationStatus.ACTIVE) - .build(); + .builder() + .id(1L) + .tariffsInfo(getTariffsInfo()) + .location(getLocation()) + .locationStatus(LocationStatus.ACTIVE) + .build(); } public static TariffLocation getTariffLocation2() { return TariffLocation - .builder() - .id(1L) - .tariffsInfo( - TariffsInfo.builder() - .id(2L) - .build()) - .location(getLocation()) - .locationStatus(LocationStatus.ACTIVE) - .build(); + .builder() + .id(1L) + .tariffsInfo( + TariffsInfo.builder() + .id(2L) + .build()) + .location(getLocation()) + .locationStatus(LocationStatus.ACTIVE) + .build(); } public static List getTariffLocationList() { return List.of(getTariffLocation(), - TariffLocation - .builder() - .id(2L) - .locationStatus(LocationStatus.ACTIVE) - .build()); + TariffLocation + .builder() + .id(2L) + .locationStatus(LocationStatus.ACTIVE) + .build()); } public static EmployeeWithTariffsIdDto getEmployeeWithTariffsIdDto() { return EmployeeWithTariffsIdDto - .builder() - .employeeDto(EmployeeDto.builder() + .builder() + .employeeDto(EmployeeDto.builder() + .id(1L) + .firstName("Петро") + .lastName("Петренко") + .phoneNumber("+380935577455") + .email("test@gmail.com") + .image("path") + .employeePositions(List.of(PositionDto.builder() + .id(1L) + .name("Водій") + .nameEn("Driver") + .build())) + .build()) + .tariffId(List.of(1L)) + .build(); + } + + public static GetEmployeeDto getGetEmployeeDto() { + return GetEmployeeDto + .builder() .id(1L) .firstName("Петро") .lastName("Петренко") @@ -1321,485 +1342,466 @@ public static EmployeeWithTariffsIdDto getEmployeeWithTariffsIdDto() { .email("test@gmail.com") .image("path") .employeePositions(List.of(PositionDto.builder() - .id(1L) - .name("Водій") - .nameEn("Driver") - .build())) - .build()) - .tariffId(List.of(1L)) - .build(); - } - - public static GetEmployeeDto getGetEmployeeDto() { - return GetEmployeeDto - .builder() - .id(1L) - .firstName("Петро") - .lastName("Петренко") - .phoneNumber("+380935577455") - .email("test@gmail.com") - .image("path") - .employeePositions(List.of(PositionDto.builder() - .id(1L) - .name("Водій") - .nameEn("Driver") - .build())) - .tariffs(List.of(GetTariffInfoForEmployeeDto.builder() - .id(1L) - .region(getRegionDto(1L)) - .locationsDtos(List.of(LocationsDtos - .builder() - .locationId(1L) - .nameEn("Kyiv") - .nameUk("Київ") - .build())) - .receivingStationDtos(List.of(GetReceivingStationDto - .builder() - .stationId(1L) - .name("Петрівка") - .build())) - .courier(CourierTranslationDto.builder() - .id(1L) - .nameUk("Тест") - .nameEn("Test") - .build()) - .build())) - .build(); + .id(1L) + .name("Водій") + .nameEn("Driver") + .build())) + .tariffs(List.of(GetTariffInfoForEmployeeDto.builder() + .id(1L) + .region(getRegionDto(1L)) + .locationsDtos(List.of(LocationsDtos + .builder() + .locationId(1L) + .nameEn("Kyiv") + .nameUk("Київ") + .build())) + .receivingStationDtos(List.of(GetReceivingStationDto + .builder() + .stationId(1L) + .name("Петрівка") + .build())) + .courier(CourierTranslationDto.builder() + .id(1L) + .nameUk("Тест") + .nameEn("Test") + .build()) + .build())) + .build(); } private static RegionDto getRegionDto(Long id) { return RegionDto.builder() - .regionId(id) - .nameEn("Kyiv region") - .nameUk("Київська область") - .build(); + .regionId(id) + .nameEn("Kyiv region") + .nameUk("Київська область") + .build(); } public static UserInfoDto getUserInfoDto() { return UserInfoDto.builder() - .customerName("Alan") - .customerSurName("Maym") - .customerPhoneNumber("091546745") - .customerEmail("wayn@email.com") - .recipientName("Anatolii") - .recipientSurName("Petyrov") - .recipientPhoneNumber("095123456") - .recipientEmail("anatolii.andr@gmail.com") - .totalUserViolations(4) - .userViolationForCurrentOrder(1) - .build(); + .customerName("Alan") + .customerSurName("Maym") + .customerPhoneNumber("091546745") + .customerEmail("wayn@email.com") + .recipientName("Anatolii") + .recipientSurName("Petyrov") + .recipientPhoneNumber("095123456") + .recipientEmail("anatolii.andr@gmail.com") + .totalUserViolations(4) + .userViolationForCurrentOrder(1) + .build(); } public static Order getOrderDetails() { return Order.builder() - .id(1L) - .user(User.builder() .id(1L) - .recipientName("Alan") - .recipientSurname("Maym") - .recipientPhone("091546745") - .recipientEmail("wayn@email.com") - .violations(4).build()) - .ubsUser(UBSuser.builder() - .id(1L) - .firstName("Anatolii") - .lastName("Petyrov") - .phoneNumber("095123456") - .email("anatolii.andr@gmail.com") - .senderFirstName("Anatolii") - .senderLastName("Petyrov") - .senderPhoneNumber("095123456") - .senderEmail("anatolii.andr@gmail.com") - .build()) - .build(); + .user(User.builder() + .id(1L) + .recipientName("Alan") + .recipientSurname("Maym") + .recipientPhone("091546745") + .recipientEmail("wayn@email.com") + .violations(4).build()) + .ubsUser(UBSuser.builder() + .id(1L) + .firstName("Anatolii") + .lastName("Petyrov") + .phoneNumber("095123456") + .email("anatolii.andr@gmail.com") + .senderFirstName("Anatolii") + .senderLastName("Petyrov") + .senderPhoneNumber("095123456") + .senderEmail("anatolii.andr@gmail.com") + .build()) + .build(); } public static Order getOrderDetailsWithoutSender() { return Order.builder() - .id(1L) - .user(User.builder() .id(1L) - .recipientName("Alan") - .recipientSurname("Maym") - .recipientPhone("091546745") - .recipientEmail("wayn@email.com") - .violations(4).build()) - .ubsUser(UBSuser.builder() - .id(1L) - .firstName("Anatolii") - .lastName("Petyrov") - .phoneNumber("095123456") - .email("anatolii.andr@gmail.com") - .build()) - .build(); + .user(User.builder() + .id(1L) + .recipientName("Alan") + .recipientSurname("Maym") + .recipientPhone("091546745") + .recipientEmail("wayn@email.com") + .violations(4).build()) + .ubsUser(UBSuser.builder() + .id(1L) + .firstName("Anatolii") + .lastName("Petyrov") + .phoneNumber("095123456") + .email("anatolii.andr@gmail.com") + .build()) + .build(); } public static UbsCustomersDtoUpdate getUbsCustomersDtoUpdate() { return UbsCustomersDtoUpdate.builder() - .recipientId(1L) - .recipientName("Anatolii Petyrov") - .recipientEmail("anatolii.andr@gmail.com") - .recipientPhoneNumber("095123456").build(); + .recipientId(1L) + .recipientName("Anatolii Petyrov") + .recipientEmail("anatolii.andr@gmail.com") + .recipientPhoneNumber("095123456").build(); } public static List addressDtoList() { List list = new ArrayList<>(); list.add(AddressDto.builder() - .id(1L) - .entranceNumber("7a") - .houseCorpus("2") - .houseNumber("7") - .street("Gorodotska") - .coordinates(Coordinates.builder().latitude(2.3).longitude(5.6).build()) - .district("Zaliznuchnuy") - .city("Lviv") - .actual(false) - .placeId("place_id") - .build()); + .id(1L) + .entranceNumber("7a") + .houseCorpus("2") + .houseNumber("7") + .street("Gorodotska") + .coordinates(Coordinates.builder().latitude(2.3).longitude(5.6).build()) + .district("Zaliznuchnuy") + .city("Lviv") + .actual(false) + .placeId("place_id") + .build()); list.add(AddressDto.builder().id(2L) - .entranceNumber("9a") - .houseCorpus("2") - .houseNumber("7") - .street("Shevchenka") - .coordinates(Coordinates.builder().latitude(3.3).longitude(6.6).build()) - .district("Zaliznuchnuy") - .city("Lviv") - .actual(false) - .placeId("place_id") - .build()); + .entranceNumber("9a") + .houseCorpus("2") + .houseNumber("7") + .street("Shevchenka") + .coordinates(Coordinates.builder().latitude(3.3).longitude(6.6).build()) + .district("Zaliznuchnuy") + .city("Lviv") + .actual(false) + .placeId("place_id") + .build()); return list; } public static UserProfileDto userProfileDto() { return UserProfileDto.builder() - .recipientName("Dima") - .recipientSurname("Petrov") - .recipientPhone("0666051373") - .recipientEmail("petrov@gmail.com") - .telegramIsNotify(true) - .viberIsNotify(false) - .build(); + .recipientName("Dima") + .recipientSurname("Petrov") + .recipientPhone("0666051373") + .recipientEmail("petrov@gmail.com") + .telegramIsNotify(true) + .viberIsNotify(false) + .build(); } public static User getUserProfile() { return User.builder() - .recipientName("Dima") - .recipientSurname("Petrov") - .recipientPhone("0666051373") - .recipientEmail("petrov@gmail.com") - .telegramBot(getTelegramBotNotifyTrue()) - .build(); + .recipientName("Dima") + .recipientSurname("Petrov") + .recipientPhone("0666051373") + .recipientEmail("petrov@gmail.com") + .telegramBot(getTelegramBotNotifyTrue()) + .build(); } public static TelegramBot getTelegramBotNotifyTrue() { return TelegramBot.builder() - .id(1L) - .chatId(111111L) - .isNotify(true) - .build(); + .id(1L) + .chatId(111111L) + .isNotify(true) + .build(); } public static TelegramBot getTelegramBotNotifyFalse() { return TelegramBot.builder() - .id(1L) - .chatId(111111L) - .isNotify(false) - .build(); + .id(1L) + .chatId(111111L) + .isNotify(false) + .build(); } public static ViberBot getViberBotNotifyTrue() { return ViberBot.builder() - .id(1L) - .chatId("111111L") - .isNotify(true) - .build(); + .id(1L) + .chatId("111111L") + .isNotify(true) + .build(); } public static ViberBot getViberBotNotifyFalse() { return ViberBot.builder() - .id(1L) - .chatId("111111L") - .isNotify(false) - .build(); + .id(1L) + .chatId("111111L") + .isNotify(false) + .build(); } public static UserProfileUpdateDto getUserProfileUpdateDto() { User user = getUserWithBotNotifyTrue(); return UserProfileUpdateDto.builder().addressDto(addressDtoList()) - .recipientName(user.getRecipientName()).recipientSurname(user.getRecipientSurname()) - .recipientPhone(user.getRecipientPhone()) - .alternateEmail("test@email.com") - .telegramIsNotify(true) - .viberIsNotify(true) - .build(); + .recipientName(user.getRecipientName()).recipientSurname(user.getRecipientSurname()) + .recipientPhone(user.getRecipientPhone()) + .alternateEmail("test@email.com") + .telegramIsNotify(true) + .viberIsNotify(true) + .build(); } public static UserProfileUpdateDto getUserProfileUpdateDtoWithBotsIsNotifyFalse() { User user = getUserWithBotNotifyTrue(); return UserProfileUpdateDto.builder().addressDto(addressDtoList()) - .recipientName(user.getRecipientName()).recipientSurname(user.getRecipientSurname()) - .recipientPhone(user.getRecipientPhone()) - .alternateEmail("test@email.com") - .telegramIsNotify(false) - .viberIsNotify(false) - .build(); + .recipientName(user.getRecipientName()).recipientSurname(user.getRecipientSurname()) + .recipientPhone(user.getRecipientPhone()) + .alternateEmail("test@email.com") + .telegramIsNotify(false) + .viberIsNotify(false) + .build(); } public static PersonalDataDto getPersonalDataDto() { return PersonalDataDto.builder() - .id(1L) - .firstName("Max") - .lastName("B") - .phoneNumber("09443332") - .email("dsd@gmail.com") - .build(); + .id(1L) + .firstName("Max") + .lastName("B") + .phoneNumber("09443332") + .email("dsd@gmail.com") + .build(); } public static User getUserPersonalData() { return User.builder() - .id(1L) - .recipientName("Max") - .recipientSurname("B") - .recipientPhone("09443332") - .recipientEmail("dsd@gmail.com") - .build(); + .id(1L) + .recipientName("Max") + .recipientSurname("B") + .recipientPhone("09443332") + .recipientEmail("dsd@gmail.com") + .build(); } public static OptionForColumnDTO getOptionForColumnDTO() { return OptionForColumnDTO.builder() - .key("1") - .en("en") - .ua("en") - .build(); + .key("1") + .en("en") + .ua("en") + .build(); } public static ReceivingStationDto getOptionReceivingStationDto() { return ReceivingStationDto.builder() - .id(1L) - .name("en") - .build(); + .id(1L) + .name("en") + .build(); } public static List
addressList() { List
list = new ArrayList<>(); list.add(Address.builder() - .id(1L) - .entranceNumber("7a") - .houseCorpus("2") - .houseNumber("7") - .street("Gorodotska") - .coordinates(Coordinates.builder().latitude(2.3).longitude(5.6).build()) - .district("Zaliznuchnuy") - .city("Lviv") - .actual(false) - .build()); + .id(1L) + .entranceNumber("7a") + .houseCorpus("2") + .houseNumber("7") + .street("Gorodotska") + .coordinates(Coordinates.builder().latitude(2.3).longitude(5.6).build()) + .district("Zaliznuchnuy") + .city("Lviv") + .actual(false) + .build()); list.add(Address.builder().id(2L) - .entranceNumber("9a") - .houseCorpus("2") - .houseNumber("7") - .street("Shevchenka") - .coordinates(Coordinates.builder().latitude(3.3).longitude(6.6).build()) - .district("Zaliznuchnuy") - .city("Lviv") - .actual(false) - .build()); + .entranceNumber("9a") + .houseCorpus("2") + .houseNumber("7") + .street("Shevchenka") + .coordinates(Coordinates.builder().latitude(3.3).longitude(6.6).build()) + .district("Zaliznuchnuy") + .city("Lviv") + .actual(false) + .build()); return list; } public static AddressDto addressDto() { return AddressDto.builder() - .id(1L) - .entranceNumber("7a") - .houseCorpus("2") - .houseNumber("25") - .street("Street") - .coordinates(Coordinates.builder() - .latitude(50.4459068) - .longitude(30.4477005) - .build()) - .district("Distinct") - .city("City") - .actual(false) - .build(); + .id(1L) + .entranceNumber("7a") + .houseCorpus("2") + .houseNumber("25") + .street("Street") + .coordinates(Coordinates.builder() + .latitude(50.4459068) + .longitude(30.4477005) + .build()) + .district("Distinct") + .city("City") + .actual(false) + .build(); } public static Address getAddress() { return Address.builder() - .id(1L) - .region("Region") - .city("City") - .street("Street") - .district("Distinct") - .houseNumber("25") - .houseCorpus("2") - .entranceNumber("7a") - .addressComment("Address Comment") - .actual(false) - .addressStatus(AddressStatus.NEW) - .coordinates(Coordinates.builder() - .latitude(50.4459068) - .longitude(30.4477005) - .build()) - .regionEn("RegionEng") - .cityEn("CityEng") - .streetEn("StreetEng") - .districtEn("DistinctEng") - .build(); + .id(1L) + .region("Region") + .city("City") + .street("Street") + .district("Distinct") + .houseNumber("25") + .houseCorpus("2") + .entranceNumber("7a") + .addressComment("Address Comment") + .actual(false) + .addressStatus(AddressStatus.NEW) + .coordinates(Coordinates.builder() + .latitude(50.4459068) + .longitude(30.4477005) + .build()) + .regionEn("RegionEng") + .cityEn("CityEng") + .streetEn("StreetEng") + .districtEn("DistinctEng") + .build(); } public static Address getAddressTrue() { return Address.builder() - .id(1L) - .region("Region") - .city("City") - .street("Street") - .district("Distinct") - .houseNumber("25") - .houseCorpus("2") - .entranceNumber("7a") - .addressComment("Address Comment") - .actual(true) - .addressStatus(AddressStatus.NEW) - .coordinates(Coordinates.builder() - .latitude(50.4459068) - .longitude(30.4477005) - .build()) - .regionEn("RegionEng") - .cityEn("CityEng") - .streetEn("StreetEng") - .districtEn("DistinctEng") - .build(); + .id(1L) + .region("Region") + .city("City") + .street("Street") + .district("Distinct") + .houseNumber("25") + .houseCorpus("2") + .entranceNumber("7a") + .addressComment("Address Comment") + .actual(true) + .addressStatus(AddressStatus.NEW) + .coordinates(Coordinates.builder() + .latitude(50.4459068) + .longitude(30.4477005) + .build()) + .regionEn("RegionEng") + .cityEn("CityEng") + .streetEn("StreetEng") + .districtEn("DistinctEng") + .build(); } public static Address getAddress(long id) { return Address.builder() - .id(id) - .region("Вінницька") - .city("Вінниця") - .street("Street") - .district("Distinct") - .houseNumber("25") - .houseCorpus("2") - .entranceNumber("7a") - .addressComment("Address Comment") - .actual(false) - .addressStatus(AddressStatus.NEW) - .coordinates(Coordinates.builder() - .latitude(50.4459068) - .longitude(30.4477005) - .build()) - .regionEn("RegionEng") - .cityEn("CityEng") - .streetEn("StreetEng") - .districtEn("DistinctEng") - .build(); + .id(id) + .region("Вінницька") + .city("Вінниця") + .street("Street") + .district("Distinct") + .houseNumber("25") + .houseCorpus("2") + .entranceNumber("7a") + .addressComment("Address Comment") + .actual(false) + .addressStatus(AddressStatus.NEW) + .coordinates(Coordinates.builder() + .latitude(50.4459068) + .longitude(30.4477005) + .build()) + .regionEn("RegionEng") + .cityEn("CityEng") + .streetEn("StreetEng") + .districtEn("DistinctEng") + .build(); } public static LocationDto getLocationApiDto() { return LocationDto.builder() - .locationNameMap(Map.of("name", "Вінниця", "name_en", "Vinnytsa")) - .build(); + .locationNameMap(Map.of("name", "Вінниця", "name_en", "Vinnytsa")) + .build(); } public static List getLocationApiDtoList() { LocationDto locationDto1 = LocationDto.builder() - .locationNameMap(Map.of("name", "Вінниця", "name_en", "Vinnytsa")) - .build(); + .locationNameMap(Map.of("name", "Вінниця", "name_en", "Vinnytsa")) + .build(); return Arrays.asList(locationDto1); } public static DistrictDto getDistrictDto() { return DistrictDto.builder() - .nameUa("Вінниця") - .nameEn("Vinnytsa") - .build(); + .nameUa("Вінниця") + .nameEn("Vinnytsa") + .build(); } public static AddressDto getAddressDto(long id) { return AddressDto.builder() - .id(id) - .region("Вінницька") - .city("Вінниця") - .street("Street") - .district("Distinct") - .houseNumber("25") - .houseCorpus("2") - .entranceNumber("7a") - .addressComment("Address Comment") - .actual(false) - .coordinates(Coordinates.builder() - .latitude(50.4459068) - .longitude(30.4477005) - .build()) - .regionEn("RegionEng") - .cityEn("CityEng") - .streetEn("StreetEng") - .districtEn("DistinctEng") - .addressRegionDistrictList(Arrays.asList(getDistrictDto())) - .build(); + .id(id) + .region("Вінницька") + .city("Вінниця") + .street("Street") + .district("Distinct") + .houseNumber("25") + .houseCorpus("2") + .entranceNumber("7a") + .addressComment("Address Comment") + .actual(false) + .coordinates(Coordinates.builder() + .latitude(50.4459068) + .longitude(30.4477005) + .build()) + .regionEn("RegionEng") + .cityEn("CityEng") + .streetEn("StreetEng") + .districtEn("DistinctEng") + .addressRegionDistrictList(Arrays.asList(getDistrictDto())) + .build(); } public static OrderAddress getOrderAddress() { return OrderAddress.builder() - .region("Region") - .city("City") - .street("Street") - .district("Distinct") - .houseNumber("25") - .houseCorpus("2") - .entranceNumber("7a") - .addressComment("Address Comment") - .actual(false) - .addressStatus(AddressStatus.NEW) - .coordinates(Coordinates.builder() - .latitude(50.4459068) - .longitude(30.4477005) - .build()) - .regionEn("RegionEng") - .cityEn("CityEng") - .streetEn("StreetEng") - .districtEn("DistinctEng") - .build(); + .region("Region") + .city("City") + .street("Street") + .district("Distinct") + .houseNumber("25") + .houseCorpus("2") + .entranceNumber("7a") + .addressComment("Address Comment") + .actual(false) + .addressStatus(AddressStatus.NEW) + .coordinates(Coordinates.builder() + .latitude(50.4459068) + .longitude(30.4477005) + .build()) + .regionEn("RegionEng") + .cityEn("CityEng") + .streetEn("StreetEng") + .districtEn("DistinctEng") + .build(); } public static UbsCustomersDto getUbsCustomersDto() { return UbsCustomersDto.builder() - .name("Ivan Michalov") - .email("michalov@gmail.com") - .phoneNumber("095531111") - .build(); + .name("Ivan Michalov") + .email("michalov@gmail.com") + .phoneNumber("095531111") + .build(); } public static Position getPosition() { return Position.builder() - .id(1L) - .name("Водій") - .nameEn("Driver") - .build(); + .id(1L) + .name("Водій") + .nameEn("Driver") + .build(); } public static PositionDto getPositionDto(Long id) { return PositionDto.builder() - .id(id) - .name("Водій") - .nameEn("Driver") - .build(); + .id(id) + .name("Водій") + .nameEn("Driver") + .build(); } public static ReceivingStation getReceivingStation() { return ReceivingStation.builder() - .id(1L) - .name("Петрівка") - .createDate(LocalDate.EPOCH) - .createdBy(getEmployee()) - .build(); + .id(1L) + .name("Петрівка") + .createDate(LocalDate.EPOCH) + .createdBy(getEmployee()) + .build(); } public static ReceivingStationDto getReceivingStationDto() { return ReceivingStationDto.builder() - .id(1L) - .name("Петрівка") - .build(); + .id(1L) + .name("Петрівка") + .build(); } public static List getReceivingList() { @@ -1808,135 +1810,135 @@ public static List getReceivingList() { public static Violation getViolation() { LocalDateTime localdatetime = LocalDateTime.of( - 2021, Month.MARCH, - 16, 13, 00, 00); + 2021, Month.MARCH, + 16, 13, 00, 00); return Violation.builder() - .id(1L) - .order(Order.builder() - .id(1L).user(ModelUtils.getTestUser()).build()) - .violationLevel(MAJOR) - .description("violation1") - .violationDate(localdatetime) - .images(new LinkedList<>()) - .addedByUser(getTestUser()) - .build(); + .id(1L) + .order(Order.builder() + .id(1L).user(ModelUtils.getTestUser()).build()) + .violationLevel(MAJOR) + .description("violation1") + .violationDate(localdatetime) + .images(new LinkedList<>()) + .addedByUser(getTestUser()) + .build(); } public static Violation getViolation2() { LocalDateTime localdatetime = LocalDateTime.of( - 2021, Month.MARCH, - 16, 13, 00, 00); + 2021, Month.MARCH, + 16, 13, 00, 00); return Violation.builder() - .id(1L) - .order(Order.builder() - .id(1L).user(ModelUtils.getTestUser()).build()) - .violationLevel(MAJOR) - .description("violation1") - .violationDate(localdatetime) - .images(List.of("as", "s")) - .build(); + .id(1L) + .order(Order.builder() + .id(1L).user(ModelUtils.getTestUser()).build()) + .violationLevel(MAJOR) + .description("violation1") + .violationDate(localdatetime) + .images(List.of("as", "s")) + .build(); } public static ViolationDetailInfoDto getViolationDetailInfoDto() { LocalDateTime localdatetime = LocalDateTime.of( - 2021, Month.MARCH, - 16, 13, 00, 00); + 2021, Month.MARCH, + 16, 13, 00, 00); return ViolationDetailInfoDto.builder() - .orderId(1L) - .addedByUser("Alan Po") - .violationLevel(MAJOR) - .description("violation1") - .images(new ArrayList<>()) - .violationDate(localdatetime) - .build(); + .orderId(1L) + .addedByUser("Alan Po") + .violationLevel(MAJOR) + .description("violation1") + .images(new ArrayList<>()) + .violationDate(localdatetime) + .build(); } public static OrderPaymentDetailDto getOrderPaymentDetailDto() { return OrderPaymentDetailDto.builder() - .amount(95000L + 1000 + 70000) - .certificates(-1000) - .pointsToUse(-70000) - .amountToPay(95000L) - .currency("UAH") - .build(); + .amount(95000L + 1000 + 70000) + .certificates(-1000) + .pointsToUse(-70000) + .amountToPay(95000L) + .currency("UAH") + .build(); } public static Payment getPayment() { return Payment.builder() - .id(1L) - .paymentStatus(PaymentStatus.PAID) - .amount(95000L) - .currency("UAH") - .orderStatus("approved") - .responseStatus("approved") - .order(getOrder()) - .paymentId("1") - .settlementDate(LocalDate.now().toString()) - .fee(0L) - .build(); + .id(1L) + .paymentStatus(PaymentStatus.PAID) + .amount(95000L) + .currency("UAH") + .orderStatus("approved") + .responseStatus("approved") + .order(getOrder()) + .paymentId("1") + .settlementDate(LocalDate.now().toString()) + .fee(0L) + .build(); } public static User getUser() { return User.builder() - .id(1L) - .addresses(singletonList(getAddress())) - .recipientEmail("someUser@gmail.com") - .recipientPhone("962473289") - .recipientSurname("Ivanov") - .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") - .recipientName("Taras") - .uuid("uuid") - .ubsUsers(getUbsUsers()) - .currentPoints(100) - .build(); + .id(1L) + .addresses(singletonList(getAddress())) + .recipientEmail("someUser@gmail.com") + .recipientPhone("962473289") + .recipientSurname("Ivanov") + .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") + .recipientName("Taras") + .uuid("uuid") + .ubsUsers(getUbsUsers()) + .currentPoints(100) + .build(); } public static User getUserWithBotNotifyTrue_AddressTrue() { return User.builder() - .id(1L) - .addresses(singletonList(getAddressTrue())) - .recipientEmail("someUser@gmail.com") - .recipientPhone("962473289") - .recipientSurname("Ivanov") - .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") - .recipientName("Taras") - .uuid("uuid") - .ubsUsers(getUbsUsers()) - .currentPoints(100) - .telegramBot(getTelegramBotNotifyTrue()) - .build(); + .id(1L) + .addresses(singletonList(getAddressTrue())) + .recipientEmail("someUser@gmail.com") + .recipientPhone("962473289") + .recipientSurname("Ivanov") + .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") + .recipientName("Taras") + .uuid("uuid") + .ubsUsers(getUbsUsers()) + .currentPoints(100) + .telegramBot(getTelegramBotNotifyTrue()) + .build(); } public static User getUserWithBotNotifyTrue() { return User.builder() - .id(1L) - .addresses(singletonList(getAddress())) - .recipientEmail("someUser@gmail.com") - .recipientPhone("962473289") - .recipientSurname("Ivanov") - .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") - .recipientName("Taras") - .uuid("uuid") - .ubsUsers(getUbsUsers()) - .currentPoints(100) - .telegramBot(getTelegramBotNotifyTrue()) - .build(); + .id(1L) + .addresses(singletonList(getAddress())) + .recipientEmail("someUser@gmail.com") + .recipientPhone("962473289") + .recipientSurname("Ivanov") + .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") + .recipientName("Taras") + .uuid("uuid") + .ubsUsers(getUbsUsers()) + .currentPoints(100) + .telegramBot(getTelegramBotNotifyTrue()) + .build(); } public static User getUserWithBotNotifyFalse() { return User.builder() - .id(1L) - .addresses(singletonList(getAddress())) - .recipientEmail("someUser@gmail.com") - .recipientPhone("962473289") - .recipientSurname("Ivanov") - .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") - .recipientName("Taras") - .uuid("uuid") - .ubsUsers(getUbsUsers()) - .currentPoints(100) - .telegramBot(getTelegramBotNotifyFalse()) - .build(); + .id(1L) + .addresses(singletonList(getAddress())) + .recipientEmail("someUser@gmail.com") + .recipientPhone("962473289") + .recipientSurname("Ivanov") + .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") + .recipientName("Taras") + .uuid("uuid") + .ubsUsers(getUbsUsers()) + .currentPoints(100) + .telegramBot(getTelegramBotNotifyFalse()) + .build(); } public static Set getUbsUsers() { @@ -1947,205 +1949,205 @@ public static Set getUbsUsers() { public static Payment getManualPayment() { return Payment.builder() - .settlementDate("02-08-2021") - .amount(500L) - .paymentStatus(PaymentStatus.PAID) - .paymentId("1l") - .receiptLink("somelink.com") - .currency("UAH") - .imagePath("") - .order(getOrder()) - .build(); + .settlementDate("02-08-2021") + .amount(500L) + .paymentStatus(PaymentStatus.PAID) + .paymentId("1l") + .receiptLink("somelink.com") + .currency("UAH") + .imagePath("") + .order(getOrder()) + .build(); } public static ManualPaymentRequestDto getManualPaymentRequestDto() { return ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021") - .amount(500L) - .receiptLink("link") - .paymentId("1") - .imagePath("fdhgh") - .build(); + .settlementdate("02-08-2021") + .amount(500L) + .receiptLink("link") + .paymentId("1") + .imagePath("fdhgh") + .build(); } public static Order getOrderTest() { return Order.builder() - .id(1L) - .orderStatus(OrderStatus.FORMED) - .payment(singletonList(Payment.builder() - .id(1L) - .amount(350L) - .paymentStatus(PaymentStatus.PAID) - .build())) - .ubsUser(UBSuser.builder() - .firstName("oleh") - .lastName("ivanov") - .email("mail@mail.ua") - .senderEmail("test@email.ua") - .senderPhoneNumber("+380974563223") - .senderLastName("TestLast") - .senderFirstName("TestFirst") .id(1L) - .phoneNumber("067894522") - .orderAddress(OrderAddress.builder() - .id(1L) - .city("Lviv") - .street("Levaya") - .district("frankivskiy") - .entranceNumber("5") - .addressComment("near mall") - .houseCorpus(null) - .houseNumber("4R") - .coordinates(Coordinates.builder() - .latitude(49.83) - .longitude(23.88) + .orderStatus(OrderStatus.FORMED) + .payment(singletonList(Payment.builder() + .id(1L) + .amount(350L) + .paymentStatus(PaymentStatus.PAID) + .build())) + .ubsUser(UBSuser.builder() + .firstName("oleh") + .lastName("ivanov") + .email("mail@mail.ua") + .senderEmail("test@email.ua") + .senderPhoneNumber("+380974563223") + .senderLastName("TestLast") + .senderFirstName("TestFirst") + .id(1L) + .phoneNumber("067894522") + .orderAddress(OrderAddress.builder() + .id(1L) + .city("Lviv") + .street("Levaya") + .district("frankivskiy") + .entranceNumber("5") + .addressComment("near mall") + .houseCorpus(null) + .houseNumber("4R") + .coordinates(Coordinates.builder() + .latitude(49.83) + .longitude(23.88) + .build()) + .build()) .build()) - .build()) - .build()) - .certificates(Collections.emptySet()) - .cancellationComment("Garbage disappeared") - .cancellationReason(CancellationReason.OTHER) - .pointsToUse(700) - .user(User.builder() - .id(1L) - .recipientName("Yuriy") - .recipientSurname("Gerasum") - .build()) - .build(); + .certificates(Collections.emptySet()) + .cancellationComment("Garbage disappeared") + .cancellationReason(CancellationReason.OTHER) + .pointsToUse(700) + .user(User.builder() + .id(1L) + .recipientName("Yuriy") + .recipientSurname("Gerasum") + .build()) + .build(); } public static Order getFormedOrder() { return Order.builder() - .id(1L) - .events(List.of(new Event(1L, LocalDateTime.now(), - "Roman", "Roman", new Order()))) - .orderStatus(OrderStatus.FORMED) - .payment(singletonList(Payment.builder() .id(1L) - .amount(350L) - .paymentStatus(PaymentStatus.PAID) - .build())) - .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) - .amountOfBagsOrdered(Collections.singletonMap(1, 2)) - .exportedQuantity(Collections.singletonMap(1, 1)) - .amountOfBagsOrdered(Map.of(1, 1)) - .confirmedQuantity(Map.of(1, 0)) - .exportedQuantity(Map.of(1, 1)) - .pointsToUse(100) - .user(User.builder().id(1L).currentPoints(100).build()) - .build(); + .events(List.of(new Event(1L, LocalDateTime.now(), + "Roman", "Roman", new Order()))) + .orderStatus(OrderStatus.FORMED) + .payment(singletonList(Payment.builder() + .id(1L) + .amount(350L) + .paymentStatus(PaymentStatus.PAID) + .build())) + .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) + .amountOfBagsOrdered(Collections.singletonMap(1, 2)) + .exportedQuantity(Collections.singletonMap(1, 1)) + .amountOfBagsOrdered(Map.of(1, 1)) + .confirmedQuantity(Map.of(1, 0)) + .exportedQuantity(Map.of(1, 1)) + .pointsToUse(100) + .user(User.builder().id(1L).currentPoints(100).build()) + .build(); } public static Order getCanceledPaidOrder() { return Order.builder() - .id(1L) - .events(List.of(new Event(1L, LocalDateTime.now(), - "Roman", "Roman", new Order()))) - .orderStatus(OrderStatus.CANCELED) - .payment(singletonList(Payment.builder() .id(1L) - .amount(350L) - .paymentStatus(PaymentStatus.PAID) - .build())) - .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) - .amountOfBagsOrdered(Collections.singletonMap(1, 2)) - .exportedQuantity(Collections.singletonMap(1, 1)) - .amountOfBagsOrdered(Map.of(1, 1)) - .confirmedQuantity(Map.of(1, 1)) - .exportedQuantity(Map.of(1, 1)) - .pointsToUse(100) - .user(User.builder().id(1L).currentPoints(100).build()) - .build(); + .events(List.of(new Event(1L, LocalDateTime.now(), + "Roman", "Roman", new Order()))) + .orderStatus(OrderStatus.CANCELED) + .payment(singletonList(Payment.builder() + .id(1L) + .amount(350L) + .paymentStatus(PaymentStatus.PAID) + .build())) + .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) + .amountOfBagsOrdered(Collections.singletonMap(1, 2)) + .exportedQuantity(Collections.singletonMap(1, 1)) + .amountOfBagsOrdered(Map.of(1, 1)) + .confirmedQuantity(Map.of(1, 1)) + .exportedQuantity(Map.of(1, 1)) + .pointsToUse(100) + .user(User.builder().id(1L).currentPoints(100).build()) + .build(); } public static Order getAdjustmentPaidOrder() { return Order.builder() - .id(1L) - .events(List.of(new Event(1L, LocalDateTime.now(), - "Roman", "Roman", new Order()))) - .orderStatus(OrderStatus.ADJUSTMENT) - .payment(singletonList(Payment.builder() .id(1L) - .amount(300000L) - .paymentStatus(PaymentStatus.PAID) - .build())) - .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) - .amountOfBagsOrdered(Collections.singletonMap(1, 2)) - .exportedQuantity(Collections.singletonMap(1, 1)) - .amountOfBagsOrdered(Map.of(1, 1)) - .confirmedQuantity(Map.of(1, 1)) - .exportedQuantity(Map.of(2, 2)) - .pointsToUse(100) - .user(User.builder().id(1L).currentPoints(100).build()) - .build(); + .events(List.of(new Event(1L, LocalDateTime.now(), + "Roman", "Roman", new Order()))) + .orderStatus(OrderStatus.ADJUSTMENT) + .payment(singletonList(Payment.builder() + .id(1L) + .amount(300000L) + .paymentStatus(PaymentStatus.PAID) + .build())) + .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) + .amountOfBagsOrdered(Collections.singletonMap(1, 2)) + .exportedQuantity(Collections.singletonMap(1, 1)) + .amountOfBagsOrdered(Map.of(1, 1)) + .confirmedQuantity(Map.of(1, 1)) + .exportedQuantity(Map.of(2, 2)) + .pointsToUse(100) + .user(User.builder().id(1L).currentPoints(100).build()) + .build(); } public static Order getFormedHalfPaidOrder() { return Order.builder() - .id(1L) - .events(List.of(new Event(1L, LocalDateTime.now(), - "Roman", "Roman", new Order()))) - .orderStatus(OrderStatus.FORMED) - .payment(singletonList(Payment.builder() .id(1L) - .amount(100L) - .paymentStatus(PaymentStatus.PAID) - .build())) - .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) - .amountOfBagsOrdered(Collections.singletonMap(1, 1)) - .exportedQuantity(Collections.singletonMap(1, 1)) - .amountOfBagsOrdered(Map.of(1, 1)) - .confirmedQuantity(Map.of(1, 1)) - .exportedQuantity(Map.of(1, 1)) - .pointsToUse(50) - .user(User.builder().id(1L).currentPoints(500).build()) - .build(); + .events(List.of(new Event(1L, LocalDateTime.now(), + "Roman", "Roman", new Order()))) + .orderStatus(OrderStatus.FORMED) + .payment(singletonList(Payment.builder() + .id(1L) + .amount(100L) + .paymentStatus(PaymentStatus.PAID) + .build())) + .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) + .amountOfBagsOrdered(Collections.singletonMap(1, 1)) + .exportedQuantity(Collections.singletonMap(1, 1)) + .amountOfBagsOrdered(Map.of(1, 1)) + .confirmedQuantity(Map.of(1, 1)) + .exportedQuantity(Map.of(1, 1)) + .pointsToUse(50) + .user(User.builder().id(1L).currentPoints(500).build()) + .build(); } public static Order getCanceledHalfPaidOrder() { return Order.builder() - .id(1L) - .events(List.of(new Event(1L, LocalDateTime.now(), - "Roman", "Roman", new Order()))) - .orderStatus(OrderStatus.CANCELED) - .payment(singletonList(Payment.builder() .id(1L) - .amount(1000L) - .paymentStatus(PaymentStatus.PAID) - .build())) - .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) - .amountOfBagsOrdered(Collections.singletonMap(1, 1)) - .exportedQuantity(Collections.singletonMap(1, 1)) - .amountOfBagsOrdered(Map.of(1, 1)) - .confirmedQuantity(Map.of(1, 1)) - .exportedQuantity(Map.of(1, 1)) - .pointsToUse(50) - .user(User.builder().id(1L).currentPoints(500).build()) - .build(); + .events(List.of(new Event(1L, LocalDateTime.now(), + "Roman", "Roman", new Order()))) + .orderStatus(OrderStatus.CANCELED) + .payment(singletonList(Payment.builder() + .id(1L) + .amount(1000L) + .paymentStatus(PaymentStatus.PAID) + .build())) + .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) + .amountOfBagsOrdered(Collections.singletonMap(1, 1)) + .exportedQuantity(Collections.singletonMap(1, 1)) + .amountOfBagsOrdered(Map.of(1, 1)) + .confirmedQuantity(Map.of(1, 1)) + .exportedQuantity(Map.of(1, 1)) + .pointsToUse(50) + .user(User.builder().id(1L).currentPoints(500).build()) + .build(); } public static OrderDetailStatusRequestDto getTestOrderDetailStatusRequestDto() { return OrderDetailStatusRequestDto.builder() - .orderStatus("FORMED") - .adminComment("all good") - .orderPaymentStatus("PAID").build(); + .orderStatus("FORMED") + .adminComment("all good") + .orderPaymentStatus("PAID").build(); } public static OrderDetailStatusDto getTestOrderDetailStatusDto() { return OrderDetailStatusDto.builder() - .orderStatus("FORMED") - .paymentStatus("PAID") - .date("15-05-2021") - .build(); + .orderStatus("FORMED") + .paymentStatus("PAID") + .date("15-05-2021") + .build(); } public static EmployeeOrderPosition getEmployeeOrderPosition() { return EmployeeOrderPosition.builder() - .id(1L) - .order(getOrder()) - .position(getPosition()) - .employee(getEmployee()) - .build(); + .id(1L) + .order(getOrder()) + .position(getPosition()) + .employee(getEmployee()) + .build(); } public static EmployeePositionDtoRequest getEmployeePositionDtoRequest() { @@ -2154,81 +2156,81 @@ public static EmployeePositionDtoRequest getEmployeePositionDtoRequest() { Map currentPositionEmployees = new HashMap<>(); String value = getEmployee().getFirstName() + " " + getEmployee().getLastName(); allPositionsEmployees.put(getPositionDto(positionId), new ArrayList<>(List.of(EmployeeNameIdDto.builder() - .id(positionId) - .name(value) - .build()))); + .id(positionId) + .name(value) + .build()))); currentPositionEmployees.put(getPositionDto(positionId), value); return EmployeePositionDtoRequest.builder() - .orderId(1L) - .allPositionsEmployees(allPositionsEmployees) - .currentPositionEmployees(currentPositionEmployees) - .build(); + .orderId(1L) + .allPositionsEmployees(allPositionsEmployees) + .currentPositionEmployees(currentPositionEmployees) + .build(); } private static Order createOrder() { return Order.builder() - .id(1L) - .orderStatus(OrderStatus.FORMED) - .ubsUser(createUbsUser()) - .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").build()) - .orderDate(LocalDateTime.of(2021, 8, 5, 21, 47, 5)) - .build(); + .id(1L) + .orderStatus(OrderStatus.FORMED) + .ubsUser(createUbsUser()) + .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").build()) + .orderDate(LocalDateTime.of(2021, 8, 5, 21, 47, 5)) + .build(); } private static UBSuser createUbsUser() { return UBSuser.builder() - .id(10L) - .orderAddress(createAddress()) - .build(); + .id(10L) + .orderAddress(createAddress()) + .build(); } private static OrderAddress createAddress() { return OrderAddress.builder() - .id(2L) - .build(); + .id(2L) + .build(); } private static OrderAddressExportDetailsDtoUpdate createOrderAddressDtoUpdate() { return OrderAddressExportDetailsDtoUpdate.builder() - .addressId(1L) - .addressHouseNumber("1") - .addressEntranceNumber("3") - .addressDistrict("District") - .addressDistrictEng("DistrictEng") - .addressStreet("Street") - .addressStreetEng("StreetEng") - .addressHouseCorpus("2") - .addressCity("City") - .addressCityEng("CityEng") - .addressRegion("Region") - .addressRegionEng("RegionEng") - .build(); + .addressId(1L) + .addressHouseNumber("1") + .addressEntranceNumber("3") + .addressDistrict("District") + .addressDistrictEng("DistrictEng") + .addressStreet("Street") + .addressStreetEng("StreetEng") + .addressHouseCorpus("2") + .addressCity("City") + .addressCityEng("CityEng") + .addressRegion("Region") + .addressRegionEng("RegionEng") + .build(); } private static OrderAddressDtoResponse createOrderAddressDtoResponse() { return OrderAddressDtoResponse.builder() - .houseNumber("1") - .entranceNumber("3") - .district("District") - .districtEng("DistrictEng") - .street("Street") - .streetEng("StreetEng") - .houseCorpus("2") - .build(); + .houseNumber("1") + .entranceNumber("3") + .district("District") + .districtEng("DistrictEng") + .street("Street") + .streetEng("StreetEng") + .houseCorpus("2") + .build(); } private static List createPaymentList() { return List.of( - Payment.builder() - .id(1L) - .paymentStatus(PaymentStatus.PAID) - .amount(100L) - .build(), - Payment.builder() - .id(2L) - .paymentStatus(PaymentStatus.PAID) - .amount(50L) - .build()); + Payment.builder() + .id(1L) + .paymentStatus(PaymentStatus.PAID) + .amount(100L) + .build(), + Payment.builder() + .id(2L) + .paymentStatus(PaymentStatus.PAID) + .amount(50L) + .build()); } private static OrderDetailStatusDto createOrderDetailStatusDto() { @@ -2236,141 +2238,141 @@ private static OrderDetailStatusDto createOrderDetailStatusDto() { String orderDate = TEST_ORDER.getOrderDate().toLocalDate().format(formatter); return OrderDetailStatusDto.builder() - .orderStatus(TEST_ORDER.getOrderStatus().name()) - .paymentStatus(TEST_PAYMENT_LIST.get(0).getPaymentStatus().name()) - .date(orderDate) - .build(); + .orderStatus(TEST_ORDER.getOrderStatus().name()) + .paymentStatus(TEST_PAYMENT_LIST.get(0).getPaymentStatus().name()) + .date(orderDate) + .build(); } private static BagInfoDto createBagInfoDto() { return BagInfoDto.builder() - .id(1) - .capacity(20) - .name("Name") - .nameEng("NameEng") - .price(100.00) - .build(); + .id(1) + .capacity(20) + .name("Name") + .nameEng("NameEng") + .price(100.00) + .build(); } private static List createBagMappingDtoList() { return Collections.singletonList( - BagMappingDto.builder() - .amount(4) - .build()); + BagMappingDto.builder() + .amount(4) + .build()); } private static Bag createBag() { return Bag.builder() - .id(1) - .name("Name") - .nameEng("NameEng") - .capacity(20) - .price(100_00L) - .commission(0L) - .fullPrice(100_00L) - .description("some_description") - .descriptionEng("some_eng_description") - .limitIncluded(true) - .createdAt(LocalDate.now()) - .createdBy(Employee.builder() - .id(1L) - .build()) - .build(); + .id(1) + .name("Name") + .nameEng("NameEng") + .capacity(20) + .price(100_00L) + .commission(0L) + .fullPrice(100_00L) + .description("some_description") + .descriptionEng("some_eng_description") + .limitIncluded(true) + .createdAt(LocalDate.now()) + .createdBy(Employee.builder() + .id(1L) + .build()) + .build(); } private static OrderBag createOrderBag() { return OrderBag.builder() - .id(1L) - .name("Name") - .nameEng("NameEng") - .capacity(20) - .price(100_00L) - .order(createOrder()) - .bag(createBag()) - .build(); + .id(1L) + .name("Name") + .nameEng("NameEng") + .capacity(20) + .price(100_00L) + .order(createOrder()) + .bag(createBag()) + .build(); } private static BagForUserDto createBagForUserDto() { return BagForUserDto.builder() - .service("Name") - .serviceEng("NameEng") - .capacity(20) - .fullPrice(100.0) - .count(22) - .totalPrice(2200.0) - .build(); + .service("Name") + .serviceEng("NameEng") + .capacity(20) + .fullPrice(100.0) + .count(22) + .totalPrice(2200.0) + .build(); } private static OrderDetailInfoDto createOrderDetailInfoDto() { return OrderDetailInfoDto.builder() - .amount(5) - .capacity(4) - .build(); + .amount(5) + .capacity(4) + .build(); } public static OrderCancellationReasonDto getCancellationDto() { return OrderCancellationReasonDto.builder() - .cancellationReason(CancellationReason.OTHER) - .cancellationComment("Garbage disappeared") - .build(); + .cancellationReason(CancellationReason.OTHER) + .cancellationComment("Garbage disappeared") + .build(); } private static OrderAddressDtoRequest createOrderDtoRequest() { return OrderAddressDtoRequest.builder() - .id(13L).city("Kyiv").district("Svyatoshyn") - .entranceNumber("1").houseCorpus("1").houseNumber("55").street("Peremohy av.") - .actual(true).coordinates(new Coordinates(12.5, 34.5)) - .build(); + .id(13L).city("Kyiv").district("Svyatoshyn") + .entranceNumber("1").houseCorpus("1").houseNumber("55").street("Peremohy av.") + .actual(true).coordinates(new Coordinates(12.5, 34.5)) + .build(); } public static User getUserWithLastLocation() { Location location = new Location(); location.setLocationStatus(LocationStatus.ACTIVE); return User.builder() - .id(1L) - .addresses(singletonList(getAddress())) - .recipientEmail("someUser@gmail.com") - .recipientPhone("962473289") - .recipientSurname("Ivanov") - .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") - .recipientName("Taras") - .build(); + .id(1L) + .addresses(singletonList(getAddress())) + .recipientEmail("someUser@gmail.com") + .recipientPhone("962473289") + .recipientSurname("Ivanov") + .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") + .recipientName("Taras") + .build(); } public static List getLocationList() { return List.of(Location.builder() - .locationStatus(LocationStatus.ACTIVE) - .nameEn("Kyiv") - .id(1L) - .nameUk("Київ") - .region(getRegion()) - .coordinates(getCoordinates()) - .build()); + .locationStatus(LocationStatus.ACTIVE) + .nameEn("Kyiv") + .id(1L) + .nameUk("Київ") + .region(getRegion()) + .coordinates(getCoordinates()) + .build()); } public static List getLocationList2() { return List.of(Location.builder() - .id(1L) - .region( - Region.builder() - .id(1L) - .build()) - .build(), - Location.builder() - .id(2L) - .region( - Region.builder() + .id(1L) + .region( + Region.builder() + .id(1L) + .build()) + .build(), + Location.builder() .id(2L) - .build()) - .build()); + .region( + Region.builder() + .id(2L) + .build()) + .build()); } private static Employee createEmployee() { return Employee.builder() - .id(1L) - .firstName("Test") - .lastName("Test") - .build(); + .id(1L) + .firstName("Test") + .lastName("Test") + .build(); } private static Map createMap() { @@ -2385,120 +2387,120 @@ private static List createAdditionalBagInfoDtoList() { private static AdditionalBagInfoDto createAdditionalBagInfoDto() { return AdditionalBagInfoDto.builder() - .recipientEmail("test@mail.com") - .build(); + .recipientEmail("test@mail.com") + .build(); } private static User createUser() { return User.builder() - .id(1L) - .uuid("Test") - .recipientEmail("test@mail.com") - .build(); + .id(1L) + .uuid("Test") + .recipientEmail("test@mail.com") + .build(); } public static Set getCoordinatesDtoSet() { Set set = new HashSet<>(); set.add(CoordinatesDto.builder() - .latitude(49.83) - .longitude(23.88) - .build()); + .latitude(49.83) + .longitude(23.88) + .build()); return set; } private static NotificationShortDto createNotificationShortDto() { return NotificationShortDto.builder() - .id(1L) - .orderId(1L) - .title("Title") - .notificationTime(LocalDateTime.of(2021, 9, 17, 20, 26, 10)) - .read(false) - .build(); + .id(1L) + .orderId(1L) + .title("Title") + .notificationTime(LocalDateTime.of(2021, 9, 17, 20, 26, 10)) + .read(false) + .build(); } private static PageableDto createPageableDto() { return new PageableDto<>( - TEST_NOTIFICATION_SHORT_DTO_LIST, - 1, - 0, - 1); + TEST_NOTIFICATION_SHORT_DTO_LIST, + 1, + 0, + 1); } private static NotificationTemplateWithPlatformsUpdateDto createNotificationTemplateWithPlatformsUpdateDto() { return NotificationTemplateWithPlatformsUpdateDto.builder() - .notificationTemplateMainInfoDto(createNotificationTemplateMainInfoDto()) - .platforms(List.of( - createNotificationPlatformDto(SITE))) - .build(); + .notificationTemplateMainInfoDto(createNotificationTemplateMainInfoDto()) + .platforms(List.of( + createNotificationPlatformDto(SITE))) + .build(); } private static NotificationTemplateWithPlatformsDto createNotificationTemplateWithPlatformsDto() { return NotificationTemplateWithPlatformsDto.builder() - .notificationTemplateMainInfoDto(createNotificationTemplateMainInfoDto()) - .platforms(List.of(createNotificationPlatformDto(SITE))) - .build(); + .notificationTemplateMainInfoDto(createNotificationTemplateMainInfoDto()) + .platforms(List.of(createNotificationPlatformDto(SITE))) + .build(); } private static NotificationPlatformDto createNotificationPlatformDto(NotificationReceiverType receiverType) { return NotificationPlatformDto.builder() - .id(1L) - .receiverType(receiverType) - .nameEng("NameEng") - .body("Body") - .bodyEng("BodyEng") - .status(ACTIVE) - .build(); + .id(1L) + .receiverType(receiverType) + .nameEng("NameEng") + .body("Body") + .bodyEng("BodyEng") + .status(ACTIVE) + .build(); } private static NotificationTemplateDto createNotificationTemplateDto() { return NotificationTemplateDto.builder() - .id(1L) - .notificationTemplateMainInfoDto(createNotificationTemplateMainInfoDto()) - .build(); + .id(1L) + .notificationTemplateMainInfoDto(createNotificationTemplateMainInfoDto()) + .build(); } private static NotificationTemplateMainInfoDto createNotificationTemplateMainInfoDto() { return NotificationTemplateMainInfoDto.builder() - .type(UNPAID_ORDER) - .trigger(ORDER_NOT_PAID_FOR_3_DAYS) - .triggerDescription("Trigger") - .triggerDescriptionEng("TriggerEng") - .time(AT_6PM_3DAYS_AFTER_ORDER_FORMED_NOT_PAID) - .timeDescription("Description") - .timeDescriptionEng("DescriptionEng") - .schedule("0 0 18 * * ?") - .title("Title") - .titleEng("TitleEng") - .notificationStatus(ACTIVE) - .build(); + .type(UNPAID_ORDER) + .trigger(ORDER_NOT_PAID_FOR_3_DAYS) + .triggerDescription("Trigger") + .triggerDescriptionEng("TriggerEng") + .time(AT_6PM_3DAYS_AFTER_ORDER_FORMED_NOT_PAID) + .timeDescription("Description") + .timeDescriptionEng("DescriptionEng") + .schedule("0 0 18 * * ?") + .title("Title") + .titleEng("TitleEng") + .notificationStatus(ACTIVE) + .build(); } private static NotificationTemplate createNotificationTemplate() { return NotificationTemplate.builder() - .id(1L) - .notificationType(UNPAID_ORDER) - .trigger(ORDER_NOT_PAID_FOR_3_DAYS) - .time(AT_6PM_3DAYS_AFTER_ORDER_FORMED_NOT_PAID) - .schedule("0 0 18 * * ?") - .title("Title") - .titleEng("TitleEng") - .notificationStatus(ACTIVE) - .notificationPlatforms(List.of( - createNotificationPlatform(SITE), - createNotificationPlatform(EMAIL), - createNotificationPlatform(MOBILE))) - .build(); + .id(1L) + .notificationType(UNPAID_ORDER) + .trigger(ORDER_NOT_PAID_FOR_3_DAYS) + .time(AT_6PM_3DAYS_AFTER_ORDER_FORMED_NOT_PAID) + .schedule("0 0 18 * * ?") + .title("Title") + .titleEng("TitleEng") + .notificationStatus(ACTIVE) + .notificationPlatforms(List.of( + createNotificationPlatform(SITE), + createNotificationPlatform(EMAIL), + createNotificationPlatform(MOBILE))) + .build(); } public static NotificationPlatform createNotificationPlatform( - NotificationReceiverType receiverType) { + NotificationReceiverType receiverType) { return NotificationPlatform.builder() - .id(1L) - .body("Body") - .bodyEng("BodyEng") - .notificationReceiverType(receiverType) - .notificationStatus(ACTIVE) - .build(); + .id(1L) + .body("Body") + .bodyEng("BodyEng") + .notificationReceiverType(receiverType) + .notificationStatus(ACTIVE) + .build(); } private static List createUserNotificationList() { @@ -2508,11 +2510,11 @@ private static List createUserNotificationList() { notification.setRead(false); notification.setUser(TEST_USER); notification.setOrder(Order.builder() - .id(1L) - .build()); + .id(1L) + .build()); notification.setNotificationType(UNPAID_ORDER); return List.of( - notification); + notification); } private static Violation createTestViolation() { @@ -2521,21 +2523,21 @@ private static Violation createTestViolation() { private static NotificationParameter createNotificationParameter() { return NotificationParameter.builder() - .key("violationDescription") - .value("violation description") - .build(); + .key("violationDescription") + .value("violation description") + .build(); } private static Order createTestOrder4() { return Order.builder().id(46L).user(User.builder().id(42L).build()) - .orderDate(LocalDateTime.now()) - .build(); + .orderDate(LocalDateTime.now()) + .build(); } private static Order createTestOrder5() { return Order.builder().id(45L).user(User.builder().id(42L).build()) - .orderDate(LocalDateTime.now()).pointsToUse(200) - .build(); + .orderDate(LocalDateTime.now()).pointsToUse(200) + .build(); } public static UserNotification createUserNotificationForViolation() { @@ -2567,13 +2569,13 @@ private static Set createNotificationParameterSet() { Set parameters = new HashSet<>(); parameters.add(NotificationParameter.builder().key("overpayment") - .value(String.valueOf(2L)).build()); + .value(String.valueOf(2L)).build()); parameters.add(NotificationParameter.builder().key("realPackageNumber") - .value(String.valueOf(0)).build()); + .value(String.valueOf(0)).build()); parameters.add(NotificationParameter.builder().key("paidPackageNumber") - .value(String.valueOf(0)).build()); + .value(String.valueOf(0)).build()); parameters.add(NotificationParameter.builder().key("orderNumber") - .value("45").build()); + .value("45").build()); return parameters; } @@ -2581,21 +2583,21 @@ private static Set createNotificationParameterSet2() { Set parameters = new HashSet<>(); parameters.add(NotificationParameter.builder().key("returnedPayment") - .value(String.valueOf(200L)).build()); + .value(String.valueOf(200L)).build()); parameters.add(NotificationParameter.builder().key("orderNumber") - .value("45").build()); + .value("45").build()); return parameters; } private static Order createTestOrder3() { return Order.builder().id(45L).user(User.builder().id(42L).build()) - .confirmedQuantity(new HashMap<>()) - .exportedQuantity(new HashMap<>()) - .amountOfBagsOrdered(new HashMap<>()) - .orderStatus(OrderStatus.ADJUSTMENT) - .orderPaymentStatus(OrderPaymentStatus.PAID) - .orderDate(LocalDateTime.now()) - .build(); + .confirmedQuantity(new HashMap<>()) + .exportedQuantity(new HashMap<>()) + .amountOfBagsOrdered(new HashMap<>()) + .orderStatus(OrderStatus.ADJUSTMENT) + .orderPaymentStatus(OrderPaymentStatus.PAID) + .orderDate(LocalDateTime.now()) + .build(); } private static UserNotification createUserNotification() { @@ -2609,15 +2611,15 @@ private static UserNotification createUserNotification() { private static Order createTestOrder2() { return Order.builder().id(43L).user(User.builder().id(42L).build()) - .orderPaymentStatus(OrderPaymentStatus.PAID).orderDate(LocalDateTime.now()).build(); + .orderPaymentStatus(OrderPaymentStatus.PAID).orderDate(LocalDateTime.now()).build(); } private static UserNotification createUserNotification4() { UserNotification notification = new UserNotification(); notification.setId(1L); notification.setUser(User.builder() - .uuid("test") - .build()); + .uuid("test") + .build()); notification.setRead(false); notification.setParameters(null); notification.setNotificationType(UNPAID_ORDER); @@ -2626,470 +2628,485 @@ private static UserNotification createUserNotification4() { private static NotificationDto createNotificationDto() { return NotificationDto.builder() - .title("Title") - .body("Body") - .build(); + .title("Title") + .body("Body") + .build(); } public static NotificationDto createViolationNotificationDto() { return NotificationDto.builder() - .title("Title") - .body("Body") - .images(emptyList()) - .build(); + .title("Title") + .body("Body") + .images(emptyList()) + .build(); } public static TariffServiceDto TariffServiceDto() { return TariffServiceDto.builder() - .capacity(20) - .price(100.0) - .commission(50.0) - .description("Description") - .descriptionEng("DescriptionEng") - .name("name") - .nameEng("nameEng") - .build(); + .capacity(20) + .price(100.0) + .commission(50.0) + .description("Description") + .descriptionEng("DescriptionEng") + .name("name") + .nameEng("nameEng") + .build(); } public static GetTariffServiceDto getGetTariffServiceDto() { return GetTariffServiceDto.builder() - .id(1) - .capacity(20) - .price(100.0) - .commission(50.0) - .fullPrice(150.0) - .limitIncluded(false) - .description("Description") - .descriptionEng("DescriptionEng") - .name("name") - .nameEng("nameEng") - .build(); + .id(1) + .capacity(20) + .price(100.0) + .commission(50.0) + .fullPrice(150.0) + .limitIncluded(false) + .description("Description") + .descriptionEng("DescriptionEng") + .name("name") + .nameEng("nameEng") + .build(); + } + + public static Optional getOptionalBag() { + return Optional.of(Bag.builder() + .id(1) + .capacity(120) + .commission(50_00L) + .price(120_00L) + .fullPrice(170_00L) + .createdAt(LocalDate.now()) + .createdBy(getEmployee()) + .editedBy(getEmployee()) + .description("Description") + .descriptionEng("DescriptionEng") + .limitIncluded(false) + .build()); + } + + public static OrderBag getOrderBag2() { + return OrderBag.builder() + .id(2L) + .capacity(2200) + .price(22000_00L) + .name("name") + .nameEng("name eng") + .amount(20) + .bag(getBag2()) + .order(getOrder()) + .build(); } - public static Optional getOptionalBag() { - return Optional.of(Bag.builder() - .id(1) - .capacity(120) - .commission(50_00L) - .price(120_00L) - .fullPrice(170_00L) - .createdAt(LocalDate.now()) - .createdBy(getEmployee()) - .editedBy(getEmployee()) - .description("Description") - .descriptionEng("DescriptionEng") - .limitIncluded(false) - .build()); + public static Bag getBag() { + return Bag.builder() + .id(1) + .capacity(120) + .commission(50_00L) + .price(120_00L) + .fullPrice(170_00L) + .createdAt(LocalDate.now()) + .createdBy(getEmployee()) + .editedBy(getEmployee()) + .limitIncluded(true) + + .tariffsInfo(getTariffInfo()) + .build(); } - public static Bag getBag() { + public static Bag getBag2() { return Bag.builder() - .id(1) - .capacity(120) - .commission(50_00L) - .price(120_00L) - .fullPrice(170_00L) - .createdAt(LocalDate.now()) - .createdBy(getEmployee()) - .editedBy(getEmployee()) - .limitIncluded(true) - .tariffsInfo(getTariffInfo()) - .build(); + .id(2) + .capacity(120) + .commission(50_00L) + .price(120_00L) + .fullPrice(170_00L) + .createdAt(LocalDate.now()) + .createdBy(getEmployee()) + .editedBy(getEmployee()) + .limitIncluded(true) + + .tariffsInfo(getTariffInfo()) + .build(); } public static OrderBag getOrderBag() { return OrderBag.builder() - .id(1L) - .capacity(120) - .price(120_00L) - .name("name") - .nameEng("name eng") - .amount(1) - .bag(getBag()) - .order(getOrder()) - .build(); + .id(1L) + .capacity(120) + .price(120_00L) + .name("name") + .nameEng("name eng") + .amount(1) + .bag(getBag()) + .order(getOrder()) + .build(); } public static OrderBag getOrderBagWithConfirmedAmount() { return OrderBag.builder() - .id(1L) - .capacity(120) - .price(120_00L) - .name("name") - .nameEng("name eng") - .amount(1) - .confirmedQuantity(2) - .bag(getBag()) - .order(getOrder()) - .build(); + .id(1L) + .capacity(120) + .price(120_00L) + .name("name") + .nameEng("name eng") + .amount(1) + .confirmedQuantity(2) + .bag(getBag()) + .order(getOrder()) + .build(); } public static OrderBag getOrderBagWithExportedAmount() { return OrderBag.builder() - .id(1L) - .capacity(120) - .price(120_00L) - .name("name") - .nameEng("name eng") - .amount(1) - .confirmedQuantity(2) - .exportedQuantity(2) - .bag(getBag()) - .order(getOrder()) - .build(); + .id(1L) + .capacity(120) + .price(120_00L) + .name("name") + .nameEng("name eng") + .amount(1) + .confirmedQuantity(2) + .exportedQuantity(2) + .bag(getBag()) + .order(getOrder()) + .build(); } public static Bag getBagDeleted() { return Bag.builder() - .id(1) - .capacity(120) - .commission(50_00L) - .price(120_00L) - .fullPrice(170_00L) - .createdAt(LocalDate.now()) - .createdBy(getEmployee()) - .editedBy(getEmployee()) - .description("Description") - .descriptionEng("DescriptionEng") - .limitIncluded(true) - .tariffsInfo(getTariffInfo()) - .build(); + .id(1) + .capacity(120) + .commission(50_00L) + .price(120_00L) + .fullPrice(170_00L) + .createdAt(LocalDate.now()) + .createdBy(getEmployee()) + .editedBy(getEmployee()) + .description("Description") + .descriptionEng("DescriptionEng") + .limitIncluded(true) + .tariffsInfo(getTariffInfo()) + .build(); } public static Bag getBagForOrder() { return Bag.builder() - .id(3) - .capacity(120) - .commission(50_00L) - .price(350_00L) - .fullPrice(400_00L) - .createdAt(LocalDate.now()) - .createdBy(getEmployee()) - .editedBy(getEmployee()) - .description("Description") - .descriptionEng("DescriptionEng") - .limitIncluded(true) - .tariffsInfo(getTariffInfo()) - .build(); + .id(3) + .capacity(120) + .commission(50_00L) + .price(350_00L) + .fullPrice(400_00L) + .createdAt(LocalDate.now()) + .createdBy(getEmployee()) + .editedBy(getEmployee()) + .description("Description") + .descriptionEng("DescriptionEng") + .limitIncluded(true) + .tariffsInfo(getTariffInfo()) + .build(); } public static TariffServiceDto getTariffServiceDto() { return TariffServiceDto.builder() - .name("Бавовняна сумка") - .capacity(20) - .price(100.0) - .commission(50.0) - .description("Description") - .build(); + .name("Бавовняна сумка") + .capacity(20) + .price(100.0) + .commission(50.0) + .description("Description") + .build(); } public static Bag getEditedBag() { return Bag.builder() - .id(1) - .capacity(20) - .price(100_00L) - .fullPrice(150_00L) - .commission(50_00L) - .name("Бавовняна сумка") - .description("Description") - .createdAt(LocalDate.now()) - .createdBy(getEmployee()) - .editedBy(getEmployee()) - .editedAt(LocalDate.now()) - .limitIncluded(true) - .tariffsInfo(getTariffInfo()) - .build(); + .id(1) + .capacity(20) + .price(100_00L) + .fullPrice(150_00L) + .commission(50_00L) + .name("Бавовняна сумка") + .description("Description") + .createdAt(LocalDate.now()) + .createdBy(getEmployee()) + .editedBy(getEmployee()) + .editedAt(LocalDate.now()) + .limitIncluded(true) + + .tariffsInfo(getTariffInfo()) + .build(); } public static OrderBag getEditedOrderBag() { return OrderBag.builder() - .id(1L) - .amount(1) - .price(150_00L) - .capacity(20) - .name("Бавовняна сумка") - .bag(getBag()) - .order(getOrder()) - .build(); + .id(1L) + .amount(1) + .price(150_00L) + .capacity(20) + .name("Бавовняна сумка") + .bag(getBag()) + .order(getOrder()) + .build(); } public static Location getLocation() { return Location.builder() - .id(1L) - .locationStatus(LocationStatus.ACTIVE) - .nameEn("Kyiv") - .nameUk("Київ") - .coordinates(Coordinates.builder() - .longitude(3.34d) - .latitude(1.32d).build()) - .region(getRegionForMapper()) - .orderAddresses(new ArrayList<>()) - .build(); + .id(1L) + .locationStatus(LocationStatus.ACTIVE) + .nameEn("Kyiv") + .nameUk("Київ") + .coordinates(Coordinates.builder() + .longitude(3.34d) + .latitude(1.32d).build()) + .region(getRegionForMapper()) + .orderAddresses(new ArrayList<>()) + .build(); } public static Location getLocationDeactivated() { return Location.builder() - .id(1L) - .locationStatus(LocationStatus.DEACTIVATED) - .nameEn("Kyiv") - .nameUk("Київ") - .coordinates(Coordinates.builder() - .longitude(3.34d) - .latitude(1.32d).build()) - .region(getRegionForMapper()) - .orderAddresses(new ArrayList<>()) - .build(); + .id(1L) + .locationStatus(LocationStatus.DEACTIVATED) + .nameEn("Kyiv") + .nameUk("Київ") + .coordinates(Coordinates.builder() + .longitude(3.34d) + .latitude(1.32d).build()) + .region(getRegionForMapper()) + .orderAddresses(new ArrayList<>()) + .build(); } public static Courier getCourier() { return Courier.builder() - .id(1L) - .courierStatus(CourierStatus.ACTIVE) - .nameUk("Тест") - .nameEn("Test") - .build(); + .id(1L) + .courierStatus(CourierStatus.ACTIVE) + .nameUk("Тест") + .nameEn("Test") + .build(); } public static Courier getDeactivatedCourier() { return Courier.builder() - .id(1L) - .courierStatus(CourierStatus.DEACTIVATED) - .nameUk("Тест") - .nameEn("Test") - .build(); + .id(1L) + .courierStatus(CourierStatus.DEACTIVATED) + .nameUk("Тест") + .nameEn("Test") + .build(); } public static CourierDto getCourierDto() { return CourierDto.builder() - .courierId(1L) - .courierStatus("ACTIVE") - .nameUk("Тест") - .nameEn("Test") - .build(); + .courierId(1L) + .courierStatus("ACTIVE") + .nameUk("Тест") + .nameEn("Test") + .build(); } public static Bag getTariffBag() { return Bag.builder() - .id(1) - .capacity(20) - .price(100_00L) - .commission(50_00L) - .fullPrice(150_00L) - .createdAt(LocalDate.now()) - .createdBy(getEmployee()) - .description("Description") - .descriptionEng("DescriptionEng") - .name("name") - .nameEng("nameEng") - .limitIncluded(false) - .tariffsInfo(getTariffInfo()) - .build(); + .id(1) + .capacity(20) + .price(100_00L) + .commission(50_00L) + .fullPrice(150_00L) + .createdAt(LocalDate.now()) + .createdBy(getEmployee()) + .description("Description") + .descriptionEng("DescriptionEng") + .name("name") + .nameEng("nameEng") + .limitIncluded(false) + .tariffsInfo(getTariffInfo()) + .build(); } public static BagTranslationDto getBagTranslationDto() { return BagTranslationDto.builder() - .id(1) - .capacity(20) - .price(150.0) - .name("name") - .nameEng("nameEng") - .limitedIncluded(false) - .build(); + .id(1) + .capacity(20) + .price(150.0) + .name("name") + .nameEng("nameEng") + .limitedIncluded(false) + .build(); } public static Bag getNewBag() { return Bag.builder() - .capacity(20) - .price(100_00L) - .commission(50_00L) - .fullPrice(150_00L) - .createdAt(LocalDate.now()) - .createdBy(getEmployee()) - .limitIncluded(false) - .description("Description") - .descriptionEng("DescriptionEng") - .name("name") - .nameEng("nameEng") - .build(); + .capacity(20) + .price(100_00L) + .commission(50_00L) + .fullPrice(150_00L) + .createdAt(LocalDate.now()) + .createdBy(getEmployee()) + .limitIncluded(false) + .description("Description") + .descriptionEng("DescriptionEng") + .name("name") + .nameEng("nameEng") + + .build(); } public static AdminCommentDto getAdminCommentDto() { return AdminCommentDto.builder() - .orderId(1L) - .adminComment("Admin") - .build(); + .orderId(1L) + .adminComment("Admin") + .build(); } public static EcoNumberDto getEcoNumberDto() { return EcoNumberDto.builder() - .ecoNumber(new HashSet<>(Arrays.asList("1111111111", "3333333333"))) - .build(); + .ecoNumber(new HashSet<>(Arrays.asList("1111111111", "3333333333"))) + .build(); } public static ServiceDto getServiceDto() { return ServiceDto.builder() - .name("Name") - .nameEng("NameEng") - .price(100.0) - .description("Description") - .descriptionEng("DescriptionEng") - .build(); + .name("Name") + .nameEng("NameEng") + .price(100.0) + .description("Description") + .descriptionEng("DescriptionEng") + .build(); } public static GetServiceDto getGetServiceDto() { return GetServiceDto.builder() - .id(1L) - .name("Name") - .nameEng("NameEng") - .price(100.0) - .description("Description") - .descriptionEng("DescriptionEng") - .build(); + .id(1L) + .name("Name") + .nameEng("NameEng") + .price(100.0) + .description("Description") + .descriptionEng("DescriptionEng") + .build(); } public static Service getService() { Employee employee = ModelUtils.getEmployee(); return Service.builder() - .id(1L) - .price(100_00L) - .createdAt(LocalDate.now()) - .createdBy(employee) - .description("Description") - .descriptionEng("DescriptionEng") - .name("Name") - .nameEng("NameEng") - .build(); + .id(1L) + .price(100_00L) + .createdAt(LocalDate.now()) + .createdBy(employee) + .description("Description") + .descriptionEng("DescriptionEng") + .name("Name") + .nameEng("NameEng") + .build(); } public static Service getNewService() { Employee employee = ModelUtils.getEmployee(); return Service.builder() - .price(100_00L) - .createdAt(LocalDate.now()) - .createdBy(employee) - .description("Description") - .descriptionEng("DescriptionEng") - .name("Name") - .nameEng("NameEng") - .build(); + .price(100_00L) + .createdAt(LocalDate.now()) + .createdBy(employee) + .description("Description") + .descriptionEng("DescriptionEng") + .name("Name") + .nameEng("NameEng") + .build(); } public static Service getEditedService() { Employee employee = ModelUtils.getEmployee(); return Service.builder() - .id(1L) - .name("Name") - .nameEng("NameEng") - .price(100_00L) - .description("Description") - .descriptionEng("DescriptionEng") - .editedAt(LocalDate.now()) - .editedBy(employee) - .build(); + .id(1L) + .name("Name") + .nameEng("NameEng") + .price(100_00L) + .description("Description") + .descriptionEng("DescriptionEng") + .editedAt(LocalDate.now()) + .editedBy(employee) + .build(); } public static CreateCourierDto getCreateCourierDto() { return CreateCourierDto.builder() - .nameUk("Тест") - .nameEn("Test") - .build(); + .nameUk("Тест") + .nameEn("Test") + .build(); } public static CounterOrderDetailsDto getcounterOrderDetailsDto() { return CounterOrderDetailsDto.builder() - .totalAmount(22.02D) - .totalConfirmed(12.34D) - .totalExported(32.2D) - .sumAmount(35.3D) - .sumConfirmed(31.54D) - .sumExported(366.44D) - .certificateBonus(23.4D) - .bonus(54.32D) - .totalSumAmount(1.32D) - .totalSumConfirmed(32.6D) - .totalSumExported(73.1D) - .orderComment("test") - .certificate(List.of("fds")) - .numberOrderFromShop(Set.of("dsd")) - .build(); + .totalAmount(22.02D) + .totalConfirmed(12.34D) + .totalExported(32.2D) + .sumAmount(35.3D) + .sumConfirmed(31.54D) + .sumExported(366.44D) + .certificateBonus(23.4D) + .bonus(54.32D) + .totalSumAmount(1.32D) + .totalSumConfirmed(32.6D) + .totalSumExported(73.1D) + .orderComment("test") + .certificate(List.of("fds")) + .numberOrderFromShop(Set.of("dsd")) + .build(); } public static Order getOrderUserFirst() { return Order.builder() - .id(1L) - .exportedQuantity(Collections.singletonMap(1, 1)) - .amountOfBagsOrdered(Map.of(1, 1)) - .confirmedQuantity(Map.of(1, 1)) - .exportedQuantity(Map.of(1, 1)) - .pointsToUse(100) - .build(); + .id(1L) + .exportedQuantity(Collections.singletonMap(1, 1)) + .amountOfBagsOrdered(Map.of(1, 1)) + .confirmedQuantity(Map.of(1, 1)) + .exportedQuantity(Map.of(1, 1)) + .pointsToUse(100) + .build(); } public static Order getOrderUserSecond() { return Order.builder() - .id(2L) - .exportedQuantity(Collections.singletonMap(1, 1)) - .amountOfBagsOrdered(Map.of(1, 1)) - .confirmedQuantity(Map.of(1, 1)) - .exportedQuantity(Map.of(1, 1)) - .pointsToUse(100) - .build(); + .id(2L) + .exportedQuantity(Collections.singletonMap(1, 1)) + .amountOfBagsOrdered(Map.of(1, 1)) + .confirmedQuantity(Map.of(1, 1)) + .exportedQuantity(Map.of(1, 1)) + .pointsToUse(100) + .build(); } public static List getBag1list() { return List.of(Bag.builder() - .id(1) - .price(100_00L) - .capacity(20) - .commission(50_00L) - .fullPrice(170_00L) - .name("name") - .nameEng("nameEng") - .limitIncluded(false) - .build()); - } - - public static List getBaglist() { - return List.of(Bag.builder() - .id(1) - .price(100_00L) - .capacity(10) - .commission(21_00L) - .fullPrice(20_00L) - .build(), - Bag.builder() - .id(2) + .id(1) .price(100_00L) - .capacity(10) - .commission(21_00L) - .fullPrice(21_00L) + .capacity(20) + .commission(50_00L) + .fullPrice(170_00L) + .name("name") + .nameEng("nameEng") + .limitIncluded(false) .build()); } - public static List getBag2list() { + public static List getBaglist() { return List.of(Bag.builder() - .id(1) - .price(100_00L) - .capacity(10) - .commission(20_00L) - .fullPrice(120_00L) - .build()); + .id(1) + .price(100_00L) + .capacity(10) + .commission(21_00L) + .fullPrice(20_00L) + .build(), + Bag.builder() + .id(2) + .price(100_00L) + .capacity(10) + .commission(21_00L) + .fullPrice(21_00L) + .build()); } - public static List getBag3list() { + public static List getBag2list() { return List.of(Bag.builder() - .id(1) - .price(100_00L) - .capacity(10) - .commission(21_00L) - .fullPrice(2000_00L) - .build(), - Bag.builder() - .id(2) + .id(1) .price(100_00L) .capacity(10) .commission(20_00L) @@ -3097,36 +3114,53 @@ public static List getBag3list() { .build()); } + public static List getBag3list() { + return List.of(Bag.builder() + .id(1) + .price(100_00L) + .capacity(10) + .commission(21_00L) + .fullPrice(2000_00L) + .build(), + Bag.builder() + .id(2) + .price(100_00L) + .capacity(10) + .commission(20_00L) + .fullPrice(120_00L) + .build()); + } + public static List getBag4list() { return List.of(Bag.builder() - .id(1) - .price(100_00L) - .capacity(10) - .commission(20_00L) - .fullPrice(120_00L) - .name("name") - .nameEng("nameEng") - .limitIncluded(false) - .build(), - Bag.builder() - .id(2) - .price(100_00L) - .capacity(10) - .commission(20_00L) - .fullPrice(120_00L) - .name("name") - .nameEng("nameEng") - .limitIncluded(false) - .build()); + .id(1) + .price(100_00L) + .capacity(10) + .commission(20_00L) + .fullPrice(120_00L) + .name("name") + .nameEng("nameEng") + .limitIncluded(false) + .build(), + Bag.builder() + .id(2) + .price(100_00L) + .capacity(10) + .commission(20_00L) + .fullPrice(120_00L) + .name("name") + .nameEng("nameEng") + .limitIncluded(false) + .build()); } public static List getCertificateList() { return List.of(Certificate.builder() - .code("uuid") - .certificateStatus(CertificateStatus.ACTIVE) - .creationDate(LocalDate.now()) - .points(999) - .build()); + .code("uuid") + .certificateStatus(CertificateStatus.ACTIVE) + .creationDate(LocalDate.now()) + .points(999) + .build()); } public static OrderStatusTranslation getStatusTranslation() { @@ -3135,521 +3169,521 @@ public static OrderStatusTranslation getStatusTranslation() { public static List getOrderStatusTranslations() { return List.of(OrderStatusTranslation.builder() - .id(1L) - .statusId(6L) - .name("Order DONE") - .build(), - OrderStatusTranslation.builder() - .id(2L) - .statusId(7L) - .name("Order NOT TAKEN OUT") - .build(), - OrderStatusTranslation.builder().id(3L) - .statusId(8L) - .name("Order CANCELLED") - .build()); + .id(1L) + .statusId(6L) + .name("Order DONE") + .build(), + OrderStatusTranslation.builder() + .id(2L) + .statusId(7L) + .name("Order NOT TAKEN OUT") + .build(), + OrderStatusTranslation.builder().id(3L) + .statusId(8L) + .name("Order CANCELLED") + .build()); } public static List getOrderStatusPaymentTranslations() { return List.of(OrderPaymentStatusTranslation.builder() - .id(1L) - .translationValue("тест") - .translationsValueEng("test") - .orderPaymentStatusId(1L) - .build(), - OrderPaymentStatusTranslation.builder() - .id(2L) - .translationValue("тест2") - .translationsValueEng("test2") - .orderPaymentStatusId(2L) - .build(), - OrderPaymentStatusTranslation.builder() - .id(3L) - .translationValue("тест3") - .translationsValueEng("test3") - .orderPaymentStatusId(3L) - .build(), - OrderPaymentStatusTranslation.builder() - .id(4L) - .translationValue("тест4") - .translationsValueEng("test4") - .orderPaymentStatusId(4L) - .build()); + .id(1L) + .translationValue("тест") + .translationsValueEng("test") + .orderPaymentStatusId(1L) + .build(), + OrderPaymentStatusTranslation.builder() + .id(2L) + .translationValue("тест2") + .translationsValueEng("test2") + .orderPaymentStatusId(2L) + .build(), + OrderPaymentStatusTranslation.builder() + .id(3L) + .translationValue("тест3") + .translationsValueEng("test3") + .orderPaymentStatusId(3L) + .build(), + OrderPaymentStatusTranslation.builder() + .id(4L) + .translationValue("тест4") + .translationsValueEng("test4") + .orderPaymentStatusId(4L) + .build()); } public static BagInfoDto getBagInfoDto() { return BagInfoDto.builder() - .id(1) - .name("name") - .nameEng("name") - .price(100.) - .capacity(10) - .build(); + .id(1) + .name("name") + .nameEng("name") + .price(100.) + .capacity(10) + .build(); } public static PaymentTableInfoDto getPaymentTableInfoDto() { return PaymentTableInfoDto.builder() - .paidAmount(200d) - .unPaidAmount(0d) - .paymentInfoDtos(List.of(getInfoPayment().setAmount(10d))) - .overpayment(800d) - .build(); + .paidAmount(200d) + .unPaidAmount(0d) + .paymentInfoDtos(List.of(getInfoPayment().setAmount(10d))) + .overpayment(800d) + .build(); } public static PaymentTableInfoDto getPaymentTableInfoDto2() { return PaymentTableInfoDto.builder() - .paidAmount(0d) - .unPaidAmount(0d) - .paymentInfoDtos(Collections.emptyList()) - .overpayment(400d) - .build(); + .paidAmount(0d) + .unPaidAmount(0d) + .paymentInfoDtos(Collections.emptyList()) + .overpayment(400d) + .build(); } public static PaymentInfoDto getInfoPayment() { return PaymentInfoDto.builder() - .comment("ddd") - .id(1L) - .amount(10d) - .build(); + .comment("ddd") + .id(1L) + .amount(10d) + .build(); } public static OrderPaymentStatusTranslation getOrderPaymentStatusTranslation() { return OrderPaymentStatusTranslation.builder() - .id(1L) - .orderPaymentStatusId(1L) - .translationValue("Абв") - .translationsValueEng("Abc") - .build(); + .id(1L) + .orderPaymentStatusId(1L) + .translationValue("Абв") + .translationsValueEng("Abc") + .build(); } public static OrderFondyClientDto getOrderFondyClientDto() { return OrderFondyClientDto.builder() - .orderId(1L) - .pointsToUse(100) - .build(); + .orderId(1L) + .pointsToUse(100) + .build(); } public static Order getOrderCount() { return Order.builder() - .id(1L) - .pointsToUse(1) - .counterOrderPaymentId(2L) - .orderPaymentStatus(OrderPaymentStatus.HALF_PAID) - .payment(Lists.newArrayList(Payment.builder() - .paymentId("1L") - .amount(200L) - .currency("UAH") - .settlementDate("20.02.1990") - .comment("avb") - .paymentStatus(PaymentStatus.PAID) - .build())) - .build(); + .id(1L) + .pointsToUse(1) + .counterOrderPaymentId(2L) + .orderPaymentStatus(OrderPaymentStatus.HALF_PAID) + .payment(Lists.newArrayList(Payment.builder() + .paymentId("1L") + .amount(200L) + .currency("UAH") + .settlementDate("20.02.1990") + .comment("avb") + .paymentStatus(PaymentStatus.PAID) + .build())) + .build(); } public static Order getOrderCountWithPaymentStatusPaid() { return Order.builder() - .id(1L) - .pointsToUse(1) - .counterOrderPaymentId(2L) - .orderPaymentStatus(OrderPaymentStatus.PAID) - .build(); + .id(1L) + .pointsToUse(1) + .counterOrderPaymentId(2L) + .orderPaymentStatus(OrderPaymentStatus.PAID) + .build(); } public static UpdateOrderPageAdminDto updateOrderPageAdminDto() { return UpdateOrderPageAdminDto.builder() - .generalOrderInfo(OrderDetailStatusRequestDto - .builder() - .orderStatus(String.valueOf(OrderStatus.CONFIRMED)) - .orderPaymentStatus(String.valueOf(PaymentStatus.PAID)) - .adminComment("aaa") - .build()) - .userInfoDto(UbsCustomersDtoUpdate - .builder() - .recipientId(2L) - .recipientName("aaaaa") - .recipientPhoneNumber("085555") - .recipientEmail("yura@333gmail.com") - .build()) - .addressExportDetailsDto(OrderAddressExportDetailsDtoUpdate - .builder() - .addressId(1L) - .addressDistrict("District") - .addressDistrictEng("DistrictEng") - .addressStreet("Street") - .addressStreetEng("StreetEng") - .addressEntranceNumber("12") - .addressHouseCorpus("123") - .addressHouseNumber("121") - .addressCity("City") - .addressCityEng("CityEng") - .addressRegion("Region") - .addressRegionEng("RegionEng") - .build()) - .ecoNumberFromShop(EcoNumberDto.builder() - .ecoNumber(Set.of("1111111111")) - .build()) - .exportDetailsDto(ExportDetailsDtoUpdate - .builder() - .dateExport("1997-12-04T15:40:24") - .timeDeliveryFrom("1997-12-04T15:40:24") - .timeDeliveryTo("1990-12-11T19:30:30") - .receivingStationId(1L) - .build()) - .orderDetailDto( - UpdateOrderDetailDto.builder() - .amountOfBagsConfirmed(Map.ofEntries(Map.entry(1, 1))) - .amountOfBagsExported(Map.ofEntries(Map.entry(1, 1))) - .build()) - .updateResponsibleEmployeeDto(List.of(UpdateResponsibleEmployeeDto.builder() - .positionId(2L) - .employeeId(2L) - .build())) - .build(); + .generalOrderInfo(OrderDetailStatusRequestDto + .builder() + .orderStatus(String.valueOf(OrderStatus.CONFIRMED)) + .orderPaymentStatus(String.valueOf(PaymentStatus.PAID)) + .adminComment("aaa") + .build()) + .userInfoDto(UbsCustomersDtoUpdate + .builder() + .recipientId(2L) + .recipientName("aaaaa") + .recipientPhoneNumber("085555") + .recipientEmail("yura@333gmail.com") + .build()) + .addressExportDetailsDto(OrderAddressExportDetailsDtoUpdate + .builder() + .addressId(1L) + .addressDistrict("District") + .addressDistrictEng("DistrictEng") + .addressStreet("Street") + .addressStreetEng("StreetEng") + .addressEntranceNumber("12") + .addressHouseCorpus("123") + .addressHouseNumber("121") + .addressCity("City") + .addressCityEng("CityEng") + .addressRegion("Region") + .addressRegionEng("RegionEng") + .build()) + .ecoNumberFromShop(EcoNumberDto.builder() + .ecoNumber(Set.of("1111111111")) + .build()) + .exportDetailsDto(ExportDetailsDtoUpdate + .builder() + .dateExport("1997-12-04T15:40:24") + .timeDeliveryFrom("1997-12-04T15:40:24") + .timeDeliveryTo("1990-12-11T19:30:30") + .receivingStationId(1L) + .build()) + .orderDetailDto( + UpdateOrderDetailDto.builder() + .amountOfBagsConfirmed(Map.ofEntries(Map.entry(1, 1))) + .amountOfBagsExported(Map.ofEntries(Map.entry(1, 1))) + .build()) + .updateResponsibleEmployeeDto(List.of(UpdateResponsibleEmployeeDto.builder() + .positionId(2L) + .employeeId(2L) + .build())) + .build(); } public static UpdateOrderPageAdminDto updateOrderPageAdminDtoWithNullFields() { return UpdateOrderPageAdminDto.builder() - .generalOrderInfo(OrderDetailStatusRequestDto - .builder() - .orderStatus(String.valueOf(OrderStatus.DONE)) - .build()) - .exportDetailsDto(ExportDetailsDtoUpdate - .builder() - .dateExport(null) - .timeDeliveryFrom(null) - .timeDeliveryTo(null) - .receivingStationId(null) - .build()) - .build(); + .generalOrderInfo(OrderDetailStatusRequestDto + .builder() + .orderStatus(String.valueOf(OrderStatus.DONE)) + .build()) + .exportDetailsDto(ExportDetailsDtoUpdate + .builder() + .dateExport(null) + .timeDeliveryFrom(null) + .timeDeliveryTo(null) + .receivingStationId(null) + .build()) + .build(); } public static UpdateOrderPageAdminDto updateOrderPageAdminDtoWithStatusCanceled() { return UpdateOrderPageAdminDto.builder() - .generalOrderInfo(OrderDetailStatusRequestDto - .builder() - .orderStatus(String.valueOf(OrderStatus.FORMED)) - .build()) - .exportDetailsDto(ExportDetailsDtoUpdate - .builder() - .dateExport(null) - .timeDeliveryFrom(null) - .timeDeliveryTo(null) - .receivingStationId(null) - .build()) - .build(); + .generalOrderInfo(OrderDetailStatusRequestDto + .builder() + .orderStatus(String.valueOf(OrderStatus.FORMED)) + .build()) + .exportDetailsDto(ExportDetailsDtoUpdate + .builder() + .dateExport(null) + .timeDeliveryFrom(null) + .timeDeliveryTo(null) + .receivingStationId(null) + .build()) + .build(); } public static UpdateOrderPageAdminDto updateOrderPageAdminDtoWithStatusBroughtItHimself() { return UpdateOrderPageAdminDto.builder() - .generalOrderInfo(OrderDetailStatusRequestDto - .builder() - .orderStatus(String.valueOf(OrderStatus.DONE)) - .build()) - .exportDetailsDto(ExportDetailsDtoUpdate - .builder() - .dateExport("2023-12-16T16:30") - .timeDeliveryFrom("2023-12-16T19:00") - .timeDeliveryTo("2023-12-16T20:30") - .receivingStationId(2L) - .build()) - .build(); + .generalOrderInfo(OrderDetailStatusRequestDto + .builder() + .orderStatus(String.valueOf(OrderStatus.DONE)) + .build()) + .exportDetailsDto(ExportDetailsDtoUpdate + .builder() + .dateExport("2023-12-16T16:30") + .timeDeliveryFrom("2023-12-16T19:00") + .timeDeliveryTo("2023-12-16T20:30") + .receivingStationId(2L) + .build()) + .build(); } public static UpdateOrderPageAdminDto updateOrderPageAdminDtoWithStatusFormed() { return UpdateOrderPageAdminDto.builder() - .generalOrderInfo(OrderDetailStatusRequestDto - .builder() - .orderStatus(String.valueOf(OrderStatus.FORMED)) - .build()) - .exportDetailsDto(ExportDetailsDtoUpdate - .builder() - .dateExport(null) - .timeDeliveryFrom(null) - .timeDeliveryTo(null) - .receivingStationId(null) - .build()) - .build(); + .generalOrderInfo(OrderDetailStatusRequestDto + .builder() + .orderStatus(String.valueOf(OrderStatus.FORMED)) + .build()) + .exportDetailsDto(ExportDetailsDtoUpdate + .builder() + .dateExport(null) + .timeDeliveryFrom(null) + .timeDeliveryTo(null) + .receivingStationId(null) + .build()) + .build(); } public static Location getLocationDto() { return Location.builder() - .id(1L) - .locationStatus(LocationStatus.DEACTIVATED) - .nameUk("Київ") - .nameEn("Kyiv") - .build(); + .id(1L) + .locationStatus(LocationStatus.DEACTIVATED) + .nameUk("Київ") + .nameEn("Kyiv") + .build(); } public static Bag bagDto() { return Bag.builder() - .id(1) - .limitIncluded(false) - .description("Description") - .descriptionEng("DescriptionEng") - .name("Test") - .nameEng("a") - .createdBy(getEmployee()) - .editedBy(getEmployee()) - .build(); + .id(1) + .limitIncluded(false) + .description("Description") + .descriptionEng("DescriptionEng") + .name("Test") + .nameEng("a") + .createdBy(getEmployee()) + .editedBy(getEmployee()) + .build(); } public static OrderStatusTranslation getOrderStatusTranslation() { return OrderStatusTranslation - .builder() - .statusId(1L) - .id(1L) - .name("ua") - .build(); + .builder() + .statusId(1L) + .id(1L) + .name("ua") + .build(); } public static Order getOrdersDto() { return Order.builder() - .id(1L) - .payment(List.of(Payment.builder().id(1L).build())) - .user(User.builder().id(1L).build()) - .imageReasonNotTakingBags(List.of("ss")) - .reasonNotTakingBagDescription("aa") - .orderStatus(OrderStatus.CANCELED) - .counterOrderPaymentId(1L) - .build(); + .id(1L) + .payment(List.of(Payment.builder().id(1L).build())) + .user(User.builder().id(1L).build()) + .imageReasonNotTakingBags(List.of("ss")) + .reasonNotTakingBagDescription("aa") + .orderStatus(OrderStatus.CANCELED) + .counterOrderPaymentId(1L) + .build(); } public static UserProfileUpdateDto updateUserProfileDto() { return UserProfileUpdateDto.builder() - .recipientName("Taras") - .recipientSurname("Ivanov") - .recipientPhone("962473289") - .addressDto(addressDtoList()) - .telegramIsNotify(true) - .viberIsNotify(false) - .build(); + .recipientName("Taras") + .recipientSurname("Ivanov") + .recipientPhone("962473289") + .addressDto(addressDtoList()) + .telegramIsNotify(true) + .viberIsNotify(false) + .build(); } public static List getAllRegion() { return List.of(Region.builder() - .id(1L) - .ukrName("Київська область") - .enName("Kyiv region") - .locations(getLocationList()) - .build()); + .id(1L) + .ukrName("Київська область") + .enName("Kyiv region") + .locations(getLocationList()) + .build()); } public static List getRegionTranslationsDto() { return List.of( - RegionTranslationDto.builder().languageCode("ua").regionName("Київська область").build(), - RegionTranslationDto.builder().regionName("Kyiv region").languageCode("en").build()); + RegionTranslationDto.builder().languageCode("ua").regionName("Київська область").build(), + RegionTranslationDto.builder().regionName("Kyiv region").languageCode("en").build()); } public static List getLocationCreateDtoList() { return List.of(LocationCreateDto.builder() - .addLocationDtoList(getAddLocationTranslationDtoList()) - .regionTranslationDtos(getRegionTranslationsDto()) - .longitude(3.34d) - .latitude(1.32d) - .build()); + .addLocationDtoList(getAddLocationTranslationDtoList()) + .regionTranslationDtos(getRegionTranslationsDto()) + .longitude(3.34d) + .latitude(1.32d) + .build()); } public static List getAddLocationTranslationDtoList() { return List.of( - AddLocationTranslationDto.builder().locationName("Київ").languageCode("ua").build(), - AddLocationTranslationDto.builder().locationName("Kyiv").languageCode("en").build()); + AddLocationTranslationDto.builder().locationName("Київ").languageCode("ua").build(), + AddLocationTranslationDto.builder().locationName("Kyiv").languageCode("en").build()); } public static Region getRegion() { return Region.builder() - .id(1L) - .ukrName("Київська область") - .enName("Kyiv region") - .locations(List.of(getLocation())) - .build(); + .id(1L) + .ukrName("Київська область") + .enName("Kyiv region") + .locations(List.of(getLocation())) + .build(); } public static Region getRegionForMapper() { return Region.builder() - .id(1L) - .ukrName("Київська область") - .enName("Kyiv region") - .build(); + .id(1L) + .ukrName("Київська область") + .enName("Kyiv region") + .build(); } public static LocationInfoDto getInfoAboutLocationDto() { return LocationInfoDto.builder() - .regionId(1L) - .regionTranslationDtos(getRegionTranslationsDto()) - .locationsDto(getLocationsDto()).build(); + .regionId(1L) + .regionTranslationDtos(getRegionTranslationsDto()) + .locationsDto(getLocationsDto()).build(); } public static List getLocationsDto() { return List.of(LocationsDto.builder() - .locationTranslationDtoList(getLocationTranslationDto()) - .locationStatus("ACTIVE") - .longitude(3.34d) - .latitude(1.32d) - .build()); + .locationTranslationDtoList(getLocationTranslationDto()) + .locationStatus("ACTIVE") + .longitude(3.34d) + .latitude(1.32d) + .build()); } public static List getLocationTranslationDto() { return List.of(LocationTranslationDto.builder() - .locationName("Київ") - .languageCode("ua") - .build(), - LocationTranslationDto.builder() - .locationName("Kyiv") - .languageCode("en").build()); + .locationName("Київ") + .languageCode("ua") + .build(), + LocationTranslationDto.builder() + .locationName("Kyiv") + .languageCode("en").build()); } public static List getCourierDtoList() { return List.of(CourierDto.builder() - .courierId(1L) - .courierStatus("ACTIVE") - .nameUk("Тест") - .nameEn("Test") - .build()); + .courierId(1L) + .courierStatus("ACTIVE") + .nameUk("Тест") + .nameEn("Test") + .build()); } public static Location getLocationForCreateRegion() { return Location.builder() - .locationStatus(LocationStatus.ACTIVE) - .nameUk("Київ").nameEn("Kyiv") - .coordinates(Coordinates.builder() - .longitude(3.34d) - .latitude(1.32d).build()) - .region(Region.builder().id(1L).enName("Kyiv region").ukrName("Київська область").build()) - .build(); + .locationStatus(LocationStatus.ACTIVE) + .nameUk("Київ").nameEn("Kyiv") + .coordinates(Coordinates.builder() + .longitude(3.34d) + .latitude(1.32d).build()) + .region(Region.builder().id(1L).enName("Kyiv region").ukrName("Київська область").build()) + .build(); } public static PaymentResponseDto getPaymentResponseDto() { return PaymentResponseDto.builder() - .order_id("1_1_1") - .payment_id(2) - .currency("a") - .amount(1) - .order_status("approved") - .response_status("failure") - .sender_cell_phone("sss") - .sender_account("ss") - .masked_card("s") - .card_type("s") - .response_code(2) - .response_description("ddd") - .order_time("s") - .settlement_date("21.12.2014") - .fee(null) - .payment_system("s") - .sender_email("s") - .payment_id(2) - .build(); + .order_id("1_1_1") + .payment_id(2) + .currency("a") + .amount(1) + .order_status("approved") + .response_status("failure") + .sender_cell_phone("sss") + .sender_account("ss") + .masked_card("s") + .card_type("s") + .response_code(2) + .response_description("ddd") + .order_time("s") + .settlement_date("21.12.2014") + .fee(null) + .payment_system("s") + .sender_email("s") + .payment_id(2) + .build(); } public static BigOrderTableViews getBigOrderTableViews() { return new BigOrderTableViews() - .setId(3333L) - .setOrderStatus("FORMED") - .setOrderPaymentStatus("PAID") - .setOrderDate(LocalDate.of(2021, 12, 8)) - .setPaymentDate(LocalDate.of(2021, 12, 8)) - .setClientName("Uliana Стан") - .setClientPhoneNumber("+380996755544") - .setClientEmail("motiy14146@ecofreon.com") - .setSenderName("Uliana Стан") - .setSenderPhone("996755544") - .setSenderEmail("motiy14146@ecofreon.com") - .setViolationsAmount(1) - .setRegion("Київська область") - .setRegionEn("Kyivs'ka oblast") - .setCity("Київ") - .setCityEn("Kyiv") - .setDistrict("Шевченківський") - .setDistrictEn("Shevchenkivs'kyi") - .setAddress("Січових Стрільців, 37, 1, 1") - .setAddressEn("Sichovyh Stril'tsiv, 37, 1, 1") - .setCommentToAddressForClient("coment") - .setBagAmount("3") - .setTotalOrderSum(50000L) - .setOrderCertificateCode("5489-2789") - .setGeneralDiscount(100L) - .setAmountDue(0L) - .setCommentForOrderByClient("commentForOrderByClient") - .setCommentForOrderByAdmin("commentForOrderByAdmin") - .setTotalPayment(20000L) - .setDateOfExport(LocalDate.of(2021, 12, 8)) - .setTimeOfExport("from 15:59:52 to 15:59:52") - .setIdOrderFromShop("3245678765") - .setReceivingStationId(1L) - .setResponsibleLogicManId(1L) - .setResponsibleDriverId(1L) - .setResponsibleCallerId(1L) - .setResponsibleNavigatorId(1L) - .setIsBlocked(true) - .setBlockedBy("Blocked Test"); + .setId(3333L) + .setOrderStatus("FORMED") + .setOrderPaymentStatus("PAID") + .setOrderDate(LocalDate.of(2021, 12, 8)) + .setPaymentDate(LocalDate.of(2021, 12, 8)) + .setClientName("Uliana Стан") + .setClientPhoneNumber("+380996755544") + .setClientEmail("motiy14146@ecofreon.com") + .setSenderName("Uliana Стан") + .setSenderPhone("996755544") + .setSenderEmail("motiy14146@ecofreon.com") + .setViolationsAmount(1) + .setRegion("Київська область") + .setRegionEn("Kyivs'ka oblast") + .setCity("Київ") + .setCityEn("Kyiv") + .setDistrict("Шевченківський") + .setDistrictEn("Shevchenkivs'kyi") + .setAddress("Січових Стрільців, 37, 1, 1") + .setAddressEn("Sichovyh Stril'tsiv, 37, 1, 1") + .setCommentToAddressForClient("coment") + .setBagAmount("3") + .setTotalOrderSum(50000L) + .setOrderCertificateCode("5489-2789") + .setGeneralDiscount(100L) + .setAmountDue(0L) + .setCommentForOrderByClient("commentForOrderByClient") + .setCommentForOrderByAdmin("commentForOrderByAdmin") + .setTotalPayment(20000L) + .setDateOfExport(LocalDate.of(2021, 12, 8)) + .setTimeOfExport("from 15:59:52 to 15:59:52") + .setIdOrderFromShop("3245678765") + .setReceivingStationId(1L) + .setResponsibleLogicManId(1L) + .setResponsibleDriverId(1L) + .setResponsibleCallerId(1L) + .setResponsibleNavigatorId(1L) + .setIsBlocked(true) + .setBlockedBy("Blocked Test"); } public static BigOrderTableDTO getBigOrderTableDto() { return new BigOrderTableDTO() - .setId(3333L) - .setOrderStatus("FORMED") - .setOrderPaymentStatus("PAID") - .setOrderDate("2021-12-08") - .setPaymentDate("2021-12-08") - .setClientName("Uliana Стан") - .setClientPhone("+380996755544") - .setClientEmail("motiy14146@ecofreon.com") - .setSenderName("Uliana Стан") - .setSenderPhone("996755544") - .setSenderEmail("motiy14146@ecofreon.com") - .setViolationsAmount(1) - .setRegion(new SenderLocation().setUa("Київська область").setEn("Kyivs'ka oblast")) - .setCity(new SenderLocation().setUa("Київ").setEn("Kyiv")) - .setDistrict(new SenderLocation().setUa("Шевченківський").setEn("Shevchenkivs'kyi")) - .setAddress( - new SenderLocation().setUa("Січових Стрільців, 37, 1, 1").setEn("Sichovyh Stril'tsiv, 37, 1, 1")) - .setCommentToAddressForClient("coment") - .setBagsAmount("3") - .setTotalOrderSum(500.) - .setOrderCertificateCode("5489-2789") - .setGeneralDiscount(100L) - .setAmountDue(0.) - .setCommentForOrderByClient("commentForOrderByClient") - .setCommentsForOrder("commentForOrderByAdmin") - .setTotalPayment(200.) - .setDateOfExport("2021-12-08") - .setTimeOfExport("from 15:59:52 to 15:59:52") - .setIdOrderFromShop("3245678765") - .setReceivingStation("1") - .setResponsibleLogicMan("1") - .setResponsibleDriver("1") - .setResponsibleCaller("1") - .setResponsibleNavigator("1") - .setIsBlocked(true) - .setBlockedBy("Blocked Test"); + .setId(3333L) + .setOrderStatus("FORMED") + .setOrderPaymentStatus("PAID") + .setOrderDate("2021-12-08") + .setPaymentDate("2021-12-08") + .setClientName("Uliana Стан") + .setClientPhone("+380996755544") + .setClientEmail("motiy14146@ecofreon.com") + .setSenderName("Uliana Стан") + .setSenderPhone("996755544") + .setSenderEmail("motiy14146@ecofreon.com") + .setViolationsAmount(1) + .setRegion(new SenderLocation().setUa("Київська область").setEn("Kyivs'ka oblast")) + .setCity(new SenderLocation().setUa("Київ").setEn("Kyiv")) + .setDistrict(new SenderLocation().setUa("Шевченківський").setEn("Shevchenkivs'kyi")) + .setAddress( + new SenderLocation().setUa("Січових Стрільців, 37, 1, 1").setEn("Sichovyh Stril'tsiv, 37, 1, 1")) + .setCommentToAddressForClient("coment") + .setBagsAmount("3") + .setTotalOrderSum(500.) + .setOrderCertificateCode("5489-2789") + .setGeneralDiscount(100L) + .setAmountDue(0.) + .setCommentForOrderByClient("commentForOrderByClient") + .setCommentsForOrder("commentForOrderByAdmin") + .setTotalPayment(200.) + .setDateOfExport("2021-12-08") + .setTimeOfExport("from 15:59:52 to 15:59:52") + .setIdOrderFromShop("3245678765") + .setReceivingStation("1") + .setResponsibleLogicMan("1") + .setResponsibleDriver("1") + .setResponsibleCaller("1") + .setResponsibleNavigator("1") + .setIsBlocked(true) + .setBlockedBy("Blocked Test"); } public static BigOrderTableDTO getBigOrderTableDtoByDateNullTest() { return new BigOrderTableDTO() - .setOrderDate("") - .setPaymentDate("") - .setDateOfExport("") - .setReceivingStation("") - .setResponsibleCaller("") - .setResponsibleDriver("") - .setResponsibleLogicMan("") - .setResponsibleNavigator("") - .setRegion(new SenderLocation().setEn(null).setUa(null)) - .setCity(new SenderLocation().setEn(null).setUa(null)) - .setDistrict(new SenderLocation().setEn(null).setUa(null)) - .setAddress(new SenderLocation().setEn(null).setUa(null)); + .setOrderDate("") + .setPaymentDate("") + .setDateOfExport("") + .setReceivingStation("") + .setResponsibleCaller("") + .setResponsibleDriver("") + .setResponsibleLogicMan("") + .setResponsibleNavigator("") + .setRegion(new SenderLocation().setEn(null).setUa(null)) + .setCity(new SenderLocation().setEn(null).setUa(null)) + .setDistrict(new SenderLocation().setEn(null).setUa(null)) + .setAddress(new SenderLocation().setEn(null).setUa(null)); } public static BigOrderTableViews getBigOrderTableViewsByDateNullTest() { return new BigOrderTableViews() - .setOrderDate(null) - .setPaymentDate(null) - .setDateOfExport(null) - .setReceivingStation(null) - .setResponsibleCaller(null) - .setResponsibleDriver(null) - .setResponsibleLogicMan(null) - .setResponsibleNavigator(null); + .setOrderDate(null) + .setPaymentDate(null) + .setDateOfExport(null) + .setReceivingStation(null) + .setResponsibleCaller(null) + .setResponsibleDriver(null) + .setResponsibleLogicMan(null) + .setResponsibleNavigator(null); } public static Order getOrderForGetOrderStatusData2Test() { @@ -3658,80 +3692,81 @@ public static Order getOrderForGetOrderStatusData2Test() { hashMap.put(2, 1); return Order.builder() - .id(1L) - .amountOfBagsOrdered(hashMap) - .confirmedQuantity(hashMap) - .exportedQuantity(hashMap) - .pointsToUse(100) - .orderStatus(OrderStatus.DONE) - .payment(Lists.newArrayList(Payment.builder() - .paymentId("1L") - .amount(200_00L) - .currency("UAH") - .settlementDate("20.02.1990") - .comment("avb") - .paymentStatus(PaymentStatus.PAID) - .build())) - .ubsUser(UBSuser.builder() - .firstName("oleh") - .lastName("ivanov") - .email("mail@mail.ua") + .orderBags(Arrays.asList(getOrderBag(), getOrderBag2())) .id(1L) - .phoneNumber("067894522") - .orderAddress(OrderAddress.builder() - .id(1L) - .city("Lviv") - .street("Levaya") - .district("frankivskiy") - .entranceNumber("5") - .addressComment("near mall") - .houseCorpus("1") - .houseNumber("4") - .coordinates(Coordinates.builder() - .latitude(49.83) - .longitude(23.88) + .amountOfBagsOrdered(hashMap) + .confirmedQuantity(hashMap) + .exportedQuantity(hashMap) + .pointsToUse(100) + .orderStatus(OrderStatus.DONE) + .payment(Lists.newArrayList(Payment.builder() + .paymentId("1L") + .amount(200_00L) + .currency("UAH") + .settlementDate("20.02.1990") + .comment("avb") + .paymentStatus(PaymentStatus.PAID) + .build())) + .ubsUser(UBSuser.builder() + .firstName("oleh") + .lastName("ivanov") + .email("mail@mail.ua") + .id(1L) + .phoneNumber("067894522") + .orderAddress(OrderAddress.builder() + .id(1L) + .city("Lviv") + .street("Levaya") + .district("frankivskiy") + .entranceNumber("5") + .addressComment("near mall") + .houseCorpus("1") + .houseNumber("4") + .coordinates(Coordinates.builder() + .latitude(49.83) + .longitude(23.88) + .build()) + .build()) + .build()) + .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").currentPoints(100).build()) + .certificates(Collections.emptySet()) + .pointsToUse(700) + .adminComment("Admin") + .cancellationComment("cancelled") + .receivingStation(ReceivingStation.builder() + .id(1L) + .name("Саперно-Слобідська") + .build()) + .orderPaymentStatus(OrderPaymentStatus.PAID) + .cancellationReason(CancellationReason.OUT_OF_CITY) + .writeOffStationSum(50_00L) + .imageReasonNotTakingBags(List.of("foto")) + + .tariffsInfo(TariffsInfo.builder() + .courier(Courier.builder() + .id(1L) + .build()) + .id(1L) + .tariffLocations(Set.of(TariffLocation.builder() + .id(1L) + .build())) + .max(99L) + .min(2L) + .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) .build()) - .build()) - .build()) - .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").currentPoints(100).build()) - .certificates(Collections.emptySet()) - .pointsToUse(700) - .adminComment("Admin") - .cancellationComment("cancelled") - .receivingStation(ReceivingStation.builder() - .id(1L) - .name("Саперно-Слобідська") - .build()) - .orderPaymentStatus(OrderPaymentStatus.PAID) - .cancellationReason(CancellationReason.OUT_OF_CITY) - .writeOffStationSum(50_00L) - .imageReasonNotTakingBags(List.of("foto")) - - .tariffsInfo(TariffsInfo.builder() - .courier(Courier.builder() - .id(1L) - .build()) - .id(1L) - .tariffLocations(Set.of(TariffLocation.builder() - .id(1L) - .build())) - .max(99L) - .min(2L) - .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) - .build()) - .build(); + .build(); } public static Order getOrderForGetOrderStatusEmptyPriceDetails() { return Order.builder() - .id(1L) - .amountOfBagsOrdered(new HashMap<>()) - .confirmedQuantity(new HashMap<>()) - .exportedQuantity(new HashMap<>()) - .pointsToUse(100) - .orderStatus(OrderStatus.DONE) - .build(); + .id(1L) + .amountOfBagsOrdered(new HashMap<>()) + .confirmedQuantity(new HashMap<>()) + .exportedQuantity(new HashMap<>()) + .pointsToUse(100) + .orderStatus(OrderStatus.DONE) + .build(); } public static Order getOrderWithoutExportedBags() { @@ -3739,387 +3774,387 @@ public static Order getOrderWithoutExportedBags() { hashMap.put(1, 1); hashMap.put(2, 1); return Order.builder() - .id(1L) - .amountOfBagsOrdered(hashMap) - .confirmedQuantity(hashMap) - .exportedQuantity(new HashMap<>()) - .pointsToUse(100) - .certificates(Collections.emptySet()) - .orderStatus(OrderStatus.CONFIRMED) - .user(User.builder().id(1L).currentPoints(100).build()) - .writeOffStationSum(50_00L) - .payment(Lists.newArrayList(Payment.builder() - .paymentId("1L") - .amount(20000L) - .currency("UAH") - .settlementDate("20.02.1990") - .comment("avb") - .paymentStatus(PaymentStatus.PAID) - .build())) - .build(); + .id(1L) + .amountOfBagsOrdered(hashMap) + .confirmedQuantity(hashMap) + .exportedQuantity(new HashMap<>()) + .pointsToUse(100) + .certificates(Collections.emptySet()) + .orderStatus(OrderStatus.CONFIRMED) + .user(User.builder().id(1L).currentPoints(100).build()) + .writeOffStationSum(50_00L) + .payment(Lists.newArrayList(Payment.builder() + .paymentId("1L") + .amount(20000L) + .currency("UAH") + .settlementDate("20.02.1990") + .comment("avb") + .paymentStatus(PaymentStatus.PAID) + .build())) + .build(); } public static Order getOrdersStatusAdjustmentDto2() { return Order.builder() - .id(1L) - .payment(List.of(Payment.builder().id(1L).build())) - .user(User.builder().id(1L).build()) - .imageReasonNotTakingBags(List.of("ss")) - .reasonNotTakingBagDescription("aa") - .orderStatus(OrderStatus.ADJUSTMENT) - .counterOrderPaymentId(1L) - .certificates(Set.of(getCertificate2())) - .pointsToUse(100) - .writeOffStationSum(50_00L) - .build(); + .id(1L) + .payment(List.of(Payment.builder().id(1L).build())) + .user(User.builder().id(1L).build()) + .imageReasonNotTakingBags(List.of("ss")) + .reasonNotTakingBagDescription("aa") + .orderStatus(OrderStatus.ADJUSTMENT) + .counterOrderPaymentId(1L) + .certificates(Set.of(getCertificate2())) + .pointsToUse(100) + .writeOffStationSum(50_00L) + .build(); } public static Order getOrdersStatusConfirmedDto() { return Order.builder() - .id(1L) - .payment(List.of(Payment.builder().id(1L).build())) - .user(User.builder().id(1L).build()) - .imageReasonNotTakingBags(List.of("ss")) - .reasonNotTakingBagDescription("aa") - .orderStatus(OrderStatus.CONFIRMED) - .counterOrderPaymentId(1L) - .build(); + .id(1L) + .payment(List.of(Payment.builder().id(1L).build())) + .user(User.builder().id(1L).build()) + .imageReasonNotTakingBags(List.of("ss")) + .reasonNotTakingBagDescription("aa") + .orderStatus(OrderStatus.CONFIRMED) + .counterOrderPaymentId(1L) + .build(); } public static Order getOrdersStatusFormedDto() { return Order.builder() - .id(1L) - .payment(List.of(Payment.builder().id(1L).build())) - .user(User.builder().id(1L).build()) - .imageReasonNotTakingBags(List.of("ss")) - .reasonNotTakingBagDescription("aa") - .orderStatus(OrderStatus.FORMED) - .counterOrderPaymentId(1L) - .pointsToUse(100) - .confirmedQuantity(Map.of(1, 1)) - .exportedQuantity(Map.of(1, 1)) - .amountOfBagsOrdered(Map.of(1, 1)) - .build(); + .id(1L) + .payment(List.of(Payment.builder().id(1L).build())) + .user(User.builder().id(1L).build()) + .imageReasonNotTakingBags(List.of("ss")) + .reasonNotTakingBagDescription("aa") + .orderStatus(OrderStatus.FORMED) + .counterOrderPaymentId(1L) + .pointsToUse(100) + .confirmedQuantity(Map.of(1, 1)) + .exportedQuantity(Map.of(1, 1)) + .amountOfBagsOrdered(Map.of(1, 1)) + .build(); } public static Order getOrdersStatusFormedDto2() { return Order.builder() - .id(1L) - .payment(List.of(Payment.builder().id(1L).build())) - .user(User.builder().id(1L).build()) - .imageReasonNotTakingBags(List.of("ss")) - .reasonNotTakingBagDescription("aa") - .orderStatus(OrderStatus.FORMED) - .counterOrderPaymentId(1L) - .pointsToUse(100) - .confirmedQuantity(Map.of(1, 3)) - .exportedQuantity(Map.of(1, 1)) - .amountOfBagsOrdered(Map.of(1, 1)) - .build(); + .id(1L) + .payment(List.of(Payment.builder().id(1L).build())) + .user(User.builder().id(1L).build()) + .imageReasonNotTakingBags(List.of("ss")) + .reasonNotTakingBagDescription("aa") + .orderStatus(OrderStatus.FORMED) + .counterOrderPaymentId(1L) + .pointsToUse(100) + .confirmedQuantity(Map.of(1, 3)) + .exportedQuantity(Map.of(1, 1)) + .amountOfBagsOrdered(Map.of(1, 1)) + .build(); } public static Order getOrdersStatusNotTakenOutDto() { return Order.builder() - .id(1L) - .payment(List.of(Payment.builder().id(1L).build())) - .user(User.builder().id(1L).build()) - .imageReasonNotTakingBags(List.of("ss")) - .reasonNotTakingBagDescription("aa") - .orderStatus(OrderStatus.NOT_TAKEN_OUT) - .counterOrderPaymentId(1L) - .build(); + .id(1L) + .payment(List.of(Payment.builder().id(1L).build())) + .user(User.builder().id(1L).build()) + .imageReasonNotTakingBags(List.of("ss")) + .reasonNotTakingBagDescription("aa") + .orderStatus(OrderStatus.NOT_TAKEN_OUT) + .counterOrderPaymentId(1L) + .build(); } public static Order getOrdersStatusOnThe_RouteDto() { return Order.builder() - .id(1L) - .payment(List.of(Payment.builder().id(1L).build())) - .user(User.builder().id(1L).build()) - .imageReasonNotTakingBags(List.of("ss")) - .reasonNotTakingBagDescription("aa") - .orderStatus(OrderStatus.ON_THE_ROUTE) - .counterOrderPaymentId(1L) - .build(); + .id(1L) + .payment(List.of(Payment.builder().id(1L).build())) + .user(User.builder().id(1L).build()) + .imageReasonNotTakingBags(List.of("ss")) + .reasonNotTakingBagDescription("aa") + .orderStatus(OrderStatus.ON_THE_ROUTE) + .counterOrderPaymentId(1L) + .build(); } public static Order getOrdersStatusBROUGHT_IT_HIMSELFDto() { return Order.builder() - .id(1L) - .payment(List.of(Payment.builder().id(1L).build())) - .user(User.builder().id(1L).build()) - .imageReasonNotTakingBags(List.of("ss")) - .reasonNotTakingBagDescription("aa") - .orderStatus(OrderStatus.BROUGHT_IT_HIMSELF) - .counterOrderPaymentId(1L) - .build(); + .id(1L) + .payment(List.of(Payment.builder().id(1L).build())) + .user(User.builder().id(1L).build()) + .imageReasonNotTakingBags(List.of("ss")) + .reasonNotTakingBagDescription("aa") + .orderStatus(OrderStatus.BROUGHT_IT_HIMSELF) + .counterOrderPaymentId(1L) + .build(); } public static Order getOrdersStatusDoneDto() { return Order.builder() - .id(1L) - .payment(List.of(Payment.builder().id(1L).build())) - .user(User.builder().id(1L).build()) - .imageReasonNotTakingBags(List.of("ss")) - .reasonNotTakingBagDescription("aa") - .orderStatus(OrderStatus.DONE) - .counterOrderPaymentId(1L) - .certificates(Set.of(Certificate.builder() - .points(0) - .build())) - .pointsToUse(0) - .build(); + .id(1L) + .payment(List.of(Payment.builder().id(1L).build())) + .user(User.builder().id(1L).build()) + .imageReasonNotTakingBags(List.of("ss")) + .reasonNotTakingBagDescription("aa") + .orderStatus(OrderStatus.DONE) + .counterOrderPaymentId(1L) + .certificates(Set.of(Certificate.builder() + .points(0) + .build())) + .pointsToUse(0) + .build(); } public static Order getOrdersStatusCanseledDto() { return Order.builder() - .id(1L) - .payment(List.of(Payment.builder().id(1L).build())) - .user(User.builder().id(1L).build()) - .imageReasonNotTakingBags(List.of("ss")) - .reasonNotTakingBagDescription("aa") - .orderStatus(OrderStatus.CANCELED) - .counterOrderPaymentId(1L) - .build(); + .id(1L) + .payment(List.of(Payment.builder().id(1L).build())) + .user(User.builder().id(1L).build()) + .imageReasonNotTakingBags(List.of("ss")) + .reasonNotTakingBagDescription("aa") + .orderStatus(OrderStatus.CANCELED) + .counterOrderPaymentId(1L) + .build(); } public static OrderAddressExportDetailsDtoUpdate getOrderAddressExportDetailsDtoUpdate() { return OrderAddressExportDetailsDtoUpdate.builder() - .addressId(1L) - .addressStreet("Street") - .addressStreetEng("StreetEng") - .addressCity("City") - .addressCityEng("City") - .addressDistrict("District") - .addressDistrictEng("DistrictEng") - .addressHouseCorpus("12") - .addressEntranceNumber("2") - .addressRegion("Region") - .addressRegionEng("RegionEng") - .addressHouseNumber("123") - .build(); + .addressId(1L) + .addressStreet("Street") + .addressStreetEng("StreetEng") + .addressCity("City") + .addressCityEng("City") + .addressDistrict("District") + .addressDistrictEng("DistrictEng") + .addressHouseCorpus("12") + .addressEntranceNumber("2") + .addressRegion("Region") + .addressRegionEng("RegionEng") + .addressHouseNumber("123") + .build(); } public static CustomTableView getCustomTableView() { return CustomTableView.builder() - .id(1L) - .uuid("uuid1") - .titles("title") - .build(); + .id(1L) + .uuid("uuid1") + .titles("title") + .build(); } public static ReadAddressByOrderDto getReadAddressByOrderDto() { return ReadAddressByOrderDto.builder() - .street("Levaya") - .district("frankivskiy") - .entranceNumber("5") - .houseCorpus("1") - .houseNumber("4") - .comment("helo") - .build(); + .street("Levaya") + .district("frankivskiy") + .entranceNumber("5") + .houseCorpus("1") + .houseNumber("4") + .comment("helo") + .build(); } public static RequestToChangeOrdersDataDto getRequestToChangeOrdersDataDTO() { return RequestToChangeOrdersDataDto.builder() - .columnName("orderStatus") - .orderIdsList(List.of(1L)) - .newValue("1") - .build(); + .columnName("orderStatus") + .orderIdsList(List.of(1L)) + .newValue("1") + .build(); } public static RequestToChangeOrdersDataDto getRequestToAddAdminCommentForOrder() { return RequestToChangeOrdersDataDto.builder() - .columnName("adminComment") - .orderIdsList(List.of(1L)) - .newValue("Admin Comment") - .build(); + .columnName("adminComment") + .orderIdsList(List.of(1L)) + .newValue("Admin Comment") + .build(); } public static List botList() { List botList = new ArrayList<>(); botList.add(new Bot() - .setType("TELEGRAM") - .setLink("https://telegram.me/ubs_test_bot?start=87df9ad5-6393-441f-8423-8b2e770b01a8")); + .setType("TELEGRAM") + .setLink("https://telegram.me/ubs_test_bot?start=87df9ad5-6393-441f-8423-8b2e770b01a8")); botList.add(new Bot() - .setType("VIBER") - .setLink("viber://pa?chatURI=ubstestbot1&context=87df9ad5-6393-441f-8423-8b2e770b01a8")); + .setType("VIBER") + .setLink("viber://pa?chatURI=ubstestbot1&context=87df9ad5-6393-441f-8423-8b2e770b01a8")); return botList; } public static UpdateAllOrderPageDto updateAllOrderPageDto() { return UpdateAllOrderPageDto.builder() - .orderId(List.of(1L)) - .exportDetailsDto(ExportDetailsDtoUpdate - .builder() - .dateExport("1997-12-04T15:40:24") - .timeDeliveryFrom("1997-12-04T15:40:24") - .timeDeliveryTo("1990-12-11T19:30:30") - .receivingStationId(1L) - .build()) - .updateResponsibleEmployeeDto(List.of(UpdateResponsibleEmployeeDto.builder() - .positionId(2L) - .employeeId(2L) - .build())) - .build(); + .orderId(List.of(1L)) + .exportDetailsDto(ExportDetailsDtoUpdate + .builder() + .dateExport("1997-12-04T15:40:24") + .timeDeliveryFrom("1997-12-04T15:40:24") + .timeDeliveryTo("1990-12-11T19:30:30") + .receivingStationId(1L) + .build()) + .updateResponsibleEmployeeDto(List.of(UpdateResponsibleEmployeeDto.builder() + .positionId(2L) + .employeeId(2L) + .build())) + .build(); } public static Order getOrder2() { return Order.builder() - .id(1L) - .payment(Lists.newArrayList(Payment.builder() - .paymentId("1") - .amount(20000L) - .currency("UAH") - .settlementDate("20.02.1990") - .comment("avb") - .paymentStatus(PaymentStatus.PAID) - .build())) - .ubsUser(UBSuser.builder() - .firstName("oleh") - .lastName("ivanov") - .email("mail@mail.ua") .id(1L) - .phoneNumber("067894522") - .orderAddress(OrderAddress.builder() - .id(1L) - .city("Lviv") - .street("Levaya") - .district("frankivskiy") - .entranceNumber("5") - .addressComment("near mall") - .houseCorpus("1") - .houseNumber("4") - .coordinates(Coordinates.builder() - .latitude(49.83) - .longitude(23.88) + .payment(Lists.newArrayList(Payment.builder() + .paymentId("1") + .amount(20000L) + .currency("UAH") + .settlementDate("20.02.1990") + .comment("avb") + .paymentStatus(PaymentStatus.PAID) + .build())) + .ubsUser(UBSuser.builder() + .firstName("oleh") + .lastName("ivanov") + .email("mail@mail.ua") + .id(1L) + .phoneNumber("067894522") + .orderAddress(OrderAddress.builder() + .id(1L) + .city("Lviv") + .street("Levaya") + .district("frankivskiy") + .entranceNumber("5") + .addressComment("near mall") + .houseCorpus("1") + .houseNumber("4") + .coordinates(Coordinates.builder() + .latitude(49.83) + .longitude(23.88) + .build()) + .build()) .build()) - .build()) - .build()) - .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").build()) - .certificates(Collections.emptySet()) - .pointsToUse(700) - .adminComment("Admin") - .cancellationComment("cancelled") - .receivingStation(ReceivingStation.builder() - .id(1L) - .name("Саперно-Слобідська") - .build()) - .orderPaymentStatus(OrderPaymentStatus.PAID) - .cancellationReason(CancellationReason.OUT_OF_CITY) - .imageReasonNotTakingBags(List.of("foto")) - .orderPaymentStatus(OrderPaymentStatus.UNPAID) - .additionalOrders(new HashSet<>()) - .build(); + .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").build()) + .certificates(Collections.emptySet()) + .pointsToUse(700) + .adminComment("Admin") + .cancellationComment("cancelled") + .receivingStation(ReceivingStation.builder() + .id(1L) + .name("Саперно-Слобідська") + .build()) + .orderPaymentStatus(OrderPaymentStatus.PAID) + .cancellationReason(CancellationReason.OUT_OF_CITY) + .imageReasonNotTakingBags(List.of("foto")) + .orderPaymentStatus(OrderPaymentStatus.UNPAID) + .additionalOrders(new HashSet<>()) + .build(); } public static AddBonusesToUserDto getAddBonusesToUserDto() { return AddBonusesToUserDto.builder() - .paymentId("5") - .receiptLink("test") - .settlementdate("test") - .amount(1000L) - .build(); + .paymentId("5") + .receiptLink("test") + .settlementdate("test") + .amount(1000L) + .build(); } public static GetTariffsInfoDto getAllTariffsInfoDto() { Location location = getLocation(); return GetTariffsInfoDto.builder() - .cardId(1L) - .locationInfoDtos(List.of(LocationsDtos.builder() - .locationId(location.getId()) - .nameEn(location.getNameEn()) - .nameUk(location.getNameUk()).build())) - .courierDto(getCourierDto()) - .createdAt(LocalDate.of(22, 2, 12)) - .creator(EmployeeNameDto.builder() - .email("sss@gmail.com").build()) - .build(); + .cardId(1L) + .locationInfoDtos(List.of(LocationsDtos.builder() + .locationId(location.getId()) + .nameEn(location.getNameEn()) + .nameUk(location.getNameUk()).build())) + .courierDto(getCourierDto()) + .createdAt(LocalDate.of(22, 2, 12)) + .creator(EmployeeNameDto.builder() + .email("sss@gmail.com").build()) + .build(); } public static GetTariffLimitsDto getGetTariffLimitsDto() { return GetTariffLimitsDto.builder() - .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) - .max(20L) - .min(2L) - .build(); + .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) + .max(20L) + .min(2L) + .build(); } public static TariffsInfo getTariffsInfo() { return TariffsInfo.builder() - .id(1L) - .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) - .max(20L) - .min(2L) - .tariffLocations(Set.of(TariffLocation.builder() - .location(getLocation()) - .build())) - .receivingStationList(Set.of(getReceivingStation())) - .courier(getCourier()) - .service(getService()) - .build(); + .id(1L) + .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) + .max(20L) + .min(2L) + .tariffLocations(Set.of(TariffLocation.builder() + .location(getLocation()) + .build())) + .receivingStationList(Set.of(getReceivingStation())) + .courier(getCourier()) + .service(getService()) + .build(); } public static TariffsInfo getTariffsInfoActive() { return TariffsInfo.builder() - .id(1L) - .tariffStatus(TariffStatus.ACTIVE) - .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) - .max(20L) - .min(2L) - .tariffLocations(Set.of(TariffLocation.builder() - .location(getLocation()) - .build())) - .receivingStationList(Set.of(getReceivingStation())) - .courier(getCourier()) - .service(getService()) - .bags(getBag4list()) - .build(); + .id(1L) + .tariffStatus(TariffStatus.ACTIVE) + .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) + .max(20L) + .min(2L) + .tariffLocations(Set.of(TariffLocation.builder() + .location(getLocation()) + .build())) + .receivingStationList(Set.of(getReceivingStation())) + .courier(getCourier()) + .service(getService()) + .bags(getBag4list()) + .build(); } public static TariffsInfo getTariffsInfoDeactivated() { return TariffsInfo.builder() - .id(1L) - .tariffStatus(TariffStatus.DEACTIVATED) - .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) - .max(20L) - .min(2L) - .tariffLocations(Set.of(TariffLocation.builder() - .location(getLocation()) - .build())) - .receivingStationList(Set.of(getReceivingStation())) - .courier(getCourier()) - .service(getService()) - .bags(getBag4list()) - .build(); + .id(1L) + .tariffStatus(TariffStatus.DEACTIVATED) + .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) + .max(20L) + .min(2L) + .tariffLocations(Set.of(TariffLocation.builder() + .location(getLocation()) + .build())) + .receivingStationList(Set.of(getReceivingStation())) + .courier(getCourier()) + .service(getService()) + .bags(getBag4list()) + .build(); } public static OrdersDataForUserDto getOrderStatusDto() { SenderInfoDto senderInfoDto = SenderInfoDto.builder() - .senderName("TestName") - .senderSurname("TestSurName") - .senderPhone("38099884433") - .senderEmail("test@mail.com") - .build(); + .senderName("TestName") + .senderSurname("TestSurName") + .senderPhone("38099884433") + .senderEmail("test@mail.com") + .build(); CertificateDto certificateDto = CertificateDto.builder() - .points(300) - .dateOfUse(LocalDate.now()) - .expirationDate(LocalDate.now()) - .code("200") - .certificateStatus("ACTIVE") - .build(); + .points(300) + .dateOfUse(LocalDate.now()) + .expirationDate(LocalDate.now()) + .code("200") + .certificateStatus("ACTIVE") + .build(); AddressInfoDto addressInfoDto = AddressInfoDto.builder() - .addressStreet("StreetTest") - .addressDistinct("AdressDistinctTest") - .addressRegion("TestRegion") - .addressComment("TestComment") - .addressCity("TestCity") - .addressStreetEng("StreetEng") - .addressDistinctEng("DisticntEng") - .addressCityEng("CityEng") - .addressRegionEng("RegionEng") - .build(); + .addressStreet("StreetTest") + .addressDistinct("AdressDistinctTest") + .addressRegion("TestRegion") + .addressComment("TestComment") + .addressCity("TestCity") + .addressStreetEng("StreetEng") + .addressDistinctEng("DisticntEng") + .addressCityEng("CityEng") + .addressRegionEng("RegionEng") + .build(); BagForUserDto bagForUserDto = new BagForUserDto(); bagForUserDto.setTotalPrice(900.); @@ -4130,162 +4165,162 @@ public static OrdersDataForUserDto getOrderStatusDto() { bagForUserDto.setServiceEng("Safe Waste"); return OrdersDataForUserDto.builder() - .id(1L) - .dateForm(LocalDateTime.of(22, 10, 12, 14, 55)) - .datePaid(LocalDateTime.now()) - .amountBeforePayment(500d) - .bonuses(100d) - .orderFullPrice(400d) - .orderComment("abc") - .paymentStatus(PaymentStatus.PAID.toString()) - .sender(senderInfoDto) - .address(addressInfoDto) - .paymentStatusEng(PaymentStatus.PAID.toString()) - .orderStatus(OrderStatus.FORMED.toString()) - .orderStatusEng(OrderStatus.FORMED.toString()) - .bags(List.of(bagForUserDto)) - .certificate(List.of(certificateDto)) - .additionalOrders(Collections.emptySet()) - .build(); + .id(1L) + .dateForm(LocalDateTime.of(22, 10, 12, 14, 55)) + .datePaid(LocalDateTime.now()) + .amountBeforePayment(500d) + .bonuses(100d) + .orderFullPrice(400d) + .orderComment("abc") + .paymentStatus(PaymentStatus.PAID.toString()) + .sender(senderInfoDto) + .address(addressInfoDto) + .paymentStatusEng(PaymentStatus.PAID.toString()) + .orderStatus(OrderStatus.FORMED.toString()) + .orderStatusEng(OrderStatus.FORMED.toString()) + .bags(List.of(bagForUserDto)) + .certificate(List.of(certificateDto)) + .additionalOrders(Collections.emptySet()) + .build(); } public static TariffsInfo getTariffInfo() { return TariffsInfo.builder() - .id(1L) - .courier(ModelUtils.getCourier()) - .courierLimit(CourierLimit.LIMIT_BY_SUM_OF_ORDER) - .tariffLocations(Set.of(TariffLocation.builder() - .tariffsInfo(ModelUtils.getTariffInfoWithLimitOfBags()) - .locationStatus(LocationStatus.ACTIVE) - .location(Location.builder().id(1L) - .locationStatus(LocationStatus.ACTIVE) - .region(ModelUtils.getRegion()) - .nameUk("Київ") - .nameEn("Kyiv") - .coordinates(ModelUtils.getCoordinates()) - .build()) - .build())) - .tariffStatus(TariffStatus.ACTIVE) - .creator(ModelUtils.getEmployee()) - .createdAt(LocalDate.of(2022, 10, 20)) - .max(6000L) - .min(500L) - .orders(Collections.emptyList()) - .receivingStationList(Set.of(ReceivingStation.builder() .id(1L) - .name("Петрівка") - .createdBy(ModelUtils.createEmployee()) - .build())) - .build(); + .courier(ModelUtils.getCourier()) + .courierLimit(CourierLimit.LIMIT_BY_SUM_OF_ORDER) + .tariffLocations(Set.of(TariffLocation.builder() + .tariffsInfo(ModelUtils.getTariffInfoWithLimitOfBags()) + .locationStatus(LocationStatus.ACTIVE) + .location(Location.builder().id(1L) + .locationStatus(LocationStatus.ACTIVE) + .region(ModelUtils.getRegion()) + .nameUk("Київ") + .nameEn("Kyiv") + .coordinates(ModelUtils.getCoordinates()) + .build()) + .build())) + .tariffStatus(TariffStatus.ACTIVE) + .creator(ModelUtils.getEmployee()) + .createdAt(LocalDate.of(2022, 10, 20)) + .max(6000L) + .min(500L) + .orders(Collections.emptyList()) + .receivingStationList(Set.of(ReceivingStation.builder() + .id(1L) + .name("Петрівка") + .createdBy(ModelUtils.createEmployee()) + .build())) + .build(); } public static TariffsInfo getTariffsInfoWithStatusNew() { return TariffsInfo.builder() - .id(1L) - .courierLimit(CourierLimit.LIMIT_BY_SUM_OF_ORDER) - .tariffLocations(Set.of(TariffLocation.builder() - .tariffsInfo(ModelUtils.getTariffInfoWithLimitOfBags()) - .location(Location.builder().id(1L) - .region(ModelUtils.getRegion()) - .nameUk("Київ") - .nameEn("Kyiv") - .coordinates(ModelUtils.getCoordinates()) - .build()) - .build())) - .tariffStatus(TariffStatus.NEW) - .creator(ModelUtils.getEmployee()) - .createdAt(LocalDate.of(2022, 10, 20)) - .orders(Collections.emptyList()) - .receivingStationList(Set.of(ReceivingStation.builder() .id(1L) - .name("Петрівка") - .createdBy(ModelUtils.createEmployee()) - .build())) - .build(); + .courierLimit(CourierLimit.LIMIT_BY_SUM_OF_ORDER) + .tariffLocations(Set.of(TariffLocation.builder() + .tariffsInfo(ModelUtils.getTariffInfoWithLimitOfBags()) + .location(Location.builder().id(1L) + .region(ModelUtils.getRegion()) + .nameUk("Київ") + .nameEn("Kyiv") + .coordinates(ModelUtils.getCoordinates()) + .build()) + .build())) + .tariffStatus(TariffStatus.NEW) + .creator(ModelUtils.getEmployee()) + .createdAt(LocalDate.of(2022, 10, 20)) + .orders(Collections.emptyList()) + .receivingStationList(Set.of(ReceivingStation.builder() + .id(1L) + .name("Петрівка") + .createdBy(ModelUtils.createEmployee()) + .build())) + .build(); } public static TariffsInfo getTariffInfoWithLimitOfBags() { return TariffsInfo.builder() - .id(1L) - .courier(ModelUtils.getCourier()) - .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) - .tariffLocations(Set.of(TariffLocation.builder() - .location(Location.builder().id(1L) - .region(ModelUtils.getRegion()) - .nameUk("Київ") - .nameEn("Kyiv") - .coordinates(ModelUtils.getCoordinates()) - .build()) - .build())) - .tariffStatus(TariffStatus.ACTIVE) - .creator(ModelUtils.getEmployee()) - .createdAt(LocalDate.of(2022, 10, 20)) - .max(100L) - .min(5L) - .orders(List.of(ModelUtils.getOrder())) - .build(); + .id(1L) + .courier(ModelUtils.getCourier()) + .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) + .tariffLocations(Set.of(TariffLocation.builder() + .location(Location.builder().id(1L) + .region(ModelUtils.getRegion()) + .nameUk("Київ") + .nameEn("Kyiv") + .coordinates(ModelUtils.getCoordinates()) + .build()) + .build())) + .tariffStatus(TariffStatus.ACTIVE) + .creator(ModelUtils.getEmployee()) + .createdAt(LocalDate.of(2022, 10, 20)) + .max(100L) + .min(5L) + .orders(List.of(ModelUtils.getOrder())) + .build(); } public static TariffsInfo getTariffInfoWithLimitOfBagsAndMaxLessThanCountOfBigBag() { return TariffsInfo.builder() - .id(1L) - .courier(ModelUtils.getCourier()) - .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) - .tariffLocations(Set.of(TariffLocation.builder() - .location(Location.builder().id(1L) - .region(ModelUtils.getRegion()) - .nameUk("Київ") - .nameEn("Kyiv") - .coordinates(ModelUtils.getCoordinates()) - .build()) - .build())) - .tariffStatus(TariffStatus.ACTIVE) - .creator(ModelUtils.getEmployee()) - .createdAt(LocalDate.of(2022, 10, 20)) - .max(10L) - .min(5L) - .orders(List.of(ModelUtils.getOrder())) - .build(); + .id(1L) + .courier(ModelUtils.getCourier()) + .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) + .tariffLocations(Set.of(TariffLocation.builder() + .location(Location.builder().id(1L) + .region(ModelUtils.getRegion()) + .nameUk("Київ") + .nameEn("Kyiv") + .coordinates(ModelUtils.getCoordinates()) + .build()) + .build())) + .tariffStatus(TariffStatus.ACTIVE) + .creator(ModelUtils.getEmployee()) + .createdAt(LocalDate.of(2022, 10, 20)) + .max(10L) + .min(5L) + .orders(List.of(ModelUtils.getOrder())) + .build(); } public static AddNewTariffDto getAddNewTariffDto() { return AddNewTariffDto.builder() - .courierId(1L) - .locationIdList(List.of(1L)) - .receivingStationsIdList(List.of(1L)) - .regionId(1L) - .build(); + .courierId(1L) + .locationIdList(List.of(1L)) + .receivingStationsIdList(List.of(1L)) + .regionId(1L) + .build(); } public static EditTariffDto getEditTariffDto() { return EditTariffDto.builder() - .locationIds(List.of(1L)) - .receivingStationIds(List.of(1L)) - .courierId(1L) - .build(); + .locationIds(List.of(1L)) + .receivingStationIds(List.of(1L)) + .courierId(1L) + .build(); } public static EditTariffDto getEditTariffDtoWithoutCourier() { return EditTariffDto.builder() - .locationIds(List.of(1L)) - .receivingStationIds(List.of(1L)) - .build(); + .locationIds(List.of(1L)) + .receivingStationIds(List.of(1L)) + .build(); } public static EditTariffDto getEditTariffDtoWith2Locations() { return EditTariffDto.builder() - .locationIds(List.of(1L, 2L)) - .receivingStationIds(List.of(1L)) - .build(); + .locationIds(List.of(1L, 2L)) + .receivingStationIds(List.of(1L)) + .build(); } public static String getSuccessfulFondyResponse() { return "{\n" + - " \"response\":{\n" + - " \"response_status\":\"success\",\n" + - " \"checkout_url\":\"https://pay.fondy.eu/checkout?token=afcb21aef707b1fea2565b66bac7dc41d7833390\"\n" + - " }\n" + - "}"; + " \"response\":{\n" + + " \"response_status\":\"success\",\n" + + " \"checkout_url\":\"https://pay.fondy.eu/checkout?token=afcb21aef707b1fea2565b66bac7dc41d7833390\"\n" + + " }\n" + + "}"; } public static List getGeocodingResult() { @@ -4317,11 +4352,11 @@ public static List getGeocodingResult() { route.types = new AddressComponentType[] {AddressComponentType.ROUTE}; geocodingResult1.addressComponents = new AddressComponent[] { - locality, - streetNumber, - region, - sublocality, - route + locality, + streetNumber, + region, + sublocality, + route }; geocodingResult1.formattedAddress = "fake address"; @@ -4350,11 +4385,11 @@ public static List getGeocodingResult() { route2.types = new AddressComponentType[] {AddressComponentType.ROUTE}; geocodingResult2.addressComponents = new AddressComponent[] { - locality2, - streetNumber2, - region2, - sublocality2, - route2 + locality2, + streetNumber2, + region2, + sublocality2, + route2 }; geocodingResult2.formattedAddress = "fake address 2"; @@ -4368,37 +4403,37 @@ public static List getGeocodingResult() { public static CreateAddressRequestDto getAddressRequestDto() { return CreateAddressRequestDto.builder() - .addressComment("fdsfs") - .searchAddress("fake street name, 13, fake street, 02000") - .district("fdsfds") - .districtEn("dsadsad") - .region("regdsad") - .regionEn("regdsaden") - .houseNumber("1") - .houseCorpus("2") - .entranceNumber("3") - .placeId("place_id") - .build(); + .addressComment("fdsfs") + .searchAddress("fake street name, 13, fake street, 02000") + .district("fdsfds") + .districtEn("dsadsad") + .region("regdsad") + .regionEn("regdsaden") + .houseNumber("1") + .houseCorpus("2") + .entranceNumber("3") + .placeId("place_id") + .build(); } public static OrderAddressDtoRequest getTestOrderAddressDtoRequest() { return OrderAddressDtoRequest.builder() - .id(0L) - .region("fake region") - .searchAddress("fake street name, 13, fake street, 02000") - .city("fake street") - .district("fake district") - .entranceNumber("1") - .houseNumber("13") - .houseCorpus("1") - .street("fake street name") - .streetEn("fake street name") - .coordinates(new Coordinates(50.5555555d, 50.5555555d)) - .cityEn("fake street") - .districtEn("fake district") - .regionEn("fake region") - .placeId("place_id") - .build(); + .id(0L) + .region("fake region") + .searchAddress("fake street name, 13, fake street, 02000") + .city("fake street") + .district("fake district") + .entranceNumber("1") + .houseNumber("13") + .houseCorpus("1") + .street("fake street name") + .streetEn("fake street name") + .coordinates(new Coordinates(50.5555555d, 50.5555555d)) + .cityEn("fake street") + .districtEn("fake district") + .regionEn("fake region") + .placeId("place_id") + .build(); } public static OrderAddressDtoRequest getTestOrderAddressLocationDto() { @@ -4407,21 +4442,21 @@ public static OrderAddressDtoRequest getTestOrderAddressLocationDto() { public static OrderAddressDtoRequest getTestOrderAddressLocationDto(boolean withDistrictRegionHouse) { return OrderAddressDtoRequest.builder() - .id(0L) - .region(withDistrictRegionHouse ? "fake region" : null) - .city("fake street") - .district(withDistrictRegionHouse ? "fake district" : null) - .entranceNumber("1") - .houseNumber("13") - .houseCorpus("1") - .street("fake street name") - .streetEn("fake street name") - .coordinates(new Coordinates(50.5555555d, 50.5555555d)) - .cityEn("fake street") - .districtEn(withDistrictRegionHouse ? "fake district" : null) - .regionEn(withDistrictRegionHouse ? "fake region" : null) - .placeId("place_id") - .build(); + .id(0L) + .region(withDistrictRegionHouse ? "fake region" : null) + .city("fake street") + .district(withDistrictRegionHouse ? "fake district" : null) + .entranceNumber("1") + .houseNumber("13") + .houseCorpus("1") + .street("fake street name") + .streetEn("fake street name") + .coordinates(new Coordinates(50.5555555d, 50.5555555d)) + .cityEn("fake street") + .districtEn(withDistrictRegionHouse ? "fake district" : null) + .regionEn(withDistrictRegionHouse ? "fake region" : null) + .placeId("place_id") + .build(); } public static User getUserForCreate() { @@ -4430,40 +4465,40 @@ public static User getUserForCreate() { public static User getUserForCreate(AddressStatus addressStatus) { return User.builder() - .id(1L) - .addresses(List.of(Address.builder().id(7L).city("fake street").cityEn("fake street") - .district("fake district").districtEn("fake district").region("fake region").regionEn("fake region") - .street("fake street name").streetEn("fake street name").houseNumber("13").addressStatus(addressStatus) - .coordinates(new Coordinates(50.5555555, 50.5555555)).build())) - .recipientEmail("someUser@gmail.com") - .recipientPhone("962473289") - .recipientSurname("Ivanov") - .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") - .recipientName("Taras") - .uuid("uuid") - .ubsUsers(getUbsUsers()) - .currentPoints(100) - .build(); + .id(1L) + .addresses(List.of(Address.builder().id(7L).city("fake street").cityEn("fake street") + .district("fake district").districtEn("fake district").region("fake region").regionEn("fake region") + .street("fake street name").streetEn("fake street name").houseNumber("13").addressStatus(addressStatus) + .coordinates(new Coordinates(50.5555555, 50.5555555)).build())) + .recipientEmail("someUser@gmail.com") + .recipientPhone("962473289") + .recipientSurname("Ivanov") + .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") + .recipientName("Taras") + .uuid("uuid") + .ubsUsers(getUbsUsers()) + .currentPoints(100) + .build(); } public static OrderWithAddressesResponseDto getAddressDtoResponse() { return OrderWithAddressesResponseDto.builder() - .addressList(List.of( - AddressDto.builder() - .id(1L) - .city("City") - .district("Distinct") - .entranceNumber("7a") - .houseCorpus("2") - .houseNumber("25") - .street("Street") - .coordinates(Coordinates.builder() - .latitude(50.4459068) - .longitude(30.4477005) - .build()) - .actual(false) - .build())) - .build(); + .addressList(List.of( + AddressDto.builder() + .id(1L) + .city("City") + .district("Distinct") + .entranceNumber("7a") + .houseCorpus("2") + .houseNumber("25") + .street("Street") + .coordinates(Coordinates.builder() + .latitude(50.4459068) + .longitude(30.4477005) + .build()) + .actual(false) + .build())) + .build(); } public static TariffsForLocationDto getTariffsForLocationDto() { @@ -4472,20 +4507,20 @@ public static TariffsForLocationDto getTariffsForLocationDto() { public static CertificateDto createCertificateDto() { return CertificateDto.builder() - .points(300) - .dateOfUse(LocalDate.now()) - .expirationDate(LocalDate.now()) - .code("200") - .certificateStatus("ACTIVE") - .build(); + .points(300) + .dateOfUse(LocalDate.now()) + .expirationDate(LocalDate.now()) + .code("200") + .certificateStatus("ACTIVE") + .build(); } public static CourierTranslationDto getCourierTranslationDto(Long id) { return CourierTranslationDto.builder() - .id(id) - .nameUk("Тест") - .nameEn("Test") - .build(); + .id(id) + .nameUk("Тест") + .nameEn("Test") + .build(); } public static List
getMaximumAmountOfAddresses() { @@ -4498,297 +4533,297 @@ public static List getAllAuthorities() { public static UserEmployeeAuthorityDto getUserEmployeeAuthorityDto() { return UserEmployeeAuthorityDto.builder() - .employeeEmail("test@mail.com") - .authorities(getAllAuthorities()) - .build(); + .employeeEmail("test@mail.com") + .authorities(getAllAuthorities()) + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithEmptyParams() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.empty()) - .citiesIds(Optional.empty()) - .stationsIds(Optional.empty()) - .courierId(Optional.empty()) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.empty()) + .citiesIds(Optional.empty()) + .stationsIds(Optional.empty()) + .courierId(Optional.empty()) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithRegion() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.of(List.of(1L))) - .citiesIds(Optional.empty()) - .stationsIds(Optional.empty()) - .courierId(Optional.empty()) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.of(List.of(1L))) + .citiesIds(Optional.empty()) + .stationsIds(Optional.empty()) + .courierId(Optional.empty()) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithRegionAndCities() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.of(List.of(1L))) - .citiesIds(Optional.of(List.of(1L, 11L))) - .stationsIds(Optional.empty()) - .courierId(Optional.empty()) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.of(List.of(1L))) + .citiesIds(Optional.of(List.of(1L, 11L))) + .stationsIds(Optional.empty()) + .courierId(Optional.empty()) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithCourier() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.empty()) - .citiesIds(Optional.empty()) - .stationsIds(Optional.empty()) - .courierId(Optional.of(1L)) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.empty()) + .citiesIds(Optional.empty()) + .stationsIds(Optional.empty()) + .courierId(Optional.of(1L)) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithReceivingStations() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.empty()) - .citiesIds(Optional.empty()) - .stationsIds(Optional.of(List.of(1L, 12L))) - .courierId(Optional.empty()) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.empty()) + .citiesIds(Optional.empty()) + .stationsIds(Optional.of(List.of(1L, 12L))) + .courierId(Optional.empty()) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.empty()) - .citiesIds(Optional.empty()) - .stationsIds(Optional.of(List.of(1L, 12L))) - .courierId(Optional.of(1L)) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.empty()) + .citiesIds(Optional.empty()) + .stationsIds(Optional.of(List.of(1L, 12L))) + .courierId(Optional.of(1L)) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithCourierAndRegion() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.of(List.of(1L))) - .citiesIds(Optional.empty()) - .stationsIds(Optional.empty()) - .courierId(Optional.of(1L)) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.of(List.of(1L))) + .citiesIds(Optional.empty()) + .stationsIds(Optional.empty()) + .courierId(Optional.of(1L)) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.of(List.of(1L))) - .citiesIds(Optional.of(List.of(1L, 11L))) - .stationsIds(Optional.of(List.of(1L, 12L))) - .courierId(Optional.empty()) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.of(List.of(1L))) + .citiesIds(Optional.of(List.of(1L, 11L))) + .stationsIds(Optional.of(List.of(1L, 12L))) + .courierId(Optional.empty()) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithAllParams() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.of(List.of(1L))) - .citiesIds(Optional.of(List.of(1L, 11L))) - .stationsIds(Optional.of(List.of(1L, 12L))) - .courierId(Optional.of(1L)) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.of(List.of(1L))) + .citiesIds(Optional.of(List.of(1L, 11L))) + .stationsIds(Optional.of(List.of(1L, 12L))) + .courierId(Optional.of(1L)) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithStatusActive() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.of(List.of(1L))) - .citiesIds(Optional.of(List.of(1L))) - .stationsIds(Optional.of(List.of(1L))) - .courierId(Optional.of(1L)) - .activationStatus("Active") - .build(); + .regionsIds(Optional.of(List.of(1L))) + .citiesIds(Optional.of(List.of(1L))) + .stationsIds(Optional.of(List.of(1L))) + .courierId(Optional.of(1L)) + .activationStatus("Active") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.of(List.of(1L))) - .citiesIds(Optional.empty()) - .stationsIds(Optional.of(List.of(1L, 12L))) - .courierId(Optional.empty()) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.of(List.of(1L))) + .citiesIds(Optional.empty()) + .stationsIds(Optional.of(List.of(1L, 12L))) + .courierId(Optional.empty()) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.of(List.of(1L))) - .citiesIds(Optional.of(List.of(1L, 11L))) - .stationsIds(Optional.empty()) - .courierId(Optional.of(1L)) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.of(List.of(1L))) + .citiesIds(Optional.of(List.of(1L, 11L))) + .stationsIds(Optional.empty()) + .courierId(Optional.of(1L)) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.of(List.of(1L))) - .citiesIds(Optional.empty()) - .stationsIds(Optional.of(List.of(1L, 12L))) - .courierId(Optional.of(1L)) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.of(List.of(1L))) + .citiesIds(Optional.empty()) + .stationsIds(Optional.of(List.of(1L, 12L))) + .courierId(Optional.of(1L)) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithCities() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.empty()) - .citiesIds(Optional.of(List.of(1L, 11L))) - .stationsIds(Optional.empty()) - .courierId(Optional.empty()) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.empty()) + .citiesIds(Optional.of(List.of(1L, 11L))) + .stationsIds(Optional.empty()) + .courierId(Optional.empty()) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithCitiesAndCourier() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.empty()) - .citiesIds(Optional.of(List.of(1L, 11L))) - .stationsIds(Optional.empty()) - .courierId(Optional.of(1L)) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.empty()) + .citiesIds(Optional.of(List.of(1L, 11L))) + .stationsIds(Optional.empty()) + .courierId(Optional.of(1L)) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithCitiesAndReceivingStations() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.empty()) - .citiesIds(Optional.of(List.of(1L, 11L))) - .stationsIds(Optional.of(List.of(1L, 12L))) - .courierId(Optional.empty()) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.empty()) + .citiesIds(Optional.of(List.of(1L, 11L))) + .stationsIds(Optional.of(List.of(1L, 12L))) + .courierId(Optional.empty()) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithCitiesAndCourierAndReceivingStations() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.empty()) - .citiesIds(Optional.of(List.of(1L, 11L))) - .stationsIds(Optional.of(List.of(1L, 12L))) - .courierId(Optional.of(1L)) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.empty()) + .citiesIds(Optional.of(List.of(1L, 11L))) + .stationsIds(Optional.of(List.of(1L, 12L))) + .courierId(Optional.of(1L)) + .activationStatus("Deactivated") + .build(); } public static BagLimitDto getBagLimitIncludedDtoTrue() { return BagLimitDto.builder() - .id(1) - .limitIncluded(true) - .build(); + .id(1) + .limitIncluded(true) + .build(); } public static BagLimitDto getBagLimitIncludedDtoFalse() { return BagLimitDto.builder() - .id(1) - .limitIncluded(false) - .build(); + .id(1) + .limitIncluded(false) + .build(); } public static SetTariffLimitsDto setTariffLimitsWithAmountOfBags() { return SetTariffLimitsDto.builder() - .min(1L) - .max(2L) - .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) - .bagLimitDtoList(List.of(getBagLimitIncludedDtoTrue())) - .build(); + .min(1L) + .max(2L) + .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) + .bagLimitDtoList(List.of(getBagLimitIncludedDtoTrue())) + .build(); } public static SetTariffLimitsDto setTariffLimitsWithNullAllTariffParamsAndFalseBagLimit() { return SetTariffLimitsDto.builder() - .min(null) - .max(null) - .courierLimit(null) - .bagLimitDtoList(List.of(getBagLimitIncludedDtoFalse())) - .build(); + .min(null) + .max(null) + .courierLimit(null) + .bagLimitDtoList(List.of(getBagLimitIncludedDtoFalse())) + .build(); } public static SetTariffLimitsDto setTariffLimitsWithNullMinAndMaxAndFalseBagLimit() { return SetTariffLimitsDto.builder() - .min(null) - .max(null) - .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) - .bagLimitDtoList(List.of(getBagLimitIncludedDtoFalse())) - .build(); + .min(null) + .max(null) + .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) + .bagLimitDtoList(List.of(getBagLimitIncludedDtoFalse())) + .build(); } public static SetTariffLimitsDto setTariffsLimitWithSameMinAndMaxValue() { return SetTariffLimitsDto.builder() - .min(2L) - .max(2L) - .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) - .bagLimitDtoList(List.of(getBagLimitIncludedDtoTrue())) - .build(); + .min(2L) + .max(2L) + .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) + .bagLimitDtoList(List.of(getBagLimitIncludedDtoTrue())) + .build(); } public static SetTariffLimitsDto setTariffLimitsWithPriceOfOrder() { return SetTariffLimitsDto.builder() - .min(100L) - .max(200L) - .courierLimit(CourierLimit.LIMIT_BY_SUM_OF_ORDER) - .bagLimitDtoList(List.of(getBagLimitIncludedDtoTrue())) - .build(); + .min(100L) + .max(200L) + .courierLimit(CourierLimit.LIMIT_BY_SUM_OF_ORDER) + .bagLimitDtoList(List.of(getBagLimitIncludedDtoTrue())) + .build(); } public static SetTariffLimitsDto setTariffLimitsWithAmountOfBigBagsWhereMaxValueIsGreater() { return SetTariffLimitsDto.builder() - .min(2L) - .max(1L) - .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) - .bagLimitDtoList(List.of(getBagLimitIncludedDtoTrue())) - .build(); + .min(2L) + .max(1L) + .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) + .bagLimitDtoList(List.of(getBagLimitIncludedDtoTrue())) + .build(); } public static SetTariffLimitsDto setTariffLimitsWithPriceOfOrderWhereMaxValueIsGreater() { return SetTariffLimitsDto.builder() - .min(200L) - .max(100L) - .courierLimit(CourierLimit.LIMIT_BY_SUM_OF_ORDER) - .bagLimitDtoList(List.of(getBagLimitIncludedDtoTrue())) - .build(); + .min(200L) + .max(100L) + .courierLimit(CourierLimit.LIMIT_BY_SUM_OF_ORDER) + .bagLimitDtoList(List.of(getBagLimitIncludedDtoTrue())) + .build(); } public static UserPointsAndAllBagsDto getUserPointsAndAllBagsDto() { return new UserPointsAndAllBagsDto( - List.of( - BagTranslationDto.builder() - .id(1) - .name("name") - .capacity(20) - .price(150.) - .nameEng("nameEng") - .limitedIncluded(false) - .build()), - 100); + List.of( + BagTranslationDto.builder() + .id(1) + .name("name") + .capacity(20) + .price(150.) + .nameEng("nameEng") + .limitedIncluded(false) + .build()), + 100); } public static Order getOrderExportDetailsWithExportDate() { return Order.builder() - .id(1L) - .dateOfExport(LocalDate.of(2023, 2, 8)) - .user(User.builder().id(1L).recipientName("Admin").recipientSurname("Ubs").build()) - .build(); + .id(1L) + .dateOfExport(LocalDate.of(2023, 2, 8)) + .user(User.builder().id(1L).recipientName("Admin").recipientSurname("Ubs").build()) + .build(); } public static Order getOrderExportDetailsWithExportDateDeliverFrom() { return Order.builder() - .id(1L) - .dateOfExport(LocalDate.of(2023, 2, 8)) - .deliverFrom(LocalDateTime.of(2023, 2, 8, 15, 0)) - .user(User.builder().id(1L).recipientName("Admin").recipientSurname("Ubs").build()) - .build(); + .id(1L) + .dateOfExport(LocalDate.of(2023, 2, 8)) + .deliverFrom(LocalDateTime.of(2023, 2, 8, 15, 0)) + .user(User.builder().id(1L).recipientName("Admin").recipientSurname("Ubs").build()) + .build(); } public static Order getOrderExportDetailsWithExportDateDeliverFromTo() { return Order.builder() - .id(1L) - .dateOfExport(LocalDate.of(2023, 2, 8)) - .deliverFrom(LocalDateTime.of(2023, 2, 8, 15, 0)) - .deliverTo(LocalDateTime.of(2023, 2, 8, 16, 30)) - .user(User.builder().id(1L).recipientName("Admin").recipientSurname("Ubs").build()) - .build(); + .id(1L) + .dateOfExport(LocalDate.of(2023, 2, 8)) + .deliverFrom(LocalDateTime.of(2023, 2, 8, 15, 0)) + .deliverTo(LocalDateTime.of(2023, 2, 8, 16, 30)) + .user(User.builder().id(1L).recipientName("Admin").recipientSurname("Ubs").build()) + .build(); } public static Order getOrderExportDetailsWithDeliverFromTo() { @@ -4800,54 +4835,54 @@ public static Order getOrderExportDetailsWithDeliverFromTo() { public static UserProfileCreateDto getUserProfileCreateDto() { return UserProfileCreateDto.builder() - .name("UbsProfile") - .email("ubsuser@mail.com") - .uuid("f81d4fae-7dec-11d0-a765-00a0c91e6bf6") - .build(); + .name("UbsProfile") + .email("ubsuser@mail.com") + .uuid("f81d4fae-7dec-11d0-a765-00a0c91e6bf6") + .build(); } public static Order getTestNotTakenOrderReason() { return Order.builder() - .id(1L) - .orderStatus(OrderStatus.NOT_TAKEN_OUT) - .reasonNotTakingBagDescription("Some description") - .imageReasonNotTakingBags(List.of("image1", "image2")) - .build(); + .id(1L) + .orderStatus(OrderStatus.NOT_TAKEN_OUT) + .reasonNotTakingBagDescription("Some description") + .imageReasonNotTakingBags(List.of("image1", "image2")) + .build(); } public static NotTakenOrderReasonDto getNotTakenOrderReasonDto() { return NotTakenOrderReasonDto.builder() - .description("Some description") - .images(List.of("image1", "image2")) - .build(); + .description("Some description") + .images(List.of("image1", "image2")) + .build(); } public static TableColumnWidthForEmployee getTestTableColumnWidth() { return TableColumnWidthForEmployee.builder() - .employee(getEmployee()) - .address(50) - .amountDue(60) - .bagsAmount(150) - .city(200) - .build(); + .employee(getEmployee()) + .address(50) + .amountDue(60) + .bagsAmount(150) + .city(200) + .build(); } public static ColumnWidthDto getTestColumnWidthDto() { return ColumnWidthDto.builder() - .address(100) - .amountDue(20) - .bagsAmount(500) - .city(320) - .clientPhone(340) - .commentForOrderByClient(600) - .build(); + .address(100) + .amountDue(20) + .bagsAmount(500) + .city(320) + .clientPhone(340) + .commentForOrderByClient(600) + .build(); } public static PositionAuthoritiesDto getPositionAuthoritiesDto() { return PositionAuthoritiesDto.builder() - .positionId(List.of(1L)) - .authorities(List.of("Auth")) - .build(); + .positionId(List.of(1L)) + .authorities(List.of("Auth")) + .build(); } public static PositionWithTranslateDto getPositionWithTranslateDto(Long id) { @@ -4856,12 +4891,12 @@ public static PositionWithTranslateDto getPositionWithTranslateDto(Long id) { nameTranslations.put("en", "Driver"); return PositionWithTranslateDto.builder() - .id(id) - .name(nameTranslations) - .build(); + .id(id) + .name(nameTranslations) + .build(); } public static Refund getRefund(Long id) { return Refund.builder().orderId(id).build(); } -} +} \ No newline at end of file diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index 49327a86e..dbe859bb1 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -23,6 +23,7 @@ import greencity.dto.tariff.SetTariffLimitsDto; import greencity.entity.order.Bag; import greencity.entity.order.Courier; +import greencity.entity.order.Order; import greencity.entity.order.Service; import greencity.entity.order.TariffLocation; import greencity.entity.order.TariffsInfo; @@ -47,6 +48,8 @@ import greencity.repository.DeactivateChosenEntityRepository; import greencity.repository.EmployeeRepository; import greencity.repository.LocationRepository; +import greencity.repository.OrderBagRepository; +import greencity.repository.OrderRepository; import greencity.repository.ReceivingStationRepository; import greencity.repository.RegionRepository; import greencity.repository.ServiceRepository; @@ -71,17 +74,10 @@ import java.util.Optional; import java.util.Set; import java.util.UUID; +import java.util.Arrays; import java.util.stream.Stream; -import static greencity.ModelUtils.TEST_USER; -import static greencity.ModelUtils.getAllTariffsInfoDto; -import static greencity.ModelUtils.getCourier; -import static greencity.ModelUtils.getCourierDto; -import static greencity.ModelUtils.getCourierDtoList; -import static greencity.ModelUtils.getDeactivatedCourier; -import static greencity.ModelUtils.getEmployee; -import static greencity.ModelUtils.getReceivingStation; -import static greencity.ModelUtils.getReceivingStationDto; +import static greencity.ModelUtils.*; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; @@ -131,22 +127,29 @@ class SuperAdminServiceImplTest { private TariffLocationRepository tariffsLocationRepository; @Mock private DeactivateChosenEntityRepository deactivateTariffsForChosenParamRepository; + @Mock + private OrderBagRepository orderBagRepository; + @Mock + private OrderRepository orderRepository; + @Mock + private OrderBagService orderBagService; @AfterEach void afterEach() { verifyNoMoreInteractions( - userRepository, - employeeRepository, - bagRepository, - locationRepository, - modelMapper, - serviceRepository, - courierRepository, - regionRepository, - receivingStationRepository, - tariffsInfoRepository, - tariffsLocationRepository, - deactivateTariffsForChosenParamRepository); + userRepository, + employeeRepository, + bagRepository, + locationRepository, + modelMapper, + serviceRepository, + courierRepository, + regionRepository, + receivingStationRepository, + tariffsInfoRepository, + tariffsLocationRepository, + deactivateTariffsForChosenParamRepository, + orderBagRepository); } @Test @@ -182,7 +185,7 @@ void addTariffServiceIfEmployeeNotFoundExceptionTest() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.addTariffService(1L, dto, uuid)); + () -> superAdminService.addTariffService(1L, dto, uuid)); verify(tariffsInfoRepository).findById(1L); verify(employeeRepository).findByUuid(uuid); @@ -197,7 +200,7 @@ void addTariffServiceIfTariffNotFoundExceptionTest() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.addTariffService(1L, dto, uuid)); + () -> superAdminService.addTariffService(1L, dto, uuid)); verify(tariffsInfoRepository).findById(1L); verify(bagRepository, never()).save(any(Bag.class)); @@ -205,7 +208,7 @@ void addTariffServiceIfTariffNotFoundExceptionTest() { @Test void getTariffServiceTest() { - List bags = List.of(ModelUtils.getOptionalBag().get()); + List bags = List.of(ModelUtils.getNewBag()); GetTariffServiceDto dto = ModelUtils.getGetTariffServiceDto(); when(tariffsInfoRepository.existsById(1L)).thenReturn(true); @@ -219,12 +222,26 @@ void getTariffServiceTest() { verify(modelMapper).map(bags.get(0), GetTariffServiceDto.class); } + @Test + void getTariffServiceIfThereAreNoBags() { + List bags = Collections.emptyList(); + + when(tariffsInfoRepository.existsById(1L)).thenReturn(true); + when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(bags); + + List dtos = superAdminService.getTariffService(1); + + assertEquals(Collections.emptyList(), dtos); + verify(tariffsInfoRepository).existsById(1L); + verify(bagRepository).findBagsByTariffsInfoId(1L); + } + @Test void getTariffServiceIfTariffNotFoundException() { when(tariffsInfoRepository.existsById(1L)).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.getTariffService(1)); + () -> superAdminService.getTariffService(1)); verify(tariffsInfoRepository).existsById(1L); verify(bagRepository, never()).findBagsByTariffsInfoId(1L); @@ -233,36 +250,61 @@ void getTariffServiceIfTariffNotFoundException() { @Test void deleteTariffServiceWhenTariffBagsWithLimits() { Bag bag = ModelUtils.getBag(); + Bag bagDeleted = ModelUtils.getBagDeleted(); TariffsInfo tariffsInfo = ModelUtils.getTariffInfo(); - bag.setTariffsInfo(tariffsInfo); + Order order = ModelUtils.getOrder(); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); + tariffsInfo.setTariffStatus(TariffStatus.DEACTIVATED); when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); - doNothing().when(bagRepository).delete(bag); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(List.of(bag)); + when(orderRepository.findAllByBagId(bag.getId())).thenReturn(Arrays.asList(order)); + superAdminService.deleteTariffService(1); - assertEquals(TariffStatus.ACTIVE, tariffsInfo.getTariffStatus()); + verify(bagRepository).findById(1); - verify(bagRepository).delete(bag); verify(bagRepository).findBagsByTariffsInfoId(1L); verify(tariffsInfoRepository, never()).save(tariffsInfo); } +// @Test +// void deleteTariffServiceWhenTariffBagsWithLimits_UnPaidOrder() { +// Bag bag = ModelUtils.getBag(); +// Bag bagDeleted = ModelUtils.getBagDeleted(); +// TariffsInfo tariffsInfo = ModelUtils.getTariffInfo(); +// Order order = ModelUtils.getOrder(); +// order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag(), ModelUtils.getOrderBag2())); +// order.setTariffsInfo(tariffsInfo); +// tariffsInfo.setBags(Arrays.asList(bag)); +// bag.setTariffsInfo(tariffsInfo); +// tariffsInfo.setTariffStatus(TariffStatus.DEACTIVATED); +// when(orderRepository.findById(order.getId())).thenReturn(Optional.of(order)); +// when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); +// when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(List.of(bag)); +// when(orderRepository.findAllByBagId(bag.getId())).thenReturn(Arrays.asList(order)); +// when(bagRepository.save(bag)).thenReturn(bagDeleted); +//doNothing().when(orderBagService.removeBagFromOrder()); +// superAdminService.deleteTariffService(1); +// +// verify(bagRepository).findById(1); +// verify(bagRepository).findBagsByTariffsInfoId(1L); +// verify(tariffsInfoRepository, never()).save(tariffsInfo); +// } + @Test void deleteTariffServiceWhenTariffBagsListIsEmpty() { Bag bag = ModelUtils.getBag(); - TariffsInfo tariffsInfo = ModelUtils.getTariffInfo(); + TariffsInfo tariffsInfo = ModelUtils.getTariffsInfoWithStatusNew(); + tariffsInfo.setBags(Arrays.asList(bag)); bag.setTariffsInfo(tariffsInfo); - TariffsInfo tariffsInfoNew = ModelUtils.getTariffsInfoWithStatusNew(); - tariffsInfoNew.setBags(Collections.emptyList()); - + tariffsInfo.setTariffStatus(TariffStatus.DEACTIVATED); when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); - doNothing().when(bagRepository).delete(bag); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(Collections.emptyList()); when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfo); + superAdminService.deleteTariffService(1); - assertEquals(TariffStatus.NEW, tariffsInfoNew.getTariffStatus()); + verify(bagRepository).findById(1); - verify(bagRepository).delete(bag); verify(bagRepository).findBagsByTariffsInfoId(1L); verify(tariffsInfoRepository).save(tariffsInfo); } @@ -270,74 +312,166 @@ void deleteTariffServiceWhenTariffBagsListIsEmpty() { @Test void deleteTariffServiceWhenTariffBagsWithoutLimits() { Bag bag = ModelUtils.getBag(); - TariffsInfo tariffsInfo = ModelUtils.getTariffInfo(); bag.setLimitIncluded(false); - bag.setTariffsInfo(tariffsInfo); + Bag bagDeleted = ModelUtils.getBagDeleted(); + bagDeleted.setLimitIncluded(false); TariffsInfo tariffsInfoNew = ModelUtils.getTariffsInfoWithStatusNew(); - tariffsInfoNew.setBags(Collections.emptyList()); + tariffsInfoNew.setBags(Arrays.asList(bag)); + bag.setTariffsInfo(tariffsInfoNew); + tariffsInfoNew.setTariffStatus(TariffStatus.DEACTIVATED); + tariffsInfoNew.setBags(Arrays.asList(bag)); + bag.setTariffsInfo(tariffsInfoNew); + tariffsInfoNew.setTariffStatus(TariffStatus.DEACTIVATED); when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); - doNothing().when(bagRepository).delete(bag); +// when(bagRepository.save(bag)).thenReturn(bagDeleted); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(List.of(bag)); - when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfoNew); + when(tariffsInfoRepository.save(tariffsInfoNew)).thenReturn(tariffsInfoNew); + superAdminService.deleteTariffService(1); - assertEquals(TariffStatus.NEW, tariffsInfoNew.getTariffStatus()); + verify(bagRepository).findById(1); - verify(bagRepository).delete(bag); +// verify(bagRepository).save(bag); verify(bagRepository).findBagsByTariffsInfoId(1L); verify(tariffsInfoRepository).save(tariffsInfoNew); } @Test - void deleteTariffServiceThrowNotFoundException() { + void deleteTariffServiceThrowBagNotFoundException() { when(bagRepository.findById(1)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.deleteTariffService(1)); + () -> superAdminService.deleteTariffService(1)); verify(bagRepository).findById(1); - verify(bagRepository, never()).delete(any(Bag.class)); + verify(bagRepository, never()).save(any(Bag.class)); } @Test - void editTariffService() { + void editTariffServiceWithUnpaidOrder() { Bag bag = ModelUtils.getBag(); + Bag editedBag = ModelUtils.getEditedBag(); Employee employee = ModelUtils.getEmployee(); TariffServiceDto dto = ModelUtils.getTariffServiceDto(); GetTariffServiceDto editedDto = ModelUtils.getGetTariffServiceDto(); + Order order = ModelUtils.getOrder(); String uuid = UUID.randomUUID().toString(); + order.setOrderBags(List.of(ModelUtils.getOrderBag())); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); - when(bagRepository.save(bag)).thenReturn(bag); - when(modelMapper.map(bag, GetTariffServiceDto.class)).thenReturn(editedDto); + when(bagRepository.save(editedBag)).thenReturn(editedBag); + when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); + doNothing().when(orderBagRepository) + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + when(orderRepository.findAllUnpaidOrdersByBagId(1)).thenReturn(List.of(order)); + when(orderRepository.saveAll(List.of(order))).thenReturn(List.of(order)); - superAdminService.editTariffService(dto, 1, uuid); + GetTariffServiceDto actual = superAdminService.editTariffService(dto, 1, uuid); + assertEquals(editedDto, actual); verify(employeeRepository).findByUuid(uuid); verify(bagRepository).findById(1); - verify(bagRepository).save(bag); - verify(modelMapper).map(bag, GetTariffServiceDto.class); + verify(bagRepository).save(editedBag); + verify(modelMapper).map(editedBag, GetTariffServiceDto.class); + verify(orderBagRepository) + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + verify(orderRepository).findAllUnpaidOrdersByBagId(1); + verify(orderRepository).saveAll(anyList()); } @Test - void editTariffServiceIfCommissionIsNull() { + void editTariffServiceWithUnpaidOrderAndBagConfirmedAmount() { Bag bag = ModelUtils.getBag(); + Bag editedBag = ModelUtils.getEditedBag(); Employee employee = ModelUtils.getEmployee(); TariffServiceDto dto = ModelUtils.getTariffServiceDto(); - dto.setCommission(null); GetTariffServiceDto editedDto = ModelUtils.getGetTariffServiceDto(); + Order order = ModelUtils.getOrder(); String uuid = UUID.randomUUID().toString(); + order.setOrderBags(List.of(ModelUtils.getOrderBagWithConfirmedAmount())); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); - when(bagRepository.save(bag)).thenReturn(bag); - when(modelMapper.map(bag, GetTariffServiceDto.class)).thenReturn(editedDto); + when(bagRepository.save(editedBag)).thenReturn(editedBag); + when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); + doNothing().when(orderBagRepository) + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + when(orderRepository.findAllUnpaidOrdersByBagId(1)).thenReturn(List.of(order)); + when(orderRepository.saveAll(List.of(order))).thenReturn(List.of(order)); - superAdminService.editTariffService(dto, 1, uuid); + GetTariffServiceDto actual = superAdminService.editTariffService(dto, 1, uuid); + assertEquals(editedDto, actual); verify(employeeRepository).findByUuid(uuid); verify(bagRepository).findById(1); - verify(bagRepository).save(bag); - verify(modelMapper).map(bag, GetTariffServiceDto.class); + verify(bagRepository).save(editedBag); + verify(modelMapper).map(editedBag, GetTariffServiceDto.class); + verify(orderBagRepository) + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + verify(orderRepository).findAllUnpaidOrdersByBagId(1); + verify(orderRepository).saveAll(anyList()); + } + + @Test + void editTariffServiceWithUnpaidOrderAndBagExportedAmount() { + Bag bag = ModelUtils.getBag(); + Bag editedBag = ModelUtils.getEditedBag(); + Employee employee = ModelUtils.getEmployee(); + TariffServiceDto dto = ModelUtils.getTariffServiceDto(); + GetTariffServiceDto editedDto = ModelUtils.getGetTariffServiceDto(); + Order order = ModelUtils.getOrder(); + String uuid = UUID.randomUUID().toString(); + order.setOrderBags(List.of(ModelUtils.getOrderBagWithExportedAmount())); + + when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); + when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.save(editedBag)).thenReturn(editedBag); + when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); + doNothing().when(orderBagRepository) + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + when(orderRepository.findAllUnpaidOrdersByBagId(1)).thenReturn(List.of(order)); + when(orderRepository.saveAll(List.of(order))).thenReturn(List.of(order)); + + GetTariffServiceDto actual = superAdminService.editTariffService(dto, 1, uuid); + + assertEquals(editedDto, actual); + verify(employeeRepository).findByUuid(uuid); + verify(bagRepository).findById(1); + verify(bagRepository).save(editedBag); + verify(modelMapper).map(editedBag, GetTariffServiceDto.class); + verify(orderBagRepository) + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + verify(orderRepository).findAllUnpaidOrdersByBagId(1); + verify(orderRepository).saveAll(anyList()); + } + + @Test + void editTariffServiceWithoutUnpaidOrder() { + Bag bag = ModelUtils.getBag(); + Bag editedBag = ModelUtils.getEditedBag(); + Employee employee = ModelUtils.getEmployee(); + TariffServiceDto dto = ModelUtils.getTariffServiceDto(); + GetTariffServiceDto editedDto = ModelUtils.getGetTariffServiceDto(); + String uuid = UUID.randomUUID().toString(); + + when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); + when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.save(editedBag)).thenReturn(editedBag); + when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); + doNothing().when(orderBagRepository) + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + when(orderRepository.findAllUnpaidOrdersByBagId(1)).thenReturn(Collections.emptyList()); + + GetTariffServiceDto actual = superAdminService.editTariffService(dto, 1, uuid); + + assertEquals(editedDto, actual); + verify(employeeRepository).findByUuid(uuid); + verify(bagRepository).findById(1); + verify(bagRepository).save(editedBag); + verify(modelMapper).map(editedBag, GetTariffServiceDto.class); + verify(orderBagRepository) + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + verify(orderRepository).findAllUnpaidOrdersByBagId(1); + verify(orderRepository, never()).saveAll(anyList()); } @Test @@ -349,7 +483,7 @@ void editTariffServiceIfEmployeeNotFoundException() { when(bagRepository.findById(1)).thenReturn(bag); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariffService(dto, 1, uuid)); + () -> superAdminService.editTariffService(dto, 1, uuid)); verify(bagRepository).findById(1); verify(bagRepository, never()).save(any(Bag.class)); @@ -362,7 +496,7 @@ void editTariffServiceIfBagNotFoundException() { when(bagRepository.findById(1)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariffService(dto, 1, uuid)); + () -> superAdminService.editTariffService(dto, 1, uuid)); verify(bagRepository).findById(1); verify(bagRepository, never()).save(any(Bag.class)); @@ -372,7 +506,7 @@ void editTariffServiceIfBagNotFoundException() { void getAllCouriersTest() { when(courierRepository.findAll()).thenReturn(List.of(getCourier())); when(modelMapper.map(getCourier(), CourierDto.class)) - .thenReturn(getCourierDto()); + .thenReturn(getCourierDto()); assertEquals(getCourierDtoList(), superAdminService.getAllCouriers()); @@ -399,7 +533,7 @@ void deleteServiceThrowNotFoundException() { when(serviceRepository.findById(service.getId())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.deleteService(1L)); + () -> superAdminService.deleteService(1L)); verify(serviceRepository).findById(1L); verify(serviceRepository, never()).delete(service); @@ -409,38 +543,40 @@ void deleteServiceThrowNotFoundException() { void getService() { Service service = ModelUtils.getService(); GetServiceDto getServiceDto = ModelUtils.getGetServiceDto(); + TariffsInfo tariffsInfo = ModelUtils.getTariffsInfo(); - when(tariffsInfoRepository.existsById(1L)).thenReturn(true); + when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(service)); when(modelMapper.map(service, GetServiceDto.class)).thenReturn(getServiceDto); assertEquals(getServiceDto, superAdminService.getService(1L)); - verify(tariffsInfoRepository).existsById(1L); + verify(tariffsInfoRepository).findById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); verify(modelMapper).map(service, GetServiceDto.class); } @Test void getServiceIfServiceNotExists() { - when(tariffsInfoRepository.existsById(1L)).thenReturn(true); + TariffsInfo tariffsInfo = ModelUtils.getTariffsInfo(); + + when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); assertNull(superAdminService.getService(1L)); - verify(tariffsInfoRepository).existsById(1L); + verify(tariffsInfoRepository).findById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); - verify(modelMapper, never()).map(any(Service.class), any(GetServiceDto.class)); } @Test void getServiceThrowTariffNotFoundException() { - when(tariffsInfoRepository.existsById(1L)).thenReturn(false); + when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.getService(1L)); + () -> superAdminService.getService(1L)); - verify(tariffsInfoRepository).existsById(1L); + verify(tariffsInfoRepository).findById(1L); } @Test @@ -472,7 +608,7 @@ void editServiceServiceNotFoundException() { when(serviceRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editService(1L, dto, uuid)); + () -> superAdminService.editService(1L, dto, uuid)); verify(serviceRepository).findById(1L); verify(serviceRepository, never()).save(any(Service.class)); @@ -489,7 +625,7 @@ void editServiceEmployeeNotFoundException() { when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editService(1L, dto, uuid)); + () -> superAdminService.editService(1L, dto, uuid)); verify(employeeRepository).findByUuid(uuid); verify(serviceRepository).findById(1L); @@ -507,7 +643,6 @@ void addService() { TariffsInfo tariffsInfo = ModelUtils.getTariffsInfo(); String uuid = UUID.randomUUID().toString(); - when(tariffsInfoRepository.existsById(1L)).thenReturn(true); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); @@ -518,7 +653,6 @@ void addService() { assertEquals(getServiceDto, superAdminService.addService(1L, serviceDto, uuid)); verify(employeeRepository).findByUuid(uuid); - verify(tariffsInfoRepository).existsById(1L); verify(tariffsInfoRepository).findById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); verify(serviceRepository).save(service); @@ -530,31 +664,33 @@ void addService() { void addServiceThrowServiceAlreadyExistsException() { Service createdService = ModelUtils.getService(); ServiceDto serviceDto = ModelUtils.getServiceDto(); + TariffsInfo tariffsInfo = ModelUtils.getTariffsInfo(); String uuid = UUID.randomUUID().toString(); - when(tariffsInfoRepository.existsById(1L)).thenReturn(true); + when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(createdService)); assertThrows(ServiceAlreadyExistsException.class, - () -> superAdminService.addService(1L, serviceDto, uuid)); + () -> superAdminService.addService(1L, serviceDto, uuid)); - verify(tariffsInfoRepository).existsById(1L); + verify(tariffsInfoRepository).findById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); } @Test void addServiceThrowEmployeeNotFoundException() { ServiceDto serviceDto = ModelUtils.getServiceDto(); + TariffsInfo tariffsInfo = ModelUtils.getTariffsInfo(); String uuid = UUID.randomUUID().toString(); - when(tariffsInfoRepository.existsById(1L)).thenReturn(true); + when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.addService(1L, serviceDto, uuid)); + () -> superAdminService.addService(1L, serviceDto, uuid)); - verify(tariffsInfoRepository).existsById(1L); + verify(tariffsInfoRepository).findById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); verify(employeeRepository).findByUuid(uuid); } @@ -564,12 +700,12 @@ void addServiceThrowTariffNotFoundException() { ServiceDto serviceDto = ModelUtils.getServiceDto(); String uuid = UUID.randomUUID().toString(); - when(tariffsInfoRepository.existsById(1L)).thenReturn(false); + when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.addService(1L, serviceDto, uuid)); + () -> superAdminService.addService(1L, serviceDto, uuid)); - verify(tariffsInfoRepository).existsById(1L); + verify(tariffsInfoRepository).findById(1L); } @Test @@ -589,7 +725,7 @@ void getLocationsByStatusTest() { List regionList = ModelUtils.getAllRegion(); when(regionRepository.findAllByLocationsLocationStatus(LocationStatus.ACTIVE)) - .thenReturn(Optional.of(regionList)); + .thenReturn(Optional.of(regionList)); var result = superAdminService.getLocationsByStatus(LocationStatus.ACTIVE); @@ -602,13 +738,13 @@ void getLocationsByStatusTest() { @Test void getLocationsByStatusNotFoundExceptionTest() { when(regionRepository.findAllByLocationsLocationStatus(LocationStatus.ACTIVE)) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); NotFoundException notFoundException = assertThrows(NotFoundException.class, - () -> superAdminService.getLocationsByStatus(LocationStatus.ACTIVE)); + () -> superAdminService.getLocationsByStatus(LocationStatus.ACTIVE)); assertEquals(String.format(ErrorMessage.REGIONS_NOT_FOUND_BY_LOCATION_STATUS, LocationStatus.ACTIVE.name()), - notFoundException.getMessage()); + notFoundException.getMessage()); verify(regionRepository).findAllByLocationsLocationStatus(LocationStatus.ACTIVE); } @@ -619,7 +755,7 @@ void addLocationTest() { Region region = ModelUtils.getRegion(); when(regionRepository.findRegionByEnNameAndUkrName("Kyiv region", "Київська область")) - .thenReturn(Optional.of(region)); + .thenReturn(Optional.of(region)); superAdminService.addLocation(locationCreateDtoList); @@ -633,7 +769,7 @@ void addLocationCreateNewRegionTest() { List locationCreateDtoList = ModelUtils.getLocationCreateDtoList(); Location location = ModelUtils.getLocationForCreateRegion(); when(regionRepository.findRegionByEnNameAndUkrName("Kyiv region", "Київська область")) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); when(regionRepository.save(any())).thenReturn(ModelUtils.getRegion()); superAdminService.addLocation(locationCreateDtoList); verify(locationRepository).findLocationByNameAndRegionId("Київ", "Kyiv", 1L); @@ -645,7 +781,7 @@ void addLocationCreateNewRegionTest() { void deleteLocationTest() { Location location = ModelUtils.getLocationDto(); location - .setTariffLocations(Set.of(TariffLocation.builder().location(Location.builder().id(2L).build()).build())); + .setTariffLocations(Set.of(TariffLocation.builder().location(Location.builder().id(2L).build()).build())); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); superAdminService.deleteLocation(1L); verify(locationRepository).findById(1L); @@ -656,7 +792,7 @@ void deleteLocationTest() { void deleteLocationThrowsBadRequestExceptionTest() { Location location = ModelUtils.getLocationDto(); location - .setTariffLocations(Set.of(TariffLocation.builder().location(Location.builder().id(1L).build()).build())); + .setTariffLocations(Set.of(TariffLocation.builder().location(Location.builder().id(1L).build()).build())); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); assertThrows(BadRequestException.class, () -> superAdminService.deleteLocation(1L)); verify(locationRepository).findById(1L); @@ -679,7 +815,7 @@ void addLocationThrowLocationAlreadyCreatedExceptionTest() { List locationCreateDtoList = ModelUtils.getLocationCreateDtoList(); Location location = ModelUtils.getLocation(); when(regionRepository.findRegionByEnNameAndUkrName("Kyiv region", "Київська область")) - .thenReturn(Optional.of(ModelUtils.getRegion())); + .thenReturn(Optional.of(ModelUtils.getRegion())); when(locationRepository.findLocationByNameAndRegionId("Київ", "Kyiv", 1L)).thenReturn(Optional.of(location)); assertThrows(NotFoundException.class, () -> superAdminService.addLocation(locationCreateDtoList)); @@ -722,17 +858,17 @@ void deactivateCourierThrowBadRequestException() { when(courierRepository.findById(anyLong())).thenReturn(Optional.of(courier)); courier.setCourierStatus(CourierStatus.DEACTIVATED); assertThrows(BadRequestException.class, - () -> superAdminService.deactivateCourier(1L)); + () -> superAdminService.deactivateCourier(1L)); verify(courierRepository).findById(1L); } @Test void deactivateCourierThrowNotFoundException() { when(courierRepository.findById(anyLong())) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); Exception thrownNotFoundEx = assertThrows(NotFoundException.class, - () -> superAdminService.deactivateCourier(1L)); + () -> superAdminService.deactivateCourier(1L)); assertEquals(ErrorMessage.COURIER_IS_NOT_FOUND_BY_ID + 1L, thrownNotFoundEx.getMessage()); verify(courierRepository).findById(1L); @@ -746,14 +882,14 @@ void createCourier() { when(employeeRepository.findByUuid(anyString())).thenReturn(Optional.ofNullable(getEmployee())); when(courierRepository.findAll()).thenReturn(List.of(Courier.builder() - .nameEn("Test1") - .nameUk("Тест1") - .build())); + .nameEn("Test1") + .nameUk("Тест1") + .build())); when(courierRepository.save(any())).thenReturn(courier); when(modelMapper.map(any(), eq(CreateCourierDto.class))).thenReturn(createCourierDto); assertEquals(createCourierDto, - superAdminService.createCourier(createCourierDto, ModelUtils.TEST_USER.getUuid())); + superAdminService.createCourier(createCourierDto, ModelUtils.TEST_USER.getUuid())); verify(courierRepository).save(any()); verify(modelMapper).map(any(), eq(CreateCourierDto.class)); @@ -770,7 +906,7 @@ void createCourierAlreadyExists() { when(courierRepository.findAll()).thenReturn(List.of(getCourier(), getCourier())); Throwable throwable = assertThrows(CourierAlreadyExists.class, - () -> superAdminService.createCourier(createCourierDto, uuid)); + () -> superAdminService.createCourier(createCourierDto, uuid)); assertEquals(ErrorMessage.COURIER_ALREADY_EXISTS, throwable.getMessage()); verify(employeeRepository).findByUuid(anyString()); verify(courierRepository).findAll(); @@ -781,24 +917,24 @@ void updateCourierTest() { Courier courier = getCourier(); CourierUpdateDto dto = CourierUpdateDto.builder() - .courierId(1L) - .nameUk("УБС") - .nameEn("UBS") - .build(); + .courierId(1L) + .nameUk("УБС") + .nameEn("UBS") + .build(); Courier courierToSave = Courier.builder() - .id(courier.getId()) - .courierStatus(courier.getCourierStatus()) - .nameUk("УБС") - .nameEn("UBS") - .build(); + .id(courier.getId()) + .courierStatus(courier.getCourierStatus()) + .nameUk("УБС") + .nameEn("UBS") + .build(); CourierDto courierDto = CourierDto.builder() - .courierId(courier.getId()) - .courierStatus("Active") - .nameUk("УБС") - .nameEn("UBS") - .build(); + .courierId(courier.getId()) + .courierStatus("Active") + .nameUk("УБС") + .nameEn("UBS") + .build(); when(courierRepository.findById(dto.getCourierId())).thenReturn(Optional.of(courier)); when(courierRepository.save(courier)).thenReturn(courierToSave); @@ -806,11 +942,11 @@ void updateCourierTest() { CourierDto actual = superAdminService.updateCourier(dto); CourierDto expected = CourierDto.builder() - .courierId(getCourier().getId()) - .courierStatus("Active") - .nameUk("УБС") - .nameEn("UBS") - .build(); + .courierId(getCourier().getId()) + .courierStatus("Active") + .nameUk("УБС") + .nameEn("UBS") + .build(); assertEquals(expected, actual); } @@ -820,20 +956,20 @@ void updateCourierNotFound() { Courier courier = getCourier(); CourierUpdateDto dto = CourierUpdateDto.builder() - .courierId(1L) - .nameUk("УБС") - .nameEn("UBS") - .build(); + .courierId(1L) + .nameUk("УБС") + .nameEn("UBS") + .build(); when(courierRepository.findById(courier.getId())) - .thenThrow(new NotFoundException(ErrorMessage.COURIER_IS_NOT_FOUND_BY_ID)); + .thenThrow(new NotFoundException(ErrorMessage.COURIER_IS_NOT_FOUND_BY_ID)); assertThrows(NotFoundException.class, () -> superAdminService.updateCourier(dto)); } @Test void getAllTariffsInfoTest() { when(tariffsInfoRepository.findAll(any(TariffsInfoSpecification.class))) - .thenReturn(List.of(ModelUtils.getTariffsInfo())); + .thenReturn(List.of(ModelUtils.getTariffsInfo())); when(modelMapper.map(any(TariffsInfo.class), eq(GetTariffsInfoDto.class))).thenReturn(getAllTariffsInfoDto()); superAdminService.getAllTariffsInfo(TariffsInfoFilterCriteria.builder().build()); @@ -847,7 +983,7 @@ void CreateReceivingStation() { AddingReceivingStationDto stationDto = AddingReceivingStationDto.builder().name("Петрівка").build(); when(receivingStationRepository.existsReceivingStationByName(any())).thenReturn(false, true); lenient().when(modelMapper.map(any(ReceivingStation.class), eq(ReceivingStationDto.class))) - .thenReturn(getReceivingStationDto()); + .thenReturn(getReceivingStationDto()); when(receivingStationRepository.save(any())).thenReturn(getReceivingStation(), getReceivingStation()); when(employeeRepository.findByUuid(test)).thenReturn(Optional.ofNullable(getEmployee())); superAdminService.createReceivingStation(stationDto, test); @@ -855,12 +991,12 @@ void CreateReceivingStation() { verify(receivingStationRepository, times(1)).existsReceivingStationByName(any()); verify(receivingStationRepository, times(1)).save(any()); verify(modelMapper, times(1)) - .map(any(ReceivingStation.class), eq(ReceivingStationDto.class)); + .map(any(ReceivingStation.class), eq(ReceivingStationDto.class)); Exception thrown = assertThrows(UnprocessableEntityException.class, - () -> superAdminService.createReceivingStation(stationDto, test)); + () -> superAdminService.createReceivingStation(stationDto, test)); assertEquals(thrown.getMessage(), ErrorMessage.RECEIVING_STATION_ALREADY_EXISTS - + stationDto.getName()); + + stationDto.getName()); verify(employeeRepository).findByUuid(any()); } @@ -869,13 +1005,13 @@ void createReceivingStationSaveCorrectValue() { String receivingStationName = "Петрівка"; Employee employee = getEmployee(); AddingReceivingStationDto addingReceivingStationDto = - AddingReceivingStationDto.builder().name(receivingStationName).build(); + AddingReceivingStationDto.builder().name(receivingStationName).build(); ReceivingStation activatedReceivingStation = ReceivingStation.builder() - .name(receivingStationName) - .createdBy(employee) - .createDate(LocalDate.now()) - .stationStatus(StationStatus.ACTIVE) - .build(); + .name(receivingStationName) + .createdBy(employee) + .createDate(LocalDate.now()) + .stationStatus(StationStatus.ACTIVE) + .build(); ReceivingStationDto receivingStationDto = getReceivingStationDto(); @@ -883,7 +1019,7 @@ void createReceivingStationSaveCorrectValue() { when(receivingStationRepository.existsReceivingStationByName(any())).thenReturn(false); when(receivingStationRepository.save(any())).thenReturn(activatedReceivingStation); when(modelMapper.map(any(), eq(ReceivingStationDto.class))) - .thenReturn(receivingStationDto); + .thenReturn(receivingStationDto); superAdminService.createReceivingStation(addingReceivingStationDto, employee.getUuid()); @@ -891,7 +1027,7 @@ void createReceivingStationSaveCorrectValue() { verify(receivingStationRepository).existsReceivingStationByName(any()); verify(receivingStationRepository).save(activatedReceivingStation); verify(modelMapper) - .map(any(ReceivingStation.class), eq(ReceivingStationDto.class)); + .map(any(ReceivingStation.class), eq(ReceivingStationDto.class)); } @@ -943,7 +1079,7 @@ void deleteReceivingStation() { when(receivingStationRepository.findById(2L)).thenReturn(Optional.empty()); Exception thrown1 = assertThrows(NotFoundException.class, - () -> superAdminService.deleteReceivingStation(2L)); + () -> superAdminService.deleteReceivingStation(2L)); assertEquals(ErrorMessage.RECEIVING_STATION_NOT_FOUND_BY_ID + 2L, thrown1.getMessage()); } @@ -952,12 +1088,12 @@ void deleteReceivingStation() { void editNewTariffSuccess() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); when(locationRepository.findAllByIdAndRegionId(dto.getLocationIdList(), dto.getRegionId())) - .thenReturn(ModelUtils.getLocationList()); + .thenReturn(ModelUtils.getLocationList()); when(employeeRepository.findByUuid(any())).thenReturn(Optional.ofNullable(getEmployee())); when(receivingStationRepository.findAllById(List.of(1L))).thenReturn(ModelUtils.getReceivingList()); when(courierRepository.findById(anyLong())).thenReturn(Optional.of(ModelUtils.getCourier())); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(Collections.emptyList()); + .thenReturn(Collections.emptyList()); when(tariffsInfoRepository.save(any())).thenReturn(ModelUtils.getTariffInfo()); when(employeeRepository.findAllByEmployeePositionId(6L)).thenReturn(ModelUtils.getEmployeeList()); when(tariffsLocationRepository.saveAll(anySet())).thenReturn(anyList()); @@ -977,13 +1113,13 @@ void addNewTariffThrowsExceptionWhenListOfLocationsIsEmptyTest() { when(employeeRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(Optional.ofNullable(getEmployee())); when(tariffsInfoRepository.save(any())).thenReturn(ModelUtils.getTariffInfo()); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(Collections.emptyList()); + .thenReturn(Collections.emptyList()); when(receivingStationRepository.findAllById(List.of(1L))).thenReturn(ModelUtils.getReceivingList()); when(locationRepository.findAllByIdAndRegionId(dto.getLocationIdList(), - dto.getRegionId())).thenReturn(Collections.emptyList()); + dto.getRegionId())).thenReturn(Collections.emptyList()); assertThrows(NotFoundException.class, - () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); + () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); verify(courierRepository).findById(1L); verify(employeeRepository).findByUuid("35467585763t4sfgchjfuyetf"); @@ -998,20 +1134,20 @@ void addNewTariffThrowsExceptionWhenListOfLocationsIsEmptyTest() { void addNewTariffThrowsExceptionWhenSuchTariffIsAlreadyExistsTest() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); TariffLocation tariffLocation = TariffLocation - .builder() - .id(1L) - .location(ModelUtils.getLocation()) - .build(); + .builder() + .id(1L) + .location(ModelUtils.getLocation()) + .build(); when(courierRepository.findById(1L)).thenReturn(Optional.of(ModelUtils.getCourier())); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(dto.getCourierId(), - dto.getLocationIdList())).thenReturn(List.of(tariffLocation)); + dto.getLocationIdList())).thenReturn(List.of(tariffLocation)); assertThrows(TariffAlreadyExistsException.class, - () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); + () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); verify(courierRepository).findById(1L); verify(tariffsLocationRepository).findAllByCourierIdAndLocationIds(dto.getCourierId(), - dto.getLocationIdList()); + dto.getLocationIdList()); verifyNoMoreInteractions(courierRepository, tariffsLocationRepository); verify(employeeRepository, never()).findAllByEmployeePositionId(6L); } @@ -1027,12 +1163,12 @@ void addNewTariffThrowsExceptionWhenCourierHasStatusDeactivated() { // Perform the test assertThrows(BadRequestException.class, - () -> superAdminService.addNewTariff(addNewTariffDto, userUUID)); + () -> superAdminService.addNewTariff(addNewTariffDto, userUUID)); // Verify the interactions verify(courierRepository).findById(addNewTariffDto.getCourierId()); verifyNoMoreInteractions(courierRepository, tariffsLocationRepository, tariffsInfoRepository, - employeeRepository); + employeeRepository); } @Test @@ -1044,12 +1180,12 @@ void addNewTariffThrowsExceptionWhenListOfReceivingStationIsEmpty() { when(employeeRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(Optional.ofNullable(getEmployee())); when(tariffsInfoRepository.save(any())).thenReturn(ModelUtils.getTariffInfo()); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(Collections.emptyList()); + .thenReturn(Collections.emptyList()); when(locationRepository.findAllByIdAndRegionId(dto.getLocationIdList(), - dto.getRegionId())).thenReturn(Collections.emptyList()); + dto.getRegionId())).thenReturn(Collections.emptyList()); assertThrows(NotFoundException.class, - () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); + () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); verify(courierRepository).findById(1L); verify(employeeRepository).findByUuid("35467585763t4sfgchjfuyetf"); @@ -1064,7 +1200,7 @@ void addNewTariffThrowsException2() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); when(courierRepository.findById(anyLong())).thenReturn(Optional.of(ModelUtils.getCourier())); assertThrows(NotFoundException.class, - () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); + () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); verify(courierRepository).findById(anyLong()); verify(receivingStationRepository).findAllById(any()); verify(tariffsLocationRepository).findAllByCourierIdAndLocationIds(anyLong(), anyList()); @@ -1076,7 +1212,7 @@ void addNewTariffThrowsException3() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); when(courierRepository.findById(anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); + () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); verify(employeeRepository, never()).findAllByEmployeePositionId(6L); } @@ -1093,10 +1229,10 @@ void editTariffTest() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); when(tariffsLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) - .thenReturn(Optional.of(tariffLocation)); + .thenReturn(Optional.of(tariffLocation)); when(tariffsLocationRepository.findAllByTariffsInfo(tariffsInfo)).thenReturn(List.of(tariffLocation)); when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfo); @@ -1126,10 +1262,10 @@ void editTariffWithDeleteTariffLocation() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); when(tariffsLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) - .thenReturn(Optional.of(tariffLocation)); + .thenReturn(Optional.of(tariffLocation)); when(tariffsLocationRepository.findAllByTariffsInfo(tariffsInfo)).thenReturn(tariffLocations); doNothing().when(tariffsLocationRepository).delete(tariffLocations.get(1)); when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfo); @@ -1153,7 +1289,7 @@ void editTariffThrowTariffNotFoundException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1166,7 +1302,7 @@ void editTariffThrowLocationNotFoundException() { when(locationRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(locationRepository).findById(1L); @@ -1183,7 +1319,7 @@ void editTariffThrowLocationBadRequestException() { when(locationRepository.findById(2L)).thenReturn(Optional.of(locations.get(1))); assertThrows(BadRequestException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(locationRepository).findById(1L); @@ -1202,10 +1338,10 @@ void editTariffThrowTariffAlreadyExistsException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); assertThrows(TariffAlreadyExistsException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(locationRepository).findById(1L); @@ -1225,11 +1361,11 @@ void editTariffThrowReceivingStationNotFoundException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); when(receivingStationRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(locationRepository).findById(1L); @@ -1249,7 +1385,7 @@ void editTariffThrowsCourierNotFoundException() { when(courierRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(courierRepository).findById(1L); @@ -1267,11 +1403,11 @@ void editTariffWithoutCourier() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); when(receivingStationRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(locationRepository).findById(1L); @@ -1291,7 +1427,7 @@ void editTariffThrowsCourierHasStatusDeactivatedException() { when(courierRepository.findById(1L)).thenReturn(Optional.of(courier)); assertThrows(BadRequestException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(courierRepository).findById(1L); @@ -1311,10 +1447,10 @@ void editTariffWithBuildTariffLocation() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); when(tariffsLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); when(tariffsLocationRepository.findAllByTariffsInfo(tariffsInfo)).thenReturn(List.of(tariffLocation)); when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfo); @@ -1334,7 +1470,7 @@ void editTariffWithBuildTariffLocation() { void checkIfTariffDoesNotExistsTest() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(anyLong(), any())) - .thenReturn(Collections.emptyList()); + .thenReturn(Collections.emptyList()); boolean actual = superAdminService.checkIfTariffExists(dto); assertFalse(actual); verify(tariffsLocationRepository).findAllByCourierIdAndLocationIds(anyLong(), any()); @@ -1344,14 +1480,14 @@ void checkIfTariffDoesNotExistsTest() { void checkIfTariffExistsTest() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); TariffLocation tariffLocation = TariffLocation - .builder() - .id(1L) - .tariffsInfo(ModelUtils.getTariffsInfo()) - .location(ModelUtils.getLocation()) - .locationStatus(LocationStatus.ACTIVE) - .build(); + .builder() + .id(1L) + .tariffsInfo(ModelUtils.getTariffsInfo()) + .location(ModelUtils.getLocation()) + .locationStatus(LocationStatus.ACTIVE) + .build(); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(anyLong(), any())) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); boolean actual = superAdminService.checkIfTariffExists(dto); assertTrue(actual); verify(tariffsLocationRepository).findAllByCourierIdAndLocationIds(anyLong(), any()); @@ -1425,7 +1561,7 @@ void setTariffLimitsIfBagNotBelongToTariff() { when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(2L, dto)); + () -> superAdminService.setTariffLimits(2L, dto)); verify(tariffsInfoRepository).findById(2L); verify(bagRepository).findById(1); @@ -1480,7 +1616,7 @@ void setTariffLimitsWithNullCourierLimitAndTrueBagLimitIncluded() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1495,7 +1631,7 @@ void setTariffLimitsWithNullAllParamsAndTrueBagLimitIncluded() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1510,7 +1646,7 @@ void setTariffLimitsWithNotNullAllParamsAndFalseBagLimitIncluded() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1523,7 +1659,7 @@ void setTariffsLimitWithSameMinAndMaxValue() { when(tariffsInfoRepository.findById(anyLong())).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1536,7 +1672,7 @@ void setTariffLimitsWithPriceOfOrderMaxValueIsGreaterThanMin() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1549,7 +1685,7 @@ void setTariffLimitsWithAmountOfBigBagMaxValueIsGreaterThanMin() { when(tariffsInfoRepository.findById(anyLong())).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1561,7 +1697,7 @@ void setTariffLimitsBagThrowTariffsInfoNotFound() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1575,7 +1711,7 @@ void setTariffLimitsBagThrowBagNotFound() { when(bagRepository.findById(1)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(bagRepository).findById(1); @@ -1600,7 +1736,7 @@ void getTariffLimitsThrowNotFoundException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.getTariffLimits(1L)); + () -> superAdminService.getTariffLimits(1L)); verify(tariffsInfoRepository).findById(1L); } @@ -1653,10 +1789,10 @@ void switchTariffStatusFromWhenCourierDeactivatedThrowBadRequestException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); Throwable t = assertThrows(BadRequestException.class, - () -> superAdminService.switchTariffStatus(1L, "Active")); + () -> superAdminService.switchTariffStatus(1L, "Active")); assertEquals(String.format(ErrorMessage.TARIFF_ACTIVATION_RESTRICTION_DUE_TO_DEACTIVATED_COURIER + - tariffInfo.getCourier().getId()), - t.getMessage()); + tariffInfo.getCourier().getId()), + t.getMessage()); verify(tariffsInfoRepository).findById(1L); verify(tariffsInfoRepository, never()).save(tariffInfo); @@ -1681,7 +1817,7 @@ void switchTariffStatusThrowNotFoundException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.switchTariffStatus(1L, "Active")); + () -> superAdminService.switchTariffStatus(1L, "Active")); verify(tariffsInfoRepository).findById(1L); verify(tariffsInfoRepository, never()).save(any(TariffsInfo.class)); @@ -1694,9 +1830,9 @@ void switchTariffStatusFromActiveToActiveThrowBadRequestException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); Throwable t = assertThrows(BadRequestException.class, - () -> superAdminService.switchTariffStatus(1L, "Active")); + () -> superAdminService.switchTariffStatus(1L, "Active")); assertEquals(String.format(ErrorMessage.TARIFF_ALREADY_HAS_THIS_STATUS, 1L, TariffStatus.ACTIVE), - t.getMessage()); + t.getMessage()); verify(tariffsInfoRepository).findById(1L); verify(tariffsInfoRepository, never()).save(tariffInfo); @@ -1710,9 +1846,9 @@ void switchTariffStatusToActiveWithoutBagThrowBadRequestException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); Throwable t = assertThrows(BadRequestException.class, - () -> superAdminService.switchTariffStatus(1L, "Active")); + () -> superAdminService.switchTariffStatus(1L, "Active")); assertEquals(ErrorMessage.TARIFF_ACTIVATION_RESTRICTION_DUE_TO_UNSPECIFIED_BAGS, - t.getMessage()); + t.getMessage()); verify(tariffsInfoRepository).findById(1L); verify(tariffsInfoRepository, never()).save(tariffInfo); @@ -1726,7 +1862,7 @@ void switchTariffStatusWithUnresolvableStatusThrowBadRequestException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); Throwable t = assertThrows(BadRequestException.class, - () -> superAdminService.switchTariffStatus(1L, "new")); + () -> superAdminService.switchTariffStatus(1L, "new")); assertEquals(ErrorMessage.UNRESOLVABLE_TARIFF_STATUS, t.getMessage()); verify(tariffsInfoRepository).findById(1L); @@ -1742,9 +1878,9 @@ void switchTariffStatusToActiveWithMinAndMaxNullThrowBadRequestException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); Throwable t = assertThrows(BadRequestException.class, - () -> superAdminService.switchTariffStatus(1L, "Active")); + () -> superAdminService.switchTariffStatus(1L, "Active")); assertEquals(ErrorMessage.TARIFF_ACTIVATION_RESTRICTION_DUE_TO_UNSPECIFIED_LIMITS, - t.getMessage()); + t.getMessage()); verify(tariffsInfoRepository).findById(1L); verify(tariffsInfoRepository, never()).save(tariffInfo); @@ -1806,7 +1942,7 @@ void changeTariffLocationsStatusParamUnresolvable() { when(tariffsInfoRepository.findById(anyLong())).thenReturn(Optional.of(tariffsInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.changeTariffLocationsStatus(1L, dto, "unresolvable")); + () -> superAdminService.changeTariffLocationsStatus(1L, dto, "unresolvable")); } @Test @@ -1814,7 +1950,7 @@ void switchActivationStatusByChosenParamsBadRequestExceptionUnresolvableStatus() DetailsOfDeactivateTariffsDto details = ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegion(); details.setActivationStatus("Test"); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test @@ -1833,7 +1969,7 @@ void switchActivationStatusByAllValidParams() { when(receivingStationRepository.findById(anyLong())).thenReturn(Optional.of(receivingStation)); when(receivingStationRepository.saveAll(List.of(receivingStation))).thenReturn(List.of(receivingStation)); doNothing().when(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); superAdminService.switchActivationStatusByChosenParams(details); @@ -1841,7 +1977,7 @@ void switchActivationStatusByAllValidParams() { verify(locationRepository).findLocationByIdAndRegionId(1L, 1L); verify(locationRepository).saveAll(List.of(location)); verify(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); verify(courierRepository).findById(1L); verify(courierRepository).save(courier); verify(receivingStationRepository).findById(anyLong()); @@ -1870,13 +2006,13 @@ void switchLocationStatusToActiveByOneRegion() { when(locationRepository.findLocationsByRegionId(1L)).thenReturn(List.of(locationDeactivated)); when(locationRepository.saveAll(List.of(locationActive))).thenReturn(List.of(locationActive)); doNothing().when(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); superAdminService.switchActivationStatusByChosenParams(details); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(List.of(1L)); verify(locationRepository).findLocationsByRegionId(1L); verify(locationRepository).saveAll(List.of(locationActive)); verify(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); } @Test @@ -1903,13 +2039,13 @@ void switchLocationStatusToActiveByTwoRegions() { when(locationRepository.findLocationsByRegionId(2L)).thenReturn(List.of(locationDeactivated)); when(locationRepository.saveAll(List.of(locationActive))).thenReturn(List.of(locationActive)); doNothing().when(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); superAdminService.switchActivationStatusByChosenParams(details); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(anyList()); verify(locationRepository, times(2)).findLocationsByRegionId(anyLong()); verify(locationRepository, times(2)).saveAll(List.of(locationActive)); verify(tariffsLocationRepository, times(2)) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); } @Test @@ -1931,7 +2067,7 @@ void deactivateTariffByNotExistingRegionThrows() { when(deactivateTariffsForChosenParamRepository.isRegionsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(List.of(1L)); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByRegions(anyList()); } @@ -1943,7 +2079,7 @@ void switchLocationStatusToActiveByNotExistingRegionThrows() { when(deactivateTariffsForChosenParamRepository.isRegionsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(List.of(1L)); } @@ -1972,19 +2108,19 @@ void switchLocationStatusToActiveByRegionAndCities() { when(deactivateTariffsForChosenParamRepository.isRegionsExists(anyList())).thenReturn(true); when(locationRepository.findLocationByIdAndRegionId(1L, 1L)) - .thenReturn(Optional.of(locationDeactivated1)); + .thenReturn(Optional.of(locationDeactivated1)); when(locationRepository.findLocationByIdAndRegionId(11L, 1L)) - .thenReturn(Optional.of(locationDeactivated2)); + .thenReturn(Optional.of(locationDeactivated2)); when(locationRepository.saveAll(List.of(locationActive1, locationActive2))) - .thenReturn(List.of(locationActive1, locationActive2)); + .thenReturn(List.of(locationActive1, locationActive2)); doNothing().when(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L, 11L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L, 11L), LocationStatus.ACTIVE.name()); superAdminService.switchActivationStatusByChosenParams(details); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(anyList()); verify(locationRepository, times(2)).findLocationByIdAndRegionId(anyLong(), anyLong()); verify(locationRepository).saveAll(List.of(locationActive1, locationActive2)); verify(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L, 11L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L, 11L), LocationStatus.ACTIVE.name()); } @Test @@ -1994,11 +2130,11 @@ void deactivateTariffByOneRegionAndNotExistingCitiesThrows() { when(regionRepository.existsRegionById(anyLong())).thenReturn(true); when(deactivateTariffsForChosenParamRepository.isCitiesExistForRegion(anyList(), anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(regionRepository).existsRegionById(1L); verify(deactivateTariffsForChosenParamRepository).isCitiesExistForRegion(List.of(1L, 11L), 1L); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByRegionsAndCities(anyList(), - anyLong()); + anyLong()); } @Test @@ -2009,7 +2145,7 @@ void switchLocationStatusToActiveByRegionAndNotExistingCitiesThrows() { when(deactivateTariffsForChosenParamRepository.isRegionsExists(anyList())).thenReturn(true); when(locationRepository.findLocationByIdAndRegionId(anyLong(), anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(anyList()); verify(locationRepository).findLocationByIdAndRegionId(anyLong(), anyLong()); } @@ -2021,7 +2157,7 @@ void switchLocationStatusToActiveByCitiesAndNotExistingRegionBadRequestException details.setActivationStatus("Active"); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test @@ -2031,7 +2167,7 @@ void switchLocationStatusToActiveByCitiesAndTwoRegionsBadRequestException() { details.setActivationStatus("Active"); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test @@ -2040,10 +2176,10 @@ void deactivateTariffByOneNotExistingRegionAndCitiesThrows() { when(regionRepository.existsRegionById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(regionRepository).existsRegionById(1L); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByRegionsAndCities(anyList(), - anyLong()); + anyLong()); } @Test @@ -2053,7 +2189,7 @@ void switchLocationStatusToActiveExistingRegionAndCitiesThrows() { when(deactivateTariffsForChosenParamRepository.isRegionsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(anyList()); } @@ -2086,7 +2222,7 @@ void deactivateTariffByNotExistingCourierThrows() { when(courierRepository.existsCourierById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(courierRepository).existsCourierById(1L); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByCourier(anyLong()); } @@ -2098,7 +2234,7 @@ void switchCourierStatusToActiveNotExistingCourierThrows() { when(courierRepository.findById(anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(courierRepository).findById(anyLong()); } @@ -2123,7 +2259,7 @@ void switchReceivingStationsStatusToActive() { when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation1)); when(receivingStationRepository.findById(12L)).thenReturn(Optional.of(receivingStation2)); when(receivingStationRepository.saveAll(List.of(receivingStation1, receivingStation2))) - .thenReturn(List.of(receivingStation1, receivingStation2)); + .thenReturn(List.of(receivingStation1, receivingStation2)); superAdminService.switchActivationStatusByChosenParams(details); verify(receivingStationRepository, times(2)).findById(anyLong()); verify(receivingStationRepository).saveAll(anyList()); @@ -2135,7 +2271,7 @@ void deactivateTariffByNotExistingReceivingStationsThrows() { when(deactivateTariffsForChosenParamRepository.isReceivingStationsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByReceivingStations(anyList()); } @@ -2147,14 +2283,14 @@ void switchReceivingStationsStatusToActiveNotExistingReceivingStationsThrows() { when(receivingStationRepository.findById(anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(receivingStationRepository).findById(anyLong()); } @Test void deactivateTariffByCourierAndReceivingStations() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); when(courierRepository.existsCourierById(anyLong())).thenReturn(true); when(deactivateTariffsForChosenParamRepository.isReceivingStationsExists(anyList())).thenReturn(true); @@ -2162,35 +2298,35 @@ void deactivateTariffByCourierAndReceivingStations() { verify(courierRepository).existsCourierById(1L); verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); verify(deactivateTariffsForChosenParamRepository) - .deactivateTariffsByCourierAndReceivingStations(1L, List.of(1L, 12L)); + .deactivateTariffsByCourierAndReceivingStations(1L, List.of(1L, 12L)); } @Test void deactivateTariffByNotExistingCourierAndReceivingStationsTrows() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); when(courierRepository.existsCourierById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(courierRepository).existsCourierById(1L); verify(deactivateTariffsForChosenParamRepository, never()) - .deactivateTariffsByCourierAndReceivingStations(anyLong(), anyList()); + .deactivateTariffsByCourierAndReceivingStations(anyLong(), anyList()); } @Test void deactivateTariffByCourierAndNotExistingReceivingStationsTrows() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); when(courierRepository.existsCourierById(anyLong())).thenReturn(true); when(deactivateTariffsForChosenParamRepository.isReceivingStationsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(courierRepository).existsCourierById(1L); verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); verify(deactivateTariffsForChosenParamRepository, never()) - .deactivateTariffsByCourierAndReceivingStations(anyLong(), anyList()); + .deactivateTariffsByCourierAndReceivingStations(anyLong(), anyList()); } @Test @@ -2212,11 +2348,11 @@ void deactivateTariffByNotExistingCourierAndOneRegionThrows() { when(regionRepository.existsRegionById(anyLong())).thenReturn(true); when(courierRepository.existsCourierById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(regionRepository).existsRegionById(1L); verify(courierRepository).existsCourierById(1L); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByCourierAndRegion(anyLong(), - anyLong()); + anyLong()); } @Test @@ -2225,16 +2361,16 @@ void deactivateTariffByCourierAndNotExistingRegionThrows() { when(regionRepository.existsRegionById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(regionRepository).existsRegionById(1L); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByCourierAndRegion(anyLong(), - anyLong()); + anyLong()); } @Test void deactivateTariffByOneRegionAndCityAndStation() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation(); doMockForTariffWithRegionAndCityAndStation(true, true, true); superAdminService.switchActivationStatusByChosenParams(details); @@ -2244,29 +2380,29 @@ void deactivateTariffByOneRegionAndCityAndStation() { @ParameterizedTest @MethodSource("deactivateTariffByNotExistingSomeOfTreeParameters") void deactivateTariffByNotExistingRegionAndCityAndStationThrows( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists) { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation(); doMockForTariffWithRegionAndCityAndStation(isRegionExists, isCitiesExistForRegion, isReceivingStationsExists); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verifyForTariffWithRegionAndCityAndStation(isRegionExists, isCitiesExistForRegion, isReceivingStationsExists); verify(deactivateTariffsForChosenParamRepository, never()) - .deactivateTariffsByRegionAndCitiesAndStations(anyLong(), anyList(), anyList()); + .deactivateTariffsByRegionAndCitiesAndStations(anyLong(), anyList(), anyList()); } static Stream deactivateTariffByNotExistingSomeOfTreeParameters() { return Stream.of( - arguments(false, true, true), - arguments(false, false, true), - arguments(false, true, false), - arguments(true, false, true), - arguments(true, false, false), - arguments(true, true, false), - arguments(false, false, false)); + arguments(false, true, true), + arguments(false, false, true), + arguments(false, true, false), + arguments(true, false, true), + arguments(true, false, false), + arguments(true, true, false), + arguments(false, false, false)); } @Test @@ -2281,39 +2417,39 @@ void deactivateTariffByAllValidParams() { @ParameterizedTest @MethodSource("deactivateTariffByAllWithNotExistingParamProvider") void deactivateTariffByAllWithNotExistingParamThrows( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists, + boolean isCourierExists) { DetailsOfDeactivateTariffsDto details = ModelUtils.getDetailsOfDeactivateTariffsDtoWithAllParams(); doMockForTariffWithAllParams(isRegionExists, isCitiesExistForRegion, isReceivingStationsExists, - isCourierExists); + isCourierExists); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verifyForTariffWithAllParams(isRegionExists, isCitiesExistForRegion, isReceivingStationsExists, - isCourierExists); + isCourierExists); verify(deactivateTariffsForChosenParamRepository, never()) - .deactivateTariffsByAllParam(anyLong(), anyList(), anyList(), anyLong()); + .deactivateTariffsByAllParam(anyLong(), anyList(), anyList(), anyLong()); } private static Stream deactivateTariffByAllWithNotExistingParamProvider() { return Stream.of( - arguments(false, true, true, true), - arguments(true, false, true, true), - arguments(true, true, false, true), - arguments(true, true, true, false), - arguments(false, false, true, true), - arguments(false, true, false, true), - arguments(false, true, true, false), - arguments(false, true, false, false), - arguments(true, false, false, true), - arguments(true, false, true, false), - arguments(true, true, false, false), - arguments(false, false, false, true), - arguments(false, false, true, false), - arguments(true, false, false, false), - arguments(false, false, false, false)); + arguments(false, true, true, true), + arguments(true, false, true, true), + arguments(true, true, false, true), + arguments(true, true, true, false), + arguments(false, false, true, true), + arguments(false, true, false, true), + arguments(false, true, true, false), + arguments(false, true, false, false), + arguments(true, false, false, true), + arguments(true, false, true, false), + arguments(true, true, false, false), + arguments(false, false, false, true), + arguments(false, false, true, false), + arguments(true, false, false, false), + arguments(false, false, false, false)); } @Test @@ -2321,7 +2457,7 @@ void deactivateTariffByAllEmptyParams() { DetailsOfDeactivateTariffsDto details = ModelUtils.getDetailsOfDeactivateTariffsDtoWithEmptyParams(); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test @@ -2329,7 +2465,7 @@ void deactivateTariffByCities() { DetailsOfDeactivateTariffsDto details = ModelUtils.getDetailsOfDeactivateTariffsDtoWithCities(); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test @@ -2337,71 +2473,71 @@ void deactivateTariffByCitiesAndCourier() { DetailsOfDeactivateTariffsDto details = ModelUtils.getDetailsOfDeactivateTariffsDtoWithCitiesAndCourier(); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test void deactivateTariffByCitiesAndReceivingStations() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCitiesAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCitiesAndReceivingStations(); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test void deactivateTariffByCitiesAndCourierAndReceivingStations() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCitiesAndCourierAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCitiesAndCourierAndReceivingStations(); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @ParameterizedTest @MethodSource("deactivateTariffByDifferentParamWithTwoRegionsProvider") void deactivateTariffByDifferentParamWithTwoRegionsThrows(DetailsOfDeactivateTariffsDto details) { assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } private static Stream deactivateTariffByDifferentParamWithTwoRegionsProvider() { return Stream.of( - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegion() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCities() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithAllParams() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations() - .setRegionsIds(Optional.of(List.of(1L, 2L))))); + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegion() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCities() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithAllParams() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations() + .setRegionsIds(Optional.of(List.of(1L, 2L))))); } private void doMockForTariffWithRegionAndCityAndStation( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists) { when(regionRepository.existsRegionById(anyLong())).thenReturn(isRegionExists); if (isRegionExists) { when(deactivateTariffsForChosenParamRepository - .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistForRegion); + .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistForRegion); if (isCitiesExistForRegion) { when(deactivateTariffsForChosenParamRepository - .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); + .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); } } } private void verifyForTariffWithRegionAndCityAndStation( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists) { verify(regionRepository).existsRegionById(1L); if (isRegionExists) { verify(deactivateTariffsForChosenParamRepository).isCitiesExistForRegion(List.of(1L, 11L), 1L); @@ -2409,24 +2545,24 @@ private void verifyForTariffWithRegionAndCityAndStation( verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); if (isReceivingStationsExists) { verify(deactivateTariffsForChosenParamRepository) - .deactivateTariffsByRegionAndCitiesAndStations(1L, List.of(1L, 11L), List.of(1L, 12L)); + .deactivateTariffsByRegionAndCitiesAndStations(1L, List.of(1L, 11L), List.of(1L, 12L)); } } } } private void doMockForTariffWithAllParams( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists, + boolean isCourierExists) { when(regionRepository.existsRegionById(anyLong())).thenReturn(isRegionExists); if (isRegionExists) { when(deactivateTariffsForChosenParamRepository - .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistForRegion); + .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistForRegion); if (isCitiesExistForRegion) { when(deactivateTariffsForChosenParamRepository - .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); + .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); if (isReceivingStationsExists) { when(courierRepository.existsCourierById(anyLong())).thenReturn(isCourierExists); } @@ -2435,10 +2571,10 @@ private void doMockForTariffWithAllParams( } private void verifyForTariffWithAllParams( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists, + boolean isCourierExists) { verify(regionRepository).existsRegionById(1L); if (isRegionExists) { verify(deactivateTariffsForChosenParamRepository).isCitiesExistForRegion(List.of(1L, 11L), 1L); @@ -2448,7 +2584,7 @@ private void verifyForTariffWithAllParams( verify(courierRepository).existsCourierById(1L); if (isCourierExists) { verify(deactivateTariffsForChosenParamRepository) - .deactivateTariffsByAllParam(1L, List.of(1L, 11L), List.of(1L, 12L), 1L); + .deactivateTariffsByAllParam(1L, List.of(1L, 11L), List.of(1L, 12L), 1L); } } } @@ -2458,7 +2594,7 @@ private void verifyForTariffWithAllParams( @Test void deactivateTariffByRegionsAndReceivingStations() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); doMockForTariffWithRegionAndStation(true, true); superAdminService.switchActivationStatusByChosenParams(details); @@ -2466,24 +2602,24 @@ void deactivateTariffByRegionsAndReceivingStations() { } private void doMockForTariffWithRegionAndStation( - boolean isRegionExists, - boolean isReceivingStationsExists) { + boolean isRegionExists, + boolean isReceivingStationsExists) { when(regionRepository.existsRegionById(anyLong())).thenReturn(isRegionExists); if (isRegionExists) { when(deactivateTariffsForChosenParamRepository - .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); + .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); } } private void verifyForTariffWithRegionAndStation( - boolean isRegionExists, - boolean isReceivingStationsExists) { + boolean isRegionExists, + boolean isReceivingStationsExists) { verify(regionRepository).existsRegionById(1L); if (isRegionExists) { verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); if (isReceivingStationsExists) { verify(tariffsInfoRepository) - .deactivateTariffsByRegionAndReceivingStations(1L, List.of(1L, 12L)); + .deactivateTariffsByRegionAndReceivingStations(1L, List.of(1L, 12L)); } } } @@ -2491,37 +2627,37 @@ private void verifyForTariffWithRegionAndStation( @Test void deactivateTariffByNotExistingRegionsAndReceivingStationsTrows() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); when(regionRepository.existsRegionById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(regionRepository).existsRegionById(1L); verify(tariffsInfoRepository, never()).deactivateTariffsByRegionAndReceivingStations( - anyLong(), - anyList()); + anyLong(), + anyList()); } @Test void deactivateTariffByRegionsAndNotExistingReceivingStationsTrows() { DetailsOfDeactivateTariffsDto details1 = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); when(regionRepository.existsRegionById(anyLong())).thenReturn(true); when(deactivateTariffsForChosenParamRepository.isReceivingStationsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details1)); + () -> superAdminService.switchActivationStatusByChosenParams(details1)); verify(regionRepository).existsRegionById(1L); verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); verify(tariffsInfoRepository, never()).deactivateTariffsByRegionAndReceivingStations( - anyLong(), - anyList()); + anyLong(), + anyList()); } @Test void deactivateTariffByCourierAndRegionAndCities() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities(); doMockForTariffWithCourierAndRegionAndCities(true, true, true); superAdminService.switchActivationStatusByChosenParams(details); @@ -2529,13 +2665,13 @@ void deactivateTariffByCourierAndRegionAndCities() { } private void doMockForTariffWithCourierAndRegionAndCities( - boolean isRegionExists, - boolean isCitiesExistsForRegion, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistsForRegion, + boolean isCourierExists) { when(regionRepository.existsRegionById(anyLong())).thenReturn(isRegionExists); if (isRegionExists) { when(deactivateTariffsForChosenParamRepository - .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistsForRegion); + .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistsForRegion); if (isCitiesExistsForRegion) { when(courierRepository.existsCourierById(anyLong())).thenReturn(isCourierExists); } @@ -2543,9 +2679,9 @@ private void doMockForTariffWithCourierAndRegionAndCities( } private void verifyForTariffWithCourierAndRegionAndCities( - boolean isRegionExists, - boolean isCitiesExistsForRegion, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistsForRegion, + boolean isCourierExists) { verify(regionRepository).existsRegionById(1L); if (isRegionExists) { verify(deactivateTariffsForChosenParamRepository).isCitiesExistForRegion(List.of(1L, 11L), 1L); @@ -2553,7 +2689,7 @@ private void verifyForTariffWithCourierAndRegionAndCities( verify(courierRepository).existsCourierById(1L); if (isCourierExists) { verify(tariffsInfoRepository) - .deactivateTariffsByCourierAndRegionAndCities(1L, List.of(1L, 11L), 1L); + .deactivateTariffsByCourierAndRegionAndCities(1L, List.of(1L, 11L), 1L); } } } @@ -2562,26 +2698,26 @@ private void verifyForTariffWithCourierAndRegionAndCities( @ParameterizedTest @MethodSource("deactivateTariffByNotExistingSomeOfTreeParameters") void deactivateTariffByCourierAndRegionsAndCitiesWithNotExistingParamThrows( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isCourierExists) { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities(); doMockForTariffWithCourierAndRegionAndCities(isRegionExists, isCitiesExistForRegion, - isCourierExists); + isCourierExists); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verifyForTariffWithCourierAndRegionAndCities(isRegionExists, isCitiesExistForRegion, - isCourierExists); + isCourierExists); verify(tariffsInfoRepository, never()) - .deactivateTariffsByCourierAndRegionAndCities(anyLong(), anyList(), anyLong()); + .deactivateTariffsByCourierAndRegionAndCities(anyLong(), anyList(), anyLong()); } @Test void deactivateTariffByCourierAndRegionAndReceivingStation() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations(); doMockForTariffWithCourierAndRegionAndReceivingStation(true, true, true); superAdminService.switchActivationStatusByChosenParams(details); @@ -2589,13 +2725,13 @@ void deactivateTariffByCourierAndRegionAndReceivingStation() { } private void doMockForTariffWithCourierAndRegionAndReceivingStation( - boolean isRegionExists, - boolean isCourierExists, - boolean isReceivingStationExists) { + boolean isRegionExists, + boolean isCourierExists, + boolean isReceivingStationExists) { when(regionRepository.existsRegionById(anyLong())).thenReturn(isRegionExists); if (isRegionExists) { when(deactivateTariffsForChosenParamRepository - .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationExists); + .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationExists); if (isReceivingStationExists) { when(courierRepository.existsCourierById(anyLong())).thenReturn(isCourierExists); } @@ -2603,9 +2739,9 @@ private void doMockForTariffWithCourierAndRegionAndReceivingStation( } private void verifyForTariffWithCourierAndRegionAndReceivingStation( - boolean isRegionExists, - boolean isCourierExists, - boolean isReceivingStationExists) { + boolean isRegionExists, + boolean isCourierExists, + boolean isReceivingStationExists) { verify(regionRepository).existsRegionById(1L); if (isRegionExists) { verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); @@ -2613,7 +2749,7 @@ private void verifyForTariffWithCourierAndRegionAndReceivingStation( verify(courierRepository).existsCourierById(1L); if (isCourierExists) { verify(tariffsInfoRepository) - .deactivateTariffsByCourierAndRegionAndReceivingStations(1L, List.of(1L, 12L), 1L); + .deactivateTariffsByCourierAndRegionAndReceivingStations(1L, List.of(1L, 12L), 1L); } } } @@ -2622,19 +2758,19 @@ private void verifyForTariffWithCourierAndRegionAndReceivingStation( @ParameterizedTest @MethodSource("deactivateTariffByNotExistingSomeOfTreeParameters") void deactivateTariffByCourierAndRegionsAndReceivingStationWithNotExistingParamThrows( - boolean isRegionExists, - boolean isCourierExists, - boolean isReceivingStationExists) { + boolean isRegionExists, + boolean isCourierExists, + boolean isReceivingStationExists) { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations(); doMockForTariffWithCourierAndRegionAndReceivingStation(isRegionExists, isReceivingStationExists, - isCourierExists); + isCourierExists); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verifyForTariffWithCourierAndRegionAndReceivingStation(isRegionExists, isReceivingStationExists, - isCourierExists); + isCourierExists); verify(tariffsInfoRepository, never()) - .deactivateTariffsByCourierAndRegionAndCities(anyLong(), anyList(), anyLong()); + .deactivateTariffsByCourierAndRegionAndCities(anyLong(), anyList(), anyLong()); } } \ No newline at end of file From 547d520952042ba41023db93181edb4e1e1489b2 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 24 Jul 2023 00:16:29 +0300 Subject: [PATCH 20/73] Fixed tests(unworking 36) --- .../greencity/repository/BagRepository.java | 1 - .../service/ubs/SuperAdminServiceImpl.java | 1 + .../src/test/java/greencity/ModelUtils.java | 6154 ++++++++--------- .../NotificationServiceImplTest.java | 7 +- .../ubs/SuperAdminServiceImplTest.java | 646 +- .../service/ubs/UBSClientServiceImplTest.java | 1 + .../ubs/UBSManagementServiceImplTest.java | 39 +- 7 files changed, 3426 insertions(+), 3423 deletions(-) diff --git a/dao/src/main/java/greencity/repository/BagRepository.java b/dao/src/main/java/greencity/repository/BagRepository.java index 270e42790..0796e00d6 100644 --- a/dao/src/main/java/greencity/repository/BagRepository.java +++ b/dao/src/main/java/greencity/repository/BagRepository.java @@ -11,7 +11,6 @@ @Repository public interface BagRepository extends JpaRepository { - /** * This is method which find capacity by id. * diff --git a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java index e397ec0da..8c30160e0 100644 --- a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java @@ -203,6 +203,7 @@ private void checkDeletedBagLimitAndDeleteTariffsInfo(Bag bag) { tariffsInfoRepository.save(tariffsInfo); } } + @Override @Transactional public GetTariffServiceDto editTariffService(TariffServiceDto dto, Integer bagId, String employeeUuid) { diff --git a/service/src/test/java/greencity/ModelUtils.java b/service/src/test/java/greencity/ModelUtils.java index e2634af0b..75e6a191f 100644 --- a/service/src/test/java/greencity/ModelUtils.java +++ b/service/src/test/java/greencity/ModelUtils.java @@ -172,7 +172,7 @@ public class ModelUtils { public static final Order TEST_ORDER = createOrder(); public static final OrderAddressDtoResponse TEST_ORDER_ADDRESS_DTO_RESPONSE = createOrderAddressDtoResponse(); public static final OrderAddressExportDetailsDtoUpdate TEST_ORDER_ADDRESS_DTO_UPDATE = - createOrderAddressDtoUpdate(); + createOrderAddressDtoUpdate(); public static final List TEST_PAYMENT_LIST = createPaymentList(); public static final OrderDetailStatusDto ORDER_DETAIL_STATUS_DTO = createOrderDetailStatusDto(); public static final List TEST_BAG_MAPPING_DTO_LIST = createBagMappingDtoList(); @@ -182,7 +182,7 @@ public class ModelUtils { public static final BagInfoDto TEST_BAG_INFO_DTO = createBagInfoDto(); public static final List TEST_BAG_LIST = singletonList(TEST_BAG); public static final List TEST_ORDER_DETAILS_INFO_DTO_LIST = - singletonList(createOrderDetailInfoDto()); + singletonList(createOrderDetailInfoDto()); public static final OrderAddressDtoRequest TEST_ORDER_ADDRESS_DTO_REQUEST = createOrderDtoRequest(); public static final Order TEST_ORDER_2 = createTestOrder2(); public static final Order TEST_ORDER_3 = createTestOrder3(); @@ -201,29 +201,29 @@ public class ModelUtils { public static final NotificationTemplateDto TEST_NOTIFICATION_TEMPLATE_DTO = createNotificationTemplateDto(); public static final NotificationTemplateWithPlatformsUpdateDto TEST_NOTIFICATION_TEMPLATE_UPDATE_DTO = - createNotificationTemplateWithPlatformsUpdateDto(); + createNotificationTemplateWithPlatformsUpdateDto(); public static final NotificationTemplateWithPlatformsDto TEST_NOTIFICATION_TEMPLATE_WITH_PLATFORMS_DTO = - createNotificationTemplateWithPlatformsDto(); + createNotificationTemplateWithPlatformsDto(); public static final Pageable TEST_PAGEABLE = PageRequest.of(0, 5, Sort.by("notificationTime").descending()); public static final Pageable TEST_NOTIFICATION_PAGEABLE = PageRequest.of(0, 5, Sort.by("id").descending()); public static final NotificationShortDto TEST_NOTIFICATION_SHORT_DTO = createNotificationShortDto(); public static final List TEST_NOTIFICATION_SHORT_DTO_LIST = - List.of(TEST_NOTIFICATION_SHORT_DTO); + List.of(TEST_NOTIFICATION_SHORT_DTO); public static final PageableDto TEST_DTO = createPageableDto(); public static final Employee TEST_EMPLOYEE = createEmployee(); public static final User TEST_USER = createUser(); public static final List TEST_USER_NOTIFICATION_LIST = createUserNotificationList(); public static final Page TEST_PAGE = - new PageImpl<>(TEST_USER_NOTIFICATION_LIST, TEST_PAGEABLE, TEST_USER_NOTIFICATION_LIST.size()); + new PageImpl<>(TEST_USER_NOTIFICATION_LIST, TEST_PAGEABLE, TEST_USER_NOTIFICATION_LIST.size()); public static final Page TEMPLATE_PAGE = - new PageImpl<>(List.of(TEST_NOTIFICATION_TEMPLATE), TEST_PAGEABLE, 1L); + new PageImpl<>(List.of(TEST_NOTIFICATION_TEMPLATE), TEST_PAGEABLE, 1L); public static final AdditionalBagInfoDto TEST_ADDITIONAL_BAG_INFO_DTO = createAdditionalBagInfoDto(); public static final List TEST_ADDITIONAL_BAG_INFO_DTO_LIST = createAdditionalBagInfoDtoList(); public static final Map TEST_MAP_ADDITIONAL_BAG = createMap(); public static final List> TEST_MAP_ADDITIONAL_BAG_LIST = - Collections.singletonList(TEST_MAP_ADDITIONAL_BAG); + Collections.singletonList(TEST_MAP_ADDITIONAL_BAG); public static final NotificationDto TEST_NOTIFICATION_DTO = createNotificationDto(); public static final UpdateOrderPageAdminDto UPDATE_ORDER_PAGE_ADMIN_DTO = updateOrderPageAdminDto(); public static final CourierUpdateDto UPDATE_COURIER_DTO = getUpdateCourierDto(); @@ -237,48 +237,48 @@ public static EmployeeFilterView getEmployeeFilterView() { } public static EmployeeFilterView getEmployeeFilterViewWithPassedIds( - Long employeeId, Long positionId, Long tariffsInfoId) { + Long employeeId, Long positionId, Long tariffsInfoId) { return EmployeeFilterView.builder() - .employeeId(employeeId) - .positionId(positionId) - .positionName("Водій") - .positionNameEn("Driver") - .tariffsInfoId(tariffsInfoId) - .firstName("First Name") - .lastName("Last Name") - .phoneNumber("Phone Number") - .email("employee@gmail.com") - .employeeStatus("ACTIVE") - .image("Image") - .regionId(15L) - .regionNameEn("Kyiv region") - .regionNameUk("Київська область") - .courierId(20L) - .receivingStationId(25L) - .receivingStationName("Receiving station") - .courierNameEn("Test") - .courierNameUk("Тест") - .locationId(30L) - .locationNameEn("Kyiv") - .locationNameUk("Київ") - .build(); + .employeeId(employeeId) + .positionId(positionId) + .positionName("Водій") + .positionNameEn("Driver") + .tariffsInfoId(tariffsInfoId) + .firstName("First Name") + .lastName("Last Name") + .phoneNumber("Phone Number") + .email("employee@gmail.com") + .employeeStatus("ACTIVE") + .image("Image") + .regionId(15L) + .regionNameEn("Kyiv region") + .regionNameUk("Київська область") + .courierId(20L) + .receivingStationId(25L) + .receivingStationName("Receiving station") + .courierNameEn("Test") + .courierNameUk("Тест") + .locationId(30L) + .locationNameEn("Kyiv") + .locationNameUk("Київ") + .build(); } public static List getEmployeeFilterViewListForOneEmployeeWithDifferentPositions( - Long employeeId, Long tariffsInfoId) { + Long employeeId, Long tariffsInfoId) { return List.of( - getEmployeeFilterViewWithPassedIds(employeeId, 3L, tariffsInfoId), - getEmployeeFilterViewWithPassedIds(employeeId, 5L, tariffsInfoId), - getEmployeeFilterViewWithPassedIds(employeeId, 7L, tariffsInfoId)); + getEmployeeFilterViewWithPassedIds(employeeId, 3L, tariffsInfoId), + getEmployeeFilterViewWithPassedIds(employeeId, 5L, tariffsInfoId), + getEmployeeFilterViewWithPassedIds(employeeId, 7L, tariffsInfoId)); } public static GetEmployeeDto getEmployeeDtoWithPositionsAndTariffs() { var getEmployeeDto = getEmployeeDto(); getEmployeeDto.setEmployeePositions(List.of( - getPositionDto(3L), - getPositionDto(5L), - getPositionDto(7L))); + getPositionDto(3L), + getPositionDto(5L), + getPositionDto(7L))); var getTariffInfoForEmployeeDto = getTariffInfoForEmployeeDto2(); getTariffInfoForEmployeeDto.setLocationsDtos(List.of(getLocationsDtos(30L))); @@ -290,93 +290,93 @@ public static GetEmployeeDto getEmployeeDtoWithPositionsAndTariffs() { public static GetEmployeeDto getEmployeeDto() { return GetEmployeeDto.builder() - .id(1L) - .firstName("First Name") - .lastName("Last Name") - .phoneNumber("Phone Number") - .email("employee@gmail.com") - .employeeStatus("ACTIVE") - .image("Image") - .build(); + .id(1L) + .firstName("First Name") + .lastName("Last Name") + .phoneNumber("Phone Number") + .email("employee@gmail.com") + .employeeStatus("ACTIVE") + .image("Image") + .build(); } public static GetReceivingStationDto getReceivingStationDto2() { return GetReceivingStationDto.builder() - .stationId(25L) - .name("Receiving station") - .build(); + .stationId(25L) + .name("Receiving station") + .build(); } public static GetTariffInfoForEmployeeDto getTariffInfoForEmployeeDto2() { return GetTariffInfoForEmployeeDto.builder() - .id(10L) - .region(getRegionDto(15L)) - .courier(getCourierTranslationDto(20L)) - .build(); + .id(10L) + .region(getRegionDto(15L)) + .courier(getCourierTranslationDto(20L)) + .build(); } public static CourierUpdateDto getUpdateCourierDto() { return CourierUpdateDto.builder() - .courierId(1L) - .nameUk("Тест") - .nameEn("Test") - .build(); + .courierId(1L) + .nameUk("Тест") + .nameEn("Test") + .build(); } public static DetailsOrderInfoDto getTestDetailsOrderInfoDto() { return DetailsOrderInfoDto.builder() - .capacity("One") - .sum("Two") - .build(); + .capacity("One") + .sum("Two") + .build(); } public static Optional getOrderWithEvents() { return Optional.of(Order.builder() + .id(1L) + .events(List.of(Event.builder() .id(1L) - .events(List.of(Event.builder() - .id(1L) - .authorName("Igor") - .eventDate(LocalDateTime.now()) - .authorName("Igor") - .build(), - Event.builder() - .id(1L) - .authorName("Igor") - .eventDate(LocalDateTime.now()) - .authorName("Igor") - .build(), - Event.builder() - .id(1L) - .authorName("Igor") - .eventDate(LocalDateTime.now()) - .authorName("Igor") - .build())) - .user(getTestUser()) - .build()); + .authorName("Igor") + .eventDate(LocalDateTime.now()) + .authorName("Igor") + .build(), + Event.builder() + .id(1L) + .authorName("Igor") + .eventDate(LocalDateTime.now()) + .authorName("Igor") + .build(), + Event.builder() + .id(1L) + .authorName("Igor") + .eventDate(LocalDateTime.now()) + .authorName("Igor") + .build())) + .user(getTestUser()) + .build()); } public static List getListOfEvents() { return List.of(Event.builder() - .id(1L) - .authorName("Igor") - .eventDate(LocalDateTime.now()) - .authorName("Igor") - .order(new Order()) - .build(), - Event.builder() - .id(1L) - .authorName("Igor") - .eventDate(LocalDateTime.now()) - .authorName("Igor") - .order(new Order()) - .build(), - Event.builder() - .id(1L) - .authorName("Igor") - .eventDate(LocalDateTime.now()) - .authorName("Igor") - .order(new Order()) - .build()); + .id(1L) + .authorName("Igor") + .eventDate(LocalDateTime.now()) + .authorName("Igor") + .order(new Order()) + .build(), + Event.builder() + .id(1L) + .authorName("Igor") + .eventDate(LocalDateTime.now()) + .authorName("Igor") + .order(new Order()) + .build(), + Event.builder() + .id(1L) + .authorName("Igor") + .eventDate(LocalDateTime.now()) + .authorName("Igor") + .order(new Order()) + .build()); } public static OrderResponseDto getOrderResponseDto() { @@ -385,373 +385,373 @@ public static OrderResponseDto getOrderResponseDto() { public static OrderResponseDto getOrderResponseDto(boolean shouldBePaid) { return OrderResponseDto.builder() - .additionalOrders(new HashSet<>(List.of("232-534-634"))) - .bags(Collections.singletonList(new BagDto(3, 999))) - .locationId(1L) - .orderComment("comment") - .certificates(Collections.emptySet()) - .pointsToUse(700) - .shouldBePaid(shouldBePaid) - .personalData(PersonalDataDto.builder() - .senderEmail("test@email.ua") - .senderPhoneNumber("+380974563223") - .senderLastName("TestLast") - .senderFirstName("TestFirst") - .firstName("oleh") - .lastName("ivanov") - .id(13L) - .email("mail@mail.ua") - .phoneNumber("067894522") - .ubsUserId(1L) - .build()) - .build(); + .additionalOrders(new HashSet<>(List.of("232-534-634"))) + .bags(Collections.singletonList(new BagDto(3, 999))) + .locationId(1L) + .orderComment("comment") + .certificates(Collections.emptySet()) + .pointsToUse(700) + .shouldBePaid(shouldBePaid) + .personalData(PersonalDataDto.builder() + .senderEmail("test@email.ua") + .senderPhoneNumber("+380974563223") + .senderLastName("TestLast") + .senderFirstName("TestFirst") + .firstName("oleh") + .lastName("ivanov") + .id(13L) + .email("mail@mail.ua") + .phoneNumber("067894522") + .ubsUserId(1L) + .build()) + .build(); } public static UBSuser getUBSuser() { return UBSuser.builder() - .firstName("oleh") - .lastName("ivanov") - .email("mail@mail.ua") + .firstName("oleh") + .lastName("ivanov") + .email("mail@mail.ua") + .id(1L) + .phoneNumber("067894522") + .senderEmail("test@email.ua") + .senderPhoneNumber("+380974563223") + .senderLastName("TestLast") + .senderFirstName("TestFirst") + .orderAddress(OrderAddress.builder() .id(1L) - .phoneNumber("067894522") - .senderEmail("test@email.ua") - .senderPhoneNumber("+380974563223") - .senderLastName("TestLast") - .senderFirstName("TestFirst") - .orderAddress(OrderAddress.builder() - .id(1L) - .houseNumber("1a") - .actual(true) - .entranceNumber("str") - .district("3a") - .houseCorpus("2a") - .city("Kiev") - .street("Gorodotska") - .coordinates(Coordinates.builder() - .longitude(2.2) - .latitude(3.2) - .build()) - .addressComment(null).build()) - .orders(List.of(Order.builder().id(1L).build())) - .build(); + .houseNumber("1a") + .actual(true) + .entranceNumber("str") + .district("3a") + .houseCorpus("2a") + .city("Kiev") + .street("Gorodotska") + .coordinates(Coordinates.builder() + .longitude(2.2) + .latitude(3.2) + .build()) + .addressComment(null).build()) + .orders(List.of(Order.builder().id(1L).build())) + .build(); } public static UBSuser getUBSuserWtihoutOrderAddress() { return UBSuser.builder() - .firstName("oleh") - .lastName("ivanov") - .email("mail@mail.ua") - .id(1L) - .phoneNumber("067894522") - .senderEmail("test@email.ua") - .senderPhoneNumber("+380974563223") - .senderLastName("TestLast") - .senderFirstName("TestFirst") - .orders(List.of(Order.builder().id(1L).build())) - .build(); + .firstName("oleh") + .lastName("ivanov") + .email("mail@mail.ua") + .id(1L) + .phoneNumber("067894522") + .senderEmail("test@email.ua") + .senderPhoneNumber("+380974563223") + .senderLastName("TestLast") + .senderFirstName("TestFirst") + .orders(List.of(Order.builder().id(1L).build())) + .build(); } public static UBSuser getUBSuserWithoutSender() { return UBSuser.builder() - .firstName("oleh") - .lastName("ivanov") - .email("mail@mail.ua") + .firstName("oleh") + .lastName("ivanov") + .email("mail@mail.ua") + .id(1L) + .phoneNumber("067894522") + .orderAddress(OrderAddress.builder() .id(1L) - .phoneNumber("067894522") - .orderAddress(OrderAddress.builder() - .id(1L) - .houseNumber("1a") - .actual(true) - .entranceNumber("str") - .district("3a") - .houseCorpus("2a") - .city("Kiev") - .street("Gorodotska") - .coordinates(Coordinates.builder() - .longitude(2.2) - .latitude(3.2) - .build()) - .addressComment(null).build()) - .orders(List.of(Order.builder().id(1L).build())) - .build(); + .houseNumber("1a") + .actual(true) + .entranceNumber("str") + .district("3a") + .houseCorpus("2a") + .city("Kiev") + .street("Gorodotska") + .coordinates(Coordinates.builder() + .longitude(2.2) + .latitude(3.2) + .build()) + .addressComment(null).build()) + .orders(List.of(Order.builder().id(1L).build())) + .build(); } public static User getTestUser() { return User.builder() - .id(1L) - .orders(Lists.newArrayList(getOrder())) - .changeOfPointsList(Lists.newArrayList(getChangeOfPoints())) - .currentPoints(getChangeOfPoints().getAmount()) - .orders(Lists.newArrayList(getOrder())) - .recipientName("Alan") - .recipientSurname("Po") - .uuid("abc") - .build(); + .id(1L) + .orders(Lists.newArrayList(getOrder())) + .changeOfPointsList(Lists.newArrayList(getChangeOfPoints())) + .currentPoints(getChangeOfPoints().getAmount()) + .orders(Lists.newArrayList(getOrder())) + .recipientName("Alan") + .recipientSurname("Po") + .uuid("abc") + .build(); } public static ChangeOfPoints getChangeOfPoints() { return ChangeOfPoints.builder() - .id(1L) - .amount(0) - .order(getOrder()) - .date(LocalDateTime.now()) - .build(); + .id(1L) + .amount(0) + .order(getOrder()) + .date(LocalDateTime.now()) + .build(); } public static Order getOrder() { return Order.builder() + .id(1L) + .payment(Lists.newArrayList(Payment.builder() .id(1L) - .payment(Lists.newArrayList(Payment.builder() - .id(1L) - .paymentId("1") - .amount(20000L) - .currency("UAH") - .comment("avb") - .paymentStatus(PaymentStatus.PAID) - .build())) - .ubsUser(UBSuser.builder() - .firstName("oleh") - .lastName("ivanov") - .email("mail@mail.ua") - .id(1L) - .phoneNumber("067894522") - .orderAddress(OrderAddress.builder() - .id(1L) - .city("Lviv") - .street("Levaya") - .district("frankivskiy") - .entranceNumber("5") - .addressComment("near mall") - .houseCorpus("1") - .houseNumber("4") - .coordinates(Coordinates.builder() - .latitude(49.83) - .longitude(23.88) - .build()) - .build()) - .build()) - .user(User.builder() - .id(1L) - .recipientName("Yuriy") - .recipientSurname("Gerasum") - .uuid("UUID") - .build()) - .certificates(Collections.emptySet()) - .pointsToUse(700) - .adminComment("Admin") - .cancellationComment("cancelled") - .receivingStation(ReceivingStation.builder() - .id(1L) - .name("Саперно-Слобідська") + .paymentId("1") + .amount(20000L) + .currency("UAH") + .comment("avb") + .paymentStatus(PaymentStatus.PAID) + .build())) + .ubsUser(UBSuser.builder() + .firstName("oleh") + .lastName("ivanov") + .email("mail@mail.ua") + .id(1L) + .phoneNumber("067894522") + .orderAddress(OrderAddress.builder() + .id(1L) + .city("Lviv") + .street("Levaya") + .district("frankivskiy") + .entranceNumber("5") + .addressComment("near mall") + .houseCorpus("1") + .houseNumber("4") + .coordinates(Coordinates.builder() + .latitude(49.83) + .longitude(23.88) .build()) - .cancellationReason(CancellationReason.OUT_OF_CITY) - .imageReasonNotTakingBags(List.of("foto")) - .orderPaymentStatus(OrderPaymentStatus.UNPAID) - .additionalOrders(new HashSet<>(Arrays.asList("1111111111", "2222222222"))) - .events(new ArrayList<>()) - .build(); + .build()) + .build()) + .user(User.builder() + .id(1L) + .recipientName("Yuriy") + .recipientSurname("Gerasum") + .uuid("UUID") + .build()) + .certificates(Collections.emptySet()) + .pointsToUse(700) + .adminComment("Admin") + .cancellationComment("cancelled") + .receivingStation(ReceivingStation.builder() + .id(1L) + .name("Саперно-Слобідська") + .build()) + .cancellationReason(CancellationReason.OUT_OF_CITY) + .imageReasonNotTakingBags(List.of("foto")) + .orderPaymentStatus(OrderPaymentStatus.UNPAID) + .additionalOrders(new HashSet<>(Arrays.asList("1111111111", "2222222222"))) + .events(new ArrayList<>()) + .build(); } public static Order getOrderWithTariffAndLocation() { return Order.builder() + .id(1L) + .payment(Lists.newArrayList(Payment.builder() .id(1L) - .payment(Lists.newArrayList(Payment.builder() - .id(1L) - .paymentId("1") - .amount(20000L) - .currency("UAH") - .comment("avb") - .paymentStatus(PaymentStatus.PAID) - .build())) - .ubsUser(UBSuser.builder() - .firstName("oleh") - .lastName("ivanov") - .email("mail@mail.ua") - .id(1L) - .phoneNumber("067894522") - .orderAddress(OrderAddress.builder() - .id(1L) - .city("Lviv") - .street("Levaya") - .district("frankivskiy") - .entranceNumber("5") - .addressComment("near mall") - .houseCorpus("1") - .houseNumber("4") - .location(getLocation()) - .coordinates(Coordinates.builder() - .latitude(49.83) - .longitude(23.88) - .build()) - .build()) - .build()) - .tariffsInfo(getTariffInfo()) - .user(User.builder() - .id(1L) - .recipientName("Yuriy") - .recipientSurname("Gerasum") - .uuid("UUID") - .build()) - .certificates(Collections.emptySet()) - .pointsToUse(700) - .adminComment("Admin") - .cancellationComment("cancelled") - .receivingStation(ReceivingStation.builder() - .id(1L) - .name("Саперно-Слобідська") + .paymentId("1") + .amount(20000L) + .currency("UAH") + .comment("avb") + .paymentStatus(PaymentStatus.PAID) + .build())) + .ubsUser(UBSuser.builder() + .firstName("oleh") + .lastName("ivanov") + .email("mail@mail.ua") + .id(1L) + .phoneNumber("067894522") + .orderAddress(OrderAddress.builder() + .id(1L) + .city("Lviv") + .street("Levaya") + .district("frankivskiy") + .entranceNumber("5") + .addressComment("near mall") + .houseCorpus("1") + .houseNumber("4") + .location(getLocation()) + .coordinates(Coordinates.builder() + .latitude(49.83) + .longitude(23.88) .build()) - .cancellationReason(CancellationReason.OUT_OF_CITY) - .imageReasonNotTakingBags(List.of("foto")) - .orderPaymentStatus(OrderPaymentStatus.UNPAID) - .additionalOrders(new HashSet<>(Arrays.asList("1111111111", "2222222222"))) - .build(); + .build()) + .build()) + .tariffsInfo(getTariffInfo()) + .user(User.builder() + .id(1L) + .recipientName("Yuriy") + .recipientSurname("Gerasum") + .uuid("UUID") + .build()) + .certificates(Collections.emptySet()) + .pointsToUse(700) + .adminComment("Admin") + .cancellationComment("cancelled") + .receivingStation(ReceivingStation.builder() + .id(1L) + .name("Саперно-Слобідська") + .build()) + .cancellationReason(CancellationReason.OUT_OF_CITY) + .imageReasonNotTakingBags(List.of("foto")) + .orderPaymentStatus(OrderPaymentStatus.UNPAID) + .additionalOrders(new HashSet<>(Arrays.asList("1111111111", "2222222222"))) + .build(); } public static Order getOrderWithoutAddress() { return Order.builder() + .id(1L) + .counterOrderPaymentId(0L) + .ubsUser(UBSuser.builder() + .firstName("oleh") + .lastName("ivanov") + .email("mail@mail.ua") .id(1L) - .counterOrderPaymentId(0L) - .ubsUser(UBSuser.builder() - .firstName("oleh") - .lastName("ivanov") - .email("mail@mail.ua") - .id(1L) - .phoneNumber("067894522") - .build()) - .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").build()) - .build(); + .phoneNumber("067894522") + .build()) + .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").build()) + .build(); } public static Order getOrderExportDetails() { return Order.builder() + .id(1L) + .deliverFrom(LocalDateTime.of(1997, 12, 4, 15, 40, 24)) + .dateOfExport(LocalDate.of(1997, 12, 4)) + .deliverTo(LocalDateTime.of(1990, 12, 11, 19, 30, 30)) + .receivingStation(ReceivingStation.builder() .id(1L) - .deliverFrom(LocalDateTime.of(1997, 12, 4, 15, 40, 24)) - .dateOfExport(LocalDate.of(1997, 12, 4)) - .deliverTo(LocalDateTime.of(1990, 12, 11, 19, 30, 30)) - .receivingStation(ReceivingStation.builder() - .id(1L) - .name("Саперно-Слобідська") - .build()) - .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").build()) - .build(); + .name("Саперно-Слобідська") + .build()) + .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").build()) + .build(); } public static Order getOrderExportDetailsWithNullValues() { return Order.builder() - .id(1L) - .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").build()) - .build(); + .id(1L) + .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").build()) + .build(); } public static Order getOrderWithoutPayment() { return Order.builder() - .id(1L) - .payment(Collections.emptyList()) - .certificates(Collections.emptySet()) - .pointsToUse(500) - .build(); + .id(1L) + .payment(Collections.emptyList()) + .certificates(Collections.emptySet()) + .pointsToUse(500) + .build(); } public static OrderDto getOrderDto() { return OrderDto.builder() - .firstName("oleh") - .lastName("ivanov") - .address("frankivskiy Levaya 4") - .addressComment("near mall") - .phoneNumber("067894522") - .latitude(49.83) - .longitude(23.88) - .build(); + .firstName("oleh") + .lastName("ivanov") + .address("frankivskiy Levaya 4") + .addressComment("near mall") + .phoneNumber("067894522") + .latitude(49.83) + .longitude(23.88) + .build(); } public static Coordinates getCoordinates() { return Coordinates.builder() - .latitude(49.83) - .longitude(23.88) - .build(); + .latitude(49.83) + .longitude(23.88) + .build(); } public static CoordinatesDto getCoordinatesDto() { return CoordinatesDto.builder() - .latitude(49.83) - .longitude(23.88) - .build(); + .latitude(49.83) + .longitude(23.88) + .build(); } public static ExportDetailsDto getExportDetails() { return ExportDetailsDto.builder() - .dateExport("1997-12-04T15:40:24") - .timeDeliveryFrom("1997-12-04T15:40:24") - .timeDeliveryTo("1990-12-11T19:30:30") - .receivingStationId(1L) - .allReceivingStations(List.of(getReceivingStationDto(), getReceivingStationDto())) - .build(); + .dateExport("1997-12-04T15:40:24") + .timeDeliveryFrom("1997-12-04T15:40:24") + .timeDeliveryTo("1990-12-11T19:30:30") + .receivingStationId(1L) + .allReceivingStations(List.of(getReceivingStationDto(), getReceivingStationDto())) + .build(); } public static ExportDetailsDtoUpdate getExportDetailsRequestToday() { return ExportDetailsDtoUpdate.builder() - .dateExport(String.valueOf(LocalDate.now())) - .timeDeliveryFrom(String.valueOf(LocalDateTime.now())) - .timeDeliveryTo(String.valueOf(LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT))) - .receivingStationId(1L) - .build(); + .dateExport(String.valueOf(LocalDate.now())) + .timeDeliveryFrom(String.valueOf(LocalDateTime.now())) + .timeDeliveryTo(String.valueOf(LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT))) + .receivingStationId(1L) + .build(); } public static ExportDetailsDtoUpdate getExportDetailsRequest() { return ExportDetailsDtoUpdate.builder() - .dateExport("1997-12-04T15:40:24") - .timeDeliveryFrom("1997-12-04T15:40:24") - .timeDeliveryTo("1990-12-11T19:30:30") - .receivingStationId(1L) - .build(); + .dateExport("1997-12-04T15:40:24") + .timeDeliveryFrom("1997-12-04T15:40:24") + .timeDeliveryTo("1990-12-11T19:30:30") + .receivingStationId(1L) + .build(); } public static Set getCoordinatesSet() { Set set = new HashSet<>(); set.add(Coordinates.builder() - .latitude(49.894) - .longitude(24.107) - .build()); + .latitude(49.894) + .longitude(24.107) + .build()); set.add(Coordinates.builder() - .latitude(49.771) - .longitude(23.909) - .build()); + .latitude(49.771) + .longitude(23.909) + .build()); set.add(Coordinates.builder() - .latitude(49.801) - .longitude(24.164) - .build()); + .latitude(49.801) + .longitude(24.164) + .build()); set.add(Coordinates.builder() - .latitude(49.854) - .longitude(24.069) - .build()); + .latitude(49.854) + .longitude(24.069) + .build()); set.add(Coordinates.builder() - .latitude(49.796) - .longitude(24.931) - .build()); + .latitude(49.796) + .longitude(24.931) + .build()); set.add(Coordinates.builder() - .latitude(49.812) - .longitude(24.035) - .build()); + .latitude(49.812) + .longitude(24.035) + .build()); set.add(Coordinates.builder() - .latitude(49.871) - .longitude(24.029) - .build()); + .latitude(49.871) + .longitude(24.029) + .build()); set.add(Coordinates.builder() - .latitude(49.666) - .longitude(24.013) - .build()); + .latitude(49.666) + .longitude(24.013) + .build()); set.add(Coordinates.builder() - .latitude(49.795) - .longitude(24.052) - .build()); + .latitude(49.795) + .longitude(24.052) + .build()); set.add(Coordinates.builder() - .latitude(49.856) - .longitude(24.049) - .build()); + .latitude(49.856) + .longitude(24.049) + .build()); set.add(Coordinates.builder() - .latitude(49.862) - .longitude(24.039) - .build()); + .latitude(49.862) + .longitude(24.039) + .build()); return set; } @@ -761,14 +761,14 @@ public static List getOrdersToGroupThem() { long userId = 10L; for (Coordinates coordinates : getCoordinatesSet()) { orders.add(Order.builder() - .id(++id) - .ubsUser(UBSuser.builder() - .id(++userId) - .orderAddress(OrderAddress.builder() - .coordinates(coordinates) - .build()) - .build()) - .build()); + .id(++id) + .ubsUser(UBSuser.builder() + .id(++userId) + .orderAddress(OrderAddress.builder() + .coordinates(coordinates) + .build()) + .build()) + .build()); } return orders; } @@ -776,422 +776,442 @@ public static List getOrdersToGroupThem() { public static List getGroupedOrders() { List list = new ArrayList<>(); list.add(GroupedOrderDto.builder() - .amountOfLitres(75) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.854) - .longitude(24.069) - .build(), - OrderDto.builder() - .latitude(49.856) - .longitude(24.049) - .build(), - OrderDto.builder() - .latitude(49.862) - .longitude(24.039) - .build())) - .build()); + .amountOfLitres(75) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.854) + .longitude(24.069) + .build(), + OrderDto.builder() + .latitude(49.856) + .longitude(24.049) + .build(), + OrderDto.builder() + .latitude(49.862) + .longitude(24.039) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.812) - .longitude(24.035) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.812) + .longitude(24.035) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.795) - .longitude(24.052) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.795) + .longitude(24.052) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.796) - .longitude(24.931) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.796) + .longitude(24.931) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.871) - .longitude(24.029) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.871) + .longitude(24.029) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.894) - .longitude(24.107) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.894) + .longitude(24.107) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.666) - .longitude(24.013) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.666) + .longitude(24.013) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.771) - .longitude(23.909) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.771) + .longitude(23.909) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.801) - .longitude(24.164) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.801) + .longitude(24.164) + .build())) + .build()); return list; } public static List getGroupedOrdersWithLiters() { List list = new ArrayList<>(); list.add(GroupedOrderDto.builder() - .amountOfLitres(75) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.854) - .longitude(24.069) - .build())) - .build()); + .amountOfLitres(75) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.854) + .longitude(24.069) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.812) - .longitude(24.035) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.812) + .longitude(24.035) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.795) - .longitude(24.052) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.795) + .longitude(24.052) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.796) - .longitude(24.931) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.796) + .longitude(24.931) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.871) - .longitude(24.029) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.871) + .longitude(24.029) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.894) - .longitude(24.107) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.894) + .longitude(24.107) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.666) - .longitude(24.013) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.666) + .longitude(24.013) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.856) - .longitude(24.049) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.856) + .longitude(24.049) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.862) - .longitude(24.039) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.862) + .longitude(24.039) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.771) - .longitude(23.909) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.771) + .longitude(23.909) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.801) - .longitude(24.164) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.801) + .longitude(24.164) + .build())) + .build()); return list; } public static List getGroupedOrdersFor60LitresLimit() { List list = new ArrayList<>(); list.add(GroupedOrderDto.builder() - .amountOfLitres(50) - .groupOfOrders(List.of( - OrderDto.builder() - .latitude(49.856) - .longitude(24.049) - .build(), - OrderDto.builder() - .latitude(49.862) - .longitude(24.039) - .build())) - .build()); + .amountOfLitres(50) + .groupOfOrders(List.of( + OrderDto.builder() + .latitude(49.856) + .longitude(24.049) + .build(), + OrderDto.builder() + .latitude(49.862) + .longitude(24.039) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.854) - .longitude(24.069) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.854) + .longitude(24.069) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.812) - .longitude(24.035) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.812) + .longitude(24.035) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.795) - .longitude(24.052) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.795) + .longitude(24.052) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.796) - .longitude(24.931) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.796) + .longitude(24.931) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.871) - .longitude(24.029) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.871) + .longitude(24.029) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.894) - .longitude(24.107) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.894) + .longitude(24.107) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.666) - .longitude(24.013) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.666) + .longitude(24.013) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.771) - .longitude(23.909) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.771) + .longitude(23.909) + .build())) + .build()); list.add(GroupedOrderDto.builder() - .amountOfLitres(25) - .groupOfOrders(List.of(OrderDto.builder() - .latitude(49.801) - .longitude(24.164) - .build())) - .build()); + .amountOfLitres(25) + .groupOfOrders(List.of(OrderDto.builder() + .latitude(49.801) + .longitude(24.164) + .build())) + .build()); return list; } public static CertificateDtoForSearching getCertificateDtoForSearching() { return CertificateDtoForSearching.builder() - .code("1111-1234") - .certificateStatus(CertificateStatus.ACTIVE) - .points(10) - .expirationDate(LocalDate.now().plusMonths(1)) - .creationDate(LocalDate.now()) - .orderId(1L) - .build(); + .code("1111-1234") + .certificateStatus(CertificateStatus.ACTIVE) + .points(10) + .expirationDate(LocalDate.now().plusMonths(1)) + .creationDate(LocalDate.now()) + .orderId(1L) + .build(); } public static CertificateDtoForAdding getCertificateDtoForAdding() { return CertificateDtoForAdding.builder() - .code("1111-1234") - .monthCount(0) - .initialPointsValue(10) - .points(0) - .build(); + .code("1111-1234") + .monthCount(0) + .initialPointsValue(10) + .points(0) + .build(); } public static Certificate getCertificate() { return Certificate.builder() - .code("1111-1234") - .certificateStatus(CertificateStatus.ACTIVE) - .points(10) - .expirationDate(LocalDate.now().plusMonths(1)) - .creationDate(LocalDate.now()) - .order(null) - .build(); + .code("1111-1234") + .certificateStatus(CertificateStatus.ACTIVE) + .points(10) + .expirationDate(LocalDate.now().plusMonths(1)) + .creationDate(LocalDate.now()) + .order(null) + .build(); } public static Certificate getCertificate2() { return Certificate.builder() - .code("1111-1234") - .certificateStatus(CertificateStatus.ACTIVE) - .points(600) - .expirationDate(LocalDate.now().plusMonths(1)) - .creationDate(LocalDate.now()) - .order(null) - .build(); + .code("1111-1234") + .certificateStatus(CertificateStatus.ACTIVE) + .points(600) + .expirationDate(LocalDate.now().plusMonths(1)) + .creationDate(LocalDate.now()) + .order(null) + .build(); } public static AddingViolationsToUserDto getAddingViolationsToUserDto() { return AddingViolationsToUserDto.builder() - .orderID(1L) - .violationDescription("String string string") - .violationLevel("low") - .build(); + .orderID(1L) + .violationDescription("String string string") + .violationLevel("low") + .build(); } public static UpdateViolationToUserDto getUpdateViolationToUserDto() { List listImages = new ArrayList<>(); listImages.add(""); return UpdateViolationToUserDto.builder() - .orderID(1L) - .violationDescription("String1 string1 string1") - .violationLevel("low") - .imagesToDelete(listImages) - .build(); + .orderID(1L) + .violationDescription("String1 string1 string1") + .violationLevel("low") + .imagesToDelete(listImages) + .build(); } public static OrderClientDto getOrderClientDto() { return OrderClientDto.builder() - .id(1L) - .orderStatus(OrderStatus.DONE) - .amount(350L) - .build(); + .id(1L) + .orderStatus(OrderStatus.DONE) + .amount(350L) + .build(); } public static Order getOrderDoneByUser() { return Order.builder() + .id(1L) + .orderStatus(OrderStatus.CONFIRMED) + .payment(singletonList(Payment.builder() .id(1L) - .orderStatus(OrderStatus.CONFIRMED) - .payment(singletonList(Payment.builder() - .id(1L) - .amount(350L) - .build())) - .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) - .amountOfBagsOrdered(Collections.singletonMap(1, 2)) - .build(); + .amount(350L) + .build())) + .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) + .amountOfBagsOrdered(Collections.singletonMap(1, 2)) + .build(); } public static AddEmployeeDto getAddEmployeeDto() { return AddEmployeeDto.builder() + .firstName("Петро") + .lastName("Петренко") + .phoneNumber("+380935577455") + .email("test@gmail.com") + .employeePositions(List.of(PositionDto.builder() + .id(1L) + .name("Водій") + .nameEn("Driver") + .build())) + .receivingStations(List.of(ReceivingStationDto.builder() + .id(1L) + .name("Петрівка") + .build())) + .build(); + } + + public static EmployeeWithTariffsDto getEmployeeWithTariffsDto() { + return EmployeeWithTariffsDto.builder() + .employeeDto(EmployeeDto.builder() + .id(1L) .firstName("Петро") .lastName("Петренко") .phoneNumber("+380935577455") .email("test@gmail.com") + .image("path") .employeePositions(List.of(PositionDto.builder() - .id(1L) - .name("Водій") - .nameEn("Driver") - .build())) - .receivingStations(List.of(ReceivingStationDto.builder() - .id(1L) - .name("Петрівка") - .build())) - .build(); - } - - public static EmployeeWithTariffsDto getEmployeeWithTariffsDto() { - return EmployeeWithTariffsDto.builder() - .employeeDto(EmployeeDto.builder() - .id(1L) - .firstName("Петро") - .lastName("Петренко") - .phoneNumber("+380935577455") - .email("test@gmail.com") - .image("path") - .employeePositions(List.of(PositionDto.builder() - .id(1L) - .name("Водій") - .nameEn("Driver") - .build())) - .build()) - .tariffs(List.of(getTariffInfoForEmployeeDto())) - .build(); + .id(1L) + .name("Водій") + .nameEn("Driver") + .build())) + .build()) + .tariffs(List.of(getTariffInfoForEmployeeDto())) + .build(); } public static GetTariffInfoForEmployeeDto getTariffInfoForEmployeeDto() { return GetTariffInfoForEmployeeDto - .builder() - .id(1L) - .region(RegionDto.builder() - .regionId(1L) - .nameEn("Kyiv region") - .nameUk("Київська область") - .build()) - .locationsDtos(List.of(getLocationsDtos(1L))) - .receivingStationDtos(List.of(getGetReceivingStationDto())) - .courier(getCourierTranslationDto(1L)) - .build(); + .builder() + .id(1L) + .region(RegionDto.builder() + .regionId(1L) + .nameEn("Kyiv region") + .nameUk("Київська область") + .build()) + .locationsDtos(List.of(getLocationsDtos(1L))) + .receivingStationDtos(List.of(getGetReceivingStationDto())) + .courier(getCourierTranslationDto(1L)) + .build(); } public static LocationsDtos getLocationsDtos(Long id) { return LocationsDtos.builder() - .locationId(id) - .nameUk("Київ") - .nameEn("Kyiv") - .build(); + .locationId(id) + .nameUk("Київ") + .nameEn("Kyiv") + .build(); } public static GetReceivingStationDto getGetReceivingStationDto() { return GetReceivingStationDto - .builder() - .stationId(1L) - .name("Петрівка") - .build(); + .builder() + .stationId(1L) + .name("Петрівка") + .build(); } public static Employee getEmployee() { return Employee.builder() + .id(1L) + .firstName("Петро") + .lastName("Петренко") + .phoneNumber("+380935577455") + .email("test@gmail.com") + .uuid("Test") + .employeeStatus(EmployeeStatus.ACTIVE) + .employeePosition(Set.of(Position.builder() .id(1L) - .firstName("Петро") - .lastName("Петренко") - .phoneNumber("+380935577455") - .email("test@gmail.com") - .uuid("Test") - .employeeStatus(EmployeeStatus.ACTIVE) - .employeePosition(Set.of(Position.builder() - .id(1L) - .name("Водій") - .nameEn("Driver") - .build())) - .tariffInfos(Set.of(TariffsInfo.builder() - .id(1L) - .service(new Service()) - .build())) - .imagePath("path") - .build(); + .name("Водій") + .nameEn("Driver") + .build())) + .tariffInfos(Set.of(TariffsInfo.builder() + .id(1L) + .service(new Service()) + .build())) + .imagePath("path") + .build(); } public static Employee getEmployeeWithTariffs() { return Employee.builder() + .id(1L) + .firstName("Петро") + .lastName("Петренко") + .phoneNumber("+380935577455") + .email("test@gmail.com") + .employeeStatus(EmployeeStatus.ACTIVE) + .employeePosition(Set.of(Position.builder() + .id(1L) + .name("Водій") + .nameEn("Driver") + .build())) + .tariffInfos(Set.of(getTariffsInfo())) + .imagePath("path") + .tariffs(List.of(getTariffInfo())) + .build(); + } + + public static List getEmployeeList() { + return List.of( + Employee.builder() .id(1L) .firstName("Петро") .lastName("Петренко") @@ -1199,142 +1219,103 @@ public static Employee getEmployeeWithTariffs() { .email("test@gmail.com") .employeeStatus(EmployeeStatus.ACTIVE) .employeePosition(Set.of(Position.builder() - .id(1L) - .name("Водій") - .nameEn("Driver") - .build())) - .tariffInfos(Set.of(getTariffsInfo())) + .id(6L) + .name("Супер адмін") + .nameEn("Super admin") + .build())) + .tariffInfos(new HashSet<>()) .imagePath("path") .tariffs(List.of(getTariffInfo())) - .build(); - } - - public static List getEmployeeList() { - return List.of( - Employee.builder() - .id(1L) - .firstName("Петро") - .lastName("Петренко") - .phoneNumber("+380935577455") - .email("test@gmail.com") - .employeeStatus(EmployeeStatus.ACTIVE) - .employeePosition(Set.of(Position.builder() - .id(6L) - .name("Супер адмін") - .nameEn("Super admin") - .build())) - .tariffInfos(new HashSet<>()) - .imagePath("path") - .tariffs(List.of(getTariffInfo())) - .build()); + .build()); } public static Employee getEmployeeForUpdateEmailCheck() { return Employee.builder() + .id(1L) + .firstName("Петро") + .lastName("Петренко") + .phoneNumber("+380935577455") + .email("test1@gmail.com") + .employeeStatus(EmployeeStatus.ACTIVE) + .employeePosition(Set.of(Position.builder() .id(1L) - .firstName("Петро") - .lastName("Петренко") - .phoneNumber("+380935577455") - .email("test1@gmail.com") - .employeeStatus(EmployeeStatus.ACTIVE) - .employeePosition(Set.of(Position.builder() - .id(1L) - .name("Водій") - .nameEn("Driver") - .build())) - .tariffInfos(Set.of(TariffsInfo.builder() - .id(1L) - .service(new Service()) - .build())) - .imagePath("path") - .build(); + .name("Водій") + .nameEn("Driver") + .build())) + .tariffInfos(Set.of(TariffsInfo.builder() + .id(1L) + .service(new Service()) + .build())) + .imagePath("path") + .build(); } public static Employee getFullEmployee() { return Employee.builder() + .id(1L) + .firstName("Петро") + .lastName("Петренко") + .phoneNumber("+380935577455") + .email("test@gmail.com") + .imagePath("path") + .employeeStatus(EmployeeStatus.ACTIVE) + .employeePosition(Set.of(Position.builder() .id(1L) - .firstName("Петро") - .lastName("Петренко") - .phoneNumber("+380935577455") - .email("test@gmail.com") - .imagePath("path") - .employeeStatus(EmployeeStatus.ACTIVE) - .employeePosition(Set.of(Position.builder() - .id(1L) - .name("Водій") - .nameEn("Driver") - .build())) - .tariffInfos(Set.of(TariffsInfo.builder() - .id(1L) - .service(getService()) - .courier(getCourier()) - .tariffLocations(Set.of(getTariffLocation())) - .receivingStationList(Set.of(getReceivingStation())) - .build())) - .tariffs(List.of(TariffsInfo.builder() - .id(1L) - .service(getService()) - .courier(getCourier()) - .tariffLocations(Set.of(getTariffLocation())) - .build())) - .build(); + .name("Водій") + .nameEn("Driver") + .build())) + .tariffInfos(Set.of(TariffsInfo.builder() + .id(1L) + .service(getService()) + .courier(getCourier()) + .tariffLocations(Set.of(getTariffLocation())) + .receivingStationList(Set.of(getReceivingStation())) + .build())) + .tariffs(List.of(TariffsInfo.builder() + .id(1L) + .service(getService()) + .courier(getCourier()) + .tariffLocations(Set.of(getTariffLocation())) + .build())) + .build(); } public static TariffLocation getTariffLocation() { return TariffLocation - .builder() - .id(1L) - .tariffsInfo(getTariffsInfo()) - .location(getLocation()) - .locationStatus(LocationStatus.ACTIVE) - .build(); + .builder() + .id(1L) + .tariffsInfo(getTariffsInfo()) + .location(getLocation()) + .locationStatus(LocationStatus.ACTIVE) + .build(); } public static TariffLocation getTariffLocation2() { return TariffLocation - .builder() - .id(1L) - .tariffsInfo( - TariffsInfo.builder() - .id(2L) - .build()) - .location(getLocation()) - .locationStatus(LocationStatus.ACTIVE) - .build(); + .builder() + .id(1L) + .tariffsInfo( + TariffsInfo.builder() + .id(2L) + .build()) + .location(getLocation()) + .locationStatus(LocationStatus.ACTIVE) + .build(); } public static List getTariffLocationList() { return List.of(getTariffLocation(), - TariffLocation - .builder() - .id(2L) - .locationStatus(LocationStatus.ACTIVE) - .build()); + TariffLocation + .builder() + .id(2L) + .locationStatus(LocationStatus.ACTIVE) + .build()); } public static EmployeeWithTariffsIdDto getEmployeeWithTariffsIdDto() { return EmployeeWithTariffsIdDto - .builder() - .employeeDto(EmployeeDto.builder() - .id(1L) - .firstName("Петро") - .lastName("Петренко") - .phoneNumber("+380935577455") - .email("test@gmail.com") - .image("path") - .employeePositions(List.of(PositionDto.builder() - .id(1L) - .name("Водій") - .nameEn("Driver") - .build())) - .build()) - .tariffId(List.of(1L)) - .build(); - } - - public static GetEmployeeDto getGetEmployeeDto() { - return GetEmployeeDto - .builder() + .builder() + .employeeDto(EmployeeDto.builder() .id(1L) .firstName("Петро") .lastName("Петренко") @@ -1342,466 +1323,485 @@ public static GetEmployeeDto getGetEmployeeDto() { .email("test@gmail.com") .image("path") .employeePositions(List.of(PositionDto.builder() - .id(1L) - .name("Водій") - .nameEn("Driver") - .build())) - .tariffs(List.of(GetTariffInfoForEmployeeDto.builder() - .id(1L) - .region(getRegionDto(1L)) - .locationsDtos(List.of(LocationsDtos - .builder() - .locationId(1L) - .nameEn("Kyiv") - .nameUk("Київ") - .build())) - .receivingStationDtos(List.of(GetReceivingStationDto - .builder() - .stationId(1L) - .name("Петрівка") - .build())) - .courier(CourierTranslationDto.builder() - .id(1L) - .nameUk("Тест") - .nameEn("Test") - .build()) - .build())) - .build(); + .id(1L) + .name("Водій") + .nameEn("Driver") + .build())) + .build()) + .tariffId(List.of(1L)) + .build(); + } + + public static GetEmployeeDto getGetEmployeeDto() { + return GetEmployeeDto + .builder() + .id(1L) + .firstName("Петро") + .lastName("Петренко") + .phoneNumber("+380935577455") + .email("test@gmail.com") + .image("path") + .employeePositions(List.of(PositionDto.builder() + .id(1L) + .name("Водій") + .nameEn("Driver") + .build())) + .tariffs(List.of(GetTariffInfoForEmployeeDto.builder() + .id(1L) + .region(getRegionDto(1L)) + .locationsDtos(List.of(LocationsDtos + .builder() + .locationId(1L) + .nameEn("Kyiv") + .nameUk("Київ") + .build())) + .receivingStationDtos(List.of(GetReceivingStationDto + .builder() + .stationId(1L) + .name("Петрівка") + .build())) + .courier(CourierTranslationDto.builder() + .id(1L) + .nameUk("Тест") + .nameEn("Test") + .build()) + .build())) + .build(); } private static RegionDto getRegionDto(Long id) { return RegionDto.builder() - .regionId(id) - .nameEn("Kyiv region") - .nameUk("Київська область") - .build(); + .regionId(id) + .nameEn("Kyiv region") + .nameUk("Київська область") + .build(); } public static UserInfoDto getUserInfoDto() { return UserInfoDto.builder() - .customerName("Alan") - .customerSurName("Maym") - .customerPhoneNumber("091546745") - .customerEmail("wayn@email.com") - .recipientName("Anatolii") - .recipientSurName("Petyrov") - .recipientPhoneNumber("095123456") - .recipientEmail("anatolii.andr@gmail.com") - .totalUserViolations(4) - .userViolationForCurrentOrder(1) - .build(); + .customerName("Alan") + .customerSurName("Maym") + .customerPhoneNumber("091546745") + .customerEmail("wayn@email.com") + .recipientName("Anatolii") + .recipientSurName("Petyrov") + .recipientPhoneNumber("095123456") + .recipientEmail("anatolii.andr@gmail.com") + .totalUserViolations(4) + .userViolationForCurrentOrder(1) + .build(); } public static Order getOrderDetails() { return Order.builder() + .id(1L) + .user(User.builder() .id(1L) - .user(User.builder() - .id(1L) - .recipientName("Alan") - .recipientSurname("Maym") - .recipientPhone("091546745") - .recipientEmail("wayn@email.com") - .violations(4).build()) - .ubsUser(UBSuser.builder() - .id(1L) - .firstName("Anatolii") - .lastName("Petyrov") - .phoneNumber("095123456") - .email("anatolii.andr@gmail.com") - .senderFirstName("Anatolii") - .senderLastName("Petyrov") - .senderPhoneNumber("095123456") - .senderEmail("anatolii.andr@gmail.com") - .build()) - .build(); + .recipientName("Alan") + .recipientSurname("Maym") + .recipientPhone("091546745") + .recipientEmail("wayn@email.com") + .violations(4).build()) + .ubsUser(UBSuser.builder() + .id(1L) + .firstName("Anatolii") + .lastName("Petyrov") + .phoneNumber("095123456") + .email("anatolii.andr@gmail.com") + .senderFirstName("Anatolii") + .senderLastName("Petyrov") + .senderPhoneNumber("095123456") + .senderEmail("anatolii.andr@gmail.com") + .build()) + .build(); } public static Order getOrderDetailsWithoutSender() { return Order.builder() + .id(1L) + .user(User.builder() .id(1L) - .user(User.builder() - .id(1L) - .recipientName("Alan") - .recipientSurname("Maym") - .recipientPhone("091546745") - .recipientEmail("wayn@email.com") - .violations(4).build()) - .ubsUser(UBSuser.builder() - .id(1L) - .firstName("Anatolii") - .lastName("Petyrov") - .phoneNumber("095123456") - .email("anatolii.andr@gmail.com") - .build()) - .build(); + .recipientName("Alan") + .recipientSurname("Maym") + .recipientPhone("091546745") + .recipientEmail("wayn@email.com") + .violations(4).build()) + .ubsUser(UBSuser.builder() + .id(1L) + .firstName("Anatolii") + .lastName("Petyrov") + .phoneNumber("095123456") + .email("anatolii.andr@gmail.com") + .build()) + .build(); } public static UbsCustomersDtoUpdate getUbsCustomersDtoUpdate() { return UbsCustomersDtoUpdate.builder() - .recipientId(1L) - .recipientName("Anatolii Petyrov") - .recipientEmail("anatolii.andr@gmail.com") - .recipientPhoneNumber("095123456").build(); + .recipientId(1L) + .recipientName("Anatolii Petyrov") + .recipientEmail("anatolii.andr@gmail.com") + .recipientPhoneNumber("095123456").build(); } public static List addressDtoList() { List list = new ArrayList<>(); list.add(AddressDto.builder() - .id(1L) - .entranceNumber("7a") - .houseCorpus("2") - .houseNumber("7") - .street("Gorodotska") - .coordinates(Coordinates.builder().latitude(2.3).longitude(5.6).build()) - .district("Zaliznuchnuy") - .city("Lviv") - .actual(false) - .placeId("place_id") - .build()); + .id(1L) + .entranceNumber("7a") + .houseCorpus("2") + .houseNumber("7") + .street("Gorodotska") + .coordinates(Coordinates.builder().latitude(2.3).longitude(5.6).build()) + .district("Zaliznuchnuy") + .city("Lviv") + .actual(false) + .placeId("place_id") + .build()); list.add(AddressDto.builder().id(2L) - .entranceNumber("9a") - .houseCorpus("2") - .houseNumber("7") - .street("Shevchenka") - .coordinates(Coordinates.builder().latitude(3.3).longitude(6.6).build()) - .district("Zaliznuchnuy") - .city("Lviv") - .actual(false) - .placeId("place_id") - .build()); + .entranceNumber("9a") + .houseCorpus("2") + .houseNumber("7") + .street("Shevchenka") + .coordinates(Coordinates.builder().latitude(3.3).longitude(6.6).build()) + .district("Zaliznuchnuy") + .city("Lviv") + .actual(false) + .placeId("place_id") + .build()); return list; } public static UserProfileDto userProfileDto() { return UserProfileDto.builder() - .recipientName("Dima") - .recipientSurname("Petrov") - .recipientPhone("0666051373") - .recipientEmail("petrov@gmail.com") - .telegramIsNotify(true) - .viberIsNotify(false) - .build(); + .recipientName("Dima") + .recipientSurname("Petrov") + .recipientPhone("0666051373") + .recipientEmail("petrov@gmail.com") + .telegramIsNotify(true) + .viberIsNotify(false) + .build(); } public static User getUserProfile() { return User.builder() - .recipientName("Dima") - .recipientSurname("Petrov") - .recipientPhone("0666051373") - .recipientEmail("petrov@gmail.com") - .telegramBot(getTelegramBotNotifyTrue()) - .build(); + .recipientName("Dima") + .recipientSurname("Petrov") + .recipientPhone("0666051373") + .recipientEmail("petrov@gmail.com") + .telegramBot(getTelegramBotNotifyTrue()) + .build(); } public static TelegramBot getTelegramBotNotifyTrue() { return TelegramBot.builder() - .id(1L) - .chatId(111111L) - .isNotify(true) - .build(); + .id(1L) + .chatId(111111L) + .isNotify(true) + .build(); } public static TelegramBot getTelegramBotNotifyFalse() { return TelegramBot.builder() - .id(1L) - .chatId(111111L) - .isNotify(false) - .build(); + .id(1L) + .chatId(111111L) + .isNotify(false) + .build(); } public static ViberBot getViberBotNotifyTrue() { return ViberBot.builder() - .id(1L) - .chatId("111111L") - .isNotify(true) - .build(); + .id(1L) + .chatId("111111L") + .isNotify(true) + .build(); } public static ViberBot getViberBotNotifyFalse() { return ViberBot.builder() - .id(1L) - .chatId("111111L") - .isNotify(false) - .build(); + .id(1L) + .chatId("111111L") + .isNotify(false) + .build(); } public static UserProfileUpdateDto getUserProfileUpdateDto() { User user = getUserWithBotNotifyTrue(); return UserProfileUpdateDto.builder().addressDto(addressDtoList()) - .recipientName(user.getRecipientName()).recipientSurname(user.getRecipientSurname()) - .recipientPhone(user.getRecipientPhone()) - .alternateEmail("test@email.com") - .telegramIsNotify(true) - .viberIsNotify(true) - .build(); + .recipientName(user.getRecipientName()).recipientSurname(user.getRecipientSurname()) + .recipientPhone(user.getRecipientPhone()) + .alternateEmail("test@email.com") + .telegramIsNotify(true) + .viberIsNotify(true) + .build(); } public static UserProfileUpdateDto getUserProfileUpdateDtoWithBotsIsNotifyFalse() { User user = getUserWithBotNotifyTrue(); return UserProfileUpdateDto.builder().addressDto(addressDtoList()) - .recipientName(user.getRecipientName()).recipientSurname(user.getRecipientSurname()) - .recipientPhone(user.getRecipientPhone()) - .alternateEmail("test@email.com") - .telegramIsNotify(false) - .viberIsNotify(false) - .build(); + .recipientName(user.getRecipientName()).recipientSurname(user.getRecipientSurname()) + .recipientPhone(user.getRecipientPhone()) + .alternateEmail("test@email.com") + .telegramIsNotify(false) + .viberIsNotify(false) + .build(); } public static PersonalDataDto getPersonalDataDto() { return PersonalDataDto.builder() - .id(1L) - .firstName("Max") - .lastName("B") - .phoneNumber("09443332") - .email("dsd@gmail.com") - .build(); + .id(1L) + .firstName("Max") + .lastName("B") + .phoneNumber("09443332") + .email("dsd@gmail.com") + .build(); } public static User getUserPersonalData() { return User.builder() - .id(1L) - .recipientName("Max") - .recipientSurname("B") - .recipientPhone("09443332") - .recipientEmail("dsd@gmail.com") - .build(); + .id(1L) + .recipientName("Max") + .recipientSurname("B") + .recipientPhone("09443332") + .recipientEmail("dsd@gmail.com") + .build(); } public static OptionForColumnDTO getOptionForColumnDTO() { return OptionForColumnDTO.builder() - .key("1") - .en("en") - .ua("en") - .build(); + .key("1") + .en("en") + .ua("en") + .build(); } public static ReceivingStationDto getOptionReceivingStationDto() { return ReceivingStationDto.builder() - .id(1L) - .name("en") - .build(); + .id(1L) + .name("en") + .build(); } public static List
addressList() { List
list = new ArrayList<>(); list.add(Address.builder() - .id(1L) - .entranceNumber("7a") - .houseCorpus("2") - .houseNumber("7") - .street("Gorodotska") - .coordinates(Coordinates.builder().latitude(2.3).longitude(5.6).build()) - .district("Zaliznuchnuy") - .city("Lviv") - .actual(false) - .build()); + .id(1L) + .entranceNumber("7a") + .houseCorpus("2") + .houseNumber("7") + .street("Gorodotska") + .coordinates(Coordinates.builder().latitude(2.3).longitude(5.6).build()) + .district("Zaliznuchnuy") + .city("Lviv") + .actual(false) + .build()); list.add(Address.builder().id(2L) - .entranceNumber("9a") - .houseCorpus("2") - .houseNumber("7") - .street("Shevchenka") - .coordinates(Coordinates.builder().latitude(3.3).longitude(6.6).build()) - .district("Zaliznuchnuy") - .city("Lviv") - .actual(false) - .build()); + .entranceNumber("9a") + .houseCorpus("2") + .houseNumber("7") + .street("Shevchenka") + .coordinates(Coordinates.builder().latitude(3.3).longitude(6.6).build()) + .district("Zaliznuchnuy") + .city("Lviv") + .actual(false) + .build()); return list; } public static AddressDto addressDto() { return AddressDto.builder() - .id(1L) - .entranceNumber("7a") - .houseCorpus("2") - .houseNumber("25") - .street("Street") - .coordinates(Coordinates.builder() - .latitude(50.4459068) - .longitude(30.4477005) - .build()) - .district("Distinct") - .city("City") - .actual(false) - .build(); + .id(1L) + .entranceNumber("7a") + .houseCorpus("2") + .houseNumber("25") + .street("Street") + .coordinates(Coordinates.builder() + .latitude(50.4459068) + .longitude(30.4477005) + .build()) + .district("Distinct") + .city("City") + .actual(false) + .build(); } public static Address getAddress() { return Address.builder() - .id(1L) - .region("Region") - .city("City") - .street("Street") - .district("Distinct") - .houseNumber("25") - .houseCorpus("2") - .entranceNumber("7a") - .addressComment("Address Comment") - .actual(false) - .addressStatus(AddressStatus.NEW) - .coordinates(Coordinates.builder() - .latitude(50.4459068) - .longitude(30.4477005) - .build()) - .regionEn("RegionEng") - .cityEn("CityEng") - .streetEn("StreetEng") - .districtEn("DistinctEng") - .build(); + .id(1L) + .region("Region") + .city("City") + .street("Street") + .district("Distinct") + .houseNumber("25") + .houseCorpus("2") + .entranceNumber("7a") + .addressComment("Address Comment") + .actual(false) + .addressStatus(AddressStatus.NEW) + .coordinates(Coordinates.builder() + .latitude(50.4459068) + .longitude(30.4477005) + .build()) + .regionEn("RegionEng") + .cityEn("CityEng") + .streetEn("StreetEng") + .districtEn("DistinctEng") + .build(); } public static Address getAddressTrue() { return Address.builder() - .id(1L) - .region("Region") - .city("City") - .street("Street") - .district("Distinct") - .houseNumber("25") - .houseCorpus("2") - .entranceNumber("7a") - .addressComment("Address Comment") - .actual(true) - .addressStatus(AddressStatus.NEW) - .coordinates(Coordinates.builder() - .latitude(50.4459068) - .longitude(30.4477005) - .build()) - .regionEn("RegionEng") - .cityEn("CityEng") - .streetEn("StreetEng") - .districtEn("DistinctEng") - .build(); + .id(1L) + .region("Region") + .city("City") + .street("Street") + .district("Distinct") + .houseNumber("25") + .houseCorpus("2") + .entranceNumber("7a") + .addressComment("Address Comment") + .actual(true) + .addressStatus(AddressStatus.NEW) + .coordinates(Coordinates.builder() + .latitude(50.4459068) + .longitude(30.4477005) + .build()) + .regionEn("RegionEng") + .cityEn("CityEng") + .streetEn("StreetEng") + .districtEn("DistinctEng") + .build(); } public static Address getAddress(long id) { return Address.builder() - .id(id) - .region("Вінницька") - .city("Вінниця") - .street("Street") - .district("Distinct") - .houseNumber("25") - .houseCorpus("2") - .entranceNumber("7a") - .addressComment("Address Comment") - .actual(false) - .addressStatus(AddressStatus.NEW) - .coordinates(Coordinates.builder() - .latitude(50.4459068) - .longitude(30.4477005) - .build()) - .regionEn("RegionEng") - .cityEn("CityEng") - .streetEn("StreetEng") - .districtEn("DistinctEng") - .build(); + .id(id) + .region("Вінницька") + .city("Вінниця") + .street("Street") + .district("Distinct") + .houseNumber("25") + .houseCorpus("2") + .entranceNumber("7a") + .addressComment("Address Comment") + .actual(false) + .addressStatus(AddressStatus.NEW) + .coordinates(Coordinates.builder() + .latitude(50.4459068) + .longitude(30.4477005) + .build()) + .regionEn("RegionEng") + .cityEn("CityEng") + .streetEn("StreetEng") + .districtEn("DistinctEng") + .build(); } public static LocationDto getLocationApiDto() { return LocationDto.builder() - .locationNameMap(Map.of("name", "Вінниця", "name_en", "Vinnytsa")) - .build(); + .locationNameMap(Map.of("name", "Вінниця", "name_en", "Vinnytsa")) + .build(); } public static List getLocationApiDtoList() { LocationDto locationDto1 = LocationDto.builder() - .locationNameMap(Map.of("name", "Вінниця", "name_en", "Vinnytsa")) - .build(); + .locationNameMap(Map.of("name", "Вінниця", "name_en", "Vinnytsa")) + .build(); return Arrays.asList(locationDto1); } public static DistrictDto getDistrictDto() { return DistrictDto.builder() - .nameUa("Вінниця") - .nameEn("Vinnytsa") - .build(); + .nameUa("Вінниця") + .nameEn("Vinnytsa") + .build(); } public static AddressDto getAddressDto(long id) { return AddressDto.builder() - .id(id) - .region("Вінницька") - .city("Вінниця") - .street("Street") - .district("Distinct") - .houseNumber("25") - .houseCorpus("2") - .entranceNumber("7a") - .addressComment("Address Comment") - .actual(false) - .coordinates(Coordinates.builder() - .latitude(50.4459068) - .longitude(30.4477005) - .build()) - .regionEn("RegionEng") - .cityEn("CityEng") - .streetEn("StreetEng") - .districtEn("DistinctEng") - .addressRegionDistrictList(Arrays.asList(getDistrictDto())) - .build(); + .id(id) + .region("Вінницька") + .city("Вінниця") + .street("Street") + .district("Distinct") + .houseNumber("25") + .houseCorpus("2") + .entranceNumber("7a") + .addressComment("Address Comment") + .actual(false) + .coordinates(Coordinates.builder() + .latitude(50.4459068) + .longitude(30.4477005) + .build()) + .regionEn("RegionEng") + .cityEn("CityEng") + .streetEn("StreetEng") + .districtEn("DistinctEng") + .addressRegionDistrictList(Arrays.asList(getDistrictDto())) + .build(); } public static OrderAddress getOrderAddress() { return OrderAddress.builder() - .region("Region") - .city("City") - .street("Street") - .district("Distinct") - .houseNumber("25") - .houseCorpus("2") - .entranceNumber("7a") - .addressComment("Address Comment") - .actual(false) - .addressStatus(AddressStatus.NEW) - .coordinates(Coordinates.builder() - .latitude(50.4459068) - .longitude(30.4477005) - .build()) - .regionEn("RegionEng") - .cityEn("CityEng") - .streetEn("StreetEng") - .districtEn("DistinctEng") - .build(); + .region("Region") + .city("City") + .street("Street") + .district("Distinct") + .houseNumber("25") + .houseCorpus("2") + .entranceNumber("7a") + .addressComment("Address Comment") + .actual(false) + .addressStatus(AddressStatus.NEW) + .coordinates(Coordinates.builder() + .latitude(50.4459068) + .longitude(30.4477005) + .build()) + .regionEn("RegionEng") + .cityEn("CityEng") + .streetEn("StreetEng") + .districtEn("DistinctEng") + .build(); } public static UbsCustomersDto getUbsCustomersDto() { return UbsCustomersDto.builder() - .name("Ivan Michalov") - .email("michalov@gmail.com") - .phoneNumber("095531111") - .build(); + .name("Ivan Michalov") + .email("michalov@gmail.com") + .phoneNumber("095531111") + .build(); } public static Position getPosition() { return Position.builder() - .id(1L) - .name("Водій") - .nameEn("Driver") - .build(); + .id(1L) + .name("Водій") + .nameEn("Driver") + .build(); } public static PositionDto getPositionDto(Long id) { return PositionDto.builder() - .id(id) - .name("Водій") - .nameEn("Driver") - .build(); + .id(id) + .name("Водій") + .nameEn("Driver") + .build(); } public static ReceivingStation getReceivingStation() { return ReceivingStation.builder() - .id(1L) - .name("Петрівка") - .createDate(LocalDate.EPOCH) - .createdBy(getEmployee()) - .build(); + .id(1L) + .name("Петрівка") + .createDate(LocalDate.EPOCH) + .createdBy(getEmployee()) + .build(); } public static ReceivingStationDto getReceivingStationDto() { return ReceivingStationDto.builder() - .id(1L) - .name("Петрівка") - .build(); + .id(1L) + .name("Петрівка") + .build(); } public static List getReceivingList() { @@ -1810,135 +1810,135 @@ public static List getReceivingList() { public static Violation getViolation() { LocalDateTime localdatetime = LocalDateTime.of( - 2021, Month.MARCH, - 16, 13, 00, 00); + 2021, Month.MARCH, + 16, 13, 00, 00); return Violation.builder() - .id(1L) - .order(Order.builder() - .id(1L).user(ModelUtils.getTestUser()).build()) - .violationLevel(MAJOR) - .description("violation1") - .violationDate(localdatetime) - .images(new LinkedList<>()) - .addedByUser(getTestUser()) - .build(); + .id(1L) + .order(Order.builder() + .id(1L).user(ModelUtils.getTestUser()).build()) + .violationLevel(MAJOR) + .description("violation1") + .violationDate(localdatetime) + .images(new LinkedList<>()) + .addedByUser(getTestUser()) + .build(); } public static Violation getViolation2() { LocalDateTime localdatetime = LocalDateTime.of( - 2021, Month.MARCH, - 16, 13, 00, 00); + 2021, Month.MARCH, + 16, 13, 00, 00); return Violation.builder() - .id(1L) - .order(Order.builder() - .id(1L).user(ModelUtils.getTestUser()).build()) - .violationLevel(MAJOR) - .description("violation1") - .violationDate(localdatetime) - .images(List.of("as", "s")) - .build(); + .id(1L) + .order(Order.builder() + .id(1L).user(ModelUtils.getTestUser()).build()) + .violationLevel(MAJOR) + .description("violation1") + .violationDate(localdatetime) + .images(List.of("as", "s")) + .build(); } public static ViolationDetailInfoDto getViolationDetailInfoDto() { LocalDateTime localdatetime = LocalDateTime.of( - 2021, Month.MARCH, - 16, 13, 00, 00); + 2021, Month.MARCH, + 16, 13, 00, 00); return ViolationDetailInfoDto.builder() - .orderId(1L) - .addedByUser("Alan Po") - .violationLevel(MAJOR) - .description("violation1") - .images(new ArrayList<>()) - .violationDate(localdatetime) - .build(); + .orderId(1L) + .addedByUser("Alan Po") + .violationLevel(MAJOR) + .description("violation1") + .images(new ArrayList<>()) + .violationDate(localdatetime) + .build(); } public static OrderPaymentDetailDto getOrderPaymentDetailDto() { return OrderPaymentDetailDto.builder() - .amount(95000L + 1000 + 70000) - .certificates(-1000) - .pointsToUse(-70000) - .amountToPay(95000L) - .currency("UAH") - .build(); + .amount(95000L + 1000 + 70000) + .certificates(-1000) + .pointsToUse(-70000) + .amountToPay(95000L) + .currency("UAH") + .build(); } public static Payment getPayment() { return Payment.builder() - .id(1L) - .paymentStatus(PaymentStatus.PAID) - .amount(95000L) - .currency("UAH") - .orderStatus("approved") - .responseStatus("approved") - .order(getOrder()) - .paymentId("1") - .settlementDate(LocalDate.now().toString()) - .fee(0L) - .build(); + .id(1L) + .paymentStatus(PaymentStatus.PAID) + .amount(95000L) + .currency("UAH") + .orderStatus("approved") + .responseStatus("approved") + .order(getOrder()) + .paymentId("1") + .settlementDate(LocalDate.now().toString()) + .fee(0L) + .build(); } public static User getUser() { return User.builder() - .id(1L) - .addresses(singletonList(getAddress())) - .recipientEmail("someUser@gmail.com") - .recipientPhone("962473289") - .recipientSurname("Ivanov") - .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") - .recipientName("Taras") - .uuid("uuid") - .ubsUsers(getUbsUsers()) - .currentPoints(100) - .build(); + .id(1L) + .addresses(singletonList(getAddress())) + .recipientEmail("someUser@gmail.com") + .recipientPhone("962473289") + .recipientSurname("Ivanov") + .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") + .recipientName("Taras") + .uuid("uuid") + .ubsUsers(getUbsUsers()) + .currentPoints(100) + .build(); } public static User getUserWithBotNotifyTrue_AddressTrue() { return User.builder() - .id(1L) - .addresses(singletonList(getAddressTrue())) - .recipientEmail("someUser@gmail.com") - .recipientPhone("962473289") - .recipientSurname("Ivanov") - .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") - .recipientName("Taras") - .uuid("uuid") - .ubsUsers(getUbsUsers()) - .currentPoints(100) - .telegramBot(getTelegramBotNotifyTrue()) - .build(); + .id(1L) + .addresses(singletonList(getAddressTrue())) + .recipientEmail("someUser@gmail.com") + .recipientPhone("962473289") + .recipientSurname("Ivanov") + .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") + .recipientName("Taras") + .uuid("uuid") + .ubsUsers(getUbsUsers()) + .currentPoints(100) + .telegramBot(getTelegramBotNotifyTrue()) + .build(); } public static User getUserWithBotNotifyTrue() { return User.builder() - .id(1L) - .addresses(singletonList(getAddress())) - .recipientEmail("someUser@gmail.com") - .recipientPhone("962473289") - .recipientSurname("Ivanov") - .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") - .recipientName("Taras") - .uuid("uuid") - .ubsUsers(getUbsUsers()) - .currentPoints(100) - .telegramBot(getTelegramBotNotifyTrue()) - .build(); + .id(1L) + .addresses(singletonList(getAddress())) + .recipientEmail("someUser@gmail.com") + .recipientPhone("962473289") + .recipientSurname("Ivanov") + .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") + .recipientName("Taras") + .uuid("uuid") + .ubsUsers(getUbsUsers()) + .currentPoints(100) + .telegramBot(getTelegramBotNotifyTrue()) + .build(); } public static User getUserWithBotNotifyFalse() { return User.builder() - .id(1L) - .addresses(singletonList(getAddress())) - .recipientEmail("someUser@gmail.com") - .recipientPhone("962473289") - .recipientSurname("Ivanov") - .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") - .recipientName("Taras") - .uuid("uuid") - .ubsUsers(getUbsUsers()) - .currentPoints(100) - .telegramBot(getTelegramBotNotifyFalse()) - .build(); + .id(1L) + .addresses(singletonList(getAddress())) + .recipientEmail("someUser@gmail.com") + .recipientPhone("962473289") + .recipientSurname("Ivanov") + .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") + .recipientName("Taras") + .uuid("uuid") + .ubsUsers(getUbsUsers()) + .currentPoints(100) + .telegramBot(getTelegramBotNotifyFalse()) + .build(); } public static Set getUbsUsers() { @@ -1949,205 +1949,205 @@ public static Set getUbsUsers() { public static Payment getManualPayment() { return Payment.builder() - .settlementDate("02-08-2021") - .amount(500L) - .paymentStatus(PaymentStatus.PAID) - .paymentId("1l") - .receiptLink("somelink.com") - .currency("UAH") - .imagePath("") - .order(getOrder()) - .build(); + .settlementDate("02-08-2021") + .amount(500L) + .paymentStatus(PaymentStatus.PAID) + .paymentId("1l") + .receiptLink("somelink.com") + .currency("UAH") + .imagePath("") + .order(getOrder()) + .build(); } public static ManualPaymentRequestDto getManualPaymentRequestDto() { return ManualPaymentRequestDto.builder() - .settlementdate("02-08-2021") - .amount(500L) - .receiptLink("link") - .paymentId("1") - .imagePath("fdhgh") - .build(); + .settlementdate("02-08-2021") + .amount(500L) + .receiptLink("link") + .paymentId("1") + .imagePath("fdhgh") + .build(); } public static Order getOrderTest() { return Order.builder() + .id(1L) + .orderStatus(OrderStatus.FORMED) + .payment(singletonList(Payment.builder() .id(1L) - .orderStatus(OrderStatus.FORMED) - .payment(singletonList(Payment.builder() - .id(1L) - .amount(350L) - .paymentStatus(PaymentStatus.PAID) - .build())) - .ubsUser(UBSuser.builder() - .firstName("oleh") - .lastName("ivanov") - .email("mail@mail.ua") - .senderEmail("test@email.ua") - .senderPhoneNumber("+380974563223") - .senderLastName("TestLast") - .senderFirstName("TestFirst") - .id(1L) - .phoneNumber("067894522") - .orderAddress(OrderAddress.builder() - .id(1L) - .city("Lviv") - .street("Levaya") - .district("frankivskiy") - .entranceNumber("5") - .addressComment("near mall") - .houseCorpus(null) - .houseNumber("4R") - .coordinates(Coordinates.builder() - .latitude(49.83) - .longitude(23.88) - .build()) - .build()) - .build()) - .certificates(Collections.emptySet()) - .cancellationComment("Garbage disappeared") - .cancellationReason(CancellationReason.OTHER) - .pointsToUse(700) - .user(User.builder() - .id(1L) - .recipientName("Yuriy") - .recipientSurname("Gerasum") + .amount(350L) + .paymentStatus(PaymentStatus.PAID) + .build())) + .ubsUser(UBSuser.builder() + .firstName("oleh") + .lastName("ivanov") + .email("mail@mail.ua") + .senderEmail("test@email.ua") + .senderPhoneNumber("+380974563223") + .senderLastName("TestLast") + .senderFirstName("TestFirst") + .id(1L) + .phoneNumber("067894522") + .orderAddress(OrderAddress.builder() + .id(1L) + .city("Lviv") + .street("Levaya") + .district("frankivskiy") + .entranceNumber("5") + .addressComment("near mall") + .houseCorpus(null) + .houseNumber("4R") + .coordinates(Coordinates.builder() + .latitude(49.83) + .longitude(23.88) .build()) - .build(); + .build()) + .build()) + .certificates(Collections.emptySet()) + .cancellationComment("Garbage disappeared") + .cancellationReason(CancellationReason.OTHER) + .pointsToUse(700) + .user(User.builder() + .id(1L) + .recipientName("Yuriy") + .recipientSurname("Gerasum") + .build()) + .build(); } public static Order getFormedOrder() { return Order.builder() + .id(1L) + .events(List.of(new Event(1L, LocalDateTime.now(), + "Roman", "Roman", new Order()))) + .orderStatus(OrderStatus.FORMED) + .payment(singletonList(Payment.builder() .id(1L) - .events(List.of(new Event(1L, LocalDateTime.now(), - "Roman", "Roman", new Order()))) - .orderStatus(OrderStatus.FORMED) - .payment(singletonList(Payment.builder() - .id(1L) - .amount(350L) - .paymentStatus(PaymentStatus.PAID) - .build())) - .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) - .amountOfBagsOrdered(Collections.singletonMap(1, 2)) - .exportedQuantity(Collections.singletonMap(1, 1)) - .amountOfBagsOrdered(Map.of(1, 1)) - .confirmedQuantity(Map.of(1, 0)) - .exportedQuantity(Map.of(1, 1)) - .pointsToUse(100) - .user(User.builder().id(1L).currentPoints(100).build()) - .build(); + .amount(350L) + .paymentStatus(PaymentStatus.PAID) + .build())) + .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) + .amountOfBagsOrdered(Collections.singletonMap(1, 2)) + .exportedQuantity(Collections.singletonMap(1, 1)) + .amountOfBagsOrdered(Map.of(1, 1)) + .confirmedQuantity(Map.of(1, 0)) + .exportedQuantity(Map.of(1, 1)) + .pointsToUse(100) + .user(User.builder().id(1L).currentPoints(100).build()) + .build(); } public static Order getCanceledPaidOrder() { return Order.builder() + .id(1L) + .events(List.of(new Event(1L, LocalDateTime.now(), + "Roman", "Roman", new Order()))) + .orderStatus(OrderStatus.CANCELED) + .payment(singletonList(Payment.builder() .id(1L) - .events(List.of(new Event(1L, LocalDateTime.now(), - "Roman", "Roman", new Order()))) - .orderStatus(OrderStatus.CANCELED) - .payment(singletonList(Payment.builder() - .id(1L) - .amount(350L) - .paymentStatus(PaymentStatus.PAID) - .build())) - .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) - .amountOfBagsOrdered(Collections.singletonMap(1, 2)) - .exportedQuantity(Collections.singletonMap(1, 1)) - .amountOfBagsOrdered(Map.of(1, 1)) - .confirmedQuantity(Map.of(1, 1)) - .exportedQuantity(Map.of(1, 1)) - .pointsToUse(100) - .user(User.builder().id(1L).currentPoints(100).build()) - .build(); + .amount(350L) + .paymentStatus(PaymentStatus.PAID) + .build())) + .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) + .amountOfBagsOrdered(Collections.singletonMap(1, 2)) + .exportedQuantity(Collections.singletonMap(1, 1)) + .amountOfBagsOrdered(Map.of(1, 1)) + .confirmedQuantity(Map.of(1, 1)) + .exportedQuantity(Map.of(1, 1)) + .pointsToUse(100) + .user(User.builder().id(1L).currentPoints(100).build()) + .build(); } public static Order getAdjustmentPaidOrder() { return Order.builder() + .id(1L) + .events(List.of(new Event(1L, LocalDateTime.now(), + "Roman", "Roman", new Order()))) + .orderStatus(OrderStatus.ADJUSTMENT) + .payment(singletonList(Payment.builder() .id(1L) - .events(List.of(new Event(1L, LocalDateTime.now(), - "Roman", "Roman", new Order()))) - .orderStatus(OrderStatus.ADJUSTMENT) - .payment(singletonList(Payment.builder() - .id(1L) - .amount(300000L) - .paymentStatus(PaymentStatus.PAID) - .build())) - .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) - .amountOfBagsOrdered(Collections.singletonMap(1, 2)) - .exportedQuantity(Collections.singletonMap(1, 1)) - .amountOfBagsOrdered(Map.of(1, 1)) - .confirmedQuantity(Map.of(1, 1)) - .exportedQuantity(Map.of(2, 2)) - .pointsToUse(100) - .user(User.builder().id(1L).currentPoints(100).build()) - .build(); + .amount(300000L) + .paymentStatus(PaymentStatus.PAID) + .build())) + .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) + .amountOfBagsOrdered(Collections.singletonMap(1, 2)) + .exportedQuantity(Collections.singletonMap(1, 1)) + .amountOfBagsOrdered(Map.of(1, 1)) + .confirmedQuantity(Map.of(1, 1)) + .exportedQuantity(Map.of(2, 2)) + .pointsToUse(100) + .user(User.builder().id(1L).currentPoints(100).build()) + .build(); } public static Order getFormedHalfPaidOrder() { return Order.builder() + .id(1L) + .events(List.of(new Event(1L, LocalDateTime.now(), + "Roman", "Roman", new Order()))) + .orderStatus(OrderStatus.FORMED) + .payment(singletonList(Payment.builder() .id(1L) - .events(List.of(new Event(1L, LocalDateTime.now(), - "Roman", "Roman", new Order()))) - .orderStatus(OrderStatus.FORMED) - .payment(singletonList(Payment.builder() - .id(1L) - .amount(100L) - .paymentStatus(PaymentStatus.PAID) - .build())) - .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) - .amountOfBagsOrdered(Collections.singletonMap(1, 1)) - .exportedQuantity(Collections.singletonMap(1, 1)) - .amountOfBagsOrdered(Map.of(1, 1)) - .confirmedQuantity(Map.of(1, 1)) - .exportedQuantity(Map.of(1, 1)) - .pointsToUse(50) - .user(User.builder().id(1L).currentPoints(500).build()) - .build(); + .amount(100L) + .paymentStatus(PaymentStatus.PAID) + .build())) + .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) + .amountOfBagsOrdered(Collections.singletonMap(1, 1)) + .exportedQuantity(Collections.singletonMap(1, 1)) + .amountOfBagsOrdered(Map.of(1, 1)) + .confirmedQuantity(Map.of(1, 1)) + .exportedQuantity(Map.of(1, 1)) + .pointsToUse(50) + .user(User.builder().id(1L).currentPoints(500).build()) + .build(); } public static Order getCanceledHalfPaidOrder() { return Order.builder() + .id(1L) + .events(List.of(new Event(1L, LocalDateTime.now(), + "Roman", "Roman", new Order()))) + .orderStatus(OrderStatus.CANCELED) + .payment(singletonList(Payment.builder() .id(1L) - .events(List.of(new Event(1L, LocalDateTime.now(), - "Roman", "Roman", new Order()))) - .orderStatus(OrderStatus.CANCELED) - .payment(singletonList(Payment.builder() - .id(1L) - .amount(1000L) - .paymentStatus(PaymentStatus.PAID) - .build())) - .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) - .amountOfBagsOrdered(Collections.singletonMap(1, 1)) - .exportedQuantity(Collections.singletonMap(1, 1)) - .amountOfBagsOrdered(Map.of(1, 1)) - .confirmedQuantity(Map.of(1, 1)) - .exportedQuantity(Map.of(1, 1)) - .pointsToUse(50) - .user(User.builder().id(1L).currentPoints(500).build()) - .build(); + .amount(1000L) + .paymentStatus(PaymentStatus.PAID) + .build())) + .orderDate(LocalDateTime.of(2021, 5, 15, 10, 20, 5)) + .amountOfBagsOrdered(Collections.singletonMap(1, 1)) + .exportedQuantity(Collections.singletonMap(1, 1)) + .amountOfBagsOrdered(Map.of(1, 1)) + .confirmedQuantity(Map.of(1, 1)) + .exportedQuantity(Map.of(1, 1)) + .pointsToUse(50) + .user(User.builder().id(1L).currentPoints(500).build()) + .build(); } public static OrderDetailStatusRequestDto getTestOrderDetailStatusRequestDto() { return OrderDetailStatusRequestDto.builder() - .orderStatus("FORMED") - .adminComment("all good") - .orderPaymentStatus("PAID").build(); + .orderStatus("FORMED") + .adminComment("all good") + .orderPaymentStatus("PAID").build(); } public static OrderDetailStatusDto getTestOrderDetailStatusDto() { return OrderDetailStatusDto.builder() - .orderStatus("FORMED") - .paymentStatus("PAID") - .date("15-05-2021") - .build(); + .orderStatus("FORMED") + .paymentStatus("PAID") + .date("15-05-2021") + .build(); } public static EmployeeOrderPosition getEmployeeOrderPosition() { return EmployeeOrderPosition.builder() - .id(1L) - .order(getOrder()) - .position(getPosition()) - .employee(getEmployee()) - .build(); + .id(1L) + .order(getOrder()) + .position(getPosition()) + .employee(getEmployee()) + .build(); } public static EmployeePositionDtoRequest getEmployeePositionDtoRequest() { @@ -2156,81 +2156,81 @@ public static EmployeePositionDtoRequest getEmployeePositionDtoRequest() { Map currentPositionEmployees = new HashMap<>(); String value = getEmployee().getFirstName() + " " + getEmployee().getLastName(); allPositionsEmployees.put(getPositionDto(positionId), new ArrayList<>(List.of(EmployeeNameIdDto.builder() - .id(positionId) - .name(value) - .build()))); + .id(positionId) + .name(value) + .build()))); currentPositionEmployees.put(getPositionDto(positionId), value); return EmployeePositionDtoRequest.builder() - .orderId(1L) - .allPositionsEmployees(allPositionsEmployees) - .currentPositionEmployees(currentPositionEmployees) - .build(); + .orderId(1L) + .allPositionsEmployees(allPositionsEmployees) + .currentPositionEmployees(currentPositionEmployees) + .build(); } private static Order createOrder() { return Order.builder() - .id(1L) - .orderStatus(OrderStatus.FORMED) - .ubsUser(createUbsUser()) - .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").build()) - .orderDate(LocalDateTime.of(2021, 8, 5, 21, 47, 5)) - .build(); + .id(1L) + .orderStatus(OrderStatus.FORMED) + .ubsUser(createUbsUser()) + .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").build()) + .orderDate(LocalDateTime.of(2021, 8, 5, 21, 47, 5)) + .build(); } private static UBSuser createUbsUser() { return UBSuser.builder() - .id(10L) - .orderAddress(createAddress()) - .build(); + .id(10L) + .orderAddress(createAddress()) + .build(); } private static OrderAddress createAddress() { return OrderAddress.builder() - .id(2L) - .build(); + .id(2L) + .build(); } private static OrderAddressExportDetailsDtoUpdate createOrderAddressDtoUpdate() { return OrderAddressExportDetailsDtoUpdate.builder() - .addressId(1L) - .addressHouseNumber("1") - .addressEntranceNumber("3") - .addressDistrict("District") - .addressDistrictEng("DistrictEng") - .addressStreet("Street") - .addressStreetEng("StreetEng") - .addressHouseCorpus("2") - .addressCity("City") - .addressCityEng("CityEng") - .addressRegion("Region") - .addressRegionEng("RegionEng") - .build(); + .addressId(1L) + .addressHouseNumber("1") + .addressEntranceNumber("3") + .addressDistrict("District") + .addressDistrictEng("DistrictEng") + .addressStreet("Street") + .addressStreetEng("StreetEng") + .addressHouseCorpus("2") + .addressCity("City") + .addressCityEng("CityEng") + .addressRegion("Region") + .addressRegionEng("RegionEng") + .build(); } private static OrderAddressDtoResponse createOrderAddressDtoResponse() { return OrderAddressDtoResponse.builder() - .houseNumber("1") - .entranceNumber("3") - .district("District") - .districtEng("DistrictEng") - .street("Street") - .streetEng("StreetEng") - .houseCorpus("2") - .build(); + .houseNumber("1") + .entranceNumber("3") + .district("District") + .districtEng("DistrictEng") + .street("Street") + .streetEng("StreetEng") + .houseCorpus("2") + .build(); } private static List createPaymentList() { return List.of( - Payment.builder() - .id(1L) - .paymentStatus(PaymentStatus.PAID) - .amount(100L) - .build(), - Payment.builder() - .id(2L) - .paymentStatus(PaymentStatus.PAID) - .amount(50L) - .build()); + Payment.builder() + .id(1L) + .paymentStatus(PaymentStatus.PAID) + .amount(100L) + .build(), + Payment.builder() + .id(2L) + .paymentStatus(PaymentStatus.PAID) + .amount(50L) + .build()); } private static OrderDetailStatusDto createOrderDetailStatusDto() { @@ -2238,141 +2238,141 @@ private static OrderDetailStatusDto createOrderDetailStatusDto() { String orderDate = TEST_ORDER.getOrderDate().toLocalDate().format(formatter); return OrderDetailStatusDto.builder() - .orderStatus(TEST_ORDER.getOrderStatus().name()) - .paymentStatus(TEST_PAYMENT_LIST.get(0).getPaymentStatus().name()) - .date(orderDate) - .build(); + .orderStatus(TEST_ORDER.getOrderStatus().name()) + .paymentStatus(TEST_PAYMENT_LIST.get(0).getPaymentStatus().name()) + .date(orderDate) + .build(); } private static BagInfoDto createBagInfoDto() { return BagInfoDto.builder() - .id(1) - .capacity(20) - .name("Name") - .nameEng("NameEng") - .price(100.00) - .build(); + .id(1) + .capacity(20) + .name("Name") + .nameEng("NameEng") + .price(100.00) + .build(); } private static List createBagMappingDtoList() { return Collections.singletonList( - BagMappingDto.builder() - .amount(4) - .build()); + BagMappingDto.builder() + .amount(4) + .build()); } private static Bag createBag() { return Bag.builder() - .id(1) - .name("Name") - .nameEng("NameEng") - .capacity(20) - .price(100_00L) - .commission(0L) - .fullPrice(100_00L) - .description("some_description") - .descriptionEng("some_eng_description") - .limitIncluded(true) - .createdAt(LocalDate.now()) - .createdBy(Employee.builder() - .id(1L) - .build()) - .build(); + .id(1) + .name("Name") + .nameEng("NameEng") + .capacity(20) + .price(100_00L) + .commission(0L) + .fullPrice(100_00L) + .description("some_description") + .descriptionEng("some_eng_description") + .limitIncluded(true) + .createdAt(LocalDate.now()) + .createdBy(Employee.builder() + .id(1L) + .build()) + .build(); } private static OrderBag createOrderBag() { return OrderBag.builder() - .id(1L) - .name("Name") - .nameEng("NameEng") - .capacity(20) - .price(100_00L) - .order(createOrder()) - .bag(createBag()) - .build(); + .id(1L) + .name("Name") + .nameEng("NameEng") + .capacity(20) + .price(100_00L) + .order(createOrder()) + .bag(createBag()) + .build(); } private static BagForUserDto createBagForUserDto() { return BagForUserDto.builder() - .service("Name") - .serviceEng("NameEng") - .capacity(20) - .fullPrice(100.0) - .count(22) - .totalPrice(2200.0) - .build(); + .service("Name") + .serviceEng("NameEng") + .capacity(20) + .fullPrice(100.0) + .count(22) + .totalPrice(2200.0) + .build(); } private static OrderDetailInfoDto createOrderDetailInfoDto() { return OrderDetailInfoDto.builder() - .amount(5) - .capacity(4) - .build(); + .amount(5) + .capacity(4) + .build(); } public static OrderCancellationReasonDto getCancellationDto() { return OrderCancellationReasonDto.builder() - .cancellationReason(CancellationReason.OTHER) - .cancellationComment("Garbage disappeared") - .build(); + .cancellationReason(CancellationReason.OTHER) + .cancellationComment("Garbage disappeared") + .build(); } private static OrderAddressDtoRequest createOrderDtoRequest() { return OrderAddressDtoRequest.builder() - .id(13L).city("Kyiv").district("Svyatoshyn") - .entranceNumber("1").houseCorpus("1").houseNumber("55").street("Peremohy av.") - .actual(true).coordinates(new Coordinates(12.5, 34.5)) - .build(); + .id(13L).city("Kyiv").district("Svyatoshyn") + .entranceNumber("1").houseCorpus("1").houseNumber("55").street("Peremohy av.") + .actual(true).coordinates(new Coordinates(12.5, 34.5)) + .build(); } public static User getUserWithLastLocation() { Location location = new Location(); location.setLocationStatus(LocationStatus.ACTIVE); return User.builder() - .id(1L) - .addresses(singletonList(getAddress())) - .recipientEmail("someUser@gmail.com") - .recipientPhone("962473289") - .recipientSurname("Ivanov") - .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") - .recipientName("Taras") - .build(); + .id(1L) + .addresses(singletonList(getAddress())) + .recipientEmail("someUser@gmail.com") + .recipientPhone("962473289") + .recipientSurname("Ivanov") + .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") + .recipientName("Taras") + .build(); } public static List getLocationList() { return List.of(Location.builder() - .locationStatus(LocationStatus.ACTIVE) - .nameEn("Kyiv") - .id(1L) - .nameUk("Київ") - .region(getRegion()) - .coordinates(getCoordinates()) - .build()); + .locationStatus(LocationStatus.ACTIVE) + .nameEn("Kyiv") + .id(1L) + .nameUk("Київ") + .region(getRegion()) + .coordinates(getCoordinates()) + .build()); } public static List getLocationList2() { return List.of(Location.builder() - .id(1L) - .region( - Region.builder() - .id(1L) - .build()) - .build(), - Location.builder() + .id(1L) + .region( + Region.builder() + .id(1L) + .build()) + .build(), + Location.builder() + .id(2L) + .region( + Region.builder() .id(2L) - .region( - Region.builder() - .id(2L) - .build()) - .build()); + .build()) + .build()); } private static Employee createEmployee() { return Employee.builder() - .id(1L) - .firstName("Test") - .lastName("Test") - .build(); + .id(1L) + .firstName("Test") + .lastName("Test") + .build(); } private static Map createMap() { @@ -2387,120 +2387,120 @@ private static List createAdditionalBagInfoDtoList() { private static AdditionalBagInfoDto createAdditionalBagInfoDto() { return AdditionalBagInfoDto.builder() - .recipientEmail("test@mail.com") - .build(); + .recipientEmail("test@mail.com") + .build(); } private static User createUser() { return User.builder() - .id(1L) - .uuid("Test") - .recipientEmail("test@mail.com") - .build(); + .id(1L) + .uuid("Test") + .recipientEmail("test@mail.com") + .build(); } public static Set getCoordinatesDtoSet() { Set set = new HashSet<>(); set.add(CoordinatesDto.builder() - .latitude(49.83) - .longitude(23.88) - .build()); + .latitude(49.83) + .longitude(23.88) + .build()); return set; } private static NotificationShortDto createNotificationShortDto() { return NotificationShortDto.builder() - .id(1L) - .orderId(1L) - .title("Title") - .notificationTime(LocalDateTime.of(2021, 9, 17, 20, 26, 10)) - .read(false) - .build(); + .id(1L) + .orderId(1L) + .title("Title") + .notificationTime(LocalDateTime.of(2021, 9, 17, 20, 26, 10)) + .read(false) + .build(); } private static PageableDto createPageableDto() { return new PageableDto<>( - TEST_NOTIFICATION_SHORT_DTO_LIST, - 1, - 0, - 1); + TEST_NOTIFICATION_SHORT_DTO_LIST, + 1, + 0, + 1); } private static NotificationTemplateWithPlatformsUpdateDto createNotificationTemplateWithPlatformsUpdateDto() { return NotificationTemplateWithPlatformsUpdateDto.builder() - .notificationTemplateMainInfoDto(createNotificationTemplateMainInfoDto()) - .platforms(List.of( - createNotificationPlatformDto(SITE))) - .build(); + .notificationTemplateMainInfoDto(createNotificationTemplateMainInfoDto()) + .platforms(List.of( + createNotificationPlatformDto(SITE))) + .build(); } private static NotificationTemplateWithPlatformsDto createNotificationTemplateWithPlatformsDto() { return NotificationTemplateWithPlatformsDto.builder() - .notificationTemplateMainInfoDto(createNotificationTemplateMainInfoDto()) - .platforms(List.of(createNotificationPlatformDto(SITE))) - .build(); + .notificationTemplateMainInfoDto(createNotificationTemplateMainInfoDto()) + .platforms(List.of(createNotificationPlatformDto(SITE))) + .build(); } private static NotificationPlatformDto createNotificationPlatformDto(NotificationReceiverType receiverType) { return NotificationPlatformDto.builder() - .id(1L) - .receiverType(receiverType) - .nameEng("NameEng") - .body("Body") - .bodyEng("BodyEng") - .status(ACTIVE) - .build(); + .id(1L) + .receiverType(receiverType) + .nameEng("NameEng") + .body("Body") + .bodyEng("BodyEng") + .status(ACTIVE) + .build(); } private static NotificationTemplateDto createNotificationTemplateDto() { return NotificationTemplateDto.builder() - .id(1L) - .notificationTemplateMainInfoDto(createNotificationTemplateMainInfoDto()) - .build(); + .id(1L) + .notificationTemplateMainInfoDto(createNotificationTemplateMainInfoDto()) + .build(); } private static NotificationTemplateMainInfoDto createNotificationTemplateMainInfoDto() { return NotificationTemplateMainInfoDto.builder() - .type(UNPAID_ORDER) - .trigger(ORDER_NOT_PAID_FOR_3_DAYS) - .triggerDescription("Trigger") - .triggerDescriptionEng("TriggerEng") - .time(AT_6PM_3DAYS_AFTER_ORDER_FORMED_NOT_PAID) - .timeDescription("Description") - .timeDescriptionEng("DescriptionEng") - .schedule("0 0 18 * * ?") - .title("Title") - .titleEng("TitleEng") - .notificationStatus(ACTIVE) - .build(); + .type(UNPAID_ORDER) + .trigger(ORDER_NOT_PAID_FOR_3_DAYS) + .triggerDescription("Trigger") + .triggerDescriptionEng("TriggerEng") + .time(AT_6PM_3DAYS_AFTER_ORDER_FORMED_NOT_PAID) + .timeDescription("Description") + .timeDescriptionEng("DescriptionEng") + .schedule("0 0 18 * * ?") + .title("Title") + .titleEng("TitleEng") + .notificationStatus(ACTIVE) + .build(); } private static NotificationTemplate createNotificationTemplate() { return NotificationTemplate.builder() - .id(1L) - .notificationType(UNPAID_ORDER) - .trigger(ORDER_NOT_PAID_FOR_3_DAYS) - .time(AT_6PM_3DAYS_AFTER_ORDER_FORMED_NOT_PAID) - .schedule("0 0 18 * * ?") - .title("Title") - .titleEng("TitleEng") - .notificationStatus(ACTIVE) - .notificationPlatforms(List.of( - createNotificationPlatform(SITE), - createNotificationPlatform(EMAIL), - createNotificationPlatform(MOBILE))) - .build(); + .id(1L) + .notificationType(UNPAID_ORDER) + .trigger(ORDER_NOT_PAID_FOR_3_DAYS) + .time(AT_6PM_3DAYS_AFTER_ORDER_FORMED_NOT_PAID) + .schedule("0 0 18 * * ?") + .title("Title") + .titleEng("TitleEng") + .notificationStatus(ACTIVE) + .notificationPlatforms(List.of( + createNotificationPlatform(SITE), + createNotificationPlatform(EMAIL), + createNotificationPlatform(MOBILE))) + .build(); } public static NotificationPlatform createNotificationPlatform( - NotificationReceiverType receiverType) { + NotificationReceiverType receiverType) { return NotificationPlatform.builder() - .id(1L) - .body("Body") - .bodyEng("BodyEng") - .notificationReceiverType(receiverType) - .notificationStatus(ACTIVE) - .build(); + .id(1L) + .body("Body") + .bodyEng("BodyEng") + .notificationReceiverType(receiverType) + .notificationStatus(ACTIVE) + .build(); } private static List createUserNotificationList() { @@ -2510,11 +2510,11 @@ private static List createUserNotificationList() { notification.setRead(false); notification.setUser(TEST_USER); notification.setOrder(Order.builder() - .id(1L) - .build()); + .id(1L) + .build()); notification.setNotificationType(UNPAID_ORDER); return List.of( - notification); + notification); } private static Violation createTestViolation() { @@ -2523,21 +2523,21 @@ private static Violation createTestViolation() { private static NotificationParameter createNotificationParameter() { return NotificationParameter.builder() - .key("violationDescription") - .value("violation description") - .build(); + .key("violationDescription") + .value("violation description") + .build(); } private static Order createTestOrder4() { return Order.builder().id(46L).user(User.builder().id(42L).build()) - .orderDate(LocalDateTime.now()) - .build(); + .orderDate(LocalDateTime.now()) + .build(); } private static Order createTestOrder5() { return Order.builder().id(45L).user(User.builder().id(42L).build()) - .orderDate(LocalDateTime.now()).pointsToUse(200) - .build(); + .orderDate(LocalDateTime.now()).pointsToUse(200) + .build(); } public static UserNotification createUserNotificationForViolation() { @@ -2569,13 +2569,13 @@ private static Set createNotificationParameterSet() { Set parameters = new HashSet<>(); parameters.add(NotificationParameter.builder().key("overpayment") - .value(String.valueOf(2L)).build()); + .value(String.valueOf(2L)).build()); parameters.add(NotificationParameter.builder().key("realPackageNumber") - .value(String.valueOf(0)).build()); + .value(String.valueOf(0)).build()); parameters.add(NotificationParameter.builder().key("paidPackageNumber") - .value(String.valueOf(0)).build()); + .value(String.valueOf(0)).build()); parameters.add(NotificationParameter.builder().key("orderNumber") - .value("45").build()); + .value("45").build()); return parameters; } @@ -2583,21 +2583,21 @@ private static Set createNotificationParameterSet2() { Set parameters = new HashSet<>(); parameters.add(NotificationParameter.builder().key("returnedPayment") - .value(String.valueOf(200L)).build()); + .value(String.valueOf(200L)).build()); parameters.add(NotificationParameter.builder().key("orderNumber") - .value("45").build()); + .value("45").build()); return parameters; } private static Order createTestOrder3() { return Order.builder().id(45L).user(User.builder().id(42L).build()) - .confirmedQuantity(new HashMap<>()) - .exportedQuantity(new HashMap<>()) - .amountOfBagsOrdered(new HashMap<>()) - .orderStatus(OrderStatus.ADJUSTMENT) - .orderPaymentStatus(OrderPaymentStatus.PAID) - .orderDate(LocalDateTime.now()) - .build(); + .confirmedQuantity(new HashMap<>()) + .exportedQuantity(new HashMap<>()) + .amountOfBagsOrdered(new HashMap<>()) + .orderStatus(OrderStatus.ADJUSTMENT) + .orderPaymentStatus(OrderPaymentStatus.PAID) + .orderDate(LocalDateTime.now()) + .build(); } private static UserNotification createUserNotification() { @@ -2611,15 +2611,15 @@ private static UserNotification createUserNotification() { private static Order createTestOrder2() { return Order.builder().id(43L).user(User.builder().id(42L).build()) - .orderPaymentStatus(OrderPaymentStatus.PAID).orderDate(LocalDateTime.now()).build(); + .orderPaymentStatus(OrderPaymentStatus.PAID).orderDate(LocalDateTime.now()).build(); } private static UserNotification createUserNotification4() { UserNotification notification = new UserNotification(); notification.setId(1L); notification.setUser(User.builder() - .uuid("test") - .build()); + .uuid("test") + .build()); notification.setRead(false); notification.setParameters(null); notification.setNotificationType(UNPAID_ORDER); @@ -2628,485 +2628,502 @@ private static UserNotification createUserNotification4() { private static NotificationDto createNotificationDto() { return NotificationDto.builder() - .title("Title") - .body("Body") - .build(); + .title("Title") + .body("Body") + .build(); } public static NotificationDto createViolationNotificationDto() { return NotificationDto.builder() - .title("Title") - .body("Body") - .images(emptyList()) - .build(); + .title("Title") + .body("Body") + .images(emptyList()) + .build(); } public static TariffServiceDto TariffServiceDto() { return TariffServiceDto.builder() - .capacity(20) - .price(100.0) - .commission(50.0) - .description("Description") - .descriptionEng("DescriptionEng") - .name("name") - .nameEng("nameEng") - .build(); + .capacity(20) + .price(100.0) + .commission(50.0) + .description("Description") + .descriptionEng("DescriptionEng") + .name("name") + .nameEng("nameEng") + .build(); } public static GetTariffServiceDto getGetTariffServiceDto() { return GetTariffServiceDto.builder() - .id(1) - .capacity(20) - .price(100.0) - .commission(50.0) - .fullPrice(150.0) - .limitIncluded(false) - .description("Description") - .descriptionEng("DescriptionEng") - .name("name") - .nameEng("nameEng") - .build(); + .id(1) + .capacity(20) + .price(100.0) + .commission(50.0) + .fullPrice(150.0) + .limitIncluded(false) + .description("Description") + .descriptionEng("DescriptionEng") + .name("name") + .nameEng("nameEng") + .build(); } public static Optional getOptionalBag() { return Optional.of(Bag.builder() - .id(1) - .capacity(120) - .commission(50_00L) - .price(120_00L) - .fullPrice(170_00L) - .createdAt(LocalDate.now()) - .createdBy(getEmployee()) - .editedBy(getEmployee()) - .description("Description") - .descriptionEng("DescriptionEng") - .limitIncluded(false) - .build()); + .id(1) + .capacity(120) + .commission(50_00L) + .price(120_00L) + .fullPrice(170_00L) + .createdAt(LocalDate.now()) + .createdBy(getEmployee()) + .editedBy(getEmployee()) + .description("Description") + .descriptionEng("DescriptionEng") + .limitIncluded(false) + .build()); } public static OrderBag getOrderBag2() { return OrderBag.builder() - .id(2L) - .capacity(2200) - .price(22000_00L) - .name("name") - .nameEng("name eng") - .amount(20) - .bag(getBag2()) - .order(getOrder()) - .build(); + .id(2L) + .capacity(2200) + .price(22000_00L) + .name("name") + .nameEng("name eng") + .amount(20) + .bag(getBag2()) + .order(getOrder()) + .build(); } public static Bag getBag() { return Bag.builder() - .id(1) - .capacity(120) - .commission(50_00L) - .price(120_00L) - .fullPrice(170_00L) - .createdAt(LocalDate.now()) - .createdBy(getEmployee()) - .editedBy(getEmployee()) - .limitIncluded(true) + .id(1) + .capacity(120) + .commission(50_00L) + .price(120_00L) + .fullPrice(170_00L) + .createdAt(LocalDate.now()) + .createdBy(getEmployee()) + .editedBy(getEmployee()) + .limitIncluded(true) - .tariffsInfo(getTariffInfo()) - .build(); + .tariffsInfo(getTariffInfo()) + .build(); } public static Bag getBag2() { return Bag.builder() - .id(2) - .capacity(120) - .commission(50_00L) - .price(120_00L) - .fullPrice(170_00L) - .createdAt(LocalDate.now()) - .createdBy(getEmployee()) - .editedBy(getEmployee()) - .limitIncluded(true) + .id(2) + .capacity(120) + .commission(50_00L) + .price(120_00L) + .fullPrice(170_00L) + .createdAt(LocalDate.now()) + .createdBy(getEmployee()) + .editedBy(getEmployee()) + .limitIncluded(true) - .tariffsInfo(getTariffInfo()) - .build(); + .tariffsInfo(getTariffInfo()) + .build(); } public static OrderBag getOrderBag() { return OrderBag.builder() - .id(1L) - .capacity(120) - .price(120_00L) - .name("name") - .nameEng("name eng") - .amount(1) - .bag(getBag()) - .order(getOrder()) - .build(); + .id(1L) + .capacity(120) + .price(120_00L) + .name("name") + .nameEng("name eng") + .amount(1) + .bag(getBag()) + .order(getOrder()) + .build(); } public static OrderBag getOrderBagWithConfirmedAmount() { return OrderBag.builder() - .id(1L) - .capacity(120) - .price(120_00L) - .name("name") - .nameEng("name eng") - .amount(1) - .confirmedQuantity(2) - .bag(getBag()) - .order(getOrder()) - .build(); + .id(1L) + .capacity(120) + .price(120_00L) + .name("name") + .nameEng("name eng") + .amount(1) + .confirmedQuantity(2) + .bag(getBag()) + .order(getOrder()) + .build(); } public static OrderBag getOrderBagWithExportedAmount() { return OrderBag.builder() - .id(1L) - .capacity(120) - .price(120_00L) - .name("name") - .nameEng("name eng") - .amount(1) - .confirmedQuantity(2) - .exportedQuantity(2) - .bag(getBag()) - .order(getOrder()) - .build(); + .id(1L) + .capacity(120) + .price(120_00L) + .name("name") + .nameEng("name eng") + .amount(1) + .confirmedQuantity(2) + .exportedQuantity(2) + .bag(getBag()) + .order(getOrder()) + .build(); } public static Bag getBagDeleted() { return Bag.builder() - .id(1) - .capacity(120) - .commission(50_00L) - .price(120_00L) - .fullPrice(170_00L) - .createdAt(LocalDate.now()) - .createdBy(getEmployee()) - .editedBy(getEmployee()) - .description("Description") - .descriptionEng("DescriptionEng") - .limitIncluded(true) - .tariffsInfo(getTariffInfo()) - .build(); + .id(1) + .capacity(120) + .commission(50_00L) + .price(120_00L) + .fullPrice(170_00L) + .createdAt(LocalDate.now()) + .createdBy(getEmployee()) + .editedBy(getEmployee()) + .description("Description") + .descriptionEng("DescriptionEng") + .limitIncluded(true) + .tariffsInfo(getTariffInfo()) + .build(); } public static Bag getBagForOrder() { return Bag.builder() - .id(3) - .capacity(120) - .commission(50_00L) - .price(350_00L) - .fullPrice(400_00L) - .createdAt(LocalDate.now()) - .createdBy(getEmployee()) - .editedBy(getEmployee()) - .description("Description") - .descriptionEng("DescriptionEng") - .limitIncluded(true) - .tariffsInfo(getTariffInfo()) - .build(); + .id(3) + .capacity(120) + .commission(50_00L) + .price(350_00L) + .fullPrice(400_00L) + .createdAt(LocalDate.now()) + .createdBy(getEmployee()) + .editedBy(getEmployee()) + .description("Description") + .descriptionEng("DescriptionEng") + .limitIncluded(true) + .tariffsInfo(getTariffInfo()) + .build(); } public static TariffServiceDto getTariffServiceDto() { return TariffServiceDto.builder() - .name("Бавовняна сумка") - .capacity(20) - .price(100.0) - .commission(50.0) - .description("Description") - .build(); + .name("Бавовняна сумка") + .capacity(20) + .price(100.0) + .commission(50.0) + .description("Description") + .build(); } public static Bag getEditedBag() { return Bag.builder() - .id(1) - .capacity(20) - .price(100_00L) - .fullPrice(150_00L) - .commission(50_00L) - .name("Бавовняна сумка") - .description("Description") - .createdAt(LocalDate.now()) - .createdBy(getEmployee()) - .editedBy(getEmployee()) - .editedAt(LocalDate.now()) - .limitIncluded(true) + .id(1) + .capacity(20) + .price(100_00L) + .fullPrice(150_00L) + .commission(50_00L) + .name("Бавовняна сумка") + .description("Description") + .createdAt(LocalDate.now()) + .createdBy(getEmployee()) + .editedBy(getEmployee()) + .editedAt(LocalDate.now()) + .limitIncluded(true) - .tariffsInfo(getTariffInfo()) - .build(); + .tariffsInfo(getTariffInfo()) + .build(); } public static OrderBag getEditedOrderBag() { return OrderBag.builder() - .id(1L) - .amount(1) - .price(150_00L) - .capacity(20) - .name("Бавовняна сумка") - .bag(getBag()) - .order(getOrder()) - .build(); + .id(1L) + .amount(1) + .price(150_00L) + .capacity(20) + .name("Бавовняна сумка") + .bag(getBag()) + .order(getOrder()) + .build(); } public static Location getLocation() { return Location.builder() - .id(1L) - .locationStatus(LocationStatus.ACTIVE) - .nameEn("Kyiv") - .nameUk("Київ") - .coordinates(Coordinates.builder() - .longitude(3.34d) - .latitude(1.32d).build()) - .region(getRegionForMapper()) - .orderAddresses(new ArrayList<>()) - .build(); + .id(1L) + .locationStatus(LocationStatus.ACTIVE) + .nameEn("Kyiv") + .nameUk("Київ") + .coordinates(Coordinates.builder() + .longitude(3.34d) + .latitude(1.32d).build()) + .region(getRegionForMapper()) + .orderAddresses(new ArrayList<>()) + .build(); } public static Location getLocationDeactivated() { return Location.builder() - .id(1L) - .locationStatus(LocationStatus.DEACTIVATED) - .nameEn("Kyiv") - .nameUk("Київ") - .coordinates(Coordinates.builder() - .longitude(3.34d) - .latitude(1.32d).build()) - .region(getRegionForMapper()) - .orderAddresses(new ArrayList<>()) - .build(); + .id(1L) + .locationStatus(LocationStatus.DEACTIVATED) + .nameEn("Kyiv") + .nameUk("Київ") + .coordinates(Coordinates.builder() + .longitude(3.34d) + .latitude(1.32d).build()) + .region(getRegionForMapper()) + .orderAddresses(new ArrayList<>()) + .build(); } public static Courier getCourier() { return Courier.builder() - .id(1L) - .courierStatus(CourierStatus.ACTIVE) - .nameUk("Тест") - .nameEn("Test") - .build(); + .id(1L) + .courierStatus(CourierStatus.ACTIVE) + .nameUk("Тест") + .nameEn("Test") + .build(); } public static Courier getDeactivatedCourier() { return Courier.builder() - .id(1L) - .courierStatus(CourierStatus.DEACTIVATED) - .nameUk("Тест") - .nameEn("Test") - .build(); + .id(1L) + .courierStatus(CourierStatus.DEACTIVATED) + .nameUk("Тест") + .nameEn("Test") + .build(); } public static CourierDto getCourierDto() { return CourierDto.builder() - .courierId(1L) - .courierStatus("ACTIVE") - .nameUk("Тест") - .nameEn("Test") - .build(); + .courierId(1L) + .courierStatus("ACTIVE") + .nameUk("Тест") + .nameEn("Test") + .build(); } public static Bag getTariffBag() { return Bag.builder() - .id(1) - .capacity(20) - .price(100_00L) - .commission(50_00L) - .fullPrice(150_00L) - .createdAt(LocalDate.now()) - .createdBy(getEmployee()) - .description("Description") - .descriptionEng("DescriptionEng") - .name("name") - .nameEng("nameEng") - .limitIncluded(false) - .tariffsInfo(getTariffInfo()) - .build(); + .id(1) + .capacity(20) + .price(100_00L) + .commission(50_00L) + .fullPrice(150_00L) + .createdAt(LocalDate.now()) + .createdBy(getEmployee()) + .description("Description") + .descriptionEng("DescriptionEng") + .name("name") + .nameEng("nameEng") + .limitIncluded(false) + .tariffsInfo(getTariffInfo()) + .build(); } public static BagTranslationDto getBagTranslationDto() { return BagTranslationDto.builder() - .id(1) - .capacity(20) - .price(150.0) - .name("name") - .nameEng("nameEng") - .limitedIncluded(false) - .build(); + .id(1) + .capacity(20) + .price(150.0) + .name("name") + .nameEng("nameEng") + .limitedIncluded(false) + .build(); } public static Bag getNewBag() { return Bag.builder() - .capacity(20) - .price(100_00L) - .commission(50_00L) - .fullPrice(150_00L) - .createdAt(LocalDate.now()) - .createdBy(getEmployee()) - .limitIncluded(false) - .description("Description") - .descriptionEng("DescriptionEng") - .name("name") - .nameEng("nameEng") + .capacity(20) + .price(100_00L) + .commission(50_00L) + .fullPrice(150_00L) + .createdAt(LocalDate.now()) + .createdBy(getEmployee()) + .limitIncluded(false) + .description("Description") + .descriptionEng("DescriptionEng") + .name("name") + .nameEng("nameEng") - .build(); + .build(); } public static AdminCommentDto getAdminCommentDto() { return AdminCommentDto.builder() - .orderId(1L) - .adminComment("Admin") - .build(); + .orderId(1L) + .adminComment("Admin") + .build(); } public static EcoNumberDto getEcoNumberDto() { return EcoNumberDto.builder() - .ecoNumber(new HashSet<>(Arrays.asList("1111111111", "3333333333"))) - .build(); + .ecoNumber(new HashSet<>(Arrays.asList("1111111111", "3333333333"))) + .build(); } public static ServiceDto getServiceDto() { return ServiceDto.builder() - .name("Name") - .nameEng("NameEng") - .price(100.0) - .description("Description") - .descriptionEng("DescriptionEng") - .build(); + .name("Name") + .nameEng("NameEng") + .price(100.0) + .description("Description") + .descriptionEng("DescriptionEng") + .build(); } public static GetServiceDto getGetServiceDto() { return GetServiceDto.builder() - .id(1L) - .name("Name") - .nameEng("NameEng") - .price(100.0) - .description("Description") - .descriptionEng("DescriptionEng") - .build(); + .id(1L) + .name("Name") + .nameEng("NameEng") + .price(100.0) + .description("Description") + .descriptionEng("DescriptionEng") + .build(); } public static Service getService() { Employee employee = ModelUtils.getEmployee(); return Service.builder() - .id(1L) - .price(100_00L) - .createdAt(LocalDate.now()) - .createdBy(employee) - .description("Description") - .descriptionEng("DescriptionEng") - .name("Name") - .nameEng("NameEng") - .build(); + .id(1L) + .price(100_00L) + .createdAt(LocalDate.now()) + .createdBy(employee) + .description("Description") + .descriptionEng("DescriptionEng") + .name("Name") + .nameEng("NameEng") + .build(); } public static Service getNewService() { Employee employee = ModelUtils.getEmployee(); return Service.builder() - .price(100_00L) - .createdAt(LocalDate.now()) - .createdBy(employee) - .description("Description") - .descriptionEng("DescriptionEng") - .name("Name") - .nameEng("NameEng") - .build(); + .price(100_00L) + .createdAt(LocalDate.now()) + .createdBy(employee) + .description("Description") + .descriptionEng("DescriptionEng") + .name("Name") + .nameEng("NameEng") + .build(); } public static Service getEditedService() { Employee employee = ModelUtils.getEmployee(); return Service.builder() - .id(1L) - .name("Name") - .nameEng("NameEng") - .price(100_00L) - .description("Description") - .descriptionEng("DescriptionEng") - .editedAt(LocalDate.now()) - .editedBy(employee) - .build(); + .id(1L) + .name("Name") + .nameEng("NameEng") + .price(100_00L) + .description("Description") + .descriptionEng("DescriptionEng") + .editedAt(LocalDate.now()) + .editedBy(employee) + .build(); } public static CreateCourierDto getCreateCourierDto() { return CreateCourierDto.builder() - .nameUk("Тест") - .nameEn("Test") - .build(); + .nameUk("Тест") + .nameEn("Test") + .build(); } public static CounterOrderDetailsDto getcounterOrderDetailsDto() { return CounterOrderDetailsDto.builder() - .totalAmount(22.02D) - .totalConfirmed(12.34D) - .totalExported(32.2D) - .sumAmount(35.3D) - .sumConfirmed(31.54D) - .sumExported(366.44D) - .certificateBonus(23.4D) - .bonus(54.32D) - .totalSumAmount(1.32D) - .totalSumConfirmed(32.6D) - .totalSumExported(73.1D) - .orderComment("test") - .certificate(List.of("fds")) - .numberOrderFromShop(Set.of("dsd")) - .build(); + .totalAmount(22.02D) + .totalConfirmed(12.34D) + .totalExported(32.2D) + .sumAmount(35.3D) + .sumConfirmed(31.54D) + .sumExported(366.44D) + .certificateBonus(23.4D) + .bonus(54.32D) + .totalSumAmount(1.32D) + .totalSumConfirmed(32.6D) + .totalSumExported(73.1D) + .orderComment("test") + .certificate(List.of("fds")) + .numberOrderFromShop(Set.of("dsd")) + .build(); } public static Order getOrderUserFirst() { return Order.builder() - .id(1L) - .exportedQuantity(Collections.singletonMap(1, 1)) - .amountOfBagsOrdered(Map.of(1, 1)) - .confirmedQuantity(Map.of(1, 1)) - .exportedQuantity(Map.of(1, 1)) - .pointsToUse(100) - .build(); + .id(1L) + .exportedQuantity(Collections.singletonMap(1, 1)) + .amountOfBagsOrdered(Map.of(1, 1)) + .confirmedQuantity(Map.of(1, 1)) + .exportedQuantity(Map.of(1, 1)) + .pointsToUse(100) + .build(); } public static Order getOrderUserSecond() { return Order.builder() - .id(2L) - .exportedQuantity(Collections.singletonMap(1, 1)) - .amountOfBagsOrdered(Map.of(1, 1)) - .confirmedQuantity(Map.of(1, 1)) - .exportedQuantity(Map.of(1, 1)) - .pointsToUse(100) - .build(); + .id(2L) + .exportedQuantity(Collections.singletonMap(1, 1)) + .amountOfBagsOrdered(Map.of(1, 1)) + .confirmedQuantity(Map.of(1, 1)) + .exportedQuantity(Map.of(1, 1)) + .pointsToUse(100) + .build(); } public static List getBag1list() { return List.of(Bag.builder() - .id(1) - .price(100_00L) - .capacity(20) - .commission(50_00L) - .fullPrice(170_00L) - .name("name") - .nameEng("nameEng") - .limitIncluded(false) - .build()); + .id(1) + .price(100_00L) + .capacity(20) + .commission(50_00L) + .fullPrice(170_00L) + .name("name") + .nameEng("nameEng") + .limitIncluded(false) + .build()); } public static List getBaglist() { return List.of(Bag.builder() - .id(1) - .price(100_00L) - .capacity(10) - .commission(21_00L) - .fullPrice(20_00L) - .build(), - Bag.builder() - .id(2) - .price(100_00L) - .capacity(10) - .commission(21_00L) - .fullPrice(21_00L) - .build()); + .id(1) + .price(100_00L) + .capacity(10) + .commission(21_00L) + .fullPrice(20_00L) + .build(), + Bag.builder() + .id(2) + .price(100_00L) + .capacity(10) + .commission(21_00L) + .fullPrice(21_00L) + .build()); } public static List getBag2list() { return List.of(Bag.builder() - .id(1) + .id(1) + .price(100_00L) + .capacity(10) + .commission(20_00L) + .fullPrice(120_00L) + .build()); + } + + public static List getBag3list() { + return List.of(Bag.builder() + .id(1) + .price(100_00L) + .capacity(10) + .commission(21_00L) + .fullPrice(2000_00L) + .build(), + Bag.builder() + .id(2) .price(100_00L) .capacity(10) .commission(20_00L) @@ -3114,53 +3131,36 @@ public static List getBag2list() { .build()); } - public static List getBag3list() { - return List.of(Bag.builder() - .id(1) - .price(100_00L) - .capacity(10) - .commission(21_00L) - .fullPrice(2000_00L) - .build(), - Bag.builder() - .id(2) - .price(100_00L) - .capacity(10) - .commission(20_00L) - .fullPrice(120_00L) - .build()); - } - public static List getBag4list() { return List.of(Bag.builder() - .id(1) - .price(100_00L) - .capacity(10) - .commission(20_00L) - .fullPrice(120_00L) - .name("name") - .nameEng("nameEng") - .limitIncluded(false) - .build(), - Bag.builder() - .id(2) - .price(100_00L) - .capacity(10) - .commission(20_00L) - .fullPrice(120_00L) - .name("name") - .nameEng("nameEng") - .limitIncluded(false) - .build()); + .id(1) + .price(100_00L) + .capacity(10) + .commission(20_00L) + .fullPrice(120_00L) + .name("name") + .nameEng("nameEng") + .limitIncluded(false) + .build(), + Bag.builder() + .id(2) + .price(100_00L) + .capacity(10) + .commission(20_00L) + .fullPrice(120_00L) + .name("name") + .nameEng("nameEng") + .limitIncluded(false) + .build()); } public static List getCertificateList() { return List.of(Certificate.builder() - .code("uuid") - .certificateStatus(CertificateStatus.ACTIVE) - .creationDate(LocalDate.now()) - .points(999) - .build()); + .code("uuid") + .certificateStatus(CertificateStatus.ACTIVE) + .creationDate(LocalDate.now()) + .points(999) + .build()); } public static OrderStatusTranslation getStatusTranslation() { @@ -3169,521 +3169,521 @@ public static OrderStatusTranslation getStatusTranslation() { public static List getOrderStatusTranslations() { return List.of(OrderStatusTranslation.builder() - .id(1L) - .statusId(6L) - .name("Order DONE") - .build(), - OrderStatusTranslation.builder() - .id(2L) - .statusId(7L) - .name("Order NOT TAKEN OUT") - .build(), - OrderStatusTranslation.builder().id(3L) - .statusId(8L) - .name("Order CANCELLED") - .build()); + .id(1L) + .statusId(6L) + .name("Order DONE") + .build(), + OrderStatusTranslation.builder() + .id(2L) + .statusId(7L) + .name("Order NOT TAKEN OUT") + .build(), + OrderStatusTranslation.builder().id(3L) + .statusId(8L) + .name("Order CANCELLED") + .build()); } public static List getOrderStatusPaymentTranslations() { return List.of(OrderPaymentStatusTranslation.builder() - .id(1L) - .translationValue("тест") - .translationsValueEng("test") - .orderPaymentStatusId(1L) - .build(), - OrderPaymentStatusTranslation.builder() - .id(2L) - .translationValue("тест2") - .translationsValueEng("test2") - .orderPaymentStatusId(2L) - .build(), - OrderPaymentStatusTranslation.builder() - .id(3L) - .translationValue("тест3") - .translationsValueEng("test3") - .orderPaymentStatusId(3L) - .build(), - OrderPaymentStatusTranslation.builder() - .id(4L) - .translationValue("тест4") - .translationsValueEng("test4") - .orderPaymentStatusId(4L) - .build()); + .id(1L) + .translationValue("тест") + .translationsValueEng("test") + .orderPaymentStatusId(1L) + .build(), + OrderPaymentStatusTranslation.builder() + .id(2L) + .translationValue("тест2") + .translationsValueEng("test2") + .orderPaymentStatusId(2L) + .build(), + OrderPaymentStatusTranslation.builder() + .id(3L) + .translationValue("тест3") + .translationsValueEng("test3") + .orderPaymentStatusId(3L) + .build(), + OrderPaymentStatusTranslation.builder() + .id(4L) + .translationValue("тест4") + .translationsValueEng("test4") + .orderPaymentStatusId(4L) + .build()); } public static BagInfoDto getBagInfoDto() { return BagInfoDto.builder() - .id(1) - .name("name") - .nameEng("name") - .price(100.) - .capacity(10) - .build(); + .id(1) + .name("name") + .nameEng("name") + .price(100.) + .capacity(10) + .build(); } public static PaymentTableInfoDto getPaymentTableInfoDto() { return PaymentTableInfoDto.builder() - .paidAmount(200d) - .unPaidAmount(0d) - .paymentInfoDtos(List.of(getInfoPayment().setAmount(10d))) - .overpayment(800d) - .build(); + .paidAmount(200d) + .unPaidAmount(0d) + .paymentInfoDtos(List.of(getInfoPayment().setAmount(10d))) + .overpayment(800d) + .build(); } public static PaymentTableInfoDto getPaymentTableInfoDto2() { return PaymentTableInfoDto.builder() - .paidAmount(0d) - .unPaidAmount(0d) - .paymentInfoDtos(Collections.emptyList()) - .overpayment(400d) - .build(); + .paidAmount(0d) + .unPaidAmount(0d) + .paymentInfoDtos(Collections.emptyList()) + .overpayment(400d) + .build(); } public static PaymentInfoDto getInfoPayment() { return PaymentInfoDto.builder() - .comment("ddd") - .id(1L) - .amount(10d) - .build(); + .comment("ddd") + .id(1L) + .amount(10d) + .build(); } public static OrderPaymentStatusTranslation getOrderPaymentStatusTranslation() { return OrderPaymentStatusTranslation.builder() - .id(1L) - .orderPaymentStatusId(1L) - .translationValue("Абв") - .translationsValueEng("Abc") - .build(); + .id(1L) + .orderPaymentStatusId(1L) + .translationValue("Абв") + .translationsValueEng("Abc") + .build(); } public static OrderFondyClientDto getOrderFondyClientDto() { return OrderFondyClientDto.builder() - .orderId(1L) - .pointsToUse(100) - .build(); + .orderId(1L) + .pointsToUse(100) + .build(); } public static Order getOrderCount() { return Order.builder() - .id(1L) - .pointsToUse(1) - .counterOrderPaymentId(2L) - .orderPaymentStatus(OrderPaymentStatus.HALF_PAID) - .payment(Lists.newArrayList(Payment.builder() - .paymentId("1L") - .amount(200L) - .currency("UAH") - .settlementDate("20.02.1990") - .comment("avb") - .paymentStatus(PaymentStatus.PAID) - .build())) - .build(); + .id(1L) + .pointsToUse(1) + .counterOrderPaymentId(2L) + .orderPaymentStatus(OrderPaymentStatus.HALF_PAID) + .payment(Lists.newArrayList(Payment.builder() + .paymentId("1L") + .amount(200L) + .currency("UAH") + .settlementDate("20.02.1990") + .comment("avb") + .paymentStatus(PaymentStatus.PAID) + .build())) + .build(); } public static Order getOrderCountWithPaymentStatusPaid() { return Order.builder() - .id(1L) - .pointsToUse(1) - .counterOrderPaymentId(2L) - .orderPaymentStatus(OrderPaymentStatus.PAID) - .build(); + .id(1L) + .pointsToUse(1) + .counterOrderPaymentId(2L) + .orderPaymentStatus(OrderPaymentStatus.PAID) + .build(); } public static UpdateOrderPageAdminDto updateOrderPageAdminDto() { return UpdateOrderPageAdminDto.builder() - .generalOrderInfo(OrderDetailStatusRequestDto - .builder() - .orderStatus(String.valueOf(OrderStatus.CONFIRMED)) - .orderPaymentStatus(String.valueOf(PaymentStatus.PAID)) - .adminComment("aaa") - .build()) - .userInfoDto(UbsCustomersDtoUpdate - .builder() - .recipientId(2L) - .recipientName("aaaaa") - .recipientPhoneNumber("085555") - .recipientEmail("yura@333gmail.com") - .build()) - .addressExportDetailsDto(OrderAddressExportDetailsDtoUpdate - .builder() - .addressId(1L) - .addressDistrict("District") - .addressDistrictEng("DistrictEng") - .addressStreet("Street") - .addressStreetEng("StreetEng") - .addressEntranceNumber("12") - .addressHouseCorpus("123") - .addressHouseNumber("121") - .addressCity("City") - .addressCityEng("CityEng") - .addressRegion("Region") - .addressRegionEng("RegionEng") - .build()) - .ecoNumberFromShop(EcoNumberDto.builder() - .ecoNumber(Set.of("1111111111")) - .build()) - .exportDetailsDto(ExportDetailsDtoUpdate - .builder() - .dateExport("1997-12-04T15:40:24") - .timeDeliveryFrom("1997-12-04T15:40:24") - .timeDeliveryTo("1990-12-11T19:30:30") - .receivingStationId(1L) - .build()) - .orderDetailDto( - UpdateOrderDetailDto.builder() - .amountOfBagsConfirmed(Map.ofEntries(Map.entry(1, 1))) - .amountOfBagsExported(Map.ofEntries(Map.entry(1, 1))) - .build()) - .updateResponsibleEmployeeDto(List.of(UpdateResponsibleEmployeeDto.builder() - .positionId(2L) - .employeeId(2L) - .build())) - .build(); + .generalOrderInfo(OrderDetailStatusRequestDto + .builder() + .orderStatus(String.valueOf(OrderStatus.CONFIRMED)) + .orderPaymentStatus(String.valueOf(PaymentStatus.PAID)) + .adminComment("aaa") + .build()) + .userInfoDto(UbsCustomersDtoUpdate + .builder() + .recipientId(2L) + .recipientName("aaaaa") + .recipientPhoneNumber("085555") + .recipientEmail("yura@333gmail.com") + .build()) + .addressExportDetailsDto(OrderAddressExportDetailsDtoUpdate + .builder() + .addressId(1L) + .addressDistrict("District") + .addressDistrictEng("DistrictEng") + .addressStreet("Street") + .addressStreetEng("StreetEng") + .addressEntranceNumber("12") + .addressHouseCorpus("123") + .addressHouseNumber("121") + .addressCity("City") + .addressCityEng("CityEng") + .addressRegion("Region") + .addressRegionEng("RegionEng") + .build()) + .ecoNumberFromShop(EcoNumberDto.builder() + .ecoNumber(Set.of("1111111111")) + .build()) + .exportDetailsDto(ExportDetailsDtoUpdate + .builder() + .dateExport("1997-12-04T15:40:24") + .timeDeliveryFrom("1997-12-04T15:40:24") + .timeDeliveryTo("1990-12-11T19:30:30") + .receivingStationId(1L) + .build()) + .orderDetailDto( + UpdateOrderDetailDto.builder() + .amountOfBagsConfirmed(Map.ofEntries(Map.entry(1, 1))) + .amountOfBagsExported(Map.ofEntries(Map.entry(1, 1))) + .build()) + .updateResponsibleEmployeeDto(List.of(UpdateResponsibleEmployeeDto.builder() + .positionId(2L) + .employeeId(2L) + .build())) + .build(); } public static UpdateOrderPageAdminDto updateOrderPageAdminDtoWithNullFields() { return UpdateOrderPageAdminDto.builder() - .generalOrderInfo(OrderDetailStatusRequestDto - .builder() - .orderStatus(String.valueOf(OrderStatus.DONE)) - .build()) - .exportDetailsDto(ExportDetailsDtoUpdate - .builder() - .dateExport(null) - .timeDeliveryFrom(null) - .timeDeliveryTo(null) - .receivingStationId(null) - .build()) - .build(); + .generalOrderInfo(OrderDetailStatusRequestDto + .builder() + .orderStatus(String.valueOf(OrderStatus.DONE)) + .build()) + .exportDetailsDto(ExportDetailsDtoUpdate + .builder() + .dateExport(null) + .timeDeliveryFrom(null) + .timeDeliveryTo(null) + .receivingStationId(null) + .build()) + .build(); } public static UpdateOrderPageAdminDto updateOrderPageAdminDtoWithStatusCanceled() { return UpdateOrderPageAdminDto.builder() - .generalOrderInfo(OrderDetailStatusRequestDto - .builder() - .orderStatus(String.valueOf(OrderStatus.FORMED)) - .build()) - .exportDetailsDto(ExportDetailsDtoUpdate - .builder() - .dateExport(null) - .timeDeliveryFrom(null) - .timeDeliveryTo(null) - .receivingStationId(null) - .build()) - .build(); + .generalOrderInfo(OrderDetailStatusRequestDto + .builder() + .orderStatus(String.valueOf(OrderStatus.FORMED)) + .build()) + .exportDetailsDto(ExportDetailsDtoUpdate + .builder() + .dateExport(null) + .timeDeliveryFrom(null) + .timeDeliveryTo(null) + .receivingStationId(null) + .build()) + .build(); } public static UpdateOrderPageAdminDto updateOrderPageAdminDtoWithStatusBroughtItHimself() { return UpdateOrderPageAdminDto.builder() - .generalOrderInfo(OrderDetailStatusRequestDto - .builder() - .orderStatus(String.valueOf(OrderStatus.DONE)) - .build()) - .exportDetailsDto(ExportDetailsDtoUpdate - .builder() - .dateExport("2023-12-16T16:30") - .timeDeliveryFrom("2023-12-16T19:00") - .timeDeliveryTo("2023-12-16T20:30") - .receivingStationId(2L) - .build()) - .build(); + .generalOrderInfo(OrderDetailStatusRequestDto + .builder() + .orderStatus(String.valueOf(OrderStatus.DONE)) + .build()) + .exportDetailsDto(ExportDetailsDtoUpdate + .builder() + .dateExport("2023-12-16T16:30") + .timeDeliveryFrom("2023-12-16T19:00") + .timeDeliveryTo("2023-12-16T20:30") + .receivingStationId(2L) + .build()) + .build(); } public static UpdateOrderPageAdminDto updateOrderPageAdminDtoWithStatusFormed() { return UpdateOrderPageAdminDto.builder() - .generalOrderInfo(OrderDetailStatusRequestDto - .builder() - .orderStatus(String.valueOf(OrderStatus.FORMED)) - .build()) - .exportDetailsDto(ExportDetailsDtoUpdate - .builder() - .dateExport(null) - .timeDeliveryFrom(null) - .timeDeliveryTo(null) - .receivingStationId(null) - .build()) - .build(); + .generalOrderInfo(OrderDetailStatusRequestDto + .builder() + .orderStatus(String.valueOf(OrderStatus.FORMED)) + .build()) + .exportDetailsDto(ExportDetailsDtoUpdate + .builder() + .dateExport(null) + .timeDeliveryFrom(null) + .timeDeliveryTo(null) + .receivingStationId(null) + .build()) + .build(); } public static Location getLocationDto() { return Location.builder() - .id(1L) - .locationStatus(LocationStatus.DEACTIVATED) - .nameUk("Київ") - .nameEn("Kyiv") - .build(); + .id(1L) + .locationStatus(LocationStatus.DEACTIVATED) + .nameUk("Київ") + .nameEn("Kyiv") + .build(); } public static Bag bagDto() { return Bag.builder() - .id(1) - .limitIncluded(false) - .description("Description") - .descriptionEng("DescriptionEng") - .name("Test") - .nameEng("a") - .createdBy(getEmployee()) - .editedBy(getEmployee()) - .build(); + .id(1) + .limitIncluded(false) + .description("Description") + .descriptionEng("DescriptionEng") + .name("Test") + .nameEng("a") + .createdBy(getEmployee()) + .editedBy(getEmployee()) + .build(); } public static OrderStatusTranslation getOrderStatusTranslation() { return OrderStatusTranslation - .builder() - .statusId(1L) - .id(1L) - .name("ua") - .build(); + .builder() + .statusId(1L) + .id(1L) + .name("ua") + .build(); } public static Order getOrdersDto() { return Order.builder() - .id(1L) - .payment(List.of(Payment.builder().id(1L).build())) - .user(User.builder().id(1L).build()) - .imageReasonNotTakingBags(List.of("ss")) - .reasonNotTakingBagDescription("aa") - .orderStatus(OrderStatus.CANCELED) - .counterOrderPaymentId(1L) - .build(); + .id(1L) + .payment(List.of(Payment.builder().id(1L).build())) + .user(User.builder().id(1L).build()) + .imageReasonNotTakingBags(List.of("ss")) + .reasonNotTakingBagDescription("aa") + .orderStatus(OrderStatus.CANCELED) + .counterOrderPaymentId(1L) + .build(); } public static UserProfileUpdateDto updateUserProfileDto() { return UserProfileUpdateDto.builder() - .recipientName("Taras") - .recipientSurname("Ivanov") - .recipientPhone("962473289") - .addressDto(addressDtoList()) - .telegramIsNotify(true) - .viberIsNotify(false) - .build(); + .recipientName("Taras") + .recipientSurname("Ivanov") + .recipientPhone("962473289") + .addressDto(addressDtoList()) + .telegramIsNotify(true) + .viberIsNotify(false) + .build(); } public static List getAllRegion() { return List.of(Region.builder() - .id(1L) - .ukrName("Київська область") - .enName("Kyiv region") - .locations(getLocationList()) - .build()); + .id(1L) + .ukrName("Київська область") + .enName("Kyiv region") + .locations(getLocationList()) + .build()); } public static List getRegionTranslationsDto() { return List.of( - RegionTranslationDto.builder().languageCode("ua").regionName("Київська область").build(), - RegionTranslationDto.builder().regionName("Kyiv region").languageCode("en").build()); + RegionTranslationDto.builder().languageCode("ua").regionName("Київська область").build(), + RegionTranslationDto.builder().regionName("Kyiv region").languageCode("en").build()); } public static List getLocationCreateDtoList() { return List.of(LocationCreateDto.builder() - .addLocationDtoList(getAddLocationTranslationDtoList()) - .regionTranslationDtos(getRegionTranslationsDto()) - .longitude(3.34d) - .latitude(1.32d) - .build()); + .addLocationDtoList(getAddLocationTranslationDtoList()) + .regionTranslationDtos(getRegionTranslationsDto()) + .longitude(3.34d) + .latitude(1.32d) + .build()); } public static List getAddLocationTranslationDtoList() { return List.of( - AddLocationTranslationDto.builder().locationName("Київ").languageCode("ua").build(), - AddLocationTranslationDto.builder().locationName("Kyiv").languageCode("en").build()); + AddLocationTranslationDto.builder().locationName("Київ").languageCode("ua").build(), + AddLocationTranslationDto.builder().locationName("Kyiv").languageCode("en").build()); } public static Region getRegion() { return Region.builder() - .id(1L) - .ukrName("Київська область") - .enName("Kyiv region") - .locations(List.of(getLocation())) - .build(); + .id(1L) + .ukrName("Київська область") + .enName("Kyiv region") + .locations(List.of(getLocation())) + .build(); } public static Region getRegionForMapper() { return Region.builder() - .id(1L) - .ukrName("Київська область") - .enName("Kyiv region") - .build(); + .id(1L) + .ukrName("Київська область") + .enName("Kyiv region") + .build(); } public static LocationInfoDto getInfoAboutLocationDto() { return LocationInfoDto.builder() - .regionId(1L) - .regionTranslationDtos(getRegionTranslationsDto()) - .locationsDto(getLocationsDto()).build(); + .regionId(1L) + .regionTranslationDtos(getRegionTranslationsDto()) + .locationsDto(getLocationsDto()).build(); } public static List getLocationsDto() { return List.of(LocationsDto.builder() - .locationTranslationDtoList(getLocationTranslationDto()) - .locationStatus("ACTIVE") - .longitude(3.34d) - .latitude(1.32d) - .build()); + .locationTranslationDtoList(getLocationTranslationDto()) + .locationStatus("ACTIVE") + .longitude(3.34d) + .latitude(1.32d) + .build()); } public static List getLocationTranslationDto() { return List.of(LocationTranslationDto.builder() - .locationName("Київ") - .languageCode("ua") - .build(), - LocationTranslationDto.builder() - .locationName("Kyiv") - .languageCode("en").build()); + .locationName("Київ") + .languageCode("ua") + .build(), + LocationTranslationDto.builder() + .locationName("Kyiv") + .languageCode("en").build()); } public static List getCourierDtoList() { return List.of(CourierDto.builder() - .courierId(1L) - .courierStatus("ACTIVE") - .nameUk("Тест") - .nameEn("Test") - .build()); + .courierId(1L) + .courierStatus("ACTIVE") + .nameUk("Тест") + .nameEn("Test") + .build()); } public static Location getLocationForCreateRegion() { return Location.builder() - .locationStatus(LocationStatus.ACTIVE) - .nameUk("Київ").nameEn("Kyiv") - .coordinates(Coordinates.builder() - .longitude(3.34d) - .latitude(1.32d).build()) - .region(Region.builder().id(1L).enName("Kyiv region").ukrName("Київська область").build()) - .build(); + .locationStatus(LocationStatus.ACTIVE) + .nameUk("Київ").nameEn("Kyiv") + .coordinates(Coordinates.builder() + .longitude(3.34d) + .latitude(1.32d).build()) + .region(Region.builder().id(1L).enName("Kyiv region").ukrName("Київська область").build()) + .build(); } public static PaymentResponseDto getPaymentResponseDto() { return PaymentResponseDto.builder() - .order_id("1_1_1") - .payment_id(2) - .currency("a") - .amount(1) - .order_status("approved") - .response_status("failure") - .sender_cell_phone("sss") - .sender_account("ss") - .masked_card("s") - .card_type("s") - .response_code(2) - .response_description("ddd") - .order_time("s") - .settlement_date("21.12.2014") - .fee(null) - .payment_system("s") - .sender_email("s") - .payment_id(2) - .build(); + .order_id("1_1_1") + .payment_id(2) + .currency("a") + .amount(1) + .order_status("approved") + .response_status("failure") + .sender_cell_phone("sss") + .sender_account("ss") + .masked_card("s") + .card_type("s") + .response_code(2) + .response_description("ddd") + .order_time("s") + .settlement_date("21.12.2014") + .fee(null) + .payment_system("s") + .sender_email("s") + .payment_id(2) + .build(); } public static BigOrderTableViews getBigOrderTableViews() { return new BigOrderTableViews() - .setId(3333L) - .setOrderStatus("FORMED") - .setOrderPaymentStatus("PAID") - .setOrderDate(LocalDate.of(2021, 12, 8)) - .setPaymentDate(LocalDate.of(2021, 12, 8)) - .setClientName("Uliana Стан") - .setClientPhoneNumber("+380996755544") - .setClientEmail("motiy14146@ecofreon.com") - .setSenderName("Uliana Стан") - .setSenderPhone("996755544") - .setSenderEmail("motiy14146@ecofreon.com") - .setViolationsAmount(1) - .setRegion("Київська область") - .setRegionEn("Kyivs'ka oblast") - .setCity("Київ") - .setCityEn("Kyiv") - .setDistrict("Шевченківський") - .setDistrictEn("Shevchenkivs'kyi") - .setAddress("Січових Стрільців, 37, 1, 1") - .setAddressEn("Sichovyh Stril'tsiv, 37, 1, 1") - .setCommentToAddressForClient("coment") - .setBagAmount("3") - .setTotalOrderSum(50000L) - .setOrderCertificateCode("5489-2789") - .setGeneralDiscount(100L) - .setAmountDue(0L) - .setCommentForOrderByClient("commentForOrderByClient") - .setCommentForOrderByAdmin("commentForOrderByAdmin") - .setTotalPayment(20000L) - .setDateOfExport(LocalDate.of(2021, 12, 8)) - .setTimeOfExport("from 15:59:52 to 15:59:52") - .setIdOrderFromShop("3245678765") - .setReceivingStationId(1L) - .setResponsibleLogicManId(1L) - .setResponsibleDriverId(1L) - .setResponsibleCallerId(1L) - .setResponsibleNavigatorId(1L) - .setIsBlocked(true) - .setBlockedBy("Blocked Test"); + .setId(3333L) + .setOrderStatus("FORMED") + .setOrderPaymentStatus("PAID") + .setOrderDate(LocalDate.of(2021, 12, 8)) + .setPaymentDate(LocalDate.of(2021, 12, 8)) + .setClientName("Uliana Стан") + .setClientPhoneNumber("+380996755544") + .setClientEmail("motiy14146@ecofreon.com") + .setSenderName("Uliana Стан") + .setSenderPhone("996755544") + .setSenderEmail("motiy14146@ecofreon.com") + .setViolationsAmount(1) + .setRegion("Київська область") + .setRegionEn("Kyivs'ka oblast") + .setCity("Київ") + .setCityEn("Kyiv") + .setDistrict("Шевченківський") + .setDistrictEn("Shevchenkivs'kyi") + .setAddress("Січових Стрільців, 37, 1, 1") + .setAddressEn("Sichovyh Stril'tsiv, 37, 1, 1") + .setCommentToAddressForClient("coment") + .setBagAmount("3") + .setTotalOrderSum(50000L) + .setOrderCertificateCode("5489-2789") + .setGeneralDiscount(100L) + .setAmountDue(0L) + .setCommentForOrderByClient("commentForOrderByClient") + .setCommentForOrderByAdmin("commentForOrderByAdmin") + .setTotalPayment(20000L) + .setDateOfExport(LocalDate.of(2021, 12, 8)) + .setTimeOfExport("from 15:59:52 to 15:59:52") + .setIdOrderFromShop("3245678765") + .setReceivingStationId(1L) + .setResponsibleLogicManId(1L) + .setResponsibleDriverId(1L) + .setResponsibleCallerId(1L) + .setResponsibleNavigatorId(1L) + .setIsBlocked(true) + .setBlockedBy("Blocked Test"); } public static BigOrderTableDTO getBigOrderTableDto() { return new BigOrderTableDTO() - .setId(3333L) - .setOrderStatus("FORMED") - .setOrderPaymentStatus("PAID") - .setOrderDate("2021-12-08") - .setPaymentDate("2021-12-08") - .setClientName("Uliana Стан") - .setClientPhone("+380996755544") - .setClientEmail("motiy14146@ecofreon.com") - .setSenderName("Uliana Стан") - .setSenderPhone("996755544") - .setSenderEmail("motiy14146@ecofreon.com") - .setViolationsAmount(1) - .setRegion(new SenderLocation().setUa("Київська область").setEn("Kyivs'ka oblast")) - .setCity(new SenderLocation().setUa("Київ").setEn("Kyiv")) - .setDistrict(new SenderLocation().setUa("Шевченківський").setEn("Shevchenkivs'kyi")) - .setAddress( - new SenderLocation().setUa("Січових Стрільців, 37, 1, 1").setEn("Sichovyh Stril'tsiv, 37, 1, 1")) - .setCommentToAddressForClient("coment") - .setBagsAmount("3") - .setTotalOrderSum(500.) - .setOrderCertificateCode("5489-2789") - .setGeneralDiscount(100L) - .setAmountDue(0.) - .setCommentForOrderByClient("commentForOrderByClient") - .setCommentsForOrder("commentForOrderByAdmin") - .setTotalPayment(200.) - .setDateOfExport("2021-12-08") - .setTimeOfExport("from 15:59:52 to 15:59:52") - .setIdOrderFromShop("3245678765") - .setReceivingStation("1") - .setResponsibleLogicMan("1") - .setResponsibleDriver("1") - .setResponsibleCaller("1") - .setResponsibleNavigator("1") - .setIsBlocked(true) - .setBlockedBy("Blocked Test"); + .setId(3333L) + .setOrderStatus("FORMED") + .setOrderPaymentStatus("PAID") + .setOrderDate("2021-12-08") + .setPaymentDate("2021-12-08") + .setClientName("Uliana Стан") + .setClientPhone("+380996755544") + .setClientEmail("motiy14146@ecofreon.com") + .setSenderName("Uliana Стан") + .setSenderPhone("996755544") + .setSenderEmail("motiy14146@ecofreon.com") + .setViolationsAmount(1) + .setRegion(new SenderLocation().setUa("Київська область").setEn("Kyivs'ka oblast")) + .setCity(new SenderLocation().setUa("Київ").setEn("Kyiv")) + .setDistrict(new SenderLocation().setUa("Шевченківський").setEn("Shevchenkivs'kyi")) + .setAddress( + new SenderLocation().setUa("Січових Стрільців, 37, 1, 1").setEn("Sichovyh Stril'tsiv, 37, 1, 1")) + .setCommentToAddressForClient("coment") + .setBagsAmount("3") + .setTotalOrderSum(500.) + .setOrderCertificateCode("5489-2789") + .setGeneralDiscount(100L) + .setAmountDue(0.) + .setCommentForOrderByClient("commentForOrderByClient") + .setCommentsForOrder("commentForOrderByAdmin") + .setTotalPayment(200.) + .setDateOfExport("2021-12-08") + .setTimeOfExport("from 15:59:52 to 15:59:52") + .setIdOrderFromShop("3245678765") + .setReceivingStation("1") + .setResponsibleLogicMan("1") + .setResponsibleDriver("1") + .setResponsibleCaller("1") + .setResponsibleNavigator("1") + .setIsBlocked(true) + .setBlockedBy("Blocked Test"); } public static BigOrderTableDTO getBigOrderTableDtoByDateNullTest() { return new BigOrderTableDTO() - .setOrderDate("") - .setPaymentDate("") - .setDateOfExport("") - .setReceivingStation("") - .setResponsibleCaller("") - .setResponsibleDriver("") - .setResponsibleLogicMan("") - .setResponsibleNavigator("") - .setRegion(new SenderLocation().setEn(null).setUa(null)) - .setCity(new SenderLocation().setEn(null).setUa(null)) - .setDistrict(new SenderLocation().setEn(null).setUa(null)) - .setAddress(new SenderLocation().setEn(null).setUa(null)); + .setOrderDate("") + .setPaymentDate("") + .setDateOfExport("") + .setReceivingStation("") + .setResponsibleCaller("") + .setResponsibleDriver("") + .setResponsibleLogicMan("") + .setResponsibleNavigator("") + .setRegion(new SenderLocation().setEn(null).setUa(null)) + .setCity(new SenderLocation().setEn(null).setUa(null)) + .setDistrict(new SenderLocation().setEn(null).setUa(null)) + .setAddress(new SenderLocation().setEn(null).setUa(null)); } public static BigOrderTableViews getBigOrderTableViewsByDateNullTest() { return new BigOrderTableViews() - .setOrderDate(null) - .setPaymentDate(null) - .setDateOfExport(null) - .setReceivingStation(null) - .setResponsibleCaller(null) - .setResponsibleDriver(null) - .setResponsibleLogicMan(null) - .setResponsibleNavigator(null); + .setOrderDate(null) + .setPaymentDate(null) + .setDateOfExport(null) + .setReceivingStation(null) + .setResponsibleCaller(null) + .setResponsibleDriver(null) + .setResponsibleLogicMan(null) + .setResponsibleNavigator(null); } public static Order getOrderForGetOrderStatusData2Test() { @@ -3692,81 +3692,81 @@ public static Order getOrderForGetOrderStatusData2Test() { hashMap.put(2, 1); return Order.builder() - .orderBags(Arrays.asList(getOrderBag(), getOrderBag2())) + .orderBags(Arrays.asList(getOrderBag(), getOrderBag2())) + .id(1L) + .amountOfBagsOrdered(hashMap) + .confirmedQuantity(hashMap) + .exportedQuantity(hashMap) + .pointsToUse(100) + .orderStatus(OrderStatus.DONE) + .payment(Lists.newArrayList(Payment.builder() + .paymentId("1L") + .amount(200_00L) + .currency("UAH") + .settlementDate("20.02.1990") + .comment("avb") + .paymentStatus(PaymentStatus.PAID) + .build())) + .ubsUser(UBSuser.builder() + .firstName("oleh") + .lastName("ivanov") + .email("mail@mail.ua") .id(1L) - .amountOfBagsOrdered(hashMap) - .confirmedQuantity(hashMap) - .exportedQuantity(hashMap) - .pointsToUse(100) - .orderStatus(OrderStatus.DONE) - .payment(Lists.newArrayList(Payment.builder() - .paymentId("1L") - .amount(200_00L) - .currency("UAH") - .settlementDate("20.02.1990") - .comment("avb") - .paymentStatus(PaymentStatus.PAID) - .build())) - .ubsUser(UBSuser.builder() - .firstName("oleh") - .lastName("ivanov") - .email("mail@mail.ua") - .id(1L) - .phoneNumber("067894522") - .orderAddress(OrderAddress.builder() - .id(1L) - .city("Lviv") - .street("Levaya") - .district("frankivskiy") - .entranceNumber("5") - .addressComment("near mall") - .houseCorpus("1") - .houseNumber("4") - .coordinates(Coordinates.builder() - .latitude(49.83) - .longitude(23.88) - .build()) - .build()) - .build()) - .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").currentPoints(100).build()) - .certificates(Collections.emptySet()) - .pointsToUse(700) - .adminComment("Admin") - .cancellationComment("cancelled") - .receivingStation(ReceivingStation.builder() - .id(1L) - .name("Саперно-Слобідська") - .build()) - .orderPaymentStatus(OrderPaymentStatus.PAID) - .cancellationReason(CancellationReason.OUT_OF_CITY) - .writeOffStationSum(50_00L) - .imageReasonNotTakingBags(List.of("foto")) - - .tariffsInfo(TariffsInfo.builder() - .courier(Courier.builder() - .id(1L) - .build()) - .id(1L) - .tariffLocations(Set.of(TariffLocation.builder() - .id(1L) - .build())) - .max(99L) - .min(2L) - .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) + .phoneNumber("067894522") + .orderAddress(OrderAddress.builder() + .id(1L) + .city("Lviv") + .street("Levaya") + .district("frankivskiy") + .entranceNumber("5") + .addressComment("near mall") + .houseCorpus("1") + .houseNumber("4") + .coordinates(Coordinates.builder() + .latitude(49.83) + .longitude(23.88) .build()) + .build()) + .build()) + .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").currentPoints(100).build()) + .certificates(Collections.emptySet()) + .pointsToUse(700) + .adminComment("Admin") + .cancellationComment("cancelled") + .receivingStation(ReceivingStation.builder() + .id(1L) + .name("Саперно-Слобідська") + .build()) + .orderPaymentStatus(OrderPaymentStatus.PAID) + .cancellationReason(CancellationReason.OUT_OF_CITY) + .writeOffStationSum(50_00L) + .imageReasonNotTakingBags(List.of("foto")) + + .tariffsInfo(TariffsInfo.builder() + .courier(Courier.builder() + .id(1L) + .build()) + .id(1L) + .tariffLocations(Set.of(TariffLocation.builder() + .id(1L) + .build())) + .max(99L) + .min(2L) + .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) + .build()) - .build(); + .build(); } public static Order getOrderForGetOrderStatusEmptyPriceDetails() { return Order.builder() - .id(1L) - .amountOfBagsOrdered(new HashMap<>()) - .confirmedQuantity(new HashMap<>()) - .exportedQuantity(new HashMap<>()) - .pointsToUse(100) - .orderStatus(OrderStatus.DONE) - .build(); + .id(1L) + .amountOfBagsOrdered(new HashMap<>()) + .confirmedQuantity(new HashMap<>()) + .exportedQuantity(new HashMap<>()) + .pointsToUse(100) + .orderStatus(OrderStatus.DONE) + .build(); } public static Order getOrderWithoutExportedBags() { @@ -3774,387 +3774,387 @@ public static Order getOrderWithoutExportedBags() { hashMap.put(1, 1); hashMap.put(2, 1); return Order.builder() - .id(1L) - .amountOfBagsOrdered(hashMap) - .confirmedQuantity(hashMap) - .exportedQuantity(new HashMap<>()) - .pointsToUse(100) - .certificates(Collections.emptySet()) - .orderStatus(OrderStatus.CONFIRMED) - .user(User.builder().id(1L).currentPoints(100).build()) - .writeOffStationSum(50_00L) - .payment(Lists.newArrayList(Payment.builder() - .paymentId("1L") - .amount(20000L) - .currency("UAH") - .settlementDate("20.02.1990") - .comment("avb") - .paymentStatus(PaymentStatus.PAID) - .build())) - .build(); + .id(1L) + .amountOfBagsOrdered(hashMap) + .confirmedQuantity(hashMap) + .exportedQuantity(new HashMap<>()) + .pointsToUse(100) + .certificates(Collections.emptySet()) + .orderStatus(OrderStatus.CONFIRMED) + .user(User.builder().id(1L).currentPoints(100).build()) + .writeOffStationSum(50_00L) + .payment(Lists.newArrayList(Payment.builder() + .paymentId("1L") + .amount(20000L) + .currency("UAH") + .settlementDate("20.02.1990") + .comment("avb") + .paymentStatus(PaymentStatus.PAID) + .build())) + .build(); } public static Order getOrdersStatusAdjustmentDto2() { return Order.builder() - .id(1L) - .payment(List.of(Payment.builder().id(1L).build())) - .user(User.builder().id(1L).build()) - .imageReasonNotTakingBags(List.of("ss")) - .reasonNotTakingBagDescription("aa") - .orderStatus(OrderStatus.ADJUSTMENT) - .counterOrderPaymentId(1L) - .certificates(Set.of(getCertificate2())) - .pointsToUse(100) - .writeOffStationSum(50_00L) - .build(); + .id(1L) + .payment(List.of(Payment.builder().id(1L).build())) + .user(User.builder().id(1L).build()) + .imageReasonNotTakingBags(List.of("ss")) + .reasonNotTakingBagDescription("aa") + .orderStatus(OrderStatus.ADJUSTMENT) + .counterOrderPaymentId(1L) + .certificates(Set.of(getCertificate2())) + .pointsToUse(100) + .writeOffStationSum(50_00L) + .build(); } public static Order getOrdersStatusConfirmedDto() { return Order.builder() - .id(1L) - .payment(List.of(Payment.builder().id(1L).build())) - .user(User.builder().id(1L).build()) - .imageReasonNotTakingBags(List.of("ss")) - .reasonNotTakingBagDescription("aa") - .orderStatus(OrderStatus.CONFIRMED) - .counterOrderPaymentId(1L) - .build(); + .id(1L) + .payment(List.of(Payment.builder().id(1L).build())) + .user(User.builder().id(1L).build()) + .imageReasonNotTakingBags(List.of("ss")) + .reasonNotTakingBagDescription("aa") + .orderStatus(OrderStatus.CONFIRMED) + .counterOrderPaymentId(1L) + .build(); } public static Order getOrdersStatusFormedDto() { return Order.builder() - .id(1L) - .payment(List.of(Payment.builder().id(1L).build())) - .user(User.builder().id(1L).build()) - .imageReasonNotTakingBags(List.of("ss")) - .reasonNotTakingBagDescription("aa") - .orderStatus(OrderStatus.FORMED) - .counterOrderPaymentId(1L) - .pointsToUse(100) - .confirmedQuantity(Map.of(1, 1)) - .exportedQuantity(Map.of(1, 1)) - .amountOfBagsOrdered(Map.of(1, 1)) - .build(); + .id(1L) + .payment(List.of(Payment.builder().id(1L).build())) + .user(User.builder().id(1L).build()) + .imageReasonNotTakingBags(List.of("ss")) + .reasonNotTakingBagDescription("aa") + .orderStatus(OrderStatus.FORMED) + .counterOrderPaymentId(1L) + .pointsToUse(100) + .confirmedQuantity(Map.of(1, 1)) + .exportedQuantity(Map.of(1, 1)) + .amountOfBagsOrdered(Map.of(1, 1)) + .build(); } public static Order getOrdersStatusFormedDto2() { return Order.builder() - .id(1L) - .payment(List.of(Payment.builder().id(1L).build())) - .user(User.builder().id(1L).build()) - .imageReasonNotTakingBags(List.of("ss")) - .reasonNotTakingBagDescription("aa") - .orderStatus(OrderStatus.FORMED) - .counterOrderPaymentId(1L) - .pointsToUse(100) - .confirmedQuantity(Map.of(1, 3)) - .exportedQuantity(Map.of(1, 1)) - .amountOfBagsOrdered(Map.of(1, 1)) - .build(); + .id(1L) + .payment(List.of(Payment.builder().id(1L).build())) + .user(User.builder().id(1L).build()) + .imageReasonNotTakingBags(List.of("ss")) + .reasonNotTakingBagDescription("aa") + .orderStatus(OrderStatus.FORMED) + .counterOrderPaymentId(1L) + .pointsToUse(100) + .confirmedQuantity(Map.of(1, 3)) + .exportedQuantity(Map.of(1, 1)) + .amountOfBagsOrdered(Map.of(1, 1)) + .build(); } public static Order getOrdersStatusNotTakenOutDto() { return Order.builder() - .id(1L) - .payment(List.of(Payment.builder().id(1L).build())) - .user(User.builder().id(1L).build()) - .imageReasonNotTakingBags(List.of("ss")) - .reasonNotTakingBagDescription("aa") - .orderStatus(OrderStatus.NOT_TAKEN_OUT) - .counterOrderPaymentId(1L) - .build(); + .id(1L) + .payment(List.of(Payment.builder().id(1L).build())) + .user(User.builder().id(1L).build()) + .imageReasonNotTakingBags(List.of("ss")) + .reasonNotTakingBagDescription("aa") + .orderStatus(OrderStatus.NOT_TAKEN_OUT) + .counterOrderPaymentId(1L) + .build(); } public static Order getOrdersStatusOnThe_RouteDto() { return Order.builder() - .id(1L) - .payment(List.of(Payment.builder().id(1L).build())) - .user(User.builder().id(1L).build()) - .imageReasonNotTakingBags(List.of("ss")) - .reasonNotTakingBagDescription("aa") - .orderStatus(OrderStatus.ON_THE_ROUTE) - .counterOrderPaymentId(1L) - .build(); + .id(1L) + .payment(List.of(Payment.builder().id(1L).build())) + .user(User.builder().id(1L).build()) + .imageReasonNotTakingBags(List.of("ss")) + .reasonNotTakingBagDescription("aa") + .orderStatus(OrderStatus.ON_THE_ROUTE) + .counterOrderPaymentId(1L) + .build(); } public static Order getOrdersStatusBROUGHT_IT_HIMSELFDto() { return Order.builder() - .id(1L) - .payment(List.of(Payment.builder().id(1L).build())) - .user(User.builder().id(1L).build()) - .imageReasonNotTakingBags(List.of("ss")) - .reasonNotTakingBagDescription("aa") - .orderStatus(OrderStatus.BROUGHT_IT_HIMSELF) - .counterOrderPaymentId(1L) - .build(); + .id(1L) + .payment(List.of(Payment.builder().id(1L).build())) + .user(User.builder().id(1L).build()) + .imageReasonNotTakingBags(List.of("ss")) + .reasonNotTakingBagDescription("aa") + .orderStatus(OrderStatus.BROUGHT_IT_HIMSELF) + .counterOrderPaymentId(1L) + .build(); } public static Order getOrdersStatusDoneDto() { return Order.builder() - .id(1L) - .payment(List.of(Payment.builder().id(1L).build())) - .user(User.builder().id(1L).build()) - .imageReasonNotTakingBags(List.of("ss")) - .reasonNotTakingBagDescription("aa") - .orderStatus(OrderStatus.DONE) - .counterOrderPaymentId(1L) - .certificates(Set.of(Certificate.builder() - .points(0) - .build())) - .pointsToUse(0) - .build(); + .id(1L) + .payment(List.of(Payment.builder().id(1L).build())) + .user(User.builder().id(1L).build()) + .imageReasonNotTakingBags(List.of("ss")) + .reasonNotTakingBagDescription("aa") + .orderStatus(OrderStatus.DONE) + .counterOrderPaymentId(1L) + .certificates(Set.of(Certificate.builder() + .points(0) + .build())) + .pointsToUse(0) + .build(); } public static Order getOrdersStatusCanseledDto() { return Order.builder() - .id(1L) - .payment(List.of(Payment.builder().id(1L).build())) - .user(User.builder().id(1L).build()) - .imageReasonNotTakingBags(List.of("ss")) - .reasonNotTakingBagDescription("aa") - .orderStatus(OrderStatus.CANCELED) - .counterOrderPaymentId(1L) - .build(); + .id(1L) + .payment(List.of(Payment.builder().id(1L).build())) + .user(User.builder().id(1L).build()) + .imageReasonNotTakingBags(List.of("ss")) + .reasonNotTakingBagDescription("aa") + .orderStatus(OrderStatus.CANCELED) + .counterOrderPaymentId(1L) + .build(); } public static OrderAddressExportDetailsDtoUpdate getOrderAddressExportDetailsDtoUpdate() { return OrderAddressExportDetailsDtoUpdate.builder() - .addressId(1L) - .addressStreet("Street") - .addressStreetEng("StreetEng") - .addressCity("City") - .addressCityEng("City") - .addressDistrict("District") - .addressDistrictEng("DistrictEng") - .addressHouseCorpus("12") - .addressEntranceNumber("2") - .addressRegion("Region") - .addressRegionEng("RegionEng") - .addressHouseNumber("123") - .build(); + .addressId(1L) + .addressStreet("Street") + .addressStreetEng("StreetEng") + .addressCity("City") + .addressCityEng("City") + .addressDistrict("District") + .addressDistrictEng("DistrictEng") + .addressHouseCorpus("12") + .addressEntranceNumber("2") + .addressRegion("Region") + .addressRegionEng("RegionEng") + .addressHouseNumber("123") + .build(); } public static CustomTableView getCustomTableView() { return CustomTableView.builder() - .id(1L) - .uuid("uuid1") - .titles("title") - .build(); + .id(1L) + .uuid("uuid1") + .titles("title") + .build(); } public static ReadAddressByOrderDto getReadAddressByOrderDto() { return ReadAddressByOrderDto.builder() - .street("Levaya") - .district("frankivskiy") - .entranceNumber("5") - .houseCorpus("1") - .houseNumber("4") - .comment("helo") - .build(); + .street("Levaya") + .district("frankivskiy") + .entranceNumber("5") + .houseCorpus("1") + .houseNumber("4") + .comment("helo") + .build(); } public static RequestToChangeOrdersDataDto getRequestToChangeOrdersDataDTO() { return RequestToChangeOrdersDataDto.builder() - .columnName("orderStatus") - .orderIdsList(List.of(1L)) - .newValue("1") - .build(); + .columnName("orderStatus") + .orderIdsList(List.of(1L)) + .newValue("1") + .build(); } public static RequestToChangeOrdersDataDto getRequestToAddAdminCommentForOrder() { return RequestToChangeOrdersDataDto.builder() - .columnName("adminComment") - .orderIdsList(List.of(1L)) - .newValue("Admin Comment") - .build(); + .columnName("adminComment") + .orderIdsList(List.of(1L)) + .newValue("Admin Comment") + .build(); } public static List botList() { List botList = new ArrayList<>(); botList.add(new Bot() - .setType("TELEGRAM") - .setLink("https://telegram.me/ubs_test_bot?start=87df9ad5-6393-441f-8423-8b2e770b01a8")); + .setType("TELEGRAM") + .setLink("https://telegram.me/ubs_test_bot?start=87df9ad5-6393-441f-8423-8b2e770b01a8")); botList.add(new Bot() - .setType("VIBER") - .setLink("viber://pa?chatURI=ubstestbot1&context=87df9ad5-6393-441f-8423-8b2e770b01a8")); + .setType("VIBER") + .setLink("viber://pa?chatURI=ubstestbot1&context=87df9ad5-6393-441f-8423-8b2e770b01a8")); return botList; } public static UpdateAllOrderPageDto updateAllOrderPageDto() { return UpdateAllOrderPageDto.builder() - .orderId(List.of(1L)) - .exportDetailsDto(ExportDetailsDtoUpdate - .builder() - .dateExport("1997-12-04T15:40:24") - .timeDeliveryFrom("1997-12-04T15:40:24") - .timeDeliveryTo("1990-12-11T19:30:30") - .receivingStationId(1L) - .build()) - .updateResponsibleEmployeeDto(List.of(UpdateResponsibleEmployeeDto.builder() - .positionId(2L) - .employeeId(2L) - .build())) - .build(); + .orderId(List.of(1L)) + .exportDetailsDto(ExportDetailsDtoUpdate + .builder() + .dateExport("1997-12-04T15:40:24") + .timeDeliveryFrom("1997-12-04T15:40:24") + .timeDeliveryTo("1990-12-11T19:30:30") + .receivingStationId(1L) + .build()) + .updateResponsibleEmployeeDto(List.of(UpdateResponsibleEmployeeDto.builder() + .positionId(2L) + .employeeId(2L) + .build())) + .build(); } public static Order getOrder2() { return Order.builder() + .id(1L) + .payment(Lists.newArrayList(Payment.builder() + .paymentId("1") + .amount(20000L) + .currency("UAH") + .settlementDate("20.02.1990") + .comment("avb") + .paymentStatus(PaymentStatus.PAID) + .build())) + .ubsUser(UBSuser.builder() + .firstName("oleh") + .lastName("ivanov") + .email("mail@mail.ua") .id(1L) - .payment(Lists.newArrayList(Payment.builder() - .paymentId("1") - .amount(20000L) - .currency("UAH") - .settlementDate("20.02.1990") - .comment("avb") - .paymentStatus(PaymentStatus.PAID) - .build())) - .ubsUser(UBSuser.builder() - .firstName("oleh") - .lastName("ivanov") - .email("mail@mail.ua") - .id(1L) - .phoneNumber("067894522") - .orderAddress(OrderAddress.builder() - .id(1L) - .city("Lviv") - .street("Levaya") - .district("frankivskiy") - .entranceNumber("5") - .addressComment("near mall") - .houseCorpus("1") - .houseNumber("4") - .coordinates(Coordinates.builder() - .latitude(49.83) - .longitude(23.88) - .build()) - .build()) - .build()) - .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").build()) - .certificates(Collections.emptySet()) - .pointsToUse(700) - .adminComment("Admin") - .cancellationComment("cancelled") - .receivingStation(ReceivingStation.builder() - .id(1L) - .name("Саперно-Слобідська") + .phoneNumber("067894522") + .orderAddress(OrderAddress.builder() + .id(1L) + .city("Lviv") + .street("Levaya") + .district("frankivskiy") + .entranceNumber("5") + .addressComment("near mall") + .houseCorpus("1") + .houseNumber("4") + .coordinates(Coordinates.builder() + .latitude(49.83) + .longitude(23.88) .build()) - .orderPaymentStatus(OrderPaymentStatus.PAID) - .cancellationReason(CancellationReason.OUT_OF_CITY) - .imageReasonNotTakingBags(List.of("foto")) - .orderPaymentStatus(OrderPaymentStatus.UNPAID) - .additionalOrders(new HashSet<>()) - .build(); + .build()) + .build()) + .user(User.builder().id(1L).recipientName("Yuriy").recipientSurname("Gerasum").build()) + .certificates(Collections.emptySet()) + .pointsToUse(700) + .adminComment("Admin") + .cancellationComment("cancelled") + .receivingStation(ReceivingStation.builder() + .id(1L) + .name("Саперно-Слобідська") + .build()) + .orderPaymentStatus(OrderPaymentStatus.PAID) + .cancellationReason(CancellationReason.OUT_OF_CITY) + .imageReasonNotTakingBags(List.of("foto")) + .orderPaymentStatus(OrderPaymentStatus.UNPAID) + .additionalOrders(new HashSet<>()) + .build(); } public static AddBonusesToUserDto getAddBonusesToUserDto() { return AddBonusesToUserDto.builder() - .paymentId("5") - .receiptLink("test") - .settlementdate("test") - .amount(1000L) - .build(); + .paymentId("5") + .receiptLink("test") + .settlementdate("test") + .amount(1000L) + .build(); } public static GetTariffsInfoDto getAllTariffsInfoDto() { Location location = getLocation(); return GetTariffsInfoDto.builder() - .cardId(1L) - .locationInfoDtos(List.of(LocationsDtos.builder() - .locationId(location.getId()) - .nameEn(location.getNameEn()) - .nameUk(location.getNameUk()).build())) - .courierDto(getCourierDto()) - .createdAt(LocalDate.of(22, 2, 12)) - .creator(EmployeeNameDto.builder() - .email("sss@gmail.com").build()) - .build(); + .cardId(1L) + .locationInfoDtos(List.of(LocationsDtos.builder() + .locationId(location.getId()) + .nameEn(location.getNameEn()) + .nameUk(location.getNameUk()).build())) + .courierDto(getCourierDto()) + .createdAt(LocalDate.of(22, 2, 12)) + .creator(EmployeeNameDto.builder() + .email("sss@gmail.com").build()) + .build(); } public static GetTariffLimitsDto getGetTariffLimitsDto() { return GetTariffLimitsDto.builder() - .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) - .max(20L) - .min(2L) - .build(); + .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) + .max(20L) + .min(2L) + .build(); } public static TariffsInfo getTariffsInfo() { return TariffsInfo.builder() - .id(1L) - .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) - .max(20L) - .min(2L) - .tariffLocations(Set.of(TariffLocation.builder() - .location(getLocation()) - .build())) - .receivingStationList(Set.of(getReceivingStation())) - .courier(getCourier()) - .service(getService()) - .build(); + .id(1L) + .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) + .max(20L) + .min(2L) + .tariffLocations(Set.of(TariffLocation.builder() + .location(getLocation()) + .build())) + .receivingStationList(Set.of(getReceivingStation())) + .courier(getCourier()) + .service(getService()) + .build(); } public static TariffsInfo getTariffsInfoActive() { return TariffsInfo.builder() - .id(1L) - .tariffStatus(TariffStatus.ACTIVE) - .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) - .max(20L) - .min(2L) - .tariffLocations(Set.of(TariffLocation.builder() - .location(getLocation()) - .build())) - .receivingStationList(Set.of(getReceivingStation())) - .courier(getCourier()) - .service(getService()) - .bags(getBag4list()) - .build(); + .id(1L) + .tariffStatus(TariffStatus.ACTIVE) + .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) + .max(20L) + .min(2L) + .tariffLocations(Set.of(TariffLocation.builder() + .location(getLocation()) + .build())) + .receivingStationList(Set.of(getReceivingStation())) + .courier(getCourier()) + .service(getService()) + .bags(getBag4list()) + .build(); } public static TariffsInfo getTariffsInfoDeactivated() { return TariffsInfo.builder() - .id(1L) - .tariffStatus(TariffStatus.DEACTIVATED) - .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) - .max(20L) - .min(2L) - .tariffLocations(Set.of(TariffLocation.builder() - .location(getLocation()) - .build())) - .receivingStationList(Set.of(getReceivingStation())) - .courier(getCourier()) - .service(getService()) - .bags(getBag4list()) - .build(); + .id(1L) + .tariffStatus(TariffStatus.DEACTIVATED) + .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) + .max(20L) + .min(2L) + .tariffLocations(Set.of(TariffLocation.builder() + .location(getLocation()) + .build())) + .receivingStationList(Set.of(getReceivingStation())) + .courier(getCourier()) + .service(getService()) + .bags(getBag4list()) + .build(); } public static OrdersDataForUserDto getOrderStatusDto() { SenderInfoDto senderInfoDto = SenderInfoDto.builder() - .senderName("TestName") - .senderSurname("TestSurName") - .senderPhone("38099884433") - .senderEmail("test@mail.com") - .build(); + .senderName("TestName") + .senderSurname("TestSurName") + .senderPhone("38099884433") + .senderEmail("test@mail.com") + .build(); CertificateDto certificateDto = CertificateDto.builder() - .points(300) - .dateOfUse(LocalDate.now()) - .expirationDate(LocalDate.now()) - .code("200") - .certificateStatus("ACTIVE") - .build(); + .points(300) + .dateOfUse(LocalDate.now()) + .expirationDate(LocalDate.now()) + .code("200") + .certificateStatus("ACTIVE") + .build(); AddressInfoDto addressInfoDto = AddressInfoDto.builder() - .addressStreet("StreetTest") - .addressDistinct("AdressDistinctTest") - .addressRegion("TestRegion") - .addressComment("TestComment") - .addressCity("TestCity") - .addressStreetEng("StreetEng") - .addressDistinctEng("DisticntEng") - .addressCityEng("CityEng") - .addressRegionEng("RegionEng") - .build(); + .addressStreet("StreetTest") + .addressDistinct("AdressDistinctTest") + .addressRegion("TestRegion") + .addressComment("TestComment") + .addressCity("TestCity") + .addressStreetEng("StreetEng") + .addressDistinctEng("DisticntEng") + .addressCityEng("CityEng") + .addressRegionEng("RegionEng") + .build(); BagForUserDto bagForUserDto = new BagForUserDto(); bagForUserDto.setTotalPrice(900.); @@ -4165,162 +4165,162 @@ public static OrdersDataForUserDto getOrderStatusDto() { bagForUserDto.setServiceEng("Safe Waste"); return OrdersDataForUserDto.builder() - .id(1L) - .dateForm(LocalDateTime.of(22, 10, 12, 14, 55)) - .datePaid(LocalDateTime.now()) - .amountBeforePayment(500d) - .bonuses(100d) - .orderFullPrice(400d) - .orderComment("abc") - .paymentStatus(PaymentStatus.PAID.toString()) - .sender(senderInfoDto) - .address(addressInfoDto) - .paymentStatusEng(PaymentStatus.PAID.toString()) - .orderStatus(OrderStatus.FORMED.toString()) - .orderStatusEng(OrderStatus.FORMED.toString()) - .bags(List.of(bagForUserDto)) - .certificate(List.of(certificateDto)) - .additionalOrders(Collections.emptySet()) - .build(); + .id(1L) + .dateForm(LocalDateTime.of(22, 10, 12, 14, 55)) + .datePaid(LocalDateTime.now()) + .amountBeforePayment(500d) + .bonuses(100d) + .orderFullPrice(400d) + .orderComment("abc") + .paymentStatus(PaymentStatus.PAID.toString()) + .sender(senderInfoDto) + .address(addressInfoDto) + .paymentStatusEng(PaymentStatus.PAID.toString()) + .orderStatus(OrderStatus.FORMED.toString()) + .orderStatusEng(OrderStatus.FORMED.toString()) + .bags(List.of(bagForUserDto)) + .certificate(List.of(certificateDto)) + .additionalOrders(Collections.emptySet()) + .build(); } public static TariffsInfo getTariffInfo() { return TariffsInfo.builder() + .id(1L) + .courier(ModelUtils.getCourier()) + .courierLimit(CourierLimit.LIMIT_BY_SUM_OF_ORDER) + .tariffLocations(Set.of(TariffLocation.builder() + .tariffsInfo(ModelUtils.getTariffInfoWithLimitOfBags()) + .locationStatus(LocationStatus.ACTIVE) + .location(Location.builder().id(1L) + .locationStatus(LocationStatus.ACTIVE) + .region(ModelUtils.getRegion()) + .nameUk("Київ") + .nameEn("Kyiv") + .coordinates(ModelUtils.getCoordinates()) + .build()) + .build())) + .tariffStatus(TariffStatus.ACTIVE) + .creator(ModelUtils.getEmployee()) + .createdAt(LocalDate.of(2022, 10, 20)) + .max(6000L) + .min(500L) + .orders(Collections.emptyList()) + .receivingStationList(Set.of(ReceivingStation.builder() .id(1L) - .courier(ModelUtils.getCourier()) - .courierLimit(CourierLimit.LIMIT_BY_SUM_OF_ORDER) - .tariffLocations(Set.of(TariffLocation.builder() - .tariffsInfo(ModelUtils.getTariffInfoWithLimitOfBags()) - .locationStatus(LocationStatus.ACTIVE) - .location(Location.builder().id(1L) - .locationStatus(LocationStatus.ACTIVE) - .region(ModelUtils.getRegion()) - .nameUk("Київ") - .nameEn("Kyiv") - .coordinates(ModelUtils.getCoordinates()) - .build()) - .build())) - .tariffStatus(TariffStatus.ACTIVE) - .creator(ModelUtils.getEmployee()) - .createdAt(LocalDate.of(2022, 10, 20)) - .max(6000L) - .min(500L) - .orders(Collections.emptyList()) - .receivingStationList(Set.of(ReceivingStation.builder() - .id(1L) - .name("Петрівка") - .createdBy(ModelUtils.createEmployee()) - .build())) - .build(); + .name("Петрівка") + .createdBy(ModelUtils.createEmployee()) + .build())) + .build(); } public static TariffsInfo getTariffsInfoWithStatusNew() { return TariffsInfo.builder() + .id(1L) + .courierLimit(CourierLimit.LIMIT_BY_SUM_OF_ORDER) + .tariffLocations(Set.of(TariffLocation.builder() + .tariffsInfo(ModelUtils.getTariffInfoWithLimitOfBags()) + .location(Location.builder().id(1L) + .region(ModelUtils.getRegion()) + .nameUk("Київ") + .nameEn("Kyiv") + .coordinates(ModelUtils.getCoordinates()) + .build()) + .build())) + .tariffStatus(TariffStatus.NEW) + .creator(ModelUtils.getEmployee()) + .createdAt(LocalDate.of(2022, 10, 20)) + .orders(Collections.emptyList()) + .receivingStationList(Set.of(ReceivingStation.builder() .id(1L) - .courierLimit(CourierLimit.LIMIT_BY_SUM_OF_ORDER) - .tariffLocations(Set.of(TariffLocation.builder() - .tariffsInfo(ModelUtils.getTariffInfoWithLimitOfBags()) - .location(Location.builder().id(1L) - .region(ModelUtils.getRegion()) - .nameUk("Київ") - .nameEn("Kyiv") - .coordinates(ModelUtils.getCoordinates()) - .build()) - .build())) - .tariffStatus(TariffStatus.NEW) - .creator(ModelUtils.getEmployee()) - .createdAt(LocalDate.of(2022, 10, 20)) - .orders(Collections.emptyList()) - .receivingStationList(Set.of(ReceivingStation.builder() - .id(1L) - .name("Петрівка") - .createdBy(ModelUtils.createEmployee()) - .build())) - .build(); + .name("Петрівка") + .createdBy(ModelUtils.createEmployee()) + .build())) + .build(); } public static TariffsInfo getTariffInfoWithLimitOfBags() { return TariffsInfo.builder() - .id(1L) - .courier(ModelUtils.getCourier()) - .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) - .tariffLocations(Set.of(TariffLocation.builder() - .location(Location.builder().id(1L) - .region(ModelUtils.getRegion()) - .nameUk("Київ") - .nameEn("Kyiv") - .coordinates(ModelUtils.getCoordinates()) - .build()) - .build())) - .tariffStatus(TariffStatus.ACTIVE) - .creator(ModelUtils.getEmployee()) - .createdAt(LocalDate.of(2022, 10, 20)) - .max(100L) - .min(5L) - .orders(List.of(ModelUtils.getOrder())) - .build(); + .id(1L) + .courier(ModelUtils.getCourier()) + .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) + .tariffLocations(Set.of(TariffLocation.builder() + .location(Location.builder().id(1L) + .region(ModelUtils.getRegion()) + .nameUk("Київ") + .nameEn("Kyiv") + .coordinates(ModelUtils.getCoordinates()) + .build()) + .build())) + .tariffStatus(TariffStatus.ACTIVE) + .creator(ModelUtils.getEmployee()) + .createdAt(LocalDate.of(2022, 10, 20)) + .max(100L) + .min(5L) + .orders(List.of(ModelUtils.getOrder())) + .build(); } public static TariffsInfo getTariffInfoWithLimitOfBagsAndMaxLessThanCountOfBigBag() { return TariffsInfo.builder() - .id(1L) - .courier(ModelUtils.getCourier()) - .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) - .tariffLocations(Set.of(TariffLocation.builder() - .location(Location.builder().id(1L) - .region(ModelUtils.getRegion()) - .nameUk("Київ") - .nameEn("Kyiv") - .coordinates(ModelUtils.getCoordinates()) - .build()) - .build())) - .tariffStatus(TariffStatus.ACTIVE) - .creator(ModelUtils.getEmployee()) - .createdAt(LocalDate.of(2022, 10, 20)) - .max(10L) - .min(5L) - .orders(List.of(ModelUtils.getOrder())) - .build(); + .id(1L) + .courier(ModelUtils.getCourier()) + .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) + .tariffLocations(Set.of(TariffLocation.builder() + .location(Location.builder().id(1L) + .region(ModelUtils.getRegion()) + .nameUk("Київ") + .nameEn("Kyiv") + .coordinates(ModelUtils.getCoordinates()) + .build()) + .build())) + .tariffStatus(TariffStatus.ACTIVE) + .creator(ModelUtils.getEmployee()) + .createdAt(LocalDate.of(2022, 10, 20)) + .max(10L) + .min(5L) + .orders(List.of(ModelUtils.getOrder())) + .build(); } public static AddNewTariffDto getAddNewTariffDto() { return AddNewTariffDto.builder() - .courierId(1L) - .locationIdList(List.of(1L)) - .receivingStationsIdList(List.of(1L)) - .regionId(1L) - .build(); + .courierId(1L) + .locationIdList(List.of(1L)) + .receivingStationsIdList(List.of(1L)) + .regionId(1L) + .build(); } public static EditTariffDto getEditTariffDto() { return EditTariffDto.builder() - .locationIds(List.of(1L)) - .receivingStationIds(List.of(1L)) - .courierId(1L) - .build(); + .locationIds(List.of(1L)) + .receivingStationIds(List.of(1L)) + .courierId(1L) + .build(); } public static EditTariffDto getEditTariffDtoWithoutCourier() { return EditTariffDto.builder() - .locationIds(List.of(1L)) - .receivingStationIds(List.of(1L)) - .build(); + .locationIds(List.of(1L)) + .receivingStationIds(List.of(1L)) + .build(); } public static EditTariffDto getEditTariffDtoWith2Locations() { return EditTariffDto.builder() - .locationIds(List.of(1L, 2L)) - .receivingStationIds(List.of(1L)) - .build(); + .locationIds(List.of(1L, 2L)) + .receivingStationIds(List.of(1L)) + .build(); } public static String getSuccessfulFondyResponse() { return "{\n" + - " \"response\":{\n" + - " \"response_status\":\"success\",\n" + - " \"checkout_url\":\"https://pay.fondy.eu/checkout?token=afcb21aef707b1fea2565b66bac7dc41d7833390\"\n" + - " }\n" + - "}"; + " \"response\":{\n" + + " \"response_status\":\"success\",\n" + + " \"checkout_url\":\"https://pay.fondy.eu/checkout?token=afcb21aef707b1fea2565b66bac7dc41d7833390\"\n" + + " }\n" + + "}"; } public static List getGeocodingResult() { @@ -4352,11 +4352,11 @@ public static List getGeocodingResult() { route.types = new AddressComponentType[] {AddressComponentType.ROUTE}; geocodingResult1.addressComponents = new AddressComponent[] { - locality, - streetNumber, - region, - sublocality, - route + locality, + streetNumber, + region, + sublocality, + route }; geocodingResult1.formattedAddress = "fake address"; @@ -4385,11 +4385,11 @@ public static List getGeocodingResult() { route2.types = new AddressComponentType[] {AddressComponentType.ROUTE}; geocodingResult2.addressComponents = new AddressComponent[] { - locality2, - streetNumber2, - region2, - sublocality2, - route2 + locality2, + streetNumber2, + region2, + sublocality2, + route2 }; geocodingResult2.formattedAddress = "fake address 2"; @@ -4403,37 +4403,37 @@ public static List getGeocodingResult() { public static CreateAddressRequestDto getAddressRequestDto() { return CreateAddressRequestDto.builder() - .addressComment("fdsfs") - .searchAddress("fake street name, 13, fake street, 02000") - .district("fdsfds") - .districtEn("dsadsad") - .region("regdsad") - .regionEn("regdsaden") - .houseNumber("1") - .houseCorpus("2") - .entranceNumber("3") - .placeId("place_id") - .build(); + .addressComment("fdsfs") + .searchAddress("fake street name, 13, fake street, 02000") + .district("fdsfds") + .districtEn("dsadsad") + .region("regdsad") + .regionEn("regdsaden") + .houseNumber("1") + .houseCorpus("2") + .entranceNumber("3") + .placeId("place_id") + .build(); } public static OrderAddressDtoRequest getTestOrderAddressDtoRequest() { return OrderAddressDtoRequest.builder() - .id(0L) - .region("fake region") - .searchAddress("fake street name, 13, fake street, 02000") - .city("fake street") - .district("fake district") - .entranceNumber("1") - .houseNumber("13") - .houseCorpus("1") - .street("fake street name") - .streetEn("fake street name") - .coordinates(new Coordinates(50.5555555d, 50.5555555d)) - .cityEn("fake street") - .districtEn("fake district") - .regionEn("fake region") - .placeId("place_id") - .build(); + .id(0L) + .region("fake region") + .searchAddress("fake street name, 13, fake street, 02000") + .city("fake street") + .district("fake district") + .entranceNumber("1") + .houseNumber("13") + .houseCorpus("1") + .street("fake street name") + .streetEn("fake street name") + .coordinates(new Coordinates(50.5555555d, 50.5555555d)) + .cityEn("fake street") + .districtEn("fake district") + .regionEn("fake region") + .placeId("place_id") + .build(); } public static OrderAddressDtoRequest getTestOrderAddressLocationDto() { @@ -4442,21 +4442,21 @@ public static OrderAddressDtoRequest getTestOrderAddressLocationDto() { public static OrderAddressDtoRequest getTestOrderAddressLocationDto(boolean withDistrictRegionHouse) { return OrderAddressDtoRequest.builder() - .id(0L) - .region(withDistrictRegionHouse ? "fake region" : null) - .city("fake street") - .district(withDistrictRegionHouse ? "fake district" : null) - .entranceNumber("1") - .houseNumber("13") - .houseCorpus("1") - .street("fake street name") - .streetEn("fake street name") - .coordinates(new Coordinates(50.5555555d, 50.5555555d)) - .cityEn("fake street") - .districtEn(withDistrictRegionHouse ? "fake district" : null) - .regionEn(withDistrictRegionHouse ? "fake region" : null) - .placeId("place_id") - .build(); + .id(0L) + .region(withDistrictRegionHouse ? "fake region" : null) + .city("fake street") + .district(withDistrictRegionHouse ? "fake district" : null) + .entranceNumber("1") + .houseNumber("13") + .houseCorpus("1") + .street("fake street name") + .streetEn("fake street name") + .coordinates(new Coordinates(50.5555555d, 50.5555555d)) + .cityEn("fake street") + .districtEn(withDistrictRegionHouse ? "fake district" : null) + .regionEn(withDistrictRegionHouse ? "fake region" : null) + .placeId("place_id") + .build(); } public static User getUserForCreate() { @@ -4465,40 +4465,40 @@ public static User getUserForCreate() { public static User getUserForCreate(AddressStatus addressStatus) { return User.builder() - .id(1L) - .addresses(List.of(Address.builder().id(7L).city("fake street").cityEn("fake street") - .district("fake district").districtEn("fake district").region("fake region").regionEn("fake region") - .street("fake street name").streetEn("fake street name").houseNumber("13").addressStatus(addressStatus) - .coordinates(new Coordinates(50.5555555, 50.5555555)).build())) - .recipientEmail("someUser@gmail.com") - .recipientPhone("962473289") - .recipientSurname("Ivanov") - .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") - .recipientName("Taras") - .uuid("uuid") - .ubsUsers(getUbsUsers()) - .currentPoints(100) - .build(); + .id(1L) + .addresses(List.of(Address.builder().id(7L).city("fake street").cityEn("fake street") + .district("fake district").districtEn("fake district").region("fake region").regionEn("fake region") + .street("fake street name").streetEn("fake street name").houseNumber("13").addressStatus(addressStatus) + .coordinates(new Coordinates(50.5555555, 50.5555555)).build())) + .recipientEmail("someUser@gmail.com") + .recipientPhone("962473289") + .recipientSurname("Ivanov") + .uuid("87df9ad5-6393-441f-8423-8b2e770b01a8") + .recipientName("Taras") + .uuid("uuid") + .ubsUsers(getUbsUsers()) + .currentPoints(100) + .build(); } public static OrderWithAddressesResponseDto getAddressDtoResponse() { return OrderWithAddressesResponseDto.builder() - .addressList(List.of( - AddressDto.builder() - .id(1L) - .city("City") - .district("Distinct") - .entranceNumber("7a") - .houseCorpus("2") - .houseNumber("25") - .street("Street") - .coordinates(Coordinates.builder() - .latitude(50.4459068) - .longitude(30.4477005) - .build()) - .actual(false) - .build())) - .build(); + .addressList(List.of( + AddressDto.builder() + .id(1L) + .city("City") + .district("Distinct") + .entranceNumber("7a") + .houseCorpus("2") + .houseNumber("25") + .street("Street") + .coordinates(Coordinates.builder() + .latitude(50.4459068) + .longitude(30.4477005) + .build()) + .actual(false) + .build())) + .build(); } public static TariffsForLocationDto getTariffsForLocationDto() { @@ -4507,20 +4507,20 @@ public static TariffsForLocationDto getTariffsForLocationDto() { public static CertificateDto createCertificateDto() { return CertificateDto.builder() - .points(300) - .dateOfUse(LocalDate.now()) - .expirationDate(LocalDate.now()) - .code("200") - .certificateStatus("ACTIVE") - .build(); + .points(300) + .dateOfUse(LocalDate.now()) + .expirationDate(LocalDate.now()) + .code("200") + .certificateStatus("ACTIVE") + .build(); } public static CourierTranslationDto getCourierTranslationDto(Long id) { return CourierTranslationDto.builder() - .id(id) - .nameUk("Тест") - .nameEn("Test") - .build(); + .id(id) + .nameUk("Тест") + .nameEn("Test") + .build(); } public static List
getMaximumAmountOfAddresses() { @@ -4533,297 +4533,297 @@ public static List getAllAuthorities() { public static UserEmployeeAuthorityDto getUserEmployeeAuthorityDto() { return UserEmployeeAuthorityDto.builder() - .employeeEmail("test@mail.com") - .authorities(getAllAuthorities()) - .build(); + .employeeEmail("test@mail.com") + .authorities(getAllAuthorities()) + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithEmptyParams() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.empty()) - .citiesIds(Optional.empty()) - .stationsIds(Optional.empty()) - .courierId(Optional.empty()) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.empty()) + .citiesIds(Optional.empty()) + .stationsIds(Optional.empty()) + .courierId(Optional.empty()) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithRegion() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.of(List.of(1L))) - .citiesIds(Optional.empty()) - .stationsIds(Optional.empty()) - .courierId(Optional.empty()) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.of(List.of(1L))) + .citiesIds(Optional.empty()) + .stationsIds(Optional.empty()) + .courierId(Optional.empty()) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithRegionAndCities() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.of(List.of(1L))) - .citiesIds(Optional.of(List.of(1L, 11L))) - .stationsIds(Optional.empty()) - .courierId(Optional.empty()) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.of(List.of(1L))) + .citiesIds(Optional.of(List.of(1L, 11L))) + .stationsIds(Optional.empty()) + .courierId(Optional.empty()) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithCourier() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.empty()) - .citiesIds(Optional.empty()) - .stationsIds(Optional.empty()) - .courierId(Optional.of(1L)) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.empty()) + .citiesIds(Optional.empty()) + .stationsIds(Optional.empty()) + .courierId(Optional.of(1L)) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithReceivingStations() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.empty()) - .citiesIds(Optional.empty()) - .stationsIds(Optional.of(List.of(1L, 12L))) - .courierId(Optional.empty()) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.empty()) + .citiesIds(Optional.empty()) + .stationsIds(Optional.of(List.of(1L, 12L))) + .courierId(Optional.empty()) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.empty()) - .citiesIds(Optional.empty()) - .stationsIds(Optional.of(List.of(1L, 12L))) - .courierId(Optional.of(1L)) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.empty()) + .citiesIds(Optional.empty()) + .stationsIds(Optional.of(List.of(1L, 12L))) + .courierId(Optional.of(1L)) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithCourierAndRegion() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.of(List.of(1L))) - .citiesIds(Optional.empty()) - .stationsIds(Optional.empty()) - .courierId(Optional.of(1L)) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.of(List.of(1L))) + .citiesIds(Optional.empty()) + .stationsIds(Optional.empty()) + .courierId(Optional.of(1L)) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.of(List.of(1L))) - .citiesIds(Optional.of(List.of(1L, 11L))) - .stationsIds(Optional.of(List.of(1L, 12L))) - .courierId(Optional.empty()) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.of(List.of(1L))) + .citiesIds(Optional.of(List.of(1L, 11L))) + .stationsIds(Optional.of(List.of(1L, 12L))) + .courierId(Optional.empty()) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithAllParams() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.of(List.of(1L))) - .citiesIds(Optional.of(List.of(1L, 11L))) - .stationsIds(Optional.of(List.of(1L, 12L))) - .courierId(Optional.of(1L)) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.of(List.of(1L))) + .citiesIds(Optional.of(List.of(1L, 11L))) + .stationsIds(Optional.of(List.of(1L, 12L))) + .courierId(Optional.of(1L)) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithStatusActive() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.of(List.of(1L))) - .citiesIds(Optional.of(List.of(1L))) - .stationsIds(Optional.of(List.of(1L))) - .courierId(Optional.of(1L)) - .activationStatus("Active") - .build(); + .regionsIds(Optional.of(List.of(1L))) + .citiesIds(Optional.of(List.of(1L))) + .stationsIds(Optional.of(List.of(1L))) + .courierId(Optional.of(1L)) + .activationStatus("Active") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.of(List.of(1L))) - .citiesIds(Optional.empty()) - .stationsIds(Optional.of(List.of(1L, 12L))) - .courierId(Optional.empty()) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.of(List.of(1L))) + .citiesIds(Optional.empty()) + .stationsIds(Optional.of(List.of(1L, 12L))) + .courierId(Optional.empty()) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.of(List.of(1L))) - .citiesIds(Optional.of(List.of(1L, 11L))) - .stationsIds(Optional.empty()) - .courierId(Optional.of(1L)) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.of(List.of(1L))) + .citiesIds(Optional.of(List.of(1L, 11L))) + .stationsIds(Optional.empty()) + .courierId(Optional.of(1L)) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.of(List.of(1L))) - .citiesIds(Optional.empty()) - .stationsIds(Optional.of(List.of(1L, 12L))) - .courierId(Optional.of(1L)) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.of(List.of(1L))) + .citiesIds(Optional.empty()) + .stationsIds(Optional.of(List.of(1L, 12L))) + .courierId(Optional.of(1L)) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithCities() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.empty()) - .citiesIds(Optional.of(List.of(1L, 11L))) - .stationsIds(Optional.empty()) - .courierId(Optional.empty()) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.empty()) + .citiesIds(Optional.of(List.of(1L, 11L))) + .stationsIds(Optional.empty()) + .courierId(Optional.empty()) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithCitiesAndCourier() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.empty()) - .citiesIds(Optional.of(List.of(1L, 11L))) - .stationsIds(Optional.empty()) - .courierId(Optional.of(1L)) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.empty()) + .citiesIds(Optional.of(List.of(1L, 11L))) + .stationsIds(Optional.empty()) + .courierId(Optional.of(1L)) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithCitiesAndReceivingStations() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.empty()) - .citiesIds(Optional.of(List.of(1L, 11L))) - .stationsIds(Optional.of(List.of(1L, 12L))) - .courierId(Optional.empty()) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.empty()) + .citiesIds(Optional.of(List.of(1L, 11L))) + .stationsIds(Optional.of(List.of(1L, 12L))) + .courierId(Optional.empty()) + .activationStatus("Deactivated") + .build(); } public static DetailsOfDeactivateTariffsDto getDetailsOfDeactivateTariffsDtoWithCitiesAndCourierAndReceivingStations() { return DetailsOfDeactivateTariffsDto.builder() - .regionsIds(Optional.empty()) - .citiesIds(Optional.of(List.of(1L, 11L))) - .stationsIds(Optional.of(List.of(1L, 12L))) - .courierId(Optional.of(1L)) - .activationStatus("Deactivated") - .build(); + .regionsIds(Optional.empty()) + .citiesIds(Optional.of(List.of(1L, 11L))) + .stationsIds(Optional.of(List.of(1L, 12L))) + .courierId(Optional.of(1L)) + .activationStatus("Deactivated") + .build(); } public static BagLimitDto getBagLimitIncludedDtoTrue() { return BagLimitDto.builder() - .id(1) - .limitIncluded(true) - .build(); + .id(1) + .limitIncluded(true) + .build(); } public static BagLimitDto getBagLimitIncludedDtoFalse() { return BagLimitDto.builder() - .id(1) - .limitIncluded(false) - .build(); + .id(1) + .limitIncluded(false) + .build(); } public static SetTariffLimitsDto setTariffLimitsWithAmountOfBags() { return SetTariffLimitsDto.builder() - .min(1L) - .max(2L) - .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) - .bagLimitDtoList(List.of(getBagLimitIncludedDtoTrue())) - .build(); + .min(1L) + .max(2L) + .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) + .bagLimitDtoList(List.of(getBagLimitIncludedDtoTrue())) + .build(); } public static SetTariffLimitsDto setTariffLimitsWithNullAllTariffParamsAndFalseBagLimit() { return SetTariffLimitsDto.builder() - .min(null) - .max(null) - .courierLimit(null) - .bagLimitDtoList(List.of(getBagLimitIncludedDtoFalse())) - .build(); + .min(null) + .max(null) + .courierLimit(null) + .bagLimitDtoList(List.of(getBagLimitIncludedDtoFalse())) + .build(); } public static SetTariffLimitsDto setTariffLimitsWithNullMinAndMaxAndFalseBagLimit() { return SetTariffLimitsDto.builder() - .min(null) - .max(null) - .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) - .bagLimitDtoList(List.of(getBagLimitIncludedDtoFalse())) - .build(); + .min(null) + .max(null) + .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) + .bagLimitDtoList(List.of(getBagLimitIncludedDtoFalse())) + .build(); } public static SetTariffLimitsDto setTariffsLimitWithSameMinAndMaxValue() { return SetTariffLimitsDto.builder() - .min(2L) - .max(2L) - .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) - .bagLimitDtoList(List.of(getBagLimitIncludedDtoTrue())) - .build(); + .min(2L) + .max(2L) + .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) + .bagLimitDtoList(List.of(getBagLimitIncludedDtoTrue())) + .build(); } public static SetTariffLimitsDto setTariffLimitsWithPriceOfOrder() { return SetTariffLimitsDto.builder() - .min(100L) - .max(200L) - .courierLimit(CourierLimit.LIMIT_BY_SUM_OF_ORDER) - .bagLimitDtoList(List.of(getBagLimitIncludedDtoTrue())) - .build(); + .min(100L) + .max(200L) + .courierLimit(CourierLimit.LIMIT_BY_SUM_OF_ORDER) + .bagLimitDtoList(List.of(getBagLimitIncludedDtoTrue())) + .build(); } public static SetTariffLimitsDto setTariffLimitsWithAmountOfBigBagsWhereMaxValueIsGreater() { return SetTariffLimitsDto.builder() - .min(2L) - .max(1L) - .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) - .bagLimitDtoList(List.of(getBagLimitIncludedDtoTrue())) - .build(); + .min(2L) + .max(1L) + .courierLimit(CourierLimit.LIMIT_BY_AMOUNT_OF_BAG) + .bagLimitDtoList(List.of(getBagLimitIncludedDtoTrue())) + .build(); } public static SetTariffLimitsDto setTariffLimitsWithPriceOfOrderWhereMaxValueIsGreater() { return SetTariffLimitsDto.builder() - .min(200L) - .max(100L) - .courierLimit(CourierLimit.LIMIT_BY_SUM_OF_ORDER) - .bagLimitDtoList(List.of(getBagLimitIncludedDtoTrue())) - .build(); + .min(200L) + .max(100L) + .courierLimit(CourierLimit.LIMIT_BY_SUM_OF_ORDER) + .bagLimitDtoList(List.of(getBagLimitIncludedDtoTrue())) + .build(); } public static UserPointsAndAllBagsDto getUserPointsAndAllBagsDto() { return new UserPointsAndAllBagsDto( - List.of( - BagTranslationDto.builder() - .id(1) - .name("name") - .capacity(20) - .price(150.) - .nameEng("nameEng") - .limitedIncluded(false) - .build()), - 100); + List.of( + BagTranslationDto.builder() + .id(1) + .name("name") + .capacity(20) + .price(150.) + .nameEng("nameEng") + .limitedIncluded(false) + .build()), + 100); } public static Order getOrderExportDetailsWithExportDate() { return Order.builder() - .id(1L) - .dateOfExport(LocalDate.of(2023, 2, 8)) - .user(User.builder().id(1L).recipientName("Admin").recipientSurname("Ubs").build()) - .build(); + .id(1L) + .dateOfExport(LocalDate.of(2023, 2, 8)) + .user(User.builder().id(1L).recipientName("Admin").recipientSurname("Ubs").build()) + .build(); } public static Order getOrderExportDetailsWithExportDateDeliverFrom() { return Order.builder() - .id(1L) - .dateOfExport(LocalDate.of(2023, 2, 8)) - .deliverFrom(LocalDateTime.of(2023, 2, 8, 15, 0)) - .user(User.builder().id(1L).recipientName("Admin").recipientSurname("Ubs").build()) - .build(); + .id(1L) + .dateOfExport(LocalDate.of(2023, 2, 8)) + .deliverFrom(LocalDateTime.of(2023, 2, 8, 15, 0)) + .user(User.builder().id(1L).recipientName("Admin").recipientSurname("Ubs").build()) + .build(); } public static Order getOrderExportDetailsWithExportDateDeliverFromTo() { return Order.builder() - .id(1L) - .dateOfExport(LocalDate.of(2023, 2, 8)) - .deliverFrom(LocalDateTime.of(2023, 2, 8, 15, 0)) - .deliverTo(LocalDateTime.of(2023, 2, 8, 16, 30)) - .user(User.builder().id(1L).recipientName("Admin").recipientSurname("Ubs").build()) - .build(); + .id(1L) + .dateOfExport(LocalDate.of(2023, 2, 8)) + .deliverFrom(LocalDateTime.of(2023, 2, 8, 15, 0)) + .deliverTo(LocalDateTime.of(2023, 2, 8, 16, 30)) + .user(User.builder().id(1L).recipientName("Admin").recipientSurname("Ubs").build()) + .build(); } public static Order getOrderExportDetailsWithDeliverFromTo() { @@ -4835,54 +4835,54 @@ public static Order getOrderExportDetailsWithDeliverFromTo() { public static UserProfileCreateDto getUserProfileCreateDto() { return UserProfileCreateDto.builder() - .name("UbsProfile") - .email("ubsuser@mail.com") - .uuid("f81d4fae-7dec-11d0-a765-00a0c91e6bf6") - .build(); + .name("UbsProfile") + .email("ubsuser@mail.com") + .uuid("f81d4fae-7dec-11d0-a765-00a0c91e6bf6") + .build(); } public static Order getTestNotTakenOrderReason() { return Order.builder() - .id(1L) - .orderStatus(OrderStatus.NOT_TAKEN_OUT) - .reasonNotTakingBagDescription("Some description") - .imageReasonNotTakingBags(List.of("image1", "image2")) - .build(); + .id(1L) + .orderStatus(OrderStatus.NOT_TAKEN_OUT) + .reasonNotTakingBagDescription("Some description") + .imageReasonNotTakingBags(List.of("image1", "image2")) + .build(); } public static NotTakenOrderReasonDto getNotTakenOrderReasonDto() { return NotTakenOrderReasonDto.builder() - .description("Some description") - .images(List.of("image1", "image2")) - .build(); + .description("Some description") + .images(List.of("image1", "image2")) + .build(); } public static TableColumnWidthForEmployee getTestTableColumnWidth() { return TableColumnWidthForEmployee.builder() - .employee(getEmployee()) - .address(50) - .amountDue(60) - .bagsAmount(150) - .city(200) - .build(); + .employee(getEmployee()) + .address(50) + .amountDue(60) + .bagsAmount(150) + .city(200) + .build(); } public static ColumnWidthDto getTestColumnWidthDto() { return ColumnWidthDto.builder() - .address(100) - .amountDue(20) - .bagsAmount(500) - .city(320) - .clientPhone(340) - .commentForOrderByClient(600) - .build(); + .address(100) + .amountDue(20) + .bagsAmount(500) + .city(320) + .clientPhone(340) + .commentForOrderByClient(600) + .build(); } public static PositionAuthoritiesDto getPositionAuthoritiesDto() { return PositionAuthoritiesDto.builder() - .positionId(List.of(1L)) - .authorities(List.of("Auth")) - .build(); + .positionId(List.of(1L)) + .authorities(List.of("Auth")) + .build(); } public static PositionWithTranslateDto getPositionWithTranslateDto(Long id) { @@ -4891,9 +4891,9 @@ public static PositionWithTranslateDto getPositionWithTranslateDto(Long id) { nameTranslations.put("en", "Driver"); return PositionWithTranslateDto.builder() - .id(id) - .name(nameTranslations) - .build(); + .id(id) + .name(nameTranslations) + .build(); } public static Refund getRefund(Long id) { diff --git a/service/src/test/java/greencity/service/notification/NotificationServiceImplTest.java b/service/src/test/java/greencity/service/notification/NotificationServiceImplTest.java index 93deee5aa..440f8e824 100644 --- a/service/src/test/java/greencity/service/notification/NotificationServiceImplTest.java +++ b/service/src/test/java/greencity/service/notification/NotificationServiceImplTest.java @@ -85,8 +85,9 @@ class NotificationServiceImplTest { private Clock fixedClock; ExecutorService mockExecutor = MoreExecutors.newDirectExecutorService(); -@Mock -private OrderBagService orderBagService; + @Mock + private OrderBagService orderBagService; + @Nested class ClockNotification { @BeforeEach @@ -303,7 +304,7 @@ void testNotifyInactiveAccounts() { List.of(abstractNotificationProvider), templateRepository, mockExecutor, - internalUrlConfigProp,orderBagService); + internalUrlConfigProp, orderBagService); User user = User.builder().id(42L).build(); User user1 = User.builder().id(43L).build(); UserNotification notification = new UserNotification(); diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index dbe859bb1..5f8e4db9b 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -137,19 +137,19 @@ class SuperAdminServiceImplTest { @AfterEach void afterEach() { verifyNoMoreInteractions( - userRepository, - employeeRepository, - bagRepository, - locationRepository, - modelMapper, - serviceRepository, - courierRepository, - regionRepository, - receivingStationRepository, - tariffsInfoRepository, - tariffsLocationRepository, - deactivateTariffsForChosenParamRepository, - orderBagRepository); + userRepository, + employeeRepository, + bagRepository, + locationRepository, + modelMapper, + serviceRepository, + courierRepository, + regionRepository, + receivingStationRepository, + tariffsInfoRepository, + tariffsLocationRepository, + deactivateTariffsForChosenParamRepository, + orderBagRepository); } @Test @@ -185,7 +185,7 @@ void addTariffServiceIfEmployeeNotFoundExceptionTest() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.addTariffService(1L, dto, uuid)); + () -> superAdminService.addTariffService(1L, dto, uuid)); verify(tariffsInfoRepository).findById(1L); verify(employeeRepository).findByUuid(uuid); @@ -200,7 +200,7 @@ void addTariffServiceIfTariffNotFoundExceptionTest() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.addTariffService(1L, dto, uuid)); + () -> superAdminService.addTariffService(1L, dto, uuid)); verify(tariffsInfoRepository).findById(1L); verify(bagRepository, never()).save(any(Bag.class)); @@ -241,7 +241,7 @@ void getTariffServiceIfTariffNotFoundException() { when(tariffsInfoRepository.existsById(1L)).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.getTariffService(1)); + () -> superAdminService.getTariffService(1)); verify(tariffsInfoRepository).existsById(1L); verify(bagRepository, never()).findBagsByTariffsInfoId(1L); @@ -340,7 +340,7 @@ void deleteTariffServiceWhenTariffBagsWithoutLimits() { void deleteTariffServiceThrowBagNotFoundException() { when(bagRepository.findById(1)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.deleteTariffService(1)); + () -> superAdminService.deleteTariffService(1)); verify(bagRepository).findById(1); verify(bagRepository, never()).save(any(Bag.class)); } @@ -361,7 +361,7 @@ void editTariffServiceWithUnpaidOrder() { when(bagRepository.save(editedBag)).thenReturn(editedBag); when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); doNothing().when(orderBagRepository) - .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); when(orderRepository.findAllUnpaidOrdersByBagId(1)).thenReturn(List.of(order)); when(orderRepository.saveAll(List.of(order))).thenReturn(List.of(order)); @@ -373,7 +373,7 @@ void editTariffServiceWithUnpaidOrder() { verify(bagRepository).save(editedBag); verify(modelMapper).map(editedBag, GetTariffServiceDto.class); verify(orderBagRepository) - .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); verify(orderRepository).findAllUnpaidOrdersByBagId(1); verify(orderRepository).saveAll(anyList()); } @@ -394,7 +394,7 @@ void editTariffServiceWithUnpaidOrderAndBagConfirmedAmount() { when(bagRepository.save(editedBag)).thenReturn(editedBag); when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); doNothing().when(orderBagRepository) - .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); when(orderRepository.findAllUnpaidOrdersByBagId(1)).thenReturn(List.of(order)); when(orderRepository.saveAll(List.of(order))).thenReturn(List.of(order)); @@ -406,7 +406,7 @@ void editTariffServiceWithUnpaidOrderAndBagConfirmedAmount() { verify(bagRepository).save(editedBag); verify(modelMapper).map(editedBag, GetTariffServiceDto.class); verify(orderBagRepository) - .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); verify(orderRepository).findAllUnpaidOrdersByBagId(1); verify(orderRepository).saveAll(anyList()); } @@ -427,7 +427,7 @@ void editTariffServiceWithUnpaidOrderAndBagExportedAmount() { when(bagRepository.save(editedBag)).thenReturn(editedBag); when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); doNothing().when(orderBagRepository) - .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); when(orderRepository.findAllUnpaidOrdersByBagId(1)).thenReturn(List.of(order)); when(orderRepository.saveAll(List.of(order))).thenReturn(List.of(order)); @@ -439,7 +439,7 @@ void editTariffServiceWithUnpaidOrderAndBagExportedAmount() { verify(bagRepository).save(editedBag); verify(modelMapper).map(editedBag, GetTariffServiceDto.class); verify(orderBagRepository) - .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); verify(orderRepository).findAllUnpaidOrdersByBagId(1); verify(orderRepository).saveAll(anyList()); } @@ -458,7 +458,7 @@ void editTariffServiceWithoutUnpaidOrder() { when(bagRepository.save(editedBag)).thenReturn(editedBag); when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); doNothing().when(orderBagRepository) - .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); when(orderRepository.findAllUnpaidOrdersByBagId(1)).thenReturn(Collections.emptyList()); GetTariffServiceDto actual = superAdminService.editTariffService(dto, 1, uuid); @@ -469,7 +469,7 @@ void editTariffServiceWithoutUnpaidOrder() { verify(bagRepository).save(editedBag); verify(modelMapper).map(editedBag, GetTariffServiceDto.class); verify(orderBagRepository) - .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); + .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); verify(orderRepository).findAllUnpaidOrdersByBagId(1); verify(orderRepository, never()).saveAll(anyList()); } @@ -483,7 +483,7 @@ void editTariffServiceIfEmployeeNotFoundException() { when(bagRepository.findById(1)).thenReturn(bag); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariffService(dto, 1, uuid)); + () -> superAdminService.editTariffService(dto, 1, uuid)); verify(bagRepository).findById(1); verify(bagRepository, never()).save(any(Bag.class)); @@ -496,7 +496,7 @@ void editTariffServiceIfBagNotFoundException() { when(bagRepository.findById(1)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariffService(dto, 1, uuid)); + () -> superAdminService.editTariffService(dto, 1, uuid)); verify(bagRepository).findById(1); verify(bagRepository, never()).save(any(Bag.class)); @@ -506,7 +506,7 @@ void editTariffServiceIfBagNotFoundException() { void getAllCouriersTest() { when(courierRepository.findAll()).thenReturn(List.of(getCourier())); when(modelMapper.map(getCourier(), CourierDto.class)) - .thenReturn(getCourierDto()); + .thenReturn(getCourierDto()); assertEquals(getCourierDtoList(), superAdminService.getAllCouriers()); @@ -533,7 +533,7 @@ void deleteServiceThrowNotFoundException() { when(serviceRepository.findById(service.getId())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.deleteService(1L)); + () -> superAdminService.deleteService(1L)); verify(serviceRepository).findById(1L); verify(serviceRepository, never()).delete(service); @@ -574,7 +574,7 @@ void getServiceThrowTariffNotFoundException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.getService(1L)); + () -> superAdminService.getService(1L)); verify(tariffsInfoRepository).findById(1L); } @@ -608,7 +608,7 @@ void editServiceServiceNotFoundException() { when(serviceRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editService(1L, dto, uuid)); + () -> superAdminService.editService(1L, dto, uuid)); verify(serviceRepository).findById(1L); verify(serviceRepository, never()).save(any(Service.class)); @@ -625,7 +625,7 @@ void editServiceEmployeeNotFoundException() { when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editService(1L, dto, uuid)); + () -> superAdminService.editService(1L, dto, uuid)); verify(employeeRepository).findByUuid(uuid); verify(serviceRepository).findById(1L); @@ -671,7 +671,7 @@ void addServiceThrowServiceAlreadyExistsException() { when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(createdService)); assertThrows(ServiceAlreadyExistsException.class, - () -> superAdminService.addService(1L, serviceDto, uuid)); + () -> superAdminService.addService(1L, serviceDto, uuid)); verify(tariffsInfoRepository).findById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); @@ -688,7 +688,7 @@ void addServiceThrowEmployeeNotFoundException() { when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.addService(1L, serviceDto, uuid)); + () -> superAdminService.addService(1L, serviceDto, uuid)); verify(tariffsInfoRepository).findById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); @@ -703,7 +703,7 @@ void addServiceThrowTariffNotFoundException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.addService(1L, serviceDto, uuid)); + () -> superAdminService.addService(1L, serviceDto, uuid)); verify(tariffsInfoRepository).findById(1L); } @@ -725,7 +725,7 @@ void getLocationsByStatusTest() { List regionList = ModelUtils.getAllRegion(); when(regionRepository.findAllByLocationsLocationStatus(LocationStatus.ACTIVE)) - .thenReturn(Optional.of(regionList)); + .thenReturn(Optional.of(regionList)); var result = superAdminService.getLocationsByStatus(LocationStatus.ACTIVE); @@ -738,13 +738,13 @@ void getLocationsByStatusTest() { @Test void getLocationsByStatusNotFoundExceptionTest() { when(regionRepository.findAllByLocationsLocationStatus(LocationStatus.ACTIVE)) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); NotFoundException notFoundException = assertThrows(NotFoundException.class, - () -> superAdminService.getLocationsByStatus(LocationStatus.ACTIVE)); + () -> superAdminService.getLocationsByStatus(LocationStatus.ACTIVE)); assertEquals(String.format(ErrorMessage.REGIONS_NOT_FOUND_BY_LOCATION_STATUS, LocationStatus.ACTIVE.name()), - notFoundException.getMessage()); + notFoundException.getMessage()); verify(regionRepository).findAllByLocationsLocationStatus(LocationStatus.ACTIVE); } @@ -755,7 +755,7 @@ void addLocationTest() { Region region = ModelUtils.getRegion(); when(regionRepository.findRegionByEnNameAndUkrName("Kyiv region", "Київська область")) - .thenReturn(Optional.of(region)); + .thenReturn(Optional.of(region)); superAdminService.addLocation(locationCreateDtoList); @@ -769,7 +769,7 @@ void addLocationCreateNewRegionTest() { List locationCreateDtoList = ModelUtils.getLocationCreateDtoList(); Location location = ModelUtils.getLocationForCreateRegion(); when(regionRepository.findRegionByEnNameAndUkrName("Kyiv region", "Київська область")) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); when(regionRepository.save(any())).thenReturn(ModelUtils.getRegion()); superAdminService.addLocation(locationCreateDtoList); verify(locationRepository).findLocationByNameAndRegionId("Київ", "Kyiv", 1L); @@ -781,7 +781,7 @@ void addLocationCreateNewRegionTest() { void deleteLocationTest() { Location location = ModelUtils.getLocationDto(); location - .setTariffLocations(Set.of(TariffLocation.builder().location(Location.builder().id(2L).build()).build())); + .setTariffLocations(Set.of(TariffLocation.builder().location(Location.builder().id(2L).build()).build())); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); superAdminService.deleteLocation(1L); verify(locationRepository).findById(1L); @@ -792,7 +792,7 @@ void deleteLocationTest() { void deleteLocationThrowsBadRequestExceptionTest() { Location location = ModelUtils.getLocationDto(); location - .setTariffLocations(Set.of(TariffLocation.builder().location(Location.builder().id(1L).build()).build())); + .setTariffLocations(Set.of(TariffLocation.builder().location(Location.builder().id(1L).build()).build())); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); assertThrows(BadRequestException.class, () -> superAdminService.deleteLocation(1L)); verify(locationRepository).findById(1L); @@ -815,7 +815,7 @@ void addLocationThrowLocationAlreadyCreatedExceptionTest() { List locationCreateDtoList = ModelUtils.getLocationCreateDtoList(); Location location = ModelUtils.getLocation(); when(regionRepository.findRegionByEnNameAndUkrName("Kyiv region", "Київська область")) - .thenReturn(Optional.of(ModelUtils.getRegion())); + .thenReturn(Optional.of(ModelUtils.getRegion())); when(locationRepository.findLocationByNameAndRegionId("Київ", "Kyiv", 1L)).thenReturn(Optional.of(location)); assertThrows(NotFoundException.class, () -> superAdminService.addLocation(locationCreateDtoList)); @@ -858,17 +858,17 @@ void deactivateCourierThrowBadRequestException() { when(courierRepository.findById(anyLong())).thenReturn(Optional.of(courier)); courier.setCourierStatus(CourierStatus.DEACTIVATED); assertThrows(BadRequestException.class, - () -> superAdminService.deactivateCourier(1L)); + () -> superAdminService.deactivateCourier(1L)); verify(courierRepository).findById(1L); } @Test void deactivateCourierThrowNotFoundException() { when(courierRepository.findById(anyLong())) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); Exception thrownNotFoundEx = assertThrows(NotFoundException.class, - () -> superAdminService.deactivateCourier(1L)); + () -> superAdminService.deactivateCourier(1L)); assertEquals(ErrorMessage.COURIER_IS_NOT_FOUND_BY_ID + 1L, thrownNotFoundEx.getMessage()); verify(courierRepository).findById(1L); @@ -882,14 +882,14 @@ void createCourier() { when(employeeRepository.findByUuid(anyString())).thenReturn(Optional.ofNullable(getEmployee())); when(courierRepository.findAll()).thenReturn(List.of(Courier.builder() - .nameEn("Test1") - .nameUk("Тест1") - .build())); + .nameEn("Test1") + .nameUk("Тест1") + .build())); when(courierRepository.save(any())).thenReturn(courier); when(modelMapper.map(any(), eq(CreateCourierDto.class))).thenReturn(createCourierDto); assertEquals(createCourierDto, - superAdminService.createCourier(createCourierDto, ModelUtils.TEST_USER.getUuid())); + superAdminService.createCourier(createCourierDto, ModelUtils.TEST_USER.getUuid())); verify(courierRepository).save(any()); verify(modelMapper).map(any(), eq(CreateCourierDto.class)); @@ -906,7 +906,7 @@ void createCourierAlreadyExists() { when(courierRepository.findAll()).thenReturn(List.of(getCourier(), getCourier())); Throwable throwable = assertThrows(CourierAlreadyExists.class, - () -> superAdminService.createCourier(createCourierDto, uuid)); + () -> superAdminService.createCourier(createCourierDto, uuid)); assertEquals(ErrorMessage.COURIER_ALREADY_EXISTS, throwable.getMessage()); verify(employeeRepository).findByUuid(anyString()); verify(courierRepository).findAll(); @@ -917,24 +917,24 @@ void updateCourierTest() { Courier courier = getCourier(); CourierUpdateDto dto = CourierUpdateDto.builder() - .courierId(1L) - .nameUk("УБС") - .nameEn("UBS") - .build(); + .courierId(1L) + .nameUk("УБС") + .nameEn("UBS") + .build(); Courier courierToSave = Courier.builder() - .id(courier.getId()) - .courierStatus(courier.getCourierStatus()) - .nameUk("УБС") - .nameEn("UBS") - .build(); + .id(courier.getId()) + .courierStatus(courier.getCourierStatus()) + .nameUk("УБС") + .nameEn("UBS") + .build(); CourierDto courierDto = CourierDto.builder() - .courierId(courier.getId()) - .courierStatus("Active") - .nameUk("УБС") - .nameEn("UBS") - .build(); + .courierId(courier.getId()) + .courierStatus("Active") + .nameUk("УБС") + .nameEn("UBS") + .build(); when(courierRepository.findById(dto.getCourierId())).thenReturn(Optional.of(courier)); when(courierRepository.save(courier)).thenReturn(courierToSave); @@ -942,11 +942,11 @@ void updateCourierTest() { CourierDto actual = superAdminService.updateCourier(dto); CourierDto expected = CourierDto.builder() - .courierId(getCourier().getId()) - .courierStatus("Active") - .nameUk("УБС") - .nameEn("UBS") - .build(); + .courierId(getCourier().getId()) + .courierStatus("Active") + .nameUk("УБС") + .nameEn("UBS") + .build(); assertEquals(expected, actual); } @@ -956,20 +956,20 @@ void updateCourierNotFound() { Courier courier = getCourier(); CourierUpdateDto dto = CourierUpdateDto.builder() - .courierId(1L) - .nameUk("УБС") - .nameEn("UBS") - .build(); + .courierId(1L) + .nameUk("УБС") + .nameEn("UBS") + .build(); when(courierRepository.findById(courier.getId())) - .thenThrow(new NotFoundException(ErrorMessage.COURIER_IS_NOT_FOUND_BY_ID)); + .thenThrow(new NotFoundException(ErrorMessage.COURIER_IS_NOT_FOUND_BY_ID)); assertThrows(NotFoundException.class, () -> superAdminService.updateCourier(dto)); } @Test void getAllTariffsInfoTest() { when(tariffsInfoRepository.findAll(any(TariffsInfoSpecification.class))) - .thenReturn(List.of(ModelUtils.getTariffsInfo())); + .thenReturn(List.of(ModelUtils.getTariffsInfo())); when(modelMapper.map(any(TariffsInfo.class), eq(GetTariffsInfoDto.class))).thenReturn(getAllTariffsInfoDto()); superAdminService.getAllTariffsInfo(TariffsInfoFilterCriteria.builder().build()); @@ -983,7 +983,7 @@ void CreateReceivingStation() { AddingReceivingStationDto stationDto = AddingReceivingStationDto.builder().name("Петрівка").build(); when(receivingStationRepository.existsReceivingStationByName(any())).thenReturn(false, true); lenient().when(modelMapper.map(any(ReceivingStation.class), eq(ReceivingStationDto.class))) - .thenReturn(getReceivingStationDto()); + .thenReturn(getReceivingStationDto()); when(receivingStationRepository.save(any())).thenReturn(getReceivingStation(), getReceivingStation()); when(employeeRepository.findByUuid(test)).thenReturn(Optional.ofNullable(getEmployee())); superAdminService.createReceivingStation(stationDto, test); @@ -991,12 +991,12 @@ void CreateReceivingStation() { verify(receivingStationRepository, times(1)).existsReceivingStationByName(any()); verify(receivingStationRepository, times(1)).save(any()); verify(modelMapper, times(1)) - .map(any(ReceivingStation.class), eq(ReceivingStationDto.class)); + .map(any(ReceivingStation.class), eq(ReceivingStationDto.class)); Exception thrown = assertThrows(UnprocessableEntityException.class, - () -> superAdminService.createReceivingStation(stationDto, test)); + () -> superAdminService.createReceivingStation(stationDto, test)); assertEquals(thrown.getMessage(), ErrorMessage.RECEIVING_STATION_ALREADY_EXISTS - + stationDto.getName()); + + stationDto.getName()); verify(employeeRepository).findByUuid(any()); } @@ -1005,13 +1005,13 @@ void createReceivingStationSaveCorrectValue() { String receivingStationName = "Петрівка"; Employee employee = getEmployee(); AddingReceivingStationDto addingReceivingStationDto = - AddingReceivingStationDto.builder().name(receivingStationName).build(); + AddingReceivingStationDto.builder().name(receivingStationName).build(); ReceivingStation activatedReceivingStation = ReceivingStation.builder() - .name(receivingStationName) - .createdBy(employee) - .createDate(LocalDate.now()) - .stationStatus(StationStatus.ACTIVE) - .build(); + .name(receivingStationName) + .createdBy(employee) + .createDate(LocalDate.now()) + .stationStatus(StationStatus.ACTIVE) + .build(); ReceivingStationDto receivingStationDto = getReceivingStationDto(); @@ -1019,7 +1019,7 @@ void createReceivingStationSaveCorrectValue() { when(receivingStationRepository.existsReceivingStationByName(any())).thenReturn(false); when(receivingStationRepository.save(any())).thenReturn(activatedReceivingStation); when(modelMapper.map(any(), eq(ReceivingStationDto.class))) - .thenReturn(receivingStationDto); + .thenReturn(receivingStationDto); superAdminService.createReceivingStation(addingReceivingStationDto, employee.getUuid()); @@ -1027,7 +1027,7 @@ void createReceivingStationSaveCorrectValue() { verify(receivingStationRepository).existsReceivingStationByName(any()); verify(receivingStationRepository).save(activatedReceivingStation); verify(modelMapper) - .map(any(ReceivingStation.class), eq(ReceivingStationDto.class)); + .map(any(ReceivingStation.class), eq(ReceivingStationDto.class)); } @@ -1079,7 +1079,7 @@ void deleteReceivingStation() { when(receivingStationRepository.findById(2L)).thenReturn(Optional.empty()); Exception thrown1 = assertThrows(NotFoundException.class, - () -> superAdminService.deleteReceivingStation(2L)); + () -> superAdminService.deleteReceivingStation(2L)); assertEquals(ErrorMessage.RECEIVING_STATION_NOT_FOUND_BY_ID + 2L, thrown1.getMessage()); } @@ -1088,12 +1088,12 @@ void deleteReceivingStation() { void editNewTariffSuccess() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); when(locationRepository.findAllByIdAndRegionId(dto.getLocationIdList(), dto.getRegionId())) - .thenReturn(ModelUtils.getLocationList()); + .thenReturn(ModelUtils.getLocationList()); when(employeeRepository.findByUuid(any())).thenReturn(Optional.ofNullable(getEmployee())); when(receivingStationRepository.findAllById(List.of(1L))).thenReturn(ModelUtils.getReceivingList()); when(courierRepository.findById(anyLong())).thenReturn(Optional.of(ModelUtils.getCourier())); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(Collections.emptyList()); + .thenReturn(Collections.emptyList()); when(tariffsInfoRepository.save(any())).thenReturn(ModelUtils.getTariffInfo()); when(employeeRepository.findAllByEmployeePositionId(6L)).thenReturn(ModelUtils.getEmployeeList()); when(tariffsLocationRepository.saveAll(anySet())).thenReturn(anyList()); @@ -1113,13 +1113,13 @@ void addNewTariffThrowsExceptionWhenListOfLocationsIsEmptyTest() { when(employeeRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(Optional.ofNullable(getEmployee())); when(tariffsInfoRepository.save(any())).thenReturn(ModelUtils.getTariffInfo()); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(Collections.emptyList()); + .thenReturn(Collections.emptyList()); when(receivingStationRepository.findAllById(List.of(1L))).thenReturn(ModelUtils.getReceivingList()); when(locationRepository.findAllByIdAndRegionId(dto.getLocationIdList(), - dto.getRegionId())).thenReturn(Collections.emptyList()); + dto.getRegionId())).thenReturn(Collections.emptyList()); assertThrows(NotFoundException.class, - () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); + () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); verify(courierRepository).findById(1L); verify(employeeRepository).findByUuid("35467585763t4sfgchjfuyetf"); @@ -1134,20 +1134,20 @@ void addNewTariffThrowsExceptionWhenListOfLocationsIsEmptyTest() { void addNewTariffThrowsExceptionWhenSuchTariffIsAlreadyExistsTest() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); TariffLocation tariffLocation = TariffLocation - .builder() - .id(1L) - .location(ModelUtils.getLocation()) - .build(); + .builder() + .id(1L) + .location(ModelUtils.getLocation()) + .build(); when(courierRepository.findById(1L)).thenReturn(Optional.of(ModelUtils.getCourier())); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(dto.getCourierId(), - dto.getLocationIdList())).thenReturn(List.of(tariffLocation)); + dto.getLocationIdList())).thenReturn(List.of(tariffLocation)); assertThrows(TariffAlreadyExistsException.class, - () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); + () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); verify(courierRepository).findById(1L); verify(tariffsLocationRepository).findAllByCourierIdAndLocationIds(dto.getCourierId(), - dto.getLocationIdList()); + dto.getLocationIdList()); verifyNoMoreInteractions(courierRepository, tariffsLocationRepository); verify(employeeRepository, never()).findAllByEmployeePositionId(6L); } @@ -1163,12 +1163,12 @@ void addNewTariffThrowsExceptionWhenCourierHasStatusDeactivated() { // Perform the test assertThrows(BadRequestException.class, - () -> superAdminService.addNewTariff(addNewTariffDto, userUUID)); + () -> superAdminService.addNewTariff(addNewTariffDto, userUUID)); // Verify the interactions verify(courierRepository).findById(addNewTariffDto.getCourierId()); verifyNoMoreInteractions(courierRepository, tariffsLocationRepository, tariffsInfoRepository, - employeeRepository); + employeeRepository); } @Test @@ -1180,12 +1180,12 @@ void addNewTariffThrowsExceptionWhenListOfReceivingStationIsEmpty() { when(employeeRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(Optional.ofNullable(getEmployee())); when(tariffsInfoRepository.save(any())).thenReturn(ModelUtils.getTariffInfo()); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(Collections.emptyList()); + .thenReturn(Collections.emptyList()); when(locationRepository.findAllByIdAndRegionId(dto.getLocationIdList(), - dto.getRegionId())).thenReturn(Collections.emptyList()); + dto.getRegionId())).thenReturn(Collections.emptyList()); assertThrows(NotFoundException.class, - () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); + () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); verify(courierRepository).findById(1L); verify(employeeRepository).findByUuid("35467585763t4sfgchjfuyetf"); @@ -1200,7 +1200,7 @@ void addNewTariffThrowsException2() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); when(courierRepository.findById(anyLong())).thenReturn(Optional.of(ModelUtils.getCourier())); assertThrows(NotFoundException.class, - () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); + () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); verify(courierRepository).findById(anyLong()); verify(receivingStationRepository).findAllById(any()); verify(tariffsLocationRepository).findAllByCourierIdAndLocationIds(anyLong(), anyList()); @@ -1212,7 +1212,7 @@ void addNewTariffThrowsException3() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); when(courierRepository.findById(anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); + () -> superAdminService.addNewTariff(dto, "35467585763t4sfgchjfuyetf")); verify(employeeRepository, never()).findAllByEmployeePositionId(6L); } @@ -1229,10 +1229,10 @@ void editTariffTest() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); when(tariffsLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) - .thenReturn(Optional.of(tariffLocation)); + .thenReturn(Optional.of(tariffLocation)); when(tariffsLocationRepository.findAllByTariffsInfo(tariffsInfo)).thenReturn(List.of(tariffLocation)); when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfo); @@ -1262,10 +1262,10 @@ void editTariffWithDeleteTariffLocation() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); when(tariffsLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) - .thenReturn(Optional.of(tariffLocation)); + .thenReturn(Optional.of(tariffLocation)); when(tariffsLocationRepository.findAllByTariffsInfo(tariffsInfo)).thenReturn(tariffLocations); doNothing().when(tariffsLocationRepository).delete(tariffLocations.get(1)); when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfo); @@ -1289,7 +1289,7 @@ void editTariffThrowTariffNotFoundException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1302,7 +1302,7 @@ void editTariffThrowLocationNotFoundException() { when(locationRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(locationRepository).findById(1L); @@ -1319,7 +1319,7 @@ void editTariffThrowLocationBadRequestException() { when(locationRepository.findById(2L)).thenReturn(Optional.of(locations.get(1))); assertThrows(BadRequestException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(locationRepository).findById(1L); @@ -1338,10 +1338,10 @@ void editTariffThrowTariffAlreadyExistsException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); assertThrows(TariffAlreadyExistsException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(locationRepository).findById(1L); @@ -1361,11 +1361,11 @@ void editTariffThrowReceivingStationNotFoundException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); when(receivingStationRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(locationRepository).findById(1L); @@ -1385,7 +1385,7 @@ void editTariffThrowsCourierNotFoundException() { when(courierRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(courierRepository).findById(1L); @@ -1403,11 +1403,11 @@ void editTariffWithoutCourier() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); when(receivingStationRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(locationRepository).findById(1L); @@ -1427,7 +1427,7 @@ void editTariffThrowsCourierHasStatusDeactivatedException() { when(courierRepository.findById(1L)).thenReturn(Optional.of(courier)); assertThrows(BadRequestException.class, - () -> superAdminService.editTariff(1L, dto)); + () -> superAdminService.editTariff(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(courierRepository).findById(1L); @@ -1447,10 +1447,10 @@ void editTariffWithBuildTariffLocation() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffsInfo)); when(locationRepository.findById(1L)).thenReturn(Optional.of(location)); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(1L, List.of(1L))) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); when(tariffsLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) - .thenReturn(Optional.empty()); + .thenReturn(Optional.empty()); when(tariffsLocationRepository.findAllByTariffsInfo(tariffsInfo)).thenReturn(List.of(tariffLocation)); when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfo); @@ -1470,7 +1470,7 @@ void editTariffWithBuildTariffLocation() { void checkIfTariffDoesNotExistsTest() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(anyLong(), any())) - .thenReturn(Collections.emptyList()); + .thenReturn(Collections.emptyList()); boolean actual = superAdminService.checkIfTariffExists(dto); assertFalse(actual); verify(tariffsLocationRepository).findAllByCourierIdAndLocationIds(anyLong(), any()); @@ -1480,14 +1480,14 @@ void checkIfTariffDoesNotExistsTest() { void checkIfTariffExistsTest() { AddNewTariffDto dto = ModelUtils.getAddNewTariffDto(); TariffLocation tariffLocation = TariffLocation - .builder() - .id(1L) - .tariffsInfo(ModelUtils.getTariffsInfo()) - .location(ModelUtils.getLocation()) - .locationStatus(LocationStatus.ACTIVE) - .build(); + .builder() + .id(1L) + .tariffsInfo(ModelUtils.getTariffsInfo()) + .location(ModelUtils.getLocation()) + .locationStatus(LocationStatus.ACTIVE) + .build(); when(tariffsLocationRepository.findAllByCourierIdAndLocationIds(anyLong(), any())) - .thenReturn(List.of(tariffLocation)); + .thenReturn(List.of(tariffLocation)); boolean actual = superAdminService.checkIfTariffExists(dto); assertTrue(actual); verify(tariffsLocationRepository).findAllByCourierIdAndLocationIds(anyLong(), any()); @@ -1561,7 +1561,7 @@ void setTariffLimitsIfBagNotBelongToTariff() { when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(2L, dto)); + () -> superAdminService.setTariffLimits(2L, dto)); verify(tariffsInfoRepository).findById(2L); verify(bagRepository).findById(1); @@ -1616,7 +1616,7 @@ void setTariffLimitsWithNullCourierLimitAndTrueBagLimitIncluded() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1631,7 +1631,7 @@ void setTariffLimitsWithNullAllParamsAndTrueBagLimitIncluded() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1646,7 +1646,7 @@ void setTariffLimitsWithNotNullAllParamsAndFalseBagLimitIncluded() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1659,7 +1659,7 @@ void setTariffsLimitWithSameMinAndMaxValue() { when(tariffsInfoRepository.findById(anyLong())).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1672,7 +1672,7 @@ void setTariffLimitsWithPriceOfOrderMaxValueIsGreaterThanMin() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1685,7 +1685,7 @@ void setTariffLimitsWithAmountOfBigBagMaxValueIsGreaterThanMin() { when(tariffsInfoRepository.findById(anyLong())).thenReturn(Optional.of(tariffInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1697,7 +1697,7 @@ void setTariffLimitsBagThrowTariffsInfoNotFound() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); } @@ -1711,7 +1711,7 @@ void setTariffLimitsBagThrowBagNotFound() { when(bagRepository.findById(1)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.setTariffLimits(1L, dto)); + () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); verify(bagRepository).findById(1); @@ -1736,7 +1736,7 @@ void getTariffLimitsThrowNotFoundException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.getTariffLimits(1L)); + () -> superAdminService.getTariffLimits(1L)); verify(tariffsInfoRepository).findById(1L); } @@ -1789,10 +1789,10 @@ void switchTariffStatusFromWhenCourierDeactivatedThrowBadRequestException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); Throwable t = assertThrows(BadRequestException.class, - () -> superAdminService.switchTariffStatus(1L, "Active")); + () -> superAdminService.switchTariffStatus(1L, "Active")); assertEquals(String.format(ErrorMessage.TARIFF_ACTIVATION_RESTRICTION_DUE_TO_DEACTIVATED_COURIER + - tariffInfo.getCourier().getId()), - t.getMessage()); + tariffInfo.getCourier().getId()), + t.getMessage()); verify(tariffsInfoRepository).findById(1L); verify(tariffsInfoRepository, never()).save(tariffInfo); @@ -1817,7 +1817,7 @@ void switchTariffStatusThrowNotFoundException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.switchTariffStatus(1L, "Active")); + () -> superAdminService.switchTariffStatus(1L, "Active")); verify(tariffsInfoRepository).findById(1L); verify(tariffsInfoRepository, never()).save(any(TariffsInfo.class)); @@ -1830,9 +1830,9 @@ void switchTariffStatusFromActiveToActiveThrowBadRequestException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); Throwable t = assertThrows(BadRequestException.class, - () -> superAdminService.switchTariffStatus(1L, "Active")); + () -> superAdminService.switchTariffStatus(1L, "Active")); assertEquals(String.format(ErrorMessage.TARIFF_ALREADY_HAS_THIS_STATUS, 1L, TariffStatus.ACTIVE), - t.getMessage()); + t.getMessage()); verify(tariffsInfoRepository).findById(1L); verify(tariffsInfoRepository, never()).save(tariffInfo); @@ -1846,9 +1846,9 @@ void switchTariffStatusToActiveWithoutBagThrowBadRequestException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); Throwable t = assertThrows(BadRequestException.class, - () -> superAdminService.switchTariffStatus(1L, "Active")); + () -> superAdminService.switchTariffStatus(1L, "Active")); assertEquals(ErrorMessage.TARIFF_ACTIVATION_RESTRICTION_DUE_TO_UNSPECIFIED_BAGS, - t.getMessage()); + t.getMessage()); verify(tariffsInfoRepository).findById(1L); verify(tariffsInfoRepository, never()).save(tariffInfo); @@ -1862,7 +1862,7 @@ void switchTariffStatusWithUnresolvableStatusThrowBadRequestException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); Throwable t = assertThrows(BadRequestException.class, - () -> superAdminService.switchTariffStatus(1L, "new")); + () -> superAdminService.switchTariffStatus(1L, "new")); assertEquals(ErrorMessage.UNRESOLVABLE_TARIFF_STATUS, t.getMessage()); verify(tariffsInfoRepository).findById(1L); @@ -1878,9 +1878,9 @@ void switchTariffStatusToActiveWithMinAndMaxNullThrowBadRequestException() { when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); Throwable t = assertThrows(BadRequestException.class, - () -> superAdminService.switchTariffStatus(1L, "Active")); + () -> superAdminService.switchTariffStatus(1L, "Active")); assertEquals(ErrorMessage.TARIFF_ACTIVATION_RESTRICTION_DUE_TO_UNSPECIFIED_LIMITS, - t.getMessage()); + t.getMessage()); verify(tariffsInfoRepository).findById(1L); verify(tariffsInfoRepository, never()).save(tariffInfo); @@ -1942,7 +1942,7 @@ void changeTariffLocationsStatusParamUnresolvable() { when(tariffsInfoRepository.findById(anyLong())).thenReturn(Optional.of(tariffsInfo)); assertThrows(BadRequestException.class, - () -> superAdminService.changeTariffLocationsStatus(1L, dto, "unresolvable")); + () -> superAdminService.changeTariffLocationsStatus(1L, dto, "unresolvable")); } @Test @@ -1950,7 +1950,7 @@ void switchActivationStatusByChosenParamsBadRequestExceptionUnresolvableStatus() DetailsOfDeactivateTariffsDto details = ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegion(); details.setActivationStatus("Test"); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test @@ -1969,7 +1969,7 @@ void switchActivationStatusByAllValidParams() { when(receivingStationRepository.findById(anyLong())).thenReturn(Optional.of(receivingStation)); when(receivingStationRepository.saveAll(List.of(receivingStation))).thenReturn(List.of(receivingStation)); doNothing().when(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); superAdminService.switchActivationStatusByChosenParams(details); @@ -1977,7 +1977,7 @@ void switchActivationStatusByAllValidParams() { verify(locationRepository).findLocationByIdAndRegionId(1L, 1L); verify(locationRepository).saveAll(List.of(location)); verify(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); verify(courierRepository).findById(1L); verify(courierRepository).save(courier); verify(receivingStationRepository).findById(anyLong()); @@ -2006,13 +2006,13 @@ void switchLocationStatusToActiveByOneRegion() { when(locationRepository.findLocationsByRegionId(1L)).thenReturn(List.of(locationDeactivated)); when(locationRepository.saveAll(List.of(locationActive))).thenReturn(List.of(locationActive)); doNothing().when(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); superAdminService.switchActivationStatusByChosenParams(details); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(List.of(1L)); verify(locationRepository).findLocationsByRegionId(1L); verify(locationRepository).saveAll(List.of(locationActive)); verify(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); } @Test @@ -2039,13 +2039,13 @@ void switchLocationStatusToActiveByTwoRegions() { when(locationRepository.findLocationsByRegionId(2L)).thenReturn(List.of(locationDeactivated)); when(locationRepository.saveAll(List.of(locationActive))).thenReturn(List.of(locationActive)); doNothing().when(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); superAdminService.switchActivationStatusByChosenParams(details); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(anyList()); verify(locationRepository, times(2)).findLocationsByRegionId(anyLong()); verify(locationRepository, times(2)).saveAll(List.of(locationActive)); verify(tariffsLocationRepository, times(2)) - .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L), LocationStatus.ACTIVE.name()); } @Test @@ -2067,7 +2067,7 @@ void deactivateTariffByNotExistingRegionThrows() { when(deactivateTariffsForChosenParamRepository.isRegionsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(List.of(1L)); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByRegions(anyList()); } @@ -2079,7 +2079,7 @@ void switchLocationStatusToActiveByNotExistingRegionThrows() { when(deactivateTariffsForChosenParamRepository.isRegionsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(List.of(1L)); } @@ -2108,19 +2108,19 @@ void switchLocationStatusToActiveByRegionAndCities() { when(deactivateTariffsForChosenParamRepository.isRegionsExists(anyList())).thenReturn(true); when(locationRepository.findLocationByIdAndRegionId(1L, 1L)) - .thenReturn(Optional.of(locationDeactivated1)); + .thenReturn(Optional.of(locationDeactivated1)); when(locationRepository.findLocationByIdAndRegionId(11L, 1L)) - .thenReturn(Optional.of(locationDeactivated2)); + .thenReturn(Optional.of(locationDeactivated2)); when(locationRepository.saveAll(List.of(locationActive1, locationActive2))) - .thenReturn(List.of(locationActive1, locationActive2)); + .thenReturn(List.of(locationActive1, locationActive2)); doNothing().when(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L, 11L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L, 11L), LocationStatus.ACTIVE.name()); superAdminService.switchActivationStatusByChosenParams(details); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(anyList()); verify(locationRepository, times(2)).findLocationByIdAndRegionId(anyLong(), anyLong()); verify(locationRepository).saveAll(List.of(locationActive1, locationActive2)); verify(tariffsLocationRepository) - .changeTariffsLocationStatusByLocationIds(List.of(1L, 11L), LocationStatus.ACTIVE.name()); + .changeTariffsLocationStatusByLocationIds(List.of(1L, 11L), LocationStatus.ACTIVE.name()); } @Test @@ -2130,11 +2130,11 @@ void deactivateTariffByOneRegionAndNotExistingCitiesThrows() { when(regionRepository.existsRegionById(anyLong())).thenReturn(true); when(deactivateTariffsForChosenParamRepository.isCitiesExistForRegion(anyList(), anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(regionRepository).existsRegionById(1L); verify(deactivateTariffsForChosenParamRepository).isCitiesExistForRegion(List.of(1L, 11L), 1L); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByRegionsAndCities(anyList(), - anyLong()); + anyLong()); } @Test @@ -2145,7 +2145,7 @@ void switchLocationStatusToActiveByRegionAndNotExistingCitiesThrows() { when(deactivateTariffsForChosenParamRepository.isRegionsExists(anyList())).thenReturn(true); when(locationRepository.findLocationByIdAndRegionId(anyLong(), anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(anyList()); verify(locationRepository).findLocationByIdAndRegionId(anyLong(), anyLong()); } @@ -2157,7 +2157,7 @@ void switchLocationStatusToActiveByCitiesAndNotExistingRegionBadRequestException details.setActivationStatus("Active"); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test @@ -2167,7 +2167,7 @@ void switchLocationStatusToActiveByCitiesAndTwoRegionsBadRequestException() { details.setActivationStatus("Active"); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test @@ -2176,10 +2176,10 @@ void deactivateTariffByOneNotExistingRegionAndCitiesThrows() { when(regionRepository.existsRegionById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(regionRepository).existsRegionById(1L); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByRegionsAndCities(anyList(), - anyLong()); + anyLong()); } @Test @@ -2189,7 +2189,7 @@ void switchLocationStatusToActiveExistingRegionAndCitiesThrows() { when(deactivateTariffsForChosenParamRepository.isRegionsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(deactivateTariffsForChosenParamRepository).isRegionsExists(anyList()); } @@ -2222,7 +2222,7 @@ void deactivateTariffByNotExistingCourierThrows() { when(courierRepository.existsCourierById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(courierRepository).existsCourierById(1L); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByCourier(anyLong()); } @@ -2234,7 +2234,7 @@ void switchCourierStatusToActiveNotExistingCourierThrows() { when(courierRepository.findById(anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(courierRepository).findById(anyLong()); } @@ -2259,7 +2259,7 @@ void switchReceivingStationsStatusToActive() { when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation1)); when(receivingStationRepository.findById(12L)).thenReturn(Optional.of(receivingStation2)); when(receivingStationRepository.saveAll(List.of(receivingStation1, receivingStation2))) - .thenReturn(List.of(receivingStation1, receivingStation2)); + .thenReturn(List.of(receivingStation1, receivingStation2)); superAdminService.switchActivationStatusByChosenParams(details); verify(receivingStationRepository, times(2)).findById(anyLong()); verify(receivingStationRepository).saveAll(anyList()); @@ -2271,7 +2271,7 @@ void deactivateTariffByNotExistingReceivingStationsThrows() { when(deactivateTariffsForChosenParamRepository.isReceivingStationsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByReceivingStations(anyList()); } @@ -2283,14 +2283,14 @@ void switchReceivingStationsStatusToActiveNotExistingReceivingStationsThrows() { when(receivingStationRepository.findById(anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(receivingStationRepository).findById(anyLong()); } @Test void deactivateTariffByCourierAndReceivingStations() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); when(courierRepository.existsCourierById(anyLong())).thenReturn(true); when(deactivateTariffsForChosenParamRepository.isReceivingStationsExists(anyList())).thenReturn(true); @@ -2298,35 +2298,35 @@ void deactivateTariffByCourierAndReceivingStations() { verify(courierRepository).existsCourierById(1L); verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); verify(deactivateTariffsForChosenParamRepository) - .deactivateTariffsByCourierAndReceivingStations(1L, List.of(1L, 12L)); + .deactivateTariffsByCourierAndReceivingStations(1L, List.of(1L, 12L)); } @Test void deactivateTariffByNotExistingCourierAndReceivingStationsTrows() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); when(courierRepository.existsCourierById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(courierRepository).existsCourierById(1L); verify(deactivateTariffsForChosenParamRepository, never()) - .deactivateTariffsByCourierAndReceivingStations(anyLong(), anyList()); + .deactivateTariffsByCourierAndReceivingStations(anyLong(), anyList()); } @Test void deactivateTariffByCourierAndNotExistingReceivingStationsTrows() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndReceivingStations(); when(courierRepository.existsCourierById(anyLong())).thenReturn(true); when(deactivateTariffsForChosenParamRepository.isReceivingStationsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(courierRepository).existsCourierById(1L); verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); verify(deactivateTariffsForChosenParamRepository, never()) - .deactivateTariffsByCourierAndReceivingStations(anyLong(), anyList()); + .deactivateTariffsByCourierAndReceivingStations(anyLong(), anyList()); } @Test @@ -2348,11 +2348,11 @@ void deactivateTariffByNotExistingCourierAndOneRegionThrows() { when(regionRepository.existsRegionById(anyLong())).thenReturn(true); when(courierRepository.existsCourierById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(regionRepository).existsRegionById(1L); verify(courierRepository).existsCourierById(1L); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByCourierAndRegion(anyLong(), - anyLong()); + anyLong()); } @Test @@ -2361,16 +2361,16 @@ void deactivateTariffByCourierAndNotExistingRegionThrows() { when(regionRepository.existsRegionById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(regionRepository).existsRegionById(1L); verify(deactivateTariffsForChosenParamRepository, never()).deactivateTariffsByCourierAndRegion(anyLong(), - anyLong()); + anyLong()); } @Test void deactivateTariffByOneRegionAndCityAndStation() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation(); doMockForTariffWithRegionAndCityAndStation(true, true, true); superAdminService.switchActivationStatusByChosenParams(details); @@ -2380,29 +2380,29 @@ void deactivateTariffByOneRegionAndCityAndStation() { @ParameterizedTest @MethodSource("deactivateTariffByNotExistingSomeOfTreeParameters") void deactivateTariffByNotExistingRegionAndCityAndStationThrows( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists) { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation(); doMockForTariffWithRegionAndCityAndStation(isRegionExists, isCitiesExistForRegion, isReceivingStationsExists); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verifyForTariffWithRegionAndCityAndStation(isRegionExists, isCitiesExistForRegion, isReceivingStationsExists); verify(deactivateTariffsForChosenParamRepository, never()) - .deactivateTariffsByRegionAndCitiesAndStations(anyLong(), anyList(), anyList()); + .deactivateTariffsByRegionAndCitiesAndStations(anyLong(), anyList(), anyList()); } static Stream deactivateTariffByNotExistingSomeOfTreeParameters() { return Stream.of( - arguments(false, true, true), - arguments(false, false, true), - arguments(false, true, false), - arguments(true, false, true), - arguments(true, false, false), - arguments(true, true, false), - arguments(false, false, false)); + arguments(false, true, true), + arguments(false, false, true), + arguments(false, true, false), + arguments(true, false, true), + arguments(true, false, false), + arguments(true, true, false), + arguments(false, false, false)); } @Test @@ -2417,39 +2417,39 @@ void deactivateTariffByAllValidParams() { @ParameterizedTest @MethodSource("deactivateTariffByAllWithNotExistingParamProvider") void deactivateTariffByAllWithNotExistingParamThrows( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists, + boolean isCourierExists) { DetailsOfDeactivateTariffsDto details = ModelUtils.getDetailsOfDeactivateTariffsDtoWithAllParams(); doMockForTariffWithAllParams(isRegionExists, isCitiesExistForRegion, isReceivingStationsExists, - isCourierExists); + isCourierExists); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verifyForTariffWithAllParams(isRegionExists, isCitiesExistForRegion, isReceivingStationsExists, - isCourierExists); + isCourierExists); verify(deactivateTariffsForChosenParamRepository, never()) - .deactivateTariffsByAllParam(anyLong(), anyList(), anyList(), anyLong()); + .deactivateTariffsByAllParam(anyLong(), anyList(), anyList(), anyLong()); } private static Stream deactivateTariffByAllWithNotExistingParamProvider() { return Stream.of( - arguments(false, true, true, true), - arguments(true, false, true, true), - arguments(true, true, false, true), - arguments(true, true, true, false), - arguments(false, false, true, true), - arguments(false, true, false, true), - arguments(false, true, true, false), - arguments(false, true, false, false), - arguments(true, false, false, true), - arguments(true, false, true, false), - arguments(true, true, false, false), - arguments(false, false, false, true), - arguments(false, false, true, false), - arguments(true, false, false, false), - arguments(false, false, false, false)); + arguments(false, true, true, true), + arguments(true, false, true, true), + arguments(true, true, false, true), + arguments(true, true, true, false), + arguments(false, false, true, true), + arguments(false, true, false, true), + arguments(false, true, true, false), + arguments(false, true, false, false), + arguments(true, false, false, true), + arguments(true, false, true, false), + arguments(true, true, false, false), + arguments(false, false, false, true), + arguments(false, false, true, false), + arguments(true, false, false, false), + arguments(false, false, false, false)); } @Test @@ -2457,7 +2457,7 @@ void deactivateTariffByAllEmptyParams() { DetailsOfDeactivateTariffsDto details = ModelUtils.getDetailsOfDeactivateTariffsDtoWithEmptyParams(); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test @@ -2465,7 +2465,7 @@ void deactivateTariffByCities() { DetailsOfDeactivateTariffsDto details = ModelUtils.getDetailsOfDeactivateTariffsDtoWithCities(); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test @@ -2473,71 +2473,71 @@ void deactivateTariffByCitiesAndCourier() { DetailsOfDeactivateTariffsDto details = ModelUtils.getDetailsOfDeactivateTariffsDtoWithCitiesAndCourier(); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test void deactivateTariffByCitiesAndReceivingStations() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCitiesAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCitiesAndReceivingStations(); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @Test void deactivateTariffByCitiesAndCourierAndReceivingStations() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCitiesAndCourierAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCitiesAndCourierAndReceivingStations(); assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } @ParameterizedTest @MethodSource("deactivateTariffByDifferentParamWithTwoRegionsProvider") void deactivateTariffByDifferentParamWithTwoRegionsThrows(DetailsOfDeactivateTariffsDto details) { assertThrows(BadRequestException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); } private static Stream deactivateTariffByDifferentParamWithTwoRegionsProvider() { return Stream.of( - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegion() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCities() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithAllParams() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities() - .setRegionsIds(Optional.of(List.of(1L, 2L)))), - arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations() - .setRegionsIds(Optional.of(List.of(1L, 2L))))); + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegion() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCities() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndCityAndStation() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithAllParams() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities() + .setRegionsIds(Optional.of(List.of(1L, 2L)))), + arguments(ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations() + .setRegionsIds(Optional.of(List.of(1L, 2L))))); } private void doMockForTariffWithRegionAndCityAndStation( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists) { when(regionRepository.existsRegionById(anyLong())).thenReturn(isRegionExists); if (isRegionExists) { when(deactivateTariffsForChosenParamRepository - .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistForRegion); + .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistForRegion); if (isCitiesExistForRegion) { when(deactivateTariffsForChosenParamRepository - .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); + .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); } } } private void verifyForTariffWithRegionAndCityAndStation( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists) { verify(regionRepository).existsRegionById(1L); if (isRegionExists) { verify(deactivateTariffsForChosenParamRepository).isCitiesExistForRegion(List.of(1L, 11L), 1L); @@ -2545,24 +2545,24 @@ private void verifyForTariffWithRegionAndCityAndStation( verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); if (isReceivingStationsExists) { verify(deactivateTariffsForChosenParamRepository) - .deactivateTariffsByRegionAndCitiesAndStations(1L, List.of(1L, 11L), List.of(1L, 12L)); + .deactivateTariffsByRegionAndCitiesAndStations(1L, List.of(1L, 11L), List.of(1L, 12L)); } } } } private void doMockForTariffWithAllParams( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists, + boolean isCourierExists) { when(regionRepository.existsRegionById(anyLong())).thenReturn(isRegionExists); if (isRegionExists) { when(deactivateTariffsForChosenParamRepository - .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistForRegion); + .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistForRegion); if (isCitiesExistForRegion) { when(deactivateTariffsForChosenParamRepository - .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); + .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); if (isReceivingStationsExists) { when(courierRepository.existsCourierById(anyLong())).thenReturn(isCourierExists); } @@ -2571,10 +2571,10 @@ private void doMockForTariffWithAllParams( } private void verifyForTariffWithAllParams( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isReceivingStationsExists, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isReceivingStationsExists, + boolean isCourierExists) { verify(regionRepository).existsRegionById(1L); if (isRegionExists) { verify(deactivateTariffsForChosenParamRepository).isCitiesExistForRegion(List.of(1L, 11L), 1L); @@ -2584,7 +2584,7 @@ private void verifyForTariffWithAllParams( verify(courierRepository).existsCourierById(1L); if (isCourierExists) { verify(deactivateTariffsForChosenParamRepository) - .deactivateTariffsByAllParam(1L, List.of(1L, 11L), List.of(1L, 12L), 1L); + .deactivateTariffsByAllParam(1L, List.of(1L, 11L), List.of(1L, 12L), 1L); } } } @@ -2594,7 +2594,7 @@ private void verifyForTariffWithAllParams( @Test void deactivateTariffByRegionsAndReceivingStations() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); doMockForTariffWithRegionAndStation(true, true); superAdminService.switchActivationStatusByChosenParams(details); @@ -2602,24 +2602,24 @@ void deactivateTariffByRegionsAndReceivingStations() { } private void doMockForTariffWithRegionAndStation( - boolean isRegionExists, - boolean isReceivingStationsExists) { + boolean isRegionExists, + boolean isReceivingStationsExists) { when(regionRepository.existsRegionById(anyLong())).thenReturn(isRegionExists); if (isRegionExists) { when(deactivateTariffsForChosenParamRepository - .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); + .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationsExists); } } private void verifyForTariffWithRegionAndStation( - boolean isRegionExists, - boolean isReceivingStationsExists) { + boolean isRegionExists, + boolean isReceivingStationsExists) { verify(regionRepository).existsRegionById(1L); if (isRegionExists) { verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); if (isReceivingStationsExists) { verify(tariffsInfoRepository) - .deactivateTariffsByRegionAndReceivingStations(1L, List.of(1L, 12L)); + .deactivateTariffsByRegionAndReceivingStations(1L, List.of(1L, 12L)); } } } @@ -2627,37 +2627,37 @@ private void verifyForTariffWithRegionAndStation( @Test void deactivateTariffByNotExistingRegionsAndReceivingStationsTrows() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); when(regionRepository.existsRegionById(anyLong())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verify(regionRepository).existsRegionById(1L); verify(tariffsInfoRepository, never()).deactivateTariffsByRegionAndReceivingStations( - anyLong(), - anyList()); + anyLong(), + anyList()); } @Test void deactivateTariffByRegionsAndNotExistingReceivingStationsTrows() { DetailsOfDeactivateTariffsDto details1 = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithRegionAndReceivingStations(); when(regionRepository.existsRegionById(anyLong())).thenReturn(true); when(deactivateTariffsForChosenParamRepository.isReceivingStationsExists(anyList())).thenReturn(false); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details1)); + () -> superAdminService.switchActivationStatusByChosenParams(details1)); verify(regionRepository).existsRegionById(1L); verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); verify(tariffsInfoRepository, never()).deactivateTariffsByRegionAndReceivingStations( - anyLong(), - anyList()); + anyLong(), + anyList()); } @Test void deactivateTariffByCourierAndRegionAndCities() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities(); doMockForTariffWithCourierAndRegionAndCities(true, true, true); superAdminService.switchActivationStatusByChosenParams(details); @@ -2665,13 +2665,13 @@ void deactivateTariffByCourierAndRegionAndCities() { } private void doMockForTariffWithCourierAndRegionAndCities( - boolean isRegionExists, - boolean isCitiesExistsForRegion, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistsForRegion, + boolean isCourierExists) { when(regionRepository.existsRegionById(anyLong())).thenReturn(isRegionExists); if (isRegionExists) { when(deactivateTariffsForChosenParamRepository - .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistsForRegion); + .isCitiesExistForRegion(anyList(), anyLong())).thenReturn(isCitiesExistsForRegion); if (isCitiesExistsForRegion) { when(courierRepository.existsCourierById(anyLong())).thenReturn(isCourierExists); } @@ -2679,9 +2679,9 @@ private void doMockForTariffWithCourierAndRegionAndCities( } private void verifyForTariffWithCourierAndRegionAndCities( - boolean isRegionExists, - boolean isCitiesExistsForRegion, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistsForRegion, + boolean isCourierExists) { verify(regionRepository).existsRegionById(1L); if (isRegionExists) { verify(deactivateTariffsForChosenParamRepository).isCitiesExistForRegion(List.of(1L, 11L), 1L); @@ -2689,7 +2689,7 @@ private void verifyForTariffWithCourierAndRegionAndCities( verify(courierRepository).existsCourierById(1L); if (isCourierExists) { verify(tariffsInfoRepository) - .deactivateTariffsByCourierAndRegionAndCities(1L, List.of(1L, 11L), 1L); + .deactivateTariffsByCourierAndRegionAndCities(1L, List.of(1L, 11L), 1L); } } } @@ -2698,26 +2698,26 @@ private void verifyForTariffWithCourierAndRegionAndCities( @ParameterizedTest @MethodSource("deactivateTariffByNotExistingSomeOfTreeParameters") void deactivateTariffByCourierAndRegionsAndCitiesWithNotExistingParamThrows( - boolean isRegionExists, - boolean isCitiesExistForRegion, - boolean isCourierExists) { + boolean isRegionExists, + boolean isCitiesExistForRegion, + boolean isCourierExists) { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndCities(); doMockForTariffWithCourierAndRegionAndCities(isRegionExists, isCitiesExistForRegion, - isCourierExists); + isCourierExists); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verifyForTariffWithCourierAndRegionAndCities(isRegionExists, isCitiesExistForRegion, - isCourierExists); + isCourierExists); verify(tariffsInfoRepository, never()) - .deactivateTariffsByCourierAndRegionAndCities(anyLong(), anyList(), anyLong()); + .deactivateTariffsByCourierAndRegionAndCities(anyLong(), anyList(), anyLong()); } @Test void deactivateTariffByCourierAndRegionAndReceivingStation() { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations(); doMockForTariffWithCourierAndRegionAndReceivingStation(true, true, true); superAdminService.switchActivationStatusByChosenParams(details); @@ -2725,13 +2725,13 @@ void deactivateTariffByCourierAndRegionAndReceivingStation() { } private void doMockForTariffWithCourierAndRegionAndReceivingStation( - boolean isRegionExists, - boolean isCourierExists, - boolean isReceivingStationExists) { + boolean isRegionExists, + boolean isCourierExists, + boolean isReceivingStationExists) { when(regionRepository.existsRegionById(anyLong())).thenReturn(isRegionExists); if (isRegionExists) { when(deactivateTariffsForChosenParamRepository - .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationExists); + .isReceivingStationsExists(anyList())).thenReturn(isReceivingStationExists); if (isReceivingStationExists) { when(courierRepository.existsCourierById(anyLong())).thenReturn(isCourierExists); } @@ -2739,9 +2739,9 @@ private void doMockForTariffWithCourierAndRegionAndReceivingStation( } private void verifyForTariffWithCourierAndRegionAndReceivingStation( - boolean isRegionExists, - boolean isCourierExists, - boolean isReceivingStationExists) { + boolean isRegionExists, + boolean isCourierExists, + boolean isReceivingStationExists) { verify(regionRepository).existsRegionById(1L); if (isRegionExists) { verify(deactivateTariffsForChosenParamRepository).isReceivingStationsExists(List.of(1L, 12L)); @@ -2749,7 +2749,7 @@ private void verifyForTariffWithCourierAndRegionAndReceivingStation( verify(courierRepository).existsCourierById(1L); if (isCourierExists) { verify(tariffsInfoRepository) - .deactivateTariffsByCourierAndRegionAndReceivingStations(1L, List.of(1L, 12L), 1L); + .deactivateTariffsByCourierAndRegionAndReceivingStations(1L, List.of(1L, 12L), 1L); } } } @@ -2758,19 +2758,19 @@ private void verifyForTariffWithCourierAndRegionAndReceivingStation( @ParameterizedTest @MethodSource("deactivateTariffByNotExistingSomeOfTreeParameters") void deactivateTariffByCourierAndRegionsAndReceivingStationWithNotExistingParamThrows( - boolean isRegionExists, - boolean isCourierExists, - boolean isReceivingStationExists) { + boolean isRegionExists, + boolean isCourierExists, + boolean isReceivingStationExists) { DetailsOfDeactivateTariffsDto details = - ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations(); + ModelUtils.getDetailsOfDeactivateTariffsDtoWithCourierAndRegionAndReceivingStations(); doMockForTariffWithCourierAndRegionAndReceivingStation(isRegionExists, isReceivingStationExists, - isCourierExists); + isCourierExists); assertThrows(NotFoundException.class, - () -> superAdminService.switchActivationStatusByChosenParams(details)); + () -> superAdminService.switchActivationStatusByChosenParams(details)); verifyForTariffWithCourierAndRegionAndReceivingStation(isRegionExists, isReceivingStationExists, - isCourierExists); + isCourierExists); verify(tariffsInfoRepository, never()) - .deactivateTariffsByCourierAndRegionAndCities(anyLong(), anyList(), anyLong()); + .deactivateTariffsByCourierAndRegionAndCities(anyLong(), anyList(), anyLong()); } } \ No newline at end of file diff --git a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java index 7204e9919..0382361b6 100644 --- a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java @@ -302,6 +302,7 @@ class UBSClientServiceImplTest { private OrderBagService orderBagService; @Mock private OrderBagRepository orderBagRepository; + @Test void testGetAllDistricts() { diff --git a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java index 3c975eb71..bc2322c0a 100644 --- a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java @@ -157,6 +157,7 @@ import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.anyLong; @@ -256,6 +257,7 @@ class UBSManagementServiceImplTest { private OrderBagService orderBagService; @Mock private OrderBagRepository orderBagRepository; + @Test void getAllCertificates() { Pageable pageable = @@ -406,7 +408,7 @@ void checkUpdateManualPayment() { when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.findById(1L)).thenReturn(Optional.of(getManualPayment())); when(paymentRepository.save(any())).thenReturn(getManualPayment()); - when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(getBaglist()); +// when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(getBaglist()); doNothing().when(eventService).save(OrderHistory.UPDATE_PAYMENT_MANUALLY + 1, employee.getFirstName() + " " + employee.getLastName(), getOrder()); @@ -415,7 +417,7 @@ void checkUpdateManualPayment() { verify(paymentRepository, times(1)).save(any()); verify(eventService, times(2)).save(any(), any(), any()); verify(fileService, times(0)).delete(null); - verify(orderBagService).findBagsByOrderId(order.getId()); +// verify(orderBagService).findBagsByOrderId(order.getId()); } @Test @@ -1160,8 +1162,10 @@ void testSetOrderDetailNeedToChangeStatusToHALF_PAID() { when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag1list()); when(paymentRepository.selectSumPaid(1L)).thenReturn(5000L); - doNothing().when(orderRepository).updateOrderPaymentStatus(1L, OrderPaymentStatus.HALF_PAID.name()); + doNothing().when(orderRepository).updateOrderPaymentStatus(1L, OrderPaymentStatus.HALF_PAID.name()); + when(orderRepository.findSumOfCertificatesByOrderId(1L)).thenReturn(10L); + when(orderBagService.findAllBagsInOrderBagsList(anyList())).thenReturn(ModelUtils.TEST_BAG_LIST2); ubsManagementService.setOrderDetail(1L, UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); @@ -1184,7 +1188,7 @@ void testSetOrderDetailNeedToChangeStatusToUNPAID() { when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag1list()); when(paymentRepository.selectSumPaid(1L)).thenReturn(null); doNothing().when(orderRepository).updateOrderPaymentStatus(1L, OrderPaymentStatus.UNPAID.name()); - + when(orderBagService.findAllBagsInOrderBagsList(anyList())).thenReturn(ModelUtils.TEST_BAG_LIST2); ubsManagementService.setOrderDetail(1L, UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); @@ -1285,7 +1289,7 @@ void testSetOrderDetailIfPaidAndPriceLessThanPaidSum() { when(orderRepository.findSumOfCertificatesByOrderId(order.getId())).thenReturn(600L); when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusFormedDto2())); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); +// when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(order.getId(), @@ -1918,7 +1922,6 @@ void getOrderSumDetailsForCanceledPaidOrderWithBags() { Order order = ModelUtils.getCanceledPaidOrder(); order.setOrderDate(LocalDateTime.now()); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag3list()); doNothing().when(notificationService).notifyPaidOrder(order); doNothing().when(notificationService).notifyHalfPaidPackage(order); @@ -1947,7 +1950,7 @@ void getOrderSumDetailsForFormedHalfPaidOrder() { Order order = ModelUtils.getFormedHalfPaidOrder(); order.setOrderDate(LocalDateTime.now()); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); +// when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); doNothing().when(notificationService).notifyPaidOrder(order); doNothing().when(notificationService).notifyHalfPaidPackage(order); @@ -1977,7 +1980,6 @@ void getOrderSumDetailsForCanceledHalfPaidOrder() { Order order = ModelUtils.getCanceledHalfPaidOrder(); order.setOrderDate(LocalDateTime.now()); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); doNothing().when(notificationService).notifyPaidOrder(order); doNothing().when(notificationService).notifyHalfPaidPackage(order); @@ -2021,7 +2023,7 @@ void getOrderStatusDataTest() { ubsManagementService.getOrderStatusData(1L, "test@gmail.com"); - verify(orderRepository).getOrderDetails(1L); +// verify(orderRepository).getOrderDetails(1L); verify(orderBagService).findBagsByOrderId(1L); verify(bagRepository).findBagsByTariffsInfoId(1L); verify(certificateRepository).findCertificate(1L); @@ -2081,7 +2083,7 @@ void getOrderStatusDataTestEmptyPriceDetails() { when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag2list()); +// when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag2list()); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when(orderStatusTranslationRepository.getOrderStatusTranslationById(6L)) @@ -2097,7 +2099,7 @@ void getOrderStatusDataTestEmptyPriceDetails() { ubsManagementService.getOrderStatusData(1L, "test@gmail.com"); verify(orderRepository).getOrderDetails(1L); - verify(orderBagService).findBagsByOrderId(1L); +// verify(orderBagService).findBagsByOrderId(1L); verify(bagRepository).findBagsByTariffsInfoId(1L); verify(certificateRepository).findCertificate(1L); verify(orderRepository, times(5)).findById(1L); @@ -2122,7 +2124,7 @@ void getOrderStatusDataWithEmptyCertificateTest() { when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); +// when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); @@ -2138,7 +2140,7 @@ void getOrderStatusDataWithEmptyCertificateTest() { ubsManagementService.getOrderStatusData(1L, "test@gmail.com"); verify(orderRepository).getOrderDetails(1L); - verify(orderBagService).findBagsByOrderId(1L); +// verify(orderBagService).findBagsByOrderId(1L); verify(bagRepository).findBagsByTariffsInfoId(1L); verify(orderRepository, times(5)).findById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); @@ -2161,7 +2163,7 @@ void getOrderStatusDataWhenOrderTranslationIsNull() { when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); +// when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); @@ -2175,7 +2177,7 @@ void getOrderStatusDataWhenOrderTranslationIsNull() { ubsManagementService.getOrderStatusData(1L, "test@gmail.com"); verify(orderRepository).getOrderDetails(1L); - verify(orderBagService).findBagsByOrderId(1L); +// verify(orderBagService).findBagsByOrderId(1L); verify(bagRepository).findBagsByTariffsInfoId(1L); verify(orderRepository, times(5)).findById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); @@ -2198,7 +2200,7 @@ void getOrderStatusDataExceptionTest() { when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); +// when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(1L)).thenReturn(getCertificateList()); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); @@ -2494,7 +2496,6 @@ void getOrderStatusDataWithNotEmptyLists() { verify(orderRepository).getOrderDetails(1L); verify(bagRepository).findBagsByTariffsInfoId(1L); - verify(orderBagService).findBagsByOrderId(1L); verify(certificateRepository).findCertificate(1L); verify(orderRepository, times(5)).findById(1L); verify(modelMapper).map(getBaglist().get(0), BagInfoDto.class); @@ -2544,7 +2545,7 @@ void getOrderStatusesTranslationTest() { ubsManagementService.getOrderStatusData(1L, "test@gmail.com"); verify(orderRepository).getOrderDetails(1L); - verify(orderBagService).findBagsByOrderId(1L); +// verify(orderBagService).findBagsByOrderId(1L); verify(bagRepository).findBagsByTariffsInfoId(1L); verify(certificateRepository).findCertificate(1L); verify(orderRepository, times(5)).findById(1L); @@ -2642,7 +2643,7 @@ void addBonusesToUserIfOrderStatusIsCanceled() { Employee employee = getEmployee(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); +// when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(order.getId())).thenReturn(getCertificateList()); ubsManagementService.addBonusesToUser(getAddBonusesToUserDto(), 1L, employee.getEmail()); From 370f8fd5d5371f143482682bf2780741174dafcd Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 24 Jul 2023 10:45:18 +0300 Subject: [PATCH 21/73] Fixed tests in UBSClientServiceImplTest --- .../service/ubs/OrderBagService.java | 14 +- .../service/ubs/UBSClientServiceImpl.java | 7 +- .../service/ubs/UBSClientServiceImplTest.java | 215 ++++++++++-------- 3 files changed, 123 insertions(+), 113 deletions(-) diff --git a/service/src/main/java/greencity/service/ubs/OrderBagService.java b/service/src/main/java/greencity/service/ubs/OrderBagService.java index c35d9f05e..43ab2c60b 100644 --- a/service/src/main/java/greencity/service/ubs/OrderBagService.java +++ b/service/src/main/java/greencity/service/ubs/OrderBagService.java @@ -8,6 +8,8 @@ import greencity.repository.OrderBagRepository; import greencity.repository.OrderRepository; import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -21,6 +23,7 @@ @Service @AllArgsConstructor @Slf4j +@Data public class OrderBagService { private final OrderBagRepository orderBagRepository; private final OrderRepository orderRepository; @@ -109,15 +112,4 @@ public void removeBagFromOrder(Long orderId, OrderBag orderBag) { order.getOrderBags().remove(orderBag); orderRepository.save(order); } - - /** - * method helps to set bags for order. - * - * @param orderBags {@link List} of {@link OrderBag} - * @author Oksana Spodaryk - */ - public void setBagsForOrder(Order order, List orderBags) { - orderBags.forEach(it -> it.setOrder(order)); - order.setOrderBags(orderBags); - } } diff --git a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java index 28200390e..a078fef47 100644 --- a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java @@ -205,7 +205,6 @@ public class UBSClientServiceImpl implements UBSClientService { private final UserRepository userRepository; private final BagRepository bagRepository; - private final OrderBagRepository orderBagRepository; private final UBSuserRepository ubsUserRepository; private final ModelMapper modelMapper; private final CertificateRepository certificateRepository; @@ -231,11 +230,10 @@ public class UBSClientServiceImpl implements UBSClientService { private final TelegramBotRepository telegramBotRepository; private final ViberBotRepository viberBotRepository; private final LocationApiService locationApiService; + private final OrderBagRepository orderBagRepository; @Lazy @Autowired private UBSManagementService ubsManagementService; - @Autowired - private OrderBagService orderBagService; @Value("${greencity.payment.fondy-payment-key}") private String fondyPaymentKey; @Value("${greencity.payment.merchant-id}") @@ -1046,7 +1044,8 @@ private Order formAndSaveOrder(Order order, Set orderCertificates, User currentUser, long sumToPayInCoins) { order.setOrderStatus(OrderStatus.FORMED); order.setCertificates(orderCertificates); - orderBagService.setBagsForOrder(order, bagsOrdered); + bagsOrdered.forEach(it -> it.setOrder(order)); + order.setOrderBags(bagsOrdered); order.setUbsUser(userData); order.setUser(currentUser); order.setSumTotalAmountWithoutDiscounts( diff --git a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java index 0382361b6..0a106eec7 100644 --- a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java @@ -42,14 +42,7 @@ import greencity.dto.user.UserProfileDto; import greencity.dto.user.UserProfileUpdateDto; import greencity.entity.coords.Coordinates; -import greencity.entity.order.Bag; -import greencity.entity.order.Certificate; -import greencity.entity.order.Event; -import greencity.entity.order.Order; -import greencity.entity.order.OrderPaymentStatusTranslation; -import greencity.entity.order.OrderStatusTranslation; -import greencity.entity.order.Payment; -import greencity.entity.order.TariffsInfo; +import greencity.entity.order.*; import greencity.entity.telegram.TelegramBot; import greencity.entity.user.User; import greencity.entity.user.employee.Employee; @@ -106,7 +99,6 @@ import java.util.stream.Collectors; import static greencity.ModelUtils.TEST_BAG_FOR_USER_DTO; -import static greencity.ModelUtils.TEST_BAG_LIST; import static greencity.ModelUtils.TEST_EMAIL; import static greencity.ModelUtils.TEST_ORDER_ADDRESS_DTO_REQUEST; import static greencity.ModelUtils.TEST_PAYMENT_LIST; @@ -755,7 +747,8 @@ void testSaveToDB() throws IllegalAccessException { f.set(ubsService, "1"); } } - + tariffsInfo.setBags(Arrays.asList(bag)); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); @@ -766,7 +759,6 @@ void testSaveToDB() throws IllegalAccessException { when(orderRepository.findById(any())).thenReturn(Optional.of(order1)); when(encryptionUtil.formRequestSignature(any(), eq(null), eq("1"))).thenReturn("TestValue"); when(fondyClient.getCheckoutResponse(any())).thenReturn(getSuccessfulFondyResponse()); - FondyOrderResponse result = ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null); Assertions.assertNotNull(result); @@ -789,10 +781,12 @@ void testSaveToDBWithTwoBags() throws IllegalAccessException { Bag bag1 = getBagForOrder(); bag1.setId(1); + bag1.setCapacity(100); bag1.setLimitIncluded(false); Bag bag3 = getBagForOrder(); + bag3.setCapacity(1000); TariffsInfo tariffsInfo = getTariffInfo(); - + tariffsInfo.setBags(Arrays.asList(bag1, bag3)); UBSuser ubSuser = getUBSuser(); OrderAddress orderAddress = ubSuser.getOrderAddress(); @@ -803,7 +797,9 @@ void testSaveToDBWithTwoBags() throws IllegalAccessException { Payment payment1 = getPayment(); payment1.setId(1L); order1.getPayment().add(payment1); - + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag(), ModelUtils.getOrderBag(), ModelUtils.getOrderBag())); + order1 + .setOrderBags(Arrays.asList(ModelUtils.getOrderBag(), ModelUtils.getOrderBag(), ModelUtils.getOrderBag())); Field[] fields = UBSClientServiceImpl.class.getDeclaredFields(); for (Field f : fields) { if (f.getName().equals("merchantId")) { @@ -845,6 +841,7 @@ void testSaveToDBWithCertificates() throws IllegalAccessException { Bag bag = getBagForOrder(); TariffsInfo tariffsInfo = getTariffInfo(); + tariffsInfo.setBags(Arrays.asList(bag)); UBSuser ubSuser = getUBSuser(); @@ -868,7 +865,7 @@ void testSaveToDBWithCertificates() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); - when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); + when(bagRepository.findById(any())).thenReturn(Optional.of(bag)); when(certificateRepository.findById(anyString())).thenReturn(Optional.of(getCertificate())); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); @@ -898,6 +895,7 @@ void testSaveToDBWithDontSendLinkToFondy() throws IllegalAccessException { Bag bag = getBagForOrder(); TariffsInfo tariffsInfo = getTariffInfo(); + tariffsInfo.setBags(Arrays.asList(bag)); Certificate certificate = getCertificate(); certificate.setPoints(1000_00); @@ -924,7 +922,7 @@ void testSaveToDBWithDontSendLinkToFondy() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); - when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); + when(bagRepository.findById(any())).thenReturn(Optional.of(bag)); when(certificateRepository.findById(anyString())).thenReturn(Optional.of(certificate)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); @@ -951,6 +949,7 @@ void testSaveToDBWhenSumToPayLessThanPoints() throws IllegalAccessException { Bag bag = getBagForOrder(); TariffsInfo tariffsInfo = getTariffInfo(); + tariffsInfo.setBags(Arrays.asList(bag)); UBSuser ubSuser = getUBSuser(); @@ -974,7 +973,7 @@ void testSaveToDBWhenSumToPayLessThanPoints() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); - when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); + when(bagRepository.findById(any())).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); when(modelMapper.map(dto.getPersonalData(), UBSuser.class)).thenReturn(ubSuser); @@ -1198,11 +1197,14 @@ void testSaveToDBWithoutOrderUnpaid() throws IllegalAccessException { Payment payment1 = getPayment(); payment1.setId(1L); order1.getPayment().add(payment1); - - when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); + TariffsInfo tariffsInfo = getTariffsInfo(); + bag.setTariffsInfo(tariffsInfo); + tariffsInfo.setBags(Arrays.asList(bag)); + order.setTariffsInfo(tariffsInfo); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); - when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); + .thenReturn(Optional.of(tariffsInfo)); + when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); + when(bagRepository.findById(any())).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto.getPersonalData(), UBSuser.class)).thenReturn(ubSuser); when(orderRepository.findById(any())).thenReturn(Optional.of(order1)); @@ -1213,7 +1215,7 @@ void testSaveToDBWithoutOrderUnpaid() throws IllegalAccessException { verify(userRepository, times(1)).findByUuid("35467585763t4sfgchjfuyetf"); verify(tariffsInfoRepository, times(1)) .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); - verify(bagRepository, times(2)).findById(any()); + verify(bagRepository, times(1)).findById(any()); verify(ubsUserRepository, times(1)).findById(anyLong()); verify(modelMapper, times(1)).map(dto.getPersonalData(), UBSuser.class); verify(orderRepository, times(1)).findById(anyLong()); @@ -1227,14 +1229,19 @@ void saveToDBFailPaidOrder() { dto.getBags().get(0).setAmount(5); Order order = getOrder(); order.setOrderPaymentStatus(OrderPaymentStatus.PAID); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); Bag bag = getBagForOrder(); TariffsInfo tariffsInfo = getTariffInfo(); - + bag.setTariffsInfo(tariffsInfo); + tariffsInfo.setBags(Arrays.asList(bag)); + order.setTariffsInfo(tariffsInfo); + when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) + .thenReturn(Optional.of(tariffsInfo)); when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); - when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); + when(bagRepository.findById(any())).thenReturn(Optional.of(bag)); when(orderRepository.findById(any())).thenReturn(Optional.of(order)); assertThrows(BadRequestException.class, @@ -2487,6 +2494,7 @@ void processOrderFondyClient() throws Exception { order.setSumTotalAmountWithoutDiscounts(1000_00L); order.setCertificates(Set.of(getCertificate())); order.setPayment(TEST_PAYMENT_LIST); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); User user = getUser(); user.setCurrentPoints(100); user.setChangeOfPointsList(new ArrayList<>()); @@ -2503,28 +2511,18 @@ void processOrderFondyClient() throws Exception { Certificate certificate = getCertificate(); CertificateDto certificateDto = createCertificateDto(); - when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(userRepository.findUserByUuid("uuid")).thenReturn(Optional.of(user)); - - when(encryptionUtil.formRequestSignature(any(), eq(null), eq("1"))).thenReturn("TestValue"); - when(fondyClient.getCheckoutResponse(any())).thenReturn(getSuccessfulFondyResponse()); - when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(TEST_BAG_LIST); when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(certificateDto); - when(modelMapper.map(any(Bag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); - + when(modelMapper.map(any(OrderBag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); ubsService.processOrderFondyClient(dto, "uuid"); - - verify(encryptionUtil).formRequestSignature(any(), eq(null), eq("1")); - verify(fondyClient).getCheckoutResponse(any()); - } @Test void processOrderFondyClient2() throws Exception { Order order = getOrderCount(); Certificate certificate = getCertificate(); - certificate.setPoints(1500); + HashMap value = new HashMap<>(); value.put(1, 22); order.setAmountOfBagsOrdered(value); @@ -2540,6 +2538,9 @@ void processOrderFondyClient2() throws Exception { OrderFondyClientDto dto = getOrderFondyClientDto(); dto.setCertificates(Set.of("1111-1234")); + order.setCertificates(Set.of(getCertificate())); + order.setPayment(TEST_PAYMENT_LIST); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); Field[] fields = UBSClientServiceImpl.class.getDeclaredFields(); for (Field f : fields) { if (f.getName().equals("merchantId")) { @@ -2548,26 +2549,23 @@ void processOrderFondyClient2() throws Exception { } } + order.setPointsToUse(-10000); CertificateDto certificateDto = createCertificateDto(); - certificateDto.setPoints(1500); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(userRepository.findUserByUuid("uuid")).thenReturn(Optional.of(user)); + when(fondyClient.getCheckoutResponse(any())).thenReturn(getSuccessfulFondyResponse()); + when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(certificateDto); + when(modelMapper.map(any(OrderBag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); when(certificateRepository.findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), CertificateStatus.ACTIVE)).thenReturn(Set.of(certificate)); - when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(TEST_BAG_LIST); - when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(certificateDto); - when(modelMapper.map(any(Bag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); - ubsService.processOrderFondyClient(dto, "uuid"); - verify(orderRepository).findById(1L); verify(userRepository).findUserByUuid("uuid"); verify(certificateRepository).findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), CertificateStatus.ACTIVE); - verify(orderBagService).findBagsByOrderId(order.getId()); - verify(modelMapper).map(certificate, CertificateDto.class); - verify(modelMapper).map(any(Bag.class), eq(BagForUserDto.class)); + verify(modelMapper).map(any(OrderBag.class), eq(BagForUserDto.class)); } @Test @@ -2586,7 +2584,6 @@ void processOrderFondyClientCertificeteNotFoundExeption() throws Exception { user.setCurrentPoints(100); user.setChangeOfPointsList(new ArrayList<>()); order.setUser(user); - OrderFondyClientDto dto = getOrderFondyClientDto(); dto.setCertificates(Set.of("1111-1234")); @@ -2600,24 +2597,21 @@ void processOrderFondyClientCertificeteNotFoundExeption() throws Exception { CertificateDto certificateDto = createCertificateDto(); certificateDto.setPoints(1500); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(userRepository.findUserByUuid("uuid")).thenReturn(Optional.of(user)); when(certificateRepository.findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), CertificateStatus.ACTIVE)).thenReturn(Collections.emptySet()); - when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(TEST_BAG_LIST); when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(certificateDto); - when(modelMapper.map(any(Bag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); - + when(modelMapper.map(any(OrderBag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); assertThrows(NotFoundException.class, () -> ubsService.processOrderFondyClient(dto, "uuid")); - verify(orderRepository).findById(1L); verify(userRepository).findUserByUuid("uuid"); verify(certificateRepository).findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), CertificateStatus.ACTIVE); - verify(orderBagService).findBagsByOrderId(order.getId()); verify(modelMapper).map(certificate, CertificateDto.class); - verify(modelMapper).map(any(Bag.class), eq(BagForUserDto.class)); + verify(modelMapper).map(any(OrderBag.class), eq(BagForUserDto.class)); } @Test @@ -2650,14 +2644,14 @@ void processOrderFondyClientCertificeteNotFoundExeption2() throws Exception { CertificateDto certificateDto = createCertificateDto(); certificateDto.setPoints(1500); - + order.setPointsToUse(-1000); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(userRepository.findUserByUuid("uuid")).thenReturn(Optional.of(user)); when(certificateRepository.findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), CertificateStatus.ACTIVE)).thenReturn(Set.of(certificate)); - when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(TEST_BAG_LIST); when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(certificateDto); - when(modelMapper.map(any(Bag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); + when(modelMapper.map(any(OrderBag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); assertThrows(NotFoundException.class, () -> ubsService.processOrderFondyClient(dto, "uuid")); @@ -2665,9 +2659,8 @@ void processOrderFondyClientCertificeteNotFoundExeption2() throws Exception { verify(userRepository).findUserByUuid("uuid"); verify(certificateRepository).findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), CertificateStatus.ACTIVE); - verify(orderBagService).findBagsByOrderId(order.getId()); verify(modelMapper).map(certificate, CertificateDto.class); - verify(modelMapper).map(any(Bag.class), eq(BagForUserDto.class)); + verify(modelMapper).map(any(OrderBag.class), eq(BagForUserDto.class)); } @Test @@ -2685,7 +2678,8 @@ void processOrderFondyClientIfSumToPayLessThanPoints() throws Exception { user.setCurrentPoints(100); user.setChangeOfPointsList(new ArrayList<>()); order.setUser(user); - + order.setPointsToUse(-10000); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); OrderFondyClientDto dto = getOrderFondyClientDto(); Field[] fields = UBSClientServiceImpl.class.getDeclaredFields(); for (Field f : fields) { @@ -2700,12 +2694,9 @@ void processOrderFondyClientIfSumToPayLessThanPoints() throws Exception { when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(userRepository.findUserByUuid("uuid")).thenReturn(Optional.of(user)); - - when(encryptionUtil.formRequestSignature(any(), eq(null), eq("1"))).thenReturn("TestValue"); when(fondyClient.getCheckoutResponse(any())).thenReturn(getSuccessfulFondyResponse()); - when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(TEST_BAG_LIST); when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(certificateDto); - when(modelMapper.map(any(Bag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); + when(modelMapper.map(any(OrderBag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); ubsService.processOrderFondyClient(dto, "uuid"); @@ -2740,7 +2731,6 @@ void saveFullOrderToDBForIF() throws IllegalAccessException { bag.setFullPrice(400_00L); TariffsInfo tariffsInfo = getTariffsInfo(); bag.setTariffsInfo(tariffsInfo); - UBSuser ubSuser = getUBSuser(); OrderAddress address = ubSuser.getOrderAddress(); @@ -2751,6 +2741,8 @@ void saveFullOrderToDBForIF() throws IllegalAccessException { Payment payment1 = getPayment(); payment1.setId(1L); order1.getPayment().add(payment1); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); + order1.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); Field[] fields = UBSClientServiceImpl.class.getDeclaredFields(); for (Field f : fields) { @@ -2760,10 +2752,13 @@ void saveFullOrderToDBForIF() throws IllegalAccessException { } } - when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); + bag.setTariffsInfo(tariffsInfo); + tariffsInfo.setBags(Arrays.asList(bag)); + order.setTariffsInfo(tariffsInfo); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); - when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); + .thenReturn(Optional.of(tariffsInfo)); + when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); + when(bagRepository.findById(any())).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); when(certificateRepository.findById("1111-1234")).thenReturn(Optional.of(getCertificate())); @@ -2791,7 +2786,7 @@ void saveFullOrderToDBWhenSumToPayeqNull() throws IllegalAccessException { user.setOrders(new ArrayList<>()); user.getOrders().add(order); user.setChangeOfPointsList(new ArrayList<>()); - + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag(), ModelUtils.getOrderBag())); Bag bag = getBagForOrder(); UBSuser ubSuser = getUBSuser().setId(null); @@ -2814,11 +2809,15 @@ void saveFullOrderToDBWhenSumToPayeqNull() throws IllegalAccessException { f.set(ubsService, "1"); } } - - when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); + TariffsInfo tariffsInfo = getTariffsInfo(); + bag.setTariffsInfo(tariffsInfo); + tariffsInfo.setBags(Arrays.asList(bag)); + order.setTariffsInfo(tariffsInfo); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); - when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); + .thenReturn(Optional.of(tariffsInfo)); + when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); + when(bagRepository.findById(any())).thenReturn(Optional.of(bag)); + when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(addressRepository.findById(any())).thenReturn(Optional.of(address)); when(locationRepository.findById(anyLong())).thenReturn(Optional.of(location)); @@ -3076,13 +3075,13 @@ void getOrderForUserTest() { order.setAmountOfBagsOrdered(Map.of(1, 10)); bags.add(bag); order.setUser(user); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); order.setOrderPaymentStatus(OrderPaymentStatus.PAID); orderList.add(order); - + when(modelMapper.map(any(OrderBag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); when(ordersForUserRepository.getAllByUserUuidAndId(user.getUuid(), order.getId())) .thenReturn(order); - when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(bags); - when(modelMapper.map(bag, BagForUserDto.class)).thenReturn(bagForUserDto); +// when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(bags); when(orderStatusTranslationRepository .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) .thenReturn(Optional.of(orderStatusTranslation)); @@ -3092,8 +3091,7 @@ void getOrderForUserTest() { ubsService.getOrderForUser(user.getUuid(), 1L); - verify(modelMapper, times(bags.size())).map(bag, BagForUserDto.class); - verify(orderBagService).findBagsByOrderId(order.getId()); + verify(modelMapper).map(any(OrderBag.class), eq(BagForUserDto.class)); verify(orderStatusTranslationRepository, times(orderList.size())) .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); verify(orderPaymentStatusTranslationRepository, times(orderList.size())) @@ -3136,11 +3134,11 @@ void getOrdersForUserTest() { orderList.add(order); Pageable pageable = PageRequest.of(0, 10, Sort.by("order_date").descending()); Page page = new PageImpl<>(orderList, pageable, 1); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); when(ordersForUserRepository.getAllByUserUuid(pageable, user.getUuid())) .thenReturn(page); - when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(bags); - when(modelMapper.map(bag, BagForUserDto.class)).thenReturn(bagForUserDto); + when(modelMapper.map(any(OrderBag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); when(orderStatusTranslationRepository .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) .thenReturn(Optional.of(orderStatusTranslation)); @@ -3153,13 +3151,11 @@ void getOrdersForUserTest() { assertEquals(dto.getTotalElements(), orderList.size()); assertEquals(dto.getPage().get(0).getId(), order.getId()); - verify(modelMapper, times(bags.size())).map(bag, BagForUserDto.class); - verify(orderBagService).findBagsByOrderId(order.getId()); + verify(modelMapper).map(any(OrderBag.class), eq(BagForUserDto.class)); verify(orderStatusTranslationRepository, times(orderList.size())) .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); verify(orderPaymentStatusTranslationRepository, times(orderList.size())) - .getById( - (long) order.getOrderPaymentStatus().getStatusValue()); + .getById((long) order.getOrderPaymentStatus().getStatusValue()); verify(ordersForUserRepository).getAllByUserUuid(pageable, user.getUuid()); } @@ -3169,6 +3165,7 @@ void testOrdersForUserWithExportedQuantity() { OrderPaymentStatusTranslation orderPaymentStatusTranslation = getOrderPaymentStatusTranslation(); OrdersDataForUserDto ordersDataForUserDto = getOrderStatusDto(); Order order = getOrderTest(); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); User user = getTestUser(); Bag bag = bagDto(); @@ -3188,8 +3185,6 @@ void testOrdersForUserWithExportedQuantity() { when(ordersForUserRepository.getAllByUserUuid(pageable, user.getUuid())) .thenReturn(page); - when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(bags); - when(modelMapper.map(bag, BagForUserDto.class)).thenReturn(bagForUserDto); when(orderStatusTranslationRepository .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) .thenReturn(Optional.of(orderStatusTranslation)); @@ -3197,13 +3192,14 @@ void testOrdersForUserWithExportedQuantity() { (long) order.getOrderPaymentStatus().getStatusValue())) .thenReturn(orderPaymentStatusTranslation); + when(modelMapper.map(any(OrderBag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); + PageableDto dto = ubsService.getOrdersForUser(user.getUuid(), pageable, null); assertEquals(dto.getTotalElements(), orderList.size()); assertEquals(dto.getPage().get(0).getId(), order.getId()); - verify(modelMapper, times(bags.size())).map(bag, BagForUserDto.class); - verify(orderBagService).findBagsByOrderId(order.getId()); + verify(modelMapper).map(any(OrderBag.class), eq(BagForUserDto.class)); verify(orderStatusTranslationRepository, times(orderList.size())) .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); verify(orderPaymentStatusTranslationRepository, times(orderList.size())) @@ -3230,6 +3226,7 @@ void testOrdersForUserWithConfirmedQuantity() { order.setConfirmedQuantity(Map.of(1, 10)); bags.add(bag); order.setUser(user); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); order.setOrderPaymentStatus(OrderPaymentStatus.PAID); orderList.add(order); Pageable pageable = PageRequest.of(0, 10, Sort.by("order_date").descending()); @@ -3237,8 +3234,7 @@ void testOrdersForUserWithConfirmedQuantity() { when(ordersForUserRepository.getAllByUserUuid(pageable, user.getUuid())) .thenReturn(page); - when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(bags); - when(modelMapper.map(bag, BagForUserDto.class)).thenReturn(bagForUserDto); + when(modelMapper.map(any(OrderBag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); when(orderStatusTranslationRepository .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) .thenReturn(Optional.of(orderStatusTranslation)); @@ -3251,8 +3247,7 @@ void testOrdersForUserWithConfirmedQuantity() { assertEquals(dto.getTotalElements(), orderList.size()); assertEquals(dto.getPage().get(0).getId(), order.getId()); - verify(modelMapper, times(bags.size())).map(bag, BagForUserDto.class); - verify(orderBagService).findBagsByOrderId(order.getId()); + verify(modelMapper).map(any(OrderBag.class), eq(BagForUserDto.class)); verify(orderStatusTranslationRepository, times(orderList.size())) .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue()); verify(orderPaymentStatusTranslationRepository, times(orderList.size())) @@ -3272,10 +3267,14 @@ void senderInfoDtoBuilderTest() { order.setAmountOfBagsOrdered(Map.of(1, 10)); order.setUser(user); order.setOrderPaymentStatus(OrderPaymentStatus.PAID); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); orderList.add(order); Pageable pageable = PageRequest.of(0, 10, Sort.by("order_date").descending()); Page page = new PageImpl<>(orderList, pageable, 1); + TariffsInfo tariffsInfo = getTariffsInfo(); + tariffsInfo.setBags(Arrays.asList(getBag())); + order.setTariffsInfo(tariffsInfo); when(ordersForUserRepository.getAllByUserUuid(pageable, user.getUuid())) .thenReturn(page); when(orderStatusTranslationRepository @@ -3284,6 +3283,7 @@ void senderInfoDtoBuilderTest() { when(orderPaymentStatusTranslationRepository.getById( (long) order.getOrderPaymentStatus().getStatusValue())) .thenReturn(orderPaymentStatusTranslation); + when(modelMapper.map(any(OrderBag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); PageableDto dto = ubsService.getOrdersForUser(user.getUuid(), pageable, null); assertEquals(dto.getTotalElements(), orderList.size()); @@ -3412,10 +3412,15 @@ void checkIfAddressHasBeenDeletedTest() throws IllegalAccessException { f.set(ubsService, "1"); } } - - when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); + TariffsInfo tariffsInfo = getTariffsInfo(); + bag.setTariffsInfo(tariffsInfo); + tariffsInfo.setBags(Arrays.asList(bag)); + order.setTariffsInfo(tariffsInfo); +// when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(tariffsInfo)); + when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); + when(bagRepository.findById(any())).thenReturn(Optional.of(bag)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); @@ -3456,11 +3461,15 @@ void checkAddressUserTest() throws IllegalAccessException { f.set(ubsService, "1"); } } - + TariffsInfo tariffsInfo = getTariffsInfo(); + bag.setTariffsInfo(tariffsInfo); + tariffsInfo.setBags(Arrays.asList(bag)); + order.setTariffsInfo(tariffsInfo); when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); - when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); + .thenReturn(Optional.of(tariffsInfo)); + when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); + when(bagRepository.findById(any())).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); when(modelMapper.map(dto.getPersonalData(), UBSuser.class)).thenReturn(ubSuser); @@ -3492,10 +3501,16 @@ void checkIfUserHaveEnoughPointsTest() throws IllegalAccessException { f.set(ubsService, "1"); } } + TariffsInfo tariffsInfo = getTariffsInfo(); + bag.setTariffsInfo(tariffsInfo); + tariffsInfo.setBags(Arrays.asList(bag)); + order.setTariffsInfo(tariffsInfo); when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); + .thenReturn(Optional.of(tariffsInfo)); + when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); + when(bagRepository.findById(any())).thenReturn(Optional.of(bag)); when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, @@ -3563,11 +3578,15 @@ void testOrdersForUserWithQuantity() { bag.setFullPrice(1200_00L); bags.add(bag); order.setUser(user); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); order.setOrderPaymentStatus(OrderPaymentStatus.PAID); orderList.add(order); Pageable pageable = PageRequest.of(0, 10, Sort.by("order_date").descending()); Page page = new PageImpl<>(orderList, pageable, 1); - + TariffsInfo tariffsInfo = getTariffsInfo(); + bag.setTariffsInfo(tariffsInfo); + tariffsInfo.setBags(Arrays.asList(bag)); + order.setTariffsInfo(tariffsInfo); when(ordersForUserRepository.getAllByUserUuid(pageable, user.getUuid())) .thenReturn(page); when(orderStatusTranslationRepository @@ -3576,7 +3595,7 @@ void testOrdersForUserWithQuantity() { when(orderPaymentStatusTranslationRepository.getById( (long) order.getOrderPaymentStatus().getStatusValue())) .thenReturn(orderPaymentStatusTranslation); - + when(modelMapper.map(any(OrderBag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); PageableDto dto = ubsService.getOrdersForUser(user.getUuid(), pageable, null); assertEquals(dto.getTotalElements(), orderList.size()); From 9e06e58564cf83da750b34d2461d63fd5cbc52bb Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 24 Jul 2023 11:04:37 +0300 Subject: [PATCH 22/73] All files working --- .../ubs/UBSManagementServiceImplTest.java | 49 +++++-------------- 1 file changed, 13 insertions(+), 36 deletions(-) diff --git a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java index bc2322c0a..5f16cde7b 100644 --- a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java @@ -473,12 +473,14 @@ void saveNewManualPaymentWithHalfPaidAmount() { when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag1list()); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.save(any())) .thenReturn(payment); doNothing().when(eventService).save(any(), any(), any()); + when(orderBagService.findAllBagsInOrderBagsList(anyList())).thenReturn(ModelUtils.TEST_BAG_LIST2); + ubsManagementService.saveNewManualPayment(1L, paymentDetails, null, "test@gmail.com"); + verify(employeeRepository, times(2)).findByEmail(anyString()); verify(eventService, times(1)).save(OrderHistory.ADD_PAYMENT_MANUALLY + 1, "Петро Петренко", order); @@ -508,7 +510,6 @@ void saveNewManualPaymentWithPaidAmount() { when(employeeRepository.findByEmail("test@gmail.com")).thenReturn(Optional.of(employee)); when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag1list()); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.save(any())) .thenReturn(payment); @@ -1140,7 +1141,6 @@ void testSetOrderDetail() { when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag1list()); when(paymentRepository.selectSumPaid(1L)).thenReturn(5000L); ubsManagementService.setOrderDetail(1L, @@ -1159,13 +1159,11 @@ void testSetOrderDetailNeedToChangeStatusToHALF_PAID() { doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); - when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag1list()); - when(paymentRepository.selectSumPaid(1L)).thenReturn(5000L); - - doNothing().when(orderRepository).updateOrderPaymentStatus(1L, OrderPaymentStatus.HALF_PAID.name()); when(orderRepository.findSumOfCertificatesByOrderId(1L)).thenReturn(10L); when(orderBagService.findAllBagsInOrderBagsList(anyList())).thenReturn(ModelUtils.TEST_BAG_LIST2); + + doNothing().when(orderRepository).updateOrderPaymentStatus(1L, OrderPaymentStatus.HALF_PAID.name()); + ubsManagementService.setOrderDetail(1L, UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); @@ -1185,7 +1183,6 @@ void testSetOrderDetailNeedToChangeStatusToUNPAID() { when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag1list()); when(paymentRepository.selectSumPaid(1L)).thenReturn(null); doNothing().when(orderRepository).updateOrderPaymentStatus(1L, OrderPaymentStatus.UNPAID.name()); when(orderBagService.findAllBagsInOrderBagsList(anyList())).thenReturn(ModelUtils.TEST_BAG_LIST2); @@ -1245,12 +1242,10 @@ void testSetOrderDetailIfHalfPaid() { Bag tariffBagDto = ModelUtils.getTariffBag(); List bagList = getBaglist(); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(orderDto)); - when(bagRepository.findCapacityById(1)).thenReturn(1); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.ofNullable(orderDetailDto)); - when(bagRepository.findById(1)).thenReturn(Optional.ofNullable(tariffBagDto)); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(bagList); when(paymentRepository.selectSumPaid(1L)).thenReturn(0L); when(orderRepository.findSumOfCertificatesByOrderId(1L)).thenReturn(0L); + when(orderBagService.findAllBagsInOrderBagsList(anyList())).thenReturn(ModelUtils.TEST_BAG_LIST2); ubsManagementService.setOrderDetail(1L, UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), @@ -1268,14 +1263,11 @@ void testSetOrderDetailIfPaidAndPriceLessThanDiscount() { when(orderRepository.findSumOfCertificatesByOrderId(order.getId())).thenReturn(600L); when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusFormedDto2())); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); - when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(order.getId(), UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "abc"); - - verify(certificateRepository).save(ModelUtils.getCertificate2().setPoints(20)); + verify(certificateRepository).save(ModelUtils.getCertificate2().setPoints(0)); verify(userRepository).updateUserCurrentPoints(1L, 100); verify(orderRepository).updateOrderPointsToUse(1L, 0); } @@ -1965,7 +1957,7 @@ void getOrderSumDetailsForFormedHalfPaidOrderWithDiffBags() { Order order = ModelUtils.getFormedHalfPaidOrder(); order.setOrderDate(LocalDateTime.now()); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag3list()); +// when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag3list()); doNothing().when(notificationService).notifyPaidOrder(order); doNothing().when(notificationService).notifyHalfPaidPackage(order); @@ -2005,7 +1997,6 @@ void getOrderStatusDataTest() { when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(1L)).thenReturn(getCertificateList()); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); @@ -2023,8 +2014,6 @@ void getOrderStatusDataTest() { ubsManagementService.getOrderStatusData(1L, "test@gmail.com"); -// verify(orderRepository).getOrderDetails(1L); - verify(orderBagService).findBagsByOrderId(1L); verify(bagRepository).findBagsByTariffsInfoId(1L); verify(certificateRepository).findCertificate(1L); verify(orderRepository, times(5)).findById(1L); @@ -2477,7 +2466,7 @@ void getOrderStatusDataWithNotEmptyLists() { .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); +// when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(1L)).thenReturn(getCertificateList()); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); @@ -2521,7 +2510,6 @@ void getOrderStatusesTranslationTest() { when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(1L)).thenReturn(getCertificateList()); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); @@ -2545,7 +2533,6 @@ void getOrderStatusesTranslationTest() { ubsManagementService.getOrderStatusData(1L, "test@gmail.com"); verify(orderRepository).getOrderDetails(1L); -// verify(orderBagService).findBagsByOrderId(1L); verify(bagRepository).findBagsByTariffsInfoId(1L); verify(certificateRepository).findCertificate(1L); verify(orderRepository, times(5)).findById(1L); @@ -2623,7 +2610,6 @@ void addBonusesToUserTest() { Employee employee = getEmployee(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(order.getId())).thenReturn(getCertificateList()); ubsManagementService.addBonusesToUser(getAddBonusesToUserDto(), 1L, employee.getEmail()); @@ -2631,7 +2617,7 @@ void addBonusesToUserTest() { verify(orderRepository).findById(1L); verify(orderRepository).save(order); verify(userRepository).save(user); - verify(notificationService).notifyBonuses(order, 809L); + verify(notificationService).notifyBonuses(order, 900L); verify(eventService).saveEvent(OrderHistory.ADDED_BONUSES, employee.getEmail(), order); } @@ -2662,7 +2648,6 @@ void addBonusesToUserWithoutExportedBagsTest() { Employee employee = getEmployee(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(order.getId())).thenReturn(getCertificateList()); ubsManagementService.addBonusesToUser(getAddBonusesToUserDto(), 1L, employee.getEmail()); @@ -2670,26 +2655,18 @@ void addBonusesToUserWithoutExportedBagsTest() { verify(orderRepository).findById(1L); verify(orderRepository).save(order); verify(userRepository).save(user); - verify(notificationService).notifyBonuses(order, 209L); + verify(notificationService).notifyBonuses(order, 300L); verify(eventService).saveEvent(OrderHistory.ADDED_BONUSES, employee.getEmail(), order); } - @Test - void addBonusesToUserWithoutOrderTest() { - when(orderRepository.findById(1L)).thenReturn(Optional.empty()); - AddBonusesToUserDto dto = getAddBonusesToUserDto(); - String email = getEmployee().getEmail(); - assertThrows(NotFoundException.class, () -> ubsManagementService.addBonusesToUser(dto, 1L, email)); - } - @Test void addBonusesToUserWithNoOverpaymentTest() { Order order = getOrderForGetOrderStatusData2Test(); String email = getEmployee().getEmail(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag3list()); when(certificateRepository.findCertificate(order.getId())).thenReturn(getCertificateList()); + when(orderBagService.findAllBagsInOrderBagsList(anyList())).thenReturn(ModelUtils.TEST_BAG_LIST2); AddBonusesToUserDto addBonusesToUserDto = getAddBonusesToUserDto(); assertThrows(BadRequestException.class, From 455b4ae625f38ccff474690e05491fd705d4b09e Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 24 Jul 2023 13:08:13 +0300 Subject: [PATCH 23/73] Fixed tests and added new --- .../service/ubs/OrderBagService.java | 13 ++-- .../service/ubs/SuperAdminServiceImpl.java | 9 +-- .../service/ubs/UBSClientServiceImpl.java | 20 +---- .../src/test/java/greencity/ModelUtils.java | 7 ++ .../service/ubs/OrderBagServiceTest.java | 65 ++++++++++++++++ .../ubs/SuperAdminServiceImplTest.java | 78 ++++++------------- .../service/ubs/UBSClientServiceImplTest.java | 31 ++++++-- 7 files changed, 133 insertions(+), 90 deletions(-) create mode 100644 service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java diff --git a/service/src/main/java/greencity/service/ubs/OrderBagService.java b/service/src/main/java/greencity/service/ubs/OrderBagService.java index 43ab2c60b..838a84c87 100644 --- a/service/src/main/java/greencity/service/ubs/OrderBagService.java +++ b/service/src/main/java/greencity/service/ubs/OrderBagService.java @@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -25,8 +26,7 @@ @Slf4j @Data public class OrderBagService { - private final OrderBagRepository orderBagRepository; - private final OrderRepository orderRepository; + private OrderBagRepository orderBagRepository; private Long getActualPrice(List orderBags, Integer id) { return orderBags.stream() @@ -106,10 +106,9 @@ public Map getActualBagsAmountForOrder(List bagsForO * @param orderBag {@link OrderBag} * @author Oksana Spodaryk */ - public void removeBagFromOrder(Long orderId, OrderBag orderBag) { - Order order = orderRepository.findById(orderId) - .orElseThrow(() -> new NotFoundException(ErrorMessage.ORDER_NOT_FOUND + orderId)); - order.getOrderBags().remove(orderBag); - orderRepository.save(order); + public void removeBagFromOrder(Order order, OrderBag orderBag) { + List modifiableList = new ArrayList<>(order.getOrderBags()); + modifiableList.remove(orderBag); + order.setOrderBags(modifiableList); } } diff --git a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java index 8c30160e0..3eb9b4909 100644 --- a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java @@ -122,8 +122,7 @@ public class SuperAdminServiceImpl implements SuperAdminService { "Current region: %s or cities: %s or receiving stations: %s or courier: %s don't exist."; private final OrderBagRepository orderBagRepository; private final OrderRepository orderRepository; - @Autowired - private OrderBagService orderBagService; + private final OrderBagService orderBagService; @Override public GetTariffServiceDto addTariffService(long tariffId, TariffServiceDto dto, String employeeUuid) { @@ -161,7 +160,7 @@ public void deleteTariffService(Integer bagId) { } private void deleteBagFromOrder(Order order, Integer bagId) { - Map amount = UBSClientServiceImpl.getActualBagsAmountForOrder(order.getOrderBags()); + Map amount = orderBagService.getActualBagsAmountForOrder(order.getOrderBags()); Integer totalBagsAmount = amount.values().stream().reduce(0, Integer::sum); if (amount.get(bagId).equals(0) || order.getOrderPaymentStatus() == OrderPaymentStatus.UNPAID) { if (totalBagsAmount.equals(amount.get(bagId))) { @@ -171,7 +170,7 @@ private void deleteBagFromOrder(Order order, Integer bagId) { } order.getOrderBags().stream().filter(it -> it.getBag().getId().equals(bagId)) .findFirst() - .ifPresent(obj -> orderBagService.removeBagFromOrder(order.getId(), obj)); + .ifPresent(obj -> orderBagService.removeBagFromOrder(order, obj)); orderRepository.save(order); } } @@ -224,7 +223,7 @@ public GetTariffServiceDto editTariffService(TariffServiceDto dto, Integer bagId } private void updateOrderSumToPay(Order order, Bag bag) { - Map amount = UBSClientServiceImpl.getActualBagsAmountForOrder(order.getOrderBags()); + Map amount = orderBagService.getActualBagsAmountForOrder(order.getOrderBags()); Long sumToPayInCoins = order.getOrderBags().stream() .map(it -> amount.get(it.getBag().getId()) * getActualBagPrice(it, bag)) .reduce(0L, Long::sum); diff --git a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java index a078fef47..9aa559908 100644 --- a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java @@ -231,6 +231,8 @@ public class UBSClientServiceImpl implements UBSClientService { private final ViberBotRepository viberBotRepository; private final LocationApiService locationApiService; private final OrderBagRepository orderBagRepository; + private final OrderBagService orderBagService; + @Lazy @Autowired private UBSManagementService ubsManagementService; @@ -886,28 +888,12 @@ private AddressInfoDto addressInfoDtoBuilder(Order order) { private List bagForUserDtosBuilder(Order order) { List bagsForOrder = order.getOrderBags(); - Map actualBagsAmount = getActualBagsAmountForOrder(bagsForOrder); + Map actualBagsAmount = orderBagService.getActualBagsAmountForOrder(bagsForOrder); return bagsForOrder.stream() .map(orderBag -> buildBagForUserDto(orderBag, actualBagsAmount.get(orderBag.getBag().getId()))) .collect(toList()); } - static Map getActualBagsAmountForOrder(List bagsForOrder) { - if (bagsForOrder.stream().allMatch(it -> it.getExportedQuantity() != null)) { - return bagsForOrder.stream() - .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getExportedQuantity)); - } - if (bagsForOrder.stream().allMatch(it -> it.getConfirmedQuantity() != null)) { - return bagsForOrder.stream() - .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getConfirmedQuantity)); - } - if (bagsForOrder.stream().allMatch(it -> it.getAmount() != null)) { - return bagsForOrder.stream() - .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getAmount)); - } - return new HashMap<>(); - } - private BagForUserDto buildBagForUserDto(OrderBag orderBag, int count) { BagForUserDto bagDto = modelMapper.map(orderBag, BagForUserDto.class); bagDto.setCount(count); diff --git a/service/src/test/java/greencity/ModelUtils.java b/service/src/test/java/greencity/ModelUtils.java index 75e6a191f..fe886952d 100644 --- a/service/src/test/java/greencity/ModelUtils.java +++ b/service/src/test/java/greencity/ModelUtils.java @@ -3686,6 +3686,13 @@ public static BigOrderTableViews getBigOrderTableViewsByDateNullTest() { .setResponsibleNavigator(null); } + public static Map getAmount() { + Map hashMap = new HashMap<>(); + hashMap.put(1, 1); + hashMap.put(2, 1); + return hashMap; + } + public static Order getOrderForGetOrderStatusData2Test() { Map hashMap = new HashMap<>(); hashMap.put(1, 1); diff --git a/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java b/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java new file mode 100644 index 000000000..497327924 --- /dev/null +++ b/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java @@ -0,0 +1,65 @@ +package greencity.service.ubs; + +import greencity.entity.order.Bag; +import greencity.entity.order.Order; +import greencity.repository.OrderBagRepository; +import java.util.List; +import static greencity.ModelUtils.getOrderBag; + +import greencity.repository.OrderRepository; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import java.util.Arrays; +import java.util.Optional; + +import static greencity.ModelUtils.*; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +@ExtendWith({MockitoExtension.class}) +public class OrderBagServiceTest { + + @InjectMocks + private OrderBagService orderBagService; + @Mock + private OrderBagRepository orderBagRepository; + @Mock + private OrderRepository orderRepository; + + @Test + void testFindBagsByOrderId() { + when(orderBagRepository.findOrderBagsByOrderId(any())).thenReturn(Arrays.asList(getOrderBag(), getOrderBag2())); + List bags = orderBagService.findBagsByOrderId(1L); + assertNotNull(bags); + Bag bag1 = getBag().setFullPrice(getOrderBag().getPrice()); + Bag bag2 = getBag2().setFullPrice(getOrderBag2().getPrice()); + + assertEquals(bag1, bags.get(0)); + assertEquals(bag2, bags.get(1)); + + } + + @Test + void testFindBagsByOrdersList() { + List bags = orderBagService.findAllBagsInOrderBagsList(Arrays.asList(getOrderBag(), getOrderBag2())); + + Bag bag1 = getBag().setFullPrice(getOrderBag().getPrice()); + Bag bag2 = getBag2().setFullPrice(getOrderBag2().getPrice()); + assertNotNull(bags); + assertEquals(bag1, bags.get(0)); + assertEquals(bag2, bags.get(1)); + } + + @Test + void testRemoveBagFromOrder() { + Order order = getOrder(); + order.setOrderBags(Arrays.asList(getOrderBag(), getOrderBag2())); + int size = order.getOrderBags().size(); + orderBagService.removeBagFromOrder(order, getOrderBag()); + assertNotEquals(order.getOrderBags().size(), size); + } +} \ No newline at end of file diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index 5f8e4db9b..c7f1b1f4d 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -21,12 +21,7 @@ import greencity.dto.tariff.GetTariffLimitsDto; import greencity.dto.tariff.GetTariffsInfoDto; import greencity.dto.tariff.SetTariffLimitsDto; -import greencity.entity.order.Bag; -import greencity.entity.order.Courier; -import greencity.entity.order.Order; -import greencity.entity.order.Service; -import greencity.entity.order.TariffLocation; -import greencity.entity.order.TariffsInfo; +import greencity.entity.order.*; import greencity.entity.user.Location; import greencity.entity.user.Region; import greencity.entity.user.employee.Employee; @@ -68,13 +63,7 @@ import org.modelmapper.ModelMapper; import java.time.LocalDate; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; -import java.util.Arrays; +import java.util.*; import java.util.stream.Stream; import static greencity.ModelUtils.*; @@ -86,23 +75,12 @@ import static org.junit.jupiter.params.provider.Arguments.arguments; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.Mockito.anyList; -import static org.mockito.Mockito.anySet; -import static org.mockito.Mockito.anyString; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.lenient; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) class SuperAdminServiceImplTest { @InjectMocks private SuperAdminServiceImpl superAdminService; - @Mock private UserRepository userRepository; @Mock @@ -249,16 +227,17 @@ void getTariffServiceIfTariffNotFoundException() { @Test void deleteTariffServiceWhenTariffBagsWithLimits() { + Map amount = new HashMap<>(); + amount.put(1, 1); + amount.put(2, 2); Bag bag = ModelUtils.getBag(); - Bag bagDeleted = ModelUtils.getBagDeleted(); TariffsInfo tariffsInfo = ModelUtils.getTariffInfo(); Order order = ModelUtils.getOrder(); order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); - tariffsInfo.setTariffStatus(TariffStatus.DEACTIVATED); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(List.of(bag)); when(orderRepository.findAllByBagId(bag.getId())).thenReturn(Arrays.asList(order)); + when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))).thenReturn(amount); superAdminService.deleteTariffService(1); @@ -267,30 +246,6 @@ void deleteTariffServiceWhenTariffBagsWithLimits() { verify(tariffsInfoRepository, never()).save(tariffsInfo); } -// @Test -// void deleteTariffServiceWhenTariffBagsWithLimits_UnPaidOrder() { -// Bag bag = ModelUtils.getBag(); -// Bag bagDeleted = ModelUtils.getBagDeleted(); -// TariffsInfo tariffsInfo = ModelUtils.getTariffInfo(); -// Order order = ModelUtils.getOrder(); -// order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag(), ModelUtils.getOrderBag2())); -// order.setTariffsInfo(tariffsInfo); -// tariffsInfo.setBags(Arrays.asList(bag)); -// bag.setTariffsInfo(tariffsInfo); -// tariffsInfo.setTariffStatus(TariffStatus.DEACTIVATED); -// when(orderRepository.findById(order.getId())).thenReturn(Optional.of(order)); -// when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); -// when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(List.of(bag)); -// when(orderRepository.findAllByBagId(bag.getId())).thenReturn(Arrays.asList(order)); -// when(bagRepository.save(bag)).thenReturn(bagDeleted); -//doNothing().when(orderBagService.removeBagFromOrder()); -// superAdminService.deleteTariffService(1); -// -// verify(bagRepository).findById(1); -// verify(bagRepository).findBagsByTariffsInfoId(1L); -// verify(tariffsInfoRepository, never()).save(tariffsInfo); -// } - @Test void deleteTariffServiceWhenTariffBagsListIsEmpty() { Bag bag = ModelUtils.getBag(); @@ -355,7 +310,9 @@ void editTariffServiceWithUnpaidOrder() { Order order = ModelUtils.getOrder(); String uuid = UUID.randomUUID().toString(); order.setOrderBags(List.of(ModelUtils.getOrderBag())); - + Map amount = new HashMap<>(); + amount.put(1, 1); + amount.put(2, 2); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); when(bagRepository.save(editedBag)).thenReturn(editedBag); @@ -364,6 +321,7 @@ void editTariffServiceWithUnpaidOrder() { .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); when(orderRepository.findAllUnpaidOrdersByBagId(1)).thenReturn(List.of(order)); when(orderRepository.saveAll(List.of(order))).thenReturn(List.of(order)); + when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))).thenReturn(amount); GetTariffServiceDto actual = superAdminService.editTariffService(dto, 1, uuid); @@ -388,7 +346,9 @@ void editTariffServiceWithUnpaidOrderAndBagConfirmedAmount() { Order order = ModelUtils.getOrder(); String uuid = UUID.randomUUID().toString(); order.setOrderBags(List.of(ModelUtils.getOrderBagWithConfirmedAmount())); - + Map amount = new HashMap<>(); + amount.put(1, 7); + amount.put(2, 5); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); when(bagRepository.save(editedBag)).thenReturn(editedBag); @@ -397,6 +357,9 @@ void editTariffServiceWithUnpaidOrderAndBagConfirmedAmount() { .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); when(orderRepository.findAllUnpaidOrdersByBagId(1)).thenReturn(List.of(order)); when(orderRepository.saveAll(List.of(order))).thenReturn(List.of(order)); + when(orderBagService + .getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag().setConfirmedQuantity(2)))) + .thenReturn(amount); GetTariffServiceDto actual = superAdminService.editTariffService(dto, 1, uuid); @@ -421,7 +384,9 @@ void editTariffServiceWithUnpaidOrderAndBagExportedAmount() { Order order = ModelUtils.getOrder(); String uuid = UUID.randomUUID().toString(); order.setOrderBags(List.of(ModelUtils.getOrderBagWithExportedAmount())); - + Map amount = new HashMap<>(); + amount.put(1, 1); + amount.put(2, 2); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); when(bagRepository.save(editedBag)).thenReturn(editedBag); @@ -430,6 +395,9 @@ void editTariffServiceWithUnpaidOrderAndBagExportedAmount() { .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); when(orderRepository.findAllUnpaidOrdersByBagId(1)).thenReturn(List.of(order)); when(orderRepository.saveAll(List.of(order))).thenReturn(List.of(order)); + OrderBag orderBag = ModelUtils.getOrderBag().setConfirmedQuantity(2); + orderBag.setExportedQuantity(2); + when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(orderBag))).thenReturn(ModelUtils.getAmount()); GetTariffServiceDto actual = superAdminService.editTariffService(dto, 1, uuid); diff --git a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java index 0a106eec7..b5a6506fe 100644 --- a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java @@ -2515,6 +2515,9 @@ void processOrderFondyClient() throws Exception { when(userRepository.findUserByUuid("uuid")).thenReturn(Optional.of(user)); when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(certificateDto); when(modelMapper.map(any(OrderBag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); + when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))) + .thenReturn(ModelUtils.getAmount()); + ubsService.processOrderFondyClient(dto, "uuid"); } @@ -2560,6 +2563,9 @@ void processOrderFondyClient2() throws Exception { when(modelMapper.map(any(OrderBag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); when(certificateRepository.findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), CertificateStatus.ACTIVE)).thenReturn(Set.of(certificate)); + when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))) + .thenReturn(ModelUtils.getAmount()); + ubsService.processOrderFondyClient(dto, "uuid"); verify(userRepository).findUserByUuid("uuid"); @@ -2598,7 +2604,8 @@ void processOrderFondyClientCertificeteNotFoundExeption() throws Exception { CertificateDto certificateDto = createCertificateDto(); certificateDto.setPoints(1500); order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); - + when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))) + .thenReturn(ModelUtils.getAmount()); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(userRepository.findUserByUuid("uuid")).thenReturn(Optional.of(user)); when(certificateRepository.findAllByCodeAndCertificateStatus(new ArrayList<>(dto.getCertificates()), @@ -2652,6 +2659,8 @@ void processOrderFondyClientCertificeteNotFoundExeption2() throws Exception { CertificateStatus.ACTIVE)).thenReturn(Set.of(certificate)); when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(certificateDto); when(modelMapper.map(any(OrderBag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); + when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))) + .thenReturn(ModelUtils.getAmount()); assertThrows(NotFoundException.class, () -> ubsService.processOrderFondyClient(dto, "uuid")); @@ -2697,6 +2706,8 @@ void processOrderFondyClientIfSumToPayLessThanPoints() throws Exception { when(fondyClient.getCheckoutResponse(any())).thenReturn(getSuccessfulFondyResponse()); when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(certificateDto); when(modelMapper.map(any(OrderBag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); + when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))) + .thenReturn(ModelUtils.getAmount()); ubsService.processOrderFondyClient(dto, "uuid"); @@ -3081,7 +3092,8 @@ void getOrderForUserTest() { when(modelMapper.map(any(OrderBag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); when(ordersForUserRepository.getAllByUserUuidAndId(user.getUuid(), order.getId())) .thenReturn(order); -// when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(bags); + when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))) + .thenReturn(ModelUtils.getAmount()); when(orderStatusTranslationRepository .getOrderStatusTranslationById((long) order.getOrderStatus().getNumValue())) .thenReturn(Optional.of(orderStatusTranslation)); @@ -3145,6 +3157,8 @@ void getOrdersForUserTest() { when(orderPaymentStatusTranslationRepository.getById( (long) order.getOrderPaymentStatus().getStatusValue())) .thenReturn(orderPaymentStatusTranslation); + when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))) + .thenReturn(ModelUtils.getAmount()); PageableDto dto = ubsService.getOrdersForUser(user.getUuid(), pageable, null); @@ -3191,9 +3205,9 @@ void testOrdersForUserWithExportedQuantity() { when(orderPaymentStatusTranslationRepository.getById( (long) order.getOrderPaymentStatus().getStatusValue())) .thenReturn(orderPaymentStatusTranslation); - + when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))) + .thenReturn(ModelUtils.getAmount()); when(modelMapper.map(any(OrderBag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); - PageableDto dto = ubsService.getOrdersForUser(user.getUuid(), pageable, null); assertEquals(dto.getTotalElements(), orderList.size()); @@ -3241,7 +3255,8 @@ void testOrdersForUserWithConfirmedQuantity() { when(orderPaymentStatusTranslationRepository.getById( (long) order.getOrderPaymentStatus().getStatusValue())) .thenReturn(orderPaymentStatusTranslation); - + when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))) + .thenReturn(ModelUtils.getAmount()); PageableDto dto = ubsService.getOrdersForUser(user.getUuid(), pageable, null); assertEquals(dto.getTotalElements(), orderList.size()); @@ -3284,7 +3299,8 @@ void senderInfoDtoBuilderTest() { (long) order.getOrderPaymentStatus().getStatusValue())) .thenReturn(orderPaymentStatusTranslation); when(modelMapper.map(any(OrderBag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); - + when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))) + .thenReturn(ModelUtils.getAmount()); PageableDto dto = ubsService.getOrdersForUser(user.getUuid(), pageable, null); assertEquals(dto.getTotalElements(), orderList.size()); assertEquals(dto.getPage().get(0).getId(), order.getId()); @@ -3596,6 +3612,9 @@ void testOrdersForUserWithQuantity() { (long) order.getOrderPaymentStatus().getStatusValue())) .thenReturn(orderPaymentStatusTranslation); when(modelMapper.map(any(OrderBag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); + when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))) + .thenReturn(ModelUtils.getAmount()); + PageableDto dto = ubsService.getOrdersForUser(user.getUuid(), pageable, null); assertEquals(dto.getTotalElements(), orderList.size()); From e60e59f7bd3668dbf1ba54d11113f608ab3ebd8d Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 24 Jul 2023 13:19:57 +0300 Subject: [PATCH 24/73] Removed import * --- .../service/ubs/UBSManagementServiceImpl.java | 18 ++++++++- .../ubs/SuperAdminServiceImplTest.java | 40 +++++++++++++++++-- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java index 853e34342..a57272131 100644 --- a/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java @@ -73,7 +73,23 @@ import greencity.enums.SortingOrder; import greencity.exceptions.BadRequestException; import greencity.exceptions.NotFoundException; -import greencity.repository.*; +import greencity.repository.OrderBagRepository; +import greencity.repository.BagRepository; +import greencity.repository.CertificateRepository; +import greencity.repository.EmployeeOrderPositionRepository; +import greencity.repository.EmployeeRepository; +import greencity.repository.OrderAddressRepository; +import greencity.repository.OrderDetailRepository; +import greencity.repository.OrderPaymentStatusTranslationRepository; +import greencity.repository.OrderRepository; +import greencity.repository.OrderStatusTranslationRepository; +import greencity.repository.PaymentRepository; +import greencity.repository.PositionRepository; +import greencity.repository.ReceivingStationRepository; +import greencity.repository.RefundRepository; +import greencity.repository.ServiceRepository; +import greencity.repository.TariffsInfoRepository; +import greencity.repository.UserRepository; import greencity.service.locations.LocationApiService; import greencity.service.notification.NotificationServiceImpl; import lombok.AllArgsConstructor; diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index c7f1b1f4d..9b233ff85 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -21,7 +21,13 @@ import greencity.dto.tariff.GetTariffLimitsDto; import greencity.dto.tariff.GetTariffsInfoDto; import greencity.dto.tariff.SetTariffLimitsDto; -import greencity.entity.order.*; +import greencity.entity.order.Bag; +import greencity.entity.order.Courier; +import greencity.entity.order.OrderBag; +import greencity.entity.order.Order; +import greencity.entity.order.Service; +import greencity.entity.order.TariffLocation; +import greencity.entity.order.TariffsInfo; import greencity.entity.user.Location; import greencity.entity.user.Region; import greencity.entity.user.employee.Employee; @@ -63,10 +69,26 @@ import org.modelmapper.ModelMapper; import java.time.LocalDate; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; +import java.util.Arrays; +import java.util.Map; +import java.util.HashMap; import java.util.stream.Stream; -import static greencity.ModelUtils.*; +import static greencity.ModelUtils.TEST_USER; +import static greencity.ModelUtils.getAllTariffsInfoDto; +import static greencity.ModelUtils.getCourier; +import static greencity.ModelUtils.getCourierDto; +import static greencity.ModelUtils.getCourierDtoList; +import static greencity.ModelUtils.getDeactivatedCourier; +import static greencity.ModelUtils.getEmployee; +import static greencity.ModelUtils.getReceivingStation; +import static greencity.ModelUtils.getReceivingStationDto; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; @@ -75,7 +97,17 @@ import static org.junit.jupiter.params.provider.Arguments.arguments; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.anyList; +import static org.mockito.Mockito.anySet; +import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class SuperAdminServiceImplTest { From 0809420a390efd8a63a3d2c054fd19f4fad3de9b Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 24 Jul 2023 13:35:04 +0300 Subject: [PATCH 25/73] added new tests --- .../service/ubs/OrderBagServiceTest.java | 91 ++++++++++++++++++- 1 file changed, 88 insertions(+), 3 deletions(-) diff --git a/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java b/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java index 497327924..1e06b7bc1 100644 --- a/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java +++ b/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java @@ -2,8 +2,11 @@ import greencity.entity.order.Bag; import greencity.entity.order.Order; +import greencity.entity.order.OrderBag; import greencity.repository.OrderBagRepository; -import java.util.List; + +import java.util.*; + import static greencity.ModelUtils.getOrderBag; import greencity.repository.OrderRepository; @@ -12,8 +15,6 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import java.util.Arrays; -import java.util.Optional; import static greencity.ModelUtils.*; import static org.junit.jupiter.api.Assertions.*; @@ -62,4 +63,88 @@ void testRemoveBagFromOrder() { orderBagService.removeBagFromOrder(order, getOrderBag()); assertNotEquals(order.getOrderBags().size(), size); } + + @Test + void testGetActualBagsAmountForOrder_WithExportedQuantity() { + List bagsForOrder = new ArrayList<>(); + OrderBag bag1 = createOrderBagWithExportedQuantity(1, 10); + OrderBag bag2 = createOrderBagWithExportedQuantity(2, 20); + bagsForOrder.add(bag1); + bagsForOrder.add(bag2); + + Map result = orderBagService.getActualBagsAmountForOrder(bagsForOrder); + + Map expected = new HashMap<>(); + expected.put(1, 10); + expected.put(2, 20); + assertEquals(expected, result); + } + + @Test + void testGetActualBagsAmountForOrder_WithConfirmedQuantity() { + List bagsForOrder = new ArrayList<>(); + OrderBag bag1 = createOrderBagWithConfirmedQuantity(1, 5); + OrderBag bag2 = createOrderBagWithConfirmedQuantity(2, 15); + bagsForOrder.add(bag1); + bagsForOrder.add(bag2); + + Map result = orderBagService.getActualBagsAmountForOrder(bagsForOrder); + + Map expected = new HashMap<>(); + expected.put(1, 5); + expected.put(2, 15); + assertEquals(expected, result); + } + + @Test + void testGetActualBagsAmountForOrder_WithAmount() { + List bagsForOrder = new ArrayList<>(); + OrderBag bag1 = createOrderBagWithAmount(1, 3); + OrderBag bag2 = createOrderBagWithAmount(2, 7); + bagsForOrder.add(bag1); + bagsForOrder.add(bag2); + + Map result = orderBagService.getActualBagsAmountForOrder(bagsForOrder); + + Map expected = new HashMap<>(); + expected.put(1, 3); + expected.put(2, 7); + assertEquals(expected, result); + } + + @Test + void testGetActualBagsAmountForOrder_WithNoMatch() { + List bagsForOrder = new ArrayList<>(); + Map result = orderBagService.getActualBagsAmountForOrder(bagsForOrder); + + Map expected = new HashMap<>(); + assertEquals(expected, result); + } + + private OrderBag createOrderBagWithExportedQuantity(int bagId, int exportedQuantity) { + OrderBag orderBag = new OrderBag(); + Bag bag = new Bag(); + bag.setId(bagId); + orderBag.setBag(bag); + orderBag.setExportedQuantity(exportedQuantity); + return orderBag; + } + + private OrderBag createOrderBagWithConfirmedQuantity(int bagId, int confirmedQuantity) { + OrderBag orderBag = new OrderBag(); + Bag bag = new Bag(); + bag.setId(bagId); + orderBag.setBag(bag); + orderBag.setConfirmedQuantity(confirmedQuantity); + return orderBag; + } + + private OrderBag createOrderBagWithAmount(int bagId, int amount) { + OrderBag orderBag = new OrderBag(); + Bag bag = new Bag(); + bag.setId(bagId); + orderBag.setBag(bag); + orderBag.setAmount(amount); + return orderBag; + } } \ No newline at end of file From 6f073dda42d298cf6a05595395b7b7c6e0f5a355 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 24 Jul 2023 14:29:59 +0300 Subject: [PATCH 26/73] added new tests and fixed all --- .../service/ubs/OrderBagService.java | 3 -- .../service/ubs/SuperAdminServiceImpl.java | 1 - .../service/ubs/UBSClientServiceImpl.java | 1 - .../service/ubs/OrderBagServiceTest.java | 2 - .../ubs/SuperAdminServiceImplTest.java | 53 +++++++++---------- 5 files changed, 25 insertions(+), 35 deletions(-) diff --git a/service/src/main/java/greencity/service/ubs/OrderBagService.java b/service/src/main/java/greencity/service/ubs/OrderBagService.java index 838a84c87..118bde46c 100644 --- a/service/src/main/java/greencity/service/ubs/OrderBagService.java +++ b/service/src/main/java/greencity/service/ubs/OrderBagService.java @@ -1,15 +1,12 @@ package greencity.service.ubs; -import greencity.constant.ErrorMessage; import greencity.entity.order.Bag; import greencity.entity.order.Order; import greencity.entity.order.OrderBag; import greencity.exceptions.NotFoundException; import greencity.repository.OrderBagRepository; -import greencity.repository.OrderRepository; import lombok.AllArgsConstructor; import lombok.Data; -import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; diff --git a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java index 3eb9b4909..06c2ba9df 100644 --- a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java @@ -66,7 +66,6 @@ import lombok.Data; import org.apache.commons.collections4.CollectionUtils; import org.modelmapper.ModelMapper; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; diff --git a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java index 9aa559908..1a82a2f1c 100644 --- a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java @@ -137,7 +137,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.EnumSet; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Locale; diff --git a/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java b/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java index 1e06b7bc1..34b3bb991 100644 --- a/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java +++ b/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java @@ -28,8 +28,6 @@ public class OrderBagServiceTest { private OrderBagService orderBagService; @Mock private OrderBagRepository orderBagRepository; - @Mock - private OrderRepository orderRepository; @Test void testFindBagsByOrderId() { diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index 9b233ff85..998c8eae1 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -23,7 +23,6 @@ import greencity.dto.tariff.SetTariffLimitsDto; import greencity.entity.order.Bag; import greencity.entity.order.Courier; -import greencity.entity.order.OrderBag; import greencity.entity.order.Order; import greencity.entity.order.Service; import greencity.entity.order.TariffLocation; @@ -72,12 +71,12 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; import java.util.Arrays; +import java.util.Optional; import java.util.Map; import java.util.HashMap; +import java.util.Set; +import java.util.UUID; import java.util.stream.Stream; import static greencity.ModelUtils.TEST_USER; @@ -113,6 +112,7 @@ class SuperAdminServiceImplTest { @InjectMocks private SuperAdminServiceImpl superAdminService; + @Mock private UserRepository userRepository; @Mock @@ -259,17 +259,12 @@ void getTariffServiceIfTariffNotFoundException() { @Test void deleteTariffServiceWhenTariffBagsWithLimits() { - Map amount = new HashMap<>(); - amount.put(1, 1); - amount.put(2, 2); Bag bag = ModelUtils.getBag(); + Bag bagDeleted = ModelUtils.getBagDeleted(); TariffsInfo tariffsInfo = ModelUtils.getTariffInfo(); - Order order = ModelUtils.getOrder(); - order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); + when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(List.of(bag)); - when(orderRepository.findAllByBagId(bag.getId())).thenReturn(Arrays.asList(order)); - when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))).thenReturn(amount); superAdminService.deleteTariffService(1); @@ -285,10 +280,16 @@ void deleteTariffServiceWhenTariffBagsListIsEmpty() { tariffsInfo.setBags(Arrays.asList(bag)); bag.setTariffsInfo(tariffsInfo); tariffsInfo.setTariffStatus(TariffStatus.DEACTIVATED); + Map amount = new HashMap<>(); + amount.put(1, 1); + amount.put(2, 2); + Order order = ModelUtils.getOrder(); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(Collections.emptyList()); when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfo); - + when(orderRepository.findAllByBagId(bag.getId())).thenReturn(Arrays.asList(order)); + when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))).thenReturn(amount); superAdminService.deleteTariffService(1); verify(bagRepository).findById(1); @@ -311,14 +312,12 @@ void deleteTariffServiceWhenTariffBagsWithoutLimits() { tariffsInfoNew.setTariffStatus(TariffStatus.DEACTIVATED); when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); -// when(bagRepository.save(bag)).thenReturn(bagDeleted); when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(List.of(bag)); when(tariffsInfoRepository.save(tariffsInfoNew)).thenReturn(tariffsInfoNew); superAdminService.deleteTariffService(1); verify(bagRepository).findById(1); -// verify(bagRepository).save(bag); verify(bagRepository).findBagsByTariffsInfoId(1L); verify(tariffsInfoRepository).save(tariffsInfoNew); } @@ -342,18 +341,18 @@ void editTariffServiceWithUnpaidOrder() { Order order = ModelUtils.getOrder(); String uuid = UUID.randomUUID().toString(); order.setOrderBags(List.of(ModelUtils.getOrderBag())); - Map amount = new HashMap<>(); - amount.put(1, 1); - amount.put(2, 2); + when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.save(editedBag)).thenReturn(editedBag); when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); doNothing().when(orderBagRepository) .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); when(orderRepository.findAllUnpaidOrdersByBagId(1)).thenReturn(List.of(order)); when(orderRepository.saveAll(List.of(order))).thenReturn(List.of(order)); - when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))).thenReturn(amount); + when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))) + .thenReturn(ModelUtils.getAmount()); GetTariffServiceDto actual = superAdminService.editTariffService(dto, 1, uuid); @@ -378,9 +377,7 @@ void editTariffServiceWithUnpaidOrderAndBagConfirmedAmount() { Order order = ModelUtils.getOrder(); String uuid = UUID.randomUUID().toString(); order.setOrderBags(List.of(ModelUtils.getOrderBagWithConfirmedAmount())); - Map amount = new HashMap<>(); - amount.put(1, 7); - amount.put(2, 5); + when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); when(bagRepository.save(editedBag)).thenReturn(editedBag); @@ -391,7 +388,7 @@ void editTariffServiceWithUnpaidOrderAndBagConfirmedAmount() { when(orderRepository.saveAll(List.of(order))).thenReturn(List.of(order)); when(orderBagService .getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag().setConfirmedQuantity(2)))) - .thenReturn(amount); + .thenReturn(ModelUtils.getAmount()); GetTariffServiceDto actual = superAdminService.editTariffService(dto, 1, uuid); @@ -416,9 +413,7 @@ void editTariffServiceWithUnpaidOrderAndBagExportedAmount() { Order order = ModelUtils.getOrder(); String uuid = UUID.randomUUID().toString(); order.setOrderBags(List.of(ModelUtils.getOrderBagWithExportedAmount())); - Map amount = new HashMap<>(); - amount.put(1, 1); - amount.put(2, 2); + when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); when(bagRepository.save(editedBag)).thenReturn(editedBag); @@ -427,15 +422,17 @@ void editTariffServiceWithUnpaidOrderAndBagExportedAmount() { .updateAllByBagIdForUnpaidOrders(1, 20, 150_00L, "Бавовняна сумка", null); when(orderRepository.findAllUnpaidOrdersByBagId(1)).thenReturn(List.of(order)); when(orderRepository.saveAll(List.of(order))).thenReturn(List.of(order)); - OrderBag orderBag = ModelUtils.getOrderBag().setConfirmedQuantity(2); - orderBag.setExportedQuantity(2); - when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(orderBag))).thenReturn(ModelUtils.getAmount()); + when(orderBagService.getActualBagsAmountForOrder( + Arrays.asList(ModelUtils.getOrderBag().setExportedQuantity(2).setConfirmedQuantity(2)))) + .thenReturn(ModelUtils.getAmount()); GetTariffServiceDto actual = superAdminService.editTariffService(dto, 1, uuid); assertEquals(editedDto, actual); verify(employeeRepository).findByUuid(uuid); verify(bagRepository).findById(1); + verify(bagRepository).findById(1); + verify(bagRepository).save(editedBag); verify(modelMapper).map(editedBag, GetTariffServiceDto.class); verify(orderBagRepository) From 598de34f7caa36e9b89b94d0bc623081704749f4 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 24 Jul 2023 14:45:51 +0300 Subject: [PATCH 27/73] added new tests and fixed code smells --- .../service/ubs/SuperAdminServiceImpl.java | 14 -------------- .../greencity/service/ubs/OrderBagServiceTest.java | 14 +++++++++++++- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java index 06c2ba9df..b15a2711c 100644 --- a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java @@ -174,20 +174,6 @@ private void deleteBagFromOrder(Order order, Integer bagId) { } } - private void checkDeletedBagLimitAndUpdateTariffsInfo(Bag bag) { - TariffsInfo tariffsInfo = bag.getTariffsInfo(); - List bags = bagRepository.findBagsByTariffsInfoId(tariffsInfo.getId()); - if (bags.isEmpty() || bags.stream().noneMatch(Bag::getLimitIncluded)) { - tariffsInfo.setTariffStatus(TariffStatus.NEW); - tariffsInfo.setBags(bags); - tariffsInfo.setMax(null); - tariffsInfo.setMin(null); - tariffsInfo.setLimitDescription(null); - tariffsInfo.setCourierLimit(CourierLimit.LIMIT_BY_SUM_OF_ORDER); - tariffsInfoRepository.save(tariffsInfo); - } - } - private void checkDeletedBagLimitAndDeleteTariffsInfo(Bag bag) { TariffsInfo tariffsInfo = bag.getTariffsInfo(); List bags = bagRepository.findBagsByTariffsInfoId(tariffsInfo.getId()); diff --git a/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java b/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java index 34b3bb991..0f80a080c 100644 --- a/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java +++ b/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java @@ -22,7 +22,7 @@ import static org.mockito.Mockito.when; @ExtendWith({MockitoExtension.class}) -public class OrderBagServiceTest { +class OrderBagServiceTest { @InjectMocks private OrderBagService orderBagService; @@ -113,6 +113,18 @@ void testGetActualBagsAmountForOrder_WithAmount() { @Test void testGetActualBagsAmountForOrder_WithNoMatch() { List bagsForOrder = new ArrayList<>(); + OrderBag bag1 = createOrderBagWithAmount(1, 3); + bag1.setExportedQuantity(null); + bag1.setConfirmedQuantity(null); + bag1.setAmount(null); + + OrderBag bag2 = createOrderBagWithAmount(2, 7); + bag2.setExportedQuantity(null); + bag2.setConfirmedQuantity(null); + bag2.setAmount(null); + bagsForOrder.add(bag1); + bagsForOrder.add(bag2); + Map result = orderBagService.getActualBagsAmountForOrder(bagsForOrder); Map expected = new HashMap<>(); From d2e443698d2d4e5a93b770bb1cd3ebb5afbc1212 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 24 Jul 2023 15:17:05 +0300 Subject: [PATCH 28/73] added new tests to cover --- .../ubs/SuperAdminServiceImplTest.java | 8 +- .../service/ubs/UBSClientServiceImplTest.java | 111 +----------------- 2 files changed, 3 insertions(+), 116 deletions(-) diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index 998c8eae1..7fb852089 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -31,10 +31,7 @@ import greencity.entity.user.Region; import greencity.entity.user.employee.Employee; import greencity.entity.user.employee.ReceivingStation; -import greencity.enums.CourierStatus; -import greencity.enums.LocationStatus; -import greencity.enums.StationStatus; -import greencity.enums.TariffStatus; +import greencity.enums.*; import greencity.exceptions.BadRequestException; import greencity.exceptions.NotFoundException; import greencity.exceptions.UnprocessableEntityException; @@ -281,8 +278,7 @@ void deleteTariffServiceWhenTariffBagsListIsEmpty() { bag.setTariffsInfo(tariffsInfo); tariffsInfo.setTariffStatus(TariffStatus.DEACTIVATED); Map amount = new HashMap<>(); - amount.put(1, 1); - amount.put(2, 2); + amount.put(1, 0); Order order = ModelUtils.getOrder(); order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); diff --git a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java index b5a6506fe..da6826fee 100644 --- a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java @@ -98,79 +98,7 @@ import java.util.UUID; import java.util.stream.Collectors; -import static greencity.ModelUtils.TEST_BAG_FOR_USER_DTO; -import static greencity.ModelUtils.TEST_EMAIL; -import static greencity.ModelUtils.TEST_ORDER_ADDRESS_DTO_REQUEST; -import static greencity.ModelUtils.TEST_PAYMENT_LIST; -import static greencity.ModelUtils.addressDto; -import static greencity.ModelUtils.addressDtoList; -import static greencity.ModelUtils.addressList; -import static greencity.ModelUtils.bagDto; -import static greencity.ModelUtils.botList; -import static greencity.ModelUtils.createCertificateDto; -import static greencity.ModelUtils.getAddress; -import static greencity.ModelUtils.getAddressDtoResponse; -import static greencity.ModelUtils.getAddressRequestDto; -import static greencity.ModelUtils.getBag; -import static greencity.ModelUtils.getBag1list; -import static greencity.ModelUtils.getBag4list; -import static greencity.ModelUtils.getBagForOrder; -import static greencity.ModelUtils.getBagTranslationDto; -import static greencity.ModelUtils.getCancellationDto; -import static greencity.ModelUtils.getCertificate; -import static greencity.ModelUtils.getCourier; -import static greencity.ModelUtils.getCourierDto; -import static greencity.ModelUtils.getCourierDtoList; -import static greencity.ModelUtils.getEmployee; -import static greencity.ModelUtils.getGeocodingResult; -import static greencity.ModelUtils.getListOfEvents; -import static greencity.ModelUtils.getLocation; -import static greencity.ModelUtils.getMaximumAmountOfAddresses; -import static greencity.ModelUtils.getOrder; -import static greencity.ModelUtils.getOrderClientDto; -import static greencity.ModelUtils.getOrderCount; -import static greencity.ModelUtils.getOrderCountWithPaymentStatusPaid; -import static greencity.ModelUtils.getOrderDetails; -import static greencity.ModelUtils.getOrderDetailsWithoutSender; -import static greencity.ModelUtils.getOrderDoneByUser; -import static greencity.ModelUtils.getOrderFondyClientDto; -import static greencity.ModelUtils.getOrderPaymentDetailDto; -import static greencity.ModelUtils.getOrderPaymentStatusTranslation; -import static greencity.ModelUtils.getOrderResponseDto; -import static greencity.ModelUtils.getOrderStatusDto; -import static greencity.ModelUtils.getOrderStatusTranslation; -import static greencity.ModelUtils.getOrderTest; -import static greencity.ModelUtils.getOrderWithEvents; -import static greencity.ModelUtils.getOrderWithTariffAndLocation; -import static greencity.ModelUtils.getOrderWithoutPayment; -import static greencity.ModelUtils.getOrdersDto; -import static greencity.ModelUtils.getPayment; -import static greencity.ModelUtils.getPaymentResponseDto; -import static greencity.ModelUtils.getSuccessfulFondyResponse; -import static greencity.ModelUtils.getTariffInfo; -import static greencity.ModelUtils.getTariffInfoWithLimitOfBags; -import static greencity.ModelUtils.getTariffInfoWithLimitOfBagsAndMaxLessThanCountOfBigBag; -import static greencity.ModelUtils.getTariffLocation; -import static greencity.ModelUtils.getTariffsForLocationDto; -import static greencity.ModelUtils.getTariffsInfo; -import static greencity.ModelUtils.getTelegramBotNotifyTrue; -import static greencity.ModelUtils.getTestOrderAddressDtoRequest; -import static greencity.ModelUtils.getTestOrderAddressLocationDto; -import static greencity.ModelUtils.getTestUser; -import static greencity.ModelUtils.getUBSuser; -import static greencity.ModelUtils.getUBSuserWithoutSender; -import static greencity.ModelUtils.getUbsCustomersDtoUpdate; -import static greencity.ModelUtils.getUbsUsers; -import static greencity.ModelUtils.getUser; -import static greencity.ModelUtils.getUserForCreate; -import static greencity.ModelUtils.getUserInfoDto; -import static greencity.ModelUtils.getUserPointsAndAllBagsDto; -import static greencity.ModelUtils.getUserProfileCreateDto; -import static greencity.ModelUtils.getUserProfileUpdateDto; -import static greencity.ModelUtils.getUserProfileUpdateDtoWithBotsIsNotifyFalse; -import static greencity.ModelUtils.getUserWithBotNotifyTrue; -import static greencity.ModelUtils.getUserWithLastLocation; -import static greencity.ModelUtils.getViberBotNotifyTrue; +import static greencity.ModelUtils.*; import static greencity.constant.ErrorMessage.ACTUAL_ADDRESS_NOT_FOUND; import static greencity.constant.ErrorMessage.ADDRESS_ALREADY_EXISTS; import static greencity.constant.ErrorMessage.CANNOT_ACCESS_PERSONAL_INFO; @@ -2484,43 +2412,6 @@ void deleteOrderFail() { }); } - @Test - void processOrderFondyClient() throws Exception { - Order order = getOrderCount(); - HashMap value = new HashMap<>(); - value.put(1, 22); - order.setAmountOfBagsOrdered(value); - order.setPointsToUse(100); - order.setSumTotalAmountWithoutDiscounts(1000_00L); - order.setCertificates(Set.of(getCertificate())); - order.setPayment(TEST_PAYMENT_LIST); - order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); - User user = getUser(); - user.setCurrentPoints(100); - user.setChangeOfPointsList(new ArrayList<>()); - order.setUser(user); - - OrderFondyClientDto dto = getOrderFondyClientDto(); - Field[] fields = UBSClientServiceImpl.class.getDeclaredFields(); - for (Field f : fields) { - if (f.getName().equals("merchantId")) { - f.setAccessible(true); - f.set(ubsService, "1"); - } - } - - Certificate certificate = getCertificate(); - CertificateDto certificateDto = createCertificateDto(); - when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); - when(userRepository.findUserByUuid("uuid")).thenReturn(Optional.of(user)); - when(modelMapper.map(certificate, CertificateDto.class)).thenReturn(certificateDto); - when(modelMapper.map(any(OrderBag.class), eq(BagForUserDto.class))).thenReturn(TEST_BAG_FOR_USER_DTO); - when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))) - .thenReturn(ModelUtils.getAmount()); - - ubsService.processOrderFondyClient(dto, "uuid"); - } - @Test void processOrderFondyClient2() throws Exception { Order order = getOrderCount(); From 5ff7a9706014a7582e33065846198b9a3c12f446 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 24 Jul 2023 15:24:01 +0300 Subject: [PATCH 29/73] added new tests to cover --- .../ubs/SuperAdminServiceImplTest.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index 7fb852089..96d8875da 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -270,6 +270,56 @@ void deleteTariffServiceWhenTariffBagsWithLimits() { verify(tariffsInfoRepository, never()).save(tariffsInfo); } + @Test + void deleteTariffService2() { + Bag bag = ModelUtils.getBag(); + TariffsInfo tariffsInfo = ModelUtils.getTariffsInfoWithStatusNew(); + tariffsInfo.setBags(Arrays.asList(bag)); + bag.setTariffsInfo(tariffsInfo); + tariffsInfo.setTariffStatus(TariffStatus.DEACTIVATED); + Map amount = new HashMap<>(); + amount.put(1, 3); + amount.put(2, 7); + + Order order = ModelUtils.getOrder(); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); + when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(Collections.emptyList()); + when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfo); + when(orderRepository.findAllByBagId(bag.getId())).thenReturn(Arrays.asList(order)); + when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))).thenReturn(amount); + superAdminService.deleteTariffService(1); + + verify(bagRepository).findById(1); + verify(bagRepository).findBagsByTariffsInfoId(1L); + verify(tariffsInfoRepository).save(tariffsInfo); + } + + @Test + void deleteTariffService3() { + Bag bag = ModelUtils.getBag(); + TariffsInfo tariffsInfo = ModelUtils.getTariffsInfoWithStatusNew(); + tariffsInfo.setBags(Arrays.asList(bag)); + bag.setTariffsInfo(tariffsInfo); + tariffsInfo.setTariffStatus(TariffStatus.DEACTIVATED); + Map amount = new HashMap<>(); + amount.put(1, 3); + amount.put(2, 7); + Order order = ModelUtils.getOrder(); + order.setOrderPaymentStatus(OrderPaymentStatus.UNPAID); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); + when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(Collections.emptyList()); + when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfo); + when(orderRepository.findAllByBagId(bag.getId())).thenReturn(Arrays.asList(order)); + when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))).thenReturn(amount); + superAdminService.deleteTariffService(1); + + verify(bagRepository).findById(1); + verify(bagRepository).findBagsByTariffsInfoId(1L); + verify(tariffsInfoRepository).save(tariffsInfo); + } + @Test void deleteTariffServiceWhenTariffBagsListIsEmpty() { Bag bag = ModelUtils.getBag(); From 32a0316b49c9fcb064288b9c7624cbcf56abf06d Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 24 Jul 2023 15:30:00 +0300 Subject: [PATCH 30/73] added new tests to cover --- .../ubs/SuperAdminServiceImplTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index 96d8875da..f3a3c2716 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -320,6 +320,30 @@ void deleteTariffService3() { verify(tariffsInfoRepository).save(tariffsInfo); } + @Test + void deleteTariffService4() { + Bag bag = ModelUtils.getBag(); + TariffsInfo tariffsInfo = ModelUtils.getTariffsInfoWithStatusNew(); + tariffsInfo.setBags(Arrays.asList(bag)); + bag.setTariffsInfo(tariffsInfo); + tariffsInfo.setTariffStatus(TariffStatus.DEACTIVATED); + Map amount = new HashMap<>(); + amount.put(1, 0); + Order order = ModelUtils.getOrder(); + order.setOrderPaymentStatus(OrderPaymentStatus.UNPAID); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); + when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(Collections.emptyList()); + when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfo); + when(orderRepository.findAllByBagId(bag.getId())).thenReturn(Arrays.asList(order)); + when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))).thenReturn(amount); + superAdminService.deleteTariffService(1); + + verify(bagRepository).findById(1); + verify(bagRepository).findBagsByTariffsInfoId(1L); + verify(tariffsInfoRepository).save(tariffsInfo); + } + @Test void deleteTariffServiceWhenTariffBagsListIsEmpty() { Bag bag = ModelUtils.getBag(); From 820f75ca73e7b9c9925e0ec7dfeb2c1b836e7669 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Tue, 25 Jul 2023 11:26:15 +0300 Subject: [PATCH 31/73] Fixed bad moment --- .../java/greencity/entity/order/OrderBag.java | 9 ++++--- .../repository/OrderBagRepository.java | 10 +++++++ .../java/greencity/constant/ErrorMessage.java | 1 - .../service/ubs/OrderBagService.java | 18 ++++++------- .../service/ubs/SuperAdminServiceImpl.java | 10 +++---- .../service/ubs/UBSClientServiceImpl.java | 12 ++++----- .../ubs/SuperAdminServiceImplTest.java | 26 +++++++------------ 7 files changed, 44 insertions(+), 42 deletions(-) diff --git a/dao/src/main/java/greencity/entity/order/OrderBag.java b/dao/src/main/java/greencity/entity/order/OrderBag.java index 95230c7e2..38c479e23 100644 --- a/dao/src/main/java/greencity/entity/order/OrderBag.java +++ b/dao/src/main/java/greencity/entity/order/OrderBag.java @@ -17,6 +17,7 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; +import javax.validation.constraints.NotBlank; import javax.validation.constraints.Size; @Entity @@ -44,10 +45,10 @@ public class OrderBag { @Column(nullable = false) private Integer amount; - @Column(name = "confirmed_quantity") + @Column private Integer confirmedQuantity; - @Column(name = "exported_quantity") + @Column private Integer exportedQuantity; @Column(nullable = false) @@ -55,11 +56,11 @@ public class OrderBag { @Column(nullable = false) private Long price; - + @NotBlank @Size(min = 1, max = 30) @Column(nullable = false) private String name; - + @NotBlank @Size(min = 1, max = 30) @Column(nullable = false) private String nameEng; diff --git a/dao/src/main/java/greencity/repository/OrderBagRepository.java b/dao/src/main/java/greencity/repository/OrderBagRepository.java index 5fa604b23..578aba332 100644 --- a/dao/src/main/java/greencity/repository/OrderBagRepository.java +++ b/dao/src/main/java/greencity/repository/OrderBagRepository.java @@ -12,6 +12,16 @@ @Repository public interface OrderBagRepository extends JpaRepository { + /** + * Retrieves a list of order bags based on the given bag ID. + * + * @param id the ID of the order + * @return a list of order bags matching the bag ID + */ + @Query(value = "SELECT * FROM ORDER_BAG_MAPPING as OBM " + + "where OBM.BAG_ID = :bagId", nativeQuery = true) + List findOrderBagsByBagId(@Param("bagId") Integer id); + /** * Retrieves a list of order bags based on the given order ID. * diff --git a/service-api/src/main/java/greencity/constant/ErrorMessage.java b/service-api/src/main/java/greencity/constant/ErrorMessage.java index 06bfd0479..5793d2a82 100644 --- a/service-api/src/main/java/greencity/constant/ErrorMessage.java +++ b/service-api/src/main/java/greencity/constant/ErrorMessage.java @@ -163,7 +163,6 @@ public final class ErrorMessage { public static final String INVALID_URL = "Invalid URL: "; public static final String LOCATION_CAN_NOT_BE_DELETED = "Such location cannot be deleted as it is linked to the tariff"; - public static final String ORDER_NOT_FOUND = "Order not found with id: "; /** * Constructor. diff --git a/service/src/main/java/greencity/service/ubs/OrderBagService.java b/service/src/main/java/greencity/service/ubs/OrderBagService.java index 118bde46c..e6173a7b8 100644 --- a/service/src/main/java/greencity/service/ubs/OrderBagService.java +++ b/service/src/main/java/greencity/service/ubs/OrderBagService.java @@ -26,7 +26,7 @@ public class OrderBagService { private OrderBagRepository orderBagRepository; private Long getActualPrice(List orderBags, Integer id) { - return orderBags.stream() + return orderBagRepository.findOrderBagsByBagId(id).stream() .filter(ob -> ob.getBag().getId().equals(id)) .map(OrderBag::getPrice) .findFirst() @@ -82,17 +82,17 @@ public List findBagsByOrderId(Long id) { * @throws NullPointerException if 'bagsForOrder' is null. */ public Map getActualBagsAmountForOrder(List bagsForOrder) { - if (bagsForOrder.stream().allMatch(it -> it.getExportedQuantity() != null)) { + if (bagsForOrder.stream().allMatch(orderBag -> orderBag.getExportedQuantity() != null)) { return bagsForOrder.stream() - .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getExportedQuantity)); + .collect(Collectors.toMap(orderBag -> orderBag.getBag().getId(), OrderBag::getExportedQuantity)); } - if (bagsForOrder.stream().allMatch(it -> it.getConfirmedQuantity() != null)) { + if (bagsForOrder.stream().allMatch(orderBag -> orderBag.getConfirmedQuantity() != null)) { return bagsForOrder.stream() - .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getConfirmedQuantity)); + .collect(Collectors.toMap(orderBag -> orderBag.getBag().getId(), OrderBag::getConfirmedQuantity)); } - if (bagsForOrder.stream().allMatch(it -> it.getAmount() != null)) { + if (bagsForOrder.stream().allMatch(orderBag -> orderBag.getAmount() != null)) { return bagsForOrder.stream() - .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getAmount)); + .collect(Collectors.toMap(orderBag -> orderBag.getBag().getId(), OrderBag::getAmount)); } return new HashMap<>(); } @@ -104,8 +104,6 @@ public Map getActualBagsAmountForOrder(List bagsForO * @author Oksana Spodaryk */ public void removeBagFromOrder(Order order, OrderBag orderBag) { - List modifiableList = new ArrayList<>(order.getOrderBags()); - modifiableList.remove(orderBag); - order.setOrderBags(modifiableList); + order.getOrderBags().remove(orderBag); } } diff --git a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java index b15a2711c..acf611a25 100644 --- a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java @@ -167,9 +167,9 @@ private void deleteBagFromOrder(Order order, Integer bagId) { orderRepository.delete(order); return; } - order.getOrderBags().stream().filter(it -> it.getBag().getId().equals(bagId)) + order.getOrderBags().stream().filter(orderBag -> orderBag.getBag().getId().equals(bagId)) .findFirst() - .ifPresent(obj -> orderBagService.removeBagFromOrder(order, obj)); + .ifPresent(orderBag -> orderBagService.removeBagFromOrder(order, orderBag)); orderRepository.save(order); } } @@ -200,7 +200,7 @@ public GetTariffServiceDto editTariffService(TariffServiceDto dto, Integer bagId bagId, bag.getCapacity(), bag.getFullPrice(), bag.getName(), bag.getNameEng()); List orders = orderRepository.findAllUnpaidOrdersByBagId(bagId); - if (!orders.isEmpty()) { + if (CollectionUtils.isNotEmpty(orders)) { orders.forEach(it -> updateOrderSumToPay(it, bag)); orderRepository.saveAll(orders); } @@ -210,12 +210,12 @@ public GetTariffServiceDto editTariffService(TariffServiceDto dto, Integer bagId private void updateOrderSumToPay(Order order, Bag bag) { Map amount = orderBagService.getActualBagsAmountForOrder(order.getOrderBags()); Long sumToPayInCoins = order.getOrderBags().stream() - .map(it -> amount.get(it.getBag().getId()) * getActualBagPrice(it, bag)) + .map(orderBag -> amount.get(orderBag.getBag().getId()) * getBagPrice(orderBag, bag)) .reduce(0L, Long::sum); order.setSumTotalAmountWithoutDiscounts(sumToPayInCoins); } - private Long getActualBagPrice(OrderBag orderBag, Bag bag) { + private Long getBagPrice(OrderBag orderBag, Bag bag) { return bag.getId().equals(orderBag.getBag().getId()) ? bag.getFullPrice() : orderBag.getPrice(); diff --git a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java index 1a82a2f1c..5c64e460f 100644 --- a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java @@ -458,7 +458,7 @@ private List getBagIds(List dto) { .collect(Collectors.toList()); } - private Bag tryToGetActiveBagById(Integer id) { + private Bag findBagById(Integer id) { return bagRepository.findById(id) .orElseThrow(() -> new NotFoundException(BAG_NOT_FOUND + id)); } @@ -1029,7 +1029,7 @@ private Order formAndSaveOrder(Order order, Set orderCertificates, User currentUser, long sumToPayInCoins) { order.setOrderStatus(OrderStatus.FORMED); order.setCertificates(orderCertificates); - bagsOrdered.forEach(it -> it.setOrder(order)); + bagsOrdered.forEach(orderBag -> orderBag.setOrder(order)); order.setOrderBags(bagsOrdered); order.setUbsUser(userData); order.setUser(currentUser); @@ -1192,7 +1192,7 @@ private void checkAmountOfBagsIfCourierLimitByAmountOfBag(TariffsInfo courierLoc private long calculateOrderSumWithoutDiscounts(List getOrderBagsAndQuantity) { return getOrderBagsAndQuantity.stream() - .map(it -> it.getPrice() * it.getAmount()) + .map(orderBag -> orderBag.getPrice() * orderBag.getAmount()) .reduce(0L, Long::sum); } @@ -1201,7 +1201,7 @@ private long formBagsToBeSavedAndCalculateOrderSum( long sumToPayInCoins = 0L; for (BagDto temp : bags) { - Bag bag = tryToGetActiveBagById(temp.getId()); + Bag bag = findBagById(temp.getId()); if (bag.getLimitIncluded().booleanValue()) { checkAmountOfBagsIfCourierLimitByAmountOfBag(tariffsInfo, temp.getAmount()); checkSumIfCourierLimitBySumOfOrder(tariffsInfo, bag.getFullPrice() * temp.getAmount()); @@ -1213,9 +1213,9 @@ private long formBagsToBeSavedAndCalculateOrderSum( } List orderedBagsIds = bags.stream().map(BagDto::getId).collect(toList()); List notOrderedBags = tariffsInfo.getBags().stream() - .filter(it -> !orderedBagsIds.contains(it.getId())) + .filter(orderBag -> !orderedBagsIds.contains(orderBag.getId())) .map(this::createOrderBag).collect(toList()); - notOrderedBags.forEach(it -> it.setAmount(0)); + notOrderedBags.forEach(orderBag -> orderBag.setAmount(0)); orderBagList.addAll(notOrderedBags); return sumToPayInCoins; } diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index f3a3c2716..f7cab417d 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -585,26 +585,20 @@ void getAllCouriersTest() { void deleteService() { Service service = ModelUtils.getService(); - when(serviceRepository.findById(service.getId())).thenReturn(Optional.of(service)); - superAdminService.deleteService(1L); - verify(serviceRepository).findById(1L); - verify(serviceRepository).delete(service); + verify(serviceRepository).deleteById(1L); } - @Test - void deleteServiceThrowNotFoundException() { - Service service = ModelUtils.getService(); - - when(serviceRepository.findById(service.getId())).thenReturn(Optional.empty()); - - assertThrows(NotFoundException.class, - () -> superAdminService.deleteService(1L)); - - verify(serviceRepository).findById(1L); - verify(serviceRepository, never()).delete(service); - } +// @Test +// void deleteServiceThrowNotFoundException() { +// Service service = ModelUtils.getService(); +// +// assertThrows(NotFoundException.class, +// () -> superAdminService.deleteService(1L)); +// +// verify(serviceRepository).deleteById(1L); +// } @Test void getService() { From ac46ceb85e49436b5610559963a72b076136d8d7 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Tue, 25 Jul 2023 11:31:23 +0300 Subject: [PATCH 32/73] Fixed bad moments --- .../ubs/SuperAdminServiceImplTest.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index f7cab417d..f3a3c2716 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -585,20 +585,26 @@ void getAllCouriersTest() { void deleteService() { Service service = ModelUtils.getService(); + when(serviceRepository.findById(service.getId())).thenReturn(Optional.of(service)); + superAdminService.deleteService(1L); - verify(serviceRepository).deleteById(1L); + verify(serviceRepository).findById(1L); + verify(serviceRepository).delete(service); } -// @Test -// void deleteServiceThrowNotFoundException() { -// Service service = ModelUtils.getService(); -// -// assertThrows(NotFoundException.class, -// () -> superAdminService.deleteService(1L)); -// -// verify(serviceRepository).deleteById(1L); -// } + @Test + void deleteServiceThrowNotFoundException() { + Service service = ModelUtils.getService(); + + when(serviceRepository.findById(service.getId())).thenReturn(Optional.empty()); + + assertThrows(NotFoundException.class, + () -> superAdminService.deleteService(1L)); + + verify(serviceRepository).findById(1L); + verify(serviceRepository, never()).delete(service); + } @Test void getService() { From 46f15f4be39eeeb16aa34bb706ca4ac0bd70e881 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Tue, 25 Jul 2023 12:22:24 +0300 Subject: [PATCH 33/73] Fixed bad moments --- ...pdate-order-bag-mapping-table-Spodaryk.xml | 36 ++++++++++++++----- .../service/ubs/OrderBagService.java | 18 +++++----- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml b/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml index eba30c3cb..1d53cc7d0 100644 --- a/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml +++ b/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml @@ -3,7 +3,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd"> - + + + + @@ -29,20 +32,35 @@ - update order_bag_mapping set - capacity=bag.capacity, - price=bag.full_price, - name=bag.name, - name_eng=bag.name_eng - from bag + + + + + + + + + + + + + + + + + update order_bag_mapping + set capacity=bag.capacity, + price=bag.full_price, + name=bag.name, + name_eng=bag.name_eng from bag where bag_id=bag.id + - - \ No newline at end of file + diff --git a/service/src/main/java/greencity/service/ubs/OrderBagService.java b/service/src/main/java/greencity/service/ubs/OrderBagService.java index e6173a7b8..118bde46c 100644 --- a/service/src/main/java/greencity/service/ubs/OrderBagService.java +++ b/service/src/main/java/greencity/service/ubs/OrderBagService.java @@ -26,7 +26,7 @@ public class OrderBagService { private OrderBagRepository orderBagRepository; private Long getActualPrice(List orderBags, Integer id) { - return orderBagRepository.findOrderBagsByBagId(id).stream() + return orderBags.stream() .filter(ob -> ob.getBag().getId().equals(id)) .map(OrderBag::getPrice) .findFirst() @@ -82,17 +82,17 @@ public List findBagsByOrderId(Long id) { * @throws NullPointerException if 'bagsForOrder' is null. */ public Map getActualBagsAmountForOrder(List bagsForOrder) { - if (bagsForOrder.stream().allMatch(orderBag -> orderBag.getExportedQuantity() != null)) { + if (bagsForOrder.stream().allMatch(it -> it.getExportedQuantity() != null)) { return bagsForOrder.stream() - .collect(Collectors.toMap(orderBag -> orderBag.getBag().getId(), OrderBag::getExportedQuantity)); + .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getExportedQuantity)); } - if (bagsForOrder.stream().allMatch(orderBag -> orderBag.getConfirmedQuantity() != null)) { + if (bagsForOrder.stream().allMatch(it -> it.getConfirmedQuantity() != null)) { return bagsForOrder.stream() - .collect(Collectors.toMap(orderBag -> orderBag.getBag().getId(), OrderBag::getConfirmedQuantity)); + .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getConfirmedQuantity)); } - if (bagsForOrder.stream().allMatch(orderBag -> orderBag.getAmount() != null)) { + if (bagsForOrder.stream().allMatch(it -> it.getAmount() != null)) { return bagsForOrder.stream() - .collect(Collectors.toMap(orderBag -> orderBag.getBag().getId(), OrderBag::getAmount)); + .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getAmount)); } return new HashMap<>(); } @@ -104,6 +104,8 @@ public Map getActualBagsAmountForOrder(List bagsForO * @author Oksana Spodaryk */ public void removeBagFromOrder(Order order, OrderBag orderBag) { - order.getOrderBags().remove(orderBag); + List modifiableList = new ArrayList<>(order.getOrderBags()); + modifiableList.remove(orderBag); + order.setOrderBags(modifiableList); } } From 27271c8f0db9a28e68b049fa0e6cfbb345d0f053 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Tue, 25 Jul 2023 12:34:46 +0300 Subject: [PATCH 34/73] Formatted --- .../src/test/java/greencity/service/ubs/OrderBagServiceTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java b/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java index 0f80a080c..e6b56145d 100644 --- a/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java +++ b/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java @@ -9,7 +9,6 @@ import static greencity.ModelUtils.getOrderBag; -import greencity.repository.OrderRepository; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; From 77647a987842b976c59796ac78d180b88194b63c Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Tue, 25 Jul 2023 13:09:14 +0300 Subject: [PATCH 35/73] Fixed bugs --- dao/src/main/java/greencity/entity/order/OrderBag.java | 6 ++++-- .../logs/ch-update-order-bag-mapping-table-Spodaryk.xml | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/dao/src/main/java/greencity/entity/order/OrderBag.java b/dao/src/main/java/greencity/entity/order/OrderBag.java index 38c479e23..4651fd944 100644 --- a/dao/src/main/java/greencity/entity/order/OrderBag.java +++ b/dao/src/main/java/greencity/entity/order/OrderBag.java @@ -45,10 +45,10 @@ public class OrderBag { @Column(nullable = false) private Integer amount; - @Column + @Column(name = "confirmed_quantity") private Integer confirmedQuantity; - @Column + @Column(name = "exported_quantity") private Integer exportedQuantity; @Column(nullable = false) @@ -56,10 +56,12 @@ public class OrderBag { @Column(nullable = false) private Long price; + @NotBlank @Size(min = 1, max = 30) @Column(nullable = false) private String name; + @NotBlank @Size(min = 1, max = 30) @Column(nullable = false) diff --git a/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml b/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml index 1d53cc7d0..5f145ef45 100644 --- a/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml +++ b/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd"> - + @@ -33,7 +33,7 @@ - + From 7c20251ed9e4b6c8a99af10f0e457edeffbf040a Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Tue, 25 Jul 2023 13:33:39 +0300 Subject: [PATCH 36/73] Separated sql from xml; changed to peek --- .../logs/ch-update-order-bag-mapping-table-Spodaryk.xml | 8 +------- .../sql/ch-update-order-bag-mapping-table-Spodaryk.sql | 6 ++++++ .../main/java/greencity/service/ubs/OrderBagService.java | 5 +---- 3 files changed, 8 insertions(+), 11 deletions(-) create mode 100644 dao/src/main/resources/db/changelog/logs/sql/ch-update-order-bag-mapping-table-Spodaryk.sql diff --git a/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml b/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml index 5f145ef45..18f8b49d5 100644 --- a/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml +++ b/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml @@ -47,14 +47,8 @@ + - update order_bag_mapping - set capacity=bag.capacity, - price=bag.full_price, - name=bag.name, - name_eng=bag.name_eng from bag - where bag_id=bag.id - diff --git a/dao/src/main/resources/db/changelog/logs/sql/ch-update-order-bag-mapping-table-Spodaryk.sql b/dao/src/main/resources/db/changelog/logs/sql/ch-update-order-bag-mapping-table-Spodaryk.sql new file mode 100644 index 000000000..b71d14c9a --- /dev/null +++ b/dao/src/main/resources/db/changelog/logs/sql/ch-update-order-bag-mapping-table-Spodaryk.sql @@ -0,0 +1,6 @@ +update order_bag_mapping +set capacity=bag.capacity, + price=bag.full_price, + name=bag.name, + name_eng=bag.name_eng from bag +where bag_id=bag.id \ No newline at end of file diff --git a/service/src/main/java/greencity/service/ubs/OrderBagService.java b/service/src/main/java/greencity/service/ubs/OrderBagService.java index 118bde46c..6e10f71b3 100644 --- a/service/src/main/java/greencity/service/ubs/OrderBagService.java +++ b/service/src/main/java/greencity/service/ubs/OrderBagService.java @@ -43,10 +43,7 @@ private Long getActualPrice(List orderBags, Integer id) { public List findAllBagsInOrderBagsList(List orderBags) { return orderBags.stream() .map(OrderBag::getBag) - .map(b -> { - b.setFullPrice(getActualPrice(orderBags, b.getId())); - return b; - }) + .peek(b -> b.setFullPrice(getActualPrice(orderBags, b.getId()))) .collect(Collectors.toList()); } From 9dffcfb1d3a8476ef1af4b9c4a5cbbd5c8062e89 Mon Sep 17 00:00:00 2001 From: Oksana Spodaryk <82940222+ospodaryk@users.noreply.github.com> Date: Fri, 28 Jul 2023 14:18:04 +0300 Subject: [PATCH 37/73] Bug delete tariff (#1200) * Added bagstatus * Fixed everything * Added new tests * fixed tests * fixed tests in SuperAdminServiceImplTest * fixed tests in UBSManagementServiceImplTest * added tests to cover+ refactored code to add element to mutable list --- .../main/java/greencity/entity/order/Bag.java | 7 + .../java/greencity/entity/order/OrderBag.java | 5 +- .../main/java/greencity/enums/BagStatus.java | 6 + .../greencity/repository/BagRepository.java | 26 +- .../repository/OrderBagRepository.java | 14 +- .../db/changelog/db.changelog-master.xml | 1 + ...dd-column-status-to-bag-table-Spodaryk.xml | 12 + .../service/ubs/SuperAdminServiceImpl.java | 25 +- .../service/ubs/UBSClientServiceImpl.java | 13 +- .../service/ubs/UBSManagementServiceImpl.java | 6 +- .../src/test/java/greencity/ModelUtils.java | 24 +- .../service/ubs/OrderBagServiceTest.java | 9 - .../ubs/SuperAdminServiceImplTest.java | 204 ++++---------- .../service/ubs/UBSClientServiceImplTest.java | 249 ++++++++++++++---- .../ubs/UBSManagementServiceImplTest.java | 75 ++---- 15 files changed, 396 insertions(+), 280 deletions(-) create mode 100644 dao/src/main/java/greencity/enums/BagStatus.java create mode 100644 dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-table-Spodaryk.xml diff --git a/dao/src/main/java/greencity/entity/order/Bag.java b/dao/src/main/java/greencity/entity/order/Bag.java index 321739e54..daf062258 100644 --- a/dao/src/main/java/greencity/entity/order/Bag.java +++ b/dao/src/main/java/greencity/entity/order/Bag.java @@ -1,6 +1,7 @@ package greencity.entity.order; import greencity.entity.user.employee.Employee; +import greencity.enums.BagStatus; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -18,6 +19,8 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; import javax.validation.constraints.Max; import javax.validation.constraints.Min; import java.time.LocalDate; @@ -87,4 +90,8 @@ public class Bag { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(nullable = false) private TariffsInfo tariffsInfo; + + @Column(nullable = false) + @Enumerated(EnumType.STRING) + private BagStatus status; } diff --git a/dao/src/main/java/greencity/entity/order/OrderBag.java b/dao/src/main/java/greencity/entity/order/OrderBag.java index 4651fd944..320212b23 100644 --- a/dao/src/main/java/greencity/entity/order/OrderBag.java +++ b/dao/src/main/java/greencity/entity/order/OrderBag.java @@ -34,11 +34,12 @@ public class OrderBag { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "order_id") private Order order; - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "bag_id") private Bag bag; diff --git a/dao/src/main/java/greencity/enums/BagStatus.java b/dao/src/main/java/greencity/enums/BagStatus.java new file mode 100644 index 000000000..f0f3fe1c2 --- /dev/null +++ b/dao/src/main/java/greencity/enums/BagStatus.java @@ -0,0 +1,6 @@ +package greencity.enums; + +public enum BagStatus { + ACTIVE, + DELETED +} diff --git a/dao/src/main/java/greencity/repository/BagRepository.java b/dao/src/main/java/greencity/repository/BagRepository.java index 0796e00d6..8746565b7 100644 --- a/dao/src/main/java/greencity/repository/BagRepository.java +++ b/dao/src/main/java/greencity/repository/BagRepository.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Map; +import java.util.Optional; @Repository public interface BagRepository extends JpaRepository { @@ -67,11 +68,26 @@ public interface BagRepository extends JpaRepository { List findAllByOrder(@Param("orderId") Long orderId); /** - * method, that returns {@link List} of {@link Bag} by tariff id. + * method, that returns {@link List} of {@link Bag} by id. * - * @param tariffInfoId tariff id {@link Long} - * @return {@link List} of {@link Bag} by tariffInfoId. - * @author Safarov Renat + * @param bagId {@link Integer} tariff service id + * @return {@link Optional} of {@link Bag} + * @author Oksana Spodaryk */ - List findBagsByTariffsInfoId(Long tariffInfoId); + @Query(nativeQuery = true, + value = "SELECT * FROM bag " + + "WHERE id = :bagId AND status = 'ACTIVE'") + Optional findActiveBagById(Integer bagId); + + /** + * method, that returns {@link List} of active {@link Bag} by tariff id. + * + * @param tariffInfoId {@link Long} tariff id + * @return {@link List} of {@link Bag} + * @author Oksana Spodaryk + */ + @Query(nativeQuery = true, + value = "SELECT * FROM bag " + + "WHERE tariffs_info_id = :tariffInfoId AND status = 'ACTIVE'") + List findAllActiveBagsByTariffsInfoId(Long tariffInfoId); } \ No newline at end of file diff --git a/dao/src/main/java/greencity/repository/OrderBagRepository.java b/dao/src/main/java/greencity/repository/OrderBagRepository.java index 578aba332..5d17132ce 100644 --- a/dao/src/main/java/greencity/repository/OrderBagRepository.java +++ b/dao/src/main/java/greencity/repository/OrderBagRepository.java @@ -12,6 +12,18 @@ @Repository public interface OrderBagRepository extends JpaRepository { + /** + * Deletes the OrderBag from the ORDER_BAG_MAPPING table where the bagId and + * orderId match the provided values. + * + * @param bagId The ID of the bag to be deleted. + * @param orderId The ID of the order to which the bag is associated. + */ + @Transactional + @Modifying + @Query(value = "DELETE FROM ORDER_BAG_MAPPING WHERE BAG_ID = :bagId AND ORDER_ID = :orderId", nativeQuery = true) + void deleteOrderBagByBagIdAndOrderId(@Param("bagId") Integer bagId, @Param("orderId") Long orderId); + /** * Retrieves a list of order bags based on the given bag ID. * @@ -40,7 +52,7 @@ public interface OrderBagRepository extends JpaRepository { * @param price {@link Long} bag full price in coins * @param name {@link String} bag name * @param nameEng {@link String} bag english name - * @author Julia Seti + * @author Oksana Spodaryk */ @Transactional @Modifying diff --git a/dao/src/main/resources/db/changelog/db.changelog-master.xml b/dao/src/main/resources/db/changelog/db.changelog-master.xml index 1632d90bd..2bd59f6d6 100644 --- a/dao/src/main/resources/db/changelog/db.changelog-master.xml +++ b/dao/src/main/resources/db/changelog/db.changelog-master.xml @@ -215,4 +215,5 @@ + \ No newline at end of file diff --git a/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-table-Spodaryk.xml b/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-table-Spodaryk.xml new file mode 100644 index 000000000..9496bacb0 --- /dev/null +++ b/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-table-Spodaryk.xml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java index acf611a25..73b906cc4 100644 --- a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java @@ -35,6 +35,7 @@ import greencity.entity.user.Region; import greencity.entity.user.employee.Employee; import greencity.entity.user.employee.ReceivingStation; +import greencity.enums.BagStatus; import greencity.enums.CourierLimit; import greencity.enums.OrderPaymentStatus; import greencity.enums.CourierStatus; @@ -133,6 +134,7 @@ private Bag createBag(long tariffId, TariffServiceDto dto, String employeeUuid) TariffsInfo tariffsInfo = tryToFindTariffById(tariffId); Employee employee = tryToFindEmployeeByUuid(employeeUuid); Bag bag = modelMapper.map(dto, Bag.class); + bag.setStatus(BagStatus.ACTIVE); bag.setTariffsInfo(tariffsInfo); bag.setCreatedBy(employee); return bag; @@ -141,7 +143,7 @@ private Bag createBag(long tariffId, TariffServiceDto dto, String employeeUuid) @Override public List getTariffService(long tariffId) { if (tariffsInfoRepository.existsById(tariffId)) { - return bagRepository.findBagsByTariffsInfoId(tariffId) + return bagRepository.findAllActiveBagsByTariffsInfoId(tariffId) .stream() .map(it -> modelMapper.map(it, GetTariffServiceDto.class)) .collect(Collectors.toList()); @@ -154,29 +156,36 @@ public List getTariffService(long tariffId) { @Transactional public void deleteTariffService(Integer bagId) { Bag bag = tryToFindBagById(bagId); + if (CollectionUtils.isEmpty(orderBagRepository.findOrderBagsByBagId(bagId))) { + bagRepository.delete(bag); + return; + } + bag.setStatus(BagStatus.DELETED); + bagRepository.save(bag); checkDeletedBagLimitAndDeleteTariffsInfo(bag); - orderRepository.findAllByBagId(bagId).forEach(it -> deleteBagFromOrder(it, bagId)); + orderRepository.findAllByBagId(bagId).forEach(order -> deleteBagFromOrder(order, bag)); } - private void deleteBagFromOrder(Order order, Integer bagId) { + private void deleteBagFromOrder(Order order, Bag bag) { + Integer bagId = bag.getId(); Map amount = orderBagService.getActualBagsAmountForOrder(order.getOrderBags()); Integer totalBagsAmount = amount.values().stream().reduce(0, Integer::sum); - if (amount.get(bagId).equals(0) || order.getOrderPaymentStatus() == OrderPaymentStatus.UNPAID) { - if (totalBagsAmount.equals(amount.get(bagId))) { + if (amount.get(bagId).equals(0) || order.getOrderPaymentStatus().equals(OrderPaymentStatus.UNPAID)) { + if (totalBagsAmount.equals(amount.get(bagId)) || bag.getLimitIncluded()) { order.setOrderBags(new ArrayList<>()); orderRepository.delete(order); return; } order.getOrderBags().stream().filter(orderBag -> orderBag.getBag().getId().equals(bagId)) .findFirst() - .ifPresent(orderBag -> orderBagService.removeBagFromOrder(order, orderBag)); + .ifPresent(orderBag -> orderBagRepository.deleteOrderBagByBagIdAndOrderId(bagId, order.getId())); orderRepository.save(order); } } private void checkDeletedBagLimitAndDeleteTariffsInfo(Bag bag) { TariffsInfo tariffsInfo = bag.getTariffsInfo(); - List bags = bagRepository.findBagsByTariffsInfoId(tariffsInfo.getId()); + List bags = bagRepository.findAllActiveBagsByTariffsInfoId(tariffsInfo.getId()); if (bags.isEmpty() || bags.stream().noneMatch(Bag::getLimitIncluded)) { tariffsInfo.setTariffStatus(TariffStatus.DEACTIVATED); tariffsInfo.setBags(bags); @@ -243,7 +252,7 @@ private Long convertBillsIntoCoins(Double bills) { } private Bag tryToFindBagById(Integer id) { - return bagRepository.findById(id).orElseThrow( + return bagRepository.findActiveBagById(id).orElseThrow( () -> new NotFoundException(ErrorMessage.BAG_NOT_FOUND + id)); } diff --git a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java index 5c64e460f..fe925bdd9 100644 --- a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java @@ -73,6 +73,7 @@ import greencity.entity.user.ubs.UBSuser; import greencity.entity.viber.ViberBot; import greencity.enums.AddressStatus; +import greencity.enums.BagStatus; import greencity.enums.BotType; import greencity.enums.CertificateStatus; import greencity.enums.CourierLimit; @@ -355,7 +356,7 @@ private boolean isTariffAvailableForCurrentLocation(TariffsInfo tariffsInfo, Loc private UserPointsAndAllBagsDto getUserPointsAndAllBagsDtoByTariffIdAndUserPoints(Long tariffId, Integer userPoints) { - var bagTranslationDtoList = bagRepository.findBagsByTariffsInfoId(tariffId).stream() + var bagTranslationDtoList = bagRepository.findAllActiveBagsByTariffsInfoId(tariffId).stream() .map(bag -> modelMapper.map(bag, BagTranslationDto.class)) .collect(toList()); return new UserPointsAndAllBagsDto(bagTranslationDtoList, userPoints); @@ -376,8 +377,12 @@ private Location getLocationByOrderIdThroughLazyInitialization(Order order) { public PersonalDataDto getSecondPageData(String uuid) { User currentUser = userRepository.findByUuid(uuid); List ubsUser = ubsUserRepository.findUBSuserByUser(currentUser); + if (ubsUser.isEmpty()) { - ubsUser.add(UBSuser.builder().id(null).build()); + UBSuser ubSuser = UBSuser.builder().id(null).build(); + List mutableUbsUserList = new ArrayList<>(ubsUser); + mutableUbsUserList.add(ubSuser); + ubsUser = mutableUbsUserList; } PersonalDataDto dto = modelMapper.map(currentUser, PersonalDataDto.class); dto.setUbsUserId(ubsUser.get(0).getId()); @@ -459,7 +464,7 @@ private List getBagIds(List dto) { } private Bag findBagById(Integer id) { - return bagRepository.findById(id) + return bagRepository.findActiveBagById(id) .orElseThrow(() -> new NotFoundException(BAG_NOT_FOUND + id)); } @@ -1213,7 +1218,7 @@ private long formBagsToBeSavedAndCalculateOrderSum( } List orderedBagsIds = bags.stream().map(BagDto::getId).collect(toList()); List notOrderedBags = tariffsInfo.getBags().stream() - .filter(orderBag -> !orderedBagsIds.contains(orderBag.getId())) + .filter(orderBag -> orderBag.getStatus() == BagStatus.ACTIVE && !orderedBagsIds.contains(orderBag.getId())) .map(this::createOrderBag).collect(toList()); notOrderedBags.forEach(orderBag -> orderBag.setAmount(0)); orderBagList.addAll(notOrderedBags); diff --git a/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java index a57272131..92debfe0e 100644 --- a/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java @@ -370,7 +370,7 @@ public OrderStatusPageDto getOrderStatusData(Long orderId, String email) { checkAvailableOrderForEmployee(order, email); CounterOrderDetailsDto prices = getPriceDetails(orderId); - var bagInfoDtoList = bagRepository.findBagsByTariffsInfoId(order.getTariffsInfo().getId()).stream() + var bagInfoDtoList = bagRepository.findAllActiveBagsByTariffsInfoId(order.getTariffsInfo().getId()).stream() .map(bag -> modelMapper.map(bag, BagInfoDto.class)) .collect(Collectors.toList()); @@ -713,7 +713,7 @@ private void collectEventAboutConfirmWaste(Map confirmed, Orde Long orderId, int countOfChanges, StringBuilder values) { for (Map.Entry entry : confirmed.entrySet()) { Integer capacity = bagRepository.findCapacityById(entry.getKey()); - Optional bagOptional = bagRepository.findById(entry.getKey()); + Optional bagOptional = bagRepository.findActiveBagById(entry.getKey()); if (bagOptional.isPresent() && checkOrderStatusAboutConfirmWaste(order)) { Optional confirmWasteWas = Optional.empty(); Optional initialAmount = Optional.empty(); @@ -740,7 +740,7 @@ private void collectEventAboutExportedWaste(Map exported, Orde Long orderId, int countOfChanges, StringBuilder values) { for (Map.Entry entry : exported.entrySet()) { Integer capacity = bagRepository.findCapacityById(entry.getKey()); - Optional bagOptional = bagRepository.findById(entry.getKey()); + Optional bagOptional = bagRepository.findActiveBagById(entry.getKey()); if (bagOptional.isPresent() && checkOrderStatusAboutExportedWaste(order)) { Optional exporterWasteWas = Optional.empty(); Optional confirmWasteWas = Optional.empty(); diff --git a/service/src/test/java/greencity/ModelUtils.java b/service/src/test/java/greencity/ModelUtils.java index fe886952d..94f263d4c 100644 --- a/service/src/test/java/greencity/ModelUtils.java +++ b/service/src/test/java/greencity/ModelUtils.java @@ -122,6 +122,7 @@ import greencity.entity.user.ubs.UBSuser; import greencity.entity.viber.ViberBot; import greencity.enums.AddressStatus; +import greencity.enums.BagStatus; import greencity.enums.CancellationReason; import greencity.enums.CertificateStatus; import greencity.enums.CourierLimit; @@ -2263,6 +2264,7 @@ private static List createBagMappingDtoList() { private static Bag createBag() { return Bag.builder() + .status(BagStatus.ACTIVE) .id(1) .name("Name") .nameEng("NameEng") @@ -2670,6 +2672,7 @@ public static GetTariffServiceDto getGetTariffServiceDto() { public static Optional getOptionalBag() { return Optional.of(Bag.builder() + .status(BagStatus.ACTIVE) .id(1) .capacity(120) .commission(50_00L) @@ -2699,6 +2702,7 @@ public static OrderBag getOrderBag2() { public static Bag getBag() { return Bag.builder() + .status(BagStatus.ACTIVE) .id(1) .capacity(120) .commission(50_00L) @@ -2708,13 +2712,13 @@ public static Bag getBag() { .createdBy(getEmployee()) .editedBy(getEmployee()) .limitIncluded(true) - .tariffsInfo(getTariffInfo()) .build(); } public static Bag getBag2() { return Bag.builder() + .status(BagStatus.ACTIVE) .id(2) .capacity(120) .commission(50_00L) @@ -2724,7 +2728,6 @@ public static Bag getBag2() { .createdBy(getEmployee()) .editedBy(getEmployee()) .limitIncluded(true) - .tariffsInfo(getTariffInfo()) .build(); } @@ -2784,12 +2787,14 @@ public static Bag getBagDeleted() { .description("Description") .descriptionEng("DescriptionEng") .limitIncluded(true) + .status(BagStatus.DELETED) .tariffsInfo(getTariffInfo()) .build(); } public static Bag getBagForOrder() { return Bag.builder() + .status(BagStatus.ACTIVE) .id(3) .capacity(120) .commission(50_00L) @@ -2818,6 +2823,7 @@ public static TariffServiceDto getTariffServiceDto() { public static Bag getEditedBag() { return Bag.builder() + .status(BagStatus.ACTIVE) .id(1) .capacity(20) .price(100_00L) @@ -2830,7 +2836,7 @@ public static Bag getEditedBag() { .editedBy(getEmployee()) .editedAt(LocalDate.now()) .limitIncluded(true) - + .status(BagStatus.ACTIVE) .tariffsInfo(getTariffInfo()) .build(); @@ -2905,6 +2911,7 @@ public static CourierDto getCourierDto() { public static Bag getTariffBag() { return Bag.builder() + .status(BagStatus.ACTIVE) .id(1) .capacity(20) .price(100_00L) @@ -2934,6 +2941,7 @@ public static BagTranslationDto getBagTranslationDto() { public static Bag getNewBag() { return Bag.builder() + .status(BagStatus.ACTIVE) .capacity(20) .price(100_00L) .commission(50_00L) @@ -2945,7 +2953,6 @@ public static Bag getNewBag() { .descriptionEng("DescriptionEng") .name("name") .nameEng("nameEng") - .build(); } @@ -3076,6 +3083,7 @@ public static Order getOrderUserSecond() { public static List getBag1list() { return List.of(Bag.builder() + .status(BagStatus.ACTIVE) .id(1) .price(100_00L) .capacity(20) @@ -3089,6 +3097,7 @@ public static List getBag1list() { public static List getBaglist() { return List.of(Bag.builder() + .status(BagStatus.ACTIVE) .id(1) .price(100_00L) .capacity(10) @@ -3096,6 +3105,7 @@ public static List getBaglist() { .fullPrice(20_00L) .build(), Bag.builder() + .status(BagStatus.ACTIVE) .id(2) .price(100_00L) .capacity(10) @@ -3106,6 +3116,7 @@ public static List getBaglist() { public static List getBag2list() { return List.of(Bag.builder() + .status(BagStatus.ACTIVE) .id(1) .price(100_00L) .capacity(10) @@ -3116,6 +3127,7 @@ public static List getBag2list() { public static List getBag3list() { return List.of(Bag.builder() + .status(BagStatus.ACTIVE) .id(1) .price(100_00L) .capacity(10) @@ -3123,6 +3135,7 @@ public static List getBag3list() { .fullPrice(2000_00L) .build(), Bag.builder() + .status(BagStatus.ACTIVE) .id(2) .price(100_00L) .capacity(10) @@ -3133,6 +3146,7 @@ public static List getBag3list() { public static List getBag4list() { return List.of(Bag.builder() + .status(BagStatus.ACTIVE) .id(1) .price(100_00L) .capacity(10) @@ -3143,6 +3157,7 @@ public static List getBag4list() { .limitIncluded(false) .build(), Bag.builder() + .status(BagStatus.ACTIVE) .id(2) .price(100_00L) .capacity(10) @@ -3416,6 +3431,7 @@ public static Location getLocationDto() { public static Bag bagDto() { return Bag.builder() + .status(BagStatus.ACTIVE) .id(1) .limitIncluded(false) .description("Description") diff --git a/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java b/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java index e6b56145d..de1d93015 100644 --- a/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java +++ b/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java @@ -52,15 +52,6 @@ void testFindBagsByOrdersList() { assertEquals(bag2, bags.get(1)); } - @Test - void testRemoveBagFromOrder() { - Order order = getOrder(); - order.setOrderBags(Arrays.asList(getOrderBag(), getOrderBag2())); - int size = order.getOrderBags().size(); - orderBagService.removeBagFromOrder(order, getOrderBag()); - assertNotEquals(order.getOrderBags().size(), size); - } - @Test void testGetActualBagsAmountForOrder_WithExportedQuantity() { List bagsForOrder = new ArrayList<>(); diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index f3a3c2716..ff4c33214 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -76,15 +76,7 @@ import java.util.UUID; import java.util.stream.Stream; -import static greencity.ModelUtils.TEST_USER; -import static greencity.ModelUtils.getAllTariffsInfoDto; -import static greencity.ModelUtils.getCourier; -import static greencity.ModelUtils.getCourierDto; -import static greencity.ModelUtils.getCourierDtoList; -import static greencity.ModelUtils.getDeactivatedCourier; -import static greencity.ModelUtils.getEmployee; -import static greencity.ModelUtils.getReceivingStation; -import static greencity.ModelUtils.getReceivingStationDto; +import static greencity.ModelUtils.*; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; @@ -219,13 +211,13 @@ void getTariffServiceTest() { GetTariffServiceDto dto = ModelUtils.getGetTariffServiceDto(); when(tariffsInfoRepository.existsById(1L)).thenReturn(true); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(bags); + when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(bags); when(modelMapper.map(bags.get(0), GetTariffServiceDto.class)).thenReturn(dto); superAdminService.getTariffService(1); verify(tariffsInfoRepository).existsById(1L); - verify(bagRepository).findBagsByTariffsInfoId(1L); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); verify(modelMapper).map(bags.get(0), GetTariffServiceDto.class); } @@ -234,13 +226,13 @@ void getTariffServiceIfThereAreNoBags() { List bags = Collections.emptyList(); when(tariffsInfoRepository.existsById(1L)).thenReturn(true); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(bags); + when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(bags); List dtos = superAdminService.getTariffService(1); assertEquals(Collections.emptyList(), dtos); verify(tariffsInfoRepository).existsById(1L); - verify(bagRepository).findBagsByTariffsInfoId(1L); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); } @Test @@ -251,7 +243,7 @@ void getTariffServiceIfTariffNotFoundException() { () -> superAdminService.getTariffService(1)); verify(tariffsInfoRepository).existsById(1L); - verify(bagRepository, never()).findBagsByTariffsInfoId(1L); + verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(1L); } @Test @@ -259,112 +251,35 @@ void deleteTariffServiceWhenTariffBagsWithLimits() { Bag bag = ModelUtils.getBag(); Bag bagDeleted = ModelUtils.getBagDeleted(); TariffsInfo tariffsInfo = ModelUtils.getTariffInfo(); - - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(List.of(bag)); - - superAdminService.deleteTariffService(1); - - verify(bagRepository).findById(1); - verify(bagRepository).findBagsByTariffsInfoId(1L); - verify(tariffsInfoRepository, never()).save(tariffsInfo); - } - - @Test - void deleteTariffService2() { - Bag bag = ModelUtils.getBag(); - TariffsInfo tariffsInfo = ModelUtils.getTariffsInfoWithStatusNew(); - tariffsInfo.setBags(Arrays.asList(bag)); - bag.setTariffsInfo(tariffsInfo); - tariffsInfo.setTariffStatus(TariffStatus.DEACTIVATED); - Map amount = new HashMap<>(); - amount.put(1, 3); - amount.put(2, 7); - - Order order = ModelUtils.getOrder(); - order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(Collections.emptyList()); - when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfo); - when(orderRepository.findAllByBagId(bag.getId())).thenReturn(Arrays.asList(order)); - when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))).thenReturn(amount); - superAdminService.deleteTariffService(1); - - verify(bagRepository).findById(1); - verify(bagRepository).findBagsByTariffsInfoId(1L); - verify(tariffsInfoRepository).save(tariffsInfo); - } - - @Test - void deleteTariffService3() { - Bag bag = ModelUtils.getBag(); - TariffsInfo tariffsInfo = ModelUtils.getTariffsInfoWithStatusNew(); - tariffsInfo.setBags(Arrays.asList(bag)); - bag.setTariffsInfo(tariffsInfo); - tariffsInfo.setTariffStatus(TariffStatus.DEACTIVATED); - Map amount = new HashMap<>(); - amount.put(1, 3); - amount.put(2, 7); Order order = ModelUtils.getOrder(); - order.setOrderPaymentStatus(OrderPaymentStatus.UNPAID); order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(Collections.emptyList()); - when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfo); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.save(bag)).thenReturn(bagDeleted); + when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(List.of(bag)); when(orderRepository.findAllByBagId(bag.getId())).thenReturn(Arrays.asList(order)); - when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))).thenReturn(amount); - superAdminService.deleteTariffService(1); - - verify(bagRepository).findById(1); - verify(bagRepository).findBagsByTariffsInfoId(1L); - verify(tariffsInfoRepository).save(tariffsInfo); - } + when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))) + .thenReturn(ModelUtils.getAmount()); + when(orderBagRepository.findOrderBagsByBagId(any())).thenReturn(Collections.singletonList(getOrderBag())); - @Test - void deleteTariffService4() { - Bag bag = ModelUtils.getBag(); - TariffsInfo tariffsInfo = ModelUtils.getTariffsInfoWithStatusNew(); - tariffsInfo.setBags(Arrays.asList(bag)); - bag.setTariffsInfo(tariffsInfo); - tariffsInfo.setTariffStatus(TariffStatus.DEACTIVATED); - Map amount = new HashMap<>(); - amount.put(1, 0); - Order order = ModelUtils.getOrder(); - order.setOrderPaymentStatus(OrderPaymentStatus.UNPAID); - order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(Collections.emptyList()); - when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfo); - when(orderRepository.findAllByBagId(bag.getId())).thenReturn(Arrays.asList(order)); - when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))).thenReturn(amount); superAdminService.deleteTariffService(1); - verify(bagRepository).findById(1); - verify(bagRepository).findBagsByTariffsInfoId(1L); - verify(tariffsInfoRepository).save(tariffsInfo); + verify(bagRepository).findActiveBagById(1); + verify(bagRepository).save(bag); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); + verify(tariffsInfoRepository, never()).save(tariffsInfo); } @Test void deleteTariffServiceWhenTariffBagsListIsEmpty() { Bag bag = ModelUtils.getBag(); - TariffsInfo tariffsInfo = ModelUtils.getTariffsInfoWithStatusNew(); - tariffsInfo.setBags(Arrays.asList(bag)); - bag.setTariffsInfo(tariffsInfo); - tariffsInfo.setTariffStatus(TariffStatus.DEACTIVATED); - Map amount = new HashMap<>(); - amount.put(1, 0); - Order order = ModelUtils.getOrder(); - order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(Collections.emptyList()); - when(tariffsInfoRepository.save(tariffsInfo)).thenReturn(tariffsInfo); - when(orderRepository.findAllByBagId(bag.getId())).thenReturn(Arrays.asList(order)); - when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))).thenReturn(amount); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); + superAdminService.deleteTariffService(1); - verify(bagRepository).findById(1); - verify(bagRepository).findBagsByTariffsInfoId(1L); - verify(tariffsInfoRepository).save(tariffsInfo); + verify(orderBagRepository).findOrderBagsByBagId(any()); + verify(bagRepository).findActiveBagById(1); + verify(bagRepository).delete(any()); + } @Test @@ -374,30 +289,27 @@ void deleteTariffServiceWhenTariffBagsWithoutLimits() { Bag bagDeleted = ModelUtils.getBagDeleted(); bagDeleted.setLimitIncluded(false); TariffsInfo tariffsInfoNew = ModelUtils.getTariffsInfoWithStatusNew(); - tariffsInfoNew.setBags(Arrays.asList(bag)); - bag.setTariffsInfo(tariffsInfoNew); - tariffsInfoNew.setTariffStatus(TariffStatus.DEACTIVATED); - tariffsInfoNew.setBags(Arrays.asList(bag)); - bag.setTariffsInfo(tariffsInfoNew); + tariffsInfoNew.setBags(Collections.emptyList()); tariffsInfoNew.setTariffStatus(TariffStatus.DEACTIVATED); - - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(List.of(bag)); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.save(bag)).thenReturn(bagDeleted); when(tariffsInfoRepository.save(tariffsInfoNew)).thenReturn(tariffsInfoNew); + when(orderBagRepository.findOrderBagsByBagId(any())).thenReturn(Collections.singletonList(getOrderBag())); superAdminService.deleteTariffService(1); - verify(bagRepository).findById(1); - verify(bagRepository).findBagsByTariffsInfoId(1L); + verify(bagRepository).findActiveBagById(1); + verify(bagRepository).save(bag); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); verify(tariffsInfoRepository).save(tariffsInfoNew); } @Test void deleteTariffServiceThrowBagNotFoundException() { - when(bagRepository.findById(1)).thenReturn(Optional.empty()); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, () -> superAdminService.deleteTariffService(1)); - verify(bagRepository).findById(1); + verify(bagRepository).findActiveBagById(1); verify(bagRepository, never()).save(any(Bag.class)); } @@ -413,7 +325,7 @@ void editTariffServiceWithUnpaidOrder() { order.setOrderBags(List.of(ModelUtils.getOrderBag())); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); when(bagRepository.save(editedBag)).thenReturn(editedBag); when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); @@ -428,7 +340,7 @@ void editTariffServiceWithUnpaidOrder() { assertEquals(editedDto, actual); verify(employeeRepository).findByUuid(uuid); - verify(bagRepository).findById(1); + verify(bagRepository).findActiveBagById(1); verify(bagRepository).save(editedBag); verify(modelMapper).map(editedBag, GetTariffServiceDto.class); verify(orderBagRepository) @@ -449,7 +361,7 @@ void editTariffServiceWithUnpaidOrderAndBagConfirmedAmount() { order.setOrderBags(List.of(ModelUtils.getOrderBagWithConfirmedAmount())); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); when(bagRepository.save(editedBag)).thenReturn(editedBag); when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); doNothing().when(orderBagRepository) @@ -464,7 +376,7 @@ void editTariffServiceWithUnpaidOrderAndBagConfirmedAmount() { assertEquals(editedDto, actual); verify(employeeRepository).findByUuid(uuid); - verify(bagRepository).findById(1); + verify(bagRepository).findActiveBagById(1); verify(bagRepository).save(editedBag); verify(modelMapper).map(editedBag, GetTariffServiceDto.class); verify(orderBagRepository) @@ -485,7 +397,7 @@ void editTariffServiceWithUnpaidOrderAndBagExportedAmount() { order.setOrderBags(List.of(ModelUtils.getOrderBagWithExportedAmount())); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); when(bagRepository.save(editedBag)).thenReturn(editedBag); when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); doNothing().when(orderBagRepository) @@ -500,8 +412,8 @@ void editTariffServiceWithUnpaidOrderAndBagExportedAmount() { assertEquals(editedDto, actual); verify(employeeRepository).findByUuid(uuid); - verify(bagRepository).findById(1); - verify(bagRepository).findById(1); + verify(bagRepository).findActiveBagById(1); + verify(bagRepository).findActiveBagById(1); verify(bagRepository).save(editedBag); verify(modelMapper).map(editedBag, GetTariffServiceDto.class); @@ -521,7 +433,7 @@ void editTariffServiceWithoutUnpaidOrder() { String uuid = UUID.randomUUID().toString(); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.of(employee)); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); when(bagRepository.save(editedBag)).thenReturn(editedBag); when(modelMapper.map(editedBag, GetTariffServiceDto.class)).thenReturn(editedDto); doNothing().when(orderBagRepository) @@ -532,7 +444,7 @@ void editTariffServiceWithoutUnpaidOrder() { assertEquals(editedDto, actual); verify(employeeRepository).findByUuid(uuid); - verify(bagRepository).findById(1); + verify(bagRepository).findActiveBagById(1); verify(bagRepository).save(editedBag); verify(modelMapper).map(editedBag, GetTariffServiceDto.class); verify(orderBagRepository) @@ -547,12 +459,12 @@ void editTariffServiceIfEmployeeNotFoundException() { Optional bag = ModelUtils.getOptionalBag(); String uuid = UUID.randomUUID().toString(); - when(bagRepository.findById(1)).thenReturn(bag); + when(bagRepository.findActiveBagById(1)).thenReturn(bag); when(employeeRepository.findByUuid(uuid)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, () -> superAdminService.editTariffService(dto, 1, uuid)); - verify(bagRepository).findById(1); + verify(bagRepository).findActiveBagById(1); verify(bagRepository, never()).save(any(Bag.class)); } @@ -561,11 +473,11 @@ void editTariffServiceIfBagNotFoundException() { TariffServiceDto dto = ModelUtils.getTariffServiceDto(); String uuid = UUID.randomUUID().toString(); - when(bagRepository.findById(1)).thenReturn(Optional.empty()); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, () -> superAdminService.editTariffService(dto, 1, uuid)); - verify(bagRepository).findById(1); + verify(bagRepository).findActiveBagById(1); verify(bagRepository, never()).save(any(Bag.class)); } @@ -1567,14 +1479,14 @@ void setTariffLimitsWithAmountOfBags() { SetTariffLimitsDto dto = ModelUtils.setTariffLimitsWithAmountOfBags(); when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); when(tariffsInfoRepository.save(tariffInfo)).thenReturn(tariffInfo); when(bagRepository.saveAll(List.of(bag))).thenReturn(List.of(bag)); superAdminService.setTariffLimits(1L, dto); verify(tariffsInfoRepository).findById(1L); - verify(bagRepository).findById(1); + verify(bagRepository).findActiveBagById(1); verify(tariffsInfoRepository).save(any()); verify(bagRepository).saveAll(List.of(bag)); } @@ -1586,14 +1498,14 @@ void setTariffLimitsWithPriceOfOrder() { SetTariffLimitsDto dto = ModelUtils.setTariffLimitsWithPriceOfOrder(); when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); when(tariffsInfoRepository.save(tariffInfo)).thenReturn(tariffInfo); when(bagRepository.saveAll(List.of(bag))).thenReturn(List.of(bag)); superAdminService.setTariffLimits(1L, dto); verify(tariffsInfoRepository).findById(1L); - verify(bagRepository).findById(1); + verify(bagRepository).findActiveBagById(1); verify(tariffsInfoRepository).save(any()); verify(bagRepository).saveAll(List.of(bag)); } @@ -1605,14 +1517,14 @@ void setTariffLimitsWithNullMinAndMaxAndFalseBagLimitIncluded() { SetTariffLimitsDto dto = ModelUtils.setTariffLimitsWithNullMinAndMaxAndFalseBagLimit(); when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); when(tariffsInfoRepository.save(tariffInfo)).thenReturn(tariffInfo); when(bagRepository.saveAll(List.of(bag))).thenReturn(List.of(bag)); superAdminService.setTariffLimits(1L, dto); verify(tariffsInfoRepository).findById(1L); - verify(bagRepository).findById(1); + verify(bagRepository).findActiveBagById(1); verify(tariffsInfoRepository).save(any()); verify(bagRepository).saveAll(List.of(bag)); } @@ -1625,13 +1537,13 @@ void setTariffLimitsIfBagNotBelongToTariff() { tariffInfo.setId(2L); when(tariffsInfoRepository.findById(2L)).thenReturn(Optional.of(tariffInfo)); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, () -> superAdminService.setTariffLimits(2L, dto)); verify(tariffsInfoRepository).findById(2L); - verify(bagRepository).findById(1); + verify(bagRepository).findActiveBagById(1); } @Test @@ -1642,14 +1554,14 @@ void setTariffLimitsWithNullMaxAndTrueBagLimitIncluded() { dto.setMax(null); when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); when(tariffsInfoRepository.save(tariffInfo)).thenReturn(tariffInfo); when(bagRepository.saveAll(List.of(bag))).thenReturn(List.of(bag)); superAdminService.setTariffLimits(1L, dto); verify(tariffsInfoRepository).findById(1L); - verify(bagRepository).findById(1); + verify(bagRepository).findActiveBagById(1); verify(tariffsInfoRepository).save(any()); verify(bagRepository).saveAll(List.of(bag)); } @@ -1662,14 +1574,14 @@ void setTariffLimitsWithNullMinAndTrueBagLimitIncluded() { dto.setMin(null); when(tariffsInfoRepository.findById(1L)).thenReturn(Optional.of(tariffInfo)); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); when(tariffsInfoRepository.save(tariffInfo)).thenReturn(tariffInfo); when(bagRepository.saveAll(List.of(bag))).thenReturn(List.of(bag)); superAdminService.setTariffLimits(1L, dto); verify(tariffsInfoRepository).findById(1L); - verify(bagRepository).findById(1); + verify(bagRepository).findActiveBagById(1); verify(tariffsInfoRepository).save(any()); verify(bagRepository).saveAll(List.of(bag)); } @@ -1775,13 +1687,13 @@ void setTariffLimitsBagThrowBagNotFound() { TariffsInfo tariffInfo = ModelUtils.getTariffInfo(); when(tariffsInfoRepository.findById(anyLong())).thenReturn(Optional.of(tariffInfo)); - when(bagRepository.findById(1)).thenReturn(Optional.empty()); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, () -> superAdminService.setTariffLimits(1L, dto)); verify(tariffsInfoRepository).findById(1L); - verify(bagRepository).findById(1); + verify(bagRepository).findActiveBagById(1); } @Test diff --git a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java index da6826fee..b207db18e 100644 --- a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java @@ -62,7 +62,26 @@ import greencity.exceptions.http.AccessDeniedException; import greencity.exceptions.user.UBSuserNotFoundException; import greencity.exceptions.user.UserNotFoundException; -import greencity.repository.*; +import greencity.repository.AddressRepository; +import greencity.repository.BagRepository; +import greencity.repository.CertificateRepository; +import greencity.repository.CourierRepository; +import greencity.repository.EmployeeRepository; +import greencity.repository.EventRepository; +import greencity.repository.LocationRepository; +import greencity.repository.OrderAddressRepository; +import greencity.repository.OrderBagRepository; +import greencity.repository.OrderPaymentStatusTranslationRepository; +import greencity.repository.OrderRepository; +import greencity.repository.OrderStatusTranslationRepository; +import greencity.repository.OrdersForUserRepository; +import greencity.repository.PaymentRepository; +import greencity.repository.TariffLocationRepository; +import greencity.repository.TariffsInfoRepository; +import greencity.repository.TelegramBotRepository; +import greencity.repository.UBSuserRepository; +import greencity.repository.UserRepository; +import greencity.repository.ViberBotRepository; import greencity.service.google.GoogleApiService; import greencity.service.locations.LocationApiService; import greencity.util.Bot; @@ -98,7 +117,80 @@ import java.util.UUID; import java.util.stream.Collectors; -import static greencity.ModelUtils.*; +import static greencity.ModelUtils.TEST_BAG_FOR_USER_DTO; +import static greencity.ModelUtils.TEST_BAG_LIST; +import static greencity.ModelUtils.TEST_EMAIL; +import static greencity.ModelUtils.TEST_ORDER_ADDRESS_DTO_REQUEST; +import static greencity.ModelUtils.TEST_PAYMENT_LIST; +import static greencity.ModelUtils.addressDto; +import static greencity.ModelUtils.addressDtoList; +import static greencity.ModelUtils.addressList; +import static greencity.ModelUtils.bagDto; +import static greencity.ModelUtils.botList; +import static greencity.ModelUtils.createCertificateDto; +import static greencity.ModelUtils.getAddress; +import static greencity.ModelUtils.getAddressDtoResponse; +import static greencity.ModelUtils.getAddressRequestDto; +import static greencity.ModelUtils.getBag; +import static greencity.ModelUtils.getBag1list; +import static greencity.ModelUtils.getBag4list; +import static greencity.ModelUtils.getBagForOrder; +import static greencity.ModelUtils.getBagTranslationDto; +import static greencity.ModelUtils.getCancellationDto; +import static greencity.ModelUtils.getCertificate; +import static greencity.ModelUtils.getCourier; +import static greencity.ModelUtils.getCourierDto; +import static greencity.ModelUtils.getCourierDtoList; +import static greencity.ModelUtils.getEmployee; +import static greencity.ModelUtils.getGeocodingResult; +import static greencity.ModelUtils.getListOfEvents; +import static greencity.ModelUtils.getLocation; +import static greencity.ModelUtils.getMaximumAmountOfAddresses; +import static greencity.ModelUtils.getOrder; +import static greencity.ModelUtils.getOrderClientDto; +import static greencity.ModelUtils.getOrderCount; +import static greencity.ModelUtils.getOrderCountWithPaymentStatusPaid; +import static greencity.ModelUtils.getOrderDetails; +import static greencity.ModelUtils.getOrderDetailsWithoutSender; +import static greencity.ModelUtils.getOrderDoneByUser; +import static greencity.ModelUtils.getOrderFondyClientDto; +import static greencity.ModelUtils.getOrderPaymentDetailDto; +import static greencity.ModelUtils.getOrderPaymentStatusTranslation; +import static greencity.ModelUtils.getOrderResponseDto; +import static greencity.ModelUtils.getOrderStatusDto; +import static greencity.ModelUtils.getOrderStatusTranslation; +import static greencity.ModelUtils.getOrderTest; +import static greencity.ModelUtils.getOrderWithEvents; +import static greencity.ModelUtils.getOrderWithTariffAndLocation; +import static greencity.ModelUtils.getOrderWithoutPayment; +import static greencity.ModelUtils.getOrdersDto; +import static greencity.ModelUtils.getPayment; +import static greencity.ModelUtils.getPaymentResponseDto; +import static greencity.ModelUtils.getSuccessfulFondyResponse; +import static greencity.ModelUtils.getTariffInfo; +import static greencity.ModelUtils.getTariffInfoWithLimitOfBags; +import static greencity.ModelUtils.getTariffInfoWithLimitOfBagsAndMaxLessThanCountOfBigBag; +import static greencity.ModelUtils.getTariffLocation; +import static greencity.ModelUtils.getTariffsForLocationDto; +import static greencity.ModelUtils.getTariffsInfo; +import static greencity.ModelUtils.getTelegramBotNotifyTrue; +import static greencity.ModelUtils.getTestOrderAddressDtoRequest; +import static greencity.ModelUtils.getTestOrderAddressLocationDto; +import static greencity.ModelUtils.getTestUser; +import static greencity.ModelUtils.getUBSuser; +import static greencity.ModelUtils.getUBSuserWithoutSender; +import static greencity.ModelUtils.getUbsCustomersDtoUpdate; +import static greencity.ModelUtils.getUbsUsers; +import static greencity.ModelUtils.getUser; +import static greencity.ModelUtils.getUserForCreate; +import static greencity.ModelUtils.getUserInfoDto; +import static greencity.ModelUtils.getUserPointsAndAllBagsDto; +import static greencity.ModelUtils.getUserProfileCreateDto; +import static greencity.ModelUtils.getUserProfileUpdateDto; +import static greencity.ModelUtils.getUserProfileUpdateDtoWithBotsIsNotifyFalse; +import static greencity.ModelUtils.getUserWithBotNotifyTrue; +import static greencity.ModelUtils.getUserWithLastLocation; +import static greencity.ModelUtils.getViberBotNotifyTrue; import static greencity.constant.ErrorMessage.ACTUAL_ADDRESS_NOT_FOUND; import static greencity.constant.ErrorMessage.ADDRESS_ALREADY_EXISTS; import static greencity.constant.ErrorMessage.CANNOT_ACCESS_PERSONAL_INFO; @@ -303,7 +395,7 @@ void getFirstPageDataByTariffAndLocationIdShouldReturnExpectedData() { when(locationRepository.findById(locationId)).thenReturn(Optional.of(location)); when(tariffLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) .thenReturn(Optional.of(tariffLocation)); - when(bagRepository.findBagsByTariffsInfoId(tariffsInfoId)).thenReturn(bags); + when(bagRepository.findAllActiveBagsByTariffsInfoId(tariffsInfoId)).thenReturn(bags); when(modelMapper.map(bags.get(0), BagTranslationDto.class)).thenReturn(bagTranslationDto); var userPointsAndAllBagsDtoActual = @@ -323,7 +415,7 @@ void getFirstPageDataByTariffAndLocationIdShouldReturnExpectedData() { verify(tariffsInfoRepository).findById(tariffsInfoId); verify(locationRepository).findById(locationId); verify(tariffLocationRepository).findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location); - verify(bagRepository).findBagsByTariffsInfoId(tariffsInfoId); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(tariffsInfoId); verify(modelMapper).map(bags.get(0), BagTranslationDto.class); } @@ -356,7 +448,7 @@ void getFirstPageDataByTariffAndLocationIdShouldThrowExceptionWhenTariffLocation verify(locationRepository).findById(locationId); verify(tariffLocationRepository).findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location); - verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } @@ -387,7 +479,7 @@ void getFirstPageDataByTariffAndLocationIdShouldThrowExceptionWhenLocationDoesNo verify(locationRepository).findById(locationId); verify(tariffLocationRepository, never()).findTariffLocationByTariffsInfoAndLocation(any(), any()); - verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } @@ -417,7 +509,7 @@ void getFirstPageDataByTariffAndLocationIdShouldThrowExceptionWhenTariffDoesNotE verify(locationRepository, never()).findById(anyLong()); verify(tariffLocationRepository, never()).findTariffLocationByTariffsInfoAndLocation(any(), any()); - verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), anyLong()); } @@ -444,7 +536,7 @@ void getFirstPageDataByTariffAndLocationIdShouldThrowExceptionWhenUserDoesNotExi verify(tariffsInfoRepository, never()).findById(anyLong()); verify(locationRepository, never()).findById(anyLong()); verify(tariffLocationRepository, never()).findTariffLocationByTariffsInfoAndLocation(any(), any()); - verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } @@ -474,7 +566,7 @@ void checkIfTariffIsAvailableForCurrentLocationThrowExceptionWhenTariffIsDeactiv verify(locationRepository).findById(locationId); verify(tariffLocationRepository, never()).findTariffLocationByTariffsInfoAndLocation(any(), any()); - verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } @@ -504,7 +596,7 @@ void checkIfTariffIsAvailableForCurrentLocationThrowExceptionWhenLocationIsDeact verify(locationRepository).findById(locationId); verify(tariffLocationRepository, never()).findTariffLocationByTariffsInfoAndLocation(any(), any()); - verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } @@ -541,7 +633,7 @@ void checkIfTariffIsAvailableForCurrentLocationWhenLocationForTariffIsDeactivate verify(locationRepository).findById(locationId); verify(tariffLocationRepository).findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location); - verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } @@ -569,7 +661,7 @@ void getFirstPageDataByOrderIdShouldReturnExpectedData() { when(orderRepository.findById(orderId)).thenReturn(Optional.of(order)); when(tariffLocationRepository.findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location)) .thenReturn(Optional.of(tariffLocation)); - when(bagRepository.findBagsByTariffsInfoId(tariffsInfoId)).thenReturn(bags); + when(bagRepository.findAllActiveBagsByTariffsInfoId(tariffsInfoId)).thenReturn(bags); when(modelMapper.map(bags.get(0), BagTranslationDto.class)).thenReturn(bagTranslationDto); var userPointsAndAllBagsDtoActual = @@ -588,7 +680,7 @@ void getFirstPageDataByOrderIdShouldReturnExpectedData() { verify(userRepository).findUserByUuid(uuid); verify(orderRepository).findById(orderId); verify(tariffLocationRepository).findTariffLocationByTariffsInfoAndLocation(tariffsInfo, location); - verify(bagRepository).findBagsByTariffsInfoId(tariffsInfoId); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(tariffsInfoId); verify(modelMapper).map(bags.get(0), BagTranslationDto.class); } @@ -611,7 +703,7 @@ void getFirstPageDataByOrderIdShouldThrowExceptionWhenUserDoesNotExist() { verify(orderRepository, never()).findById(anyLong()); verify(tariffLocationRepository, never()).findTariffLocationByTariffsInfoAndLocation(any(), any()); - verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } @@ -637,7 +729,7 @@ void getFirstPageDataByOrderIdShouldThrowExceptionWhenOrderDoesNotExist() { verify(orderRepository).findById(orderId); verify(tariffLocationRepository, never()).findTariffLocationByTariffsInfoAndLocation(any(), any()); - verify(bagRepository, never()).findBagsByTariffsInfoId(anyLong()); + verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(anyLong()); verify(modelMapper, never()).map(any(), any()); } @@ -680,7 +772,7 @@ void testSaveToDB() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); - when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(3)).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); when(modelMapper.map(dto.getPersonalData(), UBSuser.class)).thenReturn(ubSuser); @@ -739,8 +831,8 @@ void testSaveToDBWithTwoBags() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); - when(bagRepository.findById(1)).thenReturn(Optional.of(bag1)); - when(bagRepository.findById(3)).thenReturn(Optional.of(bag3)); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag1)); + when(bagRepository.findActiveBagById(3)).thenReturn(Optional.of(bag3)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); when(modelMapper.map(dto.getPersonalData(), UBSuser.class)).thenReturn(ubSuser); @@ -793,7 +885,7 @@ void testSaveToDBWithCertificates() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); - when(bagRepository.findById(any())).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(any())).thenReturn(Optional.of(bag)); when(certificateRepository.findById(anyString())).thenReturn(Optional.of(getCertificate())); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); @@ -850,7 +942,7 @@ void testSaveToDBWithDontSendLinkToFondy() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); - when(bagRepository.findById(any())).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(any())).thenReturn(Optional.of(bag)); when(certificateRepository.findById(anyString())).thenReturn(Optional.of(certificate)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); @@ -901,7 +993,7 @@ void testSaveToDBWhenSumToPayLessThanPoints() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); - when(bagRepository.findById(any())).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(any())).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); when(modelMapper.map(dto.getPersonalData(), UBSuser.class)).thenReturn(ubSuser); @@ -922,17 +1014,19 @@ void testSaveToDbThrowBadRequestExceptionPriceLowerThanLimit() throws IllegalAcc OrderResponseDto dto = getOrderResponseDto(); dto.getBags().get(0).setAmount(1); + Bag bag = getBagForOrder(); Order order = getOrder(); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); + TariffsInfo tariffsInfo = getTariffInfo(); + tariffsInfo.setBags(Arrays.asList(bag)); user.setOrders(new ArrayList<>()); user.getOrders().add(order); user.setChangeOfPointsList(new ArrayList<>()); - Bag bag = getBagForOrder(); - when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(getTariffInfo())); - when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); + .thenReturn(Optional.of(tariffsInfo)); + when(bagRepository.findActiveBagById(any())).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); @@ -940,7 +1034,7 @@ void testSaveToDbThrowBadRequestExceptionPriceLowerThanLimit() throws IllegalAcc verify(userRepository, times(1)).findByUuid(anyString()); verify(tariffsInfoRepository, times(1)) .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); - verify(bagRepository, times(1)).findById(anyInt()); + verify(bagRepository, times(1)).findActiveBagById(anyInt()); } @Test @@ -960,7 +1054,7 @@ void testSaveToDbThrowBadRequestExceptionPriceGreaterThanLimit() throws IllegalA when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(getTariffInfo())); - when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(any())).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); @@ -968,7 +1062,7 @@ void testSaveToDbThrowBadRequestExceptionPriceGreaterThanLimit() throws IllegalA verify(userRepository, times(1)).findByUuid(anyString()); verify(tariffsInfoRepository, times(1)) .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); - verify(bagRepository, times(1)).findById(anyInt()); + verify(bagRepository, times(1)).findActiveBagById(anyInt()); } @Test @@ -999,10 +1093,14 @@ void testSaveToDBWShouldThrowBadRequestException() throws IllegalAccessException payment1.setId(1L); order1.getPayment().add(payment1); + bag.setTariffsInfo(tariffsInfo); + tariffsInfo.setBags(Arrays.asList(bag)); + order.setTariffsInfo(tariffsInfo); + when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); - when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(3)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); @@ -1010,7 +1108,6 @@ void testSaveToDBWShouldThrowBadRequestException() throws IllegalAccessException verify(userRepository, times(1)).findByUuid(anyString()); verify(tariffsInfoRepository, times(1)) .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); - verify(bagRepository, times(1)).findById(any()); } @Test @@ -1088,7 +1185,7 @@ void testSaveToDBWShouldThrowBagNotFoundExceptionException() throws IllegalAcces when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(getTariffInfo())); - when(bagRepository.findById(3)).thenReturn(Optional.empty()); + when(bagRepository.findActiveBagById(3)).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); @@ -1096,7 +1193,7 @@ void testSaveToDBWShouldThrowBagNotFoundExceptionException() throws IllegalAcces verify(userRepository, times(1)).findByUuid(anyString()); verify(tariffsInfoRepository, times(1)) .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); - verify(bagRepository).findById(3); + verify(bagRepository).findActiveBagById(3); } @@ -1132,7 +1229,7 @@ void testSaveToDBWithoutOrderUnpaid() throws IllegalAccessException { when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); - when(bagRepository.findById(any())).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(any())).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto.getPersonalData(), UBSuser.class)).thenReturn(ubSuser); when(orderRepository.findById(any())).thenReturn(Optional.of(order1)); @@ -1143,7 +1240,6 @@ void testSaveToDBWithoutOrderUnpaid() throws IllegalAccessException { verify(userRepository, times(1)).findByUuid("35467585763t4sfgchjfuyetf"); verify(tariffsInfoRepository, times(1)) .findTariffsInfoByBagIdAndLocationId(anyList(), anyLong()); - verify(bagRepository, times(1)).findById(any()); verify(ubsUserRepository, times(1)).findById(anyLong()); verify(modelMapper, times(1)).map(dto.getPersonalData(), UBSuser.class); verify(orderRepository, times(1)).findById(anyLong()); @@ -1169,7 +1265,7 @@ void saveToDBFailPaidOrder() { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); - when(bagRepository.findById(any())).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(any())).thenReturn(Optional.of(bag)); when(orderRepository.findById(any())).thenReturn(Optional.of(order)); assertThrows(BadRequestException.class, @@ -1214,7 +1310,7 @@ void testSaveToDBThrowsException() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); - when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(3)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); } @@ -1238,6 +1334,65 @@ void getSecondPageData() { assertEquals(expected, actual); } + @Test + void getSecondPageData_AlternativeEmailIsNull() { + String uuid = "35467585763t4sfgchjfuyetf"; + PersonalDataDto expected = getOrderResponseDto().getPersonalData(); + + User user = getTestUser() + .setUuid(uuid) + .setRecipientEmail("mail@mail.ua") + .setRecipientPhone("067894522"); + List ubsUser = Arrays.asList(getUBSuser()); + when(userRepository.findByUuid(uuid)).thenReturn(user); + when(ubsUserRepository.findUBSuserByUser(user)).thenReturn(ubsUser); + when(modelMapper.map(user, PersonalDataDto.class)).thenReturn(expected); + + PersonalDataDto actual = ubsService.getSecondPageData("35467585763t4sfgchjfuyetf"); + + assertEquals(expected, actual); + } + + @Test + void getSecondPageData_AlternativeEmailIsEmpty() { + String uuid = "35467585763t4sfgchjfuyetf"; + PersonalDataDto expected = getOrderResponseDto().getPersonalData(); + + User user = getTestUser() + .setUuid(uuid) + .setRecipientEmail("mail@mail.ua") + .setRecipientPhone("067894522") + .setAlternateEmail(""); + List ubsUser = Arrays.asList(getUBSuser()); + when(userRepository.findByUuid(uuid)).thenReturn(user); + when(ubsUserRepository.findUBSuserByUser(user)).thenReturn(ubsUser); + when(modelMapper.map(user, PersonalDataDto.class)).thenReturn(expected); + + PersonalDataDto actual = ubsService.getSecondPageData("35467585763t4sfgchjfuyetf"); + + assertEquals(expected, actual); + } + + @Test + void getSecondPageData_ubsUser_isEmpty() { + String uuid = "35467585763t4sfgchjfuyetf"; + PersonalDataDto expected = getOrderResponseDto().getPersonalData(); + + User user = getTestUser() + .setUuid(uuid) + .setRecipientEmail("mail@mail.ua") + .setRecipientPhone("067894522") + .setAlternateEmail("my@email.com"); + List ubsUser = Arrays.asList(getUBSuser()); + when(userRepository.findByUuid(uuid)).thenReturn(user); + when(ubsUserRepository.findUBSuserByUser(user)).thenReturn(Collections.emptyList()); + when(modelMapper.map(user, PersonalDataDto.class)).thenReturn(expected); + + PersonalDataDto actual = ubsService.getSecondPageData("35467585763t4sfgchjfuyetf"); + + assertEquals(expected, actual); + } + @Test void getSecondPageDataWithUserFounded() { @@ -2660,7 +2815,7 @@ void saveFullOrderToDBForIF() throws IllegalAccessException { when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); - when(bagRepository.findById(any())).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(any())).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); when(certificateRepository.findById("1111-1234")).thenReturn(Optional.of(getCertificate())); @@ -2718,7 +2873,7 @@ void saveFullOrderToDBWhenSumToPayeqNull() throws IllegalAccessException { when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); - when(bagRepository.findById(any())).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(any())).thenReturn(Optional.of(bag)); when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(addressRepository.findById(any())).thenReturn(Optional.of(address)); @@ -2767,7 +2922,7 @@ void testSaveToDBfromIForIFThrowsException() throws IllegalAccessException { when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(getTariffInfoWithLimitOfBags())); - when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(3)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, () -> { ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null); }); @@ -2809,7 +2964,7 @@ void testCheckSumIfCourierLimitBySumOfOrderForIF1() throws IllegalAccessExceptio when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); - when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(3)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, () -> { ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null); @@ -2852,7 +3007,7 @@ void testCheckSumIfCourierLimitBySumOfOrderForIF2() throws InvocationTargetExcep when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); - when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(3)).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, () -> { ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null); @@ -3304,7 +3459,7 @@ void checkIfAddressHasBeenDeletedTest() throws IllegalAccessException { user.setOrders(new ArrayList<>()); user.getOrders().add(order); user.setChangeOfPointsList(new ArrayList<>()); - + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); Bag bag = getBagForOrder(); UBSuser ubSuser = getUBSuser(); @@ -3323,12 +3478,11 @@ void checkIfAddressHasBeenDeletedTest() throws IllegalAccessException { bag.setTariffsInfo(tariffsInfo); tariffsInfo.setBags(Arrays.asList(bag)); order.setTariffsInfo(tariffsInfo); -// when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); + when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); - when(bagRepository.findById(any())).thenReturn(Optional.of(bag)); - when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(any())).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); when(modelMapper.map(dto.getPersonalData(), UBSuser.class)).thenReturn(ubSuser); @@ -3376,7 +3530,7 @@ void checkAddressUserTest() throws IllegalAccessException { when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); - when(bagRepository.findById(any())).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(any())).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser)); when(modelMapper.map(dto, Order.class)).thenReturn(order); when(modelMapper.map(dto.getPersonalData(), UBSuser.class)).thenReturn(ubSuser); @@ -3417,8 +3571,7 @@ void checkIfUserHaveEnoughPointsTest() throws IllegalAccessException { when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user); - when(bagRepository.findById(any())).thenReturn(Optional.of(bag)); - when(bagRepository.findById(3)).thenReturn(Optional.of(bag)); + when(bagRepository.findActiveBagById(any())).thenReturn(Optional.of(bag)); assertThrows(BadRequestException.class, () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); diff --git a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java index 5f16cde7b..36d92c882 100644 --- a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java @@ -408,7 +408,6 @@ void checkUpdateManualPayment() { when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(paymentRepository.findById(1L)).thenReturn(Optional.of(getManualPayment())); when(paymentRepository.save(any())).thenReturn(getManualPayment()); -// when(orderBagService.findBagsByOrderId(order.getId())).thenReturn(getBaglist()); doNothing().when(eventService).save(OrderHistory.UPDATE_PAYMENT_MANUALLY + 1, employee.getFirstName() + " " + employee.getLastName(), getOrder()); @@ -417,7 +416,6 @@ void checkUpdateManualPayment() { verify(paymentRepository, times(1)).save(any()); verify(eventService, times(2)).save(any(), any(), any()); verify(fileService, times(0)).delete(null); -// verify(orderBagService).findBagsByOrderId(order.getId()); } @Test @@ -1140,7 +1138,7 @@ void testSetOrderDetail() { doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); - when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); +// when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); when(paymentRepository.selectSumPaid(1L)).thenReturn(5000L); ubsManagementService.setOrderDetail(1L, @@ -1182,7 +1180,7 @@ void testSetOrderDetailNeedToChangeStatusToUNPAID() { doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); - when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); +// when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); when(paymentRepository.selectSumPaid(1L)).thenReturn(null); doNothing().when(orderRepository).updateOrderPaymentStatus(1L, OrderPaymentStatus.UNPAID.name()); when(orderBagService.findAllBagsInOrderBagsList(anyList())).thenReturn(ModelUtils.TEST_BAG_LIST2); @@ -1203,7 +1201,7 @@ void testSetOrderDetailWhenSumPaidIsNull() { doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); - when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); +// when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); when(paymentRepository.selectSumPaid(1L)).thenReturn(null); ubsManagementService.setOrderDetail(1L, @@ -1281,8 +1279,7 @@ void testSetOrderDetailIfPaidAndPriceLessThanPaidSum() { when(orderRepository.findSumOfCertificatesByOrderId(order.getId())).thenReturn(600L); when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusFormedDto2())); -// when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); - when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); +// when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(order.getId(), UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), @@ -1296,12 +1293,9 @@ void testSetOrderDetailIfPaidAndPriceLessThanPaidSum() { @Test void testSetOrderDetailConfirmed() { when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusConfirmedDto())); - when(bagRepository.findCapacityById(1)).thenReturn(1); doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); - when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); - when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(1L, UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), @@ -1317,19 +1311,17 @@ void testSetOrderDetailConfirmed2() { when(bagRepository.findCapacityById(1)).thenReturn(1); when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); - when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); when(orderDetailRepository.ifRecordExist(any(), any())).thenReturn(1L); - when(orderDetailRepository.getAmount(any(), any())).thenReturn(1L); + ubsManagementService.setOrderDetail(1L, UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "test@gmail.com"); + verify(orderRepository, times(2)).findById(1L); verify(bagRepository, times(2)).findCapacityById(1); - verify(bagRepository, times(2)).findById(1); - verify(orderDetailRepository, times(2)).ifRecordExist(any(), any()); + verify(bagRepository, times(2)).findActiveBagById(1); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); - verify(orderDetailRepository).getAmount(any(), any()); verify(orderDetailRepository, times(0)).updateExporter(anyInt(), anyLong(), anyLong()); } @@ -1341,16 +1333,17 @@ void testSetOrderDetailWithExportedWaste() { doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); - when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); when(orderDetailRepository.ifRecordExist(any(), any())).thenReturn(1L); + ubsManagementService.setOrderDetail(1L, UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), "test@gmail.com"); + verify(orderRepository, times(2)).findById(1L); verify(bagRepository, times(2)).findCapacityById(1); - verify(bagRepository, times(2)).findById(1); - verify(orderDetailRepository, times(3)).ifRecordExist(any(), any()); + verify(bagRepository, times(2)).findActiveBagById(1); + verify(orderDetailRepository, times(2)).ifRecordExist(any(), any()); verify(orderDetailRepository).updateExporter(anyInt(), anyLong(), anyLong()); verify(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); } @@ -1362,7 +1355,6 @@ void testSetOrderDetailFormed() { doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); - when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(1L, UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), @@ -1376,7 +1368,7 @@ void testSetOrderDetailFormedWithBagNoPresent() { when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); when(bagRepository.findCapacityById(1)).thenReturn(1); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); - when(bagRepository.findById(1)).thenReturn(Optional.empty()); +// when(bagRepository.findActiveBagById(1)).thenReturn(Optional.empty()); ubsManagementService.setOrderDetail(1L, UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), @@ -1395,8 +1387,6 @@ void testSetOrderDetailNotTakenOut() { doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); - when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); - when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(1L, UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), @@ -1414,7 +1404,6 @@ void testSetOrderDetailOnTheRoute() { doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); - when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(1L, UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), @@ -1433,7 +1422,7 @@ void testSetOrderDetailsDone() { doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); - when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); + ubsManagementService.setOrderDetail(1L, UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), @@ -1451,7 +1440,6 @@ void testSetOrderBroughtItHimself() { doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); - when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(1L, UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsExported(), @@ -1469,7 +1457,6 @@ void testSetOrderDetailsCanseled() { doNothing().when(orderDetailRepository).updateConfirm(anyInt(), anyLong(), anyLong()); when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); - when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.setOrderDetail(1L, UPDATE_ORDER_PAGE_ADMIN_DTO.getOrderDetailDto().getAmountOfBagsConfirmed(), @@ -1609,7 +1596,6 @@ void updateOrderAdminPageInfoTest() { when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); - when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.updateOrderAdminPageInfo(updateOrderPageAdminDto, 1L, "en", "test@gmail.com"); UpdateOrderPageAdminDto emptyDto = new UpdateOrderPageAdminDto(); @@ -1649,7 +1635,6 @@ void updateOrderAdminPageInfoWithUbsCourierSumAndWriteOffStationSum() { when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); when(orderRepository.getOrderDetails(anyLong())) .thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); - when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag())); ubsManagementService.updateOrderAdminPageInfo(updateOrderPageAdminDto, 1L, "en", "test@gmail.com"); UpdateOrderPageAdminDto emptyDto = new UpdateOrderPageAdminDto(); @@ -1942,7 +1927,6 @@ void getOrderSumDetailsForFormedHalfPaidOrder() { Order order = ModelUtils.getFormedHalfPaidOrder(); order.setOrderDate(LocalDateTime.now()); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); -// when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); doNothing().when(notificationService).notifyPaidOrder(order); doNothing().when(notificationService).notifyHalfPaidPackage(order); @@ -1957,7 +1941,6 @@ void getOrderSumDetailsForFormedHalfPaidOrderWithDiffBags() { Order order = ModelUtils.getFormedHalfPaidOrder(); order.setOrderDate(LocalDateTime.now()); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); -// when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag3list()); doNothing().when(notificationService).notifyPaidOrder(order); doNothing().when(notificationService).notifyHalfPaidPackage(order); @@ -1997,7 +1980,7 @@ void getOrderStatusDataTest() { when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); + when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(1L)).thenReturn(getCertificateList()); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); @@ -2014,7 +1997,7 @@ void getOrderStatusDataTest() { ubsManagementService.getOrderStatusData(1L, "test@gmail.com"); - verify(bagRepository).findBagsByTariffsInfoId(1L); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); verify(certificateRepository).findCertificate(1L); verify(orderRepository, times(5)).findById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); @@ -2071,8 +2054,7 @@ void getOrderStatusDataTestEmptyPriceDetails() { .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); -// when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBag2list()); + when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.empty()); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); when(orderStatusTranslationRepository.getOrderStatusTranslationById(6L)) @@ -2088,8 +2070,7 @@ void getOrderStatusDataTestEmptyPriceDetails() { ubsManagementService.getOrderStatusData(1L, "test@gmail.com"); verify(orderRepository).getOrderDetails(1L); -// verify(orderBagService).findBagsByOrderId(1L); - verify(bagRepository).findBagsByTariffsInfoId(1L); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); verify(certificateRepository).findCertificate(1L); verify(orderRepository, times(5)).findById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); @@ -2113,8 +2094,7 @@ void getOrderStatusDataWithEmptyCertificateTest() { when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); -// when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); + when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); @@ -2129,8 +2109,7 @@ void getOrderStatusDataWithEmptyCertificateTest() { ubsManagementService.getOrderStatusData(1L, "test@gmail.com"); verify(orderRepository).getOrderDetails(1L); -// verify(orderBagService).findBagsByOrderId(1L); - verify(bagRepository).findBagsByTariffsInfoId(1L); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); verify(orderRepository, times(5)).findById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); verify(modelMapper).map(getBaglist().get(0), BagInfoDto.class); @@ -2152,8 +2131,7 @@ void getOrderStatusDataWhenOrderTranslationIsNull() { when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); -// when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); + when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); @@ -2166,8 +2144,7 @@ void getOrderStatusDataWhenOrderTranslationIsNull() { ubsManagementService.getOrderStatusData(1L, "test@gmail.com"); verify(orderRepository).getOrderDetails(1L); -// verify(orderBagService).findBagsByOrderId(1L); - verify(bagRepository).findBagsByTariffsInfoId(1L); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); verify(orderRepository, times(5)).findById(1L); verify(serviceRepository).findServiceByTariffsInfoId(1L); verify(modelMapper).map(getBaglist().get(0), BagInfoDto.class); @@ -2189,7 +2166,6 @@ void getOrderStatusDataExceptionTest() { when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); -// when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(1L)).thenReturn(getCertificateList()); when(serviceRepository.findServiceByTariffsInfoId(1L)).thenReturn(Optional.of(getService())); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); @@ -2465,8 +2441,7 @@ void getOrderStatusDataWithNotEmptyLists() { when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); -// when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); + when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(1L)).thenReturn(getCertificateList()); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); @@ -2484,7 +2459,7 @@ void getOrderStatusDataWithNotEmptyLists() { ubsManagementService.getOrderStatusData(1L, "test@gmail.com"); verify(orderRepository).getOrderDetails(1L); - verify(bagRepository).findBagsByTariffsInfoId(1L); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); verify(certificateRepository).findCertificate(1L); verify(orderRepository, times(5)).findById(1L); verify(modelMapper).map(getBaglist().get(0), BagInfoDto.class); @@ -2510,7 +2485,7 @@ void getOrderStatusesTranslationTest() { when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(anyLong(), anyLong())) .thenReturn(Optional.of(tariffsInfo)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); - when(bagRepository.findBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); + when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(1L)).thenReturn(getCertificateList()); when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(getOrderForGetOrderStatusData2Test())); when(modelMapper.map(getBaglist().get(0), BagInfoDto.class)).thenReturn(bagInfoDto); @@ -2533,7 +2508,7 @@ void getOrderStatusesTranslationTest() { ubsManagementService.getOrderStatusData(1L, "test@gmail.com"); verify(orderRepository).getOrderDetails(1L); - verify(bagRepository).findBagsByTariffsInfoId(1L); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); verify(certificateRepository).findCertificate(1L); verify(orderRepository, times(5)).findById(1L); verify(modelMapper).map(getBaglist().get(0), BagInfoDto.class); From ca5ea7a8940078ba4360bc181499b1b39108047c Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Fri, 28 Jul 2023 14:26:07 +0300 Subject: [PATCH 38/73] Added tests --- .../java/greencity/enums/BagStatusTest.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 dao/src/test/java/greencity/enums/BagStatusTest.java diff --git a/dao/src/test/java/greencity/enums/BagStatusTest.java b/dao/src/test/java/greencity/enums/BagStatusTest.java new file mode 100644 index 000000000..f3e36f591 --- /dev/null +++ b/dao/src/test/java/greencity/enums/BagStatusTest.java @@ -0,0 +1,32 @@ +package greencity.enums; + +import greencity.entity.order.Bag; +import org.junit.jupiter.api.Test; +import java.time.LocalDate; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class BagStatusTest { + private static Bag getBag(BagStatus status) { + return Bag.builder() + .status(status) + .id(1) + .capacity(120) + .commission(50_00L) + .price(120_00L) + .fullPrice(170_00L) + .createdAt(LocalDate.now()) + .limitIncluded(true) + .build(); + } + + @Test + void testGetStatus() { + assertEquals(BagStatus.ACTIVE, getBag(BagStatus.ACTIVE).getStatus()); + } + + @Test + void testSetStatus() { + assertEquals(BagStatus.DELETED, getBag(BagStatus.DELETED).getStatus()); + } +} \ No newline at end of file From 9f0d9b425903ec7a1fc8a55b871c47d2c1505772 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Fri, 28 Jul 2023 14:28:10 +0300 Subject: [PATCH 39/73] Removed bug --- .../main/java/greencity/service/ubs/SuperAdminServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java index 73b906cc4..79b50d7e2 100644 --- a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java @@ -171,7 +171,7 @@ private void deleteBagFromOrder(Order order, Bag bag) { Map amount = orderBagService.getActualBagsAmountForOrder(order.getOrderBags()); Integer totalBagsAmount = amount.values().stream().reduce(0, Integer::sum); if (amount.get(bagId).equals(0) || order.getOrderPaymentStatus().equals(OrderPaymentStatus.UNPAID)) { - if (totalBagsAmount.equals(amount.get(bagId)) || bag.getLimitIncluded()) { + if (totalBagsAmount.equals(amount.get(bagId))) { order.setOrderBags(new ArrayList<>()); orderRepository.delete(order); return; From 700b4095a70ed22ba93ca77af36f0b165e5575f2 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Fri, 28 Jul 2023 14:34:14 +0300 Subject: [PATCH 40/73] Added new tests --- .../ubs/SuperAdminServiceImplTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index ff4c33214..01af9c53d 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -246,6 +246,31 @@ void getTariffServiceIfTariffNotFoundException() { verify(bagRepository, never()).findAllActiveBagsByTariffsInfoId(1L); } + @Test + void deleteTariffServiceWhenThereAreMoreThan1TypeOfBag() { + Bag bag = ModelUtils.getBag(); + Bag bagDeleted = ModelUtils.getBagDeleted(); + TariffsInfo tariffsInfo = ModelUtils.getTariffInfo(); + Order order = ModelUtils.getOrder(); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag(), ModelUtils.getOrderBag2())); + when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); + when(bagRepository.save(bag)).thenReturn(bagDeleted); + when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(List.of(bag, getBag2())); + when(orderRepository.findAllByBagId(bag.getId())).thenReturn(Arrays.asList(order)); + when(orderBagService + .getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag(), ModelUtils.getOrderBag2()))) + .thenReturn(ModelUtils.getAmount()); + when(orderBagRepository.findOrderBagsByBagId(any())).thenReturn(Collections.singletonList(getOrderBag())); + + superAdminService.deleteTariffService(1); + + verify(orderBagRepository).deleteOrderBagByBagIdAndOrderId(any(), any()); + verify(bagRepository).findActiveBagById(1); + verify(bagRepository).save(bag); + verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); + verify(tariffsInfoRepository, never()).save(tariffsInfo); + } + @Test void deleteTariffServiceWhenTariffBagsWithLimits() { Bag bag = ModelUtils.getBag(); From 77ad51507c24dbed889078d043dd2130801ef81d Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Fri, 28 Jul 2023 14:36:54 +0300 Subject: [PATCH 41/73] Deleted unused method --- .../java/greencity/service/ubs/OrderBagService.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/service/src/main/java/greencity/service/ubs/OrderBagService.java b/service/src/main/java/greencity/service/ubs/OrderBagService.java index 6e10f71b3..28ad8150f 100644 --- a/service/src/main/java/greencity/service/ubs/OrderBagService.java +++ b/service/src/main/java/greencity/service/ubs/OrderBagService.java @@ -93,16 +93,4 @@ public Map getActualBagsAmountForOrder(List bagsForO } return new HashMap<>(); } - - /** - * method helps to delete bag from order. - * - * @param orderBag {@link OrderBag} - * @author Oksana Spodaryk - */ - public void removeBagFromOrder(Order order, OrderBag orderBag) { - List modifiableList = new ArrayList<>(order.getOrderBags()); - modifiableList.remove(orderBag); - order.setOrderBags(modifiableList); - } } From b9143eb4294454cad19ae8fe8473646099cfe956 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Fri, 28 Jul 2023 14:41:36 +0300 Subject: [PATCH 42/73] Fixed tests --- .../java/greencity/service/ubs/SuperAdminServiceImplTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index 01af9c53d..656cd42df 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -288,6 +288,7 @@ void deleteTariffServiceWhenTariffBagsWithLimits() { superAdminService.deleteTariffService(1); + verify(orderBagRepository).deleteOrderBagByBagIdAndOrderId(any(), any()); verify(bagRepository).findActiveBagById(1); verify(bagRepository).save(bag); verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); From 49a1aa3d5b7abe677d00cdae4ac648e92f6dfee4 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Fri, 28 Jul 2023 14:48:41 +0300 Subject: [PATCH 43/73] Removed code smell --- .../src/main/java/greencity/service/ubs/OrderBagService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/service/src/main/java/greencity/service/ubs/OrderBagService.java b/service/src/main/java/greencity/service/ubs/OrderBagService.java index 28ad8150f..bd0a8d94d 100644 --- a/service/src/main/java/greencity/service/ubs/OrderBagService.java +++ b/service/src/main/java/greencity/service/ubs/OrderBagService.java @@ -1,7 +1,6 @@ package greencity.service.ubs; import greencity.entity.order.Bag; -import greencity.entity.order.Order; import greencity.entity.order.OrderBag; import greencity.exceptions.NotFoundException; import greencity.repository.OrderBagRepository; @@ -10,7 +9,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; From a8196ad6b100c378ac0f8fb76467c6458cbc83d3 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Fri, 28 Jul 2023 14:54:48 +0300 Subject: [PATCH 44/73] Added tests to cover superAdminService.deleteTariffService() --- .../greencity/service/ubs/SuperAdminServiceImplTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index 656cd42df..07a7f2a45 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -278,17 +278,19 @@ void deleteTariffServiceWhenTariffBagsWithLimits() { TariffsInfo tariffsInfo = ModelUtils.getTariffInfo(); Order order = ModelUtils.getOrder(); order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); + Map hashMap = new HashMap<>(); + hashMap.put(1, 1); when(bagRepository.findActiveBagById(1)).thenReturn(Optional.of(bag)); when(bagRepository.save(bag)).thenReturn(bagDeleted); when(bagRepository.findAllActiveBagsByTariffsInfoId(1L)).thenReturn(List.of(bag)); when(orderRepository.findAllByBagId(bag.getId())).thenReturn(Arrays.asList(order)); when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))) - .thenReturn(ModelUtils.getAmount()); + .thenReturn(hashMap); when(orderBagRepository.findOrderBagsByBagId(any())).thenReturn(Collections.singletonList(getOrderBag())); superAdminService.deleteTariffService(1); - verify(orderBagRepository).deleteOrderBagByBagIdAndOrderId(any(), any()); + verify(orderBagRepository).findOrderBagsByBagId(any()); verify(bagRepository).findActiveBagById(1); verify(bagRepository).save(bag); verify(bagRepository).findAllActiveBagsByTariffsInfoId(1L); From 53887d432c734493f1455aa5ca41482d26ae54de Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Fri, 28 Jul 2023 15:53:47 +0300 Subject: [PATCH 45/73] Added new tests to cover all lines --- .../service/ubs/UBSClientServiceImplTest.java | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java index b207db18e..7998958b6 100644 --- a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java @@ -784,6 +784,116 @@ void testSaveToDB() throws IllegalAccessException { } + @Test + void testSaveToDB_AddressNotEqualsUsers() throws IllegalAccessException { + User user = getUserWithLastLocation(); + user.setAlternateEmail("test@mail.com"); + user.setCurrentPoints(900); + + OrderResponseDto dto = getOrderResponseDto(); + dto.getBags().get(0).setAmount(15); + dto.setAddressId(1L); + dto.setLocationId(1L); + Order order = getOrder(); + user.setOrders(new ArrayList<>()); + user.getOrders().add(order); + user.setChangeOfPointsList(new ArrayList<>()); + + Bag bag = getBagForOrder(); + TariffsInfo tariffsInfo = getTariffInfo(); + + UBSuser ubSuser = getUBSuser(); + + OrderAddress orderAddress = ubSuser.getOrderAddress(); + orderAddress.setAddressStatus(AddressStatus.NEW); + + Order order1 = getOrder(); + order1.setPayment(new ArrayList<>()); + Payment payment1 = getPayment(); + payment1.setId(1L); + order1.getPayment().add(payment1); + + Field[] fields = UBSClientServiceImpl.class.getDeclaredFields(); + for (Field f : fields) { + if (f.getName().equals("merchantId")) { + f.setAccessible(true); + f.set(ubsService, "1"); + } + } + tariffsInfo.setBags(Arrays.asList(bag)); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); + when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user.setId(null), user); + when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) + .thenReturn(Optional.of(tariffsInfo)); + when(bagRepository.findActiveBagById(3)).thenReturn(Optional.of(bag)); + when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser.setId(null))); + when(modelMapper.map(dto, Order.class)).thenReturn(order); + when(modelMapper.map(dto.getPersonalData(), UBSuser.class)).thenReturn(ubSuser.setId(null)); + when(addressRepository.findById(any())).thenReturn(Optional.of(getAddress().setUser(getTestUser()))); + when(locationRepository.findById(any())).thenReturn(Optional.of(getLocation())); + + assertThrows(NotFoundException.class, + () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); + + } + + @Test + void testSaveToDB_AddressStatusDeleted() throws IllegalAccessException { + User user = getUserWithLastLocation(); + user.setAlternateEmail("test@mail.com"); + user.setCurrentPoints(900); + + OrderResponseDto dto = getOrderResponseDto(); + dto.getBags().get(0).setAmount(15); + dto.setAddressId(1L); + dto.setLocationId(1L); + Order order = getOrder(); + user.setOrders(new ArrayList<>()); + user.getOrders().add(order); + user.setChangeOfPointsList(new ArrayList<>()); + + Bag bag = getBagForOrder(); + TariffsInfo tariffsInfo = getTariffInfo(); + + UBSuser ubSuser = getUBSuser(); + + OrderAddress orderAddress = ubSuser.getOrderAddress(); + orderAddress.setAddressStatus(AddressStatus.NEW); + + Order order1 = getOrder(); + order1.setPayment(new ArrayList<>()); + Payment payment1 = getPayment(); + payment1.setId(1L); + order1.getPayment().add(payment1); + + Field[] fields = UBSClientServiceImpl.class.getDeclaredFields(); + for (Field f : fields) { + if (f.getName().equals("merchantId")) { + f.setAccessible(true); + f.set(ubsService, "1"); + } + } + tariffsInfo.setBags(Arrays.asList(bag)); + order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); + when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user.setId(null), user); + when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) + .thenReturn(Optional.of(tariffsInfo)); + when(bagRepository.findActiveBagById(3)).thenReturn(Optional.of(bag)); + when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser.setId(null))); + when(modelMapper.map(dto, Order.class)).thenReturn(order); + when(modelMapper.map(dto.getPersonalData(), UBSuser.class)).thenReturn(ubSuser.setId(null)); + when(orderRepository.findById(any())).thenReturn(Optional.of(order1)); + when(encryptionUtil.formRequestSignature(any(), eq(null), eq("1"))).thenReturn("TestValue"); + when(fondyClient.getCheckoutResponse(any())).thenReturn(getSuccessfulFondyResponse()); + when(fondyClient.getCheckoutResponse(any())).thenReturn(getSuccessfulFondyResponse()); + when(addressRepository.findById(any())) + .thenReturn(Optional.of(getAddress().setAddressStatus(AddressStatus.DELETED))); + when(locationRepository.findById(any())).thenReturn(Optional.of(getLocation())); + assertThrows(NotFoundException.class, + () -> ubsService.saveFullOrderToDB(dto, "35467585763t4sfgchjfuyetf", null)); + + } + @Test void testSaveToDBWithTwoBags() throws IllegalAccessException { User user = getUserWithLastLocation(); From 86eaa6b8e4d6e9b60fb6164e13221bb4bc36b586 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Fri, 28 Jul 2023 16:00:37 +0300 Subject: [PATCH 46/73] fixed tests --- .../greencity/service/ubs/UBSClientServiceImplTest.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java index 7998958b6..9b7512cb8 100644 --- a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java @@ -877,15 +877,11 @@ void testSaveToDB_AddressStatusDeleted() throws IllegalAccessException { order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user.setId(null), user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findActiveBagById(3)).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser.setId(null))); when(modelMapper.map(dto, Order.class)).thenReturn(order); when(modelMapper.map(dto.getPersonalData(), UBSuser.class)).thenReturn(ubSuser.setId(null)); - when(orderRepository.findById(any())).thenReturn(Optional.of(order1)); - when(encryptionUtil.formRequestSignature(any(), eq(null), eq("1"))).thenReturn("TestValue"); - when(fondyClient.getCheckoutResponse(any())).thenReturn(getSuccessfulFondyResponse()); - when(fondyClient.getCheckoutResponse(any())).thenReturn(getSuccessfulFondyResponse()); when(addressRepository.findById(any())) .thenReturn(Optional.of(getAddress().setAddressStatus(AddressStatus.DELETED))); when(locationRepository.findById(any())).thenReturn(Optional.of(getLocation())); From 60daad82f065b4b720f7c5918ddf6da0838c1081 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Fri, 28 Jul 2023 16:04:22 +0300 Subject: [PATCH 47/73] formatted --- .../java/greencity/service/ubs/UBSClientServiceImplTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java index 9b7512cb8..eaf9b957a 100644 --- a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java @@ -877,7 +877,7 @@ void testSaveToDB_AddressStatusDeleted() throws IllegalAccessException { order.setOrderBags(Arrays.asList(ModelUtils.getOrderBag())); when(userRepository.findByUuid("35467585763t4sfgchjfuyetf")).thenReturn(user.setId(null), user); when(tariffsInfoRepository.findTariffsInfoByBagIdAndLocationId(anyList(), anyLong())) - .thenReturn(Optional.of(tariffsInfo)); + .thenReturn(Optional.of(tariffsInfo)); when(bagRepository.findActiveBagById(3)).thenReturn(Optional.of(bag)); when(ubsUserRepository.findById(1L)).thenReturn(Optional.of(ubSuser.setId(null))); when(modelMapper.map(dto, Order.class)).thenReturn(order); From 5f6f7f5475b79cbb33be7674da5e64a24b8211ef Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 09:42:03 +0300 Subject: [PATCH 48/73] Fixed code:renamed methods --- ...dd-column-status-to-bag-table-Spodaryk.xml | 8 ++++- ...pdate-order-bag-mapping-table-Spodaryk.xml | 4 +-- .../java/greencity/enums/BagStatusTest.java | 32 ------------------- .../notification/NotificationServiceImpl.java | 2 +- .../service/ubs/OrderBagService.java | 24 ++++++-------- .../service/ubs/UBSManagementServiceImpl.java | 2 +- .../NotificationServiceImplTest.java | 12 +++---- .../service/ubs/OrderBagServiceTest.java | 4 +-- .../ubs/UBSManagementServiceImplTest.java | 6 ++-- 9 files changed, 32 insertions(+), 62 deletions(-) delete mode 100644 dao/src/test/java/greencity/enums/BagStatusTest.java diff --git a/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-table-Spodaryk.xml b/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-table-Spodaryk.xml index 9496bacb0..c280afaf2 100644 --- a/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-table-Spodaryk.xml +++ b/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-table-Spodaryk.xml @@ -2,11 +2,17 @@ + + + + + - \ No newline at end of file + + diff --git a/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml b/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml index 18f8b49d5..e1725d657 100644 --- a/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml +++ b/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd"> - + @@ -33,7 +33,7 @@ - + diff --git a/dao/src/test/java/greencity/enums/BagStatusTest.java b/dao/src/test/java/greencity/enums/BagStatusTest.java deleted file mode 100644 index f3e36f591..000000000 --- a/dao/src/test/java/greencity/enums/BagStatusTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package greencity.enums; - -import greencity.entity.order.Bag; -import org.junit.jupiter.api.Test; -import java.time.LocalDate; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class BagStatusTest { - private static Bag getBag(BagStatus status) { - return Bag.builder() - .status(status) - .id(1) - .capacity(120) - .commission(50_00L) - .price(120_00L) - .fullPrice(170_00L) - .createdAt(LocalDate.now()) - .limitIncluded(true) - .build(); - } - - @Test - void testGetStatus() { - assertEquals(BagStatus.ACTIVE, getBag(BagStatus.ACTIVE).getStatus()); - } - - @Test - void testSetStatus() { - assertEquals(BagStatus.DELETED, getBag(BagStatus.DELETED).getStatus()); - } -} \ No newline at end of file diff --git a/service/src/main/java/greencity/service/notification/NotificationServiceImpl.java b/service/src/main/java/greencity/service/notification/NotificationServiceImpl.java index e123ce2d3..8f0cb757f 100644 --- a/service/src/main/java/greencity/service/notification/NotificationServiceImpl.java +++ b/service/src/main/java/greencity/service/notification/NotificationServiceImpl.java @@ -242,7 +242,7 @@ private Double getAmountToPay(Order order) { long ubsCourierSumInCoins = order.getUbsCourierSum() == null ? 0L : order.getUbsCourierSum(); long writeStationSumInCoins = order.getWriteOffStationSum() == null ? 0L : order.getWriteOffStationSum(); - List bagsType = orderBagService.findBagsByOrderId(order.getId()); + List bagsType = orderBagService.findAllBagsByOrderId(order.getId()); Map bagsAmount; if (MapUtils.isNotEmpty(order.getExportedQuantity())) { bagsAmount = order.getExportedQuantity(); diff --git a/service/src/main/java/greencity/service/ubs/OrderBagService.java b/service/src/main/java/greencity/service/ubs/OrderBagService.java index bd0a8d94d..74f124d0d 100644 --- a/service/src/main/java/greencity/service/ubs/OrderBagService.java +++ b/service/src/main/java/greencity/service/ubs/OrderBagService.java @@ -4,9 +4,7 @@ import greencity.entity.order.OrderBag; import greencity.exceptions.NotFoundException; import greencity.repository.OrderBagRepository; -import lombok.AllArgsConstructor; import lombok.Data; -import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.util.HashMap; @@ -17,13 +15,11 @@ import static greencity.constant.ErrorMessage.BAG_NOT_FOUND; @Service -@AllArgsConstructor -@Slf4j @Data -public class OrderBagService { +public final class OrderBagService { private OrderBagRepository orderBagRepository; - private Long getActualPrice(List orderBags, Integer id) { + private Long getBagPrice(List orderBags, Integer id) { return orderBags.stream() .filter(ob -> ob.getBag().getId().equals(id)) .map(OrderBag::getPrice) @@ -41,7 +37,7 @@ private Long getActualPrice(List orderBags, Integer id) { public List findAllBagsInOrderBagsList(List orderBags) { return orderBags.stream() .map(OrderBag::getBag) - .peek(b -> b.setFullPrice(getActualPrice(orderBags, b.getId()))) + .peek(b -> b.setFullPrice(getBagPrice(orderBags, b.getId()))) .collect(Collectors.toList()); } @@ -51,7 +47,7 @@ public List findAllBagsInOrderBagsList(List orderBags) { * @param id The ID of the OrderBag to search for. * @return A list of Bag instances associated with the provided OrderBag ID. */ - public List findBagsByOrderId(Long id) { + public List findAllBagsByOrderId(Long id) { List orderBags = orderBagRepository.findOrderBagsByOrderId(id); return findAllBagsInOrderBagsList(orderBags); } @@ -77,17 +73,17 @@ public List findBagsByOrderId(Long id) { * @throws NullPointerException if 'bagsForOrder' is null. */ public Map getActualBagsAmountForOrder(List bagsForOrder) { - if (bagsForOrder.stream().allMatch(it -> it.getExportedQuantity() != null)) { + if (bagsForOrder.stream().allMatch(orderBag -> orderBag.getExportedQuantity() != null)) { return bagsForOrder.stream() - .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getExportedQuantity)); + .collect(Collectors.toMap(orderBag -> orderBag.getBag().getId(), OrderBag::getExportedQuantity)); } - if (bagsForOrder.stream().allMatch(it -> it.getConfirmedQuantity() != null)) { + if (bagsForOrder.stream().allMatch(orderBag -> orderBag.getConfirmedQuantity() != null)) { return bagsForOrder.stream() - .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getConfirmedQuantity)); + .collect(Collectors.toMap(orderBag -> orderBag.getBag().getId(), OrderBag::getConfirmedQuantity)); } - if (bagsForOrder.stream().allMatch(it -> it.getAmount() != null)) { + if (bagsForOrder.stream().allMatch(orderBag -> orderBag.getAmount() != null)) { return bagsForOrder.stream() - .collect(Collectors.toMap(it -> it.getBag().getId(), OrderBag::getAmount)); + .collect(Collectors.toMap(orderBag -> orderBag.getBag().getId(), OrderBag::getAmount)); } return new HashMap<>(); } diff --git a/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java index 92debfe0e..4fb38c1c7 100644 --- a/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java @@ -1064,7 +1064,7 @@ private void setOrderDetailDto(OrderDetailDto dto, Order order) { dto.setAmount(modelMapper.map(order, new TypeToken>() { }.getType())); - dto.setCapacityAndPrice(orderBagService.findBagsByOrderId(order.getId()) + dto.setCapacityAndPrice(orderBagService.findAllBagsByOrderId(order.getId()) .stream() .map(b -> modelMapper.map(b, BagInfoDto.class)) .collect(Collectors.toList())); diff --git a/service/src/test/java/greencity/service/notification/NotificationServiceImplTest.java b/service/src/test/java/greencity/service/notification/NotificationServiceImplTest.java index 440f8e824..83f4ab80b 100644 --- a/service/src/test/java/greencity/service/notification/NotificationServiceImplTest.java +++ b/service/src/test/java/greencity/service/notification/NotificationServiceImplTest.java @@ -412,7 +412,7 @@ void testNotifyAllHalfPaidPackages() { parameters.add(NotificationParameter.builder().key("orderNumber") .value(orders.get(0).getId().toString()).build()); - when(orderBagService.findBagsByOrderId(any())).thenReturn(getBag1list()); + when(orderBagService.findAllBagsByOrderId(any())).thenReturn(getBag1list()); when(userNotificationRepository.save(any())).thenReturn(notification); when(notificationParameterRepository.saveAll(any())).thenReturn(new ArrayList<>(parameters)); @@ -513,7 +513,7 @@ void testNotifyUnpaidOrderForBroughtByHimself() { when(userNotificationRepository.save(any())).thenReturn(notification); when(notificationParameterRepository.saveAll(any())).thenReturn(new ArrayList<>(parameters)); - when(orderBagService.findBagsByOrderId(any())).thenReturn(getBag4list()); + when(orderBagService.findAllBagsByOrderId(any())).thenReturn(getBag4list()); notificationService.notifyUnpaidOrder(order); @@ -544,7 +544,7 @@ void testNotifyUnpaidOrderForDone() { when(userNotificationRepository.save(any())).thenReturn(notification); when(notificationParameterRepository.saveAll(any())).thenReturn(new ArrayList<>(parameters)); - when(orderBagService.findBagsByOrderId(any())).thenReturn(getBag4list()); + when(orderBagService.findAllBagsByOrderId(any())).thenReturn(getBag4list()); notificationService.notifyUnpaidOrder(order); verify(userNotificationRepository).save(any()); @@ -575,7 +575,7 @@ void testNotifyUnpaidOrderForCancel() { when(userNotificationRepository.save(any())).thenReturn(notification); when(notificationParameterRepository.saveAll(any())).thenReturn(new ArrayList<>(parameters)); - when(orderBagService.findBagsByOrderId(any())).thenReturn(getBag4list()); + when(orderBagService.findAllBagsByOrderId(any())).thenReturn(getBag4list()); notificationService.notifyUnpaidOrder(order); @@ -606,7 +606,7 @@ void testNotifyHalfPaidOrderForDone() { when(userNotificationRepository.save(any())).thenReturn(notification); when(notificationParameterRepository.saveAll(any())).thenReturn(new ArrayList<>(parameters)); - when(orderBagService.findBagsByOrderId(any())).thenReturn(getBag4list()); + when(orderBagService.findAllBagsByOrderId(any())).thenReturn(getBag4list()); notificationService.notifyHalfPaidPackage(order); @@ -633,7 +633,7 @@ void testNotifyHalfPaidOrderForBroughtByHimself() { when(userNotificationRepository.save(any())).thenReturn(notification); when(notificationParameterRepository.saveAll(any())).thenReturn(new ArrayList<>(parameters)); - when(orderBagService.findBagsByOrderId(any())).thenReturn(getBag4list()); + when(orderBagService.findAllBagsByOrderId(any())).thenReturn(getBag4list()); notificationService.notifyHalfPaidPackage(order); diff --git a/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java b/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java index de1d93015..fc149dc78 100644 --- a/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java +++ b/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java @@ -29,9 +29,9 @@ class OrderBagServiceTest { private OrderBagRepository orderBagRepository; @Test - void testFindBagsByOrderId() { + void testfindAllBagsByOrderId() { when(orderBagRepository.findOrderBagsByOrderId(any())).thenReturn(Arrays.asList(getOrderBag(), getOrderBag2())); - List bags = orderBagService.findBagsByOrderId(1L); + List bags = orderBagService.findAllBagsByOrderId(1L); assertNotNull(bags); Bag bag1 = getBag().setFullPrice(getOrderBag().getPrice()); Bag bag2 = getBag2().setFullPrice(getOrderBag2().getPrice()); diff --git a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java index 36d92c882..e0f0bed90 100644 --- a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java @@ -1012,7 +1012,7 @@ void testGetOrderDetails() { when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(TEST_ORDER)); when(modelMapper.map(TEST_ORDER, new TypeToken>() { }.getType())).thenReturn(TEST_BAG_MAPPING_DTO_LIST); - when(orderBagService.findBagsByOrderId(1L)).thenReturn(TEST_BAG_LIST); + when(orderBagService.findAllBagsByOrderId(1L)).thenReturn(TEST_BAG_LIST); when(modelMapper.map(TEST_BAG, BagInfoDto.class)).thenReturn(TEST_BAG_INFO_DTO); when(bagRepository.findAllByOrder(1L)).thenReturn(TEST_BAG_LIST); when(modelMapper.map(any(), eq(new TypeToken>() { @@ -1025,7 +1025,7 @@ void testGetOrderDetails() { verify(orderRepository).getOrderDetails(1L); verify(modelMapper).map(TEST_ORDER, new TypeToken>() { }.getType()); - verify(orderBagService).findBagsByOrderId(1L); + verify(orderBagService).findAllBagsByOrderId(1L); verify(bagRepository, times(1)).findAllByOrder(anyLong()); verify(modelMapper).map(TEST_BAG, BagInfoDto.class); verify(modelMapper).map(any(), eq(new TypeToken>() { @@ -2604,7 +2604,7 @@ void addBonusesToUserIfOrderStatusIsCanceled() { Employee employee = getEmployee(); when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.of(order)); -// when(orderBagService.findBagsByOrderId(1L)).thenReturn(getBaglist()); +// when(orderBagService.findAllBagsByOrderId(1L)).thenReturn(getBaglist()); when(certificateRepository.findCertificate(order.getId())).thenReturn(getCertificateList()); ubsManagementService.addBonusesToUser(getAddBonusesToUserDto(), 1L, employee.getEmail()); From 31794bf0f1ce04136951777aec606642885c70ed Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 10:02:02 +0300 Subject: [PATCH 49/73] Fixed code --- .../service/ubs/SuperAdminServiceImpl.java | 6 ++--- .../service/ubs/UBSClientServiceImpl.java | 24 +++++++++---------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java index 79b50d7e2..78f3d053f 100644 --- a/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java @@ -162,7 +162,7 @@ public void deleteTariffService(Integer bagId) { } bag.setStatus(BagStatus.DELETED); bagRepository.save(bag); - checkDeletedBagLimitAndDeleteTariffsInfo(bag); + deleteTariffsInfo(bag); orderRepository.findAllByBagId(bagId).forEach(order -> deleteBagFromOrder(order, bag)); } @@ -183,7 +183,7 @@ private void deleteBagFromOrder(Order order, Bag bag) { } } - private void checkDeletedBagLimitAndDeleteTariffsInfo(Bag bag) { + private void deleteTariffsInfo(Bag bag) { TariffsInfo tariffsInfo = bag.getTariffsInfo(); List bags = bagRepository.findAllActiveBagsByTariffsInfoId(tariffsInfo.getId()); if (bags.isEmpty() || bags.stream().noneMatch(Bag::getLimitIncluded)) { @@ -285,7 +285,7 @@ public GetServiceDto getService(long tariffId) { tryToFindTariffById(tariffId); return serviceRepository.findServiceByTariffsInfoId(tariffId) .map(it -> modelMapper.map(it, GetServiceDto.class)) - .orElseGet(() -> null); + .orElse(null); } @Override diff --git a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java index fe925bdd9..024b96c7b 100644 --- a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java @@ -425,14 +425,13 @@ private void checkSumIfCourierLimitBySumOfOrder(TariffsInfo tariffsInfo, Long su public FondyOrderResponse saveFullOrderToDB(OrderResponseDto dto, String uuid, Long orderId) { final User currentUser = userRepository.findByUuid(uuid); TariffsInfo tariffsInfo = tryToFindTariffsInfoByBagIds(getBagIds(dto.getBags()), dto.getLocationId()); - List bagsOrdered = new ArrayList<>(); if (!dto.isShouldBePaid()) { dto.setCertificates(Collections.emptySet()); dto.setPointsToUse(0); } - long sumToPayWithoutDiscountInCoins = formBagsToBeSavedAndCalculateOrderSum(bagsOrdered, + long sumToPayWithoutDiscountInCoins = formBagsToBeSavedAndCalculateOrderSum( dto.getBags(), tariffsInfo); checkIfUserHaveEnoughPoints(currentUser.getCurrentPoints(), dto.getPointsToUse()); long sumToPayInCoins = reduceOrderSumDueToUsedPoints(sumToPayWithoutDiscountInCoins, dto.getPointsToUse()); @@ -444,7 +443,7 @@ public FondyOrderResponse saveFullOrderToDB(OrderResponseDto dto, String uuid, L UBSuser userData = formUserDataToBeSaved(dto.getPersonalData(), dto.getAddressId(), dto.getLocationId(), currentUser); - + List bagsOrdered = new ArrayList<>(); getOrder(dto, currentUser, bagsOrdered, sumToPayInCoins, order, orderCertificates, userData); eventService.save(OrderHistory.ORDER_FORMED, OrderHistory.CLIENT, order); @@ -463,7 +462,7 @@ private List getBagIds(List dto) { .collect(Collectors.toList()); } - private Bag findBagById(Integer id) { + private Bag findActiveBagById(Integer id) { return bagRepository.findActiveBagById(id) .orElseThrow(() -> new NotFoundException(BAG_NOT_FOUND + id)); } @@ -891,9 +890,9 @@ private AddressInfoDto addressInfoDtoBuilder(Order order) { } private List bagForUserDtosBuilder(Order order) { - List bagsForOrder = order.getOrderBags(); - Map actualBagsAmount = orderBagService.getActualBagsAmountForOrder(bagsForOrder); - return bagsForOrder.stream() + List bagsAmountInOrder = order.getOrderBags(); + Map actualBagsAmount = orderBagService.getActualBagsAmountForOrder(bagsAmountInOrder); + return bagsAmountInOrder.stream() .map(orderBag -> buildBagForUserDto(orderBag, actualBagsAmount.get(orderBag.getBag().getId()))) .collect(toList()); } @@ -1201,12 +1200,11 @@ private long calculateOrderSumWithoutDiscounts(List getOrderBagsAndQua .reduce(0L, Long::sum); } - private long formBagsToBeSavedAndCalculateOrderSum( - List orderBagList, List bags, TariffsInfo tariffsInfo) { + private long formBagsToBeSavedAndCalculateOrderSum(List bags, TariffsInfo tariffsInfo) { long sumToPayInCoins = 0L; - + List orderBagList = new ArrayList(bags.size()); for (BagDto temp : bags) { - Bag bag = findBagById(temp.getId()); + Bag bag = findActiveBagById(temp.getId()); if (bag.getLimitIncluded().booleanValue()) { checkAmountOfBagsIfCourierLimitByAmountOfBag(tariffsInfo, temp.getAmount()); checkSumIfCourierLimitBySumOfOrder(tariffsInfo, bag.getFullPrice() * temp.getAmount()); @@ -1216,9 +1214,9 @@ private long formBagsToBeSavedAndCalculateOrderSum( orderBag.setAmount(temp.getAmount()); orderBagList.add(orderBag); } - List orderedBagsIds = bags.stream().map(BagDto::getId).collect(toList()); + List bagIds = bags.stream().map(BagDto::getId).collect(toList()); List notOrderedBags = tariffsInfo.getBags().stream() - .filter(orderBag -> orderBag.getStatus() == BagStatus.ACTIVE && !orderedBagsIds.contains(orderBag.getId())) + .filter(orderBag -> orderBag.getStatus() == BagStatus.ACTIVE && !bagIds.contains(orderBag.getId())) .map(this::createOrderBag).collect(toList()); notOrderedBags.forEach(orderBag -> orderBag.setAmount(0)); orderBagList.addAll(notOrderedBags); From 0a1b07248d37dbbfbdc604928f16dbeac2612e42 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 10:13:35 +0300 Subject: [PATCH 50/73] Fixed --- .../java/greencity/service/ubs/UBSClientServiceImplTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java index eaf9b957a..148f40b47 100644 --- a/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java @@ -8,6 +8,7 @@ import greencity.dto.OrderCourierPopUpDto; import greencity.dto.TariffsForLocationDto; import greencity.dto.address.AddressDto; + import greencity.dto.bag.BagDto; import greencity.dto.bag.BagForUserDto; import greencity.dto.bag.BagOrderDto; From 21fbf5f507331c6316e35729b5bbd7fc27821d7b Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 10:19:22 +0300 Subject: [PATCH 51/73] Fixed all code --- .../java/greencity/service/ubs/UBSClientServiceImpl.java | 5 ++--- .../java/greencity/service/ubs/UBSManagementServiceImpl.java | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java index 024b96c7b..081ffd392 100644 --- a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java @@ -1218,8 +1218,7 @@ private long formBagsToBeSavedAndCalculateOrderSum(List bags, TariffsInf List notOrderedBags = tariffsInfo.getBags().stream() .filter(orderBag -> orderBag.getStatus() == BagStatus.ACTIVE && !bagIds.contains(orderBag.getId())) .map(this::createOrderBag).collect(toList()); - notOrderedBags.forEach(orderBag -> orderBag.setAmount(0)); - orderBagList.addAll(notOrderedBags); + orderBagList.addAll(notOrderedBags.stream().peek(orderBag -> orderBag.setAmount(0)).collect(toList())); return sumToPayInCoins; } @@ -1433,7 +1432,7 @@ public void deleteOrder(String uuid, Long id) { if (order == null) { throw new NotFoundException(ORDER_WITH_CURRENT_ID_DOES_NOT_EXIST); } - order.setOrderBags(new ArrayList<>()); + order.setOrderBags(Collections.emptyList()); orderRepository.delete(order); } diff --git a/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java index 4fb38c1c7..ee5e82cb5 100644 --- a/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSManagementServiceImpl.java @@ -182,7 +182,7 @@ public class UBSManagementServiceImpl implements UBSManagementService { @Autowired private final OrderBagService orderBagService; @Autowired - private OrderBagRepository orderBagRepository; + private final OrderBagRepository orderBagRepository; /** * Method gets all order payments, count paid amount, amount which user should From 59891ac892ffbe88429a091416270be23ec30f80 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 10:28:06 +0300 Subject: [PATCH 52/73] Fixed tests --- .../src/test/java/greencity/ModelUtils.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/service/src/test/java/greencity/ModelUtils.java b/service/src/test/java/greencity/ModelUtils.java index 94f263d4c..43a7f96b7 100644 --- a/service/src/test/java/greencity/ModelUtils.java +++ b/service/src/test/java/greencity/ModelUtils.java @@ -177,7 +177,7 @@ public class ModelUtils { public static final List TEST_PAYMENT_LIST = createPaymentList(); public static final OrderDetailStatusDto ORDER_DETAIL_STATUS_DTO = createOrderDetailStatusDto(); public static final List TEST_BAG_MAPPING_DTO_LIST = createBagMappingDtoList(); - public static final Bag TEST_BAG = createBag(); + public static final Bag TEST_BAG = createBag(1); public static final OrderBag TEST_ORDER_BAG = createOrderBag(); public static final BagForUserDto TEST_BAG_FOR_USER_DTO = createBagForUserDto(); public static final BagInfoDto TEST_BAG_INFO_DTO = createBagInfoDto(); @@ -228,10 +228,7 @@ public class ModelUtils { public static final NotificationDto TEST_NOTIFICATION_DTO = createNotificationDto(); public static final UpdateOrderPageAdminDto UPDATE_ORDER_PAGE_ADMIN_DTO = updateOrderPageAdminDto(); public static final CourierUpdateDto UPDATE_COURIER_DTO = getUpdateCourierDto(); - public static final Bag TEST_BAG2 = createBag().setFullPrice(100000L); - public static final Bag TEST_BAG2_2 = createBag().setFullPrice(100000L).setId(2); - public static final Bag TEST_BAG2_3 = createBag().setFullPrice(100000L).setId(3); - public static final List TEST_BAG_LIST2 = Arrays.asList(TEST_BAG2, TEST_BAG2, TEST_BAG2_2, TEST_BAG2_3); + public static final List TEST_BAG_LIST2 = Arrays.asList(createBag(1), createBag(2), createBag(3)); public static EmployeeFilterView getEmployeeFilterView() { return getEmployeeFilterViewWithPassedIds(1L, 5L, 10L); @@ -2251,7 +2248,7 @@ private static BagInfoDto createBagInfoDto() { .capacity(20) .name("Name") .nameEng("NameEng") - .price(100.00) + .price(1000.00) .build(); } @@ -2262,10 +2259,10 @@ private static List createBagMappingDtoList() { .build()); } - private static Bag createBag() { - return Bag.builder() + private static Bag createBag(int id) { + Bag bag = Bag.builder() .status(BagStatus.ACTIVE) - .id(1) + .id(id) .name("Name") .nameEng("NameEng") .capacity(20) @@ -2280,6 +2277,7 @@ private static Bag createBag() { .id(1L) .build()) .build(); + return bag.setFullPrice(100000L); } private static OrderBag createOrderBag() { @@ -2290,7 +2288,7 @@ private static OrderBag createOrderBag() { .capacity(20) .price(100_00L) .order(createOrder()) - .bag(createBag()) + .bag(createBag(1)) .build(); } From 5a5e8cd7fb7ad206840ec4a56918215fc7000d45 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 10:39:33 +0300 Subject: [PATCH 53/73] Fixed tests --- service/src/test/java/greencity/ModelUtils.java | 4 ++-- .../test/java/greencity/service/ubs/OrderBagServiceTest.java | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/service/src/test/java/greencity/ModelUtils.java b/service/src/test/java/greencity/ModelUtils.java index 43a7f96b7..22ce0483f 100644 --- a/service/src/test/java/greencity/ModelUtils.java +++ b/service/src/test/java/greencity/ModelUtils.java @@ -2705,7 +2705,7 @@ public static Bag getBag() { .capacity(120) .commission(50_00L) .price(120_00L) - .fullPrice(170_00L) + .fullPrice(120_00L) .createdAt(LocalDate.now()) .createdBy(getEmployee()) .editedBy(getEmployee()) @@ -2721,7 +2721,7 @@ public static Bag getBag2() { .capacity(120) .commission(50_00L) .price(120_00L) - .fullPrice(170_00L) + .fullPrice(2200000L) .createdAt(LocalDate.now()) .createdBy(getEmployee()) .editedBy(getEmployee()) diff --git a/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java b/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java index fc149dc78..432341e98 100644 --- a/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java +++ b/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java @@ -33,12 +33,11 @@ void testfindAllBagsByOrderId() { when(orderBagRepository.findOrderBagsByOrderId(any())).thenReturn(Arrays.asList(getOrderBag(), getOrderBag2())); List bags = orderBagService.findAllBagsByOrderId(1L); assertNotNull(bags); - Bag bag1 = getBag().setFullPrice(getOrderBag().getPrice()); - Bag bag2 = getBag2().setFullPrice(getOrderBag2().getPrice()); + Bag bag1 = getBag(); + Bag bag2 = getBag2(); assertEquals(bag1, bags.get(0)); assertEquals(bag2, bags.get(1)); - } @Test From 004bd175e733091cac19538535756048af86ada8 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 10:45:26 +0300 Subject: [PATCH 54/73] Fixed code --- dao/src/main/java/greencity/entity/order/Bag.java | 15 +++------------ .../greencity/service/ubs/OrderBagService.java | 4 ++-- .../service/ubs/UBSClientServiceImpl.java | 5 +---- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/dao/src/main/java/greencity/entity/order/Bag.java b/dao/src/main/java/greencity/entity/order/Bag.java index daf062258..9dea2f1c4 100644 --- a/dao/src/main/java/greencity/entity/order/Bag.java +++ b/dao/src/main/java/greencity/entity/order/Bag.java @@ -10,17 +10,7 @@ import lombok.ToString; import lombok.Builder; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; +import javax.persistence.*; import javax.validation.constraints.Max; import javax.validation.constraints.Min; import java.time.LocalDate; @@ -87,7 +77,8 @@ public class Bag { @JoinColumn private Employee editedBy; - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(cascade = CascadeType.REMOVE, + fetch = FetchType.EAGER) @JoinColumn(nullable = false) private TariffsInfo tariffsInfo; diff --git a/service/src/main/java/greencity/service/ubs/OrderBagService.java b/service/src/main/java/greencity/service/ubs/OrderBagService.java index 74f124d0d..8922d6710 100644 --- a/service/src/main/java/greencity/service/ubs/OrderBagService.java +++ b/service/src/main/java/greencity/service/ubs/OrderBagService.java @@ -16,8 +16,8 @@ @Service @Data -public final class OrderBagService { - private OrderBagRepository orderBagRepository; +public class OrderBagService { + private final OrderBagRepository orderBagRepository; private Long getBagPrice(List orderBags, Integer id) { return orderBags.stream() diff --git a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java index 081ffd392..a5f0af833 100644 --- a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java @@ -379,10 +379,7 @@ public PersonalDataDto getSecondPageData(String uuid) { List ubsUser = ubsUserRepository.findUBSuserByUser(currentUser); if (ubsUser.isEmpty()) { - UBSuser ubSuser = UBSuser.builder().id(null).build(); - List mutableUbsUserList = new ArrayList<>(ubsUser); - mutableUbsUserList.add(ubSuser); - ubsUser = mutableUbsUserList; + ubsUser = Collections.singletonList(UBSuser.builder().id(null).build()); } PersonalDataDto dto = modelMapper.map(currentUser, PersonalDataDto.class); dto.setUbsUserId(ubsUser.get(0).getId()); From 444fe39e56a7bf32c472d0afa8ad470f439f6314 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 10:52:17 +0300 Subject: [PATCH 55/73] Fixed tests --- .../service/ubs/OrderBagServiceTest.java | 22 ++++++++++--------- .../ubs/SuperAdminServiceImplTest.java | 6 ++++- .../ubs/UBSManagementServiceImplTest.java | 18 ++++++++++++++- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java b/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java index 432341e98..00d6a7daf 100644 --- a/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java +++ b/service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java @@ -1,22 +1,24 @@ package greencity.service.ubs; import greencity.entity.order.Bag; -import greencity.entity.order.Order; import greencity.entity.order.OrderBag; import greencity.repository.OrderBagRepository; - -import java.util.*; - +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.HashMap; +import java.util.ArrayList; import static greencity.ModelUtils.getOrderBag; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; - -import static greencity.ModelUtils.*; -import static org.junit.jupiter.api.Assertions.*; +import static greencity.ModelUtils.getBag; +import static greencity.ModelUtils.getBag2; +import static greencity.ModelUtils.getOrderBag2; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -43,9 +45,9 @@ void testfindAllBagsByOrderId() { @Test void testFindBagsByOrdersList() { List bags = orderBagService.findAllBagsInOrderBagsList(Arrays.asList(getOrderBag(), getOrderBag2())); + Bag bag1 = getBag(); + Bag bag2 = getBag2(); - Bag bag1 = getBag().setFullPrice(getOrderBag().getPrice()); - Bag bag2 = getBag2().setFullPrice(getOrderBag2().getPrice()); assertNotNull(bags); assertEquals(bag1, bags.get(0)); assertEquals(bag2, bags.get(1)); diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index 07a7f2a45..a281aba46 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -31,7 +31,11 @@ import greencity.entity.user.Region; import greencity.entity.user.employee.Employee; import greencity.entity.user.employee.ReceivingStation; -import greencity.enums.*; +import greencity.enums.CourierStatus; +import greencity.enums.LocationStatus; +import greencity.enums.StationStatus; +import greencity.enums.TariffStatus; +import greencity.enums.BagStatus; import greencity.exceptions.BadRequestException; import greencity.exceptions.NotFoundException; import greencity.exceptions.UnprocessableEntityException; diff --git a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java index e0f0bed90..d3b773812 100644 --- a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java @@ -52,7 +52,23 @@ import greencity.enums.SortingOrder; import greencity.exceptions.BadRequestException; import greencity.exceptions.NotFoundException; -import greencity.repository.*; +import greencity.repository.BagRepository; +import greencity.repository.CertificateRepository; +import greencity.repository.EmployeeOrderPositionRepository; +import greencity.repository.EmployeeRepository; +import greencity.repository.OrderAddressRepository; +import greencity.repository.OrderDetailRepository; +import greencity.repository.OrderPaymentStatusTranslationRepository; +import greencity.repository.OrderRepository; +import greencity.repository.OrderStatusTranslationRepository; +import greencity.repository.PaymentRepository; +import greencity.repository.PositionRepository; +import greencity.repository.ReceivingStationRepository; +import greencity.repository.RefundRepository; +import greencity.repository.ServiceRepository; +import greencity.repository.TariffsInfoRepository; +import greencity.repository.UserRepository; +import greencity.repository.OrderBagRepository; import greencity.service.locations.LocationApiService; import greencity.service.notification.NotificationServiceImpl; import org.junit.jupiter.api.Assertions; From de3b25a21afe5fc737cf7599b5a4002d70c060bb Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 10:55:56 +0300 Subject: [PATCH 56/73] Fixed code --- .../java/greencity/service/ubs/UBSClientServiceImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java index a5f0af833..20cb3e9cf 100644 --- a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java @@ -1030,7 +1030,6 @@ private Order formAndSaveOrder(Order order, Set orderCertificates, User currentUser, long sumToPayInCoins) { order.setOrderStatus(OrderStatus.FORMED); order.setCertificates(orderCertificates); - bagsOrdered.forEach(orderBag -> orderBag.setOrder(order)); order.setOrderBags(bagsOrdered); order.setUbsUser(userData); order.setUser(currentUser); @@ -1050,7 +1049,7 @@ private Order formAndSaveOrder(Order order, Set orderCertificates, order.setPayment(new ArrayList<>()); } order.getPayment().add(payment); - + bagsOrdered.forEach(orderBag -> orderBag.setOrder(order)); orderRepository.save(order); return order; } @@ -1200,6 +1199,7 @@ private long calculateOrderSumWithoutDiscounts(List getOrderBagsAndQua private long formBagsToBeSavedAndCalculateOrderSum(List bags, TariffsInfo tariffsInfo) { long sumToPayInCoins = 0L; List orderBagList = new ArrayList(bags.size()); + List bagIds = bags.stream().map(BagDto::getId).collect(toList()); for (BagDto temp : bags) { Bag bag = findActiveBagById(temp.getId()); if (bag.getLimitIncluded().booleanValue()) { @@ -1210,8 +1210,8 @@ private long formBagsToBeSavedAndCalculateOrderSum(List bags, TariffsInf OrderBag orderBag = createOrderBag(bag); orderBag.setAmount(temp.getAmount()); orderBagList.add(orderBag); + bagIds.add(temp.getId()); } - List bagIds = bags.stream().map(BagDto::getId).collect(toList()); List notOrderedBags = tariffsInfo.getBags().stream() .filter(orderBag -> orderBag.getStatus() == BagStatus.ACTIVE && !bagIds.contains(orderBag.getId())) .map(this::createOrderBag).collect(toList()); From 757366bc7fa131471e6486f56eb228cb32b4ba9b Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 11:02:34 +0300 Subject: [PATCH 57/73] Fixed code --- .../main/java/greencity/service/ubs/UBSClientServiceImpl.java | 1 - 1 file changed, 1 deletion(-) diff --git a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java index 20cb3e9cf..8280a1ce1 100644 --- a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java @@ -125,7 +125,6 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; - import javax.persistence.EntityNotFoundException; import javax.transaction.Transactional; import java.math.BigDecimal; From 1b196308d054927227fbdecfdaba8d2d58083204 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 11:10:22 +0300 Subject: [PATCH 58/73] Fixed greencity.repository.AdditionalBagsInfoRepoTest --- .../greencity/service/ubs/UBSManagementServiceImplTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java index d3b773812..cf3265bba 100644 --- a/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/UBSManagementServiceImplTest.java @@ -124,9 +124,6 @@ import static greencity.ModelUtils.UPDATE_ORDER_PAGE_ADMIN_DTO; import static greencity.ModelUtils.getAddBonusesToUserDto; import static greencity.ModelUtils.getAdminCommentDto; -import static greencity.ModelUtils.getBag1list; -import static greencity.ModelUtils.getBag2list; -import static greencity.ModelUtils.getBag3list; import static greencity.ModelUtils.getBagInfoDto; import static greencity.ModelUtils.getBaglist; import static greencity.ModelUtils.getCertificateList; From cddeb11cbd3ace6179ed60e07f2f7b07db210156 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 11:34:05 +0300 Subject: [PATCH 59/73] Fixed precondition --- .../logs/ch-add-column-status-to-bag-table-Spodaryk.xml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-table-Spodaryk.xml b/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-table-Spodaryk.xml index c280afaf2..4bc7dbfbe 100644 --- a/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-table-Spodaryk.xml +++ b/dao/src/main/resources/db/changelog/logs/ch-add-column-status-to-bag-table-Spodaryk.xml @@ -2,17 +2,16 @@ - - + + + - - From a3de9e47bcf9731f893ecff8a95fe2a977fff314 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 11:45:20 +0300 Subject: [PATCH 60/73] Fixed bag --- dao/src/main/java/greencity/entity/order/Bag.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dao/src/main/java/greencity/entity/order/Bag.java b/dao/src/main/java/greencity/entity/order/Bag.java index 9dea2f1c4..034c4b023 100644 --- a/dao/src/main/java/greencity/entity/order/Bag.java +++ b/dao/src/main/java/greencity/entity/order/Bag.java @@ -77,8 +77,7 @@ public class Bag { @JoinColumn private Employee editedBy; - @ManyToOne(cascade = CascadeType.REMOVE, - fetch = FetchType.EAGER) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(nullable = false) private TariffsInfo tariffsInfo; From 30072953f7bd86dd691b44f995a5b86f46fdced4 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 11:49:31 +0300 Subject: [PATCH 61/73] Fixed code --- dao/src/main/java/greencity/entity/order/Bag.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dao/src/main/java/greencity/entity/order/Bag.java b/dao/src/main/java/greencity/entity/order/Bag.java index 034c4b023..9dea2f1c4 100644 --- a/dao/src/main/java/greencity/entity/order/Bag.java +++ b/dao/src/main/java/greencity/entity/order/Bag.java @@ -77,7 +77,8 @@ public class Bag { @JoinColumn private Employee editedBy; - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(cascade = CascadeType.REMOVE, + fetch = FetchType.EAGER) @JoinColumn(nullable = false) private TariffsInfo tariffsInfo; From 1cb4d93f806a4a7f8f626c886b22176b02b4047e Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 11:59:39 +0300 Subject: [PATCH 62/73] =?UTF-8?q?Fixed=20=D0=B8=D0=B3=D0=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/src/main/java/greencity/entity/order/Bag.java | 14 ++++++++++++-- .../service/ubs/UBSClientServiceImpl.java | 11 +++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/dao/src/main/java/greencity/entity/order/Bag.java b/dao/src/main/java/greencity/entity/order/Bag.java index 9dea2f1c4..82a4cfa4b 100644 --- a/dao/src/main/java/greencity/entity/order/Bag.java +++ b/dao/src/main/java/greencity/entity/order/Bag.java @@ -9,8 +9,18 @@ import lombok.EqualsAndHashCode; import lombok.ToString; import lombok.Builder; - -import javax.persistence.*; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.CascadeType; import javax.validation.constraints.Max; import javax.validation.constraints.Min; import java.time.LocalDate; diff --git a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java index 8280a1ce1..b98747f3b 100644 --- a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java @@ -421,13 +421,14 @@ private void checkSumIfCourierLimitBySumOfOrder(TariffsInfo tariffsInfo, Long su public FondyOrderResponse saveFullOrderToDB(OrderResponseDto dto, String uuid, Long orderId) { final User currentUser = userRepository.findByUuid(uuid); TariffsInfo tariffsInfo = tryToFindTariffsInfoByBagIds(getBagIds(dto.getBags()), dto.getLocationId()); + List bagsOrdered = new ArrayList<>(); if (!dto.isShouldBePaid()) { dto.setCertificates(Collections.emptySet()); dto.setPointsToUse(0); } - long sumToPayWithoutDiscountInCoins = formBagsToBeSavedAndCalculateOrderSum( + long sumToPayWithoutDiscountInCoins = formBagsToBeSavedAndCalculateOrderSum(bagsOrdered, dto.getBags(), tariffsInfo); checkIfUserHaveEnoughPoints(currentUser.getCurrentPoints(), dto.getPointsToUse()); long sumToPayInCoins = reduceOrderSumDueToUsedPoints(sumToPayWithoutDiscountInCoins, dto.getPointsToUse()); @@ -439,7 +440,7 @@ public FondyOrderResponse saveFullOrderToDB(OrderResponseDto dto, String uuid, L UBSuser userData = formUserDataToBeSaved(dto.getPersonalData(), dto.getAddressId(), dto.getLocationId(), currentUser); - List bagsOrdered = new ArrayList<>(); + getOrder(dto, currentUser, bagsOrdered, sumToPayInCoins, order, orderCertificates, userData); eventService.save(OrderHistory.ORDER_FORMED, OrderHistory.CLIENT, order); @@ -1195,9 +1196,8 @@ private long calculateOrderSumWithoutDiscounts(List getOrderBagsAndQua .reduce(0L, Long::sum); } - private long formBagsToBeSavedAndCalculateOrderSum(List bags, TariffsInfo tariffsInfo) { - long sumToPayInCoins = 0L; - List orderBagList = new ArrayList(bags.size()); + private long formBagsToBeSavedAndCalculateOrderSum(List orderBagList, List bags, TariffsInfo tariffsInfo) { + long sumToPayInCoins = 0L; List bagIds = bags.stream().map(BagDto::getId).collect(toList()); for (BagDto temp : bags) { Bag bag = findActiveBagById(temp.getId()); @@ -1209,7 +1209,6 @@ private long formBagsToBeSavedAndCalculateOrderSum(List bags, TariffsInf OrderBag orderBag = createOrderBag(bag); orderBag.setAmount(temp.getAmount()); orderBagList.add(orderBag); - bagIds.add(temp.getId()); } List notOrderedBags = tariffsInfo.getBags().stream() .filter(orderBag -> orderBag.getStatus() == BagStatus.ACTIVE && !bagIds.contains(orderBag.getId())) From 66ec2fcd8d2a4ed93a059e1253fdf25651be8a11 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 12:15:57 +0300 Subject: [PATCH 63/73] inserted sql in xml --- .../ch-update-order-bag-mapping-table-Spodaryk.xml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml b/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml index e1725d657..55b764feb 100644 --- a/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml +++ b/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml @@ -47,8 +47,14 @@ - - + update order_bag_mapping set + capacity=bag.capacity, + price=bag.full_price, + name=bag.name, + name_eng=bag.name_eng + from bag + where bag_id=bag.id + From 6db84ac1cc62cc94c70637fb2ee7df5764781f11 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 12:22:44 +0300 Subject: [PATCH 64/73] inserted sql in xml --- .../logs/ch-update-order-bag-mapping-table-Spodaryk.xml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml b/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml index 55b764feb..6cb5ee653 100644 --- a/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml +++ b/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml @@ -47,14 +47,7 @@ - update order_bag_mapping set - capacity=bag.capacity, - price=bag.full_price, - name=bag.name, - name_eng=bag.name_eng - from bag - where bag_id=bag.id - + From 6ea57424c4b71ff46fc8ba0dd9b4e194699c5a21 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 12:33:48 +0300 Subject: [PATCH 65/73] inserted sql in different xml --- .../db/changelog/db.changelog-master.xml | 3 +- ...olumn-order-bag-mapping-table-Spodaryk.xml | 59 +++++++++++++++++++ ...pdate-order-bag-mapping-table-Spodaryk.xml | 53 +---------------- 3 files changed, 62 insertions(+), 53 deletions(-) create mode 100644 dao/src/main/resources/db/changelog/logs/ch-add-column-order-bag-mapping-table-Spodaryk.xml diff --git a/dao/src/main/resources/db/changelog/db.changelog-master.xml b/dao/src/main/resources/db/changelog/db.changelog-master.xml index 2bd59f6d6..28ba8a72f 100644 --- a/dao/src/main/resources/db/changelog/db.changelog-master.xml +++ b/dao/src/main/resources/db/changelog/db.changelog-master.xml @@ -207,7 +207,7 @@ - + @@ -216,4 +216,5 @@ + \ No newline at end of file diff --git a/dao/src/main/resources/db/changelog/logs/ch-add-column-order-bag-mapping-table-Spodaryk.xml b/dao/src/main/resources/db/changelog/logs/ch-add-column-order-bag-mapping-table-Spodaryk.xml new file mode 100644 index 000000000..6cb5ee653 --- /dev/null +++ b/dao/src/main/resources/db/changelog/logs/ch-add-column-order-bag-mapping-table-Spodaryk.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml b/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml index 6cb5ee653..dbe8a62e2 100644 --- a/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml +++ b/dao/src/main/resources/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml @@ -2,58 +2,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - From d903985f9e2f720af4cf2bafb026125c1546869e Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 13:26:47 +0300 Subject: [PATCH 66/73] formatted --- .../java/greencity/service/ubs/UBSClientServiceImpl.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java index b98747f3b..84261a820 100644 --- a/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java +++ b/service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java @@ -1196,8 +1196,9 @@ private long calculateOrderSumWithoutDiscounts(List getOrderBagsAndQua .reduce(0L, Long::sum); } - private long formBagsToBeSavedAndCalculateOrderSum(List orderBagList, List bags, TariffsInfo tariffsInfo) { - long sumToPayInCoins = 0L; + private long formBagsToBeSavedAndCalculateOrderSum(List orderBagList, List bags, + TariffsInfo tariffsInfo) { + long sumToPayInCoins = 0L; List bagIds = bags.stream().map(BagDto::getId).collect(toList()); for (BagDto temp : bags) { Bag bag = findActiveBagById(temp.getId()); From 93b8c5f712c3ec2ab82edb20c3a11e58f47b0830 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 13:36:33 +0300 Subject: [PATCH 67/73] fixed tests --- .../java/greencity/service/ubs/SuperAdminServiceImplTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index a281aba46..33c7d57d0 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -291,9 +291,9 @@ void deleteTariffServiceWhenTariffBagsWithLimits() { when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))) .thenReturn(hashMap); when(orderBagRepository.findOrderBagsByBagId(any())).thenReturn(Collections.singletonList(getOrderBag())); - + assertEquals(bag.getStatus(), BagStatus.ACTIVE); superAdminService.deleteTariffService(1); - + assertEquals(bag.getStatus(), BagStatus.DELETED); verify(orderBagRepository).findOrderBagsByBagId(any()); verify(bagRepository).findActiveBagById(1); verify(bagRepository).save(bag); From 0d926bba7317759c6969d96b365c9ccb34ec4c26 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 13:50:07 +0300 Subject: [PATCH 68/73] added tests to cover bagstatus --- .../service/ubs/SuperAdminServiceImplTest.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index 33c7d57d0..6e4c8e1d1 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -275,6 +275,15 @@ void deleteTariffServiceWhenThereAreMoreThan1TypeOfBag() { verify(tariffsInfoRepository, never()).save(tariffsInfo); } + @Test + void testBagStatus() { + Bag bag = ModelUtils.getBag(); + bag.setStatus(BagStatus.ACTIVE); + assertEquals(BagStatus.ACTIVE, bag.getStatus()); + bag.setStatus(BagStatus.DELETED); + assertEquals(BagStatus.DELETED, bag.getStatus()); + } + @Test void deleteTariffServiceWhenTariffBagsWithLimits() { Bag bag = ModelUtils.getBag(); @@ -291,9 +300,9 @@ void deleteTariffServiceWhenTariffBagsWithLimits() { when(orderBagService.getActualBagsAmountForOrder(Arrays.asList(ModelUtils.getOrderBag()))) .thenReturn(hashMap); when(orderBagRepository.findOrderBagsByBagId(any())).thenReturn(Collections.singletonList(getOrderBag())); - assertEquals(bag.getStatus(), BagStatus.ACTIVE); + assertEquals(BagStatus.ACTIVE, bag.getStatus()); superAdminService.deleteTariffService(1); - assertEquals(bag.getStatus(), BagStatus.DELETED); + assertEquals(BagStatus.DELETED, bag.getStatus()); verify(orderBagRepository).findOrderBagsByBagId(any()); verify(bagRepository).findActiveBagById(1); verify(bagRepository).save(bag); From 48618f69e76c8812af91579f1eaeb459c2bcfc1f Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 13:53:32 +0300 Subject: [PATCH 69/73] removed codesmell --- .../java/greencity/service/ubs/SuperAdminServiceImplTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java index 6e4c8e1d1..994107bba 100644 --- a/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/SuperAdminServiceImplTest.java @@ -67,7 +67,6 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.modelmapper.ModelMapper; - import java.time.LocalDate; import java.util.ArrayList; import java.util.Collections; @@ -79,7 +78,6 @@ import java.util.Set; import java.util.UUID; import java.util.stream.Stream; - import static greencity.ModelUtils.*; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; From aab511bd9e4b648c1695e981627ec8f0c22eb014 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 14:31:23 +0300 Subject: [PATCH 70/73] Added tests to cover Bagstatus --- .../java/greencity/enums/BagStatusTest.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 dao/src/test/java/greencity/enums/BagStatusTest.java diff --git a/dao/src/test/java/greencity/enums/BagStatusTest.java b/dao/src/test/java/greencity/enums/BagStatusTest.java new file mode 100644 index 000000000..91f711fff --- /dev/null +++ b/dao/src/test/java/greencity/enums/BagStatusTest.java @@ -0,0 +1,45 @@ +package greencity.enums; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; + +public class BagStatusTest { + + @Test + public void enumValuesExistenceTest() { + assertNotNull(BagStatus.ACTIVE); + assertNotNull(BagStatus.DELETED); + } + + @Test + public void enumValuesUniquenessTest() { + assertNotEquals(BagStatus.ACTIVE, BagStatus.DELETED); + } + + @Test + public void enumValuesToStringTest() { + assertEquals("ACTIVE", BagStatus.ACTIVE.toString()); + assertEquals("DELETED", BagStatus.DELETED.toString()); + } + + @Test + public void valueOfTest() { + assertEquals(BagStatus.ACTIVE, BagStatus.valueOf("ACTIVE")); + assertEquals(BagStatus.DELETED, BagStatus.valueOf("DELETED")); + } + + @Test + public void enumOrdinalTest() { + assertEquals(0, BagStatus.ACTIVE.ordinal()); + assertEquals(1, BagStatus.DELETED.ordinal()); + } + + @Test + public void enumValuesArrayTest() { + BagStatus[] expectedArray = {BagStatus.ACTIVE, BagStatus.DELETED}; + assertArrayEquals(expectedArray, BagStatus.values()); + } +} From d592be5581ee20e2619a271592c69698c60f3bc0 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 14:38:46 +0300 Subject: [PATCH 71/73] Removed codesmell in BagStatusTest --- .../test/java/greencity/enums/BagStatusTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/dao/src/test/java/greencity/enums/BagStatusTest.java b/dao/src/test/java/greencity/enums/BagStatusTest.java index 91f711fff..2a79b535e 100644 --- a/dao/src/test/java/greencity/enums/BagStatusTest.java +++ b/dao/src/test/java/greencity/enums/BagStatusTest.java @@ -6,39 +6,39 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals; -public class BagStatusTest { +class BagStatusTest { @Test - public void enumValuesExistenceTest() { + void enumValuesExistenceTest() { assertNotNull(BagStatus.ACTIVE); assertNotNull(BagStatus.DELETED); } @Test - public void enumValuesUniquenessTest() { + void enumValuesUniquenessTest() { assertNotEquals(BagStatus.ACTIVE, BagStatus.DELETED); } @Test - public void enumValuesToStringTest() { + void enumValuesToStringTest() { assertEquals("ACTIVE", BagStatus.ACTIVE.toString()); assertEquals("DELETED", BagStatus.DELETED.toString()); } @Test - public void valueOfTest() { + void valueOfTest() { assertEquals(BagStatus.ACTIVE, BagStatus.valueOf("ACTIVE")); assertEquals(BagStatus.DELETED, BagStatus.valueOf("DELETED")); } @Test - public void enumOrdinalTest() { + void enumOrdinalTest() { assertEquals(0, BagStatus.ACTIVE.ordinal()); assertEquals(1, BagStatus.DELETED.ordinal()); } @Test - public void enumValuesArrayTest() { + void enumValuesArrayTest() { BagStatus[] expectedArray = {BagStatus.ACTIVE, BagStatus.DELETED}; assertArrayEquals(expectedArray, BagStatus.values()); } From 78d87fd03ccd50441eb886e4cd01ea5986bcc02a Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 15:45:21 +0300 Subject: [PATCH 72/73] added anotations not --- .../logs/ch-add-column-order-bag-mapping-table-Spodaryk.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dao/src/main/resources/db/changelog/logs/ch-add-column-order-bag-mapping-table-Spodaryk.xml b/dao/src/main/resources/db/changelog/logs/ch-add-column-order-bag-mapping-table-Spodaryk.xml index 6cb5ee653..1cfb9ee4f 100644 --- a/dao/src/main/resources/db/changelog/logs/ch-add-column-order-bag-mapping-table-Spodaryk.xml +++ b/dao/src/main/resources/db/changelog/logs/ch-add-column-order-bag-mapping-table-Spodaryk.xml @@ -4,7 +4,9 @@ xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd"> - + + + From b026b082f2616409a16e62ce053d87e0cbeb6169 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Mon, 31 Jul 2023 16:03:26 +0300 Subject: [PATCH 73/73] deleted unnesessary anotations not --- .../logs/ch-add-column-order-bag-mapping-table-Spodaryk.xml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dao/src/main/resources/db/changelog/logs/ch-add-column-order-bag-mapping-table-Spodaryk.xml b/dao/src/main/resources/db/changelog/logs/ch-add-column-order-bag-mapping-table-Spodaryk.xml index 1cfb9ee4f..6cb5ee653 100644 --- a/dao/src/main/resources/db/changelog/logs/ch-add-column-order-bag-mapping-table-Spodaryk.xml +++ b/dao/src/main/resources/db/changelog/logs/ch-add-column-order-bag-mapping-table-Spodaryk.xml @@ -4,9 +4,7 @@ xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd"> - - - +