Search in sources :

Example 6 with NonManagedPluginRegistry

use of org.datanucleus.plugin.NonManagedPluginRegistry in project datanucleus-core by datanucleus.

the class PluginParserTest method testRequireBundleLogged.

public void testRequireBundleLogged() {
    final java.util.Set messages = new HashSet();
    Logger.getLogger("DataNucleus.General").addAppender(new Appender() {

        public void setName(String arg0) {
        }

        public void setLayout(Layout arg0) {
        }

        public void setErrorHandler(ErrorHandler arg0) {
        }

        public boolean requiresLayout() {
            return false;
        }

        public String getName() {
            return "testappender123";
        }

        public Layout getLayout() {
            return null;
        }

        public Filter getFilter() {
            return null;
        }

        public ErrorHandler getErrorHandler() {
            return null;
        }

        public void doAppend(LoggingEvent arg0) {
            if (arg0.getRenderedMessage().indexOf("but it cannot be resolved") > 0) {
                messages.add(arg0.getRenderedMessage());
            }
        }

        public void close() {
        }

        public void clearFilters() {
        }

        public void addFilter(Filter arg0) {
        }
    });
    ClassLoaderResolver clr = new ClassLoaderResolverImpl();
    NonManagedPluginRegistry mgr = new NonManagedPluginRegistry(clr, "EXCEPTION", true);
    assertEquals(0, mgr.getExtensionPoints().length);
    mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST3.MF", null));
    mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST4.MF", null));
    mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST5.MF", null));
    mgr.resolveConstraints();
    try {
        assertEquals(2, messages.size());
        assertTrue(messages.contains("Bundle \"org.datanucleus.plugin.test5\" requires \"org.datanucleus.plugin.test6\" but it cannot be resolved."));
        assertTrue(messages.contains("Bundle \"org.datanucleus.plugin.test5\" has an optional dependency to \"org.datanucleus.plugin.test7\" but it cannot be resolved"));
    } finally {
        Logger.getLogger("DataNucleus.General").removeAppender("testappender123");
    }
}
Also used : Appender(org.apache.log4j.Appender) LoggingEvent(org.apache.log4j.spi.LoggingEvent) ErrorHandler(org.apache.log4j.spi.ErrorHandler) Layout(org.apache.log4j.Layout) Filter(org.apache.log4j.spi.Filter) NonManagedPluginRegistry(org.datanucleus.plugin.NonManagedPluginRegistry) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) HashSet(java.util.HashSet) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Aggregations

ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)6 ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)6 NonManagedPluginRegistry (org.datanucleus.plugin.NonManagedPluginRegistry)6 Bundle (org.datanucleus.plugin.Bundle)3 HashSet (java.util.HashSet)2 Appender (org.apache.log4j.Appender)2 Layout (org.apache.log4j.Layout)2 ErrorHandler (org.apache.log4j.spi.ErrorHandler)2 Filter (org.apache.log4j.spi.Filter)2 LoggingEvent (org.apache.log4j.spi.LoggingEvent)2 Extension (org.datanucleus.plugin.Extension)2 NucleusException (org.datanucleus.exceptions.NucleusException)1 ConfigurationElement (org.datanucleus.plugin.ConfigurationElement)1 ExtensionPoint (org.datanucleus.plugin.ExtensionPoint)1