SiddhiUtils { protected static Object decodeSiddhiValue(String originalValue, Attribute.Type type) { switch (type) { case STRING: return originalValue; case BOOL: return Boolean.valueOf(originalValue); case DOUBLE: return Double.valueOf(originalValue); case INT: return Integer.valueOf(originalValue); case LONG: return Long.valueOf(originalValue); case FLOAT: return Float.valueOf(originalValue); default: throw new RuntimeException("Unsupported Column type: " + originalValue + "/" + type.toString()); } } private  SiddhiUtils(); static boolean columnAlreadyExistsInStream(String columnName, StreamDefinition streamMetaData); static Object[] getOrderedValues(StreamDefinition streamMetaData, List<ColumnNameTypeValue> columns); static Boolean isStreamAllowedForThisOperation(String streamName, String operation); static final String QUERY_PLAN_IDENTIFIER; }
@Test public void testDecode() throws Exception { assertEquals("Unexpected result", "text", SiddhiUtils.decodeSiddhiValue("text", Attribute.Type.STRING)); assertEquals("Unexpected result", true, SiddhiUtils.decodeSiddhiValue("true", Attribute.Type.BOOL)); assertEquals("Unexpected result", 12.1, SiddhiUtils.decodeSiddhiValue("12.1", Attribute.Type.DOUBLE)); assertEquals("Unexpected result", 12, SiddhiUtils.decodeSiddhiValue("12", Attribute.Type.INT)); assertEquals("Unexpected result", 7L, SiddhiUtils.decodeSiddhiValue("7", Attribute.Type.LONG)); assertEquals("Unexpected result", 22f, SiddhiUtils.decodeSiddhiValue("22", Attribute.Type.FLOAT)); Double d= 22d; assertEquals("Unexpected result", "22.0", SiddhiUtils.decodeSiddhiValue(d, Attribute.Type.STRING)); assertEquals("Unexpected result", d, SiddhiUtils.decodeSiddhiValue(d, Attribute.Type.DOUBLE)); assertEquals("Unexpected result", 22, SiddhiUtils.decodeSiddhiValue(d, Attribute.Type.INT)); assertEquals("Unexpected result", 22L, SiddhiUtils.decodeSiddhiValue(d, Attribute.Type.LONG)); assertEquals("Unexpected result", 22f, SiddhiUtils.decodeSiddhiValue(d, Attribute.Type.FLOAT)); }
@Test(expected = RuntimeException.class) public void testDecodeException() throws Exception { assertEquals("Exception expected", "text", SiddhiUtils.decodeSiddhiValue("text", null)); }
@Test(expected = RuntimeException.class) public void testDecodeExceptionDouble() throws Exception { assertEquals("Exception expected", 22d, SiddhiUtils.decodeSiddhiValue(22d, null)); }