Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 1.3.0
    • Fix Version/s: None
    • Component/s: TestControl
    • Labels:
      None

      Description

      Currently test control mock feature is not supported on proxies (e.g: beans with interceptors), a sample test which fails because of this limitation can be found here: https://github.com/rmpestano/ee6-ds-demo/blob/master/src/test/java/org/os890/demo/ee6/test/MockTest.java
      .

        Activity

        Hide
        gpetracek Gerhard Petracek added a comment -

        we need to remove the check for intercepted beans (in DefaultMockFilter) and try to use/provide our new proxy-generation facility. maybe we can just provide it manually (e.g. users have to create the proxy-class in the test and pass that generated class to the "mock-instance-factory" of the used mocking framework). in that case we need to test if at least some mocking-frameworks are compatible with that approach.

        Show
        gpetracek Gerhard Petracek added a comment - we need to remove the check for intercepted beans (in DefaultMockFilter) and try to use/provide our new proxy-generation facility. maybe we can just provide it manually (e.g. users have to create the proxy-class in the test and pass that generated class to the "mock-instance-factory" of the used mocking framework). in that case we need to test if at least some mocking-frameworks are compatible with that approach.
        Hide
        tandraschko Thomas Andraschko added a comment -

        I need more input if i should fix/introduce something here.
        Never used our TestControl and i'm not sure whats wrong currently.

        Show
        tandraschko Thomas Andraschko added a comment - I need more input if i should fix/introduce something here. Never used our TestControl and i'm not sure whats wrong currently.
        Hide
        gpetracek Gerhard Petracek added a comment -

        ApplicationMockManager and DynamicMockManager allow to register instances which should get used instead of the instance created by the cdi-container.
        with that you can use mocks as cdi-beans. however, if you have an intercepted bean and you provide a mocked instance instead, the interceptors won't work (because the cdi-container just returns the mocked instance as it was created e.g. by a mocking framework).

        -> we could try to provide a new method e.g. ApplicationMockManager#createProxiedClass

        -> users would need code like:

        @RunWith(CdiTestRunner.class)
        public class MockBeanTest {
          @Inject
          private DynamicMockManager mockManager;
        
          @Inject
          private UserRepository userRepository; //will inject the mocked instance
        
          @Test
          public void shouldMockTest() {
            Class proxiedClassToMock = mockManager.createProxiedClass(UserRepository.class);
            UserRepository mockedUserRepository = mock(proxiedClassToMock);
            //...
            mockManager.addMock(mockedUserRepository);
            //...
          }
        }
        
        Show
        gpetracek Gerhard Petracek added a comment - ApplicationMockManager and DynamicMockManager allow to register instances which should get used instead of the instance created by the cdi-container. with that you can use mocks as cdi-beans. however, if you have an intercepted bean and you provide a mocked instance instead, the interceptors won't work (because the cdi-container just returns the mocked instance as it was created e.g. by a mocking framework). -> we could try to provide a new method e.g. ApplicationMockManager#createProxiedClass -> users would need code like: @RunWith(CdiTestRunner.class) public class MockBeanTest { @Inject private DynamicMockManager mockManager; @Inject private UserRepository userRepository; //will inject the mocked instance @Test public void shouldMockTest() { Class proxiedClassToMock = mockManager.createProxiedClass(UserRepository.class); UserRepository mockedUserRepository = mock(proxiedClassToMock); //... mockManager.addMock(mockedUserRepository); //... } }

          People

          • Assignee:
            tandraschko Thomas Andraschko
            Reporter:
            rmpestano Rafael
          • Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:

              Development