org.assertj.core.groups.Tuple Java Examples

The following examples show how to use org.assertj.core.groups.Tuple. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AppnexusBidderTest.java    From prebid-server-java with Apache License 2.0 7 votes vote down vote up
@Test
public void makeHttpRequestsShouldSetPlacementIdAndTrafficSourceCodeIfPresent() {
    // given
    final BidRequest bidRequest = givenBidRequest(
            identity(),
            impBuilder -> impBuilder.banner(Banner.builder().build()),
            extImpAppnexusBuilder -> extImpAppnexusBuilder.placementId(20).trafficSourceCode("tsc").keywords(asList(
                    AppnexusKeyVal.of("key1", asList("abc", "def")),
                    AppnexusKeyVal.of("key2", asList("123", "456")))));

    // when
    final Result<List<HttpRequest<BidRequest>>> result = appnexusBidder.makeHttpRequests(bidRequest);

    // then
    assertThat(result.getValue()).hasSize(1)
            .extracting(httpRequest -> mapper.readValue(httpRequest.getBody(), BidRequest.class))
            .extracting(BidRequest::getImp)
            .extracting(imps -> imps.get(0).getExt())
            .extracting(jsonNodes -> mapper.treeToValue(jsonNodes, AppnexusImpExt.class))
            .extracting(AppnexusImpExt::getAppnexus)
            .extracting(
                    AppnexusImpExtAppnexus::getPlacementId,
                    AppnexusImpExtAppnexus::getTrafficSourceCode,
                    AppnexusImpExtAppnexus::getKeywords)
            .containsOnly(Tuple.tuple(20, "tsc", "key1=abc,key1=def,key2=123,key2=456"));
}
 
Example #2
Source File: XunitXmlPluginTest.java    From allure2 with Apache License 2.0 6 votes vote down vote up
@Test
void shouldCreateTest() throws Exception {
    process(
            "xunitdata/passed-test.xml",
            "passed-test.xml"
    );

    final ArgumentCaptor<TestResult> captor = ArgumentCaptor.forClass(TestResult.class);
    verify(visitor, times(1)).visitTestResult(captor.capture());

    assertThat(captor.getAllValues())
            .hasSize(1)
            .extracting(TestResult::getName, TestResult::getHistoryId, TestResult::getStatus)
            .containsExactlyInAnyOrder(
                    Tuple.tuple("passedTest", "Some test", Status.PASSED)
            );
}
 
Example #3
Source File: GetMailboxesMethodTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
public void getMailboxesShouldNotExposeRoleOfSharedMailboxToSharee() throws Exception {
    MailboxSession userSession = mailboxManager.createSystemSession(USERNAME);
    MailboxSession user2Session = mailboxManager.createSystemSession(USERNAME2);

    MailboxPath mailboxPath = MailboxPath.forUser(USERNAME, "INBOX");
    mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "INBOX"), userSession);

    MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Lookup);
    MailboxACL.ACLCommand command = MailboxACL.command().forUser(Username.of(USERNAME2.asString())).rights(rights).asReplacement();
    mailboxManager.applyRightsCommand(mailboxPath, command, userSession);

    GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder()
        .build();

    List<JmapResponse> getMailboxesResponse = getMailboxesMethod.processToStream(getMailboxesRequest, methodCallId, user2Session).collect(Collectors.toList());

    assertThat(getMailboxesResponse)
        .hasSize(1)
        .extracting(JmapResponse::getResponse)
        .hasOnlyElementsOfType(GetMailboxesResponse.class)
        .extracting(GetMailboxesResponse.class::cast)
        .flatExtracting(GetMailboxesResponse::getList)
        .extracting(Mailbox::getName, Mailbox::getRole)
        .containsOnly(Tuple.tuple("INBOX", Optional.empty()));
}
 
Example #4
Source File: ItinerarySelectionCommandTest.java    From dddsample-core with MIT License 6 votes vote down vote up
@Test
public void testBind() {
    command = new RouteAssignmentCommand();
    request = new MockHttpServletRequest();

    request.addParameter("legs[0].voyageNumber", "CM01");
    request.addParameter("legs[0].fromUnLocode", "AAAAA");
    request.addParameter("legs[0].toUnLocode", "BBBBB");

    request.addParameter("legs[1].voyageNumber", "CM02");
    request.addParameter("legs[1].fromUnLocode", "CCCCC");
    request.addParameter("legs[1].toUnLocode", "DDDDD");

    request.addParameter("trackingId", "XYZ");

    ServletRequestDataBinder binder = new ServletRequestDataBinder(command);
    binder.bind(request);

    assertThat(command.getLegs()).hasSize(2).extracting("voyageNumber", "fromUnLocode", "toUnLocode")
            .containsAll(Arrays.asList(Tuple.tuple("CM01", "AAAAA", "BBBBB"), Tuple.tuple("CM02", "CCCCC", "DDDDD")));

    assertThat(command.getTrackingId()).isEqualTo("XYZ");
}
 
