Search in sources :

Example 1 with SortByIdFilter

use of org.xwiki.uiextension.internal.filter.SortByIdFilter in project xwiki-platform by xwiki.

the class UIExtensionScriptServiceTest method verifyExtensionsAreSortedAlphabeticallyById.

@Test
public void verifyExtensionsAreSortedAlphabeticallyById() throws Exception {
    // The UIX are voluntarily added in a wrong order.
    UIExtension uix3 = mock(UIExtension.class, "uix3");
    when(uix3.getId()).thenReturn("id3");
    when(uix3.getExtensionPointId()).thenReturn("epId");
    epExtensions.add(uix3);
    UIExtension uix1 = mock(UIExtension.class, "uix1");
    when(uix1.getId()).thenReturn("id1");
    when(uix1.getExtensionPointId()).thenReturn("epId");
    epExtensions.add(uix1);
    UIExtension uix2 = mock(UIExtension.class, "uix2");
    when(uix2.getId()).thenReturn("id2");
    when(uix2.getExtensionPointId()).thenReturn("epId");
    epExtensions.add(uix2);
    when(contextComponentManager.getInstance(UIExtensionManager.class, "epId")).thenThrow(new ComponentLookupException("No specific manager for extension point epId"));
    when(uiExtensionManager.get("epId")).thenReturn(epExtensions);
    when(contextComponentManager.getInstance(UIExtensionFilter.class, "sortById")).thenReturn(new SortByIdFilter());
    HashMap<String, String> filters = new HashMap<String, String>();
    filters.put("sortById", "");
    UIExtensionScriptService service = (UIExtensionScriptService) componentManager.getComponentUnderTest();
    List<UIExtension> extensions = service.getExtensions("epId", filters);
    Assert.assertEquals("id1", extensions.get(0).getId());
    Assert.assertEquals("id2", extensions.get(1).getId());
    Assert.assertEquals("id3", extensions.get(2).getId());
}
Also used : UIExtension(org.xwiki.uiextension.UIExtension) HashMap(java.util.HashMap) SortByIdFilter(org.xwiki.uiextension.internal.filter.SortByIdFilter) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 Test (org.junit.Test)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 UIExtension (org.xwiki.uiextension.UIExtension)1 SortByIdFilter (org.xwiki.uiextension.internal.filter.SortByIdFilter)1