001: /*
002: * Copyright 2004-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.compass.core.test.dynamic.jexl;
018:
019: import java.util.ArrayList;
020: import java.util.Calendar;
021:
022: import org.compass.core.CompassSession;
023: import org.compass.core.CompassTransaction;
024: import org.compass.core.Resource;
025: import org.compass.core.test.AbstractTestCase;
026:
027: /**
028: * @author kimchy
029: */
030: public class JexlDynamicTests extends AbstractTestCase {
031:
032: protected String[] getMappings() {
033: return new String[] { "dynamic/jexl/A.cpm.xml" };
034: }
035:
036: public void testSimpleExpression() throws Exception {
037: CompassSession session = openSession();
038: CompassTransaction tr = session.beginTransaction();
039:
040: A a = new A();
041: a.setId(new Long(1));
042: a.setValue("value");
043: a.setValue2("value2");
044: session.save("a1", a);
045:
046: Resource resource = session.loadResource("a1", new Long(1));
047: assertEquals("valuevalue2", resource.getValue("test"));
048:
049: tr.commit();
050: session.close();
051: }
052:
053: public void testExpressionWithFormat() throws Exception {
054: CompassSession session = openSession();
055: CompassTransaction tr = session.beginTransaction();
056:
057: A a = new A();
058: a.setId(new Long(1));
059: Calendar cal = Calendar.getInstance();
060: cal.set(1977, 4, 1);
061: a.setDate(cal.getTime());
062: session.save("a2", a);
063:
064: Resource resource = session.loadResource("a2", new Long(1));
065: assertEquals("1977", resource.getValue("test"));
066:
067: tr.commit();
068: session.close();
069: }
070:
071: public void testArrayRetVal() throws Exception {
072: CompassSession session = openSession();
073: CompassTransaction tr = session.beginTransaction();
074:
075: A a = new A();
076: a.setId(new Long(1));
077: a.setValuesArr(new String[] { "value1", "value2" });
078: session.save("a3", a);
079: Resource resource = session.loadResource("a3", new Long(1));
080: assertEquals(2, resource.getProperties("test").length);
081: assertEquals("value1", resource.getProperties("test")[0]
082: .getStringValue());
083: assertEquals("value2", resource.getProperties("test")[1]
084: .getStringValue());
085:
086: tr.commit();
087: session.close();
088: }
089:
090: public void testCollectionRetVal() throws Exception {
091: CompassSession session = openSession();
092: CompassTransaction tr = session.beginTransaction();
093:
094: A a = new A();
095: a.setId(new Long(1));
096: ArrayList values = new ArrayList();
097: values.add("value1");
098: values.add("value2");
099: a.setValuesCol(values);
100: session.save("a4", a);
101:
102: Resource resource = session.loadResource("a4", new Long(1));
103: assertEquals(2, resource.getProperties("test").length);
104: assertEquals("value1", resource.getProperties("test")[0]
105: .getStringValue());
106: assertEquals("value2", resource.getProperties("test")[1]
107: .getStringValue());
108:
109: tr.commit();
110: session.close();
111: }
112: }
|