Example #5
Source File: GetMailboxesMethodTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void getMailboxesShouldReturnEmptyMailboxByDefault() throws MailboxException {
    MailboxPath mailboxPath = MailboxPath.forUser(USERNAME, "name");
    MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME);
    mailboxManager.createMailbox(mailboxPath, mailboxSession);

    GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder()
            .build();

    List<JmapResponse> getMailboxesResponse = getMailboxesMethod.processToStream(getMailboxesRequest, methodCallId, mailboxSession).collect(Collectors.toList());

    assertThat(getMailboxesResponse)
            .hasSize(1)
            .extracting(JmapResponse::getResponse)
            .hasOnlyElementsOfType(GetMailboxesResponse.class)
            .extracting(GetMailboxesResponse.class::cast)
            .flatExtracting(GetMailboxesResponse::getList)
            .extracting(Mailbox::getTotalMessages, Mailbox::getUnreadMessages)
            .containsOnly(Tuple.tuple(Number.ZERO, Number.ZERO));
}
 
Example #6
Source File: GetMailboxesMethodTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void getMailboxesShouldReturnOnlyMailboxesOfCurrentUserWhenAvailable() throws Exception {
    MailboxPath mailboxPathToReturn = MailboxPath.forUser(USERNAME, "mailboxToReturn");
    MailboxPath mailboxPathtoSkip = MailboxPath.forUser(USERNAME2, "mailboxToSkip");
    MailboxSession userSession = mailboxManager.createSystemSession(USERNAME);
    MailboxSession user2Session = mailboxManager.createSystemSession(USERNAME2);
    mailboxManager.createMailbox(mailboxPathToReturn, userSession);
    mailboxManager.createMailbox(mailboxPathtoSkip, user2Session);

    GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder()
            .build();

    List<JmapResponse> getMailboxesResponse = getMailboxesMethod.processToStream(getMailboxesRequest, methodCallId, userSession).collect(Collectors.toList());

    assertThat(getMailboxesResponse)
            .hasSize(1)
            .extracting(JmapResponse::getResponse)
            .hasOnlyElementsOfType(GetMailboxesResponse.class)
            .extracting(GetMailboxesResponse.class::cast)
            .flatExtracting(GetMailboxesResponse::getList)
            .extracting(Mailbox::getId, Mailbox::getName)
            .containsOnly(Tuple.tuple(InMemoryId.of(1), mailboxPathToReturn.getName()));
}
 
Example #7
Source File: PeriodicalHealthChecksTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
void startShouldLogWhenMultipleHealthChecks() {
    ListAppender<ILoggingEvent> loggingEvents = getListAppenderForClass(PeriodicalHealthChecks.class);

    TestingHealthCheck unhealthy = () -> Mono.just(Result.unhealthy(TestingHealthCheck.COMPONENT_NAME, "cause"));
    TestingHealthCheck degraded = () -> Mono.just(Result.degraded(TestingHealthCheck.COMPONENT_NAME, "cause"));
    TestingHealthCheck healthy = () -> Mono.just(Result.healthy(TestingHealthCheck.COMPONENT_NAME));

    testee = new PeriodicalHealthChecks(ImmutableSet.of(unhealthy, degraded, healthy),
        scheduler,
        new PeriodicalHealthChecksConfiguration(PERIOD));
    testee.start();

    scheduler.advanceTimeBy(PERIOD);

    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(loggingEvents.list).hasSize(2);
        softly.assertThat(loggingEvents.list.stream()
            .map(event -> new Tuple(event.getLevel(), event.getFormattedMessage()))
            .collect(Guavate.toImmutableList()))
            .containsExactlyInAnyOrder(
                new Tuple(Level.ERROR, "UNHEALTHY: testing : cause"),
                new Tuple(Level.WARN, "DEGRADED: testing : cause"));
    });
}
 
