public Category getCategory(String filterType) { if (filterType == null) { return undefinedCategory; } else { return this.getCategories() .stream() .filter(category -> category.getName().equals(filterType.toUpperCase())) .findFirst() .orElse(undefinedCategory); } } }
public void addAllFromResourceTypes(List<ClientResourceType> clientResourceType) { this.addAll(this.getCategories(clientResourceType)); }
/** * Create a list of SelectOptions with all the categories and the ALL Option, to be used * in {@link SelectComponent} * @return the list of SelectOptions */ public List<SelectOption> createCategories() { List<SelectOption> options = new ArrayList<>(); options.add(new SelectOptionImpl("ALL", ts.getTranslation(LibraryConstants.ALL))); options.addAll(categoriesManagerCache.getCategories().stream() .map(category -> new SelectOptionImpl(category.getName(), ts.getTranslation(category.getName()))) .collect(Collectors.toList())); return options; } }
@Test public void testAvailableCategories() { Category process = mock(Category.class); Category model = mock(Category.class); when(process.getName()).thenReturn("PROCESS"); when(model.getName()).thenReturn("MODEL"); ClientResourceType clientResourceType = mock(ClientResourceType.class); when(clientResourceType.getCategory()).thenReturn(model); SyncBeanDef<ClientResourceType> syncBeanDef = mock(SyncBeanDef.class); when(syncBeanDef.getInstance()).thenReturn(clientResourceType); Collection<SyncBeanDef> resourceTypeBeans = Arrays.asList(syncBeanDef); when(iocManager.lookupBeans(eq("java"))).thenReturn(resourceTypeBeans); SyncBeanDef mock = mock(SyncBeanDef.class); when(mock.getName()).thenReturn("java"); activityBeansCache.addNewEditorActivity(mock, "1", "java"); Set<Category> categories = this.categoriesManagerCache.getCategories(); assertTrue(categories.stream().anyMatch(category -> category.equals(model))); assertTrue(categories.stream().noneMatch(category -> category.equals(process))); } }
@Test public void testAvailableCategories() { Category process = mock(Category.class); Category model = mock(Category.class); when(process.getName()).thenReturn("PROCESS"); when(model.getName()).thenReturn("MODEL"); ClientResourceType clientResourceType = mock(ClientResourceType.class); when(clientResourceType.getCategory()).thenReturn(model); SyncBeanDef<ClientResourceType> syncBeanDef = mock(SyncBeanDef.class); when(syncBeanDef.getInstance()).thenReturn(clientResourceType); Collection<SyncBeanDef> resourceTypeBeans = Arrays.asList(syncBeanDef); when(iocManager.lookupBeans(eq("java"))).thenReturn(resourceTypeBeans); SyncBeanDef mock = mock(SyncBeanDef.class); when(mock.getName()).thenReturn("java"); activityBeansCache.addNewEditorActivity(mock, "1", "java"); Set<Category> categories = this.categoriesManagerCache.getCategories(); assertTrue(categories.stream().anyMatch(category -> category.equals(model))); assertTrue(categories.stream().noneMatch(category -> category.equals(process))); } }
@Test public void testCreateCategories() { when(this.categoriesManagerCache.getCategories()).thenReturn(new HashSet<>(Arrays.asList(new Others(), new Decision()))); List<SelectOption> categories = this.categoryUtils.createCategories(); assertEquals(3, categories.size()); assertTrue(categories.stream().anyMatch(selectOption -> selectOption.getSelector().equals("ALL"))); assertTrue(categories.stream().anyMatch(selectOption -> selectOption.getSelector().equals(new Others().getName()))); assertTrue(categories.stream().anyMatch(selectOption -> selectOption.getSelector().equals(new Decision().getName()))); } }