Search in sources :

Example 6 with PortPair

use of com.openshift.restclient.capability.resources.IPortForwardable.PortPair in project jbosstools-openshift by jbosstools.

the class PortForwardingUtilsTest method shouldStopPortForwarding.

@Test
@SuppressWarnings("unchecked")
public void shouldStopPortForwarding() throws IOException {
    // given
    final IPod pod = Mockito.mock(IPod.class);
    final PortPair port = Mockito.mock(PortPair.class);
    final IPortForwardable portForwardable = Mockito.mock(IPortForwardable.class);
    Mockito.when(pod.accept(Mockito.any(CapabilityVisitor.class), Mockito.any(IPortForwardable.class))).thenReturn(portForwardable);
    Mockito.when(portForwardable.isForwarding()).thenReturn(true);
    Mockito.when(portForwardable.getPortPairs()).thenReturn(Arrays.asList(port));
    PortForwardingUtils.startPortForwarding(pod, port);
    // when
    final IPortForwardable stopPortForwarding = PortForwardingUtils.stopPortForwarding(pod, null);
    // then
    assertThat(stopPortForwarding).isNotNull().isEqualTo(portForwardable);
    assertThat(PortForwardingUtils.isPortForwardingStarted(pod)).isFalse();
    Mockito.verify(portForwardable, Mockito.times(1)).stop();
}
Also used : IPortForwardable(com.openshift.restclient.capability.resources.IPortForwardable) PortPair(com.openshift.restclient.capability.resources.IPortForwardable.PortPair) CapabilityVisitor(com.openshift.restclient.capability.CapabilityVisitor) IPod(com.openshift.restclient.model.IPod) Test(org.junit.Test)

Example 7 with PortPair

use of com.openshift.restclient.capability.resources.IPortForwardable.PortPair in project jbosstools-openshift by jbosstools.

the class PortForwardingUtilsTest method shouldGetForwardablePortsOnStartedState.

@Test
@SuppressWarnings("unchecked")
public void shouldGetForwardablePortsOnStartedState() {
    // given
    final IPod pod = Mockito.mock(IPod.class);
    final PortPair port = Mockito.mock(PortPair.class);
    final IPortForwardable portForwardable = Mockito.mock(IPortForwardable.class);
    Mockito.when(portForwardable.getPortPairs()).thenReturn(Arrays.asList(port));
    Mockito.when(pod.accept(Mockito.any(CapabilityVisitor.class), Mockito.any(IPortForwardable.class))).thenReturn(portForwardable);
    PortForwardingUtils.startPortForwarding(pod, port);
    // when
    final Set<PortPair> forwardablePorts = PortForwardingUtils.getForwardablePorts(pod);
    // then
    assertThat(forwardablePorts).isNotNull().containsExactly(port);
}
Also used : IPortForwardable(com.openshift.restclient.capability.resources.IPortForwardable) PortPair(com.openshift.restclient.capability.resources.IPortForwardable.PortPair) CapabilityVisitor(com.openshift.restclient.capability.CapabilityVisitor) IPod(com.openshift.restclient.model.IPod) Test(org.junit.Test)

Aggregations

IPortForwardable (com.openshift.restclient.capability.resources.IPortForwardable)7 PortPair (com.openshift.restclient.capability.resources.IPortForwardable.PortPair)7 IPod (com.openshift.restclient.model.IPod)6 CapabilityVisitor (com.openshift.restclient.capability.CapabilityVisitor)4 Test (org.junit.Test)4 IOException (java.io.IOException)2 Set (java.util.Set)2 IBinaryCapability (com.openshift.restclient.capability.IBinaryCapability)1 OpenShiftBinaryOption (com.openshift.restclient.capability.IBinaryCapability.OpenShiftBinaryOption)1 IPort (com.openshift.restclient.model.IPort)1 IReplicationController (com.openshift.restclient.model.IReplicationController)1 IResource (com.openshift.restclient.model.IResource)1 OutputStream (java.io.OutputStream)1 ServerSocket (java.net.ServerSocket)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1