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