Source Code Cross Referenced for TestCut.java in  » Rule-Engine » Mandarax » test » org » mandarax » reference » 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 » Mandarax » test.org.mandarax.reference 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2 of the License, or (at your option) any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         */
018:        package test.org.mandarax.reference;
019:
020:        import junit.framework.TestCase;
021:
022:        import org.mandarax.kernel.Fact;
023:        import org.mandarax.kernel.InferenceEngine;
024:        import org.mandarax.kernel.InferenceException;
025:        import org.mandarax.kernel.Prerequisite;
026:        import org.mandarax.kernel.Query;
027:        import org.mandarax.kernel.ResultSet;
028:        import org.mandarax.kernel.SimplePredicate;
029:        import org.mandarax.reference.AdvancedKnowledgeBase;
030:        import org.mandarax.reference.ResolutionInferenceEngine4;
031:        import org.mandarax.util.LogicFactorySupport;
032:        import org.mandarax.util.logging.LogCategories;
033:
034:        /**
035:         * An abstract test case class for testing cut.
036:         * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
037:         * @version 3.4 <7 March 05>
038:         * @since 2.1
039:         */
040:        public abstract class TestCut extends TestCase implements  LogCategories {
041:            public static final String QUERY_VARIABLE = "query_var";
042:
043:            protected org.mandarax.kernel.KnowledgeBase kb = new AdvancedKnowledgeBase();
044:            protected InferenceEngine ie = new ResolutionInferenceEngine4();
045:            protected LogicFactorySupport lfs = new LogicFactorySupport();
046:
047:            /**
048:             * Constructor.
049:             */
050:            public TestCut() {
051:                super ("testInferenceEngine");
052:            }
053:
054:            /**
055:             * Populate the knowledge base.
056:             * @param knowledge the knowledge base
057:             */
058:            public abstract void feedKnowledgeBase(
059:                    org.mandarax.kernel.KnowledgeBase knowledge);
060:
061:            /**
062:             * Get a description of this test case.
063:             * This is used by the <code>org.mandarax.demo</code>
064:             * package to display the test cases.
065:             * @return java.lang.String
066:             */
067:            public String getDescription() {
068:                return "test case " + getClass().getName();
069:            }
070:
071:            /**
072:             * Sets up the fixture.
073:             */
074:            protected void setUp() {
075:                feedKnowledgeBase(kb);
076:            }
077:
078:            /**
079:             * Get the expected results.
080:             * @return an array of strings
081:             */
082:            protected abstract String[] getExpectedResults();
083:
084:            /**
085:             * Run the test.
086:             */
087:            public void testInferenceEngine() {
088:                LOG_TEST.info("Start Testcase " + getClass().getName()
089:                        + " , test method: " + "testInferenceEngine()");
090:                Fact queryFact = lfs.fact(new SimplePredicate("R",
091:                        new Class[] { String.class }), lfs.variable(
092:                        QUERY_VARIABLE, String.class));
093:                Query query = lfs.query(queryFact, "?");
094:                try {
095:                    ResultSet rs = ie.query(query, kb, InferenceEngine.ALL,
096:                            InferenceEngine.BUBBLE_EXCEPTIONS);
097:
098:                    String[] expected = getExpectedResults();
099:                    boolean success = true;
100:                    int i = 0;
101:                    while (i < expected.length && success) {
102:                        success = success && rs.next();
103:                        success = success
104:                                && expected[i].equals(rs.getResult(
105:                                        String.class, QUERY_VARIABLE));
106:                        i = i + 1;
107:                    }
108:                    // there should be no more computed results:
109:                    success = success && !rs.next();
110:
111:                    assertTrue(success);
112:                } catch (InferenceException x) {
113:                    assertTrue(false);
114:                }
115:                LOG_TEST.info("Finish Testcase " + getClass().getName()
116:                        + " , test method: " + "testInferenceEngine()");
117:            }
118:
119:            /**
120:             * Convert this object to a string.
121:             * @return the string representation of the object
122:             */
123:            public String toString() {
124:                StringBuffer buf = new StringBuffer();
125:                buf.append(super .toString());
126:                buf.append(" (");
127:                buf.append(kb.getClass().getName());
128:                buf.append(" / ");
129:                buf.append(ie.getClass().getName());
130:                buf.append(")");
131:                return buf.toString();
132:            }
133:
134:            /**
135:             * Create a prerequisite with a simple predicate and a constant. 
136:             * @param p a predicate name
137:             * @param c a constant name
138:             * @return a prerequisite
139:             */
140:            protected Prerequisite prereq1(String p, String c) {
141:                return lfs.prereq(new SimplePredicate(p,
142:                        new Class[] { String.class }), lfs
143:                        .cons(c, String.class));
144:            }
145:
146:            /**
147:             * Create a prerequisite with a simple predicate and a variable. 
148:             * @param p a predicate name
149:             * @param v a variable name
150:             * @return a prerequisite
151:             */
152:            protected Prerequisite prereq2(String p, String v) {
153:                return lfs.prereq(new SimplePredicate(p,
154:                        new Class[] { String.class }), lfs.variable(v,
155:                        String.class));
156:            }
157:
158:            /**
159:             * Create a cut prerequisite. 
160:             * @return a prerequisite
161:             */
162:            protected Prerequisite cut() {
163:                return lfs.cut();
164:            }
165:
166:            /**
167:             * Create a fact with a simple predicate and a constant. 
168:             * @param p a predicate name
169:             * @param c a constant name
170:             * @return a prerequisite
171:             */
172:            protected Fact fact1(String p, String c) {
173:                return lfs.fact(new SimplePredicate(p,
174:                        new Class[] { String.class }), lfs
175:                        .cons(c, String.class));
176:            }
177:
178:            /**
179:             * Create a fact with a simple predicate and a variable. 
180:             * @param p a predicate name
181:             * @param v a variable name
182:             * @return a fact
183:             */
184:            protected Fact fact2(String p, String v) {
185:                return lfs.fact(new SimplePredicate(p,
186:                        new Class[] { String.class }), lfs.variable(v,
187:                        String.class));
188:            }
189:
190:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.