Search in sources :

Example 1 with IntegerHolder

use of org.eclipse.scout.rt.platform.holders.IntegerHolder in project scout.rt by eclipse.

the class AbstractCodeTypeWithGeneric method getCodeIndex.

@Override
public int getCodeIndex(final CODE_ID id) {
    final IntegerHolder result = new IntegerHolder(-1);
    ICodeVisitor<ICode<CODE_ID>> v = new ICodeVisitor<ICode<CODE_ID>>() {

        private int m_index = 0;

        @Override
        public boolean visit(ICode<CODE_ID> code, int treeLevel) {
            if (ObjectUtility.equals(code.getId(), id)) {
                result.setValue(m_index);
            } else {
                m_index++;
            }
            return result.getValue() < 0;
        }
    };
    visit(v, false);
    return result.getValue();
}
Also used : IntegerHolder(org.eclipse.scout.rt.platform.holders.IntegerHolder)

Example 2 with IntegerHolder

use of org.eclipse.scout.rt.platform.holders.IntegerHolder in project scout.rt by eclipse.

the class ActionTest method testOutlineButton.

@Test
public void testOutlineButton() {
    IDesktop desktopMock = Mockito.mock(IDesktop.class);
    IOutline outlineMock = Mockito.mock(IOutline.class);
    Mockito.when(desktopMock.getAvailableOutlines()).thenReturn(CollectionUtility.arrayList(outlineMock));
    final IntegerHolder execActionHolder = new IntegerHolder(0);
    final IntegerHolder execToggleHolder = new IntegerHolder(0);
    AbstractOutlineViewButton b = new AbstractOutlineViewButton(desktopMock, outlineMock.getClass()) {

        @Override
        protected void execAction() {
            execActionHolder.setValue(execActionHolder.getValue() + 1);
        }

        @Override
        protected void execSelectionChanged(boolean selection) {
            execToggleHolder.setValue(execToggleHolder.getValue() + 1);
        }
    };
    b.getUIFacade().setSelectedFromUI(true);
    b.getUIFacade().fireActionFromUI();
    assertEquals(1, execActionHolder.getValue().intValue());
    assertEquals(1, execToggleHolder.getValue().intValue());
    assertTrue(b.isSelected());
    b.getUIFacade().fireActionFromUI();
    assertEquals(2, execActionHolder.getValue().intValue());
    assertEquals(1, execToggleHolder.getValue().intValue());
    assertTrue(b.isSelected());
    b.getUIFacade().setSelectedFromUI(false);
    b.getUIFacade().fireActionFromUI();
    assertEquals(3, execActionHolder.getValue().intValue());
    assertEquals(2, execToggleHolder.getValue().intValue());
    assertFalse(b.isSelected());
}
Also used : IntegerHolder(org.eclipse.scout.rt.platform.holders.IntegerHolder) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) AbstractOutlineViewButton(org.eclipse.scout.rt.client.ui.desktop.outline.AbstractOutlineViewButton) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) Test(org.junit.Test)

Example 3 with IntegerHolder

use of org.eclipse.scout.rt.platform.holders.IntegerHolder in project scout.rt by eclipse.

the class StatementProcessorTest method testIgnoreInvalidDuplicateBinds.

@Test
public void testIgnoreInvalidDuplicateBinds() {
    AbstractSqlService sqlService = new AbstractSqlService() {
    };
    BeanInstanceUtil.initializeBeanInstance(sqlService);
    // The abstract server session contains active but without a setter and is thus not a valid bind
    // In this test, the NVPair active should be used and there should be no exception throw
    StatementProcessor sp = new StatementProcessor(sqlService, "SELECT 1 FROM DUAL INTO :active ", new Object[] { new Session(), new NVPair("active", new IntegerHolder()) });
    sp.simulate();
}
Also used : IntegerHolder(org.eclipse.scout.rt.platform.holders.IntegerHolder) AbstractSqlService(org.eclipse.scout.rt.server.jdbc.AbstractSqlService) NVPair(org.eclipse.scout.rt.platform.holders.NVPair) RunWithServerSession(org.eclipse.scout.rt.testing.server.runner.RunWithServerSession) TestJdbcServerSession(org.eclipse.scout.rt.server.TestJdbcServerSession) AbstractServerSession(org.eclipse.scout.rt.server.AbstractServerSession) Test(org.junit.Test)

Example 4 with IntegerHolder

use of org.eclipse.scout.rt.platform.holders.IntegerHolder in project scout.rt by eclipse.

the class ConcurrentExpiringMapTest method testBoundedSize.

