Search in sources :

Example 11 with CustomerData

use of io.codekvast.common.customer.CustomerData in project codekvast by crispab.

the class IntakeIntegrationTest method should_accept_valid_getCustomerDataByExternalId_trialPeriodExpired.

@Test
@Sql(scripts = "/sql/base-data.sql")
public void should_accept_valid_getCustomerDataByExternalId_trialPeriodExpired() {
    // see base-data.sql
    Instant now = Instant.parse("2017-09-21T16:21:19Z").plus(1, DAYS);
    CustomerData customerData = customerService.getCustomerDataByExternalId("test", "external-3");
    assertThat(customerData.getCustomerId(), is(3L));
    assertThat(customerData.isTrialPeriodExpired(now), is(true));
}
Also used : CustomerData(io.codekvast.common.customer.CustomerData) Instant(java.time.Instant) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 12 with CustomerData

use of io.codekvast.common.customer.CustomerData in project codekvast by crispab.

the class IntakeIntegrationTest method should_accept_valid_getCustomerDataByLicenseKey.

@Test
@Sql(scripts = "/sql/base-data.sql")
public void should_accept_valid_getCustomerDataByLicenseKey() {
    CustomerData customerData = customerService.getCustomerDataByLicenseKey("");
    assertThat(customerData.getCustomerId(), is(1L));
    assertThat(customerData.getCustomerName(), is("Demo"));
    assertThat(customerData.getPricePlan().getName(), is("DEMO"));
}
Also used : CustomerData(io.codekvast.common.customer.CustomerData) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 13 with CustomerData

use of io.codekvast.common.customer.CustomerData in project codekvast by crispab.

the class IntakeIntegrationTest method should_accept_valid_getCustomerDataByExternalId_without_pricePlanOverride.

@Test
@Sql(scripts = "/sql/base-data.sql")
public void should_accept_valid_getCustomerDataByExternalId_without_pricePlanOverride() {
    CustomerData customerData = customerService.getCustomerDataByExternalId("test", "external-2");
    assertThat(customerData.getCustomerId(), is(2L));
    assertThat(customerData.getPricePlan().getOverrideBy(), nullValue());
    assertThat(customerData.isTrialPeriodExpired(Instant.now()), is(false));
}
Also used : CustomerData(io.codekvast.common.customer.CustomerData) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 14 with CustomerData

use of io.codekvast.common.customer.CustomerData in project codekvast by crispab.

the class DashboardServiceImpl method getStatus.

