Source Code Cross Referenced for FieldIndexEntryTest.java in  » Rule-Engine » drolls-Rule-Engine » org » drools » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Rule Engine » drolls Rule Engine » org.drools.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.drools.util;
002:
003:        import junit.framework.TestCase;
004:
005:        import org.drools.Cheese;
006:        import org.drools.base.ClassFieldExtractor;
007:        import org.drools.base.ClassFieldExtractorCache;
008:        import org.drools.base.evaluators.Operator;
009:        import org.drools.base.evaluators.StringFactory;
010:        import org.drools.common.DefaultFactHandle;
011:        import org.drools.common.InternalFactHandle;
012:        import org.drools.util.AbstractHashTable.FactEntryImpl;
013:        import org.drools.util.AbstractHashTable.FieldIndex;
014:        import org.drools.util.AbstractHashTable.SingleIndex;
015:        import org.drools.util.FactHandleIndexHashTable.FieldIndexEntry;
016:
017:        public class FieldIndexEntryTest extends TestCase {
018:
019:            public void testSingleEntry() {
020:                final ClassFieldExtractor extractor = ClassFieldExtractorCache
021:                        .getExtractor(Cheese.class, "type", getClass()
022:                                .getClassLoader());
023:
024:                final FieldIndex fieldIndex = new FieldIndex(extractor, null,
025:                        StringFactory.getInstance()
026:                                .getEvaluator(Operator.EQUAL));
027:                final SingleIndex singleIndex = new SingleIndex(
028:                        new FieldIndex[] { fieldIndex }, 1);
029:
030:                final FieldIndexEntry index = new FieldIndexEntry(singleIndex,
031:                        "stilton".hashCode());
032:
033:                // Test initial construction
034:                assertNull(index.getFirst());
035:                assertEquals("stilton".hashCode(), index.hashCode());
036:
037:                final Cheese stilton1 = new Cheese("stilton", 35);
038:                final InternalFactHandle h1 = new DefaultFactHandle(1, stilton1);
039:
040:                // test add
041:                index.add(h1);
042:
043:                final FactEntryImpl entry1 = index.getFirst();
044:                assertSame(h1, entry1.getFactHandle());
045:                assertNull(entry1.getNext());
046:                assertSame(entry1, index.get(h1));
047:
048:                // test get
049:                final FactEntryImpl entry2 = index.get(h1);
050:                assertSame(entry1, entry2);
051:
052:                // test remove
053:                index.remove(h1);
054:                assertNull(index.getFirst());
055:            }
056:
057:            public void testTwoEntries() {
058:                final ClassFieldExtractor extractor = ClassFieldExtractorCache
059:                        .getExtractor(Cheese.class, "type", getClass()
060:                                .getClassLoader());
061:                final FieldIndex fieldIndex = new FieldIndex(extractor, null,
062:                        StringFactory.getInstance()
063:                                .getEvaluator(Operator.EQUAL));
064:                final SingleIndex singleIndex = new SingleIndex(
065:                        new FieldIndex[] { fieldIndex }, 1);
066:
067:                final FieldIndexEntry index = new FieldIndexEntry(singleIndex,
068:                        "stilton".hashCode());
069:
070:                final Cheese stilton1 = new Cheese("stilton", 35);
071:                final InternalFactHandle h1 = new DefaultFactHandle(1, stilton1);
072:                final Cheese stilton2 = new Cheese("stilton", 59);
073:                final InternalFactHandle h2 = new DefaultFactHandle(2, stilton2);
074:
075:                // test add
076:                index.add(h1);
077:                index.add(h2);
078:                assertEquals(h2, index.getFirst().getFactHandle());
079:                assertEquals(h1, ((FactEntryImpl) index.getFirst().getNext())
080:                        .getFactHandle());
081:
082:                // test get
083:                assertEquals(h1, index.get(h1).getFactHandle());
084:                assertEquals(h2, index.get(h2).getFactHandle());
085:
086:                // test removal for combinations
087:                // remove first
088:                index.remove(h2);
089:                assertEquals(h1, index.getFirst().getFactHandle());
090:
091:                // remove second
092:                index.add(h2);
093:                index.remove(h1);
094:                assertEquals(h2, index.getFirst().getFactHandle());
095:
096:                // check index type does not change, as this fact is removed
097:                stilton1.setType("cheddar");
098:            }
099:
100:            public void testThreeEntries() {
101:                final ClassFieldExtractor extractor = ClassFieldExtractorCache
102:                        .getExtractor(Cheese.class, "type", getClass()
103:                                .getClassLoader());
104:                final FieldIndex fieldIndex = new FieldIndex(extractor, null,
105:                        StringFactory.getInstance()
106:                                .getEvaluator(Operator.EQUAL));
107:                final SingleIndex singleIndex = new SingleIndex(
108:                        new FieldIndex[] { fieldIndex }, 1);
109:
110:                final FieldIndexEntry index = new FieldIndexEntry(singleIndex,
111:                        "stilton".hashCode());
112:
113:                final Cheese stilton1 = new Cheese("stilton", 35);
114:                final InternalFactHandle h1 = new DefaultFactHandle(1, stilton1);
115:                final Cheese stilton2 = new Cheese("stilton", 59);
116:                final InternalFactHandle h2 = new DefaultFactHandle(2, stilton2);
117:                final Cheese stilton3 = new Cheese("stilton", 59);
118:                final InternalFactHandle h3 = new DefaultFactHandle(3, stilton3);
119:
120:                // test add
121:                index.add(h1);
122:                index.add(h2);
123:                index.add(h3);
124:                assertEquals(h3, index.getFirst().getFactHandle());
125:                assertEquals(h2, ((FactEntryImpl) index.getFirst().getNext())
126:                        .getFactHandle());
127:                assertEquals(h1, ((FactEntryImpl) index.getFirst().getNext()
128:                        .getNext()).getFactHandle());
129:
130:                // test get
131:                assertEquals(h1, index.get(h1).getFactHandle());
132:                assertEquals(h2, index.get(h2).getFactHandle());
133:                assertEquals(h3, index.get(h3).getFactHandle());
134:
135:                // test removal for combinations
136:                //remove first
137:                index.remove(h3);
138:                assertEquals(h2, index.getFirst().getFactHandle());
139:                assertEquals(h1, ((FactEntryImpl) index.getFirst().getNext())
140:                        .getFactHandle());
141:
142:                index.add(h3);
143:                index.remove(h2);
144:                assertEquals(h3, index.getFirst().getFactHandle());
145:                assertEquals(h1, ((FactEntryImpl) index.getFirst().getNext())
146:                        .getFactHandle());
147:
148:                index.add(h2);
149:                index.remove(h1);
150:                assertEquals(h2, index.getFirst().getFactHandle());
151:                assertEquals(h3, ((FactEntryImpl) index.getFirst().getNext())
152:                        .getFactHandle());
153:
154:                index.remove(index.getFirst().getFactHandle());
155:                // check index type does not change, as this fact is removed
156:                stilton2.setType("cheddar");
157:            }
158:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.