use of com.cloud.utils.db.EntityManager in project cloudstack by apache.
the class IntegrationTestConfiguration method entityManager.
@Bean
public EntityManager entityManager() {
EntityManager mock = Mockito.mock(EntityManager.class);
try {
Mockito.when(mock.findById(Matchers.same(Account.class), Matchers.anyLong())).thenReturn(_accountDao.findById(Account.ACCOUNT_ID_SYSTEM));
Mockito.when(mock.findById(Matchers.same(User.class), Matchers.anyLong())).thenReturn(_userDao.findById(User.UID_SYSTEM));
Mockito.when(mock.findById(Matchers.same(NetworkOffering.class), Matchers.any(Long.class))).thenAnswer(new Answer<NetworkOffering>() {
@Override
public NetworkOffering answer(final InvocationOnMock invocation) throws Throwable {
Long id = (Long) invocation.getArguments()[1];
return _networkOfferingDao.findById(id);
}
});
Mockito.when(mock.findById(Matchers.same(IpAddress.class), Matchers.any(Long.class))).thenAnswer(new Answer<IpAddress>() {
@Override
public IpAddress answer(final InvocationOnMock invocation) throws Throwable {
Long id = (Long) invocation.getArguments()[1];
return _ipAddressDao.findById(id);
}
});
Mockito.when(mock.findById(Matchers.same(DataCenter.class), Matchers.any(Long.class))).thenAnswer(new Answer<DataCenter>() {
@Override
public DataCenter answer(final InvocationOnMock invocation) throws Throwable {
Long id = (Long) invocation.getArguments()[1];
return _zoneDao.findById(id);
}
});
} catch (Exception e) {
e.printStackTrace();
}
CallContext.init(mock);
return mock;
}
Aggregations