Search in sources :

Example 1 with CustomerData

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)).source("source").collectionStartedAt(collectionStartedAt).trialPeriodEndsAt(trialPeriodEndsAt).build();
    when(customerService.getCustomerDataByCustomerId(eq(1L))).thenReturn(customerData);
    when(customerService.countMethods(eq(1L))).thenReturn(1000);
    // when
    GetStatusResponse status = webappService.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);
}
Also used : GetStatusResponse(io.codekvast.dashboard.dashboard.model.status.GetStatusResponse) CustomerData(io.codekvast.common.customer.CustomerData) Instant(java.time.Instant) PricePlanDefaults(io.codekvast.common.customer.PricePlanDefaults) Test(org.junit.Test)

Example 2 with CustomerData

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 = webappService.getStatus();
    // then
    assertNotNull(status);
    assertThat(status.getCollectedSinceMillis(), is(nullValue()));
    assertThat(status.getTrialPeriodEndsAtMillis(), is(nullValue()));
    assertThat(status.getTrialPeriodPercent(), is(nullValue()));
    assertThat(status.getTrialPeriodExpired(), is(false));
}
Also used : GetStatusResponse(io.codekvast.dashboard.dashboard.model.status.GetStatusResponse) CustomerData(io.codekvast.common.customer.CustomerData) PricePlanDefaults(io.codekvast.common.customer.PricePlanDefaults) Test(org.junit.Test)

Example 3 with CustomerData

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

the class CustomerServiceImplTest method should_return_sensible_CustomerData.

@Test
public void should_return_sensible_CustomerData() {
    CustomerData data = service.getCustomerDataByLicenseKey("key");
    assertThat(data.getCustomerId(), is(1L));
    assertThat(data.getPricePlan().getName(), is("TEST"));
}
Also used : CustomerData(io.codekvast.common.customer.CustomerData) Test(org.junit.Test)

Example 4 with CustomerData

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

the class MariadbIntegrationTest method should_accept_valid_getCustomerDataByCustomerId.

@Test
@Sql(scripts = "/sql/base-data.sql")
public void should_accept_valid_getCustomerDataByCustomerId() {
    CustomerData customerData = customerService.getCustomerDataByCustomerId(1L);
    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) Sql(org.springframework.test.context.jdbc.Sql)

Example 5 with CustomerData

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

the class MariadbIntegrationTest 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("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) Sql(org.springframework.test.context.jdbc.Sql)

Aggregations

CustomerData (io.codekvast.common.customer.CustomerData)16 Instant (java.time.Instant)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 Sql (org.springframework.test.context.jdbc.Sql)6 Test (org.junit.Test)5 Transactional (org.springframework.transaction.annotation.Transactional)4 PricePlanDefaults (io.codekvast.common.customer.PricePlanDefaults)3 GetStatusResponse (io.codekvast.dashboard.dashboard.model.status.GetStatusResponse)3 PricePlan (io.codekvast.common.customer.PricePlan)2 AgentDescriptor (io.codekvast.dashboard.dashboard.model.status.AgentDescriptor)1 UserDescriptor (io.codekvast.dashboard.dashboard.model.status.UserDescriptor)1 User (io.codekvast.login.model.User)1 Timestamp (java.sql.Timestamp)1 Duration (java.time.Duration)1 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)1 NonceExpiredException (org.springframework.security.web.authentication.www.NonceExpiredException)1