Line 0
Link Here
|
|
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 1998, 2008 Oracle. All rights reserved. |
3 |
* This program and the accompanying materials are made available under the |
4 |
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 |
5 |
* which accompanies this distribution. |
6 |
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html |
7 |
* and the Eclipse Distribution License is available at |
8 |
* http://www.eclipse.org/org/documents/edl-v10.php. |
9 |
* |
10 |
* Contributors: |
11 |
* Oracle - initial API and implementation from Oracle TopLink |
12 |
******************************************************************************/ |
13 |
package org.eclipse.persistence.testing.tests.jpa.structconverter; |
14 |
|
15 |
import javax.persistence.EntityManager; |
16 |
|
17 |
import junit.extensions.TestSetup; |
18 |
import junit.framework.Test; |
19 |
import junit.framework.TestSuite; |
20 |
import oracle.spatial.geometry.JGeometry; |
21 |
|
22 |
import org.eclipse.persistence.platform.database.converters.StructConverter; |
23 |
|
24 |
import org.eclipse.persistence.testing.framework.junit.JUnitTestCase; |
25 |
import org.eclipse.persistence.testing.models.jpa.structconverter.SimpleSpatial; |
26 |
import org.eclipse.persistence.testing.models.jpa.structconverter.SimpleXMLSpatial; |
27 |
import org.eclipse.persistence.testing.models.jpa.structconverter.JGeometryTableCreator; |
28 |
import org.eclipse.persistence.testing.models.jpa.structconverter.DummyStructConverterType; |
29 |
|
30 |
/** |
31 |
* TestSuite to ensure Annotation-based struct converters get properly added to the project |
32 |
* |
33 |
* This test suite ensures the project is properly set-up and does a sanity test using one of the |
34 |
* converters. Other tests are handled by the StructConverter tests suites in the TestBrowser. |
35 |
* @author tware |
36 |
* |
37 |
*/ |
38 |
public class StructConverterServerTestSuite extends JUnitTestCase { |
39 |
|
40 |
public static final String STRUCT_CONVERTER_PU = "structConverter"; |
41 |
|
42 |
public StructConverterServerTestSuite(){ |
43 |
} |
44 |
|
45 |
public StructConverterServerTestSuite(String name){ |
46 |
super(name); |
47 |
} |
48 |
|
49 |
public static Test suite() { |
50 |
TestSuite suite = new TestSuite(); |
51 |
suite.setName("Struct Converter Test Suite"); |
52 |
suite.addTest(new StructConverterServerTestSuite("testSetup")); |
53 |
suite.addTest(new StructConverterServerTestSuite("testPlatform")); |
54 |
suite.addTest(new StructConverterServerTestSuite("testSimpleSpatialWrite")); |
55 |
return suite; |
56 |
} |
57 |
|
58 |
public void testSetup() { |
59 |
clearCache(); |
60 |
new JGeometryTableCreator().replaceTables(JUnitTestCase.getServerSession(STRUCT_CONVERTER_PU)); |
61 |
} |
62 |
|
63 |
/** |
64 |
* Ensure the DatabasePlatform is setup with the proper StructConverters |
65 |
*/ |
66 |
public void testPlatform(){ |
67 |
EntityManager em = createEntityManager(STRUCT_CONVERTER_PU); |
68 |
try{ |
69 |
// trigger deploy |
70 |
em.find(SimpleSpatial.class, new Long(1)); |
71 |
} catch (Exception e){}; |
72 |
|
73 |
StructConverter converter = getServerSession(STRUCT_CONVERTER_PU).getPlatform().getTypeConverters().get(JGeometry.class); |
74 |
assertNotNull("Platform does not have correct JGeometryConverter.", converter); |
75 |
assertTrue("JGeometery struct converter is wrong type.", converter.getClass().getName().indexOf("JGeometryConverter") >= 0); |
76 |
|
77 |
converter = getServerSession(STRUCT_CONVERTER_PU).getPlatform().getTypeConverters().get(DummyStructConverterType.class); |
78 |
assertNotNull("Platform does not have correct DummyStructConverter.", converter); |
79 |
assertTrue("JGeometery struct converter is wrong type.", converter.getClass().getName().indexOf("DummyStructConverter") >= 0); |
80 |
} |
81 |
|
82 |
/** |
83 |
* Sanity test to ensure a read and a write with a Converter specified by |
84 |
* annotations work properly |
85 |
*/ |
86 |
public void testSimpleSpatialWrite(){ |
87 |
EntityManager em = createEntityManager(STRUCT_CONVERTER_PU); |
88 |
|
89 |
beginTransaction(em); |
90 |
SimpleSpatial simpleSpatial = new SimpleSpatial(1000, pointCluster1()); |
91 |
em.persist(simpleSpatial); |
92 |
em.flush(); |
93 |
|
94 |
em.clear(); |
95 |
|
96 |
simpleSpatial = em.find(SimpleSpatial.class, new Long(1000)); |
97 |
|
98 |
assertNotNull("JGeometry was not properly read in.", simpleSpatial.getJGeometry()); |
99 |
rollbackTransaction(em); |
100 |
} |
101 |
|
102 |
/** |
103 |
* mdsys.sdo_geometry(5, |
104 |
* NULL, null, |
105 |
* mdsys.sdo_elem_info_array(1,1,3), |
106 |
* mdsys.sdo_ordinate_array(1.1, 1.1, 2.2, 2.2, 3.3, 4.4))); |
107 |
*/ |
108 |
public JGeometry pointCluster1() { |
109 |
Object[] points = |
110 |
new Object[] { new double[] { 1.1, 1.1 }, new double[] { 2.2, 2.2 }, |
111 |
new double[] { 3.3, 4.4 } }; |
112 |
return JGeometry.createMultiPoint(points, 2, 0); |
113 |
} |
114 |
} |