Example #8
Source File: JunitXmlPluginTest.java    From allure2 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
void shouldAddLabels() throws Exception {
    process(
            "junitdata/TEST-test.SampleTest.xml", "TEST-test.SampleTest.xml"
    );

    final ArgumentCaptor<TestResult> captor = ArgumentCaptor.forClass(TestResult.class);
    verify(visitor, times(1)).visitTestResult(captor.capture());

    assertThat(captor.getAllValues())
            .hasSize(1)
            .flatExtracting(TestResult::getLabels)
            .extracting(Label::getName, Label::getValue)
            .containsExactlyInAnyOrder(
                    Tuple.tuple(LabelName.SUITE.value(), "test.SampleTest"),
                    Tuple.tuple(LabelName.PACKAGE.value(), "test.SampleTest"),
                    Tuple.tuple(LabelName.TEST_CLASS.value(), "test.SampleTest"),
                    Tuple.tuple(LabelName.RESULT_FORMAT.value(), JunitXmlPlugin.JUNIT_RESULTS_FORMAT)
            );
}
 
Example #9
Source File: XunitXmlPluginTest.java    From allure2 with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@MethodSource("data")
void shouldSetStatusDetails(final String resource,
                            final String fileName,
                            final String message,
                            final String trace) throws Exception {
    process(resource, fileName);

    final ArgumentCaptor<TestResult> captor = ArgumentCaptor.forClass(TestResult.class);
    verify(visitor, times(1)).visitTestResult(captor.capture());

    assertThat(captor.getAllValues())
            .hasSize(1)
            .extracting(TestResult::getStatusMessage, TestResult::getStatusTrace)
            .containsExactlyInAnyOrder(
                    Tuple.tuple(message, trace)
            );
}
 
Example #10
Source File: XunitXmlPluginTest.java    From allure2 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
void shouldSetLabels() throws Exception {
    process(
            "xunitdata/passed-test.xml",
            "passed-test.xml"
    );

    final ArgumentCaptor<TestResult> captor = ArgumentCaptor.forClass(TestResult.class);
    verify(visitor, times(1)).visitTestResult(captor.capture());

    assertThat(captor.getAllValues())
            .hasSize(1)
            .flatExtracting(TestResult::getLabels)
            .extracting(Label::getName, Label::getValue)
            .containsExactlyInAnyOrder(
                    Tuple.tuple(LabelName.SUITE.value(), "org.example.XunitTest"),
                    Tuple.tuple(LabelName.PACKAGE.value(), "org.example.XunitTest"),
                    Tuple.tuple(LabelName.TEST_CLASS.value(), "org.example.XunitTest"),
                    Tuple.tuple(LabelName.RESULT_FORMAT.value(), XunitXmlPlugin.XUNIT_RESULTS_FORMAT)
            );
}
 
Example #11
Source File: HistoryTrendPluginTest.java    From allure2 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
void shouldGetData() {
    final List<HistoryTrendItem> history = randomHistoryTrendItems();
    final List<HistoryTrendItem> data = HistoryTrendPlugin.getData(createSingleLaunchResults(
            singletonMap(HISTORY_TREND_BLOCK_NAME, history),
            randomTestResult().setStatus(Status.PASSED),
            randomTestResult().setStatus(Status.FAILED),
            randomTestResult().setStatus(Status.FAILED)
    ));

    assertThat(data)
            .hasSize(1 + history.size())
            .extracting(HistoryTrendItem::getStatistic)
            .extracting(Statistic::getTotal, Statistic::getFailed, Statistic::getPassed)
            .first()
            .isEqualTo(Tuple.tuple(3L, 2L, 1L));

    final List<HistoryTrendItem> next = data.subList(1, data.size());

    assertThat(next)
            .containsExactlyElementsOf(history);

}
 
Example #12
Source File: AbstractInvokerMojoTest.java    From iterator-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAddItemProperties()
{
    mock.getMavenProject().getProperties().put( "prop1", "value1" );
    mock.getProperties().put( "prop1", "value2" );
    Properties itemProperties = new Properties();
    itemProperties.put( "prop1", "value3" );
    
    ItemWithProperties prop = new ItemWithProperties( "item" , itemProperties );
    InvocationRequest createAndConfigureAnInvocationRequest = mock.createAndConfigureAnInvocationRequest( prop );
    
    assertThat( createAndConfigureAnInvocationRequest.getProperties().entrySet() )
            .hasSize( 1 )
            .extracting( "key", "value" )
            .containsExactly(Tuple.tuple( "prop1", "value3" ));
}
 
