pctxRef.setJndiName(pctxRef.getPersistenceContextRefName() + "Original");
pctxRefs.add(pctxRef);
originalEnv.setPersistenceContextRefs(pctxRefs);
PersistenceUnitReferencesMetaData pUnitRefs = new PersistenceUnitReferencesMetaData();
PersistenceUnitReferenceMetaData pUnitRef = new PersistenceUnitReferenceMetaData();
pUnitRef.setPersistenceUnitRefName("pUnitRef1");
pUnitRef.setJndiName(pUnitRef.getPersistenceUnitRefName() + "Original");
pUnitRefs.add(pUnitRef);
pUnitRef = new PersistenceUnitReferenceMetaData();
pUnitRef.setPersistenceUnitRefName("pUnitRef2");
pUnitRef.setJndiName(pUnitRef.getPersistenceUnitRefName() + "Original");
pUnitRefs.add(pUnitRef);
originalEnv.setPersistenceUnitRefs(pUnitRefs);
LifecycleCallbacksMetaData callbacks = new LifecycleCallbacksMetaData();
LifecycleCallbackMetaData callback = new LifecycleCallbackMetaData();
callback.setClassName("class1");
callback.setMethodName("postCtor1Original");
callbacks.add(callback);
callback = new LifecycleCallbackMetaData();
callback.setClassName("class2");
callback.setMethodName("postCtor2Original");
callbacks.add(callback);
originalEnv.setPostConstructs(callbacks);
callbacks = new LifecycleCallbacksMetaData();
callback = new LifecycleCallbackMetaData();
callback.setClassName("class1");
callback.setMethodName("preDestroy1Original");
callbacks.add(callback);
callback = new LifecycleCallbackMetaData();
callback.setClassName("class2");
callback.setMethodName("preDestroy2Original");
callbacks.add(callback);
originalEnv.setPreDestroys(callbacks);
ResourceEnvironmentReferencesMetaData resEnvRefs = new ResourceEnvironmentReferencesMetaData();
ResourceEnvironmentReferenceMetaData resEnvRef = new ResourceEnvironmentReferenceMetaData();
resEnvRef.setResourceEnvRefName("resEnvRef1");
resEnvRef.setJndiName(resEnvRef.getResourceEnvRefName() + "Original");
resEnvRefs.add(resEnvRef);
resEnvRef = new ResourceEnvironmentReferenceMetaData();
resEnvRef.setResourceEnvRefName("resEnvRef2");
resEnvRef.setJndiName(resEnvRef.getResourceEnvRefName() + "Original");
resEnvRefs.add(resEnvRef);
originalEnv.setResourceEnvironmentReferences(resEnvRefs);
ResourceReferencesMetaData resRefs = new ResourceReferencesMetaData();
ResourceReferenceMetaData resRef = new ResourceReferenceMetaData();
resRef.setResourceRefName("resRef1");
resRef.setJndiName(resRef.getResourceRefName() + "Original");
resRefs.add(resRef);
resRef = new ResourceReferenceMetaData();
resRef.setResourceRefName("resRef2");
resRef.setJndiName(resRef.getResourceRefName() + "Original");
resRefs.add(resRef);
originalEnv.setResourceReferences(resRefs);
JBossServiceReferencesMetaData serviceRefs = new JBossServiceReferencesMetaData();
JBossServiceReferenceMetaData serviceRef = new JBossServiceReferenceMetaData();
serviceRef.setServiceRefName("serviceRef1");
serviceRef.setJndiName(serviceRef.getServiceRefName() + "Original");
serviceRefs.add(serviceRef);
serviceRef = new JBossServiceReferenceMetaData();
serviceRef.setServiceRefName("serviceRef2");
serviceRef.setJndiName(serviceRef.getServiceRefName() + "Original");
serviceRefs.add(serviceRef);
originalEnv.setServiceReferences(serviceRefs);
// override
JBossSessionBeanMetaData override = new JBossSessionBeanMetaData();
override.setEjbName("session");
JBossEnvironmentRefsGroupMetaData overrideEnv = new JBossEnvironmentRefsGroupMetaData();
override.setJndiEnvironmentRefsGroup(overrideEnv);
overrideEnv.setAnnotatedEjbReferences(new AnnotatedEJBReferencesMetaData());
localRefs = new EJBLocalReferencesMetaData();
localRef = new EJBLocalReferenceMetaData();
localRef.setEjbRefName("localRef2");
localRef.setJndiName(localRef.getEjbRefName() + "Override");
localRefs.add(localRef);
overrideEnv.setEjbLocalReferences(localRefs);
ejbRefs = new EJBReferencesMetaData();
ejbRef = new EJBReferenceMetaData();
ejbRef.setEjbRefName("ejbRef2");
ejbRef.setJndiName(ejbRef.getEjbRefName() + "Override");
ejbRefs.add(ejbRef);
overrideEnv.setEjbReferences(ejbRefs);
envEntries = new EnvironmentEntriesMetaData();
envEntry = new EnvironmentEntryMetaData();
envEntry.setEnvEntryName("entry2");
envEntry.setJndiName(envEntry.getEnvEntryName() + "Override");
envEntries.add(envEntry);
envEntry = new EnvironmentEntryMetaData();
envEntry.setEnvEntryName("entry3");
envEntry.setJndiName(envEntry.getEnvEntryName() + "Override");
envEntries.add(envEntry);
overrideEnv.setEnvironmentEntries(envEntries);
destRefs = new MessageDestinationReferencesMetaData();
destRef = new MessageDestinationReferenceMetaData();
destRef.setMessageDestinationRefName("destRef2");
destRef.setJndiName(destRef.getMessageDestinationRefName() + "Override");
destRefs.add(destRef);
overrideEnv.setMessageDestinationReferences(destRefs);
pctxRefs = new PersistenceContextReferencesMetaData();
pctxRef = new PersistenceContextReferenceMetaData();
pctxRef.setPersistenceContextRefName("pctxRef2");
pctxRef.setJndiName(pctxRef.getPersistenceContextRefName() + "Override");
pctxRefs.add(pctxRef);
pctxRef = new PersistenceContextReferenceMetaData();
pctxRef.setPersistenceContextRefName("pctxRef3");
pctxRef.setJndiName(pctxRef.getPersistenceContextRefName() + "Override");
pctxRefs.add(pctxRef);
overrideEnv.setPersistenceContextRefs(pctxRefs);
pUnitRefs = new PersistenceUnitReferencesMetaData();
pUnitRef = new PersistenceUnitReferenceMetaData();
pUnitRef.setPersistenceUnitRefName("pUnitRef2");
pUnitRef.setJndiName(pUnitRef.getPersistenceUnitRefName() + "Override");
pUnitRefs.add(pUnitRef);
pUnitRef = new PersistenceUnitReferenceMetaData();
pUnitRef.setPersistenceUnitRefName("pUnitRef3");
pUnitRef.setJndiName(pUnitRef.getPersistenceUnitRefName() + "Override");
pUnitRefs.add(pUnitRef);
overrideEnv.setPersistenceUnitRefs(pUnitRefs);
callbacks = new LifecycleCallbacksMetaData();
callback = new LifecycleCallbackMetaData();
callback.setClassName("class2");
callback.setMethodName("postCtor2Override");
callbacks.add(callback);
callback = new LifecycleCallbackMetaData();
callback.setClassName("class3");
callback.setMethodName("postCtor3Override");
callbacks.add(callback);
overrideEnv.setPostConstructs(callbacks);
callbacks = new LifecycleCallbacksMetaData();
callback = new LifecycleCallbackMetaData();
callback.setClassName("class2");
callback.setMethodName("preDestroy2Override");
callbacks.add(callback);
callback = new LifecycleCallbackMetaData();
callback.setClassName("class3");
callback.setMethodName("preDestroy3Override");
callbacks.add(callback);
overrideEnv.setPreDestroys(callbacks);
resEnvRefs = new ResourceEnvironmentReferencesMetaData();
resEnvRef = new ResourceEnvironmentReferenceMetaData();
resEnvRef.setResourceEnvRefName("resEnvRef2");
resEnvRef.setJndiName(resEnvRef.getResourceEnvRefName() + "Override");
resEnvRefs.add(resEnvRef);
resEnvRef = new ResourceEnvironmentReferenceMetaData();
resEnvRef.setResourceEnvRefName("resEnvRef3");
resEnvRef.setJndiName(resEnvRef.getResourceEnvRefName() + "Override");
resEnvRefs.add(resEnvRef);
overrideEnv.setResourceEnvironmentReferences(resEnvRefs);
resRefs = new ResourceReferencesMetaData();
resRef = new ResourceReferenceMetaData();
resRef.setResourceRefName("resRef2");
resRef.setJndiName(resRef.getResourceRefName() + "Override");
resRefs.add(resRef);
overrideEnv.setResourceReferences(resRefs);
serviceRefs = new JBossServiceReferencesMetaData();
serviceRef = new JBossServiceReferenceMetaData();
serviceRef.setServiceRefName("serviceRef2");
serviceRef.setJndiName(serviceRef.getServiceRefName() + "Override");
serviceRefs.add(serviceRef);
serviceRef = new JBossServiceReferenceMetaData();
serviceRef.setServiceRefName("serviceRef3");
serviceRef.setJndiName(serviceRef.getServiceRefName() + "Override");
serviceRefs.add(serviceRef);
overrideEnv.setServiceReferences(serviceRefs);
// merged
JBossSessionBeanMetaData merged = new JBossSessionBeanMetaData();
JBossEnterpriseBeansMetaData mergedBeans = new JBossEnterpriseBeansMetaData();
mergedBeans.setEjbJarMetaData(new JBoss50MetaData());
merged.setEnterpriseBeansMetaData(mergedBeans);
merged.merge(override, original);
JBossEnvironmentRefsGroupMetaData mergedEnv = (JBossEnvironmentRefsGroupMetaData) merged.getJndiEnvironmentRefsGroup();
assertNotNull(mergedEnv);
// Simple in here
assertNotNull(merged.getAnnotatedEjbReferences());
// local refs
localRefs = mergedEnv.getEjbLocalReferences();
assertNotNull(localRefs);
assertEquals(2, localRefs.size());
localRef = localRefs.get("localRef1");
assertNotNull(localRef);
assertEquals(localRef.getEjbRefName() + "Original", localRef.getJndiName());
localRef = localRefs.get("localRef2");
assertNotNull(localRef);
assertEquals(localRef.getEjbRefName() + "Override", localRef.getJndiName());
ejbRefs = mergedEnv.getEjbReferences();
assertNotNull(ejbRefs);
assertEquals(2, ejbRefs.size());
ejbRef = ejbRefs.get("ejbRef1");
assertNotNull(ejbRef);
assertEquals(ejbRef.getEjbRefName() + "Original", ejbRef.getJndiName());
ejbRef = ejbRefs.get("ejbRef2");
assertNotNull(ejbRef);
assertEquals(ejbRef.getEjbRefName() + "Override", ejbRef.getJndiName());
envEntries = mergedEnv.getEnvironmentEntries();
assertNotNull(envEntries);
assertEquals(3, envEntries.size());
envEntry = envEntries.get("entry1");
assertNotNull(envEntry);
assertEquals(envEntry.getEnvEntryName() + "Original", envEntry.getJndiName());
envEntry = envEntries.get("entry2");
assertNotNull(envEntry);
assertEquals(envEntry.getEnvEntryName() + "Override", envEntry.getJndiName());
envEntry = envEntries.get("entry3");
assertNotNull(envEntry);
assertEquals(envEntry.getEnvEntryName() + "Override", envEntry.getJndiName());
destRefs = mergedEnv.getMessageDestinationReferences();
assertNotNull(destRefs);
assertEquals(2, destRefs.size());
destRef = destRefs.get("destRef1");
assertNotNull(destRef);
assertEquals(destRef.getMessageDestinationRefName() + "Original", destRef.getJndiName());
destRef = destRefs.get("destRef2");
assertNotNull(destRef);
assertEquals(destRef.getMessageDestinationRefName() + "Override", destRef.getJndiName());
pctxRefs = mergedEnv.getPersistenceContextRefs();
assertNotNull(pctxRefs);
assertEquals(3, pctxRefs.size());
pctxRef = pctxRefs.get("pctxRef1");
assertNotNull(pctxRef);
assertEquals(pctxRef.getPersistenceContextRefName() + "Original", pctxRef.getJndiName());
pctxRef = pctxRefs.get("pctxRef2");
assertNotNull(pctxRef);
assertEquals(pctxRef.getPersistenceContextRefName() + "Override", pctxRef.getJndiName());
pctxRef = pctxRefs.get("pctxRef3");
assertNotNull(pctxRef);
assertEquals(pctxRef.getPersistenceContextRefName() + "Override", pctxRef.getJndiName());
pUnitRefs = mergedEnv.getPersistenceUnitRefs();
assertNotNull(pUnitRefs);
assertEquals(3, pUnitRefs.size());
pUnitRef = pUnitRefs.get("pUnitRef1");
assertNotNull(pUnitRef);
assertEquals(pUnitRef.getPersistenceUnitRefName() + "Original", pUnitRef.getJndiName());
pUnitRef = pUnitRefs.get("pUnitRef2");
assertNotNull(pUnitRef);
assertEquals(pUnitRef.getPersistenceUnitRefName() + "Override", pUnitRef.getJndiName());
pUnitRef = pUnitRefs.get("pUnitRef3");
assertNotNull(pUnitRef);
assertEquals(pUnitRef.getPersistenceUnitRefName() + "Override", pUnitRef.getJndiName());
callbacks = mergedEnv.getPostConstructs();
assertNotNull(callbacks);
assertEquals(4, callbacks.size());