QuickLinksProfileBuilder { public String buildQuickLinksProfile(@Nullable Object globalFiltersRaw, @Nullable Object serviceFiltersRaw) throws QuickLinksProfileEvaluationException { try { List<Filter> globalFilters = buildQuickLinkFilters(globalFiltersRaw); List<Service> services = buildServices(serviceFiltersRaw); QuickLinksProfile profile = QuickLinksProfile.create(globalFilters, services); new DefaultQuickLinkVisibilityController(profile); return new QuickLinksProfileParser().encode(profile); } catch (QuickLinksProfileEvaluationException ex) { throw ex; } catch (Exception ex) { throw new QuickLinksProfileEvaluationException("Error interpreting quicklinks profile data", ex); } }  String buildQuickLinksProfile(@Nullable Object globalFiltersRaw, @Nullable Object serviceFiltersRaw); static final String NAME; static final String COMPONENTS; static final String FILTERS; static final Set<String> ALLOWED_FILTER_ATTRIBUTES; }
@Test public void testBuildProfileOnlyGlobalFilters() throws Exception { Set<Map<String, String>> filters = newHashSet( filter("namenode_ui", null, true), filter(null, "sso", true), filter(null, null, false) ); String profileJson = new QuickLinksProfileBuilder().buildQuickLinksProfile(filters, null); QuickLinksProfile profile = new QuickLinksProfileParser().parse(profileJson.getBytes()); assertFilterExists(profile, null, null, Filter.linkNameFilter("namenode_ui", true)); assertFilterExists(profile, null, null, Filter.linkAttributeFilter("sso", true)); assertFilterExists(profile, null, null, Filter.acceptAllFilter(false)); }
@Test public void testBuildProfileOnlyServiceFilters() throws Exception { Map<String, Object> nameNode = component("NAMENODE", newHashSet(filter("namenode_ui", null, false))); Map<String, Object> hdfs = service("HDFS", newHashSet(nameNode), newHashSet(filter(null, "sso", true))); Set<Map<String, Object>> services = Sets.newHashSet(hdfs); String profileJson = new QuickLinksProfileBuilder().buildQuickLinksProfile(null, services); QuickLinksProfile profile = new QuickLinksProfileParser().parse(profileJson.getBytes()); assertFilterExists(profile, "HDFS", "NAMENODE", Filter.linkNameFilter("namenode_ui", false)); assertFilterExists(profile, "HDFS", null, Filter.linkAttributeFilter("sso", true)); }
@Test public void testBuildProfileBothGlobalAndServiceFilters() throws Exception { Set<Map<String, String>> globalFilters = newHashSet( filter(null, null, false) ); Map<String, Object> nameNode = component("NAMENODE", newHashSet(filter("namenode_ui", null, false))); Map<String, Object> hdfs = service("HDFS", newHashSet(nameNode), newHashSet(filter(null, "sso", true))); Set<Map<String, Object>> services = Sets.newHashSet(hdfs); String profileJson = new QuickLinksProfileBuilder().buildQuickLinksProfile(globalFilters, services); QuickLinksProfile profile = new QuickLinksProfileParser().parse(profileJson.getBytes()); assertFilterExists(profile, null, null, Filter.acceptAllFilter(false)); assertFilterExists(profile, "HDFS", "NAMENODE", Filter.linkNameFilter("namenode_ui", false)); assertFilterExists(profile, "HDFS", null, Filter.linkAttributeFilter("sso", true)); }
@Test(expected = QuickLinksProfileEvaluationException.class) public void testBuildProfileBadInputStructure() throws Exception { new QuickLinksProfileBuilder().buildQuickLinksProfile("Hello", "World"); }
@Test(expected = QuickLinksProfileEvaluationException.class) public void testBuildProfileMissingDataServiceName() throws Exception { Map<String, Object> nameNode = component("NAMENODE", newHashSet(filter("namenode_ui", null, false))); Map<String, Object> hdfs = service(null, newHashSet(nameNode), newHashSet(filter(null, "sso", true))); Set<Map<String, Object>> services = Sets.newHashSet(hdfs); new QuickLinksProfileBuilder().buildQuickLinksProfile(null, services); }
@Test(expected = QuickLinksProfileEvaluationException.class) public void testBuildProfileMissingDataComponentName() throws Exception { Map<String, Object> nameNode = component(null, newHashSet(filter("namenode_ui", null, false))); Map<String, Object> hdfs = service("HDFS", newHashSet(nameNode), newHashSet(filter(null, "sso", true))); Set<Map<String, Object>> services = Sets.newHashSet(hdfs); new QuickLinksProfileBuilder().buildQuickLinksProfile(null, services); }
@Test(expected = QuickLinksProfileEvaluationException.class) public void testBuildProfileInvalidProfileDefiniton_contradictingFilters() throws Exception { Set<Map<String, String>> filters = newHashSet( filter(null, "sso", true), filter(null, "sso", false) ); new QuickLinksProfileBuilder().buildQuickLinksProfile(filters, null); }
@Test(expected = QuickLinksProfileEvaluationException.class) public void testBuildProfileInvalidProfileDefiniton_invalidAttribute() throws Exception { Map<String, String> badFilter = ImmutableMap.of("visible", "true", "linkkk_atirbuteee", "sso"); Set<Map<String, String>> filters = newHashSet(badFilter); new QuickLinksProfileBuilder().buildQuickLinksProfile(filters, null); }