01: /*
02: * TestDynamicSchemaFactory.java
03: *
04: * Created on October 6, 2006, 1:34 PM
05: *
06: * To change this template, choose Tools | Template Manager
07: * and open the template in the editor.
08: */
09:
10: /*
11: * Licensed to the Apache Software Foundation (ASF) under one
12: * or more contributor license agreements. See the NOTICE file
13: * distributed with this work for additional information
14: * regarding copyright ownership. The ASF licenses this file
15: * to you under the Apache License, Version 2.0 (the
16: * "License"); you may not use this file except in compliance
17: * with the License. You may obtain a copy of the License at
18: *
19: * http://www.apache.org/licenses/LICENSE-2.0
20: *
21: * Unless required by applicable law or agreed to in writing,
22: * software distributed under the License is distributed on an
23: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
24: * KIND, either express or implied. See the License for the
25: * specific language governing permissions and limitations
26: * under the License.
27: */
28: package org.apache.openjpa.persistence.jdbc.schema;
29:
30: import java.sql.Types;
31: import java.util.*;
32: import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
33: import org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl;
34: import org.apache.openjpa.jdbc.meta.ClassMapping;
35: import org.apache.openjpa.jdbc.meta.Discriminator;
36: import org.apache.openjpa.jdbc.meta.MappingRepository;
37: import org.apache.openjpa.jdbc.meta.Version;
38: import org.apache.openjpa.jdbc.schema.DynamicSchemaFactory;
39: import org.apache.openjpa.jdbc.schema.Schemas;
40: import org.apache.openjpa.jdbc.schema.Table;
41:
42: import org.apache.openjpa.persistence.jdbc.common.apps.*;
43:
44: import java.lang.annotation.Annotation;
45: import junit.framework.*;
46: import javax.persistence.EntityManager;
47: import javax.persistence.EntityManagerFactory;
48: import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
49: import org.apache.openjpa.persistence.OpenJPAEntityManager;
50:
51: public class TestDynamicSchemaFactory extends
52: org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest {
53:
54: private ClassMapping _mapping = null;
55:
56: /** Creates a new instance of TestDynamicSchemaFactory */
57: public TestDynamicSchemaFactory() {
58: }
59:
60: public TestDynamicSchemaFactory(String test) {
61: super (test);
62: }
63:
64: public void setUp() throws Exception {
65: JDBCConfiguration conf = new JDBCConfigurationImpl();
66: conf.setSchemaFactory(DynamicSchemaFactory.class.getName());
67: MappingRepository repos = conf.newMappingRepositoryInstance();
68: _mapping = repos.getMapping(MappingTest1.class, null, true);
69: }
70:
71: public void testClassMapping() {
72: Table table = _mapping.getTable();
73: assertEquals("MAPPINGTEST1", table.getName().toUpperCase());
74: assertEquals(1, table.getPrimaryKey().getColumns().length);
75: int type = table.getPrimaryKey().getColumns()[0].getType();
76: assertEquals(Schemas.getJDBCName(type), Types.INTEGER, type);
77: }
78:
79: public void testIndicators() {
80: Version vers = _mapping.getVersion();
81: assertNotNull(vers);
82: assertEquals("MAPPINGTEST1", vers.getColumns()[0].getTable()
83: .getName().toUpperCase());
84: assertEquals(Types.INTEGER, vers.getColumns()[0].getType());
85:
86: Discriminator cls = _mapping.getDiscriminator();
87: assertNotNull(cls);
88: assertEquals("MAPPINGTEST1", cls.getColumns()[0].getTable()
89: .getName().toUpperCase());
90: assertEquals(Types.VARCHAR, cls.getColumns()[0].getType());
91: }
92:
93: public static void main(String[] args) {
94: // main(TestDynamicSchemaFactory.class);
95: }
96:
97: }
|