You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by Rajani Karuturi <Ra...@citrix.com> on 2014/03/27 10:50:36 UTC
spring unittests
Hi All,
I am trying to write unit tests for ApiAsyncJobDispatcher. This is how I defined by Test class @ server/test/com/cloud/api
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:/testContext.xml")
public class ApiAsyncJobDispatcherTest {
@Mock
private ApiDispatcher _dispatcher;
@Mock
private AsyncJobManager _asyncJobMgr;
@Mock
private EntityManager _entityMgr;
@InjectMocks
private ApiAsyncJobDispatcher apiAsyncJobDispatcher = new ApiAsyncJobDispatcher();
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
ComponentContext.initComponentsLifeCycle();
}
@Test
public void testRunJob() throws Exception {
AsyncJob asyncJob = new AsyncJobVO("", User.UID_SYSTEM, 1, DetachVolumeCmdByAdmin.class.getCanonicalName(), null, null, null);
apiAsyncJobDispatcher.runJob(asyncJob);
}
}
I am getting failed to load ApplicationContext error. The exact error message is
java.lang.ClassNotFoundException: org.apache.cloudstack.framework.eventbus.EventBusBase
I think, that class is moved to org.apache.cloudstack.framework.events.EventBus. Once I make that change in the application context file, I am getting
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.cloud.user.AccountService] is defined: expected single matching bean but found 4: mockAccountManagerImpl,accountService,accountManager,acctMgr
Am I miss something?
I did go through https://cwiki.apache.org/confluence/display/CLOUDSTACK/Unit+Testing+with+JUnit+and+Spring But, didn’t understand Note: #4 of it.
~Rajani
Re: spring unittests
Posted by Rajani Karuturi <Ra...@citrix.com>.
I think its not with the context file. The problem is with class level bean definitions using annotations once the component scan is turned on.
I will try injecting a custom context. Thanks Laszlo.
~Rajani
On 01-Apr-2014, at 12:35 am, Laszlo Hornyak <la...@gmail.com> wrote:
> Hi Rajani,
>
> I had a short investigation into the problem and that test context is quite
> exciting. (which means I would need a lot more time to find all the
> details) For a short solution I would recommend you to write another rather
> than trying to reuse.
>
>
>
> On Sat, Mar 29, 2014 at 11:30 AM, Rajani Karuturi <
> Rajani.Karuturi@citrix.com> wrote:
>
>> any help?
>>
>>
>> ~Rajani
>>
>>
>>
>> On 28-Mar-2014, at 9:48 am, Rajani Karuturi <Ra...@citrix.com>
>> wrote:
>>
>>> Its the testContext.xml we have at server/test/resouces
>>>
>>> As the async job dispatcher also comes under server/, i used the same
>> test context file.
>>>
>>> ~Rajani
>>>
>>>
>>>
>>> On 28-Mar-2014, at 1:23 am, Laszlo Hornyak <la...@gmail.com>
>> wrote:
>>>
>>>> Hi Rajani,
>>>>
>>>> Can you share your spring context file?
>>>>
>>>>
>>>> On Thu, Mar 27, 2014 at 10:50 AM, Rajani Karuturi <
>>>> Rajani.Karuturi@citrix.com> wrote:
>>>>
>>>>> Hi All,
>>>>>
>>>>> I am trying to write unit tests for ApiAsyncJobDispatcher. This is how
>> I
>>>>> defined by Test class @ server/test/com/cloud/api
>>>>>
>>>>> @RunWith(SpringJUnit4ClassRunner.class)
>>>>> @ContextConfiguration(locations = "classpath:/testContext.xml")
>>>>> public class ApiAsyncJobDispatcherTest {
>>>>> @Mock
>>>>> private ApiDispatcher _dispatcher;
>>>>>
>>>>> @Mock
>>>>> private AsyncJobManager _asyncJobMgr;
>>>>>
>>>>> @Mock
>>>>> private EntityManager _entityMgr;
>>>>>
>>>>> @InjectMocks
>>>>> private ApiAsyncJobDispatcher apiAsyncJobDispatcher = new
>>>>> ApiAsyncJobDispatcher();
>>>>>
>>>>> @Before
>>>>> public void setUp() throws Exception {
>>>>> MockitoAnnotations.initMocks(this);
>>>>> ComponentContext.initComponentsLifeCycle();
>>>>> }
>>>>>
>>>>> @Test
>>>>> public void testRunJob() throws Exception {
>>>>> AsyncJob asyncJob = new AsyncJobVO("", User.UID_SYSTEM, 1,
>>>>> DetachVolumeCmdByAdmin.class.getCanonicalName(), null, null, null);
>>>>> apiAsyncJobDispatcher.runJob(asyncJob);
>>>>> }
>>>>> }
>>>>>
>>>>>
>>>>> I am getting failed to load ApplicationContext error. The exact error
>>>>> message is
>>>>> java.lang.ClassNotFoundException:
>>>>> org.apache.cloudstack.framework.eventbus.EventBusBase
>>>>>
>>>>> I think, that class is moved to
>>>>> org.apache.cloudstack.framework.events.EventBus. Once I make that
>> change in
>>>>> the application context file, I am getting
>>>>> Caused by:
>>>>> org.springframework.beans.factory.NoUniqueBeanDefinitionException: No
>>>>> qualifying bean of type [com.cloud.user.AccountService] is defined:
>>>>> expected single matching bean but found 4:
>>>>> mockAccountManagerImpl,accountService,accountManager,acctMgr
>>>>>
>>>>>
>>>>> Am I miss something?
>>>>>
>>>>> I did go through
>>>>>
>> https://cwiki.apache.org/confluence/display/CLOUDSTACK/Unit+Testing+with+JUnit+and+SpringBut,
>> didn't understand Note: #4 of it.
>>>>>
>>>>>
>>>>> ~Rajani
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> EOF
>>>
>>
>>
>
>
> --
>
> EOF
Re: spring unittests
Posted by Laszlo Hornyak <la...@gmail.com>.
Hi Rajani,
I had a short investigation into the problem and that test context is quite
exciting. (which means I would need a lot more time to find all the
details) For a short solution I would recommend you to write another rather
than trying to reuse.
On Sat, Mar 29, 2014 at 11:30 AM, Rajani Karuturi <
Rajani.Karuturi@citrix.com> wrote:
> any help?
>
>
> ~Rajani
>
>
>
> On 28-Mar-2014, at 9:48 am, Rajani Karuturi <Ra...@citrix.com>
> wrote:
>
> > Its the testContext.xml we have at server/test/resouces
> >
> > As the async job dispatcher also comes under server/, i used the same
> test context file.
> >
> > ~Rajani
> >
> >
> >
> > On 28-Mar-2014, at 1:23 am, Laszlo Hornyak <la...@gmail.com>
> wrote:
> >
> >> Hi Rajani,
> >>
> >> Can you share your spring context file?
> >>
> >>
> >> On Thu, Mar 27, 2014 at 10:50 AM, Rajani Karuturi <
> >> Rajani.Karuturi@citrix.com> wrote:
> >>
> >>> Hi All,
> >>>
> >>> I am trying to write unit tests for ApiAsyncJobDispatcher. This is how
> I
> >>> defined by Test class @ server/test/com/cloud/api
> >>>
> >>> @RunWith(SpringJUnit4ClassRunner.class)
> >>> @ContextConfiguration(locations = "classpath:/testContext.xml")
> >>> public class ApiAsyncJobDispatcherTest {
> >>> @Mock
> >>> private ApiDispatcher _dispatcher;
> >>>
> >>> @Mock
> >>> private AsyncJobManager _asyncJobMgr;
> >>>
> >>> @Mock
> >>> private EntityManager _entityMgr;
> >>>
> >>> @InjectMocks
> >>> private ApiAsyncJobDispatcher apiAsyncJobDispatcher = new
> >>> ApiAsyncJobDispatcher();
> >>>
> >>> @Before
> >>> public void setUp() throws Exception {
> >>> MockitoAnnotations.initMocks(this);
> >>> ComponentContext.initComponentsLifeCycle();
> >>> }
> >>>
> >>> @Test
> >>> public void testRunJob() throws Exception {
> >>> AsyncJob asyncJob = new AsyncJobVO("", User.UID_SYSTEM, 1,
> >>> DetachVolumeCmdByAdmin.class.getCanonicalName(), null, null, null);
> >>> apiAsyncJobDispatcher.runJob(asyncJob);
> >>> }
> >>> }
> >>>
> >>>
> >>> I am getting failed to load ApplicationContext error. The exact error
> >>> message is
> >>> java.lang.ClassNotFoundException:
> >>> org.apache.cloudstack.framework.eventbus.EventBusBase
> >>>
> >>> I think, that class is moved to
> >>> org.apache.cloudstack.framework.events.EventBus. Once I make that
> change in
> >>> the application context file, I am getting
> >>> Caused by:
> >>> org.springframework.beans.factory.NoUniqueBeanDefinitionException: No
> >>> qualifying bean of type [com.cloud.user.AccountService] is defined:
> >>> expected single matching bean but found 4:
> >>> mockAccountManagerImpl,accountService,accountManager,acctMgr
> >>>
> >>>
> >>> Am I miss something?
> >>>
> >>> I did go through
> >>>
> https://cwiki.apache.org/confluence/display/CLOUDSTACK/Unit+Testing+with+JUnit+and+SpringBut,
> didn't understand Note: #4 of it.
> >>>
> >>>
> >>> ~Rajani
> >>>
> >>>
> >>>
> >>>
> >>
> >>
> >> --
> >>
> >> EOF
> >
>
>
--
EOF
Re: spring unittests
Posted by Rajani Karuturi <Ra...@citrix.com>.
any help?
~Rajani
On 28-Mar-2014, at 9:48 am, Rajani Karuturi <Ra...@citrix.com> wrote:
> Its the testContext.xml we have at server/test/resouces
>
> As the async job dispatcher also comes under server/, i used the same test context file.
>
> ~Rajani
>
>
>
> On 28-Mar-2014, at 1:23 am, Laszlo Hornyak <la...@gmail.com> wrote:
>
>> Hi Rajani,
>>
>> Can you share your spring context file?
>>
>>
>> On Thu, Mar 27, 2014 at 10:50 AM, Rajani Karuturi <
>> Rajani.Karuturi@citrix.com> wrote:
>>
>>> Hi All,
>>>
>>> I am trying to write unit tests for ApiAsyncJobDispatcher. This is how I
>>> defined by Test class @ server/test/com/cloud/api
>>>
>>> @RunWith(SpringJUnit4ClassRunner.class)
>>> @ContextConfiguration(locations = "classpath:/testContext.xml")
>>> public class ApiAsyncJobDispatcherTest {
>>> @Mock
>>> private ApiDispatcher _dispatcher;
>>>
>>> @Mock
>>> private AsyncJobManager _asyncJobMgr;
>>>
>>> @Mock
>>> private EntityManager _entityMgr;
>>>
>>> @InjectMocks
>>> private ApiAsyncJobDispatcher apiAsyncJobDispatcher = new
>>> ApiAsyncJobDispatcher();
>>>
>>> @Before
>>> public void setUp() throws Exception {
>>> MockitoAnnotations.initMocks(this);
>>> ComponentContext.initComponentsLifeCycle();
>>> }
>>>
>>> @Test
>>> public void testRunJob() throws Exception {
>>> AsyncJob asyncJob = new AsyncJobVO("", User.UID_SYSTEM, 1,
>>> DetachVolumeCmdByAdmin.class.getCanonicalName(), null, null, null);
>>> apiAsyncJobDispatcher.runJob(asyncJob);
>>> }
>>> }
>>>
>>>
>>> I am getting failed to load ApplicationContext error. The exact error
>>> message is
>>> java.lang.ClassNotFoundException:
>>> org.apache.cloudstack.framework.eventbus.EventBusBase
>>>
>>> I think, that class is moved to
>>> org.apache.cloudstack.framework.events.EventBus. Once I make that change in
>>> the application context file, I am getting
>>> Caused by:
>>> org.springframework.beans.factory.NoUniqueBeanDefinitionException: No
>>> qualifying bean of type [com.cloud.user.AccountService] is defined:
>>> expected single matching bean but found 4:
>>> mockAccountManagerImpl,accountService,accountManager,acctMgr
>>>
>>>
>>> Am I miss something?
>>>
>>> I did go through
>>> https://cwiki.apache.org/confluence/display/CLOUDSTACK/Unit+Testing+with+JUnit+and+SpringBut, didn't understand Note: #4 of it.
>>>
>>>
>>> ~Rajani
>>>
>>>
>>>
>>>
>>
>>
>> --
>>
>> EOF
>
Re: spring unittests
Posted by Rajani Karuturi <Ra...@citrix.com>.
Its the testContext.xml we have at server/test/resouces
As the async job dispatcher also comes under server/, i used the same test context file.
~Rajani
On 28-Mar-2014, at 1:23 am, Laszlo Hornyak <la...@gmail.com> wrote:
> Hi Rajani,
>
> Can you share your spring context file?
>
>
> On Thu, Mar 27, 2014 at 10:50 AM, Rajani Karuturi <
> Rajani.Karuturi@citrix.com> wrote:
>
>> Hi All,
>>
>> I am trying to write unit tests for ApiAsyncJobDispatcher. This is how I
>> defined by Test class @ server/test/com/cloud/api
>>
>> @RunWith(SpringJUnit4ClassRunner.class)
>> @ContextConfiguration(locations = "classpath:/testContext.xml")
>> public class ApiAsyncJobDispatcherTest {
>> @Mock
>> private ApiDispatcher _dispatcher;
>>
>> @Mock
>> private AsyncJobManager _asyncJobMgr;
>>
>> @Mock
>> private EntityManager _entityMgr;
>>
>> @InjectMocks
>> private ApiAsyncJobDispatcher apiAsyncJobDispatcher = new
>> ApiAsyncJobDispatcher();
>>
>> @Before
>> public void setUp() throws Exception {
>> MockitoAnnotations.initMocks(this);
>> ComponentContext.initComponentsLifeCycle();
>> }
>>
>> @Test
>> public void testRunJob() throws Exception {
>> AsyncJob asyncJob = new AsyncJobVO("", User.UID_SYSTEM, 1,
>> DetachVolumeCmdByAdmin.class.getCanonicalName(), null, null, null);
>> apiAsyncJobDispatcher.runJob(asyncJob);
>> }
>> }
>>
>>
>> I am getting failed to load ApplicationContext error. The exact error
>> message is
>> java.lang.ClassNotFoundException:
>> org.apache.cloudstack.framework.eventbus.EventBusBase
>>
>> I think, that class is moved to
>> org.apache.cloudstack.framework.events.EventBus. Once I make that change in
>> the application context file, I am getting
>> Caused by:
>> org.springframework.beans.factory.NoUniqueBeanDefinitionException: No
>> qualifying bean of type [com.cloud.user.AccountService] is defined:
>> expected single matching bean but found 4:
>> mockAccountManagerImpl,accountService,accountManager,acctMgr
>>
>>
>> Am I miss something?
>>
>> I did go through
>> https://cwiki.apache.org/confluence/display/CLOUDSTACK/Unit+Testing+with+JUnit+and+SpringBut, didn't understand Note: #4 of it.
>>
>>
>> ~Rajani
>>
>>
>>
>>
>
>
> --
>
> EOF
Re: spring unittests
Posted by Laszlo Hornyak <la...@gmail.com>.
Hi Rajani,
Can you share your spring context file?
On Thu, Mar 27, 2014 at 10:50 AM, Rajani Karuturi <
Rajani.Karuturi@citrix.com> wrote:
> Hi All,
>
> I am trying to write unit tests for ApiAsyncJobDispatcher. This is how I
> defined by Test class @ server/test/com/cloud/api
>
> @RunWith(SpringJUnit4ClassRunner.class)
> @ContextConfiguration(locations = "classpath:/testContext.xml")
> public class ApiAsyncJobDispatcherTest {
> @Mock
> private ApiDispatcher _dispatcher;
>
> @Mock
> private AsyncJobManager _asyncJobMgr;
>
> @Mock
> private EntityManager _entityMgr;
>
> @InjectMocks
> private ApiAsyncJobDispatcher apiAsyncJobDispatcher = new
> ApiAsyncJobDispatcher();
>
> @Before
> public void setUp() throws Exception {
> MockitoAnnotations.initMocks(this);
> ComponentContext.initComponentsLifeCycle();
> }
>
> @Test
> public void testRunJob() throws Exception {
> AsyncJob asyncJob = new AsyncJobVO("", User.UID_SYSTEM, 1,
> DetachVolumeCmdByAdmin.class.getCanonicalName(), null, null, null);
> apiAsyncJobDispatcher.runJob(asyncJob);
> }
> }
>
>
> I am getting failed to load ApplicationContext error. The exact error
> message is
> java.lang.ClassNotFoundException:
> org.apache.cloudstack.framework.eventbus.EventBusBase
>
> I think, that class is moved to
> org.apache.cloudstack.framework.events.EventBus. Once I make that change in
> the application context file, I am getting
> Caused by:
> org.springframework.beans.factory.NoUniqueBeanDefinitionException: No
> qualifying bean of type [com.cloud.user.AccountService] is defined:
> expected single matching bean but found 4:
> mockAccountManagerImpl,accountService,accountManager,acctMgr
>
>
> Am I miss something?
>
> I did go through
> https://cwiki.apache.org/confluence/display/CLOUDSTACK/Unit+Testing+with+JUnit+and+SpringBut, didn't understand Note: #4 of it.
>
>
> ~Rajani
>
>
>
>
--
EOF