1 package org.codehaus.plexus;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.io.File;
20
21 import junit.framework.TestCase;
22 import org.codehaus.plexus.component.discovery.DiscoveredComponent;
23 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
24 import org.codehaus.plexus.test.DefaultLoadOnStartService;
25
26
27
28
29 public class PlexusTestCaseTest extends TestCase {
30 private String basedir;
31
32 public void setUp() {
33 basedir = System.getProperty("basedir");
34
35 if (basedir == null) {
36 basedir = new File(".").getAbsolutePath();
37 }
38 }
39
40 public void testPlexusTestCase() throws Exception {
41 PlexusTestCase tc = new PlexusTestCase() {};
42
43 tc.setUp();
44
45 try {
46 tc.lookup(DiscoveredComponent.class, "unknown");
47
48 fail("Expected ComponentLookupException.");
49 } catch (ComponentLookupException ex) {
50 assertTrue(true);
51 }
52
53
54 DiscoveredComponent component = tc.lookup(DiscoveredComponent.class);
55
56 assertNotNull(component);
57
58 assertNotNull(tc.getClassLoader());
59
60 tc.tearDown();
61 }
62
63 public void testLoadOnStartComponents() throws Exception {
64 PlexusTestCase tc = new PlexusTestCase() {
65 protected String getCustomConfigurationName() {
66 return PlexusTestCase.getTestConfiguration(getClass());
67 }
68 };
69
70 tc.setupContainer();
71
72
73
74 assertTrue("The load on start components haven't been started.", DefaultLoadOnStartService.isStarted);
75
76 tc.tearDown();
77 }
78
79 public void testGetFile() {
80 File file = PlexusTestCase.getTestFile("pom.xml");
81
82 assertTrue(file.exists());
83
84 file = PlexusTestCase.getTestFile(basedir, "pom.xml");
85
86 assertTrue(file.exists());
87 }
88
89 public void testGetPath() {
90 File file = new File(PlexusTestCase.getTestPath("pom.xml"));
91
92 assertTrue(file.exists());
93
94 file = new File(PlexusTestCase.getTestPath(basedir, "pom.xml"));
95
96 assertTrue(file.exists());
97 }
98 }