diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 70e975788409d5399a12b5c584d560b43d8a7a7c..41c39e7f5c1e4ab0934777c19bd9e7024d43037c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -126,7 +126,7 @@ test-backend-table: stage: test-backend script: - "./fda-table-service/rest-service/src/test/resources/integration-test.before" - - "mvn -f fda-table-service/pom.xml clean test verify" + - "mvn -f fda-table-service/pom.xml -DZENODO_API_KEY=${ZENODO_API_KEY} clean test verify" - "./fda-table-service/rest-service/src/test/resources/integration-test.after" - cat ./fda-table-service/report/target/site/jacoco-aggregate/index.html needs: diff --git a/fda-table-service/gateway/src/main/java/at/tuwien/config/ZenodoConfig.java b/fda-table-service/gateway/src/main/java/at/tuwien/config/ZenodoConfig.java index c1717554871ba05be5addb80b614ed4ea33feae4..15df9c3db026b5b9872b1cd43ab093c46e285a7b 100644 --- a/fda-table-service/gateway/src/main/java/at/tuwien/config/ZenodoConfig.java +++ b/fda-table-service/gateway/src/main/java/at/tuwien/config/ZenodoConfig.java @@ -8,14 +8,18 @@ import org.springframework.context.annotation.Configuration; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.DefaultUriTemplateHandler; +import javax.validation.constraints.NotNull; + @Configuration public class ZenodoConfig { @Getter + @NotNull @Value("${zenodo.endpoint}") private String zenodoEndpoint; @Getter + @NotNull @Value("${zenodo.api_key}") private String zenodoApiKey; diff --git a/fda-table-service/gateway/src/main/java/at/tuwien/gateway/ZenodoGateway.java b/fda-table-service/gateway/src/main/java/at/tuwien/gateway/ZenodoGateway.java index e5954944168176b96dcd098d66783c589e25331a..02564d73edd151f6bdc215abd4026c46fea7fce4 100644 --- a/fda-table-service/gateway/src/main/java/at/tuwien/gateway/ZenodoGateway.java +++ b/fda-table-service/gateway/src/main/java/at/tuwien/gateway/ZenodoGateway.java @@ -34,9 +34,7 @@ public class ZenodoGateway { if (response.getBody() == null) { throw new ZenodoApiException("Endpoint returned null body"); } - if (response.getBody().length == 0) { - throw new ZenodoApiException("Endpoint returned empty body"); - } + return Arrays.asList(response.getBody()); } } diff --git a/fda-table-service/rest-service/src/test/java/at/tuwien/gateway/ZenodoIntegrationTest.java b/fda-table-service/rest-service/src/test/java/at/tuwien/gateway/ZenodoIntegrationTest.java new file mode 100644 index 0000000000000000000000000000000000000000..6014546d4954fd6b39e9ddd60e698262da2516f5 --- /dev/null +++ b/fda-table-service/rest-service/src/test/java/at/tuwien/gateway/ZenodoIntegrationTest.java @@ -0,0 +1,52 @@ +package at.tuwien.gateway; + +import at.tuwien.api.zenodo.deposit.DepositDto; +import at.tuwien.config.ReadyConfig; +import at.tuwien.exception.ZenodoApiException; +import at.tuwien.exception.ZenodoAuthenticationException; +import com.rabbitmq.client.Channel; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.web.client.RestTemplate; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +@SpringBootTest +@ExtendWith(SpringExtension.class) +public class ZenodoIntegrationTest extends BaseUnitTest { + + @MockBean + private Channel channel; + + @MockBean + private ReadyConfig readyConfig; + + @Autowired + private ZenodoGateway zenodoGateway; + + @Autowired + private RestTemplate zenodoTemplate; + + @Test + public void listDeposit_succeeds() throws ZenodoApiException, ZenodoAuthenticationException { + + /* test */ + final List<DepositDto> response = zenodoGateway.listDeposits(); + assertEquals(1, response.size()); + assertEquals(DEPOSIT_1_ID, response.get(0).getId()); + } + +} \ No newline at end of file diff --git a/fda-table-service/rest-service/src/test/resources/application.properties b/fda-table-service/rest-service/src/test/resources/application.properties index 1e126e037d336c1cdc4725614ae057a3cb7d35ed..5002d6fb8f86b0ef84d19bef2f1e169fbd910a59 100644 --- a/fda-table-service/rest-service/src/test/resources/application.properties +++ b/fda-table-service/rest-service/src/test/resources/application.properties @@ -17,5 +17,4 @@ spring.jpa.show-sql=false fda.mapping.path: /tmp fda.table.path: /tmp -zenodo.api_key: df1eea59-7244-4930-9ee2-a48ed7dad615 zenodo.endpoint: https://sandbox.zenodo.org/ \ No newline at end of file