use of io.codekvast.common.customer.PricePlanDefaults in project codekvast by crispab.
the class MariadbIntegrationTest method assertConfigPollResponse.
private void assertConfigPollResponse(GetConfigResponse1 response, String publisherConfig) {
PricePlanDefaults pp = PricePlanDefaults.DEMO;
assertThat(response, is(GetConfigResponse1.sample().toBuilder().codeBasePublisherCheckIntervalSeconds(pp.getPublishIntervalSeconds()).codeBasePublisherConfig(publisherConfig).codeBasePublisherName("http").codeBasePublisherRetryIntervalSeconds(pp.getRetryIntervalSeconds()).configPollIntervalSeconds(pp.getPollIntervalSeconds()).configPollRetryIntervalSeconds(pp.getRetryIntervalSeconds()).invocationDataPublisherConfig(publisherConfig).invocationDataPublisherIntervalSeconds(pp.getPublishIntervalSeconds()).invocationDataPublisherName("http").invocationDataPublisherRetryIntervalSeconds(pp.getRetryIntervalSeconds()).build()));
}
use of io.codekvast.common.customer.PricePlanDefaults in project codekvast by crispab.
the class CustomerServiceImpl method getCustomerData.
private CustomerData getCustomerData(String where_clause, Object... identifiers) {
logger.debug("getCustomerData({}, {})", where_clause, identifiers);
Map<String, Object> result = jdbcTemplate.queryForMap("SELECT " + "c.id, c.name, c.source, c.plan, c.createdAt, c.collectionStartedAt, " + "c.trialPeriodEndsAt, c.contactEmail, c.notes AS customerNotes, " + "ppo.createdBy, ppo.note AS pricePlanNote, ppo.maxMethods, " + "ppo.maxNumberOfAgents, ppo.publishIntervalSeconds, " + "ppo.pollIntervalSeconds, ppo.retryIntervalSeconds, " + "ppo.trialPeriodDays, ppo.retentionPeriodDays " + "FROM customers c LEFT JOIN price_plan_overrides ppo " + "ON ppo.customerId = c.id " + "WHERE " + where_clause, identifiers);
String planName = (String) result.get("plan");
Timestamp createdAt = (Timestamp) result.get("createdAt");
Timestamp collectionStartedAt = (Timestamp) result.get("collectionStartedAt");
Timestamp trialPeriodEndsAt = (Timestamp) result.get("trialPeriodEndsAt");
PricePlanDefaults ppd = PricePlanDefaults.ofDatabaseName(planName);
return CustomerData.builder().customerId((Long) result.get("id")).customerName((String) result.get("name")).source((String) result.get("source")).createdAt(createdAt.toInstant()).contactEmail((String) result.get("contactEmail")).customerNotes((String) result.get("customerNotes")).collectionStartedAt(collectionStartedAt != null ? collectionStartedAt.toInstant() : null).trialPeriodEndsAt(trialPeriodEndsAt != null ? trialPeriodEndsAt.toInstant() : null).pricePlan(PricePlan.builder().name(ppd.name()).overrideBy((String) result.get("createdBy")).note((String) result.get("pricePlanNote")).maxMethods(getOrDefault(result, "maxMethods", ppd.getMaxMethods())).maxNumberOfAgents(getOrDefault(result, "maxNumberOfAgents", ppd.getMaxNumberOfAgents())).pollIntervalSeconds(getOrDefault(result, "pollIntervalSeconds", ppd.getPollIntervalSeconds())).publishIntervalSeconds(getOrDefault(result, "publishIntervalSeconds", ppd.getPublishIntervalSeconds())).retryIntervalSeconds(getOrDefault(result, "retryIntervalSeconds", ppd.getRetryIntervalSeconds())).trialPeriodDays(getOrDefault(result, "trialPeriodDays", ppd.getTrialPeriodDays())).retentionPeriodDays(getOrDefault(result, "retentionPeriodDays", ppd.getRetentionPeriodDays())).build()).build();
}
use of io.codekvast.common.customer.PricePlanDefaults 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.PricePlanDefaults 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.PricePlanDefaults 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