Skip to content

Commit d35afa4

Browse files
GMishxheliocastro
authored andcommitted
test(components): add test for component filter
Add test cases for filtering components with more than 1 field. Signed-off-by: Gaurav Mishra <mishra.gaurav@siemens.com>
1 parent 0683857 commit d35afa4

3 files changed

Lines changed: 63 additions & 3 deletions

File tree

rest/resource-server/src/docs/asciidoc/components.adoc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,26 @@ include::{snippets}/should_document_get_components_by_name/http-response.adoc[]
122122
include::{snippets}/should_document_get_components_by_name/links.adoc[]
123123

124124

125+
[[resources-components-list-by-type-and-createdon]]
126+
==== Filtering with more fields
127+
128+
A `GET` request to fetch filtered list of service components.
129+
130+
Note : send query parameter's value in encoded format. (Reference: `https://datatracker.ietf.org/doc/html/rfc3986`)
131+
132+
===== Response structure
133+
include::{snippets}/should_document_get_components_by_type_and_created_on/response-fields.adoc[]
134+
135+
===== Example request
136+
include::{snippets}/should_document_get_components_by_type_and_created_on/curl-request.adoc[]
137+
138+
===== Example response
139+
include::{snippets}/should_document_get_components_by_type_and_created_on/http-response.adoc[]
140+
141+
===== Links
142+
include::{snippets}/should_document_get_components_by_type_and_created_on/links.adoc[]
143+
144+
125145
[[resources-components-list-by-type]]
126146
==== Listing by type
127147

rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/component/ComponentController.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
package org.eclipse.sw360.rest.resourceserver.component;
1414

15+
import com.google.common.collect.Sets;
1516
import io.swagger.v3.oas.annotations.Operation;
1617
import io.swagger.v3.oas.annotations.Parameter;
1718
import io.swagger.v3.oas.annotations.enums.ParameterIn;
@@ -1163,9 +1164,7 @@ public ResponseEntity<RequestStatus> splitComponents(
11631164
&& !fieldValue.toString().equalsIgnoreCase(filterSet.iterator().next())) {
11641165
return false;
11651166
} else if (fieldValue instanceof Set) {
1166-
Set<String> fieldValueSet = (Set<String>) fieldValue;
1167-
fieldValueSet.retainAll(filterSet);
1168-
if (fieldValueSet.isEmpty()) {
1167+
if (Sets.intersection(filterSet, (Set<String>) fieldValue).isEmpty()) {
11691168
return false;
11701169
}
11711170
}

rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ComponentSpecTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,47 @@ public void should_document_get_components_by_name() throws Exception {
911911
)));
912912
}
913913

914+
@Test
915+
public void should_document_get_components_by_type_and_created_on() throws Exception {
916+
mockMvc.perform(get("/api/components")
917+
.header("Authorization", TestHelper.generateAuthHeader(testUserId, testUserPassword))
918+
.queryParam("componentType", angularComponent.getComponentType().toString())
919+
.queryParam("createdOn", angularComponent.getCreatedOn())
920+
.queryParam("categories", "javascript, sql")
921+
.queryParam("luceneSearch", "false")
922+
.queryParam("page", "0")
923+
.queryParam("page_entries", "5")
924+
.queryParam("sort", "name,desc")
925+
.accept(MediaTypes.HAL_JSON))
926+
.andExpect(status().isOk())
927+
.andDo(this.documentationHandler.document(
928+
queryParameters(
929+
parameterWithName("componentType").description("Filter for type"),
930+
parameterWithName("createdOn").description("Filter for component creation date"),
931+
parameterWithName("categories").description("Filter for categories"),
932+
parameterWithName("luceneSearch").description("Filter with exact match or lucene match."),
933+
parameterWithName("page").description("Page of components"),
934+
parameterWithName("page_entries").description("Amount of components per page"),
935+
parameterWithName("sort").description("Defines order of the components")
936+
),
937+
links(
938+
linkWithRel("curies").description("Curies are used for online documentation"),
939+
linkWithRel("first").description("Link to first page"),
940+
linkWithRel("last").description("Link to last page")
941+
),
942+
responseFields(
943+
subsectionWithPath("_embedded.sw360:components.[]name").description("The name of the component"),
944+
subsectionWithPath("_embedded.sw360:components.[]componentType").description("The component type, possible values are: " + Arrays.asList(ComponentType.values())),
945+
subsectionWithPath("_embedded.sw360:components").description("An array of <<resources-components, Components resources>>"),
946+
subsectionWithPath("_links").description("<<resources-index-links,Links>> to other resources"),
947+
fieldWithPath("page").description("Additional paging information"),
948+
fieldWithPath("page.size").description("Number of components per page"),
949+
fieldWithPath("page.totalElements").description("Total number of all existing components"),
950+
fieldWithPath("page.totalPages").description("Total number of pages"),
951+
fieldWithPath("page.number").description("Number of the current page")
952+
)));
953+
}
954+
914955
@Test
915956
public void should_document_update_component() throws Exception {
916957
ComponentDTO updateComponent = new ComponentDTO();

0 commit comments

Comments
 (0)