Example #13
Source File: AbstractInvokerMojoTest.java    From iterator-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAddSystemProperties()
{
    mock.getMavenProject().getProperties().put( "prop1", "value1" );
    mock.getProperties().put( "prop1", "value2" );
    Properties itemProperties = new Properties();
    itemProperties.put( "prop1", "value3" );
    System.getProperties().put( "prop1", "value4" );
    
    ItemWithProperties prop = new ItemWithProperties( "item" , itemProperties );
    InvocationRequest createAndConfigureAnInvocationRequest = mock.createAndConfigureAnInvocationRequest( prop );
    
    assertThat( createAndConfigureAnInvocationRequest.getProperties().entrySet() )
            .hasSize( 1 )
            .extracting( "key", "value" )
            .containsExactly(Tuple.tuple( "prop1", "value4" ));
}
 
Example #14
Source File: BrowserConditionConfiguratorTest.java    From newrelic-alerts-configurator with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldCorrectlyCreateBrowserCondition() throws Exception {
    //given
    when(alertsConditionsApiMock.list(POLICY.getId())).thenReturn(ImmutableList.of());
    when(alertsConditionsApiMock.create(eq(POLICY.getId()), any(AlertsCondition.class))).thenReturn(AlertsCondition.builder().build());

    //when
    testee.sync(CONFIGURATION);

    //then
    verify(alertsConditionsApiMock).create(eq(POLICY.getId()), alertsConditionCaptor.capture());
    AlertsCondition result = alertsConditionCaptor.getValue();
    assertThat(result.getType()).isEqualTo("browser_metric");
    assertThat(result.getName()).isEqualTo(CONDITION_NAME);
    assertThat(result.getEnabled()).isEqualTo(true);
    assertThat(result.getEntities()).containsExactly(APPLICATION_ENTITY_ID);
    assertThat(result.getMetric()).isEqualTo("page_views_with_js_errors");
    assertThat(result.getTerms())
            .extracting("duration", "operator", "priority", "threshold", "timeFunction")
            .containsExactly(new Tuple("10", "above", "warning", "1.0", "any"));
}
 
Example #15
Source File: ApmJvmConditionConfiguratorTest.java    From newrelic-alerts-configurator with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldCorrectlyCreateUserDefinedCondition() throws Exception {
    //given
    when(alertsConditionsApiMock.list(POLICY.getId())).thenReturn(ImmutableList.of());
    when(alertsConditionsApiMock.create(eq(POLICY.getId()), any(AlertsCondition.class))).thenReturn(AlertsCondition.builder().build());

    //when
    testee.sync(CONFIGURATION);

    //then
    verify(alertsConditionsApiMock).create(eq(POLICY.getId()), alertsConditionCaptor.capture());
    AlertsCondition result = alertsConditionCaptor.getValue();
    assertThat(result.getType()).isEqualTo("apm_jvm_metric");
    assertThat(result.getName()).isEqualTo(CONDITION_NAME);
    assertThat(result.getEnabled()).isEqualTo(true);
    assertThat(result.getEntities()).containsExactly(APPLICATION_ENTITY_ID);
    assertThat(result.getMetric()).isEqualTo("gc_cpu_time");
    assertThat(result.getGcMetric()).isEqualTo("GC/PS MarkSweep");
    assertThat(result.getTerms())
            .extracting("duration", "operator", "priority", "threshold", "timeFunction")
            .containsExactly(new Tuple("5", "above", "critical", "85.0", "all"));
}
 
Example #16
Source File: AllureTestNgTest.java    From allure-java with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@AllureFeatures.Fixtures
@Issue("67")
@Test(description = "Should set correct status for failed before fixtures")
public void shouldSetCorrectStatusForFailedBeforeFixtures() {
    final AllureResults results = runTestNgSuites(
            "suites/failed-before-suite-fixture.xml",
            "suites/failed-before-test-fixture.xml",
            "suites/failed-before-method-fixture.xml"
    );

    assertThat(results.getTestResultContainers())
            .flatExtracting(TestResultContainer::getBefores)
            .hasSize(3)
            .extracting(FixtureResult::getName, FixtureResult::getStatus)
            .containsExactlyInAnyOrder(
                    Tuple.tuple("beforeSuite", Status.BROKEN),
                    Tuple.tuple("beforeTest", Status.BROKEN),
                    Tuple.tuple("beforeMethod", Status.BROKEN)
            );
}
 
