use of io.codekvast.common.customer.CustomerData in project codekvast by crispab.
the class CustomerServiceImpl method assertDatabaseSize.
@Override
@Transactional(readOnly = true)
public void assertDatabaseSize(long customerId) throws LicenseViolationException {
CustomerData customerData = getCustomerDataByCustomerId(customerId);
int numberOfMethods = countMethods(customerId);
doAssertNumberOfMethods(customerData, numberOfMethods);
}
use of io.codekvast.common.customer.CustomerData in project codekvast by crispab.
the class LoginServiceImpl method getDashboardLaunchURI.
@Override
@Transactional(rollbackFor = Exception.class)
public URI getDashboardLaunchURI(Long customerId) {
User user = getUserFromSecurityContext();
if (user.getCustomerData().stream().anyMatch(cd -> cd.getCustomerId().equals(customerId))) {
customerService.registerLogin(CustomerService.LoginRequest.builder().customerId(customerId).email(user.getEmail()).source(commonSettings.getApplicationName()).build());
CustomerData cd = customerService.getCustomerDataByCustomerId(customerId);
String code = securityService.createCodeForWebappToken(customerId, WebappCredentials.builder().customerName(cd.getCustomerName()).email(user.getEmail()).source(cd.getSource()).build());
return URI.create(String.format("%s/dashboard/launch/%s", commonSettings.getDashboardBaseUrl(), code));
}
return null;
}
use of io.codekvast.common.customer.CustomerData in project codekvast by crispab.
the class DashboardServiceImplTest method should_getStatus_inside_trial_period.
@Test
public void should_getStatus_inside_trial_period() {
// given
when(customerIdProvider.getCustomerId()).thenReturn(1L);
PricePlanDefaults ppd = PricePlanDefaults.TEST;
Instant collectionStartedAt = now.minus(3, DAYS);
Instant trialPeriodEndsAt = now.plus(3, DAYS);
CustomerData customerData = CustomerData.builder().customerId(1L).customerName("customerName").pricePlan(PricePlan.of(ppd).toBuilder().retentionPeriodDays(-1).build()).source("source").collectionStartedAt(collectionStartedAt).trialPeriodEndsAt(trialPeriodEndsAt).build();
when(customerService.getCustomerDataByCustomerId(eq(1L))).thenReturn(customerData);
when(customerService.countMethods(eq(1L))).thenReturn(1000);
// when
GetStatusResponse status = dashboardService.getStatus();
// then
assertNotNull(status);
assertThat(status.getPricePlan(), is("TEST"));
assertThat(status.getCollectedSinceMillis(), is(collectionStartedAt.toEpochMilli()));
assertThat(status.getTrialPeriodEndsAtMillis(), is(trialPeriodEndsAt.toEpochMilli()));
assertThat(status.getTrialPeriodPercent(), is(50));
assertThat(status.getTrialPeriodExpired(), is(false));
assertThat(status.getMaxNumberOfAgents(), is(ppd.getMaxNumberOfAgents()));
assertThat(status.getMaxNumberOfMethods(), is(ppd.getMaxMethods()));
assertThat(status.getNumMethods(), is(1000));
assertThat(status.getNumAgents(), is(0));
System.out.println("status = " + status);
verify(customerService).getCustomerDataByCustomerId(eq(1L));
verify(customerService).countMethods(eq(1L));
verify(customerIdProvider).getCustomerId();
verifyNoMoreInteractions(customerService, customerIdProvider);
}
use of io.codekvast.common.customer.CustomerData in project codekvast by crispab.
the class DashboardServiceImplTest method should_getStatus_not_started_no_trial_period.
@Test
public void should_getStatus_not_started_no_trial_period() {
// given
when(customerIdProvider.getCustomerId()).thenReturn(1L);
PricePlanDefaults ppd = PricePlanDefaults.TEST;
CustomerData customerData = CustomerData.builder().customerId(1L).customerName("customerName").pricePlan(PricePlan.of(ppd)).source("source").collectionStartedAt(null).trialPeriodEndsAt(null).build();
when(customerService.getCustomerDataByCustomerId(eq(1L))).thenReturn(customerData);
when(customerService.countMethods(eq(1L))).thenReturn(1000);
// when
GetStatusResponse status = dashboardService.getStatus();
// then
assertNotNull(status);
assertThat(status.getCollectedSinceMillis(), is(nullValue()));
assertThat(status.getTrialPeriodEndsAtMillis(), is(nullValue()));
assertThat(status.getTrialPeriodPercent(), is(nullValue()));
assertThat(status.getTrialPeriodExpired(), is(false));
}
use of io.codekvast.common.customer.CustomerData in project codekvast by crispab.
the class DashboardServiceImplTest method should_getFilterData.
@Test
public void should_getFilterData() {
// given
PricePlanDefaults ppd = PricePlanDefaults.TEST;
long customerId = 1L;
when(customerIdProvider.getCustomerId()).thenReturn(customerId);
CustomerData customerData = CustomerData.builder().customerId(customerId).customerName("customerName").pricePlan(PricePlan.of(ppd)).source("source").collectionStartedAt(null).trialPeriodEndsAt(null).build();
when(customerService.getCustomerDataByCustomerId(eq(customerId))).thenReturn(customerData);
// noinspection unchecked
when(jdbcTemplate.queryForList(anyString(), eq(String.class), eq(customerId))).thenReturn(asList("app2", "app1", "app3"), asList("env2", "env1", "env3"), asList("loc2", "loc1", "loc3"));
// when
GetMethodsFormData formData = dashboardService.getMethodsFormData();
// then
assertThat(formData, is(GetMethodsFormData.builder().application("app1").application("app2").application("app3").environment("env1").environment("env2").environment("env3").location("loc1").location("loc2").location("loc3").retentionPeriodDays(ppd.getRetentionPeriodDays()).build()));
}
Aggregations