@Override
@Transactional(readOnly = true)
public GetStatusResponse getStatus() {
    long startedAt = clock.millis();
    Long customerId = customerIdProvider.getCustomerId();
    CustomerData customerData = customerService.getCustomerDataByCustomerId(customerId);
    PricePlan pricePlan = customerData.getPricePlan();
    List<EnvironmentStatusDescriptor> environments = getEnvironments(customerId);
    List<ApplicationDescriptor2> applications = getApplications(customerId, pricePlan);
    List<AgentDescriptor> agents = getAgents(customerId, pricePlan.getPublishIntervalSeconds());
    Instant now = clock.instant();
    Instant collectionStartedAt = customerData.getCollectionStartedAt();
    Instant trialPeriodEndsAt = customerData.getTrialPeriodEndsAt();
    Duration trialPeriodDuration = collectionStartedAt == null || trialPeriodEndsAt == null ? null : Duration.between(collectionStartedAt, trialPeriodEndsAt);
    Duration trialPeriodProgress = trialPeriodDuration == null ? null : Duration.between(collectionStartedAt, now);
    Integer trialPeriodPercent = trialPeriodProgress == null ? null : Math.min(100, Math.toIntExact(trialPeriodProgress.toMillis() * 100L / trialPeriodDuration.toMillis()));
    return GetStatusResponse.builder().timestamp(startedAt).queryTimeMillis(clock.millis() - startedAt).pricePlan(pricePlan.getName()).retentionPeriodDays(pricePlan.getRetentionPeriodDays()).collectionResolutionSeconds(pricePlan.getPublishIntervalSeconds()).maxNumberOfAgents(pricePlan.getMaxNumberOfAgents()).maxNumberOfMethods(pricePlan.getMaxMethods()).collectedSinceMillis(pricePlan.adjustInstantToMillis(collectionStartedAt, clock)).trialPeriodEndsAtMillis(trialPeriodEndsAt == null ? null : trialPeriodEndsAt.toEpochMilli()).trialPeriodExpired(customerData.isTrialPeriodExpired(now)).trialPeriodPercent(trialPeriodPercent).numMethods(customerService.countMethods(customerId)).numAgents(agents.size()).numLiveAgents((int) agents.stream().filter(AgentDescriptor::isAgentAlive).count()).numLiveEnabledAgents((int) agents.stream().filter(AgentDescriptor::isAgentLiveAndEnabled).count()).environments(environments).applications(applications).agents(agents).build();
}
Also used : AgentDescriptor(io.codekvast.dashboard.dashboard.model.status.AgentDescriptor) CustomerData(io.codekvast.common.customer.CustomerData) Instant(java.time.Instant) Duration(java.time.Duration) EnvironmentStatusDescriptor(io.codekvast.dashboard.dashboard.model.status.EnvironmentStatusDescriptor) PricePlan(io.codekvast.common.customer.PricePlan) ApplicationDescriptor2(io.codekvast.dashboard.dashboard.model.status.ApplicationDescriptor2) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with CustomerData

use of io.codekvast.common.customer.CustomerData in project codekvast by crispab.

the class DashboardIntegrationTest method should_accept_valid_getCustomerDataByExternalId_trialPeriodExpired.

@Test
@Sql(scripts = "/sql/base-data.sql")
public void should_accept_valid_getCustomerDataByExternalId_trialPeriodExpired() {
    // see base-data.sql
    Instant now = Instant.parse("2017-09-21T16:21:19Z").plus(1, DAYS);
    CustomerData customerData = customerService.getCustomerDataByExternalId("test", "external-3");
    assertThat(customerData.getCustomerId(), is(3L));
    assertThat(customerData.isTrialPeriodExpired(now), is(true));
}
Also used : CustomerData(io.codekvast.common.customer.CustomerData) Instant(java.time.Instant) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Aggregations

CustomerData (io.codekvast.common.customer.CustomerData)48 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)28 Sql (org.springframework.test.context.jdbc.Sql)28 Test (org.junit.Test)22 Instant (java.time.Instant)13 Test (org.junit.jupiter.api.Test)10 Transactional (org.springframework.transaction.annotation.Transactional)9 PricePlanDefaults (io.codekvast.common.customer.PricePlanDefaults)4 PricePlan (io.codekvast.common.customer.PricePlan)3 GetStatusResponse (io.codekvast.dashboard.dashboard.model.status.GetStatusResponse)3 Timestamp (java.sql.Timestamp)3 CollectionStartedEvent (io.codekvast.common.messaging.model.CollectionStartedEvent)2 User (io.codekvast.login.model.User)2 CacheEvict (org.springframework.cache.annotation.CacheEvict)2 LicenseViolationException (io.codekvast.common.customer.LicenseViolationException)1 LicenseViolationEvent (io.codekvast.common.messaging.model.LicenseViolationEvent)1 GetMethodsFormData (io.codekvast.dashboard.dashboard.model.methods.GetMethodsFormData)1 AgentDescriptor (io.codekvast.dashboard.dashboard.model.status.AgentDescriptor)1 ApplicationDescriptor2 (io.codekvast.dashboard.dashboard.model.status.ApplicationDescriptor2)1 EnvironmentStatusDescriptor (io.codekvast.dashboard.dashboard.model.status.EnvironmentStatusDescriptor)1