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