@Test
public void testBoundedSize() {
    int targetSize = 10;
    final IntegerHolder countEvicted = new IntegerHolder(0);
    long now = System.currentTimeMillis();
    int overflowSize = targetSize * 3 / 2;
    TestConcurrentExpiringMap map = new TestConcurrentExpiringMap(0, TimeUnit.MILLISECONDS, targetSize) {

        @Override
        protected void execEntryEvicted(Integer key, String value) {
            Integer currentCount = countEvicted.getValue();
            countEvicted.setValue(currentCount + 1);
        }
    };
    map.setTimestamp(now - 1);
    // put in some expired values
    for (int i = 0; i < overflowSize - 1; i++) {
        map.put(i, String.valueOf(i));
        assertEquals(Integer.valueOf(0), countEvicted.getValue());
    }
    assertEquals(overflowSize - 1, map.size());
    // access elements to assert LRU behavior
    for (int i = 0; i < overflowSize - 1; i++) {
        assertEquals(String.valueOf(i), map.get(i));
    }
    assertEquals(Integer.valueOf(0), countEvicted.getValue());
    // overload
    for (int i = overflowSize; i < (overflowSize - 1) * 2; i++) {
        map.put(i, String.valueOf(i));
    }
    assertEquals(Integer.valueOf(overflowSize), countEvicted.getValue());
}
Also used : IntegerHolder(org.eclipse.scout.rt.platform.holders.IntegerHolder) Test(org.junit.Test)

Example 5 with IntegerHolder

use of org.eclipse.scout.rt.platform.holders.IntegerHolder in project scout.rt by eclipse.

the class StatementProcessorTest method testDuplicateBindNames.

@Test
public void testDuplicateBindNames() {
    final String bind1Name = "bind1";
    final String bind2Name = "bind2";
    final String bindSessionName = "userId";
    final String stmtWithInBinds = "select :" + bind1Name + ", :" + bind2Name + " from dual";
    final String stmtWithOutBinds = "select 1, 2 from dual into :" + bind1Name + ", :" + bind2Name;
    final String stmtWithSessionProperty = "select :" + bindSessionName + ", :" + bind1Name + " from dual";
    // test in binds
    assertArrayEquals(new String[] {}, exec(true, stmtWithInBinds, new NVPair(bind1Name, null), new NVPair(bind2Name, null)));
    assertArrayEquals(new String[] { bind1Name }, exec(true, stmtWithInBinds, new NVPair(bind1Name, null), new NVPair(bind2Name, null), new NVPair(bind1Name, null)));
    // test out binds
    assertArrayEquals(new String[] {}, exec(true, stmtWithOutBinds, new NVPair(bind1Name, new IntegerHolder()), new NVPair(bind2Name, new IntegerHolder())));
    assertArrayEquals(new String[] { bind1Name }, exec(true, stmtWithOutBinds, new NVPair(bind1Name, new IntegerHolder()), new NVPair(bind2Name, new IntegerHolder()), new NVPair(bind1Name, new IntegerHolder())));
    // test duplicate with property from session
    assertArrayEquals(new String[] { bindSessionName }, exec(true, stmtWithSessionProperty, new NVPair(bindSessionName, null), new NVPair(bind1Name, null)));
    // test with duplicate check disabled
    assertArrayEquals(new String[] {}, exec(false, stmtWithInBinds, new NVPair(bind1Name, null), new NVPair(bind2Name, null), new NVPair(bind1Name, null)));
    assertArrayEquals(new String[] {}, exec(false, stmtWithOutBinds, new NVPair(bind1Name, new IntegerHolder()), new NVPair(bind2Name, new IntegerHolder()), new NVPair(bind1Name, new IntegerHolder())));
    // missing input with duplicate checking
    try {
        exec(true, stmtWithInBinds, new NVPair(bind1Name, null));
        fail();
    } catch (ProcessingException e) {
        assertNotNull(e);
    }
    // missing output with duplicate checking
    try {
        exec(true, stmtWithOutBinds, new NVPair(bind1Name, new IntegerHolder()));
        fail();
    } catch (ProcessingException e) {
        assertNotNull(e);
    }
    // missing input without duplicate checking
    try {
        exec(false, stmtWithInBinds, new NVPair(bind1Name, null));
        fail();
    } catch (ProcessingException e) {
        assertNotNull(e);
    }
    // missing output without duplicate checking
    try {
        exec(false, stmtWithOutBinds, new NVPair(bind1Name, new IntegerHolder()));
        fail();
    } catch (ProcessingException e) {
        assertNotNull(e);
    }
}
Also used : IntegerHolder(org.eclipse.scout.rt.platform.holders.IntegerHolder) NVPair(org.eclipse.scout.rt.platform.holders.NVPair) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) Test(org.junit.Test)

Aggregations

IntegerHolder (org.eclipse.scout.rt.platform.holders.IntegerHolder)7 Test (org.junit.Test)5 NVPair (org.eclipse.scout.rt.platform.holders.NVPair)3 AbstractSqlService (org.eclipse.scout.rt.server.jdbc.AbstractSqlService)2 IDesktop (org.eclipse.scout.rt.client.ui.desktop.IDesktop)1 AbstractOutlineViewButton (org.eclipse.scout.rt.client.ui.desktop.outline.AbstractOutlineViewButton)1 IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)1 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)1 AbstractServerSession (org.eclipse.scout.rt.server.AbstractServerSession)1 TestJdbcServerSession (org.eclipse.scout.rt.server.TestJdbcServerSession)1 RunWithServerSession (org.eclipse.scout.rt.testing.server.runner.RunWithServerSession)1