01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.openjpa.conf;
20:
21: import org.apache.openjpa.conf.CacheMarshaller.ValidationPolicy;
22: import org.apache.openjpa.persistence.test.SingleEMFTestCase;
23:
24: public class TestCacheMarshaller extends SingleEMFTestCase {
25:
26: private CacheMarshaller cm;
27:
28: public void setUp() {
29: setUp(new Object[] {
30: "openjpa.CacheMarshallers",
31: "default(Id="
32: + getClass().getName()
33: + ", ValidationPolicy="
34: + OpenJPAVersionAndConfigurationTypeValidationPolicy.class
35: .getName() + ", InputURL=file:target/"
36: + getClass().getName() + ".ser"
37: + ", OutputFile=target/" + getClass().getName()
38: + ".ser)" });
39: emf.createEntityManager().close();
40: cm = CacheMarshallersValue.getMarshallerById(emf
41: .getConfiguration(), getClass().getName());
42: }
43:
44: public void testCacheMarshallerType() {
45: assertEquals(CacheMarshallerImpl.class, cm.getClass());
46: }
47:
48: public void testConfiguration() {
49: assertEquals(getClass().getName(), cm.getId());
50: }
51:
52: public void testValidation() {
53: ValidationPolicy vp = ((CacheMarshallerImpl) cm)
54: .getValidationPolicy();
55: assertEquals(
56: OpenJPAVersionAndConfigurationTypeValidationPolicy.class,
57: vp.getClass());
58: Object[] cached = (Object[]) vp.getCacheableData(this );
59:
60: assertEquals(3, cached.length);
61: assertEquals(OpenJPAVersion.VERSION_ID, cached[0]);
62: assertEquals(emf.getConfiguration().getClass().getName(),
63: cached[1]);
64: assertEquals(this , cached[2]);
65:
66: assertEquals(this , vp.getValidData(cached));
67: }
68:
69: public void testRoundTrip() {
70: Object o = "foo";
71: cm.store(o);
72: assertEquals(o, cm.load());
73: }
74: }
|