Search in sources :

Example 6 with CustomerData

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);
}
Also used : CustomerData(io.codekvast.common.customer.CustomerData) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with CustomerData

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;
}
Also used : User(io.codekvast.login.model.User) CustomerData(io.codekvast.common.customer.CustomerData) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 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).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 9 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 = 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 10 with CustomerData

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()));
}
Also used : CustomerData(io.codekvast.common.customer.CustomerData) GetMethodsFormData(io.codekvast.dashboard.dashboard.model.methods.GetMethodsFormData) Mockito.anyString(org.mockito.Mockito.anyString) PricePlanDefaults(io.codekvast.common.customer.PricePlanDefaults) Test(org.junit.jupiter.api.Test)

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