Search in sources :

Example 1 with LicenseViolationException

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

the class CustomerServiceImplTest method should_reject_too_many_methods.

@Test
public void should_reject_too_many_methods() {
    // Given
    when(jdbcTemplate.queryForObject(startsWith("SELECT COUNT(1) FROM methods WHERE"), eq(Long.class), eq(1L))).thenReturn(50_000L);
    // When
    LicenseViolationException exception = assertThrows(LicenseViolationException.class, () -> service.assertDatabaseSize(1L));
    // Then
    assertThat(exception.getMessage(), containsString("Too many methods"));
    assertThat(exception.getMessage(), containsString("50000"));
    verify(eventService).send(any(LicenseViolationEvent.class));
}
Also used : LicenseViolationException(io.codekvast.common.customer.LicenseViolationException) LicenseViolationEvent(io.codekvast.common.messaging.model.LicenseViolationEvent) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Test(org.junit.jupiter.api.Test)

Example 2 with LicenseViolationException

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

the class AgentControllerTest method getConfig1_should_reject_invalid_licenseKey.

@Test
public void getConfig1_should_reject_invalid_licenseKey() throws Exception {
    when(agentService.getConfig(any(GetConfigRequest1.class))).thenThrow(new LicenseViolationException("foobar"));
    mockMvc.perform(post(V1_POLL_CONFIG).content(gson.toJson(GetConfigRequest1.sample())).contentType(APPLICATION_JSON_UTF8)).andExpect(status().isForbidden());
}
Also used : LicenseViolationException(io.codekvast.common.customer.LicenseViolationException) GetConfigRequest1(io.codekvast.javaagent.model.v1.rest.GetConfigRequest1) Test(org.junit.Test)

Example 3 with LicenseViolationException

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

the class CustomerServiceImpl method doAssertNumberOfMethods.

private void doAssertNumberOfMethods(CustomerData customerData, int numberOfMethods) {
    logger.debug("Asserting {} methods for {}", numberOfMethods, customerData);
    PricePlan pp = customerData.getPricePlan();
    if (numberOfMethods > pp.getMaxMethods()) {
        eventService.send(LicenseViolationEvent.builder().customerId(customerData.getCustomerId()).plan(pp.getName()).attemptedMethods(numberOfMethods).defaultMaxMethods(PricePlanDefaults.ofDatabaseName(pp.getName()).getMaxMethods()).effectiveMaxMethods(pp.getMaxMethods()).build());
        throw new LicenseViolationException(String.format("Too many methods: %d. The plan '%s' has a limit of %d methods", numberOfMethods, pp.getName(), pp.getMaxMethods()));
    }
}
Also used : LicenseViolationException(io.codekvast.common.customer.LicenseViolationException) PricePlan(io.codekvast.common.customer.PricePlan)

Example 4 with LicenseViolationException

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

the class CustomerServiceImplTest method should_reject_too_big_codeBasePublication.

@Test
public void should_reject_too_big_codeBasePublication() {
    CustomerData customerData = service.getCustomerDataByLicenseKey("");
    LicenseViolationException exception = assertThrows(LicenseViolationException.class, () -> service.assertPublicationSize(customerData, 100_000));
    assertThat(exception.getMessage(), containsString("100000"));
    verify(eventService).send(any(LicenseViolationEvent.class));
}
Also used : CustomerData(io.codekvast.common.customer.CustomerData) LicenseViolationException(io.codekvast.common.customer.LicenseViolationException) LicenseViolationEvent(io.codekvast.common.messaging.model.LicenseViolationEvent) Test(org.junit.jupiter.api.Test)

Aggregations

LicenseViolationException (io.codekvast.common.customer.LicenseViolationException)4 LicenseViolationEvent (io.codekvast.common.messaging.model.LicenseViolationEvent)2 Test (org.junit.jupiter.api.Test)2 CustomerData (io.codekvast.common.customer.CustomerData)1 PricePlan (io.codekvast.common.customer.PricePlan)1 GetConfigRequest1 (io.codekvast.javaagent.model.v1.rest.GetConfigRequest1)1 Test (org.junit.Test)1 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)1