Search in sources :

Example 1 with ServiceLocator

use of org.eclipse.mylyn.wikitext.util.ServiceLocator in project mylyn.docs by eclipse.

the class ServiceLocatorIntegrationTest method expectedMarkupLanguagesPresent.

@Test
public void expectedMarkupLanguagesPresent() {
    ServiceLocator serviceLocator = OsgiServiceLocator.getApplicableInstance();
    assertNotNull(serviceLocator.getMarkupLanguage("HTML"));
    assertNotNull(serviceLocator.getMarkupLanguage("Textile"));
    assertNotNull(serviceLocator.getMarkupLanguage("MediaWiki"));
}
Also used : OsgiServiceLocator(org.eclipse.mylyn.wikitext.core.osgi.OsgiServiceLocator) ServiceLocator(org.eclipse.mylyn.wikitext.util.ServiceLocator) Test(org.junit.Test)

Example 2 with ServiceLocator

use of org.eclipse.mylyn.wikitext.util.ServiceLocator in project mylyn.docs by eclipse.

the class EclipseServiceLocatorTest method instance.

@Test
public void instance() {
    ServiceLocator instance = ServiceLocator.getInstance();
    assertTrue(instance.getClass().getName(), instance instanceof EclipseServiceLocator);
}
Also used : ServiceLocator(org.eclipse.mylyn.wikitext.util.ServiceLocator) Test(org.junit.Test)

Example 3 with ServiceLocator

use of org.eclipse.mylyn.wikitext.util.ServiceLocator in project mylyn.docs by eclipse.

the class ServiceLocatorTest method testLoadClassNotFound.

@Test
public void testLoadClassNotFound() throws MalformedURLException {
    final URL url = new URL("file://example");
    final AtomicBoolean wasThrown = new AtomicBoolean();
    locator = new ServiceLocator(ServiceLocatorTest.class.getClassLoader()) {

        @Override
        protected Class<?> loadClass(ResourceDescriptor resource, String className) throws ClassNotFoundException {
            wasThrown.set(true);
            throw new ClassNotFoundException(className);
        }

        @Override
        protected List<ResourceDescriptor> discoverServiceResources() {
            return Collections.singletonList(new ResourceDescriptor(url));
        }

        @Override
        protected List<String> readServiceClassNames(URL url) {
            return Collections.singletonList("test.TestLanguage");
        }

        @Override
        void logFailure(String className, Exception e) {
        }
    };
    Set<MarkupLanguage> languages = locator.getAllMarkupLanguages();
    assertTrue(wasThrown.get());
    assertNotNull(languages);
    assertTrue(languages.isEmpty());
}
Also used : ServiceLocator(org.eclipse.mylyn.wikitext.util.ServiceLocator) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) List(java.util.List) MockMarkupLanguage(org.eclipse.mylyn.internal.wikitext.MockMarkupLanguage) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) URL(java.net.URL) ExpectedException(org.junit.rules.ExpectedException) MalformedURLException(java.net.MalformedURLException) Test(org.junit.Test)

Example 4 with ServiceLocator

use of org.eclipse.mylyn.wikitext.util.ServiceLocator in project mylyn.docs by eclipse.

the class ServiceLocatorTest method getAllMarkupLanguagesFiltersDuplicates.

@Test
public void getAllMarkupLanguagesFiltersDuplicates() {
    final MarkupLanguage language1 = new TestMarkupLanguage("Language 1");
    final MarkupLanguage language1b = new MarkupLanguage() {

        {
            setName("Language 1");
        }

        @Override
        public void processContent(MarkupParser parser, String markupContent, boolean asDocument) {
            throw new IllegalStateException();
        }
    };
    final MarkupLanguage language2 = new TestMarkupLanguage("Language 3");
    final MarkupLanguage language2b = new TestMarkupLanguage("Language 3");
    ServiceLocator locator = new ServiceLocator(ServiceLocatorTest.class.getClassLoader()) {

        @Override
        void loadMarkupLanguages(MarkupLanguageVisitor visitor) {
            visitor.accept(language1);
            visitor.accept(language1b);
            visitor.accept(language2);
            visitor.accept(language2b);
        }
    };
    Set<MarkupLanguage> markupLanguages = locator.getAllMarkupLanguages();
    assertEquals(3, markupLanguages.size());
    assertTrue(markupLanguages.containsAll(ImmutableSet.of(language1, language1b)));
    assertTrue(markupLanguages.contains(language2) || markupLanguages.contains(language2b));
}
Also used : ServiceLocator(org.eclipse.mylyn.wikitext.util.ServiceLocator) MockMarkupLanguage(org.eclipse.mylyn.internal.wikitext.MockMarkupLanguage) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser) Test(org.junit.Test)

Example 5 with ServiceLocator

use of org.eclipse.mylyn.wikitext.util.ServiceLocator in project mylyn.docs by eclipse.

the class OsgiServiceLocatorTest method installAsDefaultImplementationWithClassLoader.

@Test
public void installAsDefaultImplementationWithClassLoader() {
    ServiceLocator.setImplementation(OsgiServiceLocator.class);
    ServiceLocator instance = ServiceLocator.getInstance(OsgiServiceLocatorTest.class.getClassLoader());
    assertNotNull(instance);
    assertEquals(OsgiServiceLocator.class, instance.getClass());
}
Also used : ServiceLocator(org.eclipse.mylyn.wikitext.util.ServiceLocator) Test(org.junit.Test)

Aggregations

ServiceLocator (org.eclipse.mylyn.wikitext.util.ServiceLocator)9 Test (org.junit.Test)6 MarkupLanguage (org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage)4 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 List (java.util.List)3 MockMarkupLanguage (org.eclipse.mylyn.internal.wikitext.MockMarkupLanguage)3 ExpectedException (org.junit.rules.ExpectedException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 MockMarkupLanguageProvider (org.eclipse.mylyn.internal.wikitext.MockMarkupLanguageProvider)1 OsgiServiceLocator (org.eclipse.mylyn.wikitext.core.osgi.OsgiServiceLocator)1 Visitor (org.eclipse.mylyn.wikitext.maven.internal.SourceFileTraversal.Visitor)1 MarkupParser (org.eclipse.mylyn.wikitext.parser.MarkupParser)1 MarkupLanguageProvider (org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguageProvider)1