diff --git a/src/test/java/ai/deepcode/javaclient/core/AnalysisDataTest.java b/src/test/java/ai/deepcode/javaclient/core/AnalysisDataTest.java index 56623314b..60c13d665 100644 --- a/src/test/java/ai/deepcode/javaclient/core/AnalysisDataTest.java +++ b/src/test/java/ai/deepcode/javaclient/core/AnalysisDataTest.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Objects; import java.util.Queue; +import java.util.UUID; import static ai.deepcode.javaclient.core.AnalysisDataBase.COMPLETE; import static org.junit.Assert.assertEquals; @@ -71,17 +72,17 @@ private static class RestApiMockWithBrokenFileUpload extends DeepCodeRestApiMock new CreateBundleResponse("bundleHash", Collections.singletonList("/filePath")); @Override - public @NotNull CreateBundleResponse createBundle(String orgName, FileHashRequest files) { + public @NotNull CreateBundleResponse createBundle(String orgName, String requestId, FileHashRequest files) { return bundleResponseWithMissedFile; } @Override - public @NotNull CreateBundleResponse extendBundle(String orgName, String bundleId, Req request) { + public @NotNull CreateBundleResponse extendBundle(String orgName, String requestId, String bundleId, Req request) { return bundleResponseWithMissedFile; } @Override - public @NotNull CreateBundleResponse checkBundle(String orgName, String bundleId) { + public @NotNull CreateBundleResponse checkBundle(String orgName, String requestId, String bundleId) { return bundleResponseWithMissedFile; } } @@ -92,9 +93,9 @@ public void re_createBundle_if_createBundle_fail_with_404() { final int[] reUploadCounter = {0}; restApi = new RestApiMockWithBrokenFileUpload() { @Override - public @NotNull CreateBundleResponse createBundle(String orgName, FileHashRequest files) { + public @NotNull CreateBundleResponse createBundle(String orgName, String requestId, FileHashRequest files) { reUploadCounter[0] = reUploadCounter[0] + 1; - return super.createBundle(orgName, files); + return super.createBundle(orgName, requestId, files); } }; @@ -105,7 +106,7 @@ public void re_createBundle_if_createBundle_fail_with_404() { final String project = "Project4"; final String progress = "Progress Indicator"; - analysisData.updateCachedResultsForFiles(project, Collections.singleton("File"), progress); + analysisData.updateCachedResultsForFiles(project, Collections.singleton("File"), progress, UUID.randomUUID().toString()); assertEquals("Should be made 3 attempts to re-create bundle if operation does not succeed", 3, reUploadCounter[0]); } @@ -120,13 +121,14 @@ public void re_createBundle_if_extendBundle_fail_with_404() { analysisData = new AnalysisDataBaseMock(pdUtils, hashContentUtils, deepCodeParams, dcLogger, restApi); final String project = "Project5"; final String progress = "Progress Indicator"; - analysisData.updateCachedResultsForFiles(project, Collections.singleton("File"), progress); + String requestId = UUID.randomUUID().toString(); + analysisData.updateCachedResultsForFiles(project, Collections.singleton("File"), progress, requestId); // try to extend expired bundle final int[] reUploadCounter = {0}; restApi = new RestApiMockWithBrokenFileUpload() { @Override - public @NotNull CreateBundleResponse createBundle(String orgName, FileHashRequest files) { + public @NotNull CreateBundleResponse createBundle(String orgName, String requestId, FileHashRequest files) { reUploadCounter[0] = reUploadCounter[0] + 1; final CreateBundleResponse response = new CreateBundleResponse("bundleHash", Collections.singletonList("/filePath")); @@ -135,7 +137,7 @@ public void re_createBundle_if_extendBundle_fail_with_404() { } @Override - public @NotNull CreateBundleResponse extendBundle(String orgName, String bundleId, Req request) { + public @NotNull CreateBundleResponse extendBundle(String orgName, String requestId, String bundleId, Req request) { final CreateBundleResponse response = new CreateBundleResponse(); response.setStatusCode(404); return response; @@ -144,7 +146,7 @@ public void re_createBundle_if_extendBundle_fail_with_404() { analysisData = new AnalysisDataBaseMock(pdUtils, hashContentUtils, deepCodeParams, dcLogger, restApi); // --------------------------- actual test -------------------- - analysisData.updateCachedResultsForFiles(project, Collections.singleton("File"), progress); + analysisData.updateCachedResultsForFiles(project, Collections.singleton("File"), progress, requestId); assertEquals( "Should be made 2 attempts to re-create bundle if extendBundle does not succeed", @@ -159,7 +161,7 @@ public void reupload_files_if_initial_upload_does_not_succeed() throws IOExcepti final int[] reUploadCounter = {0}; restApi = new RestApiMockWithBrokenFileUpload() { @Override - public @NotNull CreateBundleResponse createBundle(String orgName, FileHashRequest files) { + public @NotNull CreateBundleResponse createBundle(String orgName, String requestId, FileHashRequest files) { final CreateBundleResponse response = new CreateBundleResponse("bundleHash", Collections.singletonList("/filePath")); response.setStatusCode(200); @@ -167,9 +169,9 @@ public void reupload_files_if_initial_upload_does_not_succeed() throws IOExcepti } @Override - public @NotNull CreateBundleResponse extendBundle(String orgName, String bundleId, Req request) { + public @NotNull CreateBundleResponse extendBundle(String orgName, String requestId, String bundleId, Req request) { reUploadCounter[0] = reUploadCounter[0] + 1; - return super.extendBundle(orgName, bundleId, request); + return super.extendBundle(orgName, requestId, bundleId, request); } }; @@ -184,7 +186,7 @@ public void reupload_files_if_initial_upload_does_not_succeed() throws IOExcepti file.deleteOnExit(); Files.writeString(file.toPath(), "testtestest"); - analysisData.updateCachedResultsForFiles(project, Collections.singleton(file), progress); + analysisData.updateCachedResultsForFiles(project, Collections.singleton(file), progress, UUID.randomUUID().toString()); assertEquals("Should have made 10 attempts to re-upload files if operation does not succeed", 10, reUploadCounter[0]); } @@ -196,6 +198,7 @@ public void if_file_upload_fail_getAnalysis_should_not_be_invoked() { @Override public @NotNull GetAnalysisResponse getAnalysis( String orgName, + String requestId, String bundleId, Integer severity, List filesToAnalyse, @@ -213,7 +216,7 @@ public void if_file_upload_fail_getAnalysis_should_not_be_invoked() { final String project = "Project2"; final String progress = "Progress Indicator"; - analysisData.updateCachedResultsForFiles(project, Collections.singleton("File"), progress); + analysisData.updateCachedResultsForFiles(project, Collections.singleton("File"), progress, UUID.randomUUID().toString()); } // getAnalysis recover (continue polling) if operation sometimes does not succeed with 404 @@ -247,7 +250,7 @@ public void getAnalysis_recover_during_polling_if_operation_sometimes_does_not_s restApi = new RestApiMockWithBrokenFileUpload() { @Override - public @NotNull CreateBundleResponse createBundle(String orgName, FileHashRequest files) { + public @NotNull CreateBundleResponse createBundle(String orgName, String requestId, FileHashRequest files) { final CreateBundleResponse response = new CreateBundleResponse("bundleHash", Collections.singletonList("/filePath")); response.setStatusCode(200); @@ -255,7 +258,7 @@ public void getAnalysis_recover_during_polling_if_operation_sometimes_does_not_s } @Override - public @NotNull CreateBundleResponse extendBundle(String orgName, String bundleId, Req request) { + public @NotNull CreateBundleResponse extendBundle(String orgName, String requestId, String bundleId, Req request) { final CreateBundleResponse response = new CreateBundleResponse("bundleHash", Collections.emptyList()); response.setStatusCode(200); @@ -263,7 +266,7 @@ public void getAnalysis_recover_during_polling_if_operation_sometimes_does_not_s } @Override - public @NotNull CreateBundleResponse checkBundle(String orgName, String bundleId) { + public @NotNull CreateBundleResponse checkBundle(String orgName, String requestId, String bundleId) { final CreateBundleResponse response = new CreateBundleResponse("bundleHash", Collections.emptyList()); response.setStatusCode(200); response.setStatusDescription("Fake successful bundle check"); @@ -273,6 +276,7 @@ public void getAnalysis_recover_during_polling_if_operation_sometimes_does_not_s @Override public @NotNull GetAnalysisResponse getAnalysis( String orgName, + String requestId, String bundleId, Integer severity, List filesToAnalyse, @@ -293,14 +297,13 @@ public long getTimeoutForGettingAnalysesMs() { return 10_000L; // 10 sec } }; - ; analysisData = new AnalysisDataBaseMock(pdUtils, hashContentUtils, deepCodeParams, dcLogger, restApi); // --------------------------- actual test -------------------- final String project = "Project3"; final String progress = "Progress Indicator"; - analysisData.updateCachedResultsForFiles(project, Collections.singleton("File"), progress); + analysisData.updateCachedResultsForFiles(project, Collections.singleton("File"), progress, UUID.randomUUID().toString()); assertTrue( "Analysis should complete despite getting 404s in the middle of polling", diff --git a/src/test/java/ai/deepcode/javaclient/core/RunUtilsTest.java b/src/test/java/ai/deepcode/javaclient/core/RunUtilsTest.java index 379932893..c8598e4d9 100644 --- a/src/test/java/ai/deepcode/javaclient/core/RunUtilsTest.java +++ b/src/test/java/ai/deepcode/javaclient/core/RunUtilsTest.java @@ -43,7 +43,8 @@ public void isRescanShownAsNotRequestedAfterScanFinishedTest() { public void updateCachedResultsForFiles( @NotNull Object project, @NotNull Collection allProjectFiles, - @NotNull Object progress) { + @NotNull Object progress, + @NotNull String requestId) { } }; diff --git a/src/test/java/ai/deepcode/javaclient/core/mocks/DeepCodeRestApiMock.java b/src/test/java/ai/deepcode/javaclient/core/mocks/DeepCodeRestApiMock.java index 0dcac7746..34b05e58b 100644 --- a/src/test/java/ai/deepcode/javaclient/core/mocks/DeepCodeRestApiMock.java +++ b/src/test/java/ai/deepcode/javaclient/core/mocks/DeepCodeRestApiMock.java @@ -12,28 +12,29 @@ public class DeepCodeRestApiMock implements DeepCodeRestApi { @Override - public @NotNull CreateBundleResponse createBundle(String orgName, FileContentRequest files) { + public @NotNull CreateBundleResponse createBundle(String orgName, String requestId, FileContentRequest files) { throw new UnsupportedOperationException(); } @Override - public @NotNull CreateBundleResponse createBundle(String orgName, FileHashRequest files) { + public @NotNull CreateBundleResponse createBundle(String orgName, String requestId, FileHashRequest files) { throw new UnsupportedOperationException(); } @Override - public @NotNull CreateBundleResponse checkBundle(String orgName, String bundleId) { + public @NotNull CreateBundleResponse checkBundle(String orgName, String requestId, String bundleId) { throw new UnsupportedOperationException(); } @Override - public @NotNull CreateBundleResponse extendBundle(String orgName, String bundleId, Req request) { + public @NotNull CreateBundleResponse extendBundle(String orgName, String requestId, String bundleId, Req request) { throw new UnsupportedOperationException(); } @Override public @NotNull GetAnalysisResponse getAnalysis( String orgName, + String requestId, String bundleId, Integer severity, List filesToAnalyse,