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));
}
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());
}
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()));
}
}
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));
}
Aggregations