chore(release): v1.0 #1
@ -16,6 +16,12 @@
|
|||||||
<name>rest-api</name>
|
<name>rest-api</name>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.techivw</groupId>
|
<groupId>com.techivw</groupId>
|
||||||
<artifactId>domain</artifactId>
|
<artifactId>domain</artifactId>
|
||||||
@ -28,4 +34,16 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<argLine>-javaagent:${settings.localRepository}/net/bytebuddy/byte-buddy-agent/1.15.11/byte-buddy-agent-1.15.11.jar</argLine>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -0,0 +1,77 @@
|
|||||||
|
package com.techivw.webprice.infrastructure.in.controllers.adapters;
|
||||||
|
|
||||||
|
import com.techivw.webprice.application.ports.in.PriceServicePort;
|
||||||
|
import com.techivw.webprice.domain.Price;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
@WebMvcTest
|
||||||
|
@ContextConfiguration(classes = PriceControllerAdapter.class)
|
||||||
|
@ActiveProfiles("test")
|
||||||
|
public class PriceControllerAdapterTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
@MockitoBean
|
||||||
|
private PriceServicePort priceServicePort;
|
||||||
|
|
||||||
|
private static final Long PRODUCT_ID = 35455L;
|
||||||
|
private static final Long BRAND_ID = 1L;
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource("testCases")
|
||||||
|
void testGetPrice(String testName, String dateTime, double expectedPrice) throws Exception {
|
||||||
|
LocalDateTime date = LocalDateTime.parse(dateTime);
|
||||||
|
|
||||||
|
Price mockPrice = createPrice(date.minusHours(1), date.plusHours(1), 1, expectedPrice, 1);
|
||||||
|
when(priceServicePort.getPriceWithHighestPriorityByDateTimeAndProductIdAndBrandId(date, PRODUCT_ID, BRAND_ID))
|
||||||
|
.thenReturn(mockPrice);
|
||||||
|
|
||||||
|
mockMvc.perform(get("/price")
|
||||||
|
.param("dateTime", dateTime)
|
||||||
|
.param("productId", String.valueOf(PRODUCT_ID))
|
||||||
|
.param("brandId", String.valueOf(BRAND_ID)))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.price").value(expectedPrice));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Stream<Arguments> testCases() {
|
||||||
|
return Stream.of(
|
||||||
|
Arguments.of("Test 1", "2020-06-14T10:00:00", 35.50),
|
||||||
|
Arguments.of("Test 2", "2020-06-14T16:00:00", 25.45),
|
||||||
|
Arguments.of("Test 3", "2020-06-14T21:00:00", 35.50),
|
||||||
|
Arguments.of("Test 4", "2020-06-15T10:00:00", 30.50),
|
||||||
|
Arguments.of("Test 5", "2020-06-16T21:00:00", 38.95)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Price createPrice(LocalDateTime startDate, LocalDateTime endDate, long priceList, double price, int priority) {
|
||||||
|
return Price.builder()
|
||||||
|
.brandId(BRAND_ID)
|
||||||
|
.productId(PRODUCT_ID)
|
||||||
|
.startDate(startDate)
|
||||||
|
.endDate(endDate)
|
||||||
|
.priceList(priceList)
|
||||||
|
.price(BigDecimal.valueOf(price))
|
||||||
|
.priority(priority)
|
||||||
|
.currency("EUR")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user