use of org.easymock.EasyMockSupport in project Payara by payara.
the class TransactionScopedBeanTest method testAllMethods.
@Test
@SuppressWarnings("unchecked")
public void testAllMethods() {
LocalBean localBean = new LocalBean();
EasyMockSupport mockSupport = new EasyMockSupport();
Contextual<LocalBean> contextual = (Contextual<LocalBean>) mockSupport.createMock(Contextual.class);
CreationalContext<LocalBean> creationalContext = (CreationalContext<LocalBean>) mockSupport.createMock(CreationalContext.class);
TransactionScopedContextImpl transactionScopedContext = mockSupport.createMock(TransactionScopedContextImpl.class);
transactionScopedContext.beansPerTransaction = new ConcurrentHashMap<>();
// test getContextualInstance
TransactionScopedBean<LocalBean> transactionScopedBean = getTransactionScopedBean(mockSupport, localBean, contextual, creationalContext, transactionScopedContext);
assertSame(localBean, transactionScopedBean.getContextualInstance());
// test afterCompletion
contextual.destroy(localBean, creationalContext);
mockSupport.replayAll();
transactionScopedBean.afterCompletion(0);
mockSupport.verifyAll();
mockSupport.resetAll();
}
use of org.easymock.EasyMockSupport in project Payara by payara.
the class TransactionScopedContextImplTest method beforeTest.
@Before
public void beforeTest() throws Exception {
mockSupport = new EasyMockSupport();
initialContext = mockSupport.createMock(InitialContext.class);
MyInitialContextFactory.setInitialContext(initialContext);
initialContextFactoryProperty = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
urlPkgPrefixes = System.getProperty(Context.URL_PKG_PREFIXES);
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, MyInitialContextFactory.class.getName());
System.setProperty(Context.URL_PKG_PREFIXES, MyInitialContext.class.getPackage().getName());
}
use of org.easymock.EasyMockSupport in project Payara by payara.
the class RootBeanDeploymentArchiveTest method testConstructor.
@Test
public void testConstructor() throws Exception {
String archiveName = "an";
String webInfLib1 = "WEB-INF/lib/lib1.jar";
String webInfLib2 = "WEB-INF/lib/lib2.jar";
String subArchive11Name = "sa1";
String subArchive12Name = "sa2";
URI webInfLib1URI = URI.create(webInfLib1);
URI webInfLib2URI = URI.create(webInfLib2);
ArrayList<String> lib1ClassNames = new ArrayList<>();
lib1ClassNames.add(Lib1Class1.class.getName() + ".class");
lib1ClassNames.add(Lib1Class2.class.getName() + ".class");
ArrayList<String> lib2ClassNames = new ArrayList<>();
lib2ClassNames.add(Lib2Class1.class.getName() + ".class");
lib2ClassNames.add(Lib2Class2.class.getName() + ".class");
WeldUtils.BDAType bdaType = WeldUtils.BDAType.WAR;
ArrayList<String> webInfLibEntries = new ArrayList<>();
webInfLibEntries.add(webInfLib1);
webInfLibEntries.add(webInfLib2);
EasyMockSupport mockSupport = new EasyMockSupport();
BeansXml beansXML = mockSupport.createMock(BeansXml.class);
WeldBootstrap wb = mockSupport.createMock(WeldBootstrap.class);
ReadableArchive readableArchive = mockSupport.createMock(ReadableArchive.class);
ReadableArchive subArchive1 = mockSupport.createMock(ReadableArchive.class);
ReadableArchive subArchive2 = mockSupport.createMock(ReadableArchive.class);
Collection<EjbDescriptor> ejbs = Collections.emptyList();
DeploymentContext deploymentContext = mockSupport.createMock(DeploymentContext.class);
expect(deploymentContext.getClassLoader()).andReturn(null).anyTimes();
expect(readableArchive.getName()).andReturn(archiveName).anyTimes();
expect(readableArchive.exists(WeldUtils.WEB_INF_BEANS_XML)).andReturn(true).anyTimes();
expect(readableArchive.exists(WeldUtils.WEB_INF_CLASSES_META_INF_BEANS_XML)).andReturn(false).anyTimes();
// in BeanDeploymentArchiveImpl.populate
expect(deploymentContext.getTransientAppMetadata()).andReturn(null).anyTimes();
expect(deploymentContext.getModuleMetaData(Application.class)).andReturn(null).anyTimes();
expect(deploymentContext.getTransientAppMetaData(WeldDeployer.WELD_BOOTSTRAP, WeldBootstrap.class)).andReturn(wb).anyTimes();
expect(wb.parse(anyObject(URL.class))).andReturn(beansXML).anyTimes();
expect(readableArchive.getURI()).andReturn(URI.create("an.war")).anyTimes();
expect(subArchive1.getURI()).andReturn(webInfLib1URI).anyTimes();
expect(subArchive2.getURI()).andReturn(webInfLib2URI).anyTimes();
expect(beansXML.getBeanDiscoveryMode()).andReturn(BeanDiscoveryMode.ALL).anyTimes();
expect(readableArchive.entries()).andReturn(Collections.<String>emptyEnumeration());
readableArchive.close();
expect(readableArchive.exists(WeldUtils.WEB_INF_LIB)).andReturn(true).anyTimes();
expect(readableArchive.entries(WeldUtils.WEB_INF_LIB)).andReturn(Collections.enumeration(webInfLibEntries));
expect(readableArchive.getSubArchive(webInfLib1)).andReturn(subArchive1);
expect(subArchive1.exists(WeldUtils.META_INF_BEANS_XML)).andReturn(true);
expect(readableArchive.getSubArchive(webInfLib2)).andReturn(subArchive2);
expect(subArchive2.exists(WeldUtils.META_INF_BEANS_XML)).andReturn(true);
// build new BeanDeploymentArchiveImpl for lib1 and lib2
setupMocksForWebInfLibBda(subArchive1, subArchive11Name, lib1ClassNames);
setupMocksForWebInfLibBda(subArchive2, subArchive12Name, lib2ClassNames);
readableArchive.close();
mockSupport.replayAll();
RootBeanDeploymentArchive rootBeanDeploymentArchive = new RootBeanDeploymentArchive(readableArchive, ejbs, deploymentContext);
assertEquals("root_" + archiveName, rootBeanDeploymentArchive.getId());
assertEquals(WeldUtils.BDAType.UNKNOWN, rootBeanDeploymentArchive.getBDAType());
assertEquals(0, rootBeanDeploymentArchive.getBeanClasses().size());
assertEquals(0, rootBeanDeploymentArchive.getBeanClassObjects().size());
assertNull(rootBeanDeploymentArchive.getBeansXml());
BeanDeploymentArchiveImpl moduleBda = (BeanDeploymentArchiveImpl) rootBeanDeploymentArchive.getModuleBda();
assertNotNull(moduleBda);
assertEquals(WeldUtils.BDAType.WAR, moduleBda.getBDAType());
assertEquals(3, rootBeanDeploymentArchive.getBeanDeploymentArchives().size());
assertTrue(rootBeanDeploymentArchive.getBeanDeploymentArchives().contains(moduleBda));
assertEquals(3, moduleBda.getBeanDeploymentArchives().size());
assertTrue(moduleBda.getBeanDeploymentArchives().contains(rootBeanDeploymentArchive));
assertEquals(0, rootBeanDeploymentArchive.getModuleBeanClasses().size());
assertEquals(0, rootBeanDeploymentArchive.getModuleBeanClassObjects().size());
assertSame(rootBeanDeploymentArchive.getModuleClassLoaderForBDA(), moduleBda.getModuleClassLoaderForBDA());
mockSupport.verifyAll();
mockSupport.resetAll();
}
use of org.easymock.EasyMockSupport in project easymock by easymock.
the class MockBuilderTest method testWithMockSupportNamed.
@Test
public void testWithMockSupportNamed() {
EasyMockSupport support = new EasyMockSupport();
MockBuilderTest a = support.createMockBuilder(MockBuilderTest.class).addMockedMethods("myMethod", "toString").createMock("foo", MockType.NICE);
expect(a.myMethod(2)).andReturn(1);
support.replayAll();
assertEquals(1, a.myMethod(2));
assertEquals(0, a.myMethod(3));
support.verifyAll();
assertEquals("foo", a.toString());
}
use of org.easymock.EasyMockSupport in project Payara by payara.
the class TransactionScopedContextExtensionTest method testafterBeanDiscovery.
@Test
@SuppressWarnings("unchecked")
public void testafterBeanDiscovery() {
EasyMockSupport mockSupport = new EasyMockSupport();
AfterBeanDiscovery event = mockSupport.createMock(AfterBeanDiscovery.class);
BeanManager beanManager = mockSupport.createMock(BeanManager.class);
AnnotatedType<TransactionScopedCDIEventHelperImpl> annotatedType = (AnnotatedType<TransactionScopedCDIEventHelperImpl>) mockSupport.createMock(AnnotatedType.class);
InjectionTargetFactory injectionTargetFactory = mockSupport.createMock(InjectionTargetFactory.class);
InjectionTarget injectionTarget = mockSupport.createMock(InjectionTarget.class);
event.addContext(isA(TransactionScopedContextImpl.class));
expect(beanManager.createAnnotatedType(TransactionScopedCDIEventHelperImpl.class)).andReturn(annotatedType);
expect(beanManager.getInjectionTargetFactory(annotatedType)).andReturn(injectionTargetFactory);
expect(injectionTargetFactory.createInjectionTarget(anyObject(Bean.class))).andReturn(injectionTarget);
event.addBean(anyObject(Bean.class));
mockSupport.replayAll();
TransactionScopedContextExtension transactionScopedContextExtension = new TransactionScopedContextExtension();
transactionScopedContextExtension.afterBeanDiscovery(event, beanManager);
mockSupport.verifyAll();
mockSupport.resetAll();
}
Aggregations