Yair Zaslavsky has uploaded a new change for review.

Change subject: core: Changes to MockEJBStrategyRule
......................................................................

core: Changes to MockEJBStrategyRule

The following patch introduces the following changes:
1. Gives the ability to allow to mock a managed resource, not just a bean
2. mockBean should actually use Mocikto to define the actual mock using 
when..thenReturn as
the "startingMethod" was not aware to that bean when it was called

Change-Id: Ia23cbe33abe5a080cd599c6af468e3ce728c190a
Signed-off-by: Yair Zaslavsky <[email protected]>
---
M 
backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/MockEJBStrategyRule.java
1 file changed, 24 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/86/12186/1

diff --git 
a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/MockEJBStrategyRule.java
 
b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/MockEJBStrategyRule.java
index 1aa8afa..eaf69e1 100644
--- 
a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/MockEJBStrategyRule.java
+++ 
b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/MockEJBStrategyRule.java
@@ -35,6 +35,7 @@
     private EJBUtilsStrategy origStrategy;
     private EJBUtilsStrategy mockStrategy;
     private Map<BeanType, Object> mockBeanMap;
+    private Map<ContainerManagedResourceType, Object> 
mockContainerManagedResourceMap;
 
     /** Create the rule with no mocking */
     public MockEJBStrategyRule() {
@@ -46,9 +47,21 @@
         this(new EnumMap<BeanType, Object>(Collections.singletonMap(type, 
bean)));
     }
 
+    /** Creates the rule with a mock of a single resource */
+    public MockEJBStrategyRule(ContainerManagedResourceType type, Object 
resource) {
+        this(new EnumMap<BeanType, Object>(BeanType.class), new 
EnumMap<ContainerManagedResourceType,Object>(Collections.singletonMap(type, 
resource)));
+
+    }
+
     /** Create the rule with with a mock of a several beans */
     public MockEJBStrategyRule(Map<BeanType, Object> beans) {
+        this(beans, new 
EnumMap<ContainerManagedResourceType,Object>(ContainerManagedResourceType.class));;
+    }
+
+    /** Create the rule with with a mock of a several beans and several 
resources */
+    public MockEJBStrategyRule(Map<BeanType, Object> beans, 
Map<ContainerManagedResourceType,Object> resources) {
         mockBeanMap = beans;
+        mockContainerManagedResourceMap = resources;
         origStrategy = EjbUtils.getStrategy();
         mockStrategy = mock(EJBUtilsStrategy.class);
         EjbUtils.setStrategy(mockStrategy);
@@ -58,12 +71,17 @@
         Transaction trans = mock(Transaction.class);
         TransactionManager tm = mock(TransactionManager.class);
         doReturn(trans).when(tm).getTransaction();
-        doReturn(tm).when(mockStrategy)
-                .<TransactionManager> 
findResource(ContainerManagedResourceType.TRANSACTION_MANAGER);
+        mockResource(ContainerManagedResourceType.TRANSACTION_MANAGER, tm);
     }
 
     public void mockBean(BeanType type, Object bean) {
         mockBeanMap.put(type, bean);
+        when(mockStrategy.findBean(eq(type), 
any(BeanProxyType.class))).thenReturn(bean);
+    }
+
+    public void mockResource(ContainerManagedResourceType type, Object 
resource) {
+        mockContainerManagedResourceMap.put(type, resource);
+        when(mockStrategy.findResource(eq(type))).thenReturn(resource);
     }
 
     @Override
@@ -73,6 +91,10 @@
             for (Map.Entry<BeanType, Object> mockBeanEntry : 
mockBeanMap.entrySet()) {
                 when(mockStrategy.findBean(eq(mockBeanEntry.getKey()), 
any(BeanProxyType.class))).thenReturn(mockBeanEntry.getValue());
             }
+
+            for (Map.Entry<ContainerManagedResourceType, Object> 
mockResourceEntry : mockContainerManagedResourceMap.entrySet()) {
+                
when(mockStrategy.findResource(eq(mockResourceEntry.getKey()))).thenReturn(mockResourceEntry.getValue());
+            }
         } catch (SystemException e) {
             Assert.fail("Unable to mock tranaction management");
         }


--
To view, visit http://gerrit.ovirt.org/12186
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia23cbe33abe5a080cd599c6af468e3ce728c190a
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Yair Zaslavsky <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to