Skip to content

Commit

Permalink
Completed FORGE-1111 - Implement a test to verify error scenario when…
Browse files Browse the repository at this point in the history
… multiple AddonLifecycleProviders registered
  • Loading branch information
lincolnthree committed Sep 17, 2013
1 parent 39339db commit 4c90f09
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package test.org.jboss.forge.furnace.lifecycle;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.ShouldThrowException;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.forge.arquillian.archive.ForgeArchive;
import org.jboss.forge.furnace.lifecycle.AddonLifecycleProvider;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
@RunWith(Arquillian.class)
public class DuplicateAddonLifecycleProviderTest
{
@Deployment
@ShouldThrowException
public static ForgeArchive getDeployment()
{
ForgeArchive archive = ShrinkWrap.create(ForgeArchive.class)
.addClass(MockAddonLifecycleProvider.class)
.addClass(MockAddonLifecycleProvider2.class)
.addAsServiceProvider(AddonLifecycleProvider.class, MockAddonLifecycleProvider.class,
MockAddonLifecycleProvider2.class);

return archive;
}

@Test
public void shouldNotRun() throws Exception
{
Assert.fail("Deployment should have failed.");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package test.org.jboss.forge.furnace.lifecycle;

import org.jboss.forge.furnace.Furnace;
import org.jboss.forge.furnace.addons.Addon;
import org.jboss.forge.furnace.addons.AddonRegistry;
import org.jboss.forge.furnace.event.EventManager;
import org.jboss.forge.furnace.lifecycle.AddonLifecycleProvider;
import org.jboss.forge.furnace.lifecycle.ControlType;
import org.jboss.forge.furnace.spi.ServiceRegistry;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
*/
public class MockAddonLifecycleProvider implements AddonLifecycleProvider
{

@Override
public void initialize(Furnace furnace, AddonRegistry registry, Addon self) throws Exception
{

}

@Override
public void start(Addon addon) throws Exception
{
}

@Override
public void stop(Addon addon) throws Exception
{
}

@Override
public ServiceRegistry getServiceRegistry(Addon addon) throws Exception
{
return null;
}

@Override
public EventManager getEventManager(Addon addon)
{
return null;
}

@Override
public void postStartup(Addon addon) throws Exception
{

}

@Override
public void preShutdown(Addon addon) throws Exception
{
}

@Override
public ControlType getControlType()
{
return ControlType.ALL;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package test.org.jboss.forge.furnace.lifecycle;

import org.jboss.forge.furnace.Furnace;
import org.jboss.forge.furnace.addons.Addon;
import org.jboss.forge.furnace.addons.AddonRegistry;
import org.jboss.forge.furnace.event.EventManager;
import org.jboss.forge.furnace.lifecycle.AddonLifecycleProvider;
import org.jboss.forge.furnace.lifecycle.ControlType;
import org.jboss.forge.furnace.spi.ServiceRegistry;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
*/
public class MockAddonLifecycleProvider2 implements AddonLifecycleProvider
{

@Override
public void initialize(Furnace furnace, AddonRegistry registry, Addon self) throws Exception
{

}

@Override
public void start(Addon addon) throws Exception
{
}

@Override
public void stop(Addon addon) throws Exception
{
}

@Override
public ServiceRegistry getServiceRegistry(Addon addon) throws Exception
{
return null;
}

@Override
public EventManager getEventManager(Addon addon)
{
return null;
}

@Override
public void postStartup(Addon addon) throws Exception
{

}

@Override
public void preShutdown(Addon addon) throws Exception
{
}

@Override
public ControlType getControlType()
{
return ControlType.ALL;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public AddonLifecycleProviderEntry call() throws Exception
AddonLifecycleProvider.class, classLoader);

Iterator<AddonLifecycleProvider> iterator = serviceLoader.iterator();
if (serviceLoader != null && iterator.hasNext())
while (serviceLoader != null && iterator.hasNext())
{
AddonLifecycleProvider provider = iterator.next();

Expand Down Expand Up @@ -215,10 +215,14 @@ public AddonLifecycleProviderEntry call() throws Exception
}
});
}
catch (Throwable e)
catch (RuntimeException e)
{
throw e;
}
catch (Exception e)
{
// FIXME Figure out why ServiceLoader is trying to load things from the wrong ClassLoader
logger.log(Level.FINEST, "ServiceLoader misbehaved when loading AddonLifecycleProvider instances.", e);
throw new ContainerException("Error occurred while attempting to local instance of ["
+ AddonLifecycleProvider.class.getName() + "] for addon [" + addon + "].");
}

return result;
Expand Down

0 comments on commit 4c90f09

Please sign in to comment.