Search in sources :

Example 1 with RandomStringUtils.randomAlphanumeric

use of org.apache.commons.lang.RandomStringUtils.randomAlphanumeric in project sonarqube by SonarSource.

the class SafeModeHealthActionTest method request_returns_status_and_causes_from_HealthChecker_checkNode_method.

@Test
public void request_returns_status_and_causes_from_HealthChecker_checkNode_method() {
    authenticateWithPasscode();
    Health.Status randomStatus = Health.Status.values()[new Random().nextInt(Health.Status.values().length)];
    Health.Builder builder = newHealthCheckBuilder().setStatus(randomStatus);
    IntStream.range(0, new Random().nextInt(5)).mapToObj(i -> RandomStringUtils.randomAlphanumeric(3)).forEach(builder::addCause);
    Health health = builder.build();
    when(healthChecker.checkNode()).thenReturn(health);
    TestRequest request = underTest.newRequest();
    System.HealthResponse healthResponse = request.executeProtobuf(System.HealthResponse.class);
    assertThat(healthResponse.getHealth().name()).isEqualTo(randomStatus.name());
    assertThat(health.getCauses()).isEqualTo(health.getCauses());
}
Also used : IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) RandomStringUtils.randomAlphanumeric(org.apache.commons.lang.RandomStringUtils.randomAlphanumeric) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TestRequest(org.sonar.server.ws.TestRequest) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Random(java.util.Random) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) System(org.sonarqube.ws.System) Health.newHealthCheckBuilder(org.sonar.server.health.Health.newHealthCheckBuilder) ThrowingCallable(org.assertj.core.api.ThrowableAssert.ThrowingCallable) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SystemPasscode(org.sonar.server.user.SystemPasscode) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) HealthChecker(org.sonar.server.health.HealthChecker) Health(org.sonar.server.health.Health) RandomStringUtils(org.apache.commons.lang.RandomStringUtils) TestResponse(org.sonar.server.ws.TestResponse) Mockito.mock(org.mockito.Mockito.mock) Random(java.util.Random) Health(org.sonar.server.health.Health) System(org.sonarqube.ws.System) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 2 with RandomStringUtils.randomAlphanumeric

use of org.apache.commons.lang.RandomStringUtils.randomAlphanumeric in project sonarqube by SonarSource.

the class HealthActionTest method request_returns_status_and_causes_from_HealthChecker_checkNode_method_when_standalone.

@Test
public void request_returns_status_and_causes_from_HealthChecker_checkNode_method_when_standalone() {
    authenticateWithRandomMethod();
    Health.Status randomStatus = Health.Status.values()[new Random().nextInt(Health.Status.values().length)];
    Health.Builder builder = newHealthCheckBuilder().setStatus(randomStatus);
    IntStream.range(0, new Random().nextInt(5)).mapToObj(i -> RandomStringUtils.randomAlphanumeric(3)).forEach(builder::addCause);
    Health health = builder.build();
    when(healthChecker.checkNode()).thenReturn(health);
    when(webServer.isStandalone()).thenReturn(true);
    TestRequest request = underTest.newRequest();
    System.HealthResponse healthResponse = request.executeProtobuf(System.HealthResponse.class);
    assertThat(healthResponse.getHealth().name()).isEqualTo(randomStatus.name());
    assertThat(health.getCauses()).isEqualTo(health.getCauses());
}
Also used : IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) RandomStringUtils.randomAlphanumeric(org.apache.commons.lang.RandomStringUtils.randomAlphanumeric) Date(java.util.Date) WebServer(org.sonar.server.platform.WebServer) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) GREEN(org.sonar.server.health.Health.GREEN) Random(java.util.Random) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) NodeHealth.newNodeHealthBuilder(org.sonar.process.cluster.health.NodeHealth.newNodeHealthBuilder) Health.newHealthCheckBuilder(org.sonar.server.health.Health.newHealthCheckBuilder) ThrowingCallable(org.assertj.core.api.ThrowableAssert.ThrowingCallable) WebService(org.sonar.api.server.ws.WebService) Collections.singleton(java.util.Collections.singleton) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) NodeDetails(org.sonar.process.cluster.health.NodeDetails) HealthChecker(org.sonar.server.health.HealthChecker) Health(org.sonar.server.health.Health) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) RandomStringUtils(org.apache.commons.lang.RandomStringUtils) UserSessionRule(org.sonar.server.tester.UserSessionRule) ImmutableSet(com.google.common.collect.ImmutableSet) Collections.emptySet(java.util.Collections.emptySet) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) TestRequest(org.sonar.server.ws.TestRequest) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) System(org.sonarqube.ws.System) ClusterHealth(org.sonar.server.health.ClusterHealth) NodeDetails.newNodeDetailsBuilder(org.sonar.process.cluster.health.NodeDetails.newNodeDetailsBuilder) List(java.util.List) Rule(org.junit.Rule) SystemPasscode(org.sonar.server.user.SystemPasscode) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) NodeHealth(org.sonar.process.cluster.health.NodeHealth) Collections(java.util.Collections) TestResponse(org.sonar.server.ws.TestResponse) Mockito.mock(org.mockito.Mockito.mock) Random(java.util.Random) Health(org.sonar.server.health.Health) ClusterHealth(org.sonar.server.health.ClusterHealth) NodeHealth(org.sonar.process.cluster.health.NodeHealth) System(org.sonarqube.ws.System) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Aggregations

Arrays (java.util.Arrays)2 Random (java.util.Random)2 IntStream (java.util.stream.IntStream)2 RandomStringUtils (org.apache.commons.lang.RandomStringUtils)2 RandomStringUtils.randomAlphanumeric (org.apache.commons.lang.RandomStringUtils.randomAlphanumeric)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2 ThrowingCallable (org.assertj.core.api.ThrowableAssert.ThrowingCallable)2 Test (org.junit.Test)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.when (org.mockito.Mockito.when)2 WebService (org.sonar.api.server.ws.WebService)2 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)2 Health (org.sonar.server.health.Health)2 Health.newHealthCheckBuilder (org.sonar.server.health.Health.newHealthCheckBuilder)2 HealthChecker (org.sonar.server.health.HealthChecker)2 SystemPasscode (org.sonar.server.user.SystemPasscode)2 TestRequest (org.sonar.server.ws.TestRequest)2 TestResponse (org.sonar.server.ws.TestResponse)2