use of org.junit.Assert.assertEquals in project flow by vaadin.
the class BinderTest method validationStatusHandler_onlyRunForChangedField.
@Test
public void validationStatusHandler_onlyRunForChangedField() {
TestTextField firstNameField = new TestTextField();
TestTextField lastNameField = new TestTextField();
AtomicInteger invokes = new AtomicInteger();
binder.forField(firstNameField).withValidator(new NotEmptyValidator<>("")).withValidationStatusHandler(validationStatus -> invokes.addAndGet(1)).bind(Person::getFirstName, Person::setFirstName);
binder.forField(lastNameField).withValidator(new NotEmptyValidator<>("")).bind(Person::getLastName, Person::setLastName);
binder.setBean(item);
// setting the bean causes 2:
Assert.assertEquals(2, invokes.get());
lastNameField.setValue("");
Assert.assertEquals(2, invokes.get());
firstNameField.setValue("");
Assert.assertEquals(3, invokes.get());
binder.removeBean();
Person person = new Person();
person.setFirstName("a");
person.setLastName("a");
binder.readBean(person);
// reading from a bean causes 2:
Assert.assertEquals(5, invokes.get());
lastNameField.setValue("");
Assert.assertEquals(5, invokes.get());
firstNameField.setValue("");
Assert.assertEquals(6, invokes.get());
}
use of org.junit.Assert.assertEquals in project flow by vaadin.
the class BinderTest method withConverter_disablesDefaulNullRepresentation.
@Test
public void withConverter_disablesDefaulNullRepresentation() {
Integer customNullConverter = 0;
binder.forField(ageField).withNullRepresentation("foo").withConverter(new StringToIntegerConverter("")).withConverter(age -> age, age -> age == null ? customNullConverter : age).bind(Person::getSalary, Person::setSalary);
binder.setBean(item);
Assert.assertEquals(customNullConverter.toString(), ageField.getValue());
Integer salary = 11;
ageField.setValue(salary.toString());
Assert.assertEquals(11, salary.intValue());
}
use of org.junit.Assert.assertEquals in project flow by vaadin.
the class BinderTest method beanBinder_withConverter_nullRepresentationIsNotDisabled.
@Test
public void beanBinder_withConverter_nullRepresentationIsNotDisabled() {
String customNullPointerRepresentation = "foo";
Binder<Person> binder = new Binder<>(Person.class);
binder.forField(nameField).withConverter(value -> value, value -> value == null ? customNullPointerRepresentation : value).bind("firstName");
Person person = new Person();
binder.setBean(person);
Assert.assertEquals(customNullPointerRepresentation, nameField.getValue());
}
use of org.junit.Assert.assertEquals in project pravega by pravega.
the class IntermittentCnxnFailureTest method createStreamTest.
@Test
public void createStreamTest() throws Exception {
final ScalingPolicy policy1 = ScalingPolicy.fixed(2);
final StreamConfiguration configuration1 = StreamConfiguration.builder().scope(SCOPE).streamName(stream1).scalingPolicy(policy1).build();
// start stream creation in background/asynchronously.
// the connection to server will fail and should be retried
controllerService.createStream(configuration1, System.currentTimeMillis());
// we should get illegalStateException
try {
Retry.withExpBackoff(10, 10, 4).retryingOn(StoreException.DataNotFoundException.class).throwingOn(IllegalStateException.class).run(() -> {
Futures.getAndHandleExceptions(streamStore.getConfiguration(SCOPE, stream1, null, executor), CompletionException::new);
return null;
});
} catch (CompletionException ex) {
Assert.assertEquals(Exceptions.unwrap(ex).getMessage(), "stream state unknown");
assertEquals(Exceptions.unwrap(ex).getClass(), IllegalStateException.class);
}
// Mock createSegment to return success.
doReturn(CompletableFuture.completedFuture(true)).when(segmentHelperMock).createSegment(anyString(), anyString(), anyInt(), any(), any(), any(), any());
AtomicBoolean result = new AtomicBoolean(false);
Retry.withExpBackoff(10, 10, 4).retryingOn(IllegalStateException.class).throwingOn(RuntimeException.class).run(() -> {
Futures.getAndHandleExceptions(streamStore.getConfiguration(SCOPE, stream1, null, executor).thenAccept(configuration -> result.set(configuration.equals(configuration1))), CompletionException::new);
return null;
});
assertTrue(result.get());
}
use of org.junit.Assert.assertEquals in project pravega by pravega.
the class TaskTest method testStreamTaskSweeping.
@Test(timeout = 10000)
public void testStreamTaskSweeping() {
final String stream = "testPartialCreationStream";
final String deadHost = "deadHost";
final int initialSegments = 2;
final ScalingPolicy policy1 = ScalingPolicy.fixed(initialSegments);
final StreamConfiguration configuration1 = StreamConfiguration.builder().scope(SCOPE).streamName(stream1).scalingPolicy(policy1).build();
final ArrayList<Integer> sealSegments = new ArrayList<>();
sealSegments.add(0);
final ArrayList<AbstractMap.SimpleEntry<Double, Double>> newRanges = new ArrayList<>();
newRanges.add(new AbstractMap.SimpleEntry<>(0.0, 0.25));
newRanges.add(new AbstractMap.SimpleEntry<>(0.25, 0.5));
// Create objects.
StreamMetadataTasks mockStreamTasks = new StreamMetadataTasks(streamStore, hostStore, taskMetadataStore, segmentHelperMock, executor, deadHost, Mockito.mock(ConnectionFactory.class), false, "");
mockStreamTasks.setCreateIndexOnlyMode();
TaskSweeper sweeper = new TaskSweeper(taskMetadataStore, HOSTNAME, executor, streamMetadataTasks);
// Create stream test.
completePartialTask(mockStreamTasks.createStream(SCOPE, stream, configuration1, System.currentTimeMillis()), deadHost, sweeper);
Assert.assertEquals(initialSegments, streamStore.getActiveSegments(SCOPE, stream, null, executor).join().size());
List<StreamConfiguration> streams = streamStore.listStreamsInScope(SCOPE).join();
Assert.assertTrue(streams.stream().allMatch(x -> !x.getStreamName().equals(stream)));
}
Aggregations