@Test
public void testResolvePackages() throws Exception {
final Bean projectServiceBean = (Bean) beanManager.getBeans( ProjectService.class ).iterator().next();
final CreationalContext cc = beanManager.createCreationalContext( projectServiceBean );
final ProjectService projectService = (ProjectService) beanManager.getReference( projectServiceBean,
ProjectService.class,
cc );
final URL root = this.getClass().getResource( "/ProjectBackendTestProject1" );
final URL pom = this.getClass().getResource( "/ProjectBackendTestProject1/pom.xml" );
final URL kmodule = this.getClass().getResource( "/ProjectBackendTestProject1/src/main/resources/META-INF/kmodule.xml" );
final URL imports = this.getClass().getResource( "/ProjectBackendTestProject1/project.imports" );
final Project project = new Project( paths.convert( fs.getPath( root.toURI() ) ),
paths.convert( fs.getPath( pom.toURI() ) ),
paths.convert( fs.getPath( kmodule.toURI() ) ),
paths.convert( fs.getPath( imports.toURI() ) ),
"ProjectBackendTestProject1" );
{
Set<Package> packages = projectService.resolvePackages( (Package) null );
assertEquals( 0, packages.size() );
}
Package defaultPkg = null;
{
Set<Package> packages = projectService.resolvePackages( project );
assertEquals( 6, packages.size() );
for ( final Package pkg : packages ) {
if ( pkg.getCaption().equals( "<default>" ) ) {
defaultPkg = pkg;
break;
}
}
assertEquals( defaultPkg, projectService.resolveDefaultPackage( project ) );
}
assertNotNull( defaultPkg );
assertEquals( "<default>", defaultPkg.getCaption() );
assertEquals( "<default>", defaultPkg.getRelativeCaption() );
Package rootPkg = null;
{
Set<Package> packages = projectService.resolvePackages( defaultPkg );
assertEquals( 1, packages.size() );
rootPkg = packages.iterator().next();
}
assertNotNull( rootPkg );
assertEquals( "org", rootPkg.getCaption() );
assertEquals( "org", rootPkg.getRelativeCaption() );
Package kiePkg = null;
{
Set<Package> packages = projectService.resolvePackages( rootPkg );
assertEquals( 1, packages.size() );
kiePkg = packages.iterator().next();
}
assertNotNull( kiePkg );
assertEquals( "org.kie", kiePkg.getCaption() );
assertEquals( "kie", kiePkg.getRelativeCaption() );
assertEquals( rootPkg, projectService.resolveParentPackage( kiePkg ) );
assertEquals( defaultPkg, projectService.resolveParentPackage( rootPkg ) );
assertNull( projectService.resolveParentPackage( defaultPkg ) );
{
Set<Package> packages = projectService.resolvePackages( kiePkg );
assertEquals( 1, packages.size() );
}
}