Search in sources :

Example 1 with GetStatusResponse

use of io.codekvast.dashboard.dashboard.model.status.GetStatusResponse 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);
}
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.jupiter.api.Test)

Example 2 with GetStatusResponse

use of io.codekvast.dashboard.dashboard.model.status.GetStatusResponse 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));
}
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.jupiter.api.Test)

Example 3 with GetStatusResponse

use of io.codekvast.dashboard.dashboard.model.status.GetStatusResponse in project codekvast by crispab.

the class MariadbIntegrationTest method should_getStatus_correctly.

@Test
@Sql(scripts = "/sql/base-data.sql")
public void should_getStatus_correctly() {
    // given
    Timestamps timestamps = new Timestamps().invoke();
    setSecurityContextCustomerId(1L);
    // when
    GetStatusResponse status = dashboardService.getStatus();
    // then
    assertThat(status.getPricePlan(), is("DEMO"));
    assertThat(status.getCollectionResolutionSeconds(), is(PricePlanDefaults.DEMO.getPublishIntervalSeconds()));
    assertThat(status.getMaxNumberOfAgents(), is(PricePlanDefaults.DEMO.getMaxNumberOfAgents()));
    assertThat(status.getMaxNumberOfMethods(), is(100));
    assertThat(status.getNumAgents(), is(4));
    assertThat(status.getNumLiveAgents(), is(2));
    assertThat(status.getNumLiveEnabledAgents(), is(1));
    assertThat(status.getAgents().get(0), is(AgentDescriptor.builder().agentAlive(true).agentLiveAndEnabled(true).agentVersion("agentVersion1").appName("app1").appVersion("v1").environment("env1").excludePackages("com.foobar.excluded1").hostname("hostname1").id(1L).methodVisibility("public").nextPollExpectedAtMillis(cutMillis(timestamps.plusOneMinute)).nextPublicationExpectedAtMillis(cutMillis(Timestamp.from(timestamps.minusTenMinutes.toInstant().plusSeconds(PricePlanDefaults.DEMO.getPublishIntervalSeconds())))).packages("com.foobar1").pollReceivedAtMillis(cutMillis(timestamps.minusTenMinutes)).publishedAtMillis(cutMillis(timestamps.minusTwoMinutes)).startedAtMillis(cutMillis(timestamps.minusThreeDaysPlus)).tags("tag1=t1,tag2=t2").build()));
    assertThat(status.getNumMethods(), is(10));
    assertThat(status.getCollectedSinceMillis(), is(nullValue()));
    assertThat(status.getCollectedDays(), is(nullValue()));
    assertThat(status.getUsers(), hasSize(2));
}
Also used : GetStatusResponse(io.codekvast.dashboard.dashboard.model.status.GetStatusResponse) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Sql(org.springframework.test.context.jdbc.Sql)

Example 4 with GetStatusResponse

use of io.codekvast.dashboard.dashboard.model.status.GetStatusResponse in project codekvast by crispab.

the class DashboardServiceImplTest method should_getStatus_after_trial_period.

@Test
public void should_getStatus_after_trial_period() {
    // given
    when(customerIdProvider.getCustomerId()).thenReturn(1L);
    PricePlanDefaults ppd = PricePlanDefaults.TEST;
    Instant collectionStartedAt = now.minus(3, DAYS);
    Instant trialPeriodEndsAt = now.minus(1, MILLIS);
    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.getCollectedSinceMillis(), is(collectionStartedAt.toEpochMilli()));
    assertThat(status.getTrialPeriodEndsAtMillis(), is(trialPeriodEndsAt.toEpochMilli()));
    assertThat(status.getTrialPeriodPercent(), is(100));
    assertThat(status.getTrialPeriodExpired(), is(true));
}
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.jupiter.api.Test)

Example 5 with GetStatusResponse

use of io.codekvast.dashboard.dashboard.model.status.GetStatusResponse in project codekvast by crispab.

the class DashboardIntegrationTest method should_getStatus_correctly.

@Test
@Sql(scripts = "/sql/base-data.sql")
public void should_getStatus_correctly() {
    // given
    Timestamps timestamps = new Timestamps(jdbcTemplate).invoke();
    setSecurityContextCustomerId(1L);
    // when
    GetStatusResponse status = dashboardService.getStatus();
    // then
    assertThat(status.getPricePlan(), is("DEMO"));
    assertThat(status.getCollectionResolutionSeconds(), is(PricePlanDefaults.DEMO.getPublishIntervalSeconds()));
    assertThat(status.getMaxNumberOfAgents(), is(PricePlanDefaults.DEMO.getMaxNumberOfAgents()));
    assertThat(status.getMaxNumberOfMethods(), is(100));
    assertThat(status.getNumAgents(), is(4));
    assertThat(status.getNumLiveAgents(), is(2));
    assertThat(status.getNumLiveEnabledAgents(), is(1));
    assertThat(status.getAgents().get(0), is(AgentDescriptor.builder().agentId(1L).agentAlive(true).agentLiveAndEnabled(true).agentVersion("agentVersion1").appName("app1").appVersion("v1").environment("env1").excludePackages("com.foobar.excluded1").hostname("hostname1").jvmId(1L).methodVisibility("public").nextPollExpectedAtMillis(cutMillis(timestamps.getInOneMinute())).nextPublicationExpectedAtMillis(cutMillis(Timestamp.from(timestamps.getTenMinutesAgo().toInstant().plusSeconds(PricePlanDefaults.DEMO.getPublishIntervalSeconds())))).packages("com.foobar1").pollReceivedAtMillis(cutMillis(timestamps.getTenMinutesAgo())).publishedAtMillis(cutMillis(timestamps.getTwoMinutesAgo())).startedAtMillis(cutMillis(timestamps.getAlmostThreeDaysAgo())).tags("tag1=t1,tag2=t2").build()));
    assertThat(status.getNumMethods(), is(10));
    assertThat(status.getCollectedSinceMillis(), is(nullValue()));
}
Also used : GetStatusResponse(io.codekvast.dashboard.dashboard.model.status.GetStatusResponse) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Aggregations

GetStatusResponse (io.codekvast.dashboard.dashboard.model.status.GetStatusResponse)6 CustomerData (io.codekvast.common.customer.CustomerData)3 PricePlanDefaults (io.codekvast.common.customer.PricePlanDefaults)3 Test (org.junit.jupiter.api.Test)3 Instant (java.time.Instant)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Sql (org.springframework.test.context.jdbc.Sql)2 Test (org.junit.Test)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1