List of usage examples for org.eclipse.jgit.api TransportConfigCallback configure
void configure(Transport transport);
From source file:org.eclipse.che.git.impl.jgit.JGitConnectionTest.java
License:Open Source License
@Test public void shouldSetSshSessionFactoryWhenSshTransportReceived() throws Exception { //given/* w w w.java 2 s.c o m*/ SshTransport sshTransport = mock(SshTransport.class); when(sshKeyProvider.getPrivateKey(anyString())).thenReturn(new byte[0]); doAnswer(invocation -> { TransportConfigCallback callback = (TransportConfigCallback) invocation.getArguments()[0]; callback.configure(sshTransport); return null; }).when(transportCommand).setTransportConfigCallback(any()); //when jGitConnection.executeRemoteCommand("ssh://host.xz/repo.git", transportCommand, null, null); //then verify(sshTransport).setSshSessionFactory(any()); }
From source file:org.eclipse.che.git.impl.jgit.JGitConnectionTest.java
License:Open Source License
@Test public void shouldDoNothingWhenTransportHttpReceived() throws Exception { //given/*from ww w . j a v a 2 s .c o m*/ /* * We need create {@link TransportHttp} mock, but this class has parent * abstract class {@link Transport}. Class Transport uses fields of children * classes for static initialization collection {@link Transport#protocols}. * When we create mock for {@link TransportHttp} - Mockito mocks fields and * they return null value. For full mock creation TransportHttp Mockito * launches static block in the parent class {@link Transport}, but static * block initializes collection with help mocked children fields which * return null values, so Transport class loses real field value in the * collection. It creates troubles in other tests when we use real object * of TransportHttp(collection 'protocols' contains not all values). * To realize right initialization {@link Transport#protocols} we create * mock of {@link Transport} and this class initializes collection "protocols" * with help real children {@link TransportHttp}, which returns real not null * value. And then we can create mock {@link TransportHttp}. */ mock(Transport.class); TransportHttp transportHttp = mock(TransportHttp.class); when(sshKeyProvider.getPrivateKey(anyString())).thenReturn(new byte[0]); doAnswer(invocation -> { TransportConfigCallback callback = (TransportConfigCallback) invocation.getArguments()[0]; callback.configure(transportHttp); return null; }).when(transportCommand).setTransportConfigCallback(any()); //when jGitConnection.executeRemoteCommand("ssh://host.xz/repo.git", transportCommand, null, null); //then verifyZeroInteractions(transportHttp); }
From source file:org.springframework.cloud.config.server.support.GoogleCloudSourceSupportTests.java
License:Apache License
@Test public void verifySetsAuthHeadersForHttpsGCSRepo() throws URISyntaxException { Map<String, String> authHeaders = createAuthHeaders(); TransportConfigCallback callback = transportConfigCallbackWith(authHeaders); TransportHttp transport = mockTransportHttp(HTTPS_GOOGLE_CLOUD_SOURCE_REPO); Map<String, String> actualHeaders = recordSetHeaders(transport); callback.configure(transport); assertThat(actualHeaders).containsAllEntriesOf(authHeaders); }
From source file:org.springframework.cloud.config.server.support.GoogleCloudSourceSupportTests.java
License:Apache License
@Test public void verifySetsAuthHeadersForHttpGCSRepo() throws URISyntaxException { Map<String, String> authHeaders = createAuthHeaders(); TransportConfigCallback callback = transportConfigCallbackWith(authHeaders); TransportHttp transport = mockTransportHttp(HTTP_GOOGLE_CLOUD_SOURCE_REPO); Map<String, String> actualHeaders = recordSetHeaders(transport); callback.configure(transport); assertThat(actualHeaders).containsAllEntriesOf(authHeaders); }
From source file:org.springframework.cloud.config.server.support.GoogleCloudSourceSupportTests.java
License:Apache License
@Test public void verifyDoesNothingForSshGCSRepo() throws URISyntaxException { TransportConfigCallback callback = transportConfigCallbackWith(createAuthHeaders()); TransportHttp transport = mockTransportHttp(SSH_GOOGLE_CLOUD_SOURCE_REPO); callback.configure(transport); verifyOnlyValidInteraction(transport); }
From source file:org.springframework.cloud.config.server.support.GoogleCloudSourceSupportTests.java
License:Apache License
@Test public void verifyDoesNothingForHttpsOtherRepo() throws URISyntaxException { TransportConfigCallback callback = transportConfigCallbackWith(createAuthHeaders()); TransportHttp transport = mockTransportHttp(HTTPS_OTHER_REPO); callback.configure(transport); verifyOnlyValidInteraction(transport); }
From source file:org.springframework.cloud.config.server.support.GoogleCloudSourceSupportTests.java
License:Apache License
@Test public void verifyDoesNothingForNonHttpTransports() throws URISyntaxException { TransportConfigCallback callback = transportConfigCallbackWith(createAuthHeaders()); Transport transport = mockSshTransport(SSH_GOOGLE_CLOUD_SOURCE_REPO); callback.configure(transport); verifyOnlyValidInteraction(transport); }