Skip to content

Commit 095a69e

Browse files
committed
fix
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 931a172 commit 095a69e

2 files changed

Lines changed: 2 additions & 29 deletions

File tree

server/src/test/java/com/cloud/event/ActionEventInterceptorTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ public EventVO answer(InvocationOnMock invocation) throws Throwable {
175175
user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone",
176176
UUID.randomUUID().toString(), User.Source.UNKNOWN);
177177
CallContext.register(user, account);
178-
179-
Mockito.when(accountDao.findById(ACCOUNT_ID)).thenReturn(account);
180178
}
181179

182180
/**

server/src/test/java/com/cloud/event/ActionEventUtilsTest.java

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,8 @@ public EventVO answer(InvocationOnMock invocation) throws Throwable {
177177
account.setId(ACCOUNT_ID);
178178
user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone",
179179
UUID.randomUUID().toString(), User.Source.UNKNOWN);
180-
181-
Mockito.when(accountDao.findById(ACCOUNT_ID)).thenReturn(account);
182180
Mockito.when(userDao.findById(USER_ID)).thenReturn(user);
181+
CallContext.register(user, account);
183182
}
184183

185184
/**
@@ -204,12 +203,11 @@ public void teardown() {
204203
utils.init();
205204

206205
componentContextMocked.close();
206+
CallContext.unregister();
207207
}
208208

209209
@Test
210210
public void testPopulateFirstClassEntities() {
211-
CallContext.register(user, account);
212-
213211
//Inject some entity UUIDs into the call context
214212
String instanceUuid = UUID.randomUUID().toString();
215213
String ipUuid = UUID.randomUUID().toString();
@@ -231,8 +229,6 @@ public void testPopulateFirstClassEntities() {
231229
Assert.assertTrue(json.has("IpAddress"));
232230
Assert.assertEquals(json.get("VirtualMachine").getAsString(), instanceUuid);
233231
Assert.assertEquals(json.get("IpAddress").getAsString(), ipUuid);
234-
235-
CallContext.unregister();
236232
}
237233

238234
private void checkEventResourceAndUnregisterContext(Long resourceId, String resourceUuid, String resourceType) {
@@ -248,14 +244,10 @@ private void checkEventResourceAndUnregisterContext(Long resourceId, String reso
248244
EventVO eventVO = persistedEvents.get(0);
249245
Assert.assertEquals(eventVO.getResourceType(), resourceType);
250246
Assert.assertEquals(eventVO.getResourceId(), resourceId);
251-
252-
CallContext.unregister();
253247
}
254248

255249
@Test
256250
public void testPublishedEventResource() {
257-
CallContext.register(user, account);
258-
259251
final Long resourceId = 1L;
260252
final String resourceType = ApiCommandResourceType.VirtualMachine.toString();
261253
final String resourceUuid = UUID.randomUUID().toString();
@@ -270,8 +262,6 @@ public void testPublishedEventResource() {
270262

271263
@Test
272264
public void testPublishedEventResourceWithCallContext() {
273-
CallContext.register(user, account);
274-
275265
final Long resourceId = 1L;
276266
final String resourceType = ApiCommandResourceType.VirtualMachine.toString();
277267
final String resourceUuid = UUID.randomUUID().toString();
@@ -287,8 +277,6 @@ public void testPublishedEventResourceWithCallContext() {
287277

288278
@Test
289279
public void testScheduledEvent() {
290-
CallContext.register(user, account);
291-
292280
final Long resourceId = 1L;
293281
final String resourceType = ApiCommandResourceType.VirtualMachine.toString();
294282
final String resourceUuid = UUID.randomUUID().toString();
@@ -304,14 +292,10 @@ public void testScheduledEvent() {
304292
Assert.assertEquals(persistedEvents.size(), 1);
305293
EventVO eventVO = persistedEvents.get(0);
306294
Assert.assertEquals(eventVO.getState(), com.cloud.event.Event.State.Scheduled);
307-
308-
CallContext.unregister();
309295
}
310296

311297
@Test
312298
public void testCreatedEvent() {
313-
CallContext.register(user, account);
314-
315299
final Long resourceId = 1L;
316300
final String resourceType = ApiCommandResourceType.VirtualMachine.toString();
317301
final String resourceUuid = UUID.randomUUID().toString();
@@ -327,14 +311,10 @@ public void testCreatedEvent() {
327311
Assert.assertEquals(persistedEvents.size(), 1);
328312
EventVO eventVO = persistedEvents.get(0);
329313
Assert.assertEquals(eventVO.getState(), com.cloud.event.Event.State.Created);
330-
331-
CallContext.unregister();
332314
}
333315

334316
@Test
335317
public void testNestedEvent() {
336-
CallContext.register(user, account);
337-
338318
final Long resourceId = 1L;
339319
final String resourceType = ApiCommandResourceType.VirtualMachine.toString();
340320
final String resourceUuid = UUID.randomUUID().toString();
@@ -344,14 +324,10 @@ public void testNestedEvent() {
344324
Assert.assertEquals(persistedEvents.size(), 1);
345325
EventVO eventVO = persistedEvents.get(0);
346326
Assert.assertEquals(eventVO.getState(), com.cloud.event.Event.State.Started);
347-
348-
CallContext.unregister();
349327
}
350328

351329
@Test
352330
public void testSnapshotEventResource() {
353-
CallContext.register(user, account);
354-
355331
final Long snapshotResourceId = 100L;
356332
final String snapshotResourceType = ApiCommandResourceType.Snapshot.toString();
357333
final String snapshotResourceUuid = UUID.randomUUID().toString();
@@ -366,7 +342,6 @@ public void testSnapshotEventResource() {
366342

367343
@Test
368344
public void testVmSnapshotEventResource() {
369-
CallContext.register(user, account);
370345

371346
final Long vmSnapshotResourceId = 100L;
372347
final String vmSnapshotResourceType = ApiCommandResourceType.VmSnapshot.toString();

0 commit comments

Comments
 (0)