JBossEnvironmentRefsGroupMetaData originalEnv = new JBossEnvironmentRefsGroupMetaData();
original.setJndiEnvironmentRefsGroup(originalEnv);
originalEnv.setAnnotatedEjbReferences(new AnnotatedEJBReferencesMetaData());
EJBLocalReferencesMetaData localRefs = new EJBLocalReferencesMetaData();
EJBLocalReferenceMetaData localRef = new EJBLocalReferenceMetaData();
localRef.setEjbRefName("localRef1");
localRef.setJndiName(localRef.getEjbRefName() + "Original");
localRefs.add(localRef);
localRef = new EJBLocalReferenceMetaData();
localRef.setEjbRefName("localRef2");
localRef.setJndiName(localRef.getEjbRefName() + "Original");
localRefs.add(localRef);
originalEnv.setEjbLocalReferences(localRefs);
EJBReferencesMetaData ejbRefs = new EJBReferencesMetaData();
EJBReferenceMetaData ejbRef = new EJBReferenceMetaData();
ejbRef.setEjbRefName("ejbRef1");
ejbRef.setJndiName(ejbRef.getEjbRefName() + "Original");
ejbRefs.add(ejbRef);
ejbRef = new EJBReferenceMetaData();
ejbRef.setEjbRefName("ejbRef2");
ejbRef.setJndiName(ejbRef.getEjbRefName() + "Original");
ejbRefs.add(ejbRef);
originalEnv.setEjbReferences(ejbRefs);
EnvironmentEntriesMetaData envEntries = new EnvironmentEntriesMetaData();
EnvironmentEntryMetaData envEntry = new EnvironmentEntryMetaData();
envEntry.setEnvEntryName("entry1");
envEntry.setJndiName(envEntry.getEnvEntryName() + "Original");
envEntries.add(envEntry);
envEntry = new EnvironmentEntryMetaData();
envEntry.setEnvEntryName("entry2");
envEntry.setJndiName(envEntry.getEnvEntryName() + "Original");
envEntries.add(envEntry);
originalEnv.setEnvironmentEntries(envEntries);
MessageDestinationReferencesMetaData destRefs = new MessageDestinationReferencesMetaData();
MessageDestinationReferenceMetaData destRef = new MessageDestinationReferenceMetaData();
destRef.setMessageDestinationRefName("destRef1");
destRef.setJndiName(destRef.getMessageDestinationRefName() + "Original");
destRefs.add(destRef);
destRef = new MessageDestinationReferenceMetaData();
destRef.setMessageDestinationRefName("destRef2");
destRef.setJndiName(destRef.getMessageDestinationRefName() + "Original");
destRefs.add(destRef);
originalEnv.setMessageDestinationReferences(destRefs);
PersistenceContextReferencesMetaData pctxRefs = new PersistenceContextReferencesMetaData();
PersistenceContextReferenceMetaData pctxRef = new PersistenceContextReferenceMetaData();
pctxRef.setPersistenceContextRefName("pctxRef1");
pctxRef.setJndiName(pctxRef.getPersistenceContextRefName() + "Original");
pctxRefs.add(pctxRef);
pctxRef = new PersistenceContextReferenceMetaData();
pctxRef.setPersistenceContextRefName("pctxRef2");
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");