Example usage for org.springframework.integration.support.utils IntegrationUtils bytesToString

List of usage examples for org.springframework.integration.support.utils IntegrationUtils bytesToString

Introduction

In this page you can find the example usage for org.springframework.integration.support.utils IntegrationUtils bytesToString.

Prototype

public static String bytesToString(byte[] bytes, String encoding) 

Source Link

Document

Utility method for null-safe conversion from byte[] to String

Usage

From source file:org.springframework.integration.zookeeper.metadata.ZookeeperMetadataStoreTests.java

@Test
public void testPersistKeyValue() throws Exception {
    String testKey = "ZookeeperMetadataStoreTests-Persist";
    metadataStore.put(testKey, "Integration");
    assertNotNull(client.checkExists().forPath(metadataStore.getPath(testKey)));
    assertEquals("Integration",
            IntegrationUtils.bytesToString(client.getData().forPath(metadataStore.getPath(testKey)), "UTF-8"));
}

From source file:org.springframework.integration.zookeeper.metadata.ZookeeperMetadataStoreTests.java

@Test
public void testPutIfAbsent() throws Exception {
    final String testKey = "ZookeeperMetadataStoreTests-Persist";
    final String testKey2 = "ZookeeperMetadataStoreTests-Persist-2";
    metadataStore.put(testKey, "Integration");
    assertNotNull(client.checkExists().forPath(metadataStore.getPath(testKey)));
    assertEquals("Integration",
            IntegrationUtils.bytesToString(client.getData().forPath(metadataStore.getPath(testKey)), "UTF-8"));
    CuratorFramework otherClient = createNewClient();
    final ZookeeperMetadataStore otherMetadataStore = new ZookeeperMetadataStore(otherClient);
    otherMetadataStore.start();//  w  w  w. ja  v  a2 s.com
    otherMetadataStore.putIfAbsent(testKey, "OtherValue");
    assertEquals("Integration",
            IntegrationUtils.bytesToString(client.getData().forPath(metadataStore.getPath(testKey)), "UTF-8"));
    assertEquals("Integration", metadataStore.get(testKey));
    assertThat("Integration", eventually(equalsResult(new Evaluator<String>() {
        @Override
        public String evaluate() {
            return otherMetadataStore.get(testKey);
        }
    })));
    otherMetadataStore.putIfAbsent(testKey2, "Integration-2");
    assertEquals("Integration-2",
            IntegrationUtils.bytesToString(client.getData().forPath(metadataStore.getPath(testKey2)), "UTF-8"));
    assertEquals("Integration-2", otherMetadataStore.get(testKey2));
    assertThat("Integration-2", eventually(equalsResult(new Evaluator<String>() {
        @Override
        public String evaluate() {
            return metadataStore.get(testKey2);
        }
    })));
    closeClient(otherClient);
}

From source file:org.springframework.integration.zookeeper.metadata.ZookeeperMetadataStoreTests.java

@Test
public void testReplace() throws Exception {
    final String testKey = "ZookeeperMetadataStoreTests-Replace";
    metadataStore.put(testKey, "Integration");
    assertNotNull(client.checkExists().forPath(metadataStore.getPath(testKey)));
    assertEquals("Integration",
            IntegrationUtils.bytesToString(client.getData().forPath(metadataStore.getPath(testKey)), "UTF-8"));
    CuratorFramework otherClient = createNewClient();
    final ZookeeperMetadataStore otherMetadataStore = new ZookeeperMetadataStore(otherClient);
    otherMetadataStore.start();//from   w  w w  .j av  a 2s .c  om
    otherMetadataStore.replace(testKey, "OtherValue", "Integration-2");
    assertEquals("Integration",
            IntegrationUtils.bytesToString(client.getData().forPath(metadataStore.getPath(testKey)), "UTF-8"));
    assertEquals("Integration", metadataStore.get(testKey));
    assertThat("Integration", eventually(equalsResult(new Evaluator<String>() {
        @Override
        public String evaluate() {
            return otherMetadataStore.get(testKey);
        }
    })));
    otherMetadataStore.replace(testKey, "Integration", "Integration-2");
    assertEquals("Integration-2",
            IntegrationUtils.bytesToString(client.getData().forPath(metadataStore.getPath(testKey)), "UTF-8"));
    assertThat("Integration-2", eventually(equalsResult(new Evaluator<String>() {
        @Override
        public String evaluate() {
            return metadataStore.get(testKey);
        }
    })));
    assertEquals("Integration-2", otherMetadataStore.get(testKey));
    closeClient(otherClient);
}