@Test void should_update_customers_and_start_trial_period_when_agent_polls_the_first_time_and_trial_period_days() { CustomerData customerData = CustomerData.builder() .customerId(1L) .source("test") .customerName("customerName") .collectionStartedAt(null) .pricePlan(PricePlan.of(PricePlanDefaults.TEST).toBuilder().trialPeriodDays(10).build()) .build(); when(jdbcTemplate.update(anyString(), any(Timestamp.class), any(Timestamp.class), anyLong())) .thenReturn(1); CustomerData data = service.registerAgentPoll(customerData, NOW); assertThat(data.getCollectionStartedAt(), is(NOW)); verify(jdbcTemplate) .update( startsWith("UPDATE customers"), eq(Timestamp.from(NOW)), eq(Timestamp.from(NOW.plus(10, DAYS))), eq(1L)); verify(eventService).send(any(CollectionStartedEvent.class)); }
@Override @Transactional public CustomerData registerAgentPoll(CustomerData customerData, Instant polledAt) { CustomerData result = customerData; if (customerData.getCollectionStartedAt() == null) { result = recordCollectionStarted(result, polledAt); } return result; }
CustomerServiceImpl implements CustomerService { @Override @Transactional public CustomerData registerAgentPoll(CustomerData customerData, Instant polledAt) { CustomerData result = customerData; if (customerData.getCollectionStartedAt() == null) { result = recordCollectionStarted(result, polledAt); } return result; } }
CustomerServiceImpl implements CustomerService { @Override @Transactional public CustomerData registerAgentPoll(CustomerData customerData, Instant polledAt) { CustomerData result = customerData; if (customerData.getCollectionStartedAt() == null) { result = recordCollectionStarted(result, polledAt); } return result; }  }
CustomerServiceImpl implements CustomerService { @Override @Transactional public CustomerData registerAgentPoll(CustomerData customerData, Instant polledAt) { CustomerData result = customerData; if (customerData.getCollectionStartedAt() == null) { result = recordCollectionStarted(result, polledAt); } return result; }  @PostConstruct @Transactional void ensurePricePlansExistInDatabase(); @Override @Transactional(readOnly = true) @Cacheable(CUSTOMERS_CACHE) CustomerData getCustomerDataByLicenseKey(@NonNull String licenseKey); @Override @Transactional(readOnly = true) @Cacheable(CUSTOMERS_CACHE) CustomerData getCustomerDataByCustomerId(long customerId); @Override @Transactional(readOnly = true) @Cacheable(CUSTOMERS_CACHE) List<CustomerData> getCustomerDataByUserEmail(String email); @Override @Transactional(readOnly = true) @Cacheable(CUSTOMERS_CACHE) CustomerData getCustomerDataByExternalId(
      @NonNull String source, @NonNull String externalId); @Override @Transactional(readOnly = true) void assertPublicationSize(CustomerData customerData, int publicationSize); @Override @Transactional(readOnly = true) void assertDatabaseSize(long customerId); @Override @Transactional(readOnly = true) int countMethods(long customerId); @Override @Transactional CustomerData registerAgentPoll(CustomerData customerData, Instant polledAt); @Override @Transactional void registerLogin(LoginRequest request); @Override @Transactional @CacheEvict(value = CUSTOMERS_CACHE, allEntries = true) AddCustomerResponse addCustomer(AddCustomerRequest request); @Override @Transactional @CacheEvict(value = CUSTOMERS_CACHE, allEntries = true) void changePlanForExternalId(
      String source, @NonNull String externalId, @NonNull String newPlanName); @Override @Transactional @CacheEvict(value = CUSTOMERS_CACHE, allEntries = true) void deleteCustomerByExternalId(@NonNull String source, String externalId); @Override @Transactional(readOnly = true) @Cacheable(ROLES_CACHE) List<String> getRoleNamesByUserEmail(String email); @Override @Transactional(readOnly = true) @Secured(Roles.ADMIN) List<CustomerData> getCustomerData(); @Override @Transactional @CacheEvict(value = CUSTOMERS_CACHE, allEntries = true) void updateAppDetails(String appName, String contactEmail, Long customerId); }
CustomerServiceImpl implements CustomerService { @Override @Transactional public CustomerData registerAgentPoll(CustomerData customerData, Instant polledAt) { CustomerData result = customerData; if (customerData.getCollectionStartedAt() == null) { result = recordCollectionStarted(result, polledAt); } return result; }  @PostConstruct @Transactional void ensurePricePlansExistInDatabase(); @Override @Transactional(readOnly = true) @Cacheable(CUSTOMERS_CACHE) CustomerData getCustomerDataByLicenseKey(@NonNull String licenseKey); @Override @Transactional(readOnly = true) @Cacheable(CUSTOMERS_CACHE) CustomerData getCustomerDataByCustomerId(long customerId); @Override @Transactional(readOnly = true) @Cacheable(CUSTOMERS_CACHE) List<CustomerData> getCustomerDataByUserEmail(String email); @Override @Transactional(readOnly = true) @Cacheable(CUSTOMERS_CACHE) CustomerData getCustomerDataByExternalId(
      @NonNull String source, @NonNull String externalId); @Override @Transactional(readOnly = true) void assertPublicationSize(CustomerData customerData, int publicationSize); @Override @Transactional(readOnly = true) void assertDatabaseSize(long customerId); @Override @Transactional(readOnly = true) int countMethods(long customerId); @Override @Transactional CustomerData registerAgentPoll(CustomerData customerData, Instant polledAt); @Override @Transactional void registerLogin(LoginRequest request); @Override @Transactional @CacheEvict(value = CUSTOMERS_CACHE, allEntries = true) AddCustomerResponse addCustomer(AddCustomerRequest request); @Override @Transactional @CacheEvict(value = CUSTOMERS_CACHE, allEntries = true) void changePlanForExternalId(
      String source, @NonNull String externalId, @NonNull String newPlanName); @Override @Transactional @CacheEvict(value = CUSTOMERS_CACHE, allEntries = true) void deleteCustomerByExternalId(@NonNull String source, String externalId); @Override @Transactional(readOnly = true) @Cacheable(ROLES_CACHE) List<String> getRoleNamesByUserEmail(String email); @Override @Transactional(readOnly = true) @Secured(Roles.ADMIN) List<CustomerData> getCustomerData(); @Override @Transactional @CacheEvict(value = CUSTOMERS_CACHE, allEntries = true) void updateAppDetails(String appName, String contactEmail, Long customerId);  }