use of org.ligoj.bootstrap.core.validation.ValidationJsonException in project ligoj-api by ligoj.
the class ParameterValueResource method checkCompletude.
/**
* Check optional but secure assertions.
*/
private void checkCompletude(final BasicParameterValueVo vo, final Parameter parameter) {
Arrays.stream(new Supplier<?>[] { vo::getText, vo::getBool, vo::getDate, vo::getIndex, vo::getInteger, vo::getTags, vo::getSelections }).map(Supplier::get).filter(Objects::nonNull).skip(1).findFirst().ifPresent(e -> {
final ValidationJsonException exception = new ValidationJsonException();
exception.addError(parameter.getId(), "Too many values");
throw exception;
});
}
use of org.ligoj.bootstrap.core.validation.ValidationJsonException in project ligoj-api by ligoj.
the class CurlCacheTokenTest method getTokenCache.
@Test
public void getTokenCache() {
final Object sync = new Object();
AtomicInteger counter = new AtomicInteger();
Assertions.assertEquals("ok", cacheToken.getTokenCache(sync, "key", k -> {
if (counter.incrementAndGet() == 2) {
return "ok";
}
return null;
}, 2, () -> new ValidationJsonException()));
Assertions.assertEquals(2, counter.get());
}
use of org.ligoj.bootstrap.core.validation.ValidationJsonException in project ligoj-api by ligoj.
the class MatcherUtilTest method assertThrowsValidationNotSameProperty.
@Test
public void assertThrowsValidationNotSameProperty() {
final ValidationJsonException violationException = new ValidationJsonException();
final List<Map<String, Serializable>> errors = new ArrayList<>();
final Map<String, Serializable> error = new HashMap<>();
error.put("rule", "any");
errors.add(error);
violationException.getErrors().put("any", errors);
Assertions.assertEquals("expected: <firstName> but was: <[any]>", Assertions.assertThrows(AssertionFailedError.class, () -> {
MatcherUtil.assertThrows(violationException, "firstName", "message");
}).getMessage());
}
use of org.ligoj.bootstrap.core.validation.ValidationJsonException in project ligoj-api by ligoj.
the class CurlCacheTokenTest method getTokenCacheFailed.
@Test
public void getTokenCacheFailed() {
final Object sync = new Object();
AtomicInteger counter = new AtomicInteger();
Assertions.assertThrows(ValidationJsonException.class, () -> {
Assertions.assertEquals("", cacheToken.getTokenCache(sync, "key", k -> {
counter.incrementAndGet();
return null;
}, 2, () -> new ValidationJsonException()));
});
Assertions.assertEquals(2, counter.get());
Assertions.assertEquals("ok", cacheToken.getTokenCache(sync, "key", k -> {
if (counter.incrementAndGet() == 4) {
return "ok";
}
return null;
}, 2, () -> new ValidationJsonException()));
Assertions.assertEquals(4, counter.get());
}
use of org.ligoj.bootstrap.core.validation.ValidationJsonException in project ligoj-api by ligoj.
the class MatcherUtilTest method assertThrowsValidationNotSameMessage.
@Test
public void assertThrowsValidationNotSameMessage() {
final ValidationJsonException violationException = new ValidationJsonException();
final List<Map<String, Serializable>> errors = new ArrayList<>();
final Map<String, Serializable> error = new HashMap<>();
error.put("rule", "any");
errors.add(error);
violationException.getErrors().put("firstName", errors);
Assertions.assertEquals("expected: <message> but was: <any>", Assertions.assertThrows(AssertionFailedError.class, () -> {
MatcherUtil.assertThrows(violationException, "firstName", "message");
}).getMessage());
}
Aggregations