2 package org.netbeans.server.componentsmatch;
4 import java.io.IOException;
5 import java.io.InputStreamReader;
6 import java.io.StringReader;
7 import org.netbeans.modules.exceptions.entity.InnocentClass;
8 import org.netbeans.server.uihandler.DatabaseTestCase;
14 public class MatcherTest extends DatabaseTestCase{
16 /** Creates a new instance of MatcherTest */
17 public MatcherTest(String name) {
21 public void testSimple() throws IOException {
22 Matcher.read(new StringReader(""));//clean Matcher
23 Package fsPack = new Package("org.openide.filesystems");
24 Component fsComp = new Component("openide","filesystems",4);
25 Component openideCodeComp = new Component("openide","code",2);
26 fsPack.addComponent(fsComp);
27 fsPack.addComponent(openideCodeComp);
28 Matcher.addGlobalPackage(fsPack);
30 assertEquals("Components size",2,fsPack.getComponents().size());
31 assertSame(fsComp,fsPack.getFirstComponent());
34 Matcher matcher = Matcher.getDefault();
35 Component comp = matcher.match(new StackTraceElement[] {
36 new StackTraceElement("org.openide.filesystems.LocalFileSystem","getName(String)","file",45)
38 assertSame(fsComp,comp);
40 comp = matcher.match(new StackTraceElement[] {
41 new StackTraceElement("java.lang.String","getName(String)","file",45),
42 new StackTraceElement("org.openide.filesystems.LocalFileSystem","getName(String)","file",45)
44 assertSame(fsComp,comp);
46 comp = matcher.match(new StackTraceElement[] {
47 new StackTraceElement("java.lang.String","getName(String)","file",45),
51 comp = matcher.match(new StackTraceElement[] {
52 new StackTraceElement("java.lang.String","getName(String)","${java.home}/lib/rt.jar",45),
56 comp = matcher.match(new StackTraceElement[] {
57 new StackTraceElement("java.lang.String","getName(String)","${netbeans.home}/lib/org-openide-util.jar",45),
59 assertEquals(comp.getComponent(), "netbeans.home");
60 assertEquals(comp.getSubComponent(), "org-openide-util.jar");
62 comp = matcher.match(new StackTraceElement[] {
63 new StackTraceElement("org.nothing.nothing","getName(String)","${netbeans.home}/lib/org-openide-util.jar",45),
64 new StackTraceElement("org.openide.filesystems.LocalFileSystem","getName(String)","file",45)
66 assertEquals(comp.getComponent(), "netbeans.home");
67 assertEquals(comp.getSubComponent(), "org-openide-util.jar");
69 comp = matcher.match(new StackTraceElement[] {
70 new StackTraceElement("java.lang.String","getName(String)","file",45),
71 new StackTraceElement("org.nothing.nothing","getName(String)","${user.dir}/lib/some-user-module.jar",45),
72 new StackTraceElement("org.openide.filesystems.LocalFileSystem","getName(String)","file",45)
74 assertEquals(comp.getComponent(), "user.dir");
75 assertEquals(comp.getSubComponent(), "some-user-module.jar");
79 public void testRead() throws IOException {
80 Matcher.read(new InputStreamReader (Matcher.class.getResourceAsStream("componentmapping.txt")));
81 // org.netbeans.api.java.source;27;java;retouche;22;editor;code completion;2;java;j2seproject;1;refactoring;retouche;1;java;srcmodel;1;
82 Package pack = Matcher.getDefault().packages.get("org.netbeans.api.java.source");
83 assertNotNull("package exists",pack);
84 Component first = pack.getFirstComponent();
85 assertEquals("component","java",first.getComponent());
86 assertEquals("subcomponent","retouche",first.getSubComponent());
87 assertEquals("issues count",22,first.getIssues());
88 assertEquals("components count",5,pack.getComponents().size());
90 Matcher matcher = Matcher.getDefault();
91 Component comp = matcher.match(new StackTraceElement[] {
92 new StackTraceElement("java.lang.String","getName(String)","file",45),
93 new StackTraceElement("org.openide.ErrorManager","getDefault()","file",45)
96 assertEquals("openide",comp.getComponent());
97 assertEquals("wizards",comp.getSubComponent());
98 comp = matcher.match(new StackTraceElement[] {
99 new StackTraceElement("java.lang.String","getName(String)","file",45),
100 new StackTraceElement("java.util.Vector","size()","file",45),
101 new StackTraceElement("org.netbeans.modules.j2ee.refactoring.unknown.MyClass","getDefault()","file",45)
103 assertEquals("j2ee",comp.getComponent());
104 assertEquals("refactoring",comp.getSubComponent());
106 comp = matcher.match(new StackTraceElement[] {
107 new StackTraceElement("org.netbeans.modules.reallyunknownmodule.Aaa","getDefault()","file",45)
112 public void testOrgNetBeansLib() throws IOException {
113 Matcher.read(new InputStreamReader(Matcher.class.getResourceAsStream("componentmapping.txt")));
114 Matcher matcher = Matcher.getDefault();
116 Component comp = matcher.match(new StackTraceElement[] {
117 new StackTraceElement("org.netbeans.lib.xxx","checkLexerInputFinished()","file",45),
121 public void testVisualWebInsync() throws IOException {
122 Matcher.read(new InputStreamReader(Matcher.class.getResourceAsStream("septemberComponents.txt")));
123 Matcher matcher = Matcher.getDefault();
125 Component comp = matcher.match(new StackTraceElement[] {
126 new StackTraceElement("org.netbeans.modules.visualweb.insync.ModelSet","modelSet()","file",45),
128 assertEquals("visualweb",comp.getComponent());
130 public void testXml() throws IOException {
131 Matcher.read(new InputStreamReader(Matcher.class.getResourceAsStream("septemberComponents.txt")));
132 Matcher matcher = Matcher.getDefault();
134 Component comp = matcher.match(new StackTraceElement[] {
135 new StackTraceElement("org.netbeans.modules.xml.wsdl.ui.navigator.WSDLNavigatorContent.","modelSet()","file",45),
136 new StackTraceElement("java.awt.event.InvocationEvent.","dispatch()","file",45),
138 // http://installer.netbeans.org/issues/show_bug.cgi?id=112532
139 assertFalse("core".equals(comp.getComponent()));
142 public void testInnocent() throws IOException{
143 Matcher.read(new InputStreamReader (Matcher.class.getResourceAsStream("componentmapping.txt")));
144 Matcher matcher = Matcher.getDefault();
146 Component comp = matcher.match(new StackTraceElement[] {
147 new StackTraceElement("org.openide.util.lookup.InstanceContent$SimpleItem","<init>","file",45)
149 assertNotNull(comp);//no Innocent
151 comp = matcher.match(new StackTraceElement[] {
152 new StackTraceElement("org.openide.util.lookup.SimpleLookup","<init>","file",45)
154 assertNotNull(comp);//no Innocent
156 perUtils.persist(new InnocentClass("org.openide.util.lookup")); // look up is innocent
158 comp = matcher.match(new StackTraceElement[] {
159 new StackTraceElement("org.openide.util.lookup.InstanceContent$SimpleItem","<init>","file",45)
163 comp = matcher.match(new StackTraceElement[] {
164 new StackTraceElement("org.openide.util.lookup.SimpleLookup","<init>","file",45)
168 comp = matcher.match(new StackTraceElement[] {
169 new StackTraceElement("org.openide.util.lookup.Lookups","<init>","file",45)
173 comp = matcher.match(new StackTraceElement[] {
174 new StackTraceElement("org.openide.util.Enumerations","<init>","file",45)