1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codehaus.mojo.nbm;
17
18 import java.io.File;
19 import java.util.ArrayList;
20 import java.util.Arrays;
21 import java.util.Collections;
22 import java.util.HashMap;
23 import java.util.HashSet;
24 import java.util.Map;
25 import java.util.Set;
26 import org.apache.maven.plugin.MojoExecutionException;
27 import org.apache.maven.plugin.logging.Log;
28 import org.codehaus.mojo.nbm.CreateClusterAppMojo.BundleTuple;
29 import org.codehaus.mojo.nbm.utils.ExamineManifest;
30 import static org.junit.Assert.*;
31 import org.junit.Test;
32
33
34
35
36
37 public class CreateClusterAppMojoTest
38 {
39
40 public CreateClusterAppMojoTest()
41 {
42 }
43
44 @Test
45 public void computeClusterOrderingTest() throws Exception {
46 HashMap<String, Set<String>> clusterDeps = new HashMap<String, Set<String>>();
47 HashMap<String, Set<String>> clusterModules = new HashMap<String, Set<String>>();
48 clusterModules.put( "platform", new HashSet<String>(Arrays.asList( new String[] {"pl-a", "pl-b", "pl-c"})));
49 clusterModules.put( "ide", new HashSet<String>(Arrays.asList( new String[] {"i-a", "i-b", "i-c"})));
50 clusterModules.put( "java", new HashSet<String>(Arrays.asList( new String[] {"j-a", "j-b", "j-c"})));
51
52 clusterDeps.put( "java", new HashSet<String>(Arrays.asList( new String[] {"i-a", "pl-b", "pl-c"})));
53 clusterDeps.put( "ide", new HashSet<String>(Arrays.asList( new String[] {"pl-b", "pl-c"})));
54 Map<String, Set<String>> res = CreateClusterAppMojo.computeClusterOrdering( clusterDeps, clusterModules);
55 assertNotNull( res );
56 Set<String> resJava = res.get( "java");
57 assertNotNull( resJava );
58 assertEquals( resJava.size(), 2);
59 assertTrue( resJava.contains( "ide"));
60 assertTrue( resJava.contains( "platform"));
61
62 Set<String> resIde = res.get( "ide");
63 assertNotNull( resIde );
64 assertEquals( resIde.size(), 1);
65 assertTrue( resIde.contains( "platform"));
66
67 }
68
69 @Test
70 public void assignClustersToBundles() throws Exception {
71 ArrayList<BundleTuple> bundles = new ArrayList<BundleTuple>();
72 BundleTuple tup1 = createBundleTuple("a.b.c", new File(getClass().getResource( "/osgimanifests" + File.separator + "a.b.c.MF").toURI()));
73 bundles.add( tup1 );
74 BundleTuple tup2 = createBundleTuple("b.c.d", new File(getClass().getResource( "/osgimanifests" + File.separator + "b.c.d.MF").toURI()));
75 assertTrue(Arrays.toString( tup2.manifest.getOsgiImports().toArray()), tup2.manifest.getOsgiImports().contains( "a.b.c"));
76 bundles.add( tup2 );
77 HashMap<String, Set<String>> clusterDeps = new HashMap<String, Set<String>>();
78 clusterDeps.put( "java", new HashSet<String>(Arrays.asList( new String[] {"i-a", "pl-b", "pl-c"})));
79 clusterDeps.put( "ide", new HashSet<String>(Arrays.asList( new String[] {"pl-b", "pl-c", "a.b.c"})));
80
81 CreateClusterAppMojo.assignClustersToBundles(bundles, Collections.<String>emptySet(), clusterDeps, Collections.<String, Set<String>>emptyMap(), null);
82 assertEquals( "ide", tup1.cluster);
83 assertEquals( "ide", tup2.cluster);
84
85 clusterDeps.clear();
86 clusterDeps.put( "ide", new HashSet<String>(Arrays.asList( new String[] {"i-a", "pl-b", "pl-c"})));
87 clusterDeps.put( "java", new HashSet<String>(Arrays.asList( new String[] {"pl-b", "pl-c", "b.c.d"})));
88 tup2.cluster = null;
89 tup1.cluster = null;
90
91 CreateClusterAppMojo.assignClustersToBundles(bundles, Collections.<String>emptySet(), clusterDeps, Collections.<String, Set<String>>emptyMap(), null);
92 assertEquals( "java", tup2.cluster);
93 assertEquals( "java", tup1.cluster);
94
95 }
96
97 private BundleTuple createBundleTuple( String cnb, File file ) throws MojoExecutionException
98 {
99 assertTrue( file.exists());
100
101 ExamineManifest em = new ExamineManifest( null );
102 em.setManifestFile( file );
103 em.setPopulateDependencies( true);
104 em.checkFile();
105 assertEquals( cnb, em.getModule());
106 BundleTuple toRet = new BundleTuple( null, em);
107
108 return toRet;
109 }
110 }