/** * Provides informations of business context instances. * * <p> * <i> Example URL: /bc/app</i> * </p> * * @return a list of {@link ApplicationData}. */ @RequestMapping(method = GET, value = "") @ResponseBody public Collection<ApplicationData> getApplications() { return businessContextManagementService.getApplications(); }
/** * Reloads the business context data. */ private void refreshBusinessContext() { applicationMap.clear(); businessTransactionsMap.clear(); for (BusinessTransactionData businessTx : businessContextService.getBusinessTransactions()) { businessTransactionsMap.put(new Pair<Integer, Integer>(businessTx.getApplication().getId(), businessTx.getId()), businessTx); } for (ApplicationData application : businessContextService.getApplications()) { applicationMap.put(application.getId(), application); } }
@Test public void testBusinessContextCache() throws BusinessException { assertThat(cachedDataService.getApplicationForId(FIRST_APPLICATION_ID), is(equalTo(firstApplication))); assertThat(cachedDataService.getApplicationForId(SECOND_APPLICATION_ID), is(equalTo(secondApplication))); assertThat(cachedDataService.getBusinessTransactionForId(FIRST_APPLICATION_ID, FIRST_BUSINESS_TX_ID), is(equalTo(firstBusinessTx))); assertThat(cachedDataService.getBusinessTransactionForId(FIRST_APPLICATION_ID, SECOND_BUSINESS_TX_ID), is(equalTo(secondBusinessTx))); assertThat(cachedDataService.getBusinessTransactionForId(SECOND_APPLICATION_ID, THIRD_BUSINESS_TX_ID), is(equalTo(thirdBusinessTx))); verify(businessContextService, times(1)).getBusinessTransactions(); verify(businessContextService, times(1)).getApplications(); assertThat(cachedDataService.getApplicationForId(1), is(nullValue())); assertThat(cachedDataService.getApplicationForId(1), is(nullValue())); assertThat(cachedDataService.getBusinessTransactionForId(SECOND_APPLICATION_ID, FIRST_BUSINESS_TX_ID), is(nullValue())); assertThat(cachedDataService.getBusinessTransactionForId(FIRST_APPLICATION_ID, THIRD_BUSINESS_TX_ID), is(nullValue())); assertThat(cachedDataService.getBusinessTransactionForId(1, THIRD_BUSINESS_TX_ID), is(nullValue())); assertThat(cachedDataService.getBusinessTransactionForId(1, 1), is(nullValue())); verify(businessContextService, times(7)).getBusinessTransactions(); verify(businessContextService, times(7)).getApplications(); } }
@BeforeMethod public void initialize() throws BusinessException { firstApplication = new ApplicationData(FIRST_APPLICATION_ID, FIRST_APPLICATION_ID, "firstApplication"); firstBusinessTx = new BusinessTransactionData(FIRST_BUSINESS_TX_ID, FIRST_BUSINESS_TX_ID, firstApplication, "firstBusinessTx"); secondBusinessTx = new BusinessTransactionData(SECOND_BUSINESS_TX_ID, SECOND_BUSINESS_TX_ID, firstApplication, "secondBusinessTx"); secondApplication = new ApplicationData(SECOND_APPLICATION_ID, SECOND_APPLICATION_ID, "secondApplication"); thirdBusinessTx = new BusinessTransactionData(THIRD_BUSINESS_TX_ID, THIRD_BUSINESS_TX_ID, secondApplication, "thirdBusinessTx"); List<BusinessTransactionData> businessTxs = new ArrayList<>(); businessTxs.add(firstBusinessTx); businessTxs.add(secondBusinessTx); businessTxs.add(thirdBusinessTx); List<ApplicationData> applications = new ArrayList<>(); applications.add(firstApplication); applications.add(secondApplication); when(businessContextService.getBusinessTransactions()).thenReturn(businessTxs); when(businessContextService.getApplications()).thenReturn(applications); }