-
Notifications
You must be signed in to change notification settings - Fork 2
UFAL/Release hotfix 2026 02 26 - Merge PR #1260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7623cd1
78f9648
98edc1d
475b25a
ff0427e
2f03408
0f1ff8b
a7fa356
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -207,8 +207,11 @@ public InputStream get(String file, String accessToken) { | |
| break; | ||
| } | ||
|
|
||
| // do not close this httpClient | ||
| result = getResponse.getEntity().getContent(); | ||
| // the client will be closed, we need to copy the response stream to a new one that we can return | ||
| try (InputStream is = getResponse.getEntity().getContent()) { | ||
| byte[] bytes = is.readAllBytes(); | ||
| result = new java.io.ByteArrayInputStream(bytes); | ||
| } | ||
|
Comment on lines
+210
to
+214
|
||
| } | ||
| } catch (MalformedURLException e1) { | ||
| getGotError(e1, url + '/' + file); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /** | ||
| * The contents of this file are subject to the license and copyright | ||
| * detailed in the LICENSE and NOTICE files at the root of the source | ||
| * tree and available online at | ||
| * | ||
| * http://www.dspace.org/license/ | ||
| */ | ||
| package org.dspace.external; | ||
|
|
||
| import static org.junit.Assert.assertTrue; | ||
| import static org.mockito.Mockito.doReturn; | ||
| import static org.mockito.Mockito.spy; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.nio.charset.StandardCharsets; | ||
|
|
||
| import eu.openaire.jaxb.model.Response; | ||
| import okhttp3.mockwebserver.MockResponse; | ||
| import okhttp3.mockwebserver.MockWebServer; | ||
| import org.apache.http.client.methods.HttpGet; | ||
| import org.apache.http.impl.client.CloseableHttpClient; | ||
| import org.apache.http.impl.client.HttpClientBuilder; | ||
| import org.dspace.app.client.DSpaceHttpClientFactory; | ||
| import org.junit.Test; | ||
| import org.mockito.MockedStatic; | ||
| import org.mockito.Mockito; | ||
|
|
||
|
|
||
| public class OpenAIRERestConnectorTest { | ||
|
|
||
| @Test | ||
| public void searchProjectByKeywords() { | ||
| try (InputStream is = this.getClass().getResourceAsStream("openaire-projects.xml"); | ||
| MockWebServer mockServer = new MockWebServer()) { | ||
| String projects = new String(is.readAllBytes(), StandardCharsets.UTF_8) | ||
| .replaceAll("( mushroom)", "( DEADBEEF)"); | ||
| mockServer.enqueue(new MockResponse().setResponseCode(200).setBody(projects)); | ||
|
|
||
| // setup mocks so we don't have to set whole DSpace kernel etc. | ||
| // still, the idea is to test how the get method behaves | ||
| CloseableHttpClient httpClient = spy(HttpClientBuilder.create().build()); | ||
| doReturn(httpClient.execute(new HttpGet(mockServer.url("").toString()))) | ||
| .when(httpClient).execute(Mockito.any()); | ||
|
|
||
|
Comment on lines
+41
to
+46
|
||
| DSpaceHttpClientFactory mock = Mockito.mock(DSpaceHttpClientFactory.class); | ||
| when(mock.build()).thenReturn(httpClient); | ||
|
|
||
| try (MockedStatic<DSpaceHttpClientFactory> mockedFactory = | ||
| Mockito.mockStatic(DSpaceHttpClientFactory.class)) { | ||
| mockedFactory.when(DSpaceHttpClientFactory::getInstance).thenReturn(mock); | ||
| OpenAIRERestConnector connector = new OpenAIRERestConnector(mockServer.url("").toString()); | ||
| Response response = connector.searchProjectByKeywords(0, 10, "keyword"); | ||
| // Basically check it doesn't throw UnmarshallerException and that we are getting our mocked response | ||
| assertTrue("Expected the query to contain the replaced keyword", | ||
| response.getHeader().getQuery().contains("DEADBEEF")); | ||
| } | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } | ||
|
Comment on lines
+59
to
+61
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,155 @@ | ||||||
| /** | ||||||
| * The contents of this file are subject to the license and copyright | ||||||
| * detailed in the LICENSE and NOTICE files at the root of the source | ||||||
| * tree and available online at | ||||||
| * | ||||||
| * http://www.dspace.org/license/ | ||||||
| */ | ||||||
| package org.dspace.identifier; | ||||||
|
|
||||||
| import static org.hamcrest.CoreMatchers.equalTo; | ||||||
| import static org.hamcrest.CoreMatchers.not; | ||||||
| import static org.hamcrest.CoreMatchers.startsWith; | ||||||
| import static org.hamcrest.MatcherAssert.assertThat; | ||||||
|
|
||||||
| import java.text.SimpleDateFormat; | ||||||
| import java.util.ArrayList; | ||||||
| import java.util.Calendar; | ||||||
| import java.util.List; | ||||||
| import java.util.TimeZone; | ||||||
|
|
||||||
| import org.dspace.AbstractIntegrationTestWithDatabase; | ||||||
| import org.dspace.builder.CollectionBuilder; | ||||||
| import org.dspace.builder.CommunityBuilder; | ||||||
| import org.dspace.builder.ItemBuilder; | ||||||
| import org.dspace.builder.VersionBuilder; | ||||||
| import org.dspace.content.Collection; | ||||||
| import org.dspace.content.Item; | ||||||
| import org.dspace.content.MetadataValue; | ||||||
| import org.dspace.content.factory.ContentServiceFactory; | ||||||
| import org.dspace.content.service.InstallItemService; | ||||||
| import org.dspace.content.service.ItemService; | ||||||
| import org.dspace.kernel.ServiceManager; | ||||||
| import org.dspace.services.factory.DSpaceServicesFactory; | ||||||
| import org.dspace.workflow.WorkflowItem; | ||||||
| import org.dspace.workflow.WorkflowItemService; | ||||||
| import org.dspace.workflow.factory.WorkflowServiceFactory; | ||||||
| import org.junit.Before; | ||||||
| import org.junit.Test; | ||||||
|
|
||||||
| /** | ||||||
| * Unit Tests for ClarinVersionedHandleIdentifierProvider | ||||||
| * | ||||||
| * @authorMilan Kuchtiak | ||||||
|
||||||
| * @authorMilan Kuchtiak | |
| * @author Milan Kuchtiak |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a checkstyle suppression for
OpenAIRERestConnectorTest.javaweakens the repo’s enforced convention (avoid directHttpClientBuilder.create()usage). It would be better to adjust the test to comply (e.g., mockCloseableHttpClient) and remove this suppression.