void KillOver21(MutableInt m) { if(m.getValue() > 21) { m.setValue(0); } }
protected <O extends ObjectType> void searchObjectsIterative(Class<O> type, ObjectQuery query, Consumer<PrismObject<O>> handler, Integer expectedNumberOfObjects) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException { Task task = taskManager.createTaskInstance(AbstractModelIntegrationTest.class.getName() + ".assertObjects"); OperationResult result = task.getResult(); final MutableInt count = new MutableInt(0); // Cannot convert to lambda here. Java does not want to understand the generic types properly. SearchResultMetadata searchMetadata = modelService.searchObjectsIterative(type, query, (object, oresult) -> { count.increment(); if (handler != null) { handler.accept(object); } return true; }, null, task, result); if (verbose) display(type.getSimpleName()+"s", count.getValue()); assertEquals("Unexpected number of "+type.getSimpleName()+"s", expectedNumberOfObjects, count.getValue()); }
@Test public void functionRunnerShouldWorkIfNotSucceededOnMaxRetryReached() throws Exception { final MutableInt value = new MutableInt(0); new FunctionRunnerWithRetry(MAX_RETRY).execute( () -> { value.increment(); return (Integer) value.getValue() == MAX_RETRY; } ); assertThat(value.getValue()).isEqualTo(MAX_RETRY); }
@Test public void functionRunnerShouldWorkIfNotSucceededOnFirstTry() throws Exception { final MutableInt value = new MutableInt(0); new FunctionRunnerWithRetry(MAX_RETRY).execute( () -> { value.increment(); return (Integer) value.getValue() == MAX_RETRY / 2; } ); assertThat(value.getValue()).isEqualTo(MAX_RETRY / 2); }
@Test(expected = LightweightTransactionException.class) public void functionRunnerShouldFailIfTransactionCanNotBePerformed() throws Exception { final MutableInt value = new MutableInt(0); new FunctionRunnerWithRetry(MAX_RETRY).execute( () -> { value.increment(); return false; } ); assertThat(value.getValue()).isEqualTo(MAX_RETRY); }
@Test public void functionRunnerShouldWorkOnFirstTry() throws Exception { final MutableInt value = new MutableInt(0); new FunctionRunnerWithRetry(MAX_RETRY).execute( () -> { value.increment(); return true; } ); assertThat(value.getValue()).isEqualTo(1); }
private void assertDummyAccountShadows(int expected, boolean raw, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException { ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(RESOURCE_DUMMY_OID, new QName(RESOURCE_DUMMY_NAMESPACE, "AccountObjectClass"), prismContext); final MutableInt count = new MutableInt(0); ResultHandler<ShadowType> handler = (shadow, parentResult) -> { count.increment(); display("Found",shadow); return true; }; Collection<SelectorOptions<GetOperationOptions>> options = null; if (raw) { options = SelectorOptions.createCollection(GetOperationOptions.createRaw()); } modelService.searchObjectsIterative(ShadowType.class, query, handler, options, task, result); assertEquals("Unexpected number of search results (raw="+raw+")", expected, count.getValue()); }