📄 basebetarightmemorytestclass.java
字号:
/*
* Copyright 2005 JBoss Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.drools.reteoo.beta;
import java.util.Iterator;
import javax.naming.OperationNotSupportedException;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.drools.WorkingMemory;
import org.drools.common.DefaultFactHandle;
import org.drools.reteoo.ReteooFactHandleFactory;
import org.drools.reteoo.ObjectMatches;
import org.drools.reteoo.ReteTuple;
import org.drools.reteoo.ReteooRuleBase;
import org.drools.reteoo.ReteooWorkingMemory;
import org.drools.spi.FactHandleFactory;
import org.drools.util.MultiLinkedListNodeWrapper;
/**
*
* BaseBetaRightMemoryTestClass
* A base class for test cases testing BetaRightMemory implementations
*
* @author <a href="mailto:tirelli@post.com">Edson Tirelli</a>
*
* Created: 28/02/2006
*/
public abstract class BaseBetaRightMemoryTestClass extends TestCase {
protected ReteooWorkingMemory workingMemory;
protected BetaRightMemory memory;
protected MockBetaRightMemory child;
protected DummyValueObject obj0;
protected DummyValueObject obj1;
protected DummyValueObject obj2;
protected FactHandleFactory factory;
protected DefaultFactHandle f0;
protected DefaultFactHandle f1;
protected DefaultFactHandle f2;
protected ObjectMatches matches0;
protected ObjectMatches matches1;
protected ObjectMatches matches2;
protected ReteTuple tuple0;
protected ReteTuple tuple1;
protected ReteTuple tuple2;
public BaseBetaRightMemoryTestClass() {
this.memory = null;
this.child = new MockBetaRightMemory();
}
protected void setUp() throws Exception {
super.setUp();
this.workingMemory = new ReteooWorkingMemory( new ReteooRuleBase() );
this.obj0 = new DummyValueObject( true,
"string1",
10,
"object1" );
this.obj1 = new DummyValueObject( true,
"string2",
20,
"object2" );
this.obj2 = new DummyValueObject( true,
null,
20,
null );
this.factory = new ReteooFactHandleFactory();
this.f0 = (DefaultFactHandle) this.factory.newFactHandle( this.obj0 );
this.f1 = (DefaultFactHandle) this.factory.newFactHandle( this.obj1 );
this.f2 = (DefaultFactHandle) this.factory.newFactHandle( this.obj2 );
this.matches0 = new ObjectMatches( this.f0 );
this.matches1 = new ObjectMatches( this.f1 );
this.matches2 = new ObjectMatches( this.f2 );
this.tuple0 = new ReteTuple( this.f0 );
this.tuple1 = new ReteTuple( this.f1 );
this.tuple2 = new ReteTuple( this.f2 );
}
protected void tearDown() throws Exception {
super.tearDown();
}
/*
* Test method for 'org.drools.reteoo.beta.DefaultRightMemory.add(WorkingMemory, ObjectMatches)'
*/
public void testAddWorkingMemoryObjectMatches() {
this.memory.add( this.workingMemory,
this.matches0 );
Assert.assertEquals( "Memory should have size 1",
1,
this.memory.size() );
this.memory.add( this.workingMemory,
this.matches1 );
Assert.assertEquals( "Memory should have size 2",
2,
this.memory.size() );
this.memory.add( this.workingMemory,
this.matches2 );
Assert.assertEquals( "Memory should have size 3",
3,
this.memory.size() );
}
/*
* Test method for 'org.drools.reteoo.beta.DefaultRightMemory.remove(WorkingMemory, ObjectMatches)'
*/
public void testRemoveWorkingMemoryObjectMatches() {
this.memory.add( this.workingMemory,
this.matches0 );
this.memory.add( this.workingMemory,
this.matches1 );
this.memory.add( this.workingMemory,
this.matches2 );
Assert.assertEquals( "Memory should have size 3",
3,
this.memory.size() );
this.memory.remove( this.workingMemory,
this.matches0 );
Assert.assertEquals( "Memory should have size 2",
2,
this.memory.size() );
this.memory.remove( this.workingMemory,
this.matches2 );
Assert.assertEquals( "Memory should have size 1",
1,
this.memory.size() );
this.memory.remove( this.workingMemory,
this.matches1 );
Assert.assertEquals( "Memory should have size 0",
0,
this.memory.size() );
}
/*
* Test method for 'org.drools.reteoo.beta.DefaultRightMemory.add(WorkingMemory, MultiLinkedListNodeWrapper)'
*/
public void testAddWorkingMemoryMultiLinkedListNodeWrapper() {
final MultiLinkedListNodeWrapper wrapper0 = new MultiLinkedListNodeWrapper( this.matches0 );
final MultiLinkedListNodeWrapper wrapper1 = new MultiLinkedListNodeWrapper( this.matches1 );
final MultiLinkedListNodeWrapper wrapper2 = new MultiLinkedListNodeWrapper( this.matches2 );
this.memory.add( this.workingMemory,
wrapper0 );
Assert.assertEquals( "Memory should have size 1",
1,
this.memory.size() );
this.memory.add( this.workingMemory,
wrapper2 );
Assert.assertEquals( "Memory should have size 2",
2,
this.memory.size() );
this.memory.add( this.workingMemory,
wrapper1 );
Assert.assertEquals( "Memory should have size 3",
3,
this.memory.size() );
}
/*
* Test method for 'org.drools.reteoo.beta.DefaultRightMemory.remove(WorkingMemory, MultiLinkedListNodeWrapper)'
*/
public void testRemoveWorkingMemoryMultiLinkedListNodeWrapper() {
final MultiLinkedListNodeWrapper wrapper0 = new MultiLinkedListNodeWrapper( this.matches0 );
final MultiLinkedListNodeWrapper wrapper1 = new MultiLinkedListNodeWrapper( this.matches1 );
final MultiLinkedListNodeWrapper wrapper2 = new MultiLinkedListNodeWrapper( this.matches2 );
this.memory.add( this.workingMemory,
wrapper0 );
this.memory.add( this.workingMemory,
wrapper1 );
this.memory.add( this.workingMemory,
wrapper2 );
Assert.assertEquals( "Memory should have size 3",
3,
this.memory.size() );
this.memory.remove( this.workingMemory,
wrapper1 );
Assert.assertEquals( "Memory should have size 2",
2,
this.memory.size() );
this.memory.remove( this.workingMemory,
wrapper2 );
Assert.assertEquals( "Memory should have size 1",
1,
this.memory.size() );
this.memory.remove( this.workingMemory,
wrapper0 );
Assert.assertEquals( "Memory should have size 0",
0,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -