Search in sources :

Example 21 with Condition

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

the class EsClientProviderTest method connection_to_local_es_when_cluster_mode_is_disabled.

@Test
public void connection_to_local_es_when_cluster_mode_is_disabled() {
    settings.setProperty(CLUSTER_ENABLED.getKey(), false);
    settings.setProperty(SEARCH_HOST.getKey(), localhostHostname);
    settings.setProperty(SEARCH_PORT.getKey(), 9000);
    settings.setProperty(ES_PORT.getKey(), 8080);
    EsClient client = underTest.provide(settings.asConfig());
    RestHighLevelClient nativeClient = client.nativeClient();
    assertThat(nativeClient.getLowLevelClient().getNodes()).hasSize(1);
    Node node = nativeClient.getLowLevelClient().getNodes().get(0);
    assertThat(node.getHost().getAddress().getHostName()).isEqualTo(localhostHostname);
    assertThat(node.getHost().getPort()).isEqualTo(9000);
    assertThat(logTester.logs(LoggerLevel.INFO)).has(new Condition<>(s -> s.contains("Connected to local Elasticsearch: [http://" + localhostHostname + ":9000]"), ""));
}
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)

Example 22 with Condition

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

the class EsClientProviderTest method connection_to_remote_es_nodes_when_cluster_mode_is_enabled_and_local_es_is_disabled.

@Test
public void connection_to_remote_es_nodes_when_cluster_mode_is_enabled_and_local_es_is_disabled() {
    settings.setProperty(CLUSTER_ENABLED.getKey(), true);
    settings.setProperty(CLUSTER_NODE_TYPE.getKey(), "application");
    settings.setProperty(CLUSTER_SEARCH_HOSTS.getKey(), format("%s:8080,%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(8080);
    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 + ":8080, 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)

Example 23 with Condition

use of org.assertj.core.api.Condition in project rabbitmq-java-client by rabbitmq.

the class JavaNioTest method byteBufferFactory.

@Test
public void byteBufferFactory() throws Exception {
    ConnectionFactory cf = new ConnectionFactory();
    cf.useNio();
    int baseCapacity = 32768;
    NioParams nioParams = new NioParams();
    nioParams.setReadByteBufferSize(baseCapacity / 2);
    nioParams.setWriteByteBufferSize(baseCapacity / 4);
    List<ByteBuffer> byteBuffers = new CopyOnWriteArrayList<>();
    cf.setNioParams(nioParams.setByteBufferFactory(new DefaultByteBufferFactory(capacity -> {
        ByteBuffer bb = ByteBuffer.allocate(capacity);
        byteBuffers.add(bb);
        return bb;
    })));
    try (Connection c = cf.newConnection()) {
        sendAndVerifyMessage(c, 100);
    }
    assertThat(byteBuffers).hasSize(2);
    Condition<Integer> condition = new Condition<>(c -> c == nioParams.getReadByteBufferSize() || c == nioParams.getWriteByteBufferSize(), "capacity set by factory");
    assertThat(byteBuffers.get(0).capacity()).is(condition);
    assertThat(byteBuffers.get(1).capacity()).is(condition);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Condition(org.assertj.core.api.Condition) NioParams(com.rabbitmq.client.impl.nio.NioParams) DefaultByteBufferFactory(com.rabbitmq.client.impl.nio.DefaultByteBufferFactory) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 24 with Condition

use of org.assertj.core.api.Condition in project project-build-plugin by axonivy.

the class TestDeployToRunningEngine method canDeployIar.

@Test
public void canDeployIar() throws Exception {
    deployMojo.deployToEngineApplication = "Portal";
    File deployedIar = getTarget(deployMojo.deployFile, deployMojo);
    File deployedIarFlagFile = new File(deployedIar.getParent(), deployedIar.getName() + ".deployed");
    File deployedIarLogFile = new File(deployedIar.getParent(), deployedIar.getName() + ".deploymentLog");
    Executor startedProcess = null;
    try {
        startedProcess = mojo.startEngine();
        deployMojo.execute();
        assertThat(deployedIar).doesNotExist();
        assertThat(deployedIarFlagFile).exists();
        assertThat(deployedIarLogFile).exists();
        assertThat(linesOf(deployedIarLogFile)).haveAtLeast(1, new Condition<>(s -> s.contains("Deploying users ..."), ""));
    } finally {
        kill(startedProcess);
    }
}
Also used : PrintStream(java.io.PrintStream) Executor(org.apache.commons.exec.Executor) StartTestEngineMojo(ch.ivyteam.ivy.maven.test.StartTestEngineMojo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Server(org.apache.maven.settings.Server) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ProjectMojoRule(ch.ivyteam.ivy.maven.ProjectMojoRule) File(java.io.File) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Rule(org.junit.Rule) BaseEngineProjectMojoTest(ch.ivyteam.ivy.maven.BaseEngineProjectMojoTest) EngineControl(ch.ivyteam.ivy.maven.engine.EngineControl) After(org.junit.After) Condition(org.assertj.core.api.Condition) DeployMethod(ch.ivyteam.ivy.maven.deploy.DeployToEngineMojo.DeployMethod) Assertions.linesOf(org.assertj.core.api.Assertions.linesOf) Before(org.junit.Before) Executor(org.apache.commons.exec.Executor) File(java.io.File) Test(org.junit.Test) BaseEngineProjectMojoTest(ch.ivyteam.ivy.maven.BaseEngineProjectMojoTest)

Example 25 with Condition

use of org.assertj.core.api.Condition in project spring-data-jdbc by spring-projects.

the class JdbcRepositoryPropertyConversionIntegrationTests method representingTheSameAs.

private Condition<Date> representingTheSameAs(Date other) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
    String expected = format.format(other);
    return new Condition<>(date -> format.format(date).equals(expected), expected);
}
Also used : Condition(org.assertj.core.api.Condition) SimpleDateFormat(java.text.SimpleDateFormat)

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