01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.core.test.simple;
18:
19: import org.compass.core.CompassSession;
20: import org.compass.core.CompassTransaction;
21: import org.compass.core.Resource;
22: import org.compass.core.test.AbstractTestCase;
23:
24: /**
25: * @author kimchy
26: */
27: public class SimpleTests extends AbstractTestCase {
28:
29: protected String[] getMappings() {
30: return new String[] { "simple/A.cpm.xml" };
31: }
32:
33: public void testSimple() throws Exception {
34: CompassSession session = openSession();
35: CompassTransaction tr = session.beginTransaction();
36:
37: A a = new A();
38: a.setId(1);
39: a.setValue("value");
40: session.save(a);
41:
42: a = session.load(A.class, 1);
43: assertEquals("value", a.getValue());
44:
45: Resource resource = session.loadResource(A.class, 1);
46: assertEquals("value", resource.getValue("value"));
47: assertEquals("1", resource.getId());
48: assertEquals(1, resource.getIds().length);
49: assertEquals("1", resource.getIds()[0]);
50: assertEquals(1, resource.getIdProperties().length);
51: assertEquals("1", resource.getIdProperties()[0]
52: .getStringValue());
53: assertEquals("1", resource.getIdProperty().getStringValue());
54:
55: tr.commit();
56: session.close();
57: }
58:
59: public void testSimpleDelete() {
60: CompassSession session = openSession();
61: CompassTransaction tr = session.beginTransaction();
62: for (int i = 0; i < 30; i++) {
63: A a = new A();
64: a.setId(i);
65: a.setValue("value");
66: session.save(a);
67: }
68: tr.commit();
69: session.close();
70:
71: session = openSession();
72: tr = session.beginTransaction();
73: assertEquals(30, session.queryBuilder().matchAll().hits()
74: .length());
75: for (int i = 0; i < 30; i = i + 2) {
76: session.delete(A.class, new Long(i));
77: }
78: assertEquals(15, session.queryBuilder().matchAll().hits()
79: .length());
80: tr.commit();
81: session.close();
82: }
83: }
|