Skip to content

Commit

Permalink
Merge pull request #3761 from rcsilva83/search-by-group
Browse files Browse the repository at this point in the history
  • Loading branch information
nscuro authored May 27, 2024
2 parents f08a24d + f894e8f commit 7a27645
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public PaginatedResult getComponents(final Project project, final boolean includ
final PaginatedResult result;
String querySring ="SELECT FROM org.dependencytrack.model.Component WHERE project == :project ";
if (filter != null) {
querySring += " && (project == :project) && name.toLowerCase().matches(:name)";
querySring += " && (project == :project) && (name.toLowerCase().matches(:filter) || group.toLowerCase().matches(:filter))";
}
if (onlyOutdated) {
// Components are considered outdated when metadata does exists, but the version is different than latestVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,38 @@ public void getAllDirectComponentsTest() throws MalformedPackageURLException {
assertThat(json).hasSize(100);
}

@Test
public void getComponentsByNameTest() throws MalformedPackageURLException {
final Project project = prepareProject();

final Response response = jersey.target(V1_COMPONENT + "/project/" + project.getUuid())
.queryParam("searchText", "name-1")
.request()
.header(X_API_KEY, apiKey)
.get(Response.class);
assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
assertThat(response.getHeaderString(TOTAL_COUNT_HEADER)).isEqualTo("111"); // 75 outdated direct dependencies

final JsonArray json = parseJsonArray(response);
assertThat(json).hasSize(100);
}

@Test
public void getComponentsByGroupTest() throws MalformedPackageURLException {
final Project project = prepareProject();

final Response response = jersey.target(V1_COMPONENT + "/project/" + project.getUuid())
.queryParam("searchText", "group")
.request()
.header(X_API_KEY, apiKey)
.get(Response.class);
assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
assertThat(response.getHeaderString(TOTAL_COUNT_HEADER)).isEqualTo("1000"); // 75 outdated direct dependencies

final JsonArray json = parseJsonArray(response);
assertThat(json).hasSize(100);
}

@Test
public void getComponentByUuidTest() {
Project project = qm.createProject("Acme Application", null, null, null, null, null, true, false);
Expand Down

0 comments on commit 7a27645

Please sign in to comment.