1 package org.apache.maven.plugin.war;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.archiver.MavenArchiveConfiguration;
23 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
24 import org.codehaus.plexus.util.FileUtils;
25
26 import java.io.File;
27
28
29
30
31 public class WarManifestMojoTest
32 extends AbstractMojoTestCase
33 {
34 File testPom;
35
36 WarManifestMojo mojo;
37
38 public void testEnvironment()
39 throws Exception
40 {
41 loadMojo( "target/test-classes/unit/manifest/basic-manifest-test/plugin-config.xml" );
42 }
43
44 public void testBasicManifest()
45 throws Exception
46 {
47 loadMojo( "target/test-classes/unit/manifest/basic-manifest-test/plugin-config.xml" );
48
49 mojo.execute();
50
51 File warSourceDir = (File) getVariableValueFromObject( mojo, "warSourceDirectory" );
52
53 File manifestDir = new File( warSourceDir, "META-INF" );
54
55 File manifest = new File( manifestDir, "MANIFEST.MF" );
56
57 assertTrue( manifest.exists() );
58 }
59
60 public void testManifestWithClasspath()
61 throws Exception
62 {
63 loadMojo( "target/test-classes/unit/manifest/manifest-with-classpath/plugin-config.xml" );
64
65 MavenArchiveConfiguration config = (MavenArchiveConfiguration) getVariableValueFromObject( mojo, "archive" );
66
67 mojo.execute();
68
69 assertTrue( config.getManifest().isAddClasspath() );
70
71 File warSourceDir = (File) getVariableValueFromObject( mojo, "warSourceDirectory" );
72
73 File manifestDir = new File( warSourceDir, "META-INF" );
74
75 File manifest = new File( manifestDir, "MANIFEST.MF" );
76
77 assertTrue( manifest.exists() );
78
79 String content = FileUtils.fileRead( manifest );
80
81 int idx = content.indexOf( "Class-Path" );
82
83 assertTrue( idx >= 0 );
84 }
85
86 public void testManifestWithMainClass()
87 throws Exception
88 {
89 loadMojo( "target/test-classes/unit/manifest/manifest-with-main-class/plugin-config.xml" );
90
91 MavenArchiveConfiguration config = (MavenArchiveConfiguration) getVariableValueFromObject( mojo, "archive" );
92
93 mojo.execute();
94
95 assertEquals( "org.dummy.test.SomeClass", config.getManifest().getMainClass() );
96
97 File warSourceDir = (File) getVariableValueFromObject( mojo, "warSourceDirectory" );
98
99 File manifestDir = new File( warSourceDir, "META-INF" );
100
101 File manifest = new File( manifestDir, "MANIFEST.MF" );
102
103 assertTrue( manifest.exists() );
104
105 String content = FileUtils.fileRead( manifest );
106
107 int idx = content.indexOf( "Main-Class" );
108
109 assertTrue( idx >= 0 );
110 }
111
112 public void testManifestWithOtherAttributes()
113 throws Exception
114 {
115 loadMojo( "target/test-classes/unit/manifest/manifest-with-other-attrs/plugin-config.xml" );
116
117 MavenArchiveConfiguration config = (MavenArchiveConfiguration) getVariableValueFromObject( mojo, "archive" );
118
119 mojo.execute();
120
121 assertTrue( config.getManifest().isAddExtensions() );
122
123 File warSourceDir = (File) getVariableValueFromObject( mojo, "warSourceDirectory" );
124
125 File manifestDir = new File( warSourceDir, "META-INF" );
126
127 File manifest = new File( manifestDir, "MANIFEST.MF" );
128
129 assertTrue( manifest.exists() );
130
131 String content = FileUtils.fileRead( manifest );
132
133 int idx = content.indexOf( "Specification-Title" );
134
135 assertTrue( idx >= 0 );
136
137 idx = content.indexOf( "Specification-Vendor" );
138
139 assertTrue( idx >= 0 );
140
141 idx = content.indexOf( "Implementation-Vendor" );
142
143 assertTrue( idx >= 0 );
144 }
145
146 public void testManifestWithCustomAttributes()
147 throws Exception
148 {
149 loadMojo( "target/test-classes/unit/manifest/manifest-with-custom-attrs/plugin-config.xml" );
150
151 MavenArchiveConfiguration config = (MavenArchiveConfiguration) getVariableValueFromObject( mojo, "archive" );
152
153 mojo.execute();
154
155 assertTrue( config.getManifest().isAddExtensions() );
156
157 File warSourceDir = (File) getVariableValueFromObject( mojo, "warSourceDirectory" );
158
159 File manifestDir = new File( warSourceDir, "META-INF" );
160
161 File manifest = new File( manifestDir, "MANIFEST.MF" );
162
163 assertTrue( manifest.exists() );
164
165 String content = FileUtils.fileRead( manifest );
166
167 int idx = content.indexOf( "Specification-Title" );
168
169 assertTrue( idx >= 0 );
170
171 idx = content.indexOf( "Custom-Version" );
172
173 assertTrue( idx >= 0);
174
175
176 }
177
178 public void loadMojo( String pluginXml )
179 throws Exception
180 {
181 testPom = new File( getBasedir(), pluginXml );
182
183 mojo = (WarManifestMojo) lookupMojo( "manifest", testPom );
184
185 assertNotNull( mojo );
186 }
187 }