Search in sources :

Example 1 with HttpBasedAuthentication

use of com.oracle.bedrock.runtime.remote.http.HttpBasedAuthentication in project oracle-bedrock by coherence-community.

the class SoapConnectionTest method shouldOpenAuthenticatedConnection.

@Test
public void shouldOpenAuthenticatedConnection() throws Exception {
    URL url = new URL("http://oracle.com:80/foo");
    Envelope envelope = mock(Envelope.class);
    String useName = "dummy";
    HttpBasedAuthentication authentication = mock(HttpBasedAuthentication.class);
    HttpURLConnection httpConnection = mock(HttpURLConnection.class);
    when(authentication.openConnection(any(URL.class), anyString(), any(OptionsByType.class))).thenReturn(httpConnection);
    SoapConnection realConnection = new SoapConnection("oracle.com", 80, "/foo", useName, authentication) {

        @Override
        public List<Object> send(Envelope envelope, HttpURLConnection httpConnection) throws IOException {
            return Collections.emptyList();
        }
    };
    SoapConnection connection = spy(realConnection);
    connection.send(envelope);
    verify(authentication).openConnection(eq(url), eq(useName), any(OptionsByType.class));
    verify(connection).send(same(envelope), same(httpConnection));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Matchers.anyString(org.mockito.Matchers.anyString) Envelope(org.w3c.soap.envelope.Envelope) OptionsByType(com.oracle.bedrock.OptionsByType) URL(java.net.URL) HttpBasedAuthentication(com.oracle.bedrock.runtime.remote.http.HttpBasedAuthentication) Test(org.junit.Test)

Example 2 with HttpBasedAuthentication

use of com.oracle.bedrock.runtime.remote.http.HttpBasedAuthentication in project oracle-bedrock by coherence-community.

the class WindowsRemoteTerminalTest method shouldCreateWindowsSession.

@Test
public void shouldCreateWindowsSession() throws Exception {
    String userName = "Bob";
    HttpBasedAuthentication authentication = new Password("secret");
    String hostName = "foo.com";
    int port = 1234;
    RemotePlatform platform = mock(RemotePlatform.class);
    when(platform.getUserName()).thenReturn(userName);
    when(platform.getAuthentication()).thenReturn(authentication);
    when(platform.getAddress()).thenReturn(InetAddress.getByName(hostName));
    when(platform.getPort()).thenReturn(port);
    WindowsRemoteTerminal shell = new WindowsRemoteTerminal(platform);
    WindowsSession session = shell.createSession();
    assertThat(session, is(notNullValue()));
    SoapConnection soapConnection = session.getSoapConnection();
    assertThat(soapConnection.getUrl().getHost(), is("foo.com"));
    assertThat(soapConnection.getUrl().getPort(), is(1234));
    assertThat(soapConnection.getUserName(), is("Bob"));
    assertThat(soapConnection.getAuthentication(), is(sameInstance(authentication)));
}
Also used : RemotePlatform(com.oracle.bedrock.runtime.remote.RemotePlatform) HttpBasedAuthentication(com.oracle.bedrock.runtime.remote.http.HttpBasedAuthentication) Password(com.oracle.bedrock.runtime.remote.Password) Test(org.junit.Test)

Aggregations

HttpBasedAuthentication (com.oracle.bedrock.runtime.remote.http.HttpBasedAuthentication)2 Test (org.junit.Test)2 OptionsByType (com.oracle.bedrock.OptionsByType)1 Password (com.oracle.bedrock.runtime.remote.Password)1 RemotePlatform (com.oracle.bedrock.runtime.remote.RemotePlatform)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Envelope (org.w3c.soap.envelope.Envelope)1