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.persistence.jdbc.annotations;
20:
21: import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
22: import org.apache.openjpa.jdbc.meta.ClassMapping;
23: import org.apache.openjpa.jdbc.meta.MappingRepository;
24: import org.apache.openjpa.jdbc.meta.strats.NoneDiscriminatorStrategy;
25: import org.apache.openjpa.jdbc.meta.strats.SubclassJoinDiscriminatorStrategy;
26: import org.apache.openjpa.jdbc.meta.strats.ValueMapDiscriminatorStrategy;
27: import org.apache.openjpa.jdbc.sql.JoinSyntaxes;
28: import org.apache.openjpa.persistence.test.SingleEMFTestCase;
29:
30: /**
31: * <p>Test discriminator mappings.</p>
32: *
33: * @author Abe White
34: */
35: public class TestDiscriminator extends SingleEMFTestCase {
36:
37: public void setUp() throws Exception {
38: super .setUp(AnnoTest1.class, AnnoTest2.class, Flat1.class,
39: CLEAR_TABLES);
40: // Commented out since OpenJPA does not have Entity1 and Entity2.
41: // These tests should be ported to use classes that are available
42: // in OpenJPA.
43: // setUp(Entity1.class, Entity2.class, AnnoTest1.class, CLEAR_TABLES);
44: }
45:
46: // public void testNoDefaultJoinedDiscriminatorWithoutColumn() {
47: // JDBCConfiguration conf = (JDBCConfiguration) emf.getConfiguration();
48: // ClassMapping cls = conf.getMappingRepositoryInstance().
49: // getMapping(Entity1.class, null, true);
50: // if (conf.getDBDictionaryInstance().joinSyntax
51: // != JoinSyntaxes.SYNTAX_TRADITIONAL) {
52: // assertTrue(cls.getDiscriminator().getStrategy()
53: // instanceof SubclassJoinDiscriminatorStrategy);
54: // } else {
55: // assertEquals(NoneDiscriminatorStrategy.getInstance(),
56: // cls.getDiscriminator().getStrategy());
57: // }
58: // assertEquals(0, cls.getDiscriminator().getColumns().length);
59: // }
60:
61: public void testJoinedDiscriminatorWithColumn() {
62: JDBCConfiguration conf = (JDBCConfiguration) emf
63: .getConfiguration();
64: MappingRepository repo = conf.getMappingRepositoryInstance();
65: ClassMapping cls = repo.getMapping(AnnoTest1.class, null, true);
66: assertTrue(cls.getDiscriminator().getStrategy() instanceof ValueMapDiscriminatorStrategy);
67: assertEquals(1, cls.getDiscriminator().getColumns().length);
68: assertEquals("ANNOCLS", cls.getDiscriminator().getColumns()[0]
69: .getName());
70: }
71:
72: // public void testDefaultFlatDiscriminator() {
73: // ClassMapping cls = ((JDBCConfiguration) emf.getConfiguration()).
74: // getMappingRepositoryInstance().getMapping(Entity2.class,
75: // null, true);
76: // assertTrue(cls.getDiscriminator().getStrategy()
77: // instanceof ValueMapDiscriminatorStrategy);
78: // assertEquals(1, cls.getDiscriminator().getColumns().length);
79: // }
80: }
|