Search in sources :

Example 6 with Condition

use of org.assertj.core.api.Condition in project spring-cloud-stream by spring-cloud.

the class PartitionCapableBinderTests method testPartitionedModuleSpEL.

@Test
public void testPartitionedModuleSpEL() throws Exception {
    B binder = getBinder();
    CP consumerProperties = createConsumerProperties();
    consumerProperties.setConcurrency(2);
    consumerProperties.setInstanceIndex(0);
    consumerProperties.setInstanceCount(3);
    consumerProperties.setPartitioned(true);
    QueueChannel input0 = new QueueChannel();
    input0.setBeanName("test.input0S");
    Binding<MessageChannel> input0Binding = binder.bindConsumer(String.format("part%s0", getDestinationNameDelimiter()), "testPartitionedModuleSpEL", input0, consumerProperties);
    consumerProperties.setInstanceIndex(1);
    QueueChannel input1 = new QueueChannel();
    input1.setBeanName("test.input1S");
    Binding<MessageChannel> input1Binding = binder.bindConsumer(String.format("part%s0", getDestinationNameDelimiter()), "testPartitionedModuleSpEL", input1, consumerProperties);
    consumerProperties.setInstanceIndex(2);
    QueueChannel input2 = new QueueChannel();
    input2.setBeanName("test.input2S");
    Binding<MessageChannel> input2Binding = binder.bindConsumer(String.format("part%s0", getDestinationNameDelimiter()), "testPartitionedModuleSpEL", input2, consumerProperties);
    PP producerProperties = createProducerProperties();
    producerProperties.setPartitionKeyExpression(spelExpressionParser.parseExpression("payload"));
    producerProperties.setPartitionSelectorExpression(spelExpressionParser.parseExpression("hashCode()"));
    producerProperties.setPartitionCount(3);
    DirectChannel output = createBindableChannel("output", createProducerBindingProperties(producerProperties));
    output.setBeanName("test.output");
    Binding<MessageChannel> outputBinding = binder.bindProducer(String.format("part%s0", getDestinationNameDelimiter()), output, producerProperties);
    try {
        Object endpoint = extractEndpoint(outputBinding);
        checkRkExpressionForPartitionedModuleSpEL(endpoint);
    } catch (UnsupportedOperationException ignored) {
    }
    Message<String> message2 = MessageBuilder.withPayload("2").setHeader(IntegrationMessageHeaderAccessor.CORRELATION_ID, "foo").setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN).setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, 42).setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE, 43).build();
    output.send(message2);
    output.send(MessageBuilder.withPayload("1").setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN).build());
    output.send(MessageBuilder.withPayload("0").setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN).build());
    Message<?> receive0 = receive(input0);
    assertThat(receive0).isNotNull();
    Message<?> receive1 = receive(input1);
    assertThat(receive1).isNotNull();
    Message<?> receive2 = receive(input2);
    assertThat(receive2).isNotNull();
    Condition<Message<?>> correlationHeadersForPayload2 = new Condition<Message<?>>() {

        @Override
        public boolean matches(Message<?> value) {
            IntegrationMessageHeaderAccessor accessor = new IntegrationMessageHeaderAccessor(value);
            return "foo".equals(accessor.getCorrelationId()) && 42 == accessor.getSequenceNumber() && 43 == accessor.getSequenceSize();
        }
    };
    if (usesExplicitRouting()) {
        assertThat(receive0.getPayload()).isEqualTo("0".getBytes());
        assertThat(receive1.getPayload()).isEqualTo("1".getBytes());
        assertThat(receive2.getPayload()).isEqualTo("2".getBytes());
        assertThat(receive2).has(correlationHeadersForPayload2);
    } else {
        List<Message<?>> receivedMessages = Arrays.asList(receive0, receive1, receive2);
        assertThat(receivedMessages).extracting("payload").containsExactlyInAnyOrder("0".getBytes(), "1".getBytes(), "2".getBytes());
        Condition<Message<?>> payloadIs2 = new Condition<Message<?>>() {

            @Override
            public boolean matches(Message<?> value) {
                return value.getPayload().equals("2".getBytes());
            }
        };
        assertThat(receivedMessages).filteredOn(payloadIs2).areExactly(1, correlationHeadersForPayload2);
    }
    input0Binding.unbind();
    input1Binding.unbind();
    input2Binding.unbind();
    outputBinding.unbind();
}
Also used : Condition(org.assertj.core.api.Condition) QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) DirectChannel(org.springframework.integration.channel.DirectChannel) IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) MessageChannel(org.springframework.messaging.MessageChannel) Test(org.junit.Test)

Example 7 with Condition

use of org.assertj.core.api.Condition in project neo4j by neo4j.

