@Test public void unusedConnectionsShouldHaveUseOfZero() { final Integration emptyIntegration = new Integration.Builder().build(); when(dataManager.fetchAll(Integration.class)).thenReturn(ListResult.of(emptyIntegration, emptyIntegration)); handler.processInternal(NOT_USED); verify(dataManager).fetchAll(Integration.class); verify(dataManager).fetchAll(Connection.class); verify(dataManager).fetchAll(Extension.class); verifyNoMoreInteractions(dataManager); }
void processInternal(final ChangeEvent event) { LOG.debug("Processing event: {}", event); final ListResult<Integration> integrationsResult = dataManager.fetchAll(Integration.class); final List<Integration> integrations = integrationsResult.getItems(); updateUsageFor(Connection.class, integrations, Integration::getConnectionIds, Functions.compose(Optional::get, Connection::getId), UsageUpdateHandler::withUpdatedUsage); updateUsageFor(Extension.class, integrations, Integration::getExtensionIds, Extension::getExtensionId, UsageUpdateHandler::withUpdatedUsage); }
UsageUpdateHandler implements ResourceUpdateHandler { void processInternal(final ChangeEvent event) { LOG.debug("Processing event: {}", event); final ListResult<Integration> integrationsResult = dataManager.fetchAll(Integration.class); final List<Integration> integrations = integrationsResult.getItems(); updateUsageFor(Connection.class, integrations, Integration::getConnectionIds, Functions.compose(Optional::get, Connection::getId), UsageUpdateHandler::withUpdatedUsage); updateUsageFor(Extension.class, integrations, Integration::getExtensionIds, Extension::getExtensionId, UsageUpdateHandler::withUpdatedUsage); } }
UsageUpdateHandler implements ResourceUpdateHandler { void processInternal(final ChangeEvent event) { LOG.debug("Processing event: {}", event); final ListResult<Integration> integrationsResult = dataManager.fetchAll(Integration.class); final List<Integration> integrations = integrationsResult.getItems(); updateUsageFor(Connection.class, integrations, Integration::getConnectionIds, Functions.compose(Optional::get, Connection::getId), UsageUpdateHandler::withUpdatedUsage); updateUsageFor(Extension.class, integrations, Integration::getExtensionIds, Extension::getExtensionId, UsageUpdateHandler::withUpdatedUsage); } UsageUpdateHandler(final DataManager dataManager); }
UsageUpdateHandler implements ResourceUpdateHandler { void processInternal(final ChangeEvent event) { LOG.debug("Processing event: {}", event); final ListResult<Integration> integrationsResult = dataManager.fetchAll(Integration.class); final List<Integration> integrations = integrationsResult.getItems(); updateUsageFor(Connection.class, integrations, Integration::getConnectionIds, Functions.compose(Optional::get, Connection::getId), UsageUpdateHandler::withUpdatedUsage); updateUsageFor(Extension.class, integrations, Integration::getExtensionIds, Extension::getExtensionId, UsageUpdateHandler::withUpdatedUsage); } UsageUpdateHandler(final DataManager dataManager); @Override boolean canHandle(final ChangeEvent event); @Override void process(final ChangeEvent event); }
UsageUpdateHandler implements ResourceUpdateHandler { void processInternal(final ChangeEvent event) { LOG.debug("Processing event: {}", event); final ListResult<Integration> integrationsResult = dataManager.fetchAll(Integration.class); final List<Integration> integrations = integrationsResult.getItems(); updateUsageFor(Connection.class, integrations, Integration::getConnectionIds, Functions.compose(Optional::get, Connection::getId), UsageUpdateHandler::withUpdatedUsage); updateUsageFor(Extension.class, integrations, Integration::getExtensionIds, Extension::getExtensionId, UsageUpdateHandler::withUpdatedUsage); } UsageUpdateHandler(final DataManager dataManager); @Override boolean canHandle(final ChangeEvent event); @Override void process(final ChangeEvent event);  }