001: package org.drools.base.extractors;
002:
003: import junit.framework.Assert;
004: import junit.framework.TestCase;
005:
006: import org.drools.Address;
007: import org.drools.Person;
008: import org.drools.base.ClassFieldExtractorCache;
009: import org.drools.spi.Extractor;
010:
011: public class MVELClassFieldExtractorTest extends TestCase {
012:
013: Extractor extractor = ClassFieldExtractorCache.getExtractor(
014: Person.class, "addresses['home'].street", getClass()
015: .getClassLoader());
016: Person person = null;
017:
018: protected void setUp() throws Exception {
019: super .setUp();
020: person = new Person("bob", 30);
021: Address business = new Address("Business Street", "999", null);
022: Address home = new Address("Home Street", "555", "55555555");
023: person.getAddresses().put("business", business);
024: person.getAddresses().put("home", home);
025: }
026:
027: public void testGetBooleanValue() {
028: try {
029: this .extractor.getBooleanValue(null, this .person);
030: fail("Should have throw an exception");
031: } catch (final Exception e) {
032: // success
033: }
034: }
035:
036: public void testGetByteValue() {
037: try {
038: this .extractor.getByteValue(null, this .person);
039: fail("Should have throw an exception");
040: } catch (final Exception e) {
041: // success
042: }
043: }
044:
045: public void testGetCharValue() {
046: try {
047: this .extractor.getCharValue(null, this .person);
048: fail("Should have throw an exception");
049: } catch (final Exception e) {
050: // success
051: }
052: }
053:
054: public void testGetDoubleValue() {
055: try {
056: this .extractor.getDoubleValue(null, this .person);
057: fail("Should have throw an exception");
058: } catch (final Exception e) {
059: // success
060: }
061: }
062:
063: public void testGetFloatValue() {
064: try {
065: this .extractor.getFloatValue(null, this .person);
066: fail("Should have throw an exception");
067: } catch (final Exception e) {
068: // success
069: }
070: }
071:
072: public void testGetIntValue() {
073: try {
074: this .extractor.getIntValue(null, this .person);
075: fail("Should have throw an exception");
076: } catch (final Exception e) {
077: // success
078: }
079: }
080:
081: public void testGetLongValue() {
082: try {
083: this .extractor.getLongValue(null, this .person);
084: fail("Should have throw an exception");
085: } catch (final Exception e) {
086: // success
087: }
088: }
089:
090: public void testGetShortValue() {
091: try {
092: this .extractor.getShortValue(null, this .person);
093: fail("Should have throw an exception");
094: } catch (final Exception e) {
095: // success
096: }
097: }
098:
099: public void testGetValue() {
100: try {
101: Assert.assertEquals("Home Street", this .extractor.getValue(
102: null, this .person));
103: Assert.assertTrue(this .extractor
104: .getValue(null, this .person) instanceof String);
105: } catch (final Exception e) {
106: fail("Should not throw an exception");
107: }
108: }
109:
110: public void testIsNullValue() {
111: try {
112: Assert.assertFalse(this .extractor.isNullValue(null,
113: this .person));
114:
115: Extractor nullExtractor = ClassFieldExtractorCache
116: .getExtractor(Person.class,
117: "addresses['business'].phone", getClass()
118: .getClassLoader());
119: Assert.assertTrue(nullExtractor.isNullValue(null,
120: this .person));
121: } catch (final Exception e) {
122: fail("Should not throw an exception");
123: }
124: }
125:
126: }
|