the class ConnectionTrackingIT method killConnectionViaBolt.

private void killConnectionViaBolt(TrackedNetworkConnection trackedConnection) throws Exception {
    String id = trackedConnection.id();
    String user = trackedConnection.username();
    TransportConnection connection = connectSocketTo(neo4j.boltURI());
    try {
        connection.send(util.defaultAcceptedVersions()).send(auth("neo4j", NEO4J_USER_PWD)).send(util.defaultRunAutoCommitTx("CALL dbms.killConnection('" + id + "')"));
        assertThat(connection).satisfies(util.eventuallyReceivesSelectedProtocolVersion());
        assertThat(connection).satisfies(util.eventuallyReceives(msgSuccess(), msgSuccess(), msgRecord(eqRecord(new Condition<>(anyValue -> true, "any value"), new Condition<>(v -> v.equals(stringOrNoValue(user)), "user value"), new Condition<>(v -> v.equals(stringValue("Connection found")), "connection"))), msgSuccess()));
    } finally {
        connection.disconnect();
    }
}
Also used : HamcrestCondition(org.assertj.core.api.HamcrestCondition) Condition(org.assertj.core.api.Condition) TransportConnection(org.neo4j.bolt.testing.client.TransportConnection)

Example 8 with Condition

use of org.assertj.core.api.Condition in project Activiti by Activiti.

the class ProcessEngineAutoConfigurationTest method shouldAddAsyncPropertyValidatorWhenAsyncExecutorIsEnabled.

@Test
public void shouldAddAsyncPropertyValidatorWhenAsyncExecutorIsEnabled() {
    // given
    ActivitiProperties activitiProperties = new ActivitiProperties();
    activitiProperties.setAsyncExecutorActivate(false);
    SpringProcessEngineConfiguration conf = new SpringProcessEngineConfiguration(applicationUpgradeContextServiceMock);
    // when
    processEngineAutoConfiguration.addAsyncPropertyValidator(activitiProperties, conf);
    // then
    ProcessValidator processValidator = conf.getProcessValidator();
    assertThat(processValidator).isNotNull();
    assertThat(processValidator.getValidatorSets()).flatExtracting(ValidatorSet::getValidators).haveExactly(1, new Condition<>(validator -> validator instanceof AsyncPropertyValidator, "instance of AsyncPropertyValidator"));
}
Also used : SpringProcessEngineConfiguration(org.activiti.spring.SpringProcessEngineConfiguration) Test(org.junit.jupiter.api.Test) InjectMocks(org.mockito.InjectMocks) ApplicationUpgradeContextService(org.activiti.core.common.spring.project.ApplicationUpgradeContextService) BeforeEach(org.junit.jupiter.api.BeforeEach) MockitoAnnotations.initMocks(org.mockito.MockitoAnnotations.initMocks) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ValidatorSet(org.activiti.validation.validator.ValidatorSet) Condition(org.assertj.core.api.Condition) AsyncPropertyValidator(org.activiti.spring.boot.process.validation.AsyncPropertyValidator) ProcessValidator(org.activiti.validation.ProcessValidator) SpringProcessEngineConfiguration(org.activiti.spring.SpringProcessEngineConfiguration) ProcessValidator(org.activiti.validation.ProcessValidator) AsyncPropertyValidator(org.activiti.spring.boot.process.validation.AsyncPropertyValidator) Test(org.junit.jupiter.api.Test)

Example 9 with Condition

use of org.assertj.core.api.Condition in project syndesis-qe by syndesisio.

the class IntegrationSteps method exportIntegration.

