@Test(groups = "slow", description = "Test Account creation generates an event") public void testBusEvents() throws Exception { final AccountEventHandler eventHandler = new AccountEventHandler(); bus.register(eventHandler); final AccountModelDao accountModelDao = createTestAccount(); final AccountData defaultAccount = new DefaultAccount(accountModelDao); final Account account = createAccount(defaultAccount); await().atMost(10, SECONDS).until(new Callable<Boolean>() { @Override public Boolean call() throws Exception { return eventHandler.getAccountCreationInternalEvents().size() == 1; } }); final AccountCreationInternalEvent accountCreationInternalEvent = eventHandler.getAccountCreationInternalEvents().get(0); Assert.assertEquals(accountCreationInternalEvent.getId(), account.getId()); // account_record_id is most likely 1, although, depending on the DB, we cannot be sure Assert.assertNotNull(accountCreationInternalEvent.getSearchKey1()); Assert.assertEquals(accountCreationInternalEvent.getSearchKey2(), internalCallContext.getTenantRecordId()); }
@Test(groups = "fast", expectedExceptions = RuntimeException.class) public void testEventBusException() throws Exception { AccountCreationInternalEvent event = mock(AccountCreationInternalEvent.class); provideCommonBusEventInfo(event); when(event.getBusEventType()).thenReturn(BusInternalEventType.ACCOUNT_CREATE); when(event.getId()).thenReturn(ACCOUNT_ID); doThrow(EventBusException.class).when(externalBus).post(any(BusEvent.class)); beatrixListener.handleAllInternalKillbillEvents(event); }
@Test(groups = "fast") public void testAccountCreate() throws Exception { AccountCreationInternalEvent event = mock(AccountCreationInternalEvent.class); provideCommonBusEventInfo(event); when(event.getBusEventType()).thenReturn(BusInternalEventType.ACCOUNT_CREATE); when(event.getId()).thenReturn(ACCOUNT_ID); ArgumentCaptor<BusEvent> eventCaptor = ArgumentCaptor.forClass(BusEvent.class); beatrixListener.handleAllInternalKillbillEvents(event); verify(externalBus, times(1)).post(eventCaptor.capture()); DefaultBusExternalEvent postedEvent = (DefaultBusExternalEvent)eventCaptor.getValue(); assertEquals(postedEvent.getObjectId(), ACCOUNT_ID); assertEquals(postedEvent.getObjectType(), ObjectType.ACCOUNT); assertEquals(postedEvent.getEventType(), ExtBusEventType.ACCOUNT_CREATION); assertNull(postedEvent.getMetaData()); assertCommonFieldsWithAccountId(postedEvent); }