|
Lines 103-108
Link Here
|
| 103 |
suite.setName("AdvancedJPAJunitTest"); |
103 |
suite.setName("AdvancedJPAJunitTest"); |
| 104 |
|
104 |
|
| 105 |
suite.addTest(new AdvancedJPAJunitTest("testSetup")); |
105 |
suite.addTest(new AdvancedJPAJunitTest("testSetup")); |
|
|
106 |
// This test runs only on a JEE6 / JPA 2.0 capable server |
| 106 |
suite.addTest(new AdvancedJPAJunitTest("testMetamodelMinimalSanityTest")); |
107 |
suite.addTest(new AdvancedJPAJunitTest("testMetamodelMinimalSanityTest")); |
| 107 |
suite.addTest(new AdvancedJPAJunitTest("testExistenceCheckingSetting")); |
108 |
suite.addTest(new AdvancedJPAJunitTest("testExistenceCheckingSetting")); |
| 108 |
|
109 |
|
|
Lines 181-274
Link Here
|
| 181 |
* This test performs minimal sanity testing on the advanced JPA model |
182 |
* This test performs minimal sanity testing on the advanced JPA model |
| 182 |
* in order to verify metamodel creation.<p> |
183 |
* in order to verify metamodel creation.<p> |
| 183 |
* See the metamodel test package suite for full regression tests. |
184 |
* See the metamodel test package suite for full regression tests. |
|
|
185 |
* See SVN rev# 5124 |
| 186 |
* http://fisheye2.atlassian.com/changelog/~author=mobrien/eclipselink/?cs=5124 |
| 184 |
*/ |
187 |
*/ |
| 185 |
public void testMetamodelMinimalSanityTest() { |
188 |
public void testMetamodelMinimalSanityTest() { |
| 186 |
EntityManager em = createEntityManager("default1"); |
189 |
// Run test only when the JPA 2.0 specification is enabled on the server, or we are in SE mode with JPA 2.0 capability |
| 187 |
// pre-clear metamodel to enable test reentry (SE only - not EE) |
190 |
if(!this.isJPA10()) { |
| 188 |
if(!this.isOnServer()) { |
191 |
EntityManager em = createEntityManager("default1"); |
| 189 |
((EntityManagerFactoryImpl)((EntityManagerImpl)em).getEntityManagerFactory()).setMetamodel(null); |
192 |
// pre-clear metamodel to enable test reentry (SE only - not EE) |
| 190 |
} |
193 |
if(!this.isOnServer()) { |
| 191 |
Metamodel metamodel = em.getMetamodel(); |
194 |
((EntityManagerFactoryImpl)((EntityManagerImpl)em).getEntityManagerFactory()).setMetamodel(null); |
| 192 |
// get declared attributes |
195 |
} |
| 193 |
EntityType<LargeProject> entityLargeProject = metamodel.entity(LargeProject.class); |
196 |
Metamodel metamodel = em.getMetamodel(); |
| 194 |
Set<Attribute<LargeProject, ?>> declaredAttributes = entityLargeProject.getDeclaredAttributes(); |
197 |
// get declared attributes |
| 195 |
assertTrue(declaredAttributes.size() > 0); // instead of a assertEquals(1, size) for future compatibility with changes to Buyer |
198 |
EntityType<LargeProject> entityLargeProject = metamodel.entity(LargeProject.class); |
|
|
199 |
Set<Attribute<LargeProject, ?>> declaredAttributes = entityLargeProject.getDeclaredAttributes(); |
| 200 |
assertTrue(declaredAttributes.size() > 0); // instead of a assertEquals(1, size) for future compatibility with changes to Buyer |
| 196 |
|
201 |
|
| 197 |
// check that getDeclaredAttribute and getDeclaredAttributes return the same attribute |
202 |
// check that getDeclaredAttribute and getDeclaredAttributes return the same attribute |
| 198 |
Attribute<LargeProject, ?> budgetAttribute = entityLargeProject.getDeclaredAttribute("budget"); |
203 |
Attribute<LargeProject, ?> budgetAttribute = entityLargeProject.getDeclaredAttribute("budget"); |
| 199 |
assertNotNull(budgetAttribute); |
204 |
assertNotNull(budgetAttribute); |
| 200 |
Attribute<LargeProject, ?> budgetSingularAttribute = entityLargeProject.getDeclaredSingularAttribute("budget"); |
205 |
Attribute<LargeProject, ?> budgetSingularAttribute = entityLargeProject.getDeclaredSingularAttribute("budget"); |
| 201 |
assertNotNull(budgetSingularAttribute); |
206 |
assertNotNull(budgetSingularAttribute); |
| 202 |
assertEquals(budgetSingularAttribute, budgetAttribute); |
207 |
assertEquals(budgetSingularAttribute, budgetAttribute); |
| 203 |
assertTrue(declaredAttributes.contains(budgetSingularAttribute)); |
208 |
assertTrue(declaredAttributes.contains(budgetSingularAttribute)); |
| 204 |
// check the type |
209 |
// check the type |
| 205 |
Class budgetClass = budgetSingularAttribute.getJavaType(); |
210 |
Class budgetClass = budgetSingularAttribute.getJavaType(); |
| 206 |
// Verify whether we expect a boxed class or not |
211 |
// Verify whether we expect a boxed class or not |
| 207 |
assertEquals(double.class, budgetClass); |
212 |
assertEquals(double.class, budgetClass); |
| 208 |
//assertEquals(Double.class, budgetClass); |
213 |
//assertEquals(Double.class, budgetClass); |
| 209 |
|
214 |
|
| 210 |
// Test LargeProject.budget.buyingDays |
215 |
// Test LargeProject.budget.buyingDays |
| 211 |
|
216 |
|
| 212 |
// Check an EnumSet on an Entity |
217 |
// Check an EnumSet on an Entity |
| 213 |
EntityType<Buyer> entityBuyer = metamodel.entity(Buyer.class); |
218 |
EntityType<Buyer> entityBuyer = metamodel.entity(Buyer.class); |
| 214 |
// public enum Weekdays { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY } |
219 |
// public enum Weekdays { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY } |
| 215 |
// private EnumSet<Weekdays> buyingDays; |
220 |
// private EnumSet<Weekdays> buyingDays; |
| 216 |
assertNotNull(entityBuyer); |
221 |
assertNotNull(entityBuyer); |
| 217 |
// check persistence type |
222 |
// check persistence type |
| 218 |
assertEquals(PersistenceType.ENTITY, entityBuyer.getPersistenceType()); |
223 |
assertEquals(PersistenceType.ENTITY, entityBuyer.getPersistenceType()); |
| 219 |
assertEquals(Buyer.class, entityBuyer.getJavaType()); |
224 |
assertEquals(Buyer.class, entityBuyer.getJavaType()); |
| 220 |
// verify EnumSet is a SingularAttribute |
225 |
// verify EnumSet is a SingularAttribute |
| 221 |
Attribute buyingDaysAttribute = entityBuyer.getAttribute("buyingDays"); |
226 |
Attribute buyingDaysAttribute = entityBuyer.getAttribute("buyingDays"); |
| 222 |
assertNotNull(buyingDaysAttribute); |
227 |
assertNotNull(buyingDaysAttribute); |
| 223 |
// Check persistent attribute type |
228 |
// Check persistent attribute type |
| 224 |
assertEquals(PersistentAttributeType.BASIC, buyingDaysAttribute.getPersistentAttributeType()); |
229 |
assertEquals(PersistentAttributeType.BASIC, buyingDaysAttribute.getPersistentAttributeType()); |
| 225 |
// Non-spec check on the attribute impl type |
230 |
// Non-spec check on the attribute impl type |
| 226 |
// EnumSet is not a Set in the Metamodel - it is a treated as a BasicType single object (SingularAttributeType) |
231 |
// EnumSet is not a Set in the Metamodel - it is a treated as a BasicType single object (SingularAttributeType) |
| 227 |
// BasicTypeImpl@8980685:EnumSet [ javaType: class java.util.EnumSet] |
232 |
// BasicTypeImpl@8980685:EnumSet [ javaType: class java.util.EnumSet] |
| 228 |
assertFalse(((SingularAttributeImpl)buyingDaysAttribute).isPlural()); |
233 |
assertFalse(((SingularAttributeImpl)buyingDaysAttribute).isPlural()); |
| 229 |
BindableType buyingDaysElementBindableType = ((SingularAttributeImpl)buyingDaysAttribute).getBindableType(); |
234 |
BindableType buyingDaysElementBindableType = ((SingularAttributeImpl)buyingDaysAttribute).getBindableType(); |
| 230 |
assertEquals(BindableType.SINGULAR_ATTRIBUTE, buyingDaysElementBindableType); |
235 |
assertEquals(BindableType.SINGULAR_ATTRIBUTE, buyingDaysElementBindableType); |
| 231 |
SingularAttribute<? super Buyer, EnumSet> buyingDaysSingularAttribute = entityBuyer.getSingularAttribute("buyingDays", EnumSet.class); |
236 |
SingularAttribute<? super Buyer, EnumSet> buyingDaysSingularAttribute = entityBuyer.getSingularAttribute("buyingDays", EnumSet.class); |
| 232 |
assertNotNull(buyingDaysSingularAttribute); |
237 |
assertNotNull(buyingDaysSingularAttribute); |
| 233 |
assertFalse(buyingDaysSingularAttribute.isCollection()); |
238 |
assertFalse(buyingDaysSingularAttribute.isCollection()); |
| 234 |
|
239 |
/* |
| 235 |
// Not yet implemented |
240 |
// In mid-implementation in Design Issue 74 |
| 236 |
/* // Check for Id that exists |
241 |
// http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_74:_20090909:_Implement_IdentifiableType.hasSingleIdAttribute.28.29 |
| 237 |
boolean expectedIAExceptionThrown = false; |
242 |
// Check for Id that exists |
| 238 |
boolean hasSingleIdAttribute = false; |
243 |
boolean expectedIAExceptionThrown = false; |
| 239 |
try { |
244 |
boolean hasSingleIdAttribute = false; |
| 240 |
hasSingleIdAttribute = entityBuyer.hasSingleIdAttribute(); |
245 |
try { |
| 241 |
} catch (IllegalArgumentException iae) { |
246 |
hasSingleIdAttribute = entityBuyer.hasSingleIdAttribute(); |
| 242 |
//iae.printStackTrace(); |
247 |
} catch (IllegalArgumentException iae) { |
| 243 |
expectedIAExceptionThrown = true; |
248 |
//iae.printStackTrace(); |
| 244 |
} |
249 |
expectedIAExceptionThrown = true; |
| 245 |
assertFalse(expectedIAExceptionThrown); |
250 |
} |
| 246 |
assertTrue(hasSingleIdAttribute); |
251 |
assertFalse(expectedIAExceptionThrown); |
|
|
252 |
assertTrue(hasSingleIdAttribute); |
| 247 |
*/ |
253 |
*/ |
|
|
254 |
// In mid implementation in Design Issue 83 |
| 255 |
/* // Verify that the BasicMap Buyer.creditCards is picked up properly |
| 256 |
//* @param <X> The type the represented Map belongs to |
| 257 |
//* @param <K> The type of the key of the represented Map |
| 258 |
//* @param <V> The type of the value of the represented Map |
| 259 |
//public class MapAttributeImpl<X, K, V> extends PluralAttributeImpl<X, java.util.Map<K, V>, V> |
| 260 |
Attribute buyerCreditCards = entityBuyer.getAttribute("creditCards"); |
| 261 |
assertNotNull(buyerCreditCards); |
| 262 |
assertTrue(buyerCreditCards.isCollection()); |
| 263 |
assertTrue(buyerCreditCards instanceof MapAttributeImpl); |
| 264 |
MapAttribute<? super Buyer, ?, ?> buyerCreditCardsMap = entityBuyer.getMap("creditCards"); |
| 248 |
|
265 |
|
| 249 |
// Fixing elementType in parallel transaction for Design Issue 83 |
266 |
// Verify owning type |
| 250 |
// http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_83:_20090914:_MapAttributeImpl.elementType_incorrectly_set_when_.40ObjectTypeConverter_is_present |
267 |
assertNotNull(buyerCreditCardsMap); |
| 251 |
/* // Verify that the BasicMap Buyer.creditCards is picked up properly |
268 |
assertEquals(entityBuyer, buyerCreditCardsMap.getDeclaringType()); |
| 252 |
//* @param <X> The type the represented Map belongs to |
|
|
| 253 |
//* @param <K> The type of the key of the represented Map |
| 254 |
//* @param <V> The type of the value of the represented Map |
| 255 |
//public class MapAttributeImpl<X, K, V> extends PluralAttributeImpl<X, java.util.Map<K, V>, V> |
| 256 |
Attribute buyerCreditCards = entityBuyer.getAttribute("creditCards"); |
| 257 |
assertNotNull(buyerCreditCards); |
| 258 |
assertTrue(buyerCreditCards.isCollection()); |
| 259 |
assertTrue(buyerCreditCards instanceof MapAttributeImpl); |
| 260 |
MapAttribute<? super Buyer, ?, ?> buyerCreditCardsMap = entityBuyer.getMap("creditCards"); |
| 261 |
|
269 |
|
| 262 |
// Verify owning type |
270 |
// Verify Map Key |
| 263 |
assertNotNull(buyerCreditCardsMap); |
271 |
assertEquals(String.class, buyerCreditCardsMap.getKeyJavaType()); |
| 264 |
assertEquals(entityBuyer, buyerCreditCardsMap.getDeclaringType()); |
|
|
| 265 |
|
272 |
|
| 266 |
// Verify Map Key |
273 |
// Verify Map Value |
| 267 |
assertEquals(String.class, buyerCreditCardsMap.getKeyJavaType()); |
274 |
assertEquals(Long.class, buyerCreditCardsMap.getElementType().getJavaType()); |
| 268 |
|
|
|
| 269 |
// Verify Map Value |
| 270 |
assertEquals(Long.class, buyerCreditCardsMap.getElementType().getJavaType()); |
| 271 |
*/ |
275 |
*/ |
|
|
276 |
} |
| 272 |
} |
277 |
} |
| 273 |
|
278 |
|
| 274 |
/** |
279 |
/** |