//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleUploadInACoupleOfRounds() throws java.io.IOException, org.neo4j.commandline.admin.CommandFailed //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHandleUploadInACoupleOfRounds() { ControlledProgressListener progressListener = new ControlledProgressListener(); HttpCopier copier = new HttpCopier(new ControlledOutsideWorld(_fs), millis => { }, (name, length) => progressListener); Path source = CreateDump(); long sourceLength = _fs.getFileSize(source.toFile()); long firstUploadLength = sourceLength / 3; string authorizationTokenResponse = "abc"; string signedURIPath = "/signed"; string uploadLocationPath = "/upload"; WireMock.stubFor(AuthenticationRequest(false).willReturn(SuccessfulAuthorizationResponse(authorizationTokenResponse))); WireMock.stubFor(InitiateUploadTargetRequest(authorizationTokenResponse).willReturn(SuccessfulInitiateUploadTargetResponse(signedURIPath))); WireMock.stubFor(InitiateUploadRequest(signedURIPath).willReturn(SuccessfulInitiateUploadResponse(uploadLocationPath))); WireMock.stubFor(ResumeUploadRequest(uploadLocationPath, 0, sourceLength).willReturn(aResponse().withStatus(HTTP_INTERNAL_ERROR))); WireMock.stubFor(GetResumablePositionRequest(sourceLength, uploadLocationPath).willReturn(UploadIncompleteGetResumablePositionResponse(firstUploadLength))); WireMock.stubFor(ResumeUploadRequest(uploadLocationPath, firstUploadLength, sourceLength).willReturn(SuccessfulResumeUploadResponse())); WireMock.stubFor(TriggerImportRequest(authorizationTokenResponse).willReturn(SuccessfulTriggerImportResponse())); WireMock.stubFor(FirstStatusPollingRequest(authorizationTokenResponse)); WireMock.stubFor(SecondStatusPollingRequest(authorizationTokenResponse)); // when AuthenticateAndCopy(copier, source, "user", "pass".ToCharArray()); // then verify(putRequestedFor(urlEqualTo(uploadLocationPath)).withHeader("Content-Length", equalTo(Convert.ToString(sourceLength))).withoutHeader("Content-Range")); verify(putRequestedFor(urlEqualTo(uploadLocationPath)).withHeader("Content-Length", equalTo(Convert.ToString(sourceLength - firstUploadLength))).withHeader("Content-Range", equalTo(format("bytes %d-%d/%d", firstUploadLength, sourceLength - 1, sourceLength)))); verify(putRequestedFor(urlEqualTo(uploadLocationPath)).withHeader("Content-Length", equalTo("0")).withHeader("Content-Range", equalTo("bytes */" + sourceLength))); assertTrue(progressListener.DoneCalled); // we need to add 3 to the progress listener because of the database phases assertEquals(sourceLength + 3, progressListener.Progress); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleIncompleteUploadButPositionSaysComplete() throws java.io.IOException, org.neo4j.commandline.admin.CommandFailed //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHandleIncompleteUploadButPositionSaysComplete() { HttpCopier copier = new HttpCopier(new ControlledOutsideWorld(_fs), millis => { }, _noOpProgress); Path source = CreateDump(); long sourceLength = _fs.getFileSize(source.toFile()); string authorizationTokenResponse = "abc"; string signedURIPath = "/signed"; string uploadLocationPath = "/upload"; WireMock.stubFor(AuthenticationRequest(false).willReturn(SuccessfulAuthorizationResponse(authorizationTokenResponse))); WireMock.stubFor(InitiateUploadTargetRequest(authorizationTokenResponse).willReturn(SuccessfulInitiateUploadTargetResponse(signedURIPath))); WireMock.stubFor(InitiateUploadRequest(signedURIPath).willReturn(SuccessfulInitiateUploadResponse(uploadLocationPath))); WireMock.stubFor(ResumeUploadRequest(uploadLocationPath, 0, sourceLength).willReturn(aResponse().withStatus(HTTP_INTERNAL_ERROR))); WireMock.stubFor(GetResumablePositionRequest(sourceLength, uploadLocationPath).willReturn(UploadCompleteGetResumablePositionResponse())); WireMock.stubFor(TriggerImportRequest(authorizationTokenResponse).willReturn(SuccessfulTriggerImportResponse())); WireMock.stubFor(FirstStatusPollingRequest(authorizationTokenResponse)); WireMock.stubFor(SecondStatusPollingRequest(authorizationTokenResponse)); // when AuthenticateAndCopy(copier, source, "user", "pass".ToCharArray()); // then verify(putRequestedFor(urlEqualTo(uploadLocationPath)).withHeader("Content-Length", equalTo(Convert.ToString(sourceLength))).withoutHeader("Content-Range")); verify(putRequestedFor(urlEqualTo(uploadLocationPath)).withHeader("Content-Length", equalTo("0")).withHeader("Content-Range", equalTo("bytes */" + sourceLength))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleConflictResponseFromInitiateUploadTargetAndContinueOnUserConsent() throws java.io.IOException, org.neo4j.commandline.admin.CommandFailed //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHandleConflictResponseFromInitiateUploadTargetAndContinueOnUserConsent() { ControlledOutsideWorld outsideWorld = new ControlledOutsideWorld(_fs); outsideWorld.WithPromptResponse("my-username"); // prompt for username outsideWorld.WithPasswordResponse("pass".ToCharArray()); // prompt for password outsideWorld.WithPromptResponse("y"); // prompt for consent to overwrite db HttpCopier copier = new HttpCopier(outsideWorld); Path source = CreateDump(); long sourceLength = _fs.getFileSize(source.toFile()); string authorizationTokenResponse = "abc"; string signedURIPath = "/signed"; string uploadLocationPath = "/upload"; WireMock.stubFor(AuthenticationRequest(true).willReturn(SuccessfulAuthorizationResponse(authorizationTokenResponse))); WireMock.stubFor(AuthenticationRequest(false).willReturn(aResponse().withStatus(HTTP_CONFLICT))); WireMock.stubFor(InitiateUploadTargetRequest(authorizationTokenResponse).willReturn(SuccessfulInitiateUploadTargetResponse(signedURIPath))); // and just the rest of the responses so that the upload can continue w/o failing WireMock.stubFor(InitiateUploadRequest(signedURIPath).willReturn(SuccessfulInitiateUploadResponse(uploadLocationPath))); WireMock.stubFor(ResumeUploadRequest(uploadLocationPath, sourceLength).willReturn(SuccessfulResumeUploadResponse())); WireMock.stubFor(TriggerImportRequest(authorizationTokenResponse).willReturn(SuccessfulTriggerImportResponse())); WireMock.stubFor(FirstStatusPollingRequest(authorizationTokenResponse)); WireMock.stubFor(SecondStatusPollingRequest(authorizationTokenResponse)); // when AuthenticateAndCopy(copier, source, "user", "pass".ToCharArray()); // then there should be one request w/o the user consent and then (since the user entered 'y') one w/ user consent verify(postRequestedFor(urlEqualTo("/import/auth")).withHeader("Confirmed", equalTo("false"))); verify(postRequestedFor(urlEqualTo("/import/auth")).withHeader("Confirmed", equalTo("true"))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleSuccessfulHappyCaseRunThroughOfTheWholeProcess() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHandleSuccessfulHappyCaseRunThroughOfTheWholeProcess() { // given ControlledProgressListener progressListener = new ControlledProgressListener(); HttpCopier copier = new HttpCopier(new ControlledOutsideWorld(_fs), millis => { }, (name, length) => progressListener); Path source = CreateDump(); long sourceLength = _fs.getFileSize(source.toFile()); string authorizationTokenResponse = "abc"; string signedURIPath = "/signed"; string uploadLocationPath = "/upload"; WireMock.stubFor(AuthenticationRequest(false).willReturn(SuccessfulAuthorizationResponse(authorizationTokenResponse))); WireMock.stubFor(InitiateUploadTargetRequest(authorizationTokenResponse).willReturn(SuccessfulInitiateUploadTargetResponse(signedURIPath))); WireMock.stubFor(InitiateUploadRequest(signedURIPath).willReturn(SuccessfulInitiateUploadResponse(uploadLocationPath))); WireMock.stubFor(ResumeUploadRequest(uploadLocationPath, sourceLength).willReturn(SuccessfulResumeUploadResponse())); WireMock.stubFor(TriggerImportRequest(authorizationTokenResponse).willReturn(SuccessfulTriggerImportResponse())); WireMock.stubFor(FirstStatusPollingRequest(authorizationTokenResponse)); WireMock.stubFor(SecondStatusPollingRequest(authorizationTokenResponse)); // when AuthenticateAndCopy(copier, source, "user", "pass".ToCharArray()); // then verify(postRequestedFor(urlEqualTo("/import/auth"))); verify(postRequestedFor(urlEqualTo("/import"))); verify(postRequestedFor(urlEqualTo(signedURIPath))); verify(putRequestedFor(urlEqualTo(uploadLocationPath))); verify(postRequestedFor(urlEqualTo("/import/upload-complete"))); assertTrue(progressListener.DoneCalled); // we need to add 3 to the progress listener because of the database phases assertEquals(sourceLength + 3, progressListener.Progress); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleUnexpectedResponseFromAuthorizationRequest() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHandleUnexpectedResponseFromAuthorizationRequest() { // given HttpCopier copier = new HttpCopier(new ControlledOutsideWorld(_fs)); Path source = CreateDump(); WireMock.stubFor(AuthenticationRequest(false).willReturn(aResponse().withStatus(HTTP_INTERNAL_ERROR))); // when/then AssertThrows(typeof(CommandFailed), allOf(containsString("Unexpected response"), containsString("Authorization")), () => authenticateAndCopy(copier, source, "user", "pass".ToCharArray())); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleInsufficientCredentialsInAuthorizationRequest() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHandleInsufficientCredentialsInAuthorizationRequest() { // given HttpCopier copier = new HttpCopier(new ControlledOutsideWorld(_fs)); Path source = CreateDump(); WireMock.stubFor(AuthenticationRequest(false).willReturn(aResponse().withStatus(HTTP_FORBIDDEN))); // when/then AssertThrows(typeof(CommandFailed), containsString("administrative access"), () => authenticateAndCopy(copier, source, "user", "pass".ToCharArray())); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleAuthenticateMovedRoute() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHandleAuthenticateMovedRoute() { // given HttpCopier copier = new HttpCopier(new ControlledOutsideWorld(_fs)); Path source = CreateDump(); WireMock.stubFor(AuthenticationRequest(false).willReturn(aResponse().withStatus(HTTP_NOT_FOUND))); // when/then AssertThrows(typeof(CommandFailed), CoreMatchers.containsString("please contact support"), () => authenticateAndCopy(copier, source, "user", "pass".ToCharArray())); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleBadCredentialsInAuthorizationRequest() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHandleBadCredentialsInAuthorizationRequest() { // given HttpCopier copier = new HttpCopier(new ControlledOutsideWorld(_fs)); Path source = CreateDump(); WireMock.stubFor(AuthenticationRequest(false).willReturn(aResponse().withStatus(HTTP_UNAUTHORIZED))); // when/then AssertThrows(typeof(CommandFailed), CoreMatchers.equalTo("Invalid username/password credentials"), () => authenticateAndCopy(copier, source, "user", "pass".ToCharArray())); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleUnauthorizedResponseFromInitiateUploadTarget() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHandleUnauthorizedResponseFromInitiateUploadTarget() { HttpCopier copier = new HttpCopier(new ControlledOutsideWorld(_fs)); Path source = CreateDump(); string token = "abc"; WireMock.stubFor(AuthenticationRequest(false).willReturn(SuccessfulAuthorizationResponse(token))); WireMock.stubFor(InitiateUploadTargetRequest(token).willReturn(aResponse().withStatus(HTTP_UNAUTHORIZED))); // when/then AssertThrows(typeof(CommandFailed), containsString("authorization token is invalid"), () => authenticateAndCopy(copier, source, "user", "pass".ToCharArray())); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleInitiateUploadFailure() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHandleInitiateUploadFailure() { HttpCopier copier = new HttpCopier(new ControlledOutsideWorld(_fs)); Path source = CreateDump(); string authorizationTokenResponse = "abc"; string signedURIPath = "/signed"; WireMock.stubFor(AuthenticationRequest(false).willReturn(SuccessfulAuthorizationResponse(authorizationTokenResponse))); WireMock.stubFor(InitiateUploadTargetRequest(authorizationTokenResponse).willReturn(SuccessfulInitiateUploadTargetResponse(signedURIPath))); WireMock.stubFor(InitiateUploadRequest(signedURIPath).willReturn(aResponse().withStatus(HTTP_INTERNAL_ERROR))); // when AssertThrows(typeof(CommandFailed), allOf(containsString("Unexpected response"), containsString("Initiating database upload")), () => authenticateAndCopy(copier, source, "user", "pass".ToCharArray())); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleUnexpectedResponseFromInitiateUploadTargetRequest() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHandleUnexpectedResponseFromInitiateUploadTargetRequest() { ControlledOutsideWorld outsideWorld = new ControlledOutsideWorld(_fs); outsideWorld.WithPromptResponse("my-username"); // prompt for username outsideWorld.WithPromptResponse("n"); // prompt for consent to overwrite db HttpCopier copier = new HttpCopier(outsideWorld); Path source = CreateDump(); string authorizationTokenResponse = "abc"; WireMock.stubFor(AuthenticationRequest(false).willReturn(SuccessfulAuthorizationResponse(authorizationTokenResponse))); WireMock.stubFor(InitiateUploadTargetRequest(authorizationTokenResponse).willReturn(aResponse().withStatus(HTTP_BAD_GATEWAY))); // when AssertThrows(typeof(CommandFailed), allOf(containsString("Unexpected response"), containsString("Initiating upload target")), () => authenticateAndCopy(copier, source, "user", "pass".ToCharArray())); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleMoveUploadTargetdRoute() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHandleMoveUploadTargetdRoute() { // given HttpCopier copier = new HttpCopier(new ControlledOutsideWorld(_fs)); Path source = CreateDump(); long sourceLength = _fs.getFileSize(source.toFile()); string authorizationTokenResponse = "abc"; string signedURIPath = "/signed"; string uploadLocationPath = "/upload"; WireMock.stubFor(AuthenticationRequest(false).willReturn(SuccessfulAuthorizationResponse(authorizationTokenResponse))); WireMock.stubFor(InitiateUploadRequest(signedURIPath).willReturn(SuccessfulInitiateUploadResponse(uploadLocationPath))); WireMock.stubFor(InitiateUploadTargetRequest("abc").willReturn(aResponse().withStatus(HTTP_NOT_FOUND))); // when/then AssertThrows(typeof(CommandFailed), CoreMatchers.containsString("please contact support"), () => authenticateAndCopy(copier, source, "user", "pass".ToCharArray())); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleConflictOnTriggerImportAfterUpload() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHandleConflictOnTriggerImportAfterUpload() { // given HttpCopier copier = new HttpCopier(new ControlledOutsideWorld(_fs)); Path source = CreateDump(); long sourceLength = _fs.getFileSize(source.toFile()); string authorizationTokenResponse = "abc"; string signedURIPath = "/signed"; string uploadLocationPath = "/upload"; WireMock.stubFor(AuthenticationRequest(false).willReturn(SuccessfulAuthorizationResponse(authorizationTokenResponse))); WireMock.stubFor(InitiateUploadTargetRequest(authorizationTokenResponse).willReturn(SuccessfulInitiateUploadTargetResponse(signedURIPath))); WireMock.stubFor(InitiateUploadRequest(signedURIPath).willReturn(SuccessfulInitiateUploadResponse(uploadLocationPath))); WireMock.stubFor(ResumeUploadRequest(uploadLocationPath, sourceLength).willReturn(SuccessfulResumeUploadResponse())); WireMock.stubFor(TriggerImportRequest(authorizationTokenResponse).willReturn(aResponse().withStatus(HTTP_CONFLICT))); // when AssertThrows(typeof(CommandFailed), containsString("A non-empty database already exists"), () => authenticateAndCopy(copier, source, "user", "pass".ToCharArray())); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldBackoffAndFailIfTooManyAttempts() throws java.io.IOException, InterruptedException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldBackoffAndFailIfTooManyAttempts() { // given HttpCopier.Sleeper sleeper = mock(typeof(HttpCopier.Sleeper)); HttpCopier copier = new HttpCopier(new ControlledOutsideWorld(_fs), sleeper, _noOpProgress); Path source = CreateDump(); long sourceLength = _fs.getFileSize(source.toFile()); string authorizationTokenResponse = "abc"; string signedURIPath = "/signed"; string uploadLocationPath = "/upload"; WireMock.stubFor(AuthenticationRequest(false).willReturn(SuccessfulAuthorizationResponse(authorizationTokenResponse))); WireMock.stubFor(InitiateUploadTargetRequest(authorizationTokenResponse).willReturn(SuccessfulInitiateUploadTargetResponse(signedURIPath))); WireMock.stubFor(InitiateUploadRequest(signedURIPath).willReturn(SuccessfulInitiateUploadResponse(uploadLocationPath))); WireMock.stubFor(ResumeUploadRequest(uploadLocationPath, sourceLength).willReturn(aResponse().withStatus(HTTP_INTERNAL_ERROR))); WireMock.stubFor(GetResumablePositionRequest(sourceLength, uploadLocationPath).willReturn(UploadIncompleteGetResumablePositionResponse(0))); // when/then AssertThrows(typeof(CommandFailed), containsString("Upload failed after numerous attempts"), () => authenticateAndCopy(copier, source, "user", "pass".ToCharArray())); Mockito.verify(sleeper, atLeast(30)).sleep(anyLong()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleConflictResponseFromAuthenticationWithoutUserConsent() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHandleConflictResponseFromAuthenticationWithoutUserConsent() { ControlledOutsideWorld outsideWorld = new ControlledOutsideWorld(_fs); outsideWorld.WithPromptResponse("my-username"); // prompt for username outsideWorld.WithPromptResponse("n"); // prompt for consent to overwrite db HttpCopier copier = new HttpCopier(outsideWorld); Path source = CreateDump(); string authorizationTokenResponse = "abc"; string signedURIPath = "/signed"; WireMock.stubFor(AuthenticationRequest(false).willReturn(aResponse().withStatus(HTTP_CONFLICT))); WireMock.stubFor(AuthenticationRequest(true).willReturn(SuccessfulAuthorizationResponse(authorizationTokenResponse))); WireMock.stubFor(InitiateUploadTargetRequest(authorizationTokenResponse).willReturn(SuccessfulInitiateUploadTargetResponse(signedURIPath))); // when AssertThrows(typeof(CommandFailed), containsString("No consent to overwrite"), () => authenticateAndCopy(copier, source, "user", "pass".ToCharArray())); // then there should be one request w/o the user consent and then (since the user entered 'y') one w/ user consent verify(postRequestedFor(urlEqualTo("/import/auth")).withHeader("Confirmed", equalTo("false"))); verify(0, postRequestedFor(urlEqualTo("/import/auth")).withHeader("Confirmed", equalTo("true"))); }