Skip to content

Commit

Permalink
Merge pull request #909 from catenax-ng/bug/392-add-http-400-response
Browse files Browse the repository at this point in the history
bug: 392 fix http 400 response of filter parameter
  • Loading branch information
ds-mwesener authored Jan 16, 2024
2 parents 3097aee + 4b5948e commit 1e00736
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.eclipse.tractusx.traceability.common.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -33,6 +34,7 @@ public class PageableFilterRequest {
private OwnPageable ownPageable;

@JsonProperty("searchCriteria")
@Valid
private SearchCriteriaRequestParam searchCriteriaRequestParam;

public SearchCriteriaRequestParam getSearchCriteriaRequestParam() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@
@AllArgsConstructor
public class SearchCriteriaRequestParam {
@ArraySchema(arraySchema = @Schema(description = "Filter Criteria", additionalProperties = Schema.AdditionalPropertiesValue.FALSE, example = "owner,EQUAL,OWN"), maxItems = Integer.MAX_VALUE)
private List<@Size(max=1000, message = "Filter string should not be longer than 1000 characters.") String> filter;
List<String> filter;

public List<@Size(max = 1000, message = "Filter string should not be longer than 1000 characters.") String> getFilter() {
return filter;
}

public SearchCriteria toSearchCriteria(BaseRequestFieldMapper fieldMapper) {
ArrayList<SearchCriteriaFilter> filters = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,15 +395,17 @@ void givenAlerts_whenProvideFilterLongerThan1000_thenReturnHttp400() throws Jose
alertNotificationsSupport.defaultAlertsStored();

// when/then
SearchCriteriaRequestParam searchCriteriaRequestParam = new SearchCriteriaRequestParam(List.of("1".repeat(1000)));
SearchCriteriaRequestParam searchCriteriaRequestParam = new SearchCriteriaRequestParam(List.of("1".repeat(1001)));
given()
.header(oAuth2Support.jwtAuthorization(ADMIN))
.body(new PageableFilterRequest(new OwnPageable(0, 10, Collections.emptyList()), searchCriteriaRequestParam))
.contentType(ContentType.JSON)
.when()
.post("/api/alerts/filter")
.then()
.statusCode(400);
.log().all()
.statusCode(400)
.body("message", equalTo("Filter string should not be longer than 1000 characters."));
}

}

0 comments on commit 1e00736

Please sign in to comment.