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.metadata;
18:
19: import java.text.SimpleDateFormat;
20: import java.util.Date;
21:
22: import junit.framework.TestCase;
23: import org.compass.core.*;
24: import org.compass.core.config.CompassConfiguration;
25:
26: public class MetaDataTests extends TestCase {
27:
28: private Compass compass;
29:
30: protected void setUp() throws Exception {
31: super .setUp();
32: CompassConfiguration conf = new CompassConfiguration()
33: .configure("/org/compass/core/test/metadata/compass.cfg.xml");
34: compass = conf.buildCompass();
35: compass.getSearchEngineIndexManager().deleteIndex();
36: compass.getSearchEngineIndexManager().verifyIndex();
37: }
38:
39: protected void tearDown() throws Exception {
40: compass.close();
41: compass.getSearchEngineIndexManager().deleteIndex();
42: super .tearDown();
43: }
44:
45: public void testMD() {
46: CompassSession sess = compass.openSession();
47: CompassTransaction tr = sess.beginTransaction();
48:
49: Long id = new Long(1);
50: Date date = new Date();
51: A a = new A();
52: a.setId(id);
53: a.setValue("string value");
54: a.setDateValue(date);
55:
56: sess.save(a);
57:
58: Resource r = sess.loadResource(A.class, id);
59: assertEquals("TestAlias", r.getAlias());
60: Property p = r.getProperty("testMD1");
61: assertNotNull(p);
62: assertEquals("string value", p.getStringValue());
63: p = r.getProperty("TestMD2");
64: assertNotNull(p);
65: SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
66: assertEquals(sdf.format(date), p.getStringValue());
67: Property[] pArr = r.getProperties("TestMD3");
68: assertNotNull(pArr);
69: assertEquals(2, pArr.length);
70:
71: tr.commit();
72: }
73: }
|