Example #17
Source File: Allure1PluginTest.java    From allure2 with Apache License 2.0 6 votes vote down vote up
@Test
void shouldProcessNullParameters() throws Exception {
    final Set<TestResult> results = process(
            "allure1/empty-parameter-value.xml", generateTestSuiteXmlName()
    ).getResults();

    assertThat(results)
            .hasSize(1)
            .flatExtracting(TestResult::getParameters)
            .hasSize(4)
            .extracting(Parameter::getName, Parameter::getValue)
            .containsExactlyInAnyOrder(
                    Tuple.tuple("parameterArgument", null),
                    Tuple.tuple("parameter", "default"),
                    Tuple.tuple("invalid", null),
                    Tuple.tuple(null, null)
            );
}
 
Example #18
Source File: ApmUserDefinedConditionConfiguratorTest.java    From newrelic-alerts-configurator with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldCorrectlyCreateUserDefinedCondition() throws Exception {
    //given
    when(alertsConditionsApiMock.list(POLICY.getId())).thenReturn(ImmutableList.of());
    when(alertsConditionsApiMock.create(eq(POLICY.getId()), any(AlertsCondition.class))).thenReturn(AlertsCondition.builder().build());

    //when
    testee.sync(CONFIGURATION);

    //then
    verify(alertsConditionsApiMock).create(eq(POLICY.getId()), alertsConditionCaptor.capture());
    AlertsCondition result = alertsConditionCaptor.getValue();
    assertThat(result.getConditionScope()).isEqualTo("application");
    assertThat(result.getType()).isEqualTo("apm_app_metric");
    assertThat(result.getName()).isEqualTo(CONDITION_NAME);
    assertThat(result.getEnabled()).isEqualTo(true);
    assertThat(result.getEntities()).containsExactly(APPLICATION_ENTITY_ID);
    assertThat(result.getMetric()).isEqualTo("user_defined");
    assertThat(result.getTerms())
            .extracting("duration", "operator", "priority", "threshold", "timeFunction")
            .containsExactly(new Tuple("5", "above", "critical", "0.5", "all"));
    assertThat(result.getUserDefined().getMetric()).isEqualTo(METRIC);
    assertThat(result.getUserDefined().getValueFunction()).isEqualTo("average");
}
 
Example #19
Source File: AllureTestNgTest.java    From allure-java with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@AllureFeatures.Fixtures
@Issue("67")
@Test(description = "Should set correct status for failed after fixtures")
public void shouldSetCorrectStatusForFailedAfterFixtures() {
    final Consumer<TestNG> configurer = parallel(XmlSuite.ParallelMode.METHODS, 5);

    final AllureResults results = runTestNgSuites(
            configurer,
            "suites/failed-after-suite-fixture.xml",
            "suites/failed-after-test-fixture.xml",
            "suites/failed-after-method-fixture.xml"
    );

    assertThat(results.getTestResultContainers())
            .flatExtracting(TestResultContainer::getAfters)
            .hasSize(3)
            .extracting(FixtureResult::getName, FixtureResult::getStatus)
            .containsExactlyInAnyOrder(
                    Tuple.tuple("afterSuite", Status.BROKEN),
                    Tuple.tuple("afterTest", Status.BROKEN),
                    Tuple.tuple("afterMethod", Status.BROKEN)
            );
}
 
Example #20
Source File: GetMailboxesMethodTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void getMailboxesShouldReturnMailboxesWhenAvailable() throws Exception {
    MailboxPath mailboxPath = MailboxPath.forUser(USERNAME, "name");
    MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME);
    mailboxManager.createMailbox(mailboxPath, mailboxSession);
    MessageManager messageManager = mailboxManager.getMailbox(mailboxPath, mailboxSession);
    messageManager.appendMessage(MessageManager.AppendCommand.from(
        Message.Builder.of()
            .setSubject("test")
            .setBody("testmail", StandardCharsets.UTF_8)), mailboxSession);
    messageManager.appendMessage(MessageManager.AppendCommand.from(
        Message.Builder.of()
            .setSubject("test2")
            .setBody("testmail", StandardCharsets.UTF_8)), mailboxSession);

    GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder()
            .build();

    List<JmapResponse> getMailboxesResponse = getMailboxesMethod.processToStream(getMailboxesRequest, methodCallId, mailboxSession).collect(Collectors.toList());

    assertThat(getMailboxesResponse)
            .hasSize(1)
            .extracting(JmapResponse::getResponse)
            .hasOnlyElementsOfType(GetMailboxesResponse.class)
            .extracting(GetMailboxesResponse.class::cast)
            .flatExtracting(GetMailboxesResponse::getList)
            .extracting(Mailbox::getId, Mailbox::getName, Mailbox::getUnreadMessages)
            .containsOnly(Tuple.tuple(InMemoryId.of(1), mailboxPath.getName(), Number.fromLong(2L)));
}
 
