Skip to content

Commit

Permalink
Worked on integration tests, DependencyFacetTest is half done
Browse files Browse the repository at this point in the history
(dependency resolution and Gradle build properties must be better
thought).
  • Loading branch information
adam-wyluda committed Jul 26, 2013
1 parent 467364f commit 53b0d09
Show file tree
Hide file tree
Showing 13 changed files with 691 additions and 132 deletions.
82 changes: 44 additions & 38 deletions tests/pom.xml
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>gradle-parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>gradle-tests</artifactId>
<name>Forge - Gradle Addon Tests</name>
<dependencies>
<dependency>
<groupId>org.jboss.forge.furnace</groupId>
<artifactId>container-cdi</artifactId>
<classifier>forge-addon</classifier>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>gradle</artifactId>
<classifier>forge-addon</classifier>
</dependency>
<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>projects</artifactId>
<classifier>forge-addon</classifier>
</dependency>
<dependency>
<groupId>org.jboss.forge.test</groupId>
<artifactId>forge-test-harness</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.forge.test</groupId>
<artifactId>arquillian-forge-classpath</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>gradle-parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>gradle-tests</artifactId>
<name>Forge - Gradle Addon Tests</name>
<dependencies>
<dependency>
<groupId>org.jboss.forge.furnace</groupId>
<artifactId>container-cdi</artifactId>
<classifier>forge-addon</classifier>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>gradle</artifactId>
<classifier>forge-addon</classifier>
</dependency>
<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>projects</artifactId>
<classifier>forge-addon</classifier>
</dependency>
<dependency>
<groupId>org.jboss.forge.test</groupId>
<artifactId>forge-test-harness</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.forge.test</groupId>
<artifactId>arquillian-forge-classpath</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>parser-java-api</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,34 @@
@Exported
public class GradleTestProjectProvider
{
static final String[] RESOURCES = new String[] {
"build.gradle",
"test-profile.gradle",
"settings.gradle",
"src/main/interfaces/org/testproject/Service.java",
"src/main/images/forge.txt",
"src/test/mocks/org/testproject/TestMainClass.java",
"src/test/templates/pom.xml"
};

public static ForgeArchive getDeployment()
{
return ShrinkWrap
.create(ForgeArchive.class)
ForgeArchive archive = ShrinkWrap.create(ForgeArchive.class)
.addBeansXML()
.addClass(GradleTestProjectProvider.class)
.addAsResource("build.gradle")
.addAsResource("test-profile.gradle")
.addAsResource("settings.gradle")
.addAsResource("src/main/images/forge.txt")
.addAsResource("src/test/templates/pom.xml")
.addAsAddonDependencies(
AddonDependencyEntry.create("org.jboss.forge.furnace:container-cdi", "2.0.0-SNAPSHOT"),
AddonDependencyEntry.create("org.jboss.forge.addon:resources", "2.0.0-SNAPSHOT"),
AddonDependencyEntry.create("org.jboss.forge.addon:gradle", "2.0.0-SNAPSHOT"),
AddonDependencyEntry.create("org.jboss.forge.addon:projects", "2.0.0-SNAPSHOT")
);
for (String resource : RESOURCES)
{
archive = archive.addAsResource(resource);
}
return archive;
}

@Inject
private Furnace furnace;
@Inject
Expand All @@ -59,25 +68,7 @@ public Project create()
DirectoryResource.class);
projectDir = addonDir.createTempResource();

FileResource<?> gradleFile = projectDir.getChild("build.gradle").reify(FileResource.class);
gradleFile.createNewFile();
gradleFile.setContents(getClass().getResourceAsStream("/build.gradle"));

FileResource<?> testProfileFile = projectDir.getChild("test-profile.gradle").reify(FileResource.class);
testProfileFile.createNewFile();
testProfileFile.setContents(getClass().getResourceAsStream("/test-profile.gradle"));

FileResource<?> settingsFile = projectDir.getChild("settings.gradle").reify(FileResource.class);
settingsFile.createNewFile();
settingsFile.setContents(getClass().getResourceAsStream("/settings.gradle"));

FileResource<?> forgeFile = projectDir.getChild("src/main/images/forge.txt").reify(FileResource.class);
forgeFile.createNewFile();
forgeFile.setContents(getClass().getResourceAsStream("/src/main/images/forge.txt"));

FileResource<?> pomFile = projectDir.getChild("src/test/templates/pom.xml").reify(FileResource.class);
pomFile.createNewFile();
pomFile.setContents(getClass().getResourceAsStream("/src/test/templates/pom.xml"));
initFiles(RESOURCES);

return findProject();
}
Expand All @@ -91,4 +82,14 @@ public void clean()
{
projectDir.delete(true);
}

private void initFiles(String... files)
{
for (String file : files)
{
FileResource<?> res = projectDir.getChild(file).reify(FileResource.class);
res.createNewFile();
res.setContents(getClass().getResourceAsStream("/" + file));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.jboss.forge.addon.gradle.projects;

import static org.junit.Assert.fail;

import java.util.List;

import org.jboss.forge.addon.dependencies.Dependency;
import org.jboss.forge.addon.dependencies.DependencyRepository;
import org.jboss.forge.addon.resource.DirectoryResource;

public class ProjectAssert
{
public static void assertContainsDirectoryNamed(List<DirectoryResource> dirs, String name)
{
for (DirectoryResource dir : dirs)
{
if (dir.getFullyQualifiedName().endsWith(name))
{
return;
}
}
fail("List of directories doesn't contain directory named " + name);
}

public static void assertDirectoryIsOneOf(DirectoryResource dir, String... names)
{
for (String name : names)
{
if (dir.getFullyQualifiedName().endsWith(name))
{
return;
}
}
fail(String.format("Directory [%s] is not one of %s", dir.getFullyQualifiedName(), names));
}

public static void assertContainsDependency(List<Dependency> deps, String scope, String artifact, String group,
String version)
{
for (Dependency dep : deps)
{
if (dep.getCoordinate().getArtifactId().equals(artifact) &&
dep.getCoordinate().getGroupId().equals(group) &&
dep.getCoordinate().getVersion().equals(version) &&
dep.getScopeType().equals(scope))
{
return;
}
}
fail(String.format("Deps doesn't contain dependency %s '%s:%s:%s'", scope, group, artifact, version));
}

public static void assertNotContainsDependency(List<Dependency> deps, String scope, String artifact, String group,
String version)
{
for (Dependency dep : deps)
{
if (dep.getCoordinate().getArtifactId().equals(artifact) &&
dep.getCoordinate().getGroupId().equals(group) &&
dep.getCoordinate().getVersion().equals(version) &&
dep.getScopeType().equals(scope))
{
fail(String.format("Deps contains dependency %s '%s:%s:%s'", scope, group, artifact, version));
}
}
}

public static void assertContainsRepository(List<DependencyRepository> repos, String url)
{
for (DependencyRepository repo : repos)
{
if (repo.getUrl().equals(url))
{
return;
}
}
fail(String.format("Repositories doesn't contain repository with url %s", url));
}

public static void assertNotContainsRepository(List<DependencyRepository> repos, String url)
{
for (DependencyRepository repo : repos)
{
if (repo.getUrl().equals(url))
{
fail(String.format("Repositories contains repository with url %s", url));
}
}
}
}

0 comments on commit 53b0d09

Please sign in to comment.