Search in sources :

Example 1 with DecodingException

use of com.emc.storageos.coordinator.exceptions.DecodingException in project coprhd-controller by CoprHD.

the class PropertyInfoTest method testEncodeDecode.

@Test
public void testEncodeDecode() {
    Map<String, String> map = new HashMap<String, String>();
    map.put("node_id", "node2");
    map.put("system_connectemc_username", "username");
    map.put("version", "");
    map.put("twoEquals", "abc==abc==abc");
    PropertyInfoExt propertyInfo = new PropertyInfoExt(map);
    String encodeStr2 = propertyInfo.encodeAsString();
    Assert.assertTrue(encodeStr2.indexOf("node_id") != -1);
    Assert.assertTrue(encodeStr2.indexOf("system_connectemc_username") != -1);
    Assert.assertTrue(encodeStr2.indexOf("version") != -1);
    Assert.assertTrue(encodeStr2.indexOf("twoEquals") != -1);
    try {
        PropertyInfoExt props = PropertyInfoExt.class.newInstance().decodeFromString(encodeStr2);
        Assert.assertTrue(props.getAllProperties().get("system_connectemc_username").equals("username"));
        Assert.assertTrue(props.getAllProperties().get("version").equals(""));
        Assert.assertTrue(props.getAllProperties().get("twoEquals").equals("abc==abc==abc"));
    } catch (DecodingException e) {
        Assert.assertTrue(false);
    } catch (Exception e) {
        Assert.assertTrue(false);
    }
    PropertyInfoExt propertyInfo1 = new PropertyInfoExt(new String[] { "", "node_id=node2", "system_connectemc_username=username", "multiEquals=a=b=c" });
    String encodeStr1 = propertyInfo1.encodeAsString();
    char[] chars = encodeStr1.toCharArray();
    int len = chars.length;
    int count = 0;
    for (int i = 0; i < len; i++) {
        if (chars[i] == '=') {
            count++;
        }
    }
    Assert.assertTrue(count == 5);
}
Also used : HashMap(java.util.HashMap) PropertyInfoExt(com.emc.storageos.coordinator.client.model.PropertyInfoExt) DecodingException(com.emc.storageos.coordinator.exceptions.DecodingException) DecodingException(com.emc.storageos.coordinator.exceptions.DecodingException) Test(org.junit.Test)

Aggregations

PropertyInfoExt (com.emc.storageos.coordinator.client.model.PropertyInfoExt)1 DecodingException (com.emc.storageos.coordinator.exceptions.DecodingException)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1