diff --git a/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayConnectorUtils.java b/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayConnectorUtils.java index 8473c94..f72a93d 100644 --- a/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayConnectorUtils.java +++ b/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayConnectorUtils.java @@ -29,6 +29,7 @@ import eu.europa.ec.dgc.gateway.connector.model.QueryParameter; import eu.europa.ec.dgc.gateway.connector.model.TrustedIssuer; import eu.europa.ec.dgc.signing.SignedCertificateMessageParser; +import eu.europa.ec.dgc.signing.SignedMessageParser; import eu.europa.ec.dgc.signing.SignedStringMessageParser; import eu.europa.ec.dgc.utils.CertificateUtils; import feign.FeignException; @@ -158,7 +159,7 @@ boolean checkTrustAnchorSignature(TrustListItemDto trustListItem, List void setQueryParameter(QueryParameter queryPa * result in a list of "CSCA" and "UPLOAD" certificates with at least one matching property. */ public void setQueryParameter(QueryParameter queryParameter, List values) { - if (!queryParameter.getArrayValue() && values.size() > 1) { + if (Boolean.FALSE.equals(queryParameter.getArrayValue()) && values.size() > 1) { throw new IllegalArgumentException("Only one value is allowed for non-array query parameters."); } diff --git a/src/test/java/eu/europa/ec/dgc/gateway/connector/TrustedIssuerDownloadConnectorTest.java b/src/test/java/eu/europa/ec/dgc/gateway/connector/TrustedIssuerDownloadConnectorTest.java index 1f93ce7..ae3ba4d 100644 --- a/src/test/java/eu/europa/ec/dgc/gateway/connector/TrustedIssuerDownloadConnectorTest.java +++ b/src/test/java/eu/europa/ec/dgc/gateway/connector/TrustedIssuerDownloadConnectorTest.java @@ -21,6 +21,7 @@ package eu.europa.ec.dgc.gateway.connector; import eu.europa.ec.dgc.gateway.connector.client.DgcGatewayConnectorRestClient; +import eu.europa.ec.dgc.gateway.connector.model.QueryParameter; import eu.europa.ec.dgc.gateway.connector.model.TrustedIssuer; import eu.europa.ec.dgc.testdata.TrustedIssuerTestHelper; import feign.FeignException; @@ -37,6 +38,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.ResponseEntity; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.when; @@ -91,4 +93,30 @@ private Request dummyRequest() { return Request.create(Request.HttpMethod.GET, "url", new HashMap<>(), null, new RequestTemplate()); } + @Test + void setQueryParameters() throws Exception { + Map param = new HashMap<>(); + param.put("country","DE"); + + when(restClientMock.downloadTrustedIssuers(param)) + .thenReturn(ResponseEntity.ok( + List.of(trustedIssuerTestHelper.createTrustedIssuer("DE")))); + + connector.setQueryParameter(QueryParameter.COUNTRY_CODE, "DE"); + List result = connector.getTrustedIssuers(); + + Assertions.assertEquals(1, result.size()); + Assertions.assertEquals("DE", result.get(0).getCountry()); + + connector.setQueryParameter(QueryParameter.WITH_FEDERATION, List.of(true,false)); + + } + + @Test + public void setWrongQueryFormat() { + assertThrows(IllegalArgumentException.class, () -> { + connector.setQueryParameter(QueryParameter.WITH_FEDERATION, List.of(true,false)); + }); + } + }