Skip to content

Commit

Permalink
Merge pull request #820 from catenax-ng/feature/TRACEFOSS-2834-case-i…
Browse files Browse the repository at this point in the history
…nsensitive-autocomplete-for-parts

feature(tx-backend): TRACEFOSS-2834 case insensitivity to parts autocomplete
  • Loading branch information
ds-mwesener authored Dec 5, 2023
2 parents 1a46242 + 851c961 commit 74fd112
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Changed detailed part view action from clicking on list item to a menu action column
- Changed FE fieldName mapping to fix bug for properties catenaxSiteId and function
- Fix of global search field
- Parts autocomplete API now is case insensitive when using "startWith" parameter

### Removed
- removed asset filters ( qualityInvestigationIdsInStatusActive, qualityInvestigationIdsInStatusActive )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ public List<String> getDistinctAssetFieldValues(

List<Predicate> predicates = new ArrayList<>();
if (nonNull(startWith)) {
predicates.add(builder.like(fieldPath, startWith + "%"));
predicates.add(
builder.like(
builder.lower(fieldPath),
startWith.toLowerCase() + "%")
);
}

if (nonNull(owner)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ void shouldReturnAssetsWithManufacturerName() throws JoseException {
.body("content.manufacturerName", everyItem(not(equalTo(assetsSupport.emptyText()))));
}

// Deprecated please remove once controller has been removed
@Test
void shoulReturnSupplierAssets() throws JoseException {
//GIVEN
Expand All @@ -94,7 +93,6 @@ void shoulReturnSupplierAssets() throws JoseException {
.body("totalItems", equalTo(12));
}

// Deprecated please remove once controller has been removed
@Test
void shouldReturnOwnAssets() throws JoseException {
//GIVEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.restassured.http.ContentType;
import org.eclipse.tractusx.traceability.integration.IntegrationTestSpecification;
import org.eclipse.tractusx.traceability.integration.common.support.AssetsSupport;
import org.hamcrest.Matchers;
import org.jose4j.lang.JoseException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -119,6 +120,68 @@ void givenNotEnumTypeFieldNameAndSizeAndOwnerOwn_whenCallDistinctFilterValues_th
.body("size()", is(1));
}

@Test
void givenBusinessPartnerLowercase_whenCallDistinctFilterValues_thenProperResponse() throws JoseException {
// given
assetsSupport.defaultAssetsStored();
String fieldName = "businessPartner";
String resultLimit = "100";
String startWith = "bpnl";

// then
given()
.header(oAuth2Support.jwtAuthorization(ADMIN))
.contentType(ContentType.JSON)
.log().all()
.when()
.param("fieldName", fieldName)
.param("size", resultLimit)
.param("startWith", startWith)
.get("/api/assets/as-built/distinctFilterValues")
.then()
.log().all()
.statusCode(200)
.assertThat()
.body(".", Matchers.containsInRelativeOrder(
"BPNL00000003AXS3",
"BPNL00000003AYRE",
"BPNL00000003B0Q0",
"BPNL00000003B2OM",
"BPNL00000003B3NX",
"BPNL00000003B5MJ"));
}

@Test
void givenBusinessPartnerMixedCase_whenCallDistinctFilterValues_thenProperResponse() throws JoseException {
// given
assetsSupport.defaultAssetsStored();
String fieldName = "businessPartner";
String resultLimit = "100";
String startWith = "bpNl";

// then
given()
.header(oAuth2Support.jwtAuthorization(ADMIN))
.contentType(ContentType.JSON)
.log().all()
.when()
.param("fieldName", fieldName)
.param("size", resultLimit)
.param("startWith", startWith)
.get("/api/assets/as-built/distinctFilterValues")
.then()
.log().all()
.statusCode(200)
.assertThat()
.body(".", Matchers.containsInRelativeOrder(
"BPNL00000003AXS3",
"BPNL00000003AYRE",
"BPNL00000003B0Q0",
"BPNL00000003B2OM",
"BPNL00000003B3NX",
"BPNL00000003B5MJ"));
}

@Test
void givenNotExistentOwnerEnumValue_whenCallDistinctFilterValues_thenProperResponse() throws JoseException {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.tractusx.traceability.assets.infrastructure.asplanned.repository.JpaAssetAsPlannedRepository;
import org.eclipse.tractusx.traceability.integration.IntegrationTestSpecification;
import org.eclipse.tractusx.traceability.integration.common.support.AssetsSupport;
import org.hamcrest.Matchers;
import org.jose4j.lang.JoseException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -118,6 +119,56 @@ void givenNotEnumTypeFieldNameAndOwnerOwn_whenCallDistinctFilterValues_thenPrope
.body("size()", is(1));
}

@Test
void givenIdShortLowerCase_whenCallDistinctFilterValues_thenProperResponse() throws JoseException {
// given
assetsSupport.defaultAssetsAsPlannedStored();
String fieldName = "idShort";
String startWith = "vehicle";

// then
given()
.header(oAuth2Support.jwtAuthorization(ADMIN))
.contentType(ContentType.JSON)
.log().all()
.when()
.param("fieldName", fieldName)
.param("startWith", startWith)
.get("/api/assets/as-planned/distinctFilterValues")
.then()
.log().all()
.statusCode(200)
.assertThat()
.body(".", Matchers.containsInRelativeOrder(
"VehicleModelA",
"VehicleModelB"));
}

@Test
void givenIdShortMixedCase_whenCallDistinctFilterValues_thenProperResponse() throws JoseException {
// given
assetsSupport.defaultAssetsAsPlannedStored();
String fieldName = "idShort";
String startWith = "vehicleMODEL";

// then
given()
.header(oAuth2Support.jwtAuthorization(ADMIN))
.contentType(ContentType.JSON)
.log().all()
.when()
.param("fieldName", fieldName)
.param("startWith", startWith)
.get("/api/assets/as-planned/distinctFilterValues")
.then()
.log().all()
.statusCode(200)
.assertThat()
.body(".", Matchers.containsInRelativeOrder(
"VehicleModelA",
"VehicleModelB"));
}

@Test
void givenWrongOwnerEnum_whenCallDistinctFilterValues_thenProperResponse() throws JoseException {
// given
Expand Down

0 comments on commit 74fd112

Please sign in to comment.