@When("^export the integrat?ion$")
public void exportIntegration() throws InterruptedException {
    File exportedIntegrationFile = detailPage.exportIntegration();
    assertThat(exportedIntegrationFile).exists().isFile().has(new Condition<>(f -> f.length() > 0, "File size should be greater than 0"));
    ExportedIntegrationJSONUtil.testExportedFile(exportedIntegrationFile);
}
Also used : Arrays(java.util.Arrays) Then(io.cucumber.java.en.Then) ModalDialogPage(io.syndesis.qe.pages.ModalDialogPage) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Integrations(io.syndesis.qe.pages.integrations.Integrations) Autowired(org.springframework.beans.factory.annotation.Autowired) TimeoutException(java.util.concurrent.TimeoutException) ArrayList(java.util.ArrayList) CommonSteps(io.syndesis.qe.steps.CommonSteps) IntegrationStartingStatus(io.syndesis.qe.pages.integrations.IntegrationStartingStatus) DataMapper(io.syndesis.qe.pages.integrations.editor.add.steps.DataMapper) DataTable(io.cucumber.datatable.DataTable) TestConfiguration(io.syndesis.qe.TestConfiguration) CamelK(io.syndesis.qe.resource.impl.CamelK) ExportedIntegrationJSONUtil(io.syndesis.qe.utils.ExportedIntegrationJSONUtil) When(io.cucumber.java.en.When) Condition.visible(com.codeborne.selenide.Condition.visible) OpenShiftUtils(io.syndesis.qe.utils.OpenShiftUtils) Collectors(java.util.stream.Collectors) File(java.io.File) Selenide(com.codeborne.selenide.Selenide) SelenideElement(com.codeborne.selenide.SelenideElement) TimeUnit(java.util.concurrent.TimeUnit) ImportIntegration(io.syndesis.qe.pages.integrations.importt.ImportIntegration) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Assertions.fail(org.assertj.core.api.Assertions.fail) TestUtils(io.syndesis.qe.utils.TestUtils) ResourceFactory(io.syndesis.qe.resource.ResourceFactory) Condition(org.assertj.core.api.Condition) Details(io.syndesis.qe.pages.integrations.summary.Details) OpenShiftWaitUtils(io.syndesis.qe.wait.OpenShiftWaitUtils) File(java.io.File) When(io.cucumber.java.en.When)

Example 10 with Condition

use of org.assertj.core.api.Condition in project sonarqube by SonarSource.

the class EsClientProviderTest method es_client_provider_must_add_default_port_when_not_specified.

@Test
public void es_client_provider_must_add_default_port_when_not_specified() {
    settings.setProperty(CLUSTER_ENABLED.getKey(), true);
    settings.setProperty(CLUSTER_NODE_TYPE.getKey(), "application");
    settings.setProperty(CLUSTER_SEARCH_HOSTS.getKey(), format("%s,%s:8081", localhostHostname, localhostHostname));
    EsClient client = underTest.provide(settings.asConfig());
    RestHighLevelClient nativeClient = client.nativeClient();
    assertThat(nativeClient.getLowLevelClient().getNodes()).hasSize(2);
    Node node = nativeClient.getLowLevelClient().getNodes().get(0);
    assertThat(node.getHost().getAddress().getHostName()).isEqualTo(localhostHostname);
    assertThat(node.getHost().getPort()).isEqualTo(9001);
    node = nativeClient.getLowLevelClient().getNodes().get(1);
    assertThat(node.getHost().getAddress().getHostName()).isEqualTo(localhostHostname);
    assertThat(node.getHost().getPort()).isEqualTo(8081);
    assertThat(logTester.logs(LoggerLevel.INFO)).has(new Condition<>(s -> s.contains("Connected to remote Elasticsearch: [http://" + localhostHostname + ":9001, http://" + localhostHostname + ":8081]"), ""));
}
Also used : SEARCH_PORT(org.sonar.process.ProcessProperties.Property.SEARCH_PORT) ES_PORT(org.sonar.process.ProcessProperties.Property.ES_PORT) CLUSTER_ENABLED(org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Node(org.elasticsearch.client.Node) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) MapSettings(org.sonar.api.config.internal.MapSettings) String.format(java.lang.String.format) InetAddress(java.net.InetAddress) CLUSTER_NODE_TYPE(org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_TYPE) Rule(org.junit.Rule) LogTester(org.sonar.api.utils.log.LogTester) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) CLUSTER_SEARCH_HOSTS(org.sonar.process.ProcessProperties.Property.CLUSTER_SEARCH_HOSTS) Condition(org.assertj.core.api.Condition) CLUSTER_NAME(org.sonar.process.ProcessProperties.Property.CLUSTER_NAME) SEARCH_HOST(org.sonar.process.ProcessProperties.Property.SEARCH_HOST) Before(org.junit.Before) LoggerLevel(org.sonar.api.utils.log.LoggerLevel) Node(org.elasticsearch.client.Node) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) Test(org.junit.Test)

Aggregations

Condition (org.assertj.core.api.Condition)33 Test (org.junit.Test)19 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)16 List (java.util.List)9 Before (org.junit.Before)7 File (java.io.File)5 IOException (java.io.IOException)5 Arrays (java.util.Arrays)5 ExecutorService (java.util.concurrent.ExecutorService)4 Assertions (org.assertj.core.api.Assertions)4 Rule (org.junit.Rule)4 Mock (org.mockito.Mock)4 When (io.cucumber.java.en.When)3 SupportPage (io.syndesis.qe.pages.SupportPage)3 InetAddress (java.net.InetAddress)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 Enumeration (java.util.Enumeration)3 TimeUnit (java.util.concurrent.TimeUnit)3 ZipEntry (java.util.zip.ZipEntry)3