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