1 package com.atlassian.plugin.osgi.factory.transform.stage;
2
3 import junit.framework.TestCase;
4 import org.dom4j.Element;
5 import org.dom4j.DocumentHelper;
6 import org.dom4j.DocumentException;
7
8 import java.io.IOException;
9
10 import com.atlassian.plugin.osgi.external.SingleModuleDescriptorFactory;
11 import com.atlassian.plugin.PluginParseException;
12
13 public class TestModuleTypeSpringStage extends TestCase
14 {
15 public void testTransform() throws IOException, DocumentException
16 {
17 Element pluginRoot = DocumentHelper.createDocument().addElement("atlassian-plugin");
18 Element moduleType = pluginRoot.addElement("module-type");
19 moduleType.addAttribute("key", "foo");
20 moduleType.addAttribute("class", "my.FooDescriptor");
21
22 SpringTransformerTestHelper.transform(new ModuleTypeSpringStage(), pluginRoot,
23 "beans:bean[@id='springHostContainer' and @class='"+ ModuleTypeSpringStage.SPRING_HOST_CONTAINER+"']",
24 "beans:bean[@id='moduleType-foo' and @class='"+ SingleModuleDescriptorFactory.class.getName()+"']",
25 "osgi:service[@id='moduleType-foo_osgiService' and @auto-export='interfaces']");
26 }
27
28 public void testTransformForOneApp() throws IOException, DocumentException
29 {
30 Element pluginRoot = DocumentHelper.createDocument().addElement("atlassian-plugin");
31 Element moduleType = pluginRoot.addElement("module-type");
32 moduleType.addAttribute("key", "foo");
33 moduleType.addAttribute("class", "my.FooDescriptor");
34 moduleType.addAttribute("application", "bar");
35 SpringTransformerTestHelper.transform(new ModuleTypeSpringStage(), pluginRoot,
36 "not(beans:bean[@id='moduleType-foo' and @class='" + SingleModuleDescriptorFactory.class.getName()+"'])");
37
38 pluginRoot = DocumentHelper.createDocument().addElement("atlassian-plugin");
39 moduleType = pluginRoot.addElement("module-type");
40 moduleType.addAttribute("key", "foo");
41 moduleType.addAttribute("class", "my.FooDescriptor");
42 moduleType.addAttribute("application", "foo");
43 SpringTransformerTestHelper.transform(new ModuleTypeSpringStage(), pluginRoot,
44 "beans:bean[@id='moduleType-foo' and @class='"+ SingleModuleDescriptorFactory.class.getName()+"']");
45 }
46
47 public void testTransformOfBadElement() throws IOException, DocumentException
48 {
49 Element pluginRoot = DocumentHelper.createDocument().addElement("atlassian-plugin");
50 Element moduleType = pluginRoot.addElement("module-type");
51 moduleType.addAttribute("key", "foo");
52
53 try
54 {
55 SpringTransformerTestHelper.transform(new ModuleTypeSpringStage(), pluginRoot,
56 "beans:bean[@id='moduleType-foo' and @class='"+ SingleModuleDescriptorFactory.class.getName()+"']",
57 "osgi:service[@id='moduleType-foo_osgiService' and @auto-export='interfaces']");
58 fail();
59 }
60 catch (PluginParseException ex)
61 {
62
63 }
64 }
65
66 public void testTransformOfBadElementKey() throws IOException, DocumentException
67 {
68 Element pluginRoot = DocumentHelper.createDocument().addElement("atlassian-plugin");
69 Element moduleType = pluginRoot.addElement("module-type");
70
71 try
72 {
73 SpringTransformerTestHelper.transform(new ModuleTypeSpringStage(), pluginRoot,
74 "beans:bean[@id='moduleType-foo' and @class='"+ SingleModuleDescriptorFactory.class.getName()+"']",
75 "osgi:service[@id='moduleType-foo_osgiService' and @auto-export='interfaces']");
76 fail();
77 }
78 catch (PluginParseException ex)
79 {
80
81 }
82 }
83
84 }