org.arquillian.cube.HostPort类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(48)

本文整理了Java中org.arquillian.cube.HostPort类的一些代码示例,展示了HostPort类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HostPort类的具体详情如下:
包路径:org.arquillian.cube.HostPort
类名称:HostPort

HostPort介绍

暂无

代码示例

代码示例来源:origin: arquillian/arquillian-cube

public static class MyTest {
    @HostPort(containerName = "test", value = 99)
    int port;

    public void myMethod(String first, @HostPort(containerName = "test", value = 99) int port) {

    }
  }
}

代码示例来源:origin: org.arquillian.cube/arquillian-cube-core

@Override
public void enrich(Object testCase) {
  if (cubeRegistryInstance.get() != null) {
    List<Field> fieldsWithAnnotation =
      ReflectionUtil.getFieldsWithAnnotation(testCase.getClass(), HostPort.class);
    for (Field dockerHostPortField : fieldsWithAnnotation) {
      if (!dockerHostPortField.isAccessible()) {
        dockerHostPortField.setAccessible(true);
      }
      if (int.class.isAssignableFrom(dockerHostPortField.getType()) || Integer.class.isAssignableFrom(
        dockerHostPortField.getType())) {
        try {
          final HostPort hostPortAnnotation = dockerHostPortField.getAnnotation(HostPort.class);
          String containerName = hostPortAnnotation.containerName();
          int exposedPort = hostPortAnnotation.value();
          int bindPort = getBindingPort(containerName, exposedPort);
          if (bindPort > 0) {
            dockerHostPortField.set(testCase, bindPort);
          } else {
            logger.log(Level.WARNING, String.format("There is no container with id %s.", containerName));
          }
        } catch (IllegalAccessException e) {
          throw new IllegalArgumentException(e);
        }
      }
    }
  }
}

代码示例来源:origin: org.arquillian.cube/arquillian-cube-docker

private static int findEnrichedValueForFieldWithHostPortAnnotation(HostPort hostPort, HasPortBindings portBindings) {
  int hostPortValue = hostPort.value();
  if (hostPortValue == 0) {
    throw new IllegalArgumentException(
      String.format("%s annotation does not specify any exposed port", HostPort.class.getSimpleName()));
  }
  final HasPortBindings.PortAddress bindingForExposedPort = portBindings.getMappedAddress(hostPortValue);
  if (bindingForExposedPort == null) {
    throw new IllegalArgumentException(
      String.format("exposed port %s is not exposed on container object.", hostPortValue));
  }
  return bindingForExposedPort.getPort();
}

代码示例来源:origin: arquillian/arquillian-cube

private static int findEnrichedValueForFieldWithHostPortAnnotation(HostPort hostPort, HasPortBindings portBindings) {
  int hostPortValue = hostPort.value();
  if (hostPortValue == 0) {
    throw new IllegalArgumentException(
      String.format("%s annotation does not specify any exposed port", HostPort.class.getSimpleName()));
  }
  final HasPortBindings.PortAddress bindingForExposedPort = portBindings.getMappedAddress(hostPortValue);
  if (bindingForExposedPort == null) {
    throw new IllegalArgumentException(
      String.format("exposed port %s is not exposed on container object.", hostPortValue));
  }
  return bindingForExposedPort.getPort();
}

代码示例来源:origin: arquillian/arquillian-cube

public void myMethod(String first, @HostPort(containerName = "test", value = 99) int port) {
  }
}

代码示例来源:origin: arquillian/arquillian-cube

@Override
public Object[] resolve(Method method) {
  Object[] values = new Object[method.getParameterTypes().length];
  if (cubeRegistryInstance.get() != null) {
    Integer[] annotatedParameters = annotatedParameters(method);
    Class<?>[] parameterTypes = method.getParameterTypes();
    for (Integer i : annotatedParameters) {
      if (int.class.isAssignableFrom(parameterTypes[i]) || Integer.class.isAssignableFrom(parameterTypes[i])) {
        final Annotation[] parameterAnnotations = method.getParameterAnnotations()[i];
        final HostPort hostPortAnnotation = findHostPort(parameterAnnotations);
        String containerName = hostPortAnnotation.containerName();
        int exposedPort = hostPortAnnotation.value();
        int bindPort = getBindingPort(containerName, exposedPort);
        if (bindPort > 0) {
          values[i] = bindPort;
        } else {
          logger.log(Level.WARNING, String.format("There is no container with id %s.", containerName));
        }
      }
    }
  }
  return values;
}

代码示例来源:origin: arquillian/arquillian-cube

@Cube(value = "containerWithHostPort", portBinding = "8080->8080/tcp")
@Image(BASE_IMAGE)
public static class TestContainerObjectWithHostPort {
  @HostPort(8080)
  int port;
}

代码示例来源:origin: arquillian/arquillian-cube

