Search in sources :

Example 6 with SqlServiceMock

use of org.eclipse.scout.rt.server.jdbc.fixture.SqlServiceMock in project scout.rt by eclipse.

the class SelectIntoArrayTest method testSelectFromFormDataArray.

@Test
public void testSelectFromFormDataArray() throws Exception {
    SqlServiceMock sql = new SqlServiceMock();
    Object[][] expectedData = new Object[][] { new Object[] { true, 1, "abc" } };
    sql.setResultData(expectedData);
    // 
    MyFormData f1 = new MyFormData();
    f1.getActive().setValue(true);
    f1.getState().setValue(1);
    f1.getName().setValue("abc");
    MyFormData f2 = new MyFormData();
    f2.getActive().setValue(null);
    f2.getState().setValue(null);
    f2.getName().setValue(null);
    // 
    MyFormData[] h = new MyFormData[] { f1, f2 };
    Object[][] data = sql.select("SELECT A,B,C FROM T WHERE A=:{h.active} AND B=:{h.state} AND C=:{h.name}", new NVPair("h", h));
    assertNotNull(data);
    assertEquals(2, data.length);
    assertArrayEquals(new Object[] { true, 1, "abc" }, data[0]);
    assertArrayEquals(new Object[] { true, 1, "abc" }, data[1]);
}
Also used : SqlServiceMock(org.eclipse.scout.rt.server.jdbc.fixture.SqlServiceMock) NVPair(org.eclipse.scout.rt.platform.holders.NVPair) Test(org.junit.Test)

Example 7 with SqlServiceMock

use of org.eclipse.scout.rt.server.jdbc.fixture.SqlServiceMock in project scout.rt by eclipse.

the class SelectIntoArrayTest method testSelectIntoFormDataWithArray.

@Test
public void testSelectIntoFormDataWithArray() throws Exception {
    SqlServiceMock sql = createSqlServiceMock(ROLES_DATA);
    // 
    FormDataWithArray formData = new FormDataWithArray();
    formData.getPersonNr().setValue(42L);
    sql.selectInto("SELECT ROLE_NR FROM USER_ROLE WHERE USER_NR = :personNr INTO :{roles}", formData);
    Long[] r = formData.getRoles().getValue();
    assertNotNull(r);
    assertEquals(3, r.length);
    assertEquals("first role", 3L, r[0].longValue());
    assertEquals("second role", 5L, r[1].longValue());
    assertEquals("third role", 7L, r[2].longValue());
}
Also used : SqlServiceMock(org.eclipse.scout.rt.server.jdbc.fixture.SqlServiceMock) FormDataWithArray(org.eclipse.scout.rt.server.jdbc.fixture.FormDataWithArray) Test(org.junit.Test)

Example 8 with SqlServiceMock

use of org.eclipse.scout.rt.server.jdbc.fixture.SqlServiceMock in project scout.rt by eclipse.

the class SelectIntoArrayTest method testSelectIntoListInHolder.

@Test
public void testSelectIntoListInHolder() throws Exception {
    SqlServiceMock sql = createSqlServiceMock(ROLES_DATA);
    // 
    Holder<List> rolesHolder = new Holder<List>(List.class);
    sql.selectInto("SELECT ROLE_NR FROM USER_ROLE WHERE USER_NR = :personNr INTO :{roles}", new NVPair("personNr", 63L), new NVPair("roles", rolesHolder));
    List r = rolesHolder.getValue();
    assertNotNull(r);
    assertEquals(3, r.size());
    assertEquals("first role", 3L, r.get(0));
    assertEquals("second role", 5L, r.get(1));
    assertEquals("third role", 7L, r.get(2));
}
Also used : SqlServiceMock(org.eclipse.scout.rt.server.jdbc.fixture.SqlServiceMock) BeanArrayHolder(org.eclipse.scout.rt.platform.holders.BeanArrayHolder) ITableBeanHolder(org.eclipse.scout.rt.platform.holders.ITableBeanHolder) Holder(org.eclipse.scout.rt.platform.holders.Holder) NVPair(org.eclipse.scout.rt.platform.holders.NVPair) List(java.util.List) Test(org.junit.Test)

