Java 类com.rabbitmq.client.impl.LongStringHelper 实例源码

项目:kafka-connect-rabbitmq    文件:MessageConverterTest.java   
@TestFactory
public Stream<DynamicTest> headers() {
  final List<HeaderTestCase> tests = Arrays.asList(
      HeaderTestCase.of(Byte.valueOf("1"), Schema.Type.INT8.toString().toLowerCase(), Byte.valueOf("1")),
      HeaderTestCase.of(Short.valueOf("1"), Schema.Type.INT16.toString().toLowerCase(), Short.valueOf("1")),
      HeaderTestCase.of(Integer.valueOf("1"), Schema.Type.INT32.toString().toLowerCase(), Integer.valueOf("1")),
      HeaderTestCase.of(Long.valueOf("1"), Schema.Type.INT64.toString().toLowerCase(), Long.valueOf("1")),
      HeaderTestCase.of(Float.valueOf("1"), Schema.Type.FLOAT32.toString().toLowerCase(), Float.valueOf("1")),
      HeaderTestCase.of(Double.valueOf("1"), Schema.Type.FLOAT64.toString().toLowerCase(), Double.valueOf("1")),
      HeaderTestCase.of("1", Schema.Type.STRING.toString().toLowerCase(), "1"),
      HeaderTestCase.of(LongStringHelper.asLongString("1"), Schema.Type.STRING.toString().toLowerCase(), "1"),
      HeaderTestCase.of(new Date(1500691965123L), "timestamp", new Date(1500691965123L))
  );

  return tests.stream().map(test -> dynamicTest(test.toString(), () -> {
    final Map<String, Object> INPUT_HEADERS = ImmutableMap.of("input", test.input);
    BasicProperties basicProperties = mock(BasicProperties.class);
    when(basicProperties.getHeaders()).thenReturn(INPUT_HEADERS);
    final Map<String, Struct> actual = MessageConverter.headers(basicProperties);
    verify(basicProperties, only()).getHeaders();
    assertNotNull(actual, "actual should not be null.");
    assertTrue(actual.containsKey("input"), "actual should contain key 'input'");
    Struct actualStruct = actual.get("input");
    actualStruct.validate();
    assertStruct(test.expectedStruct(), actualStruct);
  }));
}
项目:Camel    文件:RabbitMQEndpointTest.java   
@Test
public void testCreatingRabbitExchangeSetsCustomHeaders() throws Exception {
    RabbitMQEndpoint endpoint = context.getEndpoint("rabbitmq:localhost/exchange", RabbitMQEndpoint.class);

    String routingKey = UUID.randomUUID().toString();
    String exchangeName = UUID.randomUUID().toString();
    long tag = UUID.randomUUID().toString().hashCode();

    Mockito.when(envelope.getRoutingKey()).thenReturn(routingKey);
    Mockito.when(envelope.getExchange()).thenReturn(exchangeName);
    Mockito.when(envelope.getDeliveryTag()).thenReturn(tag);

    Map<String, Object> customHeaders = new HashMap<String, Object>();
    customHeaders.put("stringHeader", "A string");
    customHeaders.put("bigDecimalHeader", new BigDecimal("12.34"));
    customHeaders.put("integerHeader", 42);
    customHeaders.put("doubleHeader", 42.24);
    customHeaders.put("booleanHeader", true);
    customHeaders.put("dateHeader", new Date(0));
    customHeaders.put("byteArrayHeader", "foo".getBytes());
    customHeaders.put("longStringHeader", LongStringHelper.asLongString("Some really long string"));
    customHeaders.put("timestampHeader", new Timestamp(4200));
    customHeaders.put("byteHeader", new Byte((byte) 0));
    customHeaders.put("floatHeader", new Float(42.4242));
    customHeaders.put("longHeader", new Long(420000000000000000L));
    Mockito.when(properties.getHeaders()).thenReturn(customHeaders);

    byte[] body = new byte[20];
    Exchange exchange = endpoint.createRabbitExchange(envelope, properties, body);
    assertEquals(exchangeName, exchange.getIn().getHeader(RabbitMQConstants.EXCHANGE_NAME));
    assertEquals(routingKey, exchange.getIn().getHeader(RabbitMQConstants.ROUTING_KEY));
    assertEquals(tag, exchange.getIn().getHeader(RabbitMQConstants.DELIVERY_TAG));
    assertEquals("A string", exchange.getIn().getHeader("stringHeader"));
    assertEquals(new BigDecimal("12.34"), exchange.getIn().getHeader("bigDecimalHeader"));
    assertEquals(42, exchange.getIn().getHeader("integerHeader"));
    assertEquals(42.24, exchange.getIn().getHeader("doubleHeader"));
    assertEquals(true, exchange.getIn().getHeader("booleanHeader"));
    assertEquals(new Date(0), exchange.getIn().getHeader("dateHeader"));
    assertArrayEquals("foo".getBytes(), (byte[]) exchange.getIn().getHeader("byteArrayHeader"));
    assertEquals("Some really long string", exchange.getIn().getHeader("longStringHeader"));
    assertEquals(new Timestamp(4200), exchange.getIn().getHeader("timestampHeader"));
    assertEquals(new Byte((byte) 0), exchange.getIn().getHeader("byteHeader"));
    assertEquals(new Float(42.4242), exchange.getIn().getHeader("floatHeader"));
    assertEquals(new Long(420000000000000000L), exchange.getIn().getHeader("longHeader"));
    assertEquals(body, exchange.getIn().getBody());
}