Search in sources :

Example 76 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project xwiki-platform by xwiki.

the class NotificationPreferenceScriptServiceTest method saveNotificationPreferences.

@Test
public void saveNotificationPreferences() throws Exception {
    DocumentReference userRef = new DocumentReference("xwiki", "XWiki", "UserA");
    NotificationPreferenceImpl existingPref1 = new NotificationPreferenceImpl(true, NotificationFormat.ALERT, "create");
    NotificationPreferenceImpl existingPref2 = new NotificationPreferenceImpl(true, NotificationFormat.EMAIL, "update");
    NotificationPreferenceImpl existingPref3 = new NotificationPreferenceImpl(false, NotificationFormat.EMAIL, "delete");
    when(notificationPreferenceManager.getAllPreferences(eq(userRef))).thenReturn(Arrays.asList(existingPref1, existingPref2, existingPref3));
    final MutableBoolean isOk = new MutableBoolean(false);
    doAnswer(invocationOnMock -> {
        List<NotificationPreference> prefsToSave = invocationOnMock.getArgument(0);
        // 1 of the preferences contained in the JSON file should be saved because the inherited preference
        // is the same
        assertEquals(9, prefsToSave.size());
        assertTrue(prefsToSave.contains(existingPref1));
        assertTrue(prefsToSave.contains(existingPref2));
        assertFalse(prefsToSave.contains(existingPref3));
        isOk.setTrue();
        return true;
    }).when(notificationPreferenceManager).savePreferences(any(List.class));
    mocker.getComponentUnderTest().saveNotificationPreferences(IOUtils.toString(getClass().getResourceAsStream("/preferences.json")), userRef);
    assertTrue(isOk.booleanValue());
}
Also used : AbstractNotificationPreference(org.xwiki.notifications.preferences.internal.AbstractNotificationPreference) NotificationPreference(org.xwiki.notifications.preferences.NotificationPreference) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) ComponentList(org.xwiki.test.annotation.ComponentList) List(java.util.List) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 77 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project apex-malhar by apache.

the class SimpleDoneQueryQueueManagerTest method resetPermitsTest.

@Test
public void resetPermitsTest() throws Exception {
    SimpleDoneQueueManager<Query, Void> sdqqm = new SimpleDoneQueueManager<Query, Void>();
    sdqqm.setup(null);
    sdqqm.beginWindow(0);
    Query query = new MockQuery("1");
    sdqqm.enqueue(query, null, new MutableBoolean(false));
    Assert.assertEquals(1, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
    QueryBundle<Query, Void, MutableBoolean> qb = sdqqm.dequeueBlock();
    Assert.assertEquals(0, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
    sdqqm.endWindow();
    sdqqm.beginWindow(1);
    Assert.assertEquals(1, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
    qb = sdqqm.dequeueBlock();
    Assert.assertEquals(0, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
    testBlocking(sdqqm);
    sdqqm.endWindow();
}
Also used : Query(org.apache.apex.malhar.lib.appdata.schemas.Query) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) Test(org.junit.Test)

Example 78 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project apex-malhar by apache.

the class SimpleDoneQueryQueueManagerTest method firstDoneTest.

@Test
public void firstDoneTest() {
    SimpleDoneQueueManager<Query, Void> sdqqm = new SimpleDoneQueueManager<Query, Void>();
    sdqqm.setup(null);
    sdqqm.beginWindow(0);
    Query query = new MockQuery("1");
    sdqqm.enqueue(query, null, new MutableBoolean(true));
    QueryBundle<Query, Void, MutableBoolean> qb = sdqqm.dequeue();
    Assert.assertEquals("Should return back null.", null, qb);
    sdqqm.endWindow();
    sdqqm.beginWindow(1);
    qb = sdqqm.dequeue();
    Assert.assertEquals("Should return back null.", null, qb);
    qb = sdqqm.dequeue();
    Assert.assertEquals("Should return back null.", null, qb);
    sdqqm.endWindow();
    sdqqm.teardown();
}
Also used : Query(org.apache.apex.malhar.lib.appdata.schemas.Query) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) Test(org.junit.Test)

Example 79 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project apex-malhar by apache.

the class SimpleDoneQueryQueueManagerTest method expiredTestBlockingExpiredFirstValidLast.

@Test
public void expiredTestBlockingExpiredFirstValidLast() throws Exception {
    SimpleDoneQueueManager<Query, Void> sdqqm = new SimpleDoneQueueManager<Query, Void>();
    sdqqm.setup(null);
    sdqqm.beginWindow(0);
    Query query = new MockQuery("1");
    MutableBoolean queueContext = new MutableBoolean(false);
    sdqqm.enqueue(query, null, queueContext);
    Query query1 = new MockQuery("2");
    MutableBoolean queueContext1 = new MutableBoolean(false);
    sdqqm.enqueue(query1, null, queueContext1);
    Assert.assertEquals(2, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
    QueryBundle<Query, Void, MutableBoolean> qb = sdqqm.dequeueBlock();
    Assert.assertEquals(1, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
    sdqqm.endWindow();
    sdqqm.beginWindow(1);
    Assert.assertEquals(2, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
    queueContext.setValue(true);
    qb = sdqqm.dequeueBlock();
    Assert.assertEquals(0, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
    testBlocking(sdqqm);
    sdqqm.endWindow();
    sdqqm.beginWindow(2);
    Assert.assertEquals(1, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
    qb = sdqqm.dequeueBlock();
    testBlocking(sdqqm);
    sdqqm.endWindow();
    sdqqm.teardown();
}
Also used : Query(org.apache.apex.malhar.lib.appdata.schemas.Query) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) Test(org.junit.Test)

Example 80 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project sling-org-apache-sling-testing-clients by apache.

the class PollingTest method testCallableOnce.

// 
// Tests with Callable
// 
@Test
public void testCallableOnce() throws Exception {
    final MutableInt callCount = new MutableInt(0);
    final MutableBoolean called = new MutableBoolean(false);
    Polling p = new Polling(() -> {
        callCount.increment();
        return true;
    });
    p.poll(500, 10);
    assertEquals(1, callCount.intValue());
}
Also used : MutableInt(org.apache.commons.lang3.mutable.MutableInt) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) Test(org.junit.Test)

Aggregations

MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)107 Test (org.junit.Test)28 Path (java.nio.file.Path)26 Test (org.junit.jupiter.api.Test)17 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)12 Query (org.apache.apex.malhar.lib.appdata.schemas.Query)11 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)11 List (java.util.List)9 AMutableInt64 (org.apache.asterix.om.base.AMutableInt64)8 MutableInt (org.apache.commons.lang3.mutable.MutableInt)7 MutableLong (org.apache.commons.lang3.mutable.MutableLong)7 Collections (java.util.Collections)6 AMutableDouble (org.apache.asterix.om.base.AMutableDouble)6 Set (java.util.Set)5 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)5 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)5 PageCache (org.neo4j.io.pagecache.PageCache)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 ClassAd (org.apache.asterix.external.classad.ClassAd)4