use of com.openshift.restclient.capability.resources.IPortForwardable in project jbosstools-openshift by jbosstools.
the class PortForwardingUtils method getForwardablePorts.
/**
* Returns the {@link PortPair} for the given {@code pod}
* @param pod the pod to analyze
* @return an <strong>immutable</strong> {@link Set} of {@link PortPair}
*/
public static Set<IPortForwardable.PortPair> getForwardablePorts(final IPod pod) {
final Set<IPortForwardable.PortPair> ports = new HashSet<>();
final IPortForwardable forwardable = REGISTRY.get(pod);
if (forwardable != null && forwardable.getPortPairs() != null) {
ports.addAll(forwardable.getPortPairs());
} else if (pod.getContainerPorts() != null) {
pod.getContainerPorts().stream().map(containerPort -> new IPortForwardable.PortPair(containerPort)).forEach(portPair -> ports.add(portPair));
}
return Collections.unmodifiableSet(ports);
}
use of com.openshift.restclient.capability.resources.IPortForwardable 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();
}
use of com.openshift.restclient.capability.resources.IPortForwardable 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);
}
Aggregations