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();
}
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());
}
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();
}
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());
}
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);
}
}
Aggregations