Example 9 with SqlServiceMock

use of org.eclipse.scout.rt.server.jdbc.fixture.SqlServiceMock in project scout.rt by eclipse.

the class SelectIntoArrayTest method testSelectIntoFormDataArray.

@Test
public void testSelectIntoFormDataArray() throws Exception {
    SqlServiceMock sql = createSqlServiceMock(DATA);
    // 
    Object[][] expectedData = DATA;
    BeanArrayHolder<MyFormData> h = new BeanArrayHolder<SelectIntoArrayTest.MyFormData>(MyFormData.class);
    sql.selectInto("SELECT A,B,C FROM T WHERE D=0 INTO :{h.active},:{h.state},:{h.name}", new NVPair("h", h));
    MyFormData[] a = h.getBeans();
    assertNotNull(a);
    assertEquals(4, a.length);
    for (int i = 0; i < a.length; i++) {
        a[i].assertValues(expectedData[i]);
    }
}
Also used : SqlServiceMock(org.eclipse.scout.rt.server.jdbc.fixture.SqlServiceMock) NVPair(org.eclipse.scout.rt.platform.holders.NVPair) BeanArrayHolder(org.eclipse.scout.rt.platform.holders.BeanArrayHolder) Test(org.junit.Test)

Example 10 with SqlServiceMock

use of org.eclipse.scout.rt.server.jdbc.fixture.SqlServiceMock in project scout.rt by eclipse.

the class SelectIntoArrayTest method testSelectIntoTableFieldBeanDataInBean.

/**
 * {@link TableFieldBeanData} is from type {@link ITableBeanHolder} (introduced with Luna). TableData is in a bean
 * (ContainerBean).
 */
@Test
public void testSelectIntoTableFieldBeanDataInBean() throws Exception {
    SqlServiceMock sql = createSqlServiceMock(DATA);
    // 
    ContainerBean bean = new ContainerBean();
    bean.setTableFieldBeanData(new TableFieldBeanData());
    sql.selectInto("SELECT A,B,C FROM T WHERE D=0 INTO :{tableFieldBeanData.active},:{tableFieldBeanData.state},:{tableFieldBeanData.name}", bean);
    assertContainsData(bean.getTableFieldBeanData());
}
Also used : ContainerBean(org.eclipse.scout.rt.server.jdbc.fixture.ContainerBean) SqlServiceMock(org.eclipse.scout.rt.server.jdbc.fixture.SqlServiceMock) TableFieldBeanData(org.eclipse.scout.rt.server.jdbc.fixture.TableFieldBeanData) Test(org.junit.Test)

Aggregations

SqlServiceMock (org.eclipse.scout.rt.server.jdbc.fixture.SqlServiceMock)31 Test (org.junit.Test)28 NVPair (org.eclipse.scout.rt.platform.holders.NVPair)12 TableFieldBeanData (org.eclipse.scout.rt.server.jdbc.fixture.TableFieldBeanData)12 TableBeanHolderFilter (org.eclipse.scout.rt.platform.holders.TableBeanHolderFilter)4 FormDataWithSet (org.eclipse.scout.rt.server.jdbc.fixture.FormDataWithSet)4 BeanArrayHolder (org.eclipse.scout.rt.platform.holders.BeanArrayHolder)3 ContainerBean (org.eclipse.scout.rt.server.jdbc.fixture.ContainerBean)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Holder (org.eclipse.scout.rt.platform.holders.Holder)2 ITableBeanHolder (org.eclipse.scout.rt.platform.holders.ITableBeanHolder)2 FormDataWithArray (org.eclipse.scout.rt.server.jdbc.fixture.FormDataWithArray)2 BeanMetaData (org.eclipse.scout.rt.platform.BeanMetaData)1 ITableBeanRowHolder (org.eclipse.scout.rt.platform.holders.ITableBeanRowHolder)1 Before (org.junit.Before)1