Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: code refactor to fix configuration #427

Merged
merged 8 commits into from
Oct 29, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ca.bc.gov.restapi.results.common.endpoint;

import ca.bc.gov.restapi.results.common.service.OpenMapsService;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -12,7 +12,7 @@
*/
@RestController
@RequestMapping("/api/feature-service")
@AllArgsConstructor
@RequiredArgsConstructor
public class FeatureServiceEndpoint {

private final OpenMapsService openMapsService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package ca.bc.gov.restapi.results.common.pagination;

import java.util.List;
import lombok.Getter;
import lombok.Setter;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.With;

/** Holds an API response with pagination information and data. */
@Getter
@Setter
/**
* Holds an API response with pagination information and data.
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@With
@Builder
public class PaginatedResult<T> {

private int pageIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

import jakarta.validation.constraints.Positive;
import jakarta.validation.constraints.PositiveOrZero;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;

/**
* Pagination parameters to be used in the processing of HTTP GET requests.
*
* @param page The page to be returned. Zero-based, and must be non-negative; defaults to 0
* @param perPage The maximum number of results in each page. Defaults to 20
*/
public record PaginationParameters(@PositiveOrZero Integer page, @Positive Integer perPage) {
public record PaginationParameters(
@PositiveOrZero(message = "Page number needs to be zero or a positive value")
Integer page,
@Positive(message = "Page size needs to be a positive value")
Integer perPage
) {

/**
* Build an instance of {@link PaginationParameters}, using the default values for {@code page}
Expand All @@ -23,4 +30,8 @@ public record PaginationParameters(@PositiveOrZero Integer page, @Positive Integ
perPage = 5;
}
}

public Pageable toPageable(int maxPageSize) {
return PageRequest.of(page, maxPageSize);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ForestClientApiProvider {
*/
public Optional<ForestClientDto> fetchClientByNumber(String number) {

log.info("Starting {} request to /clients/findByClientNumber/{number}", PROVIDER);
log.info("Starting {} request to /clients/findByClientNumber/{}", PROVIDER,number);

try {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package ca.bc.gov.restapi.results.common.endpoint;

import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.okJson;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import ca.bc.gov.restapi.results.extensions.AbstractTestContainerIntegrationTest;
import ca.bc.gov.restapi.results.extensions.WiremockLogNotifier;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.client.AutoConfigureMockRestServiceServer;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;

@WithMockUser(roles = "user_read")
@AutoConfigureMockMvc
@DisplayName("Integrated Test | Feature Service Endpoint")
class FeatureServiceEndpointIntegrationTest extends AbstractTestContainerIntegrationTest {

@Autowired
private MockMvc mockMvc;

@RegisterExtension
static WireMockExtension clientApiStub = WireMockExtension
.newInstance()
.options(
wireMockConfig()
.port(10001)
.notifier(new WiremockLogNotifier())
.asynchronousResponseEnabled(true)
.stubRequestLoggingDisabled(false)
)
.configureStaticDsl(true)
.build();

@Test

@DisplayName("Get opening polygon and properties happy path should succeed")
void getOpeningPolygonAndProperties_happyPath_shouldSucceed() throws Exception {
String openingId = "58993";

clientApiStub.stubFor(
WireMock.get(urlPathEqualTo("/"))
.withQueryParam("service", equalTo("WFS"))
.withQueryParam("version", equalTo("2.0.0"))
.withQueryParam("request", equalTo("GetFeature"))
.withQueryParam("typeName", equalTo("WHSE_FOREST_VEGETATION.RSLT_OPENING_SVW"))
.withQueryParam("outputFormat", equalTo("application/json"))
.withQueryParam("SrsName", equalTo("EPSG:4326"))
.withQueryParam("PROPERTYNAME",
equalTo("OPENING_ID,"
+ "GEOMETRY,"
+ "REGION_NAME,"
+ "REGION_CODE,"
+ "DISTRICT_NAME,"
+ "DISTRICT_CODE,"
+ "CLIENT_NAME,"
+ "CLIENT_NUMBER,"
+ "OPENING_WHEN_CREATED"
))
.withQueryParam("CQL_FILTER", equalTo("OPENING_ID=" + openingId))
.willReturn(okJson("""
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"id": "WHSE_FOREST_VEGETATION.RSLT_OPENING_SVW.fid-6f119ee7_19129391292_7c7b",
"geometry_name": "GEOMETRY",
"properties": {
"OPENING_ID": 58993,
"OPENING_CATEGORY_CODE": "FTML",
"OPENING_STATUS_CODE": "FG",
"REGION_CODE": "ROM",
"REGION_NAME": "Omineca Natural Resource Region",
"DISTRICT_CODE": "DMK",
"DISTRICT_NAME": "Mackenzie Natural Resource District",
"CLIENT_NAME": "CONIFEX MACKENZIE FOREST PRODUCTS INC.",
"CLIENT_NUMBER": "00161229",
"OPENING_WHO_CREATED": "MLSIS",
"OPENING_WHEN_CREATED": "1999-08-26Z",
"OPENING_WHO_UPDATED": "IDIR\\\\\\\\SCAKERLE",
"OPENING_WHEN_UPDATED": "2023-11-14Z",
"OBJECTID": 3869732,
"bbox": [
-125.6056,
56.06894,
-125.59267,
56.07429
]
}
}
]
}
"""))
);

mockMvc
.perform(
get("/api/feature-service/polygon-and-props/{openingId}", openingId)
.header("Content-Type", MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType("application/json"))
.andExpect(jsonPath("$.type").value("FeatureCollection"))
.andExpect(jsonPath("$.features[0].type").value("Feature"))
.andExpect(
jsonPath("$.features[0].id")
.value("WHSE_FOREST_VEGETATION.RSLT_OPENING_SVW.fid-6f119ee7_19129391292_7c7b"))
.andExpect(jsonPath("$.features[0].geometry_name").value("GEOMETRY"))
.andExpect(jsonPath("$.features[0].properties.OPENING_ID").value(openingId))
.andExpect(jsonPath("$.features[0].properties.OPENING_CATEGORY_CODE").value("FTML"))
.andExpect(jsonPath("$.features[0].properties.OPENING_STATUS_CODE").value("FG"))
.andExpect(jsonPath("$.features[0].properties.REGION_CODE").value("ROM"))
.andExpect(
jsonPath("$.features[0].properties.REGION_NAME")
.value("Omineca Natural Resource Region"))
.andExpect(jsonPath("$.features[0].properties.DISTRICT_CODE").value("DMK"))
.andExpect(
jsonPath("$.features[0].properties.DISTRICT_NAME")
.value("Mackenzie Natural Resource District"))
.andExpect(
jsonPath("$.features[0].properties.CLIENT_NAME")
.value("CONIFEX MACKENZIE FOREST PRODUCTS INC."))
.andExpect(jsonPath("$.features[0].properties.CLIENT_NUMBER").value("00161229"))
.andExpect(jsonPath("$.features[0].properties.OPENING_WHO_CREATED").value("MLSIS"))
.andExpect(jsonPath("$.features[0].properties.OPENING_WHEN_CREATED").value("1999-08-26Z"))
.andExpect(
jsonPath("$.features[0].properties.OPENING_WHO_UPDATED").value("IDIR\\\\SCAKERLE"))
.andExpect(jsonPath("$.features[0].properties.OPENING_WHEN_UPDATED").value("2023-11-14Z"))
.andExpect(jsonPath("$.features[0].properties.OBJECTID").value("3869732"))
.andExpect(jsonPath("$.features[0].properties.bbox[0]").value("-125.6056"))
.andExpect(jsonPath("$.features[0].properties.bbox[1]").value("56.06894"))
.andExpect(jsonPath("$.features[0].properties.bbox[2]").value("-125.59267"))
.andExpect(jsonPath("$.features[0].properties.bbox[3]").value("56.07429"))
.andReturn();
}
}

This file was deleted.

Loading
Loading