Search in sources :

Example 1 with JDBCNumberValueHandler

use of org.jkiss.dbeaver.model.impl.jdbc.data.handlers.JDBCNumberValueHandler in project dbeaver by serge-rider.

the class PostgreValueParserTest method convertStringToValue.

@Test
public void convertStringToValue() throws DBCException {
    Assert.assertEquals(1, PostgreValueParser.convertStringToValue(session, intItemType, "1"));
    Assert.assertEquals(1.111, PostgreValueParser.convertStringToValue(session, doubleItemType, "1.111"));
    Assert.assertEquals("A", PostgreValueParser.convertStringToValue(session, stringItemType, "A"));
    Assert.assertNotEquals("ABC", PostgreValueParser.convertStringToValue(session, stringItemType, "A"));
    Assert.assertNotEquals(123, PostgreValueParser.convertStringToValue(session, intItemType, "1"));
    Assert.assertArrayEquals(new String[] { "A", "B" }, (Object[]) PostgreValueParser.convertStringToValue(session, arrayStringItemType, "{\"A\",\"B\"}"));
    Assert.assertArrayEquals(new Integer[] { 1, 22 }, (Object[]) PostgreValueParser.convertStringToValue(session, arrayIntItemType, "{1,22}"));
    Assert.assertArrayEquals(new Double[] { 1.1, 22.22 }, (Object[]) PostgreValueParser.convertStringToValue(session, arrayDoubleItemType, "{1.1,22.22}"));
    Assert.assertNotEquals(new Integer[] { 33333, 22 }, (Object[]) PostgreValueParser.convertStringToValue(session, arrayIntItemType, "{1,22}"));
    JDBCCollection innerCollection1 = new JDBCCollection(doubleItemType, new JDBCNumberValueHandler(doubleItemType, dbdFormatSettings), new Double[] { 1.1, 22.22 });
    JDBCCollection innerCollection2 = new JDBCCollection(doubleItemType, new JDBCNumberValueHandler(doubleItemType, dbdFormatSettings), new Double[] { 3.3, 44.44 });
    Assert.assertArrayEquals(new Object[] { innerCollection1, innerCollection2 }, (Object[]) PostgreValueParser.convertStringToValue(session, arrayDoubleItemType, "{{1.1,22.22},{3.3,44.44}}"));
    JDBCCollection innerCollection3 = new JDBCCollection(doubleItemType, new JDBCNumberValueHandler(doubleItemType, dbdFormatSettings), new Object[] { innerCollection1, innerCollection2 });
    Assert.assertArrayEquals(new Object[] { innerCollection3, innerCollection3 }, (Object[]) PostgreValueParser.convertStringToValue(session, arrayDoubleItemType, "{{{1.1,22.22},{3.3,44.44}},{{1.1,22.22},{3.3,44.44}}}"));
    Assert.assertEquals("{{{1.1,22.22},{3.3,44.44}},{1.1,22.22},{3.3,44.44}}}", PostgreValueParser.convertStringToValue(session, arrayDoubleItemType, "{{{1.1,22.22},{3.3,44.44}},{1.1,22.22},{3.3,44.44}}}"));
    // Bad input data tests
    Assert.assertEquals("{{{1.1,22.22},3.3,44.44}},{1.1,22.22},{3.3,44.44}", PostgreValueParser.convertStringToValue(session, arrayDoubleItemType, "{{{1.1,22.22},3.3,44.44}},{1.1,22.22},{3.3,44.44}"));
    Assert.assertEquals("{{1.1,22.22},3.3,44.44}},{1.1,22.22},{3.3,", PostgreValueParser.convertStringToValue(session, arrayDoubleItemType, "{{1.1,22.22},3.3,44.44}},{1.1,22.22},{3.3,"));
    Assert.assertEquals("{{1.1,22.22},,44.44}},{1.1,22.22},{3.3,}", PostgreValueParser.convertStringToValue(session, arrayDoubleItemType, "{{1.1,22.22},,44.44}},{1.1,22.22},{3.3,}"));
    Boolean[] booleans = { true, false };
    Assert.assertEquals(true, PostgreValueParser.convertStringToValue(session, booleanItemType, "true"));
    Assert.assertNotEquals(false, PostgreValueParser.convertStringToValue(session, booleanItemType, "true"));
    Assert.assertArrayEquals(booleans, (Object[]) PostgreValueParser.convertStringToValue(session, arrayBooleanItemType, "{TRUE,FALSE}"));
// todo: add support alternatives to "true/false"
// Assert.assertArrayEquals(booleans, (Object[]) PostgreValueParser.convertStringToValue(session, arrayBooleanItemType, "{'t','f'}", true));
// Assert.assertArrayEquals(booleans, (Object[]) PostgreValueParser.convertStringToValue(session, arrayBooleanItemType, "{'true','false'}", true));
// Assert.assertArrayEquals(booleans, (Object[]) PostgreValueParser.convertStringToValue(session, arrayBooleanItemType,"{'1','0'}", true));
// Assert.assertArrayEquals(booleans, (Object[]) PostgreValueParser.convertStringToValue(session, arrayBooleanItemType,"{'y','n'}", true));
// Assert.assertArrayEquals(booleans, (Object[]) PostgreValueParser.convertStringToValue(session, arrayBooleanItemType,"{'yes,'no'}", true));
// Assert.assertArrayEquals(booleans, (Object[]) PostgreValueParser.convertStringToValue(session, arrayBooleanItemType,"{'on,'off'}", true));
}
Also used : JDBCCollection(org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCollection) JDBCNumberValueHandler(org.jkiss.dbeaver.model.impl.jdbc.data.handlers.JDBCNumberValueHandler) Test(org.junit.Test)

Aggregations

JDBCCollection (org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCollection)1 JDBCNumberValueHandler (org.jkiss.dbeaver.model.impl.jdbc.data.handlers.JDBCNumberValueHandler)1 Test (org.junit.Test)1