1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.index;
20
21 import java.io.File;
22 import java.io.IOException;
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.Random;
26
27 import org.apache.maven.index.context.IndexCreator;
28 import org.apache.maven.index.creator.JarFileContentsIndexCreator;
29 import org.apache.maven.index.creator.MavenArchetypeArtifactInfoIndexCreator;
30 import org.apache.maven.index.creator.MavenPluginArtifactInfoIndexCreator;
31 import org.apache.maven.index.creator.MinimalArtifactInfoIndexCreator;
32 import org.codehaus.plexus.util.FileUtils;
33 import org.junit.Test;
34
35 import static org.junit.Assert.assertFalse;
36 import static org.junit.Assert.assertNotEquals;
37
38 public class AbstractIndexCreatorHelper extends AbstractTestSupport {
39 public List<IndexCreator> DEFAULT_CREATORS;
40
41 public List<IndexCreator> FULL_CREATORS;
42
43 public List<IndexCreator> MIN_CREATORS;
44
45 Random rand = new Random();
46
47 @Override
48 public void setUp() throws Exception {
49 super.setUp();
50
51 DEFAULT_CREATORS = new ArrayList<>();
52 FULL_CREATORS = new ArrayList<>();
53 MIN_CREATORS = new ArrayList<>();
54
55 IndexCreator min = lookup(IndexCreator.class, MinimalArtifactInfoIndexCreator.ID);
56 IndexCreator mavenPlugin = lookup(IndexCreator.class, MavenPluginArtifactInfoIndexCreator.ID);
57 IndexCreator mavenArchetype = lookup(IndexCreator.class, MavenArchetypeArtifactInfoIndexCreator.ID);
58 IndexCreator jar = lookup(IndexCreator.class, JarFileContentsIndexCreator.ID);
59
60 MIN_CREATORS.add(min);
61
62 DEFAULT_CREATORS.add(min);
63 DEFAULT_CREATORS.add(mavenPlugin);
64 DEFAULT_CREATORS.add(mavenArchetype);
65
66 FULL_CREATORS.add(min);
67 FULL_CREATORS.add(mavenPlugin);
68 FULL_CREATORS.add(mavenArchetype);
69 FULL_CREATORS.add(jar);
70 }
71
72 protected void deleteDirectory(File dir) throws IOException {
73 FileUtils.deleteDirectory(dir);
74 }
75
76 protected File getDirectory(String name) {
77
78
79 File outputFolder = new File(getBasedir(), "target/tests/" + name + "-" + rand.nextLong() + "/");
80 outputFolder.delete();
81 assertFalse(outputFolder.exists());
82 return outputFolder;
83 }
84
85 @Test
86 public void testDirectory() throws IOException {
87 File dir = this.getDirectory("foo");
88 assert (dir.getAbsolutePath().contains("foo"));
89 this.deleteDirectory(dir);
90 assertFalse(dir.exists());
91
92 File dir2 = this.getDirectory("foo");
93 assertNotEquals("Directories aren't unique", dir.getCanonicalPath(), dir2.getCanonicalPath());
94 }
95 }