Example #21
Source File: KotlinDslKotlinGradleBuildCustomizerTests.java    From initializr with Apache License 2.0 5 votes vote down vote up
@Test
void kotlinPluginsAreConfigured() {
	GradleBuild build = new GradleBuild();
	new KotlinDslKotlinGradleBuildCustomizer(new SimpleKotlinProjectSettings("1.2.70")).customize(build);
	assertThat(build.plugins().values()).extracting("id", "version").containsExactlyInAnyOrder(
			Tuple.tuple("org.jetbrains.kotlin.jvm", "1.2.70"),
			Tuple.tuple("org.jetbrains.kotlin.plugin.spring", "1.2.70"));
}
 
Example #22
Source File: CountingChildrenTest.java    From brave with Apache License 2.0 5 votes vote down vote up
@Test public void countChildren() {
  brave.Span root1 = tracer.newTrace().name("root1").start();
  brave.Span root2 = tracer.newTrace().name("root2").start();
  brave.Span root1Child1 = tracer.newChild(root1.context()).name("root1Child1").start();
  brave.Span root1Child1Child1 =
    tracer.newChild(root1Child1.context()).name("root1Child1Child1").start();
  tracer.newChild(root1Child1.context()).name("root1Child1ChildAbandoned").start().abandon();
  brave.Span root2Child1 = tracer.newChild(root2.context()).name("root2Child1").start();
  brave.Span root1Child1Child2 =
    tracer.newChild(root1Child1.context()).name("root1Child1Child2").start();
  brave.Span root1Child1Child2Child1 =
    tracer.newChild(root1Child1Child1.context()).name("root1Child1Child2Child1").start();
  root1Child1Child2Child1.finish();
  root2Child1.finish();
  root1Child1Child1.finish();
  root2.finish();
  root1Child1Child2.finish();
  root1Child1.finish();
  root1.finish();

  List<Tuple> nameToChildCount = spans.spans().stream()
    .map(s -> tuple(s.name(), s.tags().get("childCount")))
    .collect(Collectors.toList());

  assertThat(nameToChildCount)
    .containsExactly(
      tuple("root1Child1Child2Child1", "0"),
      tuple("root2Child1", "0"),
      tuple("root1Child1Child1", "1"),
      tuple("root2", "1"),
      tuple("root1Child1Child2", "0"),
      tuple("root1Child1", "2"),
      tuple("root1", "1")
    );
}
 
Example #23
Source File: GetMailboxesMethodTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void getMailboxesShouldReturnMailboxesWithRoles() throws Exception {
    MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME);
    mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "INBOX"), mailboxSession);
    mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Archive"), mailboxSession);
    mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Drafts"), mailboxSession);
    mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Outbox"), mailboxSession);
    mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Sent"), mailboxSession);
    mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Trash"), mailboxSession);
    mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Spam"), mailboxSession);
    mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Templates"), mailboxSession);
    mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Restored-Messages"), mailboxSession);
    mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "WITHOUT ROLE"), mailboxSession);

    GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder()
            .build();

    List<JmapResponse> getMailboxesResponse = getMailboxesMethod.processToStream(getMailboxesRequest, methodCallId, mailboxSession).collect(Collectors.toList());

    assertThat(getMailboxesResponse)
            .hasSize(1)
            .extracting(JmapResponse::getResponse)
            .hasOnlyElementsOfType(GetMailboxesResponse.class)
            .extracting(GetMailboxesResponse.class::cast)
            .flatExtracting(GetMailboxesResponse::getList)
            .extracting(Mailbox::getName, Mailbox::getRole)
            .containsOnly(
                    Tuple.tuple("INBOX", Optional.of(Role.INBOX)),
                    Tuple.tuple("Archive", Optional.of(Role.ARCHIVE)),
                    Tuple.tuple("Drafts", Optional.of(Role.DRAFTS)),
                    Tuple.tuple("Outbox", Optional.of(Role.OUTBOX)),
                    Tuple.tuple("Sent", Optional.of(Role.SENT)),
                    Tuple.tuple("Trash", Optional.of(Role.TRASH)),
                    Tuple.tuple("Spam", Optional.of(Role.SPAM)),
                    Tuple.tuple("Templates", Optional.of(Role.TEMPLATES)),
                    Tuple.tuple("Restored-Messages", Optional.of(Role.RESTORED_MESSAGES)),
                    Tuple.tuple("WITHOUT ROLE", Optional.empty()));
}
 
