PluginFQNParser { public Collection<PluginFQN> parsePlugins(Map<String, String> attributes) throws InfrastructureException { if (attributes == null) { return emptyList(); } String pluginsAttribute = attributes.getOrDefault(Constants.WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE, null); String editorAttribute = attributes.getOrDefault(Constants.WORKSPACE_TOOLING_EDITOR_ATTRIBUTE, null); List<PluginFQN> metaFQNs = new ArrayList<>(); if (!isNullOrEmpty(pluginsAttribute)) { metaFQNs.addAll(parsePluginFQNs(pluginsAttribute)); } if (!isNullOrEmpty(editorAttribute)) { Collection<PluginFQN> editorsFQNs = parsePluginFQNs(editorAttribute); if (editorsFQNs.size() > 1) { throw new InfrastructureException( "Multiple editors found in workspace config attributes. " + "Only one editor is supported per workspace."); } metaFQNs.addAll(editorsFQNs); } return metaFQNs; }  Collection<PluginFQN> parsePlugins(Map<String, String> attributes); ExtendedPluginFQN parsePluginFQN(String plugin); ExtendedPluginFQN evaluateFqn(String reference, FileContentProvider fileContentProvider);  }
@Test public void shouldReturnEmptyListWhenNoPluginsOrEditors() throws Exception { Map<String, String> attributes = ImmutableMap.of("testProperty", "testValue"); Collection<PluginFQN> result = parser.parsePlugins(attributes); assertTrue( result.isEmpty(), "PluginFQNParser should return empty list when attributes does not contain plugins or editors"); }
@Test(dataProvider = "validAttributesProvider") public void shouldParseAllPluginsAndEditor(AttributeParsingTestCase testCase) throws Exception { Collection<PluginFQN> actual = parser.parsePlugins(testCase.attributes); assertEqualsNoOrder(actual.toArray(), testCase.expectedPlugins.toArray()); }
@Test( dataProvider = "invalidAttributeStringProvider", expectedExceptions = InfrastructureException.class) public void shouldThrowExceptionWhenPluginStringIsInvalid(String plugin) throws Exception { Map<String, String> attributes = createAttributes("", plugin); parser.parsePlugins(attributes); }
@Test( dataProvider = "invalidAttributeStringProvider", expectedExceptions = InfrastructureException.class) public void shouldThrowExceptionWhenEditorStringIsInvalid(String editor) throws Exception { Map<String, String> attributes = createAttributes(editor, ""); parser.parsePlugins(attributes); }
@Test( expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = "Multiple editors.*") public void shouldThrowExceptionWhenMultipleEditorsDefined() throws Exception { Map<String, String> attributes = createAttributes("publisher1/editor1/version1,publisher1/editor2/version1", ""); parser.parsePlugins(attributes); }
@Test( expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = "Invalid Che tooling plugins configuration: plugin publisher1/testplugin/1.0 is duplicated") public void shouldThrowExceptionWhenDuplicatePluginDefined() throws Exception { Map<String, String> attributes = createAttributes( "", formatPlugin("http: formatPlugin("http: parser.parsePlugins(attributes); }
@Test( expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = "Invalid Che tooling plugins configuration: plugin publisher1/testplugin/1.0 is duplicated") public void shouldDetectDuplicatedPluginsIfTheyArePrefixedOrSuffixedWithEmptySpaces() throws Exception { Map<String, String> attributes = createAttributes( "", " " + formatPlugin("http: formatPlugin("http: parser.parsePlugins(attributes); }