Search in sources :

Example 36 with Assert.assertEquals

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());
}
Also used : HasValue(com.vaadin.flow.component.HasValue) Person(com.vaadin.flow.tests.data.bean.Person) HashMap(java.util.HashMap) Assert.assertSame(org.junit.Assert.assertSame) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IntegerRangeValidator(com.vaadin.flow.data.validator.IntegerRangeValidator) Map(java.util.Map) BindingBuilder(com.vaadin.flow.data.binder.Binder.BindingBuilder) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) StringToIntegerConverter(com.vaadin.flow.data.converter.StringToIntegerConverter) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) Objects(java.util.Objects) StringLengthValidator(com.vaadin.flow.data.validator.StringLengthValidator) Stream(java.util.stream.Stream) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) NotEmptyValidator(com.vaadin.flow.data.validator.NotEmptyValidator) Assert(org.junit.Assert) Binding(com.vaadin.flow.data.binder.Binder.Binding) TestTextField(com.vaadin.flow.data.binder.testcomponents.TestTextField) Sex(com.vaadin.flow.tests.data.bean.Sex) Matchers.containsString(org.hamcrest.Matchers.containsString) Assert.assertEquals(org.junit.Assert.assertEquals) NotEmptyValidator(com.vaadin.flow.data.validator.NotEmptyValidator) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestTextField(com.vaadin.flow.data.binder.testcomponents.TestTextField) Person(com.vaadin.flow.tests.data.bean.Person) Test(org.junit.Test)

Example 37 with Assert.assertEquals

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());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HasValue(com.vaadin.flow.component.HasValue) Person(com.vaadin.flow.tests.data.bean.Person) HashMap(java.util.HashMap) Assert.assertSame(org.junit.Assert.assertSame) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IntegerRangeValidator(com.vaadin.flow.data.validator.IntegerRangeValidator) Map(java.util.Map) BindingBuilder(com.vaadin.flow.data.binder.Binder.BindingBuilder) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) StringToIntegerConverter(com.vaadin.flow.data.converter.StringToIntegerConverter) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) Objects(java.util.Objects) StringLengthValidator(com.vaadin.flow.data.validator.StringLengthValidator) Stream(java.util.stream.Stream) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) NotEmptyValidator(com.vaadin.flow.data.validator.NotEmptyValidator) Assert(org.junit.Assert) Binding(com.vaadin.flow.data.binder.Binder.Binding) TestTextField(com.vaadin.flow.data.binder.testcomponents.TestTextField) Sex(com.vaadin.flow.tests.data.bean.Sex) Matchers.containsString(org.hamcrest.Matchers.containsString) Assert.assertEquals(org.junit.Assert.assertEquals) StringToIntegerConverter(com.vaadin.flow.data.converter.StringToIntegerConverter) Person(com.vaadin.flow.tests.data.bean.Person) Test(org.junit.Test)

Example 38 with Assert.assertEquals

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());
}
Also used : HasValue(com.vaadin.flow.component.HasValue) Person(com.vaadin.flow.tests.data.bean.Person) HashMap(java.util.HashMap) Assert.assertSame(org.junit.Assert.assertSame) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IntegerRangeValidator(com.vaadin.flow.data.validator.IntegerRangeValidator) Map(java.util.Map) BindingBuilder(com.vaadin.flow.data.binder.Binder.BindingBuilder) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) StringToIntegerConverter(com.vaadin.flow.data.converter.StringToIntegerConverter) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) Objects(java.util.Objects) StringLengthValidator(com.vaadin.flow.data.validator.StringLengthValidator) Stream(java.util.stream.Stream) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) NotEmptyValidator(com.vaadin.flow.data.validator.NotEmptyValidator) Assert(org.junit.Assert) Binding(com.vaadin.flow.data.binder.Binder.Binding) TestTextField(com.vaadin.flow.data.binder.testcomponents.TestTextField) Sex(com.vaadin.flow.tests.data.bean.Sex) Matchers.containsString(org.hamcrest.Matchers.containsString) Assert.assertEquals(org.junit.Assert.assertEquals) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Matchers.containsString(org.hamcrest.Matchers.containsString) Person(com.vaadin.flow.tests.data.bean.Person) Test(org.junit.Test)

