1 package org.apache.archiva.redback.components.modello.jpox;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.codehaus.modello.ModelloParameterConstants;
23 import org.codehaus.modello.core.ModelloCore;
24 import org.codehaus.modello.model.Model;
25 import org.codehaus.plexus.util.ReaderFactory;
26 import org.dom4j.Document;
27 import org.dom4j.io.SAXReader;
28
29 import java.io.File;
30 import java.util.Properties;
31
32
33
34
35
36
37 public class JPoxJdoMappingModelloGeneratorTest
38 extends AbstractJpoxGeneratorTestCase
39 {
40 public JPoxJdoMappingModelloGeneratorTest()
41 {
42 super( "jpox-jdo-mapping" );
43 }
44
45 public void testSimpleInvocation()
46 throws Exception
47 {
48 ModelloCore core = (ModelloCore) lookup( ModelloCore.ROLE );
49
50 Model model =
51 core.loadModel( ReaderFactory.newXmlReader( getTestFile( "src/test/resources/mergere-tissue.mdo" ) ) );
52
53
54
55
56
57 Properties parameters = new Properties();
58
59 parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() );
60
61 parameters.setProperty( ModelloParameterConstants.VERSION, "1.0.0" );
62
63 parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.FALSE.toString() );
64
65 core.generate( model, "jpox-jdo-mapping", parameters );
66
67
68
69
70
71 assertTrue( new File( getOutputDirectory(), "package.jdo" ).exists() );
72
73
74
75 SAXReader reader = new SAXReader();
76 reader.setEntityResolver( new JdoEntityResolver() );
77 Document jdoDocument = reader.read( new File( getOutputDirectory() + "/package.jdo" ) );
78
79 assertNotNull( jdoDocument );
80
81
82 assertNoTextNodes( jdoDocument, "//jdo", true );
83
84 assertAttributeEquals( jdoDocument, "//class[@name='TissueModelloMetadata']/field[@name='modelVersion']/column",
85 "default-value", "1.0.0" );
86
87 assertAttributeEquals( jdoDocument, "//class[@name='Issue']/field[@name='summary']", "persistence-modifier",
88 "none" );
89
90
91
92
93
94 assertAttributeEquals( jdoDocument, "//class[@name='Issue']/field[@name='friends']/collection",
95 "dependent-element", "false" );
96
97
98 assertElementNotExists( jdoDocument, "//class[@name='Issue']/field[@name='assignee']/collection" );
99
100
101 assertElementExists( jdoDocument, "//class[@name='Issue']/field[@name='configuration']/map" );
102
103
104
105 assertAttributeMissing( jdoDocument, "//class[@name='Issue']/field[@name='reporter']", "default-fetch-group" );
106 assertAttributeEquals( jdoDocument, "//class[@name='Issue']/field[@name='configuration']",
107 "default-fetch-group", "true" );
108 assertAttributeEquals( jdoDocument, "//class[@name='Issue']/field[@name='assignee']", "default-fetch-group",
109 "false" );
110
111
112
113
114 assertAttributeEquals( jdoDocument, "//class[@name='ComplexIdentity']/field[@name='id']", "value-strategy",
115 "native" );
116 assertAttributeEquals( jdoDocument, "//class[@name='Issue']/field[@name='accountId']", "value-strategy",
117 "native" );
118
119 assertAttributeMissing( jdoDocument, "//class[@name='User']/field[@name='id']", "value-strategy" );
120
121
122
123 assertAttributeEquals( jdoDocument, "//class[@name='User']", "persistence-capable-superclass",
124 "org.mergere.user.AbstractUser" );
125
126
127
128 assertAttributeEquals( jdoDocument, "//class[@name='Issue']/field[@name='accountId']", "primary-key", "true" );
129 assertAttributeEquals( jdoDocument, "//class[@name='Issue']/field[@name='summary']", "primary-key", "false" );
130
131 assertAttributeEquals( jdoDocument, "//class[@name='ComplexIdentity']/field[@name='id']", "primary-key",
132 "true" );
133 assertAttributeEquals( jdoDocument, "//class[@name='ComplexIdentity']/field[@name='username']", "primary-key",
134 "false" );
135 assertAttributeEquals( jdoDocument, "//class[@name='ComplexIdentity']/field[@name='fullName']", "primary-key",
136 "false" );
137 assertAttributeEquals( jdoDocument, "//class[@name='ComplexIdentity']/field[@name='email']", "primary-key",
138 "false" );
139 assertAttributeEquals( jdoDocument, "//class[@name='ComplexIdentity']/field[@name='locked']", "primary-key",
140 "false" );
141 assertAttributeEquals( jdoDocument, "//class[@name='ComplexIdentity']/field[@name='lastLoginDate']",
142 "primary-key", "false" );
143
144
145
146 assertAttributeEquals( jdoDocument, "//class[@name='DifferentTable']", "table", "MyTable" );
147 assertAttributeEquals( jdoDocument, "//class[@name='Issue']/field[@name='accountId']/column", "name", "id" );
148 }
149 }