Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@
<artifactId>podzilla-utils-lib</artifactId>
<version>v1.1.12</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@Slf4j
@RestController
@RequestMapping("/assign")
@RequestMapping("/api/assign")
public class AssignerController {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@Slf4j
@RestController
@RequestMapping("warehouse/manager")
@RequestMapping("api/manager")
public class ManagerController {
@Autowired
private ManagerService managerService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.UUID;

@RestController
@RequestMapping("warehouse/package")
@RequestMapping("api/package")
@Validated
public class PackagedOrdersController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@Slf4j
@RestController
@RequestMapping("warehouse/packagers")
@RequestMapping("api/packagers")
public class PackagerController {

private final PackagerService packagerService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@Slf4j
@RestController
@RequestMapping("/stock")
@RequestMapping("/api/stock")
public class StockController {

@Autowired
Expand Down
39 changes: 2 additions & 37 deletions src/main/java/com/podzilla/warehouse/Models/AssignedOrders.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,52 +32,17 @@ public class AssignedOrders {
@CreationTimestamp
private LocalDateTime assignedAt;

@Column(nullable = false)
@OneToMany(mappedBy = "packagedOrder")
private List<Stock> items;

@Column(nullable = false)
private DeliveryAddress deliveryAddress;
@Column(nullable = false)
private BigDecimal totalAmount;
@Column(nullable = false)
private double orderLatitude;
@Column(nullable = false)
private double orderLongitude;
@Column(nullable = false)
private String signature;
@Column(nullable = false)
private ConfirmationType confirmationType;

public AssignedOrders(UUID orderId, UUID assignerId, UUID courierId, List<Stock> items,
DeliveryAddress deliveryAddress, BigDecimal totalAmount, double orderLatitude,
double orderLongitude, String signature, ConfirmationType confirmationType) {
public AssignedOrders(UUID orderId, UUID assignerId, UUID courierId) {
this.orderId = orderId;
this.assignerId = assignerId;
this.courierId = courierId;
this.assignedAt = LocalDateTime.now();
this.items = items;
this.deliveryAddress = deliveryAddress;
this.totalAmount = totalAmount;
this.orderLatitude = orderLatitude;
this.orderLongitude = orderLongitude;
this.signature = signature;
this.confirmationType = confirmationType;
}

public AssignedOrders(UUID orderId, UUID assignerId, UUID courierId, LocalDateTime assignedAt,
List<Stock> items, DeliveryAddress deliveryAddress, BigDecimal totalAmount,
double orderLatitude, double orderLongitude, String signature, ConfirmationType confirmationType) {
public AssignedOrders(UUID orderId, UUID assignerId, UUID courierId, LocalDateTime assignedAt) {
this.orderId = orderId;
this.assignerId = assignerId;
this.courierId = courierId;
this.assignedAt = assignedAt;
this.items = items;
this.deliveryAddress = deliveryAddress;
this.totalAmount = totalAmount;
this.orderLatitude = orderLatitude;
this.orderLongitude = orderLongitude;
this.signature = signature;
this.confirmationType = confirmationType;
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/podzilla/warehouse/Models/Stock.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ public class Stock {

@Column(nullable = false)
private String category;

@ManyToOne
@JoinColumn(name = "order_id", nullable = true)
private PackagedOrders packagedOrder;

@CreationTimestamp
@Column(updatable = false)
private LocalDateTime createdAt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,18 @@ public Optional<List<AssignedOrders>> findByAssignerIdIsNull() {
@CachePut(key = "'orderId:' + #orderId")
public AssignedOrders assignOrder(UUID orderId, UUID assignerId, UUID courierId) {
PackagedOrders packagedOrder = packagedOrdersRepository.findOneByOrderId(orderId).get();
AssignedOrders assignment = new AssignedOrders(orderId, assignerId, courierId, packagedOrder.getItems(),
packagedOrder.getDeliveryAddress(), packagedOrder.getTotalAmount(), packagedOrder.getOrderLatitude(),
packagedOrder.getOrderLongitude(), packagedOrder.getSignature(), packagedOrder.getConfirmationType());
AssignedOrders assignment = new AssignedOrders(orderId, assignerId, courierId);
assignedOrdersRepository.save(assignment);

OrderAssignedToCourierEvent event =
EventFactory.createOrderAssignedToCourierEvent(
orderId,
courierId,
assignment.getTotalAmount(),
assignment.getOrderLatitude(),
assignment.getOrderLongitude(),
assignment.getSignature(),
assignment.getConfirmationType()
packagedOrder.getTotalAmount(),
packagedOrder.getOrderLatitude(),
packagedOrder.getOrderLongitude(),
packagedOrder.getSignature(),
packagedOrder.getConfirmationType()
);

eventPublisher.publishEvent(EventsConstants.ORDER_ASSIGNED_TO_COURIER, event);
Expand Down

This file was deleted.

37 changes: 37 additions & 0 deletions src/test/java/com/podzilla/warehouse/e2e/E2eTestBase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.podzilla.warehouse.e2e;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;

/**
* Base class for E2E tests that interact with a running instance of the application.
* This assumes the application is running on localhost:8080 with context path /api.
*/
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public abstract class E2eTestBase {

protected static final String BASE_URL = "http://localhost:8080/api";
protected RestTemplate restTemplate;

@BeforeAll
public void setup() {
RestTemplateBuilder builder = new RestTemplateBuilder();
restTemplate = builder
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.build();

// Verify the application is running
try {
restTemplate.getForEntity("http://localhost:8080//actuator/health", String.class);
} catch (Exception e) {
System.err.println("WARNING: The application does not appear to be running at " + BASE_URL);
System.err.println("Make sure to start the application using Docker before running these tests.");
}
}
}
136 changes: 136 additions & 0 deletions src/test/java/com/podzilla/warehouse/e2e/E2eTestUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package com.podzilla.warehouse.e2e;

import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

/**
* Utility class for E2E tests with helper methods for common operations.
*/
public class E2eTestUtils {

/**
* Performs a GET request to the specified endpoint.
*
* @param restTemplate The RestTemplate to use
* @param baseUrl The base URL of the API
* @param endpoint The endpoint to call (without the base URL)
* @param responseType The expected response type
* @return The response entity
*/
public static <T> ResponseEntity<T> get(RestTemplate restTemplate, String baseUrl, String endpoint, Class<T> responseType) {
String url = baseUrl + endpoint;
return restTemplate.getForEntity(url, responseType);
}

/**
* Performs a GET request to the specified endpoint with a parameterized type reference.
*
* @param restTemplate The RestTemplate to use
* @param baseUrl The base URL of the API
* @param endpoint The endpoint to call (without the base URL)
* @param typeReference The parameterized type reference for the response
* @return The response entity
*/
public static <T> ResponseEntity<T> get(RestTemplate restTemplate, String baseUrl, String endpoint, ParameterizedTypeReference<T> typeReference) {
String url = baseUrl + endpoint;
return restTemplate.exchange(url, HttpMethod.GET, null, typeReference);
}

/**
* Performs a POST request to the specified endpoint with the given request body.
*
* @param restTemplate The RestTemplate to use
* @param baseUrl The base URL of the API
* @param endpoint The endpoint to call (without the base URL)
* @param requestBody The request body
* @param responseType The expected response type
* @return The response entity
*/
public static <T> ResponseEntity<T> post(RestTemplate restTemplate, String baseUrl, String endpoint, Object requestBody, Class<T> responseType) {
String url = baseUrl + endpoint;
return restTemplate.postForEntity(url, requestBody, responseType);
}

/**
* Performs a POST request to the specified endpoint with the given request body and a parameterized type reference.
*
* @param restTemplate The RestTemplate to use
* @param baseUrl The base URL of the API
* @param endpoint The endpoint to call (without the base URL)
* @param requestBody The request body
* @param typeReference The parameterized type reference for the response
* @return The response entity
*/
public static <T> ResponseEntity<T> post(RestTemplate restTemplate, String baseUrl, String endpoint, Object requestBody, ParameterizedTypeReference<T> typeReference) {
String url = baseUrl + endpoint;
HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody);
return restTemplate.exchange(url, HttpMethod.POST, requestEntity, typeReference);
}

/**
* Performs a PUT request to the specified endpoint with the given request body.
*
* @param restTemplate The RestTemplate to use
* @param baseUrl The base URL of the API
* @param endpoint The endpoint to call (without the base URL)
* @param requestBody The request body
* @param responseType The expected response type
* @return The response entity
*/
public static <T> ResponseEntity<T> put(RestTemplate restTemplate, String baseUrl, String endpoint, Object requestBody, Class<T> responseType) {
String url = baseUrl + endpoint;
HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody);
return restTemplate.exchange(url, HttpMethod.PUT, requestEntity, responseType);
}

/**
* Performs a PUT request to the specified endpoint with the given request body and a parameterized type reference.
*
* @param restTemplate The RestTemplate to use
* @param baseUrl The base URL of the API
* @param endpoint The endpoint to call (without the base URL)
* @param requestBody The request body
* @param typeReference The parameterized type reference for the response
* @return The response entity
*/
public static <T> ResponseEntity<T> put(RestTemplate restTemplate, String baseUrl, String endpoint, Object requestBody, ParameterizedTypeReference<T> typeReference) {
String url = baseUrl + endpoint;
HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody);
return restTemplate.exchange(url, HttpMethod.PUT, requestEntity, typeReference);
}

/**
* Performs a DELETE request to the specified endpoint.
*
* @param restTemplate The RestTemplate to use
* @param baseUrl The base URL of the API
* @param endpoint The endpoint to call (without the base URL)
* @param responseType The expected response type
* @return The response entity
*/
public static <T> ResponseEntity<T> delete(RestTemplate restTemplate, String baseUrl, String endpoint, Class<T> responseType) {
String url = baseUrl + endpoint;
HttpEntity<Object> requestEntity = new HttpEntity<>(null);
return restTemplate.exchange(url, HttpMethod.DELETE, requestEntity, responseType);
}

/**
* Performs a DELETE request to the specified endpoint with a parameterized type reference.
*
* @param restTemplate The RestTemplate to use
* @param baseUrl The base URL of the API
* @param endpoint The endpoint to call (without the base URL)
* @param typeReference The parameterized type reference for the response
* @return The response entity
*/
public static <T> ResponseEntity<T> delete(RestTemplate restTemplate, String baseUrl, String endpoint, ParameterizedTypeReference<T> typeReference) {
String url = baseUrl + endpoint;
HttpEntity<Object> requestEntity = new HttpEntity<>(null);
return restTemplate.exchange(url, HttpMethod.DELETE, requestEntity, typeReference);
}
}
Loading
Loading