@Test public void getRecordableEventDescriptors() throws Exception { RecordableEventDescriptor descriptorWiki1_1 = mock(RecordableEventDescriptor.class); RecordableEventDescriptor descriptorWiki1_2 = mock(RecordableEventDescriptor.class); UntypedRecordableEventDescriptor descriptorWiki1_3 = mock(UntypedRecordableEventDescriptor.class); UntypedRecordableEventDescriptor descriptorWiki1_4 = mock(UntypedRecordableEventDescriptor.class); RecordableEventDescriptor descriptorWiki2_1 = mock(RecordableEventDescriptor.class); RecordableEventDescriptor descriptorWiki2_2 = mock(RecordableEventDescriptor.class); UntypedRecordableEventDescriptor descriptorWiki2_3 = mock(UntypedRecordableEventDescriptor.class); UntypedRecordableEventDescriptor descriptorWiki2_4 = mock(UntypedRecordableEventDescriptor.class); when(contextComponentManager.getInstanceList(RecordableEventDescriptor.class)).thenReturn( Arrays.asList(descriptorWiki1_1, descriptorWiki1_2)); when(contextComponentManager.getInstanceList(UntypedRecordableEventDescriptor.class)).thenReturn( Arrays.asList(descriptorWiki1_3, descriptorWiki1_4)); when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wiki1"); when(descriptorWiki1_1.isEnabled("wiki1")).thenReturn(true); when(descriptorWiki1_2.isEnabled("wiki1")).thenReturn(false); when(descriptorWiki1_3.isEnabled("wiki1")).thenReturn(false); when(descriptorWiki1_4.isEnabled("wiki1")).thenReturn(true); when(wikiDescriptorManager.getAllIds()).thenReturn(Arrays.asList("wiki1", "wiki2", "wiki3")); ComponentManager wiki1ComponentManager = mock(ComponentManager.class); when(componentManagerManager.getComponentManager("wiki:wiki1", false)).thenReturn(wiki1ComponentManager); when(wiki1ComponentManager.getInstanceList(RecordableEventDescriptor.class)).thenReturn( Arrays.asList(descriptorWiki1_1, descriptorWiki1_2)); when(wiki1ComponentManager.getInstanceList(UntypedRecordableEventDescriptor.class)).thenReturn( Arrays.asList(descriptorWiki1_3, descriptorWiki1_4)); ComponentManager wiki2ComponentManager = mock(ComponentManager.class); when(componentManagerManager.getComponentManager("wiki:wiki2", false)).thenReturn(wiki2ComponentManager); when(wiki2ComponentManager.getInstanceList(RecordableEventDescriptor.class)).thenReturn( Arrays.asList(descriptorWiki2_1, descriptorWiki2_2)); when(wiki2ComponentManager.getInstanceList(UntypedRecordableEventDescriptor.class)).thenReturn( Arrays.asList(descriptorWiki2_3, descriptorWiki2_4)); when(descriptorWiki2_1.isEnabled("wiki2")).thenReturn(false); when(descriptorWiki2_2.isEnabled("wiki2")).thenReturn(true); when(descriptorWiki2_3.isEnabled("wiki2")).thenReturn(true); when(descriptorWiki2_4.isEnabled("wiki2")).thenReturn(false); List<RecordableEventDescriptor> result = mocker.getComponentUnderTest().getRecordableEventDescriptors(true); assertNotNull(result); assertEquals(4, result.size()); assertTrue(result.contains(descriptorWiki1_1)); assertTrue(result.contains(descriptorWiki1_4)); assertTrue(result.contains(descriptorWiki2_2)); assertTrue(result.contains(descriptorWiki2_3)); List<RecordableEventDescriptor> result2 = mocker.getComponentUnderTest().getRecordableEventDescriptors(false); assertNotNull(result2); assertEquals(2, result2.size()); assertTrue(result2.contains(descriptorWiki1_1)); assertTrue(result2.contains(descriptorWiki1_4)); }
@Override public List<RecordableEventDescriptor> getRecordableEventDescriptors(boolean allWikis) throws EventStreamException { try { Set<RecordableEventDescriptor> recordableEventDescriptors = new HashSet<>(); recordableEventDescriptors.addAll(contextComponentManager.getInstanceList(RecordableEventDescriptor.class)); recordableEventDescriptors.addAll(contextComponentManager.getInstanceList( UntypedRecordableEventDescriptor.class)); Iterator<RecordableEventDescriptor> iterator = recordableEventDescriptors.iterator(); while (iterator.hasNext()) { RecordableEventDescriptor descriptor = iterator.next(); if (!descriptor.isEnabled(wikiDescriptorManager.getCurrentWikiId())) { iterator.remove(); } } if (allWikis) { for (String wikiId : wikiDescriptorManager.getAllIds()) { recordableEventDescriptors.addAll(getDescriptorsFromWiki(wikiId)); } } return new ArrayList<>(recordableEventDescriptors); } catch (WikiManagerException | ComponentLookupException e) { throw new EventStreamException("Failed to get the list of all Recordable Event Descriptors.", e); } }
DefaultRecordableEventDescriptorManager implements RecordableEventDescriptorManager { @Override public List<RecordableEventDescriptor> getRecordableEventDescriptors(boolean allWikis) throws EventStreamException { try { Set<RecordableEventDescriptor> recordableEventDescriptors = new HashSet<>(); recordableEventDescriptors.addAll(contextComponentManager.getInstanceList(RecordableEventDescriptor.class)); recordableEventDescriptors.addAll(contextComponentManager.getInstanceList( UntypedRecordableEventDescriptor.class)); Iterator<RecordableEventDescriptor> iterator = recordableEventDescriptors.iterator(); while (iterator.hasNext()) { RecordableEventDescriptor descriptor = iterator.next(); if (!descriptor.isEnabled(wikiDescriptorManager.getCurrentWikiId())) { iterator.remove(); } } if (allWikis) { for (String wikiId : wikiDescriptorManager.getAllIds()) { recordableEventDescriptors.addAll(getDescriptorsFromWiki(wikiId)); } } return new ArrayList<>(recordableEventDescriptors); } catch (WikiManagerException | ComponentLookupException e) { throw new EventStreamException("Failed to get the list of all Recordable Event Descriptors.", e); } } }
DefaultRecordableEventDescriptorManager implements RecordableEventDescriptorManager { @Override public List<RecordableEventDescriptor> getRecordableEventDescriptors(boolean allWikis) throws EventStreamException { try { Set<RecordableEventDescriptor> recordableEventDescriptors = new HashSet<>(); recordableEventDescriptors.addAll(contextComponentManager.getInstanceList(RecordableEventDescriptor.class)); recordableEventDescriptors.addAll(contextComponentManager.getInstanceList( UntypedRecordableEventDescriptor.class)); Iterator<RecordableEventDescriptor> iterator = recordableEventDescriptors.iterator(); while (iterator.hasNext()) { RecordableEventDescriptor descriptor = iterator.next(); if (!descriptor.isEnabled(wikiDescriptorManager.getCurrentWikiId())) { iterator.remove(); } } if (allWikis) { for (String wikiId : wikiDescriptorManager.getAllIds()) { recordableEventDescriptors.addAll(getDescriptorsFromWiki(wikiId)); } } return new ArrayList<>(recordableEventDescriptors); } catch (WikiManagerException | ComponentLookupException e) { throw new EventStreamException("Failed to get the list of all Recordable Event Descriptors.", e); } }  }
DefaultRecordableEventDescriptorManager implements RecordableEventDescriptorManager { @Override public List<RecordableEventDescriptor> getRecordableEventDescriptors(boolean allWikis) throws EventStreamException { try { Set<RecordableEventDescriptor> recordableEventDescriptors = new HashSet<>(); recordableEventDescriptors.addAll(contextComponentManager.getInstanceList(RecordableEventDescriptor.class)); recordableEventDescriptors.addAll(contextComponentManager.getInstanceList( UntypedRecordableEventDescriptor.class)); Iterator<RecordableEventDescriptor> iterator = recordableEventDescriptors.iterator(); while (iterator.hasNext()) { RecordableEventDescriptor descriptor = iterator.next(); if (!descriptor.isEnabled(wikiDescriptorManager.getCurrentWikiId())) { iterator.remove(); } } if (allWikis) { for (String wikiId : wikiDescriptorManager.getAllIds()) { recordableEventDescriptors.addAll(getDescriptorsFromWiki(wikiId)); } } return new ArrayList<>(recordableEventDescriptors); } catch (WikiManagerException | ComponentLookupException e) { throw new EventStreamException("Failed to get the list of all Recordable Event Descriptors.", e); } }  @Override List<RecordableEventDescriptor> getRecordableEventDescriptors(boolean allWikis); @Override RecordableEventDescriptor getDescriptorForEventType(String eventType, boolean allWikis); }
DefaultRecordableEventDescriptorManager implements RecordableEventDescriptorManager { @Override public List<RecordableEventDescriptor> getRecordableEventDescriptors(boolean allWikis) throws EventStreamException { try { Set<RecordableEventDescriptor> recordableEventDescriptors = new HashSet<>(); recordableEventDescriptors.addAll(contextComponentManager.getInstanceList(RecordableEventDescriptor.class)); recordableEventDescriptors.addAll(contextComponentManager.getInstanceList( UntypedRecordableEventDescriptor.class)); Iterator<RecordableEventDescriptor> iterator = recordableEventDescriptors.iterator(); while (iterator.hasNext()) { RecordableEventDescriptor descriptor = iterator.next(); if (!descriptor.isEnabled(wikiDescriptorManager.getCurrentWikiId())) { iterator.remove(); } } if (allWikis) { for (String wikiId : wikiDescriptorManager.getAllIds()) { recordableEventDescriptors.addAll(getDescriptorsFromWiki(wikiId)); } } return new ArrayList<>(recordableEventDescriptors); } catch (WikiManagerException | ComponentLookupException e) { throw new EventStreamException("Failed to get the list of all Recordable Event Descriptors.", e); } }  @Override List<RecordableEventDescriptor> getRecordableEventDescriptors(boolean allWikis); @Override RecordableEventDescriptor getDescriptorForEventType(String eventType, boolean allWikis);  }