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