1 package com.atlassian.plugin.test;
2
3 import junit.framework.TestCase;
4 import junit.framework.Assert;
5
6 import java.io.File;
7 import java.net.URLClassLoader;
8 import java.net.URL;
9
10 import org.apache.commons.io.IOUtils;
11 import com.atlassian.plugin.test.PluginJarBuilder;
12
13 public class TestPluginJarBuilder extends TestCase {
14
15 public void testBuild() throws Exception {
16 File jar = new PluginJarBuilder("foo")
17 .addJava("my.Foo", "package my; public class Foo { public String hi() {return \"hi\";}}")
18 .addResource("foo.txt", "Some text")
19 .addPluginInformation("someKey", "someName", "1.33")
20 .build();
21 assertNotNull(jar);
22
23 URLClassLoader cl = new URLClassLoader(new URL[]{jar.toURI().toURL()}, null);
24 Class<?> cls = cl.loadClass("my.Foo");
25 assertNotNull(cls);
26 Object foo = cls.newInstance();
27 String result = (String) cls.getMethod("hi").invoke(foo);
28 assertEquals("hi", result);
29 Assert.assertEquals("Some text", IOUtils.toString(cl.getResourceAsStream("foo.txt")));
30 assertNotNull(cl.getResource("META-INF/MANIFEST.MF"));
31
32 String xml = IOUtils.toString(cl.getResourceAsStream("atlassian-plugin.xml"));
33 assertTrue(xml.indexOf("someKey") > 0);
34 assertTrue(xml.indexOf("someName") > 0);
35 assertTrue(xml.indexOf("1.33") > 0);
36 }
37 }