Example 39 with Assert.assertEquals

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());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) StreamStoreFactory(io.pravega.controller.store.stream.StreamStoreFactory) Retry(io.pravega.common.util.Retry) SegmentHelper(io.pravega.controller.server.SegmentHelper) Exceptions(io.pravega.common.Exceptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) StoreException(io.pravega.controller.store.stream.StoreException) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) TaskMetadataStore(io.pravega.controller.store.task.TaskMetadataStore) TestingServerStarter(io.pravega.test.common.TestingServerStarter) After(org.junit.After) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TestingServer(org.apache.curator.test.TestingServer) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) HostMonitorConfigImpl(io.pravega.controller.store.host.impl.HostMonitorConfigImpl) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Mockito.doReturn(org.mockito.Mockito.doReturn) Before(org.junit.Before) ControllerService(io.pravega.controller.server.ControllerService) Assert.assertTrue(org.junit.Assert.assertTrue) CompletionException(java.util.concurrent.CompletionException) Test(org.junit.Test) HostStoreFactory(io.pravega.controller.store.host.HostStoreFactory) Executors(java.util.concurrent.Executors) TaskStoreFactory(io.pravega.controller.store.task.TaskStoreFactory) CuratorFramework(org.apache.curator.framework.CuratorFramework) Config(io.pravega.controller.util.Config) ConnectionFactoryImpl(io.pravega.client.netty.impl.ConnectionFactoryImpl) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) Assert(org.junit.Assert) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Futures(io.pravega.common.concurrent.Futures) Assert.assertEquals(org.junit.Assert.assertEquals) ClientConfig(io.pravega.client.ClientConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletionException(java.util.concurrent.CompletionException) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) StoreException(io.pravega.controller.store.stream.StoreException) Test(org.junit.Test)

Example 40 with Assert.assertEquals

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)));
}
Also used : Arrays(java.util.Arrays) AssertExtensions(io.pravega.test.common.AssertExtensions) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) TaskMetadataStore(io.pravega.controller.store.task.TaskMetadataStore) After(org.junit.After) URI(java.net.URI) LockFailedException(io.pravega.controller.store.task.LockFailedException) CreateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus) StartScaleResponse(io.pravega.controller.store.stream.StartScaleResponse) CompletionException(java.util.concurrent.CompletionException) UUID(java.util.UUID) State(io.pravega.controller.store.stream.tables.State) EqualsAndHashCode(lombok.EqualsAndHashCode) Collectors(java.util.stream.Collectors) TaggedResource(io.pravega.controller.store.task.TaggedResource) Executors(java.util.concurrent.Executors) Serializable(java.io.Serializable) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) CuratorFramework(org.apache.curator.framework.CuratorFramework) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) Resource(io.pravega.controller.store.task.Resource) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) StreamStoreFactory(io.pravega.controller.store.stream.StreamStoreFactory) SegmentHelper(io.pravega.controller.server.SegmentHelper) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) RetryOneTime(org.apache.curator.retry.RetryOneTime) TestingServerStarter(io.pravega.test.common.TestingServerStarter) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TestingServer(org.apache.curator.test.TestingServer) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) Segment(io.pravega.controller.store.stream.Segment) ConnectionFactory(io.pravega.client.netty.impl.ConnectionFactory) HostMonitorConfigImpl(io.pravega.controller.store.host.impl.HostMonitorConfigImpl) Before(org.junit.Before) SegmentHelperMock(io.pravega.controller.mocks.SegmentHelperMock) TestTasks(io.pravega.controller.task.Stream.TestTasks) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) HostStoreFactory(io.pravega.controller.store.host.HostStoreFactory) ExecutionException(java.util.concurrent.ExecutionException) Mockito(org.mockito.Mockito) AbstractMap(java.util.AbstractMap) TaskStoreFactory(io.pravega.controller.store.task.TaskStoreFactory) ConnectionFactoryImpl(io.pravega.client.netty.impl.ConnectionFactoryImpl) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) Data(lombok.Data) Assert(org.junit.Assert) Collections(java.util.Collections) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Assert.assertEquals(org.junit.Assert.assertEquals) ClientConfig(io.pravega.client.ClientConfig) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) ArrayList(java.util.ArrayList) AbstractMap(java.util.AbstractMap) ConnectionFactory(io.pravega.client.netty.impl.ConnectionFactory) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) Test(org.junit.Test)

Aggregations

Assert.assertEquals (org.junit.Assert.assertEquals)68 Assert (org.junit.Assert)67 Test (org.junit.Test)62 List (java.util.List)56 Before (org.junit.Before)42 Assert.assertTrue (org.junit.Assert.assertTrue)41 ArrayList (java.util.ArrayList)39 Assert.assertFalse (org.junit.Assert.assertFalse)39 Arrays (java.util.Arrays)29 Assert.assertNotNull (org.junit.Assert.assertNotNull)29 Collections (java.util.Collections)28 Map (java.util.Map)25 After (org.junit.After)25 HashMap (java.util.HashMap)24 Collectors (java.util.stream.Collectors)24 Assert.assertNull (org.junit.Assert.assertNull)23 Set (java.util.Set)17 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)15 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)15 SysSystemService (eu.bcvsolutions.idm.acc.service.api.SysSystemService)15