|
| 1 | +package com.buabook.kdb.connection.test; |
| 2 | + |
| 3 | +import org.junit.Test; |
| 4 | + |
| 5 | +import com.buabook.kdb.connection.KdbConnection; |
| 6 | +import com.buabook.kdb.connection.KdbProcess; |
| 7 | +import com.buabook.kdb.exceptions.KdbTargetProcessUnavailableException; |
| 8 | + |
| 9 | +import static org.hamcrest.Matchers.*; |
| 10 | +import static org.junit.Assert.assertThat; |
| 11 | + |
| 12 | +@SuppressWarnings("resource") |
| 13 | +public class KdbConnectionTest { |
| 14 | + |
| 15 | + // KdbConnection.connect |
| 16 | + |
| 17 | + @Test(expected=KdbTargetProcessUnavailableException.class) |
| 18 | + public void testConnectThrowsExceptionIfNullProcess() throws KdbTargetProcessUnavailableException { |
| 19 | + new KdbConnection(null).connect(); |
| 20 | + } |
| 21 | + |
| 22 | + @Test(expected=KdbTargetProcessUnavailableException.class) |
| 23 | + public void testConnectThrowsExceptionIfCannotConnectToProcess() throws KdbTargetProcessUnavailableException { |
| 24 | + new KdbConnection(new KdbProcess("localhost", 1)).connect(); |
| 25 | + } |
| 26 | + |
| 27 | + // KdbConnection.isConnected |
| 28 | + |
| 29 | + @Test |
| 30 | + public void testIsConnectedReturnsFalseWhenConnectionIsNotConnected() { |
| 31 | + KdbConnection connection = new KdbConnection(new KdbProcess("localhost", 12345)); |
| 32 | + assertThat(connection.isConnected(), is(equalTo(false))); |
| 33 | + } |
| 34 | + |
| 35 | + // KdbConnection.getRemoteProcess |
| 36 | + |
| 37 | + @Test |
| 38 | + public void testGetRemoteProcessReturnsConfiguredProcess() { |
| 39 | + KdbProcess target = new KdbProcess("my-test-host.com", 34343); |
| 40 | + assertThat(new KdbConnection(target).getRemoteProcess(), is(equalTo(target))); |
| 41 | + } |
| 42 | +} |
0 commit comments