|
1 | 1 | package edu.ucsb.nceas.mdqengine.scheduler; |
2 | 2 |
|
3 | 3 | import edu.ucsb.nceas.mdqengine.MDQconfig; |
| 4 | +import org.apache.http.client.methods.CloseableHttpResponse; |
| 5 | +import org.apache.http.client.methods.HttpPost; |
| 6 | +import org.apache.http.impl.client.CloseableHttpClient; |
| 7 | +import org.apache.http.impl.client.HttpClients; |
| 8 | +import org.dataone.client.v2.impl.MultipartCNode; |
| 9 | +import org.dataone.client.v2.impl.MultipartMNode; |
4 | 10 | import org.dataone.hashstore.HashStore; |
5 | 11 | import org.dataone.hashstore.HashStoreFactory; |
6 | 12 |
|
|
19 | 25 | import java.util.Properties; |
20 | 26 |
|
21 | 27 | import org.dataone.service.types.v1.Identifier; |
| 28 | +import org.dataone.service.types.v1.Session; |
22 | 29 | import org.dataone.service.types.v2.SystemMetadata; |
23 | 30 | import org.junit.jupiter.api.AfterAll; |
24 | 31 | import org.junit.jupiter.api.BeforeAll; |
25 | | -import org.junit.jupiter.api.Disabled; |
26 | 32 | import org.junit.jupiter.api.Test; |
27 | 33 | import org.junit.jupiter.api.io.TempDir; |
28 | 34 | import org.mockito.MockedStatic; |
|
35 | 41 | import static org.junit.jupiter.api.Assertions.fail; |
36 | 42 | import static org.mockito.ArgumentMatchers.any; |
37 | 43 | import static org.mockito.ArgumentMatchers.anyString; |
| 44 | +import static org.mockito.Mockito.mock; |
38 | 45 | import static org.mockito.Mockito.mockStatic; |
| 46 | +import static org.mockito.Mockito.times; |
| 47 | +import static org.mockito.Mockito.verify; |
| 48 | +import static org.mockito.Mockito.when; |
39 | 49 |
|
40 | 50 | /** |
41 | 51 | * Test class for RequestReportJob |
@@ -161,6 +171,39 @@ public static void overrideConfigFilePathInMDQConfig(String fullPathToMetadigPro |
161 | 171 |
|
162 | 172 | // Junit Tests |
163 | 173 |
|
| 174 | + /** |
| 175 | + * Confirm that a http post request is executed when 'submitReportRequest' is called for a |
| 176 | + * pid with a data object and sysmeta that is available in hashstore |
| 177 | + */ |
| 178 | + @Test |
| 179 | + public void testSubmitReportRequest_pidFoundInHashStore() throws Exception { |
| 180 | + MultipartCNode cnNode = mock(MultipartCNode.class); |
| 181 | + MultipartMNode mnNode = mock(MultipartMNode.class); |
| 182 | + boolean isCN = false; |
| 183 | + Session session = mock(Session.class); |
| 184 | + String qualityServiceUrl = "http://metadig-controller.metadig.svc:8080/quality"; |
| 185 | + String pidStr = testPid; |
| 186 | + String suiteId = "mockSuite"; |
| 187 | + |
| 188 | + // Mock HTTP client and response |
| 189 | + CloseableHttpClient mockHttpClient = mock(CloseableHttpClient.class); |
| 190 | + CloseableHttpResponse mockResponse = mock(CloseableHttpResponse.class); |
| 191 | + |
| 192 | + // Ensure execute() returns a mock response |
| 193 | + when(mockHttpClient.execute(any(HttpPost.class))).thenReturn(mockResponse); |
| 194 | + |
| 195 | + // When 'submitReportRequest' is called, it uses the mocked client that we can keep track of |
| 196 | + try (MockedStatic<HttpClients> mockedHttpClients = mockStatic(HttpClients.class)) { |
| 197 | + mockedHttpClients.when(HttpClients::createDefault).thenReturn(mockHttpClient); |
| 198 | + |
| 199 | + RequestReportJob job = new RequestReportJob(); |
| 200 | + job.submitReportRequest(cnNode, mnNode, isCN, session, qualityServiceUrl, pidStr, suiteId); |
| 201 | + |
| 202 | + // Verify that the HTTP POST request was executed |
| 203 | + verify(mockHttpClient, times(1)).execute(any(HttpPost.class)); |
| 204 | + } |
| 205 | + } |
| 206 | + |
164 | 207 | /** |
165 | 208 | * Confirm that a sysmeta object is returned. No exception should be thrown. |
166 | 209 | */ |
|
0 commit comments