View Javadoc

1   package com.atlassian.plugin.osgi.factory.transform.model;
2   
3   import junit.framework.TestCase;
4   import org.dom4j.Element;
5   import org.dom4j.DocumentFactory;
6   import com.atlassian.plugin.PluginParseException;
7   
8   public class TestComponentImport extends TestCase
9   {
10      public void testValidate()
11      {
12          Element e = DocumentFactory.getInstance().createElement("component-import");
13          e.addAttribute("key", " foo ");
14          e.addAttribute("interface", " foo.Bar ");
15          e.addAttribute("filter", " (bleh=blargh) ");
16  
17          ComponentImport ci = new ComponentImport(e);
18          assertEquals("foo", ci.getKey());
19          assertEquals("foo.Bar", ci.getInterfaces().iterator().next());
20          assertEquals("(bleh=blargh)", ci.getFilter());
21  
22  
23          e.remove(e.attribute("filter"));
24          ci = new ComponentImport(e);
25          assertNull(ci.getFilter());
26  
27  
28          try
29          {
30              e.remove(e.attribute("interface"));
31              new ComponentImport(e);
32              fail();
33          }
34          catch (PluginParseException ex)
35          {
36              // test passed
37          }
38  
39  
40          Element inf = DocumentFactory.getInstance().createElement("interface");
41          e.add(inf);
42          try
43          {
44              new ComponentImport(e);
45              fail();
46          }
47          catch (PluginParseException ex)
48          {
49              // test passed
50          }
51  
52          inf.setText("foo.Bar");
53          ci = new ComponentImport(e);
54          assertEquals("foo.Bar", ci.getInterfaces().iterator().next());
55  
56      }
57  }