Example #24
Source File: TermSuiteExtractors.java    From termsuite-core with Apache License 2.0 5 votes vote down vote up
@Override
public Tuple extract(Relation input) {
	return new Tuple(
			VariationUtils.toTagString(input),
			getRuleString(input),
			input.getTo());
}
 
Example #25
Source File: GetMailboxesMethodTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void getMailboxesShouldReturnMailboxesWithSortOrder() throws Exception {
    MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME);
    mailboxManager.createMailbox(MailboxPath.inbox(USERNAME), mailboxSession);
    mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Archive"), mailboxSession);
    mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Drafts"), mailboxSession);
    mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Outbox"), mailboxSession);
    mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Sent"), mailboxSession);
    mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Trash"), mailboxSession);
    mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Spam"), mailboxSession);
    mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Templates"), mailboxSession);

    GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder()
            .build();

    List<JmapResponse> getMailboxesResponse = getMailboxesMethod.processToStream(getMailboxesRequest, methodCallId, mailboxSession).collect(Collectors.toList());

    assertThat(getMailboxesResponse)
            .hasSize(1)
            .extracting(JmapResponse::getResponse)
            .hasOnlyElementsOfType(GetMailboxesResponse.class)
            .extracting(GetMailboxesResponse.class::cast)
            .flatExtracting(GetMailboxesResponse::getList)
            .extracting(Mailbox::getName, Mailbox::getSortOrder)
            .containsExactly(
                    Tuple.tuple("INBOX", SortOrder.of(10)),
                    Tuple.tuple("Archive", SortOrder.of(20)),
                    Tuple.tuple("Drafts", SortOrder.of(30)),
                    Tuple.tuple("Outbox", SortOrder.of(40)),
                    Tuple.tuple("Sent", SortOrder.of(50)),
                    Tuple.tuple("Trash", SortOrder.of(60)),
                    Tuple.tuple("Spam", SortOrder.of(70)),
                    Tuple.tuple("Templates", SortOrder.of(80)));
}
 
Example #26
Source File: TermSuiteExtractors.java    From termsuite-core with Apache License 2.0 5 votes vote down vote up
@Override
public Tuple extract(Relation input) {
	return new Tuple(
			input.getPropertyValue(RelationProperty.DERIVATION_TYPE),
			input.getFrom().getGroupingKey(),
			input.getTo().getGroupingKey()
			);
}
 
Example #27
Source File: TermSuiteExtractors.java    From termsuite-core with Apache License 2.0 5 votes vote down vote up
@Override
public Tuple extract(Relation input) {
	return new Tuple(
			input.getTo().getGroupingKey(),
			getRuleString(input),
			input.getTo().getFrequency());
}
 
Example #28
Source File: TermSuiteExtractors.java    From termsuite-core with Apache License 2.0 5 votes vote down vote up
@Override
public Tuple extract(Relation input) {
	return new Tuple(
			input.getFrom(),
			VariationUtils.toTagString(input),
			input.getTo());
}
 
Example #29
Source File: SemanticGathererSpec.java    From termsuite-core with Apache License 2.0 5 votes vote down vote up
@Override
public Tuple extract(RelationService input) {
	return new Tuple(
			input.getFrom().getGroupingKey(),
			input.getTo().getGroupingKey()
		);
}
 
Example #30
Source File: TermSuiteExtractors.java    From termsuite-core with Apache License 2.0 5 votes vote down vote up
@Override
public Tuple extract(Relation input) {
	return new Tuple(
			input.getType(),
			getRuleString(input),
			input.getTo());
}