@Override
public void enrich(Object testCase) {
  if (cubeRegistryInstance.get() != null) {
    List<Field> fieldsWithAnnotation =
      ReflectionUtil.getFieldsWithAnnotation(testCase.getClass(), HostPort.class);
    for (Field dockerHostPortField : fieldsWithAnnotation) {
      if (!dockerHostPortField.isAccessible()) {
        dockerHostPortField.setAccessible(true);
      }
      if (int.class.isAssignableFrom(dockerHostPortField.getType()) || Integer.class.isAssignableFrom(
        dockerHostPortField.getType())) {
        try {
          final HostPort hostPortAnnotation = dockerHostPortField.getAnnotation(HostPort.class);
          String containerName = hostPortAnnotation.containerName();
          int exposedPort = hostPortAnnotation.value();
          int bindPort = getBindingPort(containerName, exposedPort);
          if (bindPort > 0) {
            dockerHostPortField.set(testCase, bindPort);
          } else {
            logger.log(Level.WARNING, String.format("There is no container with id %s.", containerName));
          }
        } catch (IllegalAccessException e) {
          throw new IllegalArgumentException(e);
        }
      }
    }
  }
}

代码示例来源:origin: arquillian/arquillian-cube

@Cube(value = "pingpong", portBinding = "5000->8080/tcp")
public class PingPongContainer {

  @HostIp
  String dockerHost;

  @HostPort(8080)
  private int port;

  @CubeDockerFile
  public static Archive<?> createContainer() {
    String dockerDescriptor = Descriptors.create(DockerDescriptor.class)
      .from("jonmorehouse/ping-pong")
      .expose(8080)
      .exportAsString();
    return ShrinkWrap.create(GenericArchive.class)
      .add(new StringAsset(dockerDescriptor), "Dockerfile");
  }

  public int getConnectionPort() {
    return port;
  }

  public String getDockerHost() {
    return this.dockerHost;
  }
}

代码示例来源:origin: org.arquillian.cube/arquillian-cube-core

@Override
public Object[] resolve(Method method) {
  Object[] values = new Object[method.getParameterTypes().length];
  if (cubeRegistryInstance.get() != null) {
    Integer[] annotatedParameters = annotatedParameters(method);
    Class<?>[] parameterTypes = method.getParameterTypes();
    for (Integer i : annotatedParameters) {
      if (int.class.isAssignableFrom(parameterTypes[i]) || Integer.class.isAssignableFrom(parameterTypes[i])) {
        final Annotation[] parameterAnnotations = method.getParameterAnnotations()[i];
        final HostPort hostPortAnnotation = findHostPort(parameterAnnotations);
        String containerName = hostPortAnnotation.containerName();
        int exposedPort = hostPortAnnotation.value();
        int bindPort = getBindingPort(containerName, exposedPort);
        if (bindPort > 0) {
          values[i] = bindPort;
        } else {
          logger.log(Level.WARNING, String.format("There is no container with id %s.", containerName));
        }
      }
    }
  }
  return values;
}

代码示例来源:origin: arquillian/arquillian-cube

@Category({RequiresDockerMachine.class, RequiresDocker.class})
@RequiresDockerMachine(name = "dev")
@RunWith(ArquillianConditionalRunner.class)
public class PingPongIT {

  @HostIp
  String ip;

  @HostPort(containerName = "pingpong", value = 8080)
  int port;

  @Test
  public void shouldDoPingPong() {
    get("http://" + ip + ":" + port).then().assertThat().body("status", equalTo("OK"));
  }
}

代码示例来源:origin: arquillian/arquillian-cube

@Category({RequiresDockerMachine.class, RequiresDocker.class})
@RequiresDockerMachine(name = "dev")
@RunWith(ArquillianConditionalRunner.class)
public class TodoBrowserIT {

  @Drone
  WebDriver webDriver;

  @CubeIp(containerName = "helloworld")
  String ip;

  @HostPort(containerName = "helloworld", value = 80)
  int port;

  @Test
  public void shouldShowHelloWorld() throws MalformedURLException, InterruptedException {
    URL url = new URL("http", ip, port, "/");
    webDriver.get(url.toString());
    final String message = webDriver.findElement(By.tagName("h1")).getText();
    assertThat(message, is("Hello world!"));
  }
}

代码示例来源:origin: arquillian/arquillian-cube

String ip;
@HostPort(containerName = "pingpong", value = 8080)
int port;

代码示例来源:origin: arquillian/arquillian-cube

@Category({RequiresDockerMachine.class, RequiresDocker.class})
@RequiresDockerMachine(name = "dev")
@RunWith(ArquillianConditionalRunner.class)
public class TodoBrowserIT {

  @Drone
  WebDriver webDriver;

  @CubeIp(containerName = "helloworld")
  String ip;

  @HostPort(containerName = "helloworld", value = 80)
  int port;

  @Test
  public void shouldShowHelloWorld() throws MalformedURLException, InterruptedException {
    URL url = new URL("http", ip, port, "/");
    webDriver.get(url.toString());
    final String message = webDriver.findElement(By.tagName("h1")).getText();
    assertThat(message, is("Hello world!"));
  }
}

代码示例来源:origin: arquillian/arquillian-cube

String hostIp;
@HostPort(containerName = "tomcat", value = 8080)
int tomcatPort;

代码示例来源:origin: arquillian/arquillian-cube

String ip;
@HostPort(containerName = "pingpong", value = 8080)
int port;

相关文章

微信公众号

最新文章

更多