-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FORGE-1565: Added tests. ServiceRegistryImpl.loadClass returns the wr…
…ong class though
- Loading branch information
Showing
4 changed files
with
196 additions
and
2 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
tests/src/main/java/test/org/jboss/forge/furnace/mocks/Aa.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package test.org.jboss.forge.furnace.mocks; | ||
/** | ||
* Copyright 2014 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 | ||
*/ | ||
|
||
|
||
/** | ||
* Keep the class name. The Hashcode should be the same as BB | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
public class Aa | ||
{ | ||
public static void main(String[] args) throws Exception | ||
{ | ||
System.out.println("test.Aa".hashCode()); | ||
System.out.println("test.BB".hashCode()); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/src/main/java/test/org/jboss/forge/furnace/mocks/BB.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package test.org.jboss.forge.furnace.mocks; | ||
/** | ||
* Copyright 2014 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 | ||
*/ | ||
|
||
/** | ||
* Keep the class name. The Hashcode should be the same as Aa | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
public class BB | ||
{ | ||
} |
126 changes: 126 additions & 0 deletions
126
tests/src/test/java/test/org/jboss/forge/furnace/addons/AddonRegistryMultipleAddonsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/** | ||
* 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.addons; | ||
|
||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
import static org.hamcrest.CoreMatchers.is; | ||
|
||
import java.util.Iterator; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.forge.arquillian.AddonDependency; | ||
import org.jboss.forge.arquillian.Dependencies; | ||
import org.jboss.forge.arquillian.archive.ForgeArchive; | ||
import org.jboss.forge.furnace.addons.Addon; | ||
import org.jboss.forge.furnace.addons.AddonId; | ||
import org.jboss.forge.furnace.addons.AddonRegistry; | ||
import org.jboss.forge.furnace.repositories.AddonDependencyEntry; | ||
import org.jboss.forge.furnace.services.Imported; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import test.org.jboss.forge.furnace.mocks.Aa; | ||
import test.org.jboss.forge.furnace.mocks.BB; | ||
|
||
/** | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
@RunWith(Arquillian.class) | ||
public class AddonRegistryMultipleAddonsTest | ||
{ | ||
|
||
@Deployment | ||
@Dependencies({ | ||
@AddonDependency(name = "org.jboss.forge.furnace.container:cdi") | ||
}) | ||
public static ForgeArchive getDeployment() | ||
{ | ||
ForgeArchive archive = ShrinkWrap.create(ForgeArchive.class) | ||
.addBeansXML() | ||
.addAsAddonDependencies( | ||
AddonDependencyEntry.create("org.jboss.forge.furnace.container:cdi"), | ||
AddonDependencyEntry.create("test:dep2"), | ||
AddonDependencyEntry.create("test:dep1") | ||
|
||
); | ||
|
||
return archive; | ||
} | ||
|
||
@Deployment(name = "test:dep2,2", testable = false, order = 2) | ||
public static ForgeArchive getDeploymentDep2() | ||
{ | ||
ForgeArchive archive = ShrinkWrap.create(ForgeArchive.class) | ||
.addClass(BB.class) | ||
.addBeansXML() | ||
.addAsAddonDependencies( | ||
AddonDependencyEntry.create("org.jboss.forge.furnace.container:cdi") | ||
); | ||
return archive; | ||
} | ||
|
||
@Deployment(name = "test:dep1,1", testable = false, order = 1) | ||
public static ForgeArchive getDeploymentDep1() | ||
{ | ||
ForgeArchive archive = ShrinkWrap | ||
.create(ForgeArchive.class) | ||
.addClass(Aa.class) | ||
.addBeansXML() | ||
.addAsAddonDependencies( | ||
AddonDependencyEntry.create("org.jboss.forge.furnace.container:cdi") | ||
); | ||
|
||
return archive; | ||
} | ||
|
||
@Inject | ||
private AddonRegistry addonRegistry; | ||
|
||
@Test | ||
public void testServiceContainedWithExpectedObjectsDifferentClassLoaders() throws Exception | ||
{ | ||
AddonId depOneId = AddonId.from("test:dep1", "1"); | ||
AddonId depTwoId = AddonId.from("test:dep2", "2"); | ||
|
||
Addon depOne = addonRegistry.getAddon(depOneId); | ||
Addon depTwo = addonRegistry.getAddon(depTwoId); | ||
|
||
Assert.assertTrue(depOne.getServiceRegistry().hasService(Aa.class)); | ||
Assert.assertFalse(depOne.getServiceRegistry().hasService(BB.class)); | ||
|
||
Assert.assertFalse(depTwo.getServiceRegistry().hasService(Aa.class)); | ||
Assert.assertTrue(depTwo.getServiceRegistry().hasService(BB.class)); | ||
} | ||
|
||
@Test | ||
public void testImportedWithExpectedObjectsDifferentClassLoaders() throws Exception | ||
{ | ||
Imported<Aa> services = addonRegistry.getServices(Aa.class); | ||
Assert.assertFalse("Imported<Aa> should have been satisfied", services.isUnsatisfied()); | ||
Assert.assertFalse("Imported<Aa> should not have been ambiguous", services.isAmbiguous()); | ||
Iterator<Aa> iterator = services.iterator(); | ||
Assert.assertTrue(iterator.hasNext()); | ||
Assert.assertThat(iterator.next(), is(instanceOf(Aa.class))); | ||
Assert.assertFalse(iterator.hasNext()); | ||
|
||
Imported<BB> services2 = addonRegistry.getServices(BB.class); | ||
Assert.assertFalse("Imported<BB> should have been satisfied", services.isUnsatisfied()); | ||
Assert.assertFalse("Imported<BB> should not have been ambiguous", services.isAmbiguous()); | ||
Iterator<BB> iterator2 = services2.iterator(); | ||
Assert.assertTrue(iterator2.hasNext()); | ||
Assert.assertThat(iterator2.next(), is(instanceOf(BB.class))); | ||
Assert.assertFalse(iterator2.hasNext()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters