use of org.apache.cloudstack.framework.events.Event in project cloudstack by apache.
the class HypervisorTemplateAdapterTest method testEmitDeleteEventUuid.
@Test
public void testEmitDeleteEventUuid() throws InterruptedException, ExecutionException, EventBusException {
//All the mocks required for this test to work.
ImageStoreEntity store = mock(ImageStoreEntity.class);
when(store.getId()).thenReturn(1l);
when(store.getDataCenterId()).thenReturn(1l);
when(store.getName()).thenReturn("Test Store");
TemplateDataStoreVO dataStoreVO = mock(TemplateDataStoreVO.class);
when(dataStoreVO.getDownloadState()).thenReturn(Status.DOWNLOADED);
TemplateInfo info = mock(TemplateInfo.class);
when(info.getDataStore()).thenReturn(store);
VMTemplateVO template = mock(VMTemplateVO.class);
when(template.getId()).thenReturn(1l);
when(template.getName()).thenReturn("Test Template");
when(template.getFormat()).thenReturn(ImageFormat.QCOW2);
when(template.getAccountId()).thenReturn(1l);
//TODO possibly return this from method for comparison, if things work how i want
when(template.getUuid()).thenReturn("Test UUID");
TemplateProfile profile = mock(TemplateProfile.class);
when(profile.getTemplate()).thenReturn(template);
when(profile.getZoneId()).thenReturn(1l);
TemplateApiResult result = mock(TemplateApiResult.class);
when(result.isSuccess()).thenReturn(true);
when(result.isFailed()).thenReturn(false);
@SuppressWarnings("unchecked") AsyncCallFuture<TemplateApiResult> future = mock(AsyncCallFuture.class);
when(future.get()).thenReturn(result);
AccountVO acct = mock(AccountVO.class);
when(acct.getId()).thenReturn(1l);
when(acct.getDomainId()).thenReturn(1l);
when(_templateMgr.getImageStoreByTemplate(anyLong(), anyLong())).thenReturn(Collections.singletonList((DataStore) store));
when(_templateStoreDao.listByTemplateStore(anyLong(), anyLong())).thenReturn(Collections.singletonList(dataStoreVO));
when(_dataFactory.getTemplate(anyLong(), any(DataStore.class))).thenReturn(info);
when(_dataFactory.listTemplateOnCache(anyLong())).thenReturn(Collections.singletonList(info));
when(_templateService.deleteTemplateAsync(any(TemplateInfo.class))).thenReturn(future);
when(_accountDao.findById(anyLong())).thenReturn(acct);
when(_accountDao.findByIdIncludingRemoved(anyLong())).thenReturn(acct);
//Test actually begins here.
setupUsageUtils();
_adapter.delete(profile);
Assert.assertNotNull(usageEvents);
Assert.assertNotNull(events);
Assert.assertEquals(1, events.size());
Event event = events.get(0);
Assert.assertNotNull(event);
Assert.assertNotNull(event.getResourceType());
Assert.assertEquals(VirtualMachineTemplate.class.getName(), event.getResourceType());
Assert.assertNotNull(event.getResourceUUID());
Assert.assertEquals("Test UUID", event.getResourceUUID());
Assert.assertEquals(EventTypes.EVENT_TEMPLATE_DELETE, event.getEventType());
cleanupUsageUtils();
}
use of org.apache.cloudstack.framework.events.Event in project cloudstack by apache.
the class ActionEventUtilsTest method testPopulateFirstClassEntities.
@Test
public void testPopulateFirstClassEntities() {
AccountVO account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
account.setId(ACCOUNT_ID);
UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
Mockito.when(accountDao.findById(ACCOUNT_ID)).thenReturn(account);
Mockito.when(userDao.findById(USER_ID)).thenReturn(user);
CallContext.register(user, account);
//Inject some entity UUIDs into the call context
String instanceUuid = UUID.randomUUID().toString();
String ipUuid = UUID.randomUUID().toString();
CallContext.current().putContextParameter(VirtualMachine.class, instanceUuid);
CallContext.current().putContextParameter(IpAddress.class, ipUuid);
ActionEventUtils.onActionEvent(USER_ID, ACCOUNT_ID, account.getDomainId(), "StaticNat", "Test event");
//Assertions
Assert.assertNotEquals(publishedEvents.size(), 0);
Assert.assertEquals(publishedEvents.size(), 1);
Event event = publishedEvents.get(0);
Assert.assertNotNull(event.getDescription());
JsonObject json = new JsonParser().parse(event.getDescription()).getAsJsonObject();
Assert.assertTrue(json.has("VirtualMachine"));
Assert.assertTrue(json.has("IpAddress"));
Assert.assertEquals(json.get("VirtualMachine").getAsString(), instanceUuid);
Assert.assertEquals(json.get("IpAddress").getAsString(), ipUuid);
CallContext.unregister();
}
Aggregations