org.hamcrest.collection.IsIterableContainingInOrder Java Examples

The following examples show how to use org.hamcrest.collection.IsIterableContainingInOrder. 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 Project: spring-analysis-note   Author: Vip-Augus   File: ImportSelectorTests.java    License: MIT License 6 votes vote down vote up
@Test
public void importSelectorsWithNestedGroup() {
	DefaultListableBeanFactory beanFactory = spy(new DefaultListableBeanFactory());
	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanFactory);
	context.register(ParentConfiguration1.class);
	context.refresh();
	InOrder ordered = inOrder(beanFactory);
	ordered.verify(beanFactory).registerBeanDefinition(eq("a"), any());
	ordered.verify(beanFactory).registerBeanDefinition(eq("e"), any());
	ordered.verify(beanFactory).registerBeanDefinition(eq("c"), any());
	assertThat(TestImportGroup.instancesCount.get(), equalTo(2));
	assertThat(TestImportGroup.imports.size(), equalTo(2));
	assertThat(TestImportGroup.allImports(), hasEntry(
			is(ParentConfiguration1.class.getName()),
			IsIterableContainingInOrder.contains(DeferredImportSelector1.class.getName(),
					ChildConfiguration1.class.getName())));
	assertThat(TestImportGroup.allImports(), hasEntry(
			is(ChildConfiguration1.class.getName()),
			IsIterableContainingInOrder.contains(DeferredImportedSelector3.class.getName())));
}
 
Example #2
Source Project: spring-analysis-note   Author: Vip-Augus   File: ImportSelectorTests.java    License: MIT License 6 votes vote down vote up
@Test
public void importSelectorsWithNestedGroupSameDeferredImport() {
	DefaultListableBeanFactory beanFactory = spy(new DefaultListableBeanFactory());
	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanFactory);
	context.register(ParentConfiguration2.class);
	context.refresh();
	InOrder ordered = inOrder(beanFactory);
	ordered.verify(beanFactory).registerBeanDefinition(eq("b"), any());
	ordered.verify(beanFactory).registerBeanDefinition(eq("d"), any());
	assertThat(TestImportGroup.instancesCount.get(), equalTo(2));
	assertThat(TestImportGroup.allImports().size(), equalTo(2));
	assertThat(TestImportGroup.allImports(), hasEntry(
			is(ParentConfiguration2.class.getName()),
			IsIterableContainingInOrder.contains(DeferredImportSelector2.class.getName(),
					ChildConfiguration2.class.getName())));
	assertThat(TestImportGroup.allImports(), hasEntry(
			is(ChildConfiguration2.class.getName()),
			IsIterableContainingInOrder.contains(DeferredImportSelector2.class.getName())));
}
 
Example #3
Source Project: java-technology-stack   Author: codeEngraver   File: ImportSelectorTests.java    License: MIT License 6 votes vote down vote up
@Test
public void importSelectorsWithNestedGroup() {
	DefaultListableBeanFactory beanFactory = spy(new DefaultListableBeanFactory());
	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanFactory);
	context.register(ParentConfiguration1.class);
	context.refresh();
	InOrder ordered = inOrder(beanFactory);
	ordered.verify(beanFactory).registerBeanDefinition(eq("a"), any());
	ordered.verify(beanFactory).registerBeanDefinition(eq("e"), any());
	ordered.verify(beanFactory).registerBeanDefinition(eq("c"), any());
	assertThat(TestImportGroup.instancesCount.get(), equalTo(2));
		assertThat(TestImportGroup.imports.size(), equalTo(2));
	assertThat(TestImportGroup.allImports(), hasEntry(
			is(ParentConfiguration1.class.getName()),
			IsIterableContainingInOrder.contains(DeferredImportSelector1.class.getName(),
					ChildConfiguration1.class.getName())));
	assertThat(TestImportGroup.allImports(), hasEntry(
			is(ChildConfiguration1.class.getName()),
			IsIterableContainingInOrder.contains(DeferredImportedSelector3.class.getName())));
}
 
Example #4
Source Project: java-technology-stack   Author: codeEngraver   File: ImportSelectorTests.java    License: MIT License 6 votes vote down vote up
@Test
public void importSelectorsWithNestedGroupSameDeferredImport() {
	DefaultListableBeanFactory beanFactory = spy(new DefaultListableBeanFactory());
	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanFactory);
	context.register(ParentConfiguration2.class);
	context.refresh();
	InOrder ordered = inOrder(beanFactory);
	ordered.verify(beanFactory).registerBeanDefinition(eq("b"), any());
	ordered.verify(beanFactory).registerBeanDefinition(eq("d"), any());
	assertThat(TestImportGroup.instancesCount.get(), equalTo(2));
	assertThat(TestImportGroup.allImports().size(), equalTo(2));
	assertThat(TestImportGroup.allImports(), hasEntry(
			is(ParentConfiguration2.class.getName()),
			IsIterableContainingInOrder.contains(DeferredImportSelector2.class.getName(),
					ChildConfiguration2.class.getName())));
	assertThat(TestImportGroup.allImports(), hasEntry(
			is(ChildConfiguration2.class.getName()),
			IsIterableContainingInOrder.contains(DeferredImportSelector2.class.getName())));
}
 
Example #5
Source Project: servicecomb-saga-actuator   Author: apache   File: GraphBuilderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void buildsGraphOfParallelRequests() {
  SingleLeafDirectedAcyclicGraph<SagaRequest> tasks = graphBuilder.build(requests);

  Traveller<SagaRequest> traveller = new ByLevelTraveller<>(tasks, new FromRootTraversalDirection<SagaRequest>());
  Collection<Node<SagaRequest>> nodes = traveller.nodes();

  traveller.next();
  assertThat(requestsOf(nodes), IsIterableContainingInOrder.contains(NoOpSagaRequest.SAGA_START_REQUEST));
  nodes.clear();

  traveller.next();
  assertThat(requestsOf(nodes), contains(request1, request2));
  nodes.clear();

  traveller.next();
  assertThat(requestsOf(nodes), contains(request3));
  nodes.clear();

  traveller.next();
  assertThat(requestsOf(nodes), IsIterableContainingInOrder.contains(NoOpSagaRequest.SAGA_END_REQUEST));
}
 
Example #6
Source Project: servicecomb-saga-actuator   Author: apache   File: ActorBasedSagaIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void transactionsAreRunSuccessfully() {
  saga = sagaFactory.createSaga(requestJson, sagaId, eventStore, sagaDefinition);
  saga.run();

  assertThat(eventStore, IsIterableContainingInOrder.contains(
      SagaEventMatcher.eventWith(sagaId, SAGA_START_TRANSACTION, SagaStartedEvent.class),
      SagaEventMatcher.eventWith(sagaId, transaction1, TransactionStartedEvent.class),
      SagaEventMatcher.eventWith(sagaId, transaction1, TransactionEndedEvent.class),
      SagaEventMatcher.eventWith(sagaId, transaction2, TransactionStartedEvent.class),
      SagaEventMatcher.eventWith(sagaId, transaction2, TransactionEndedEvent.class),
      SagaEventMatcher.eventWith(sagaId, SAGA_END_TRANSACTION, SagaEndedEvent.class)
  ));

  verify(transaction1).send(request1.serviceName(), SagaResponse.EMPTY_RESPONSE);
  verify(transaction2).send(request2.serviceName(), transactionResponse1);

  verify(compensation1, never()).send(request1.serviceName());
  verify(compensation2, never()).send(request2.serviceName());
}
 
Example #7
Source Project: servicecomb-saga-actuator   Author: apache   File: ActorBasedSagaIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void skipIgnoredTransaction() throws Exception {
  when(sagaDefinition.requests()).thenReturn(new SagaRequest[]{request1, request2, request3});
  saga = sagaFactory.createSaga(requestJson, sagaId, eventStore, sagaDefinition);

  when(childrenExtractor.fromJson(transactionResponse1.body())).thenReturn(setOf(request3.id()));

  saga.run();

  assertThat(eventStore, IsIterableContainingInOrder.contains(
      SagaEventMatcher.eventWith(sagaId, SAGA_START_TRANSACTION, SagaStartedEvent.class),
      SagaEventMatcher.eventWith(sagaId, transaction1, TransactionStartedEvent.class),
      SagaEventMatcher.eventWith(sagaId, transaction1, TransactionEndedEvent.class),
      SagaEventMatcher.eventWith(sagaId, transaction3, TransactionStartedEvent.class),
      SagaEventMatcher.eventWith(sagaId, transaction3, TransactionEndedEvent.class),
      SagaEventMatcher.eventWith(sagaId, SAGA_END_TRANSACTION, SagaEndedEvent.class)
  ));

  verify(transaction1).send(request1.serviceName(), SagaResponse.EMPTY_RESPONSE);
  verify(transaction3).send(request3.serviceName(), transactionResponse1);
  verify(transaction2, never()).send(anyString(), any(SagaResponse.class));

  verify(compensation1, never()).send(request1.serviceName());
  verify(compensation2, never()).send(request2.serviceName());
  verify(compensation3, never()).send(request3.serviceName());
}
 
Example #8
Source Project: servicecomb-saga-actuator   Author: apache   File: ActorBasedSagaIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void skipAllIgnoredTransactions() throws Exception {
  when(sagaDefinition.requests()).thenReturn(new SagaRequest[]{request1, request2, request3, request4});
  saga = sagaFactory.createSaga(requestJson, sagaId, eventStore, sagaDefinition);

  when(childrenExtractor.fromJson(transactionResponse1.body())).thenReturn(setOf("none"));

  saga.run();

  assertThat(eventStore, IsIterableContainingInOrder.contains(
      SagaEventMatcher.eventWith(sagaId, SAGA_START_TRANSACTION, SagaStartedEvent.class),
      SagaEventMatcher.eventWith(sagaId, transaction1, TransactionStartedEvent.class),
      SagaEventMatcher.eventWith(sagaId, transaction1, TransactionEndedEvent.class),
      SagaEventMatcher.eventWith(sagaId, SAGA_END_TRANSACTION, SagaEndedEvent.class)
  ));

  verify(transaction1).send(request1.serviceName(), SagaResponse.EMPTY_RESPONSE);
  verify(transaction2, never()).send(anyString(), any(SagaResponse.class));
  verify(transaction3, never()).send(anyString(), any(SagaResponse.class));
  verify(transaction4, never()).send(anyString(), any(SagaResponse.class));

  verify(compensation1, never()).send(request1.serviceName());
  verify(compensation2, never()).send(request2.serviceName());
  verify(compensation3, never()).send(request3.serviceName());
  verify(compensation4, never()).send(request4.serviceName());
}
 
Example #9
Source Project: servicecomb-saga-actuator   Author: apache   File: ActorBasedSagaIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void retriesFailedTransactionTillSuccess() {
  when(sagaDefinition.policy()).thenReturn(new ForwardRecovery());
  saga = sagaFactory.createSaga(requestJson, sagaId, eventStore, sagaDefinition);

  when(transaction2.send(request2.serviceName(), transactionResponse1))
      .thenThrow(exception).thenThrow(exception).thenReturn(transactionResponse2);
  when(transaction2.retries()).thenReturn(-1);

  saga.run();

  assertThat(eventStore, IsIterableContainingInOrder.contains(
      SagaEventMatcher.eventWith(sagaId, SAGA_START_TRANSACTION, SagaStartedEvent.class),
      SagaEventMatcher.eventWith(sagaId, transaction1, TransactionStartedEvent.class),
      SagaEventMatcher.eventWith(sagaId, transaction1, TransactionEndedEvent.class),
      SagaEventMatcher.eventWith(sagaId, transaction2, TransactionStartedEvent.class),
      SagaEventMatcher.eventWith(sagaId, transaction2, TransactionEndedEvent.class),
      SagaEventMatcher.eventWith(sagaId, SAGA_END_TRANSACTION, SagaEndedEvent.class)
  ));

  verify(transaction1).send(request1.serviceName(), SagaResponse.EMPTY_RESPONSE);
  verify(transaction2, times(3)).send(request2.serviceName(), transactionResponse1);

  verify(compensation1, never()).send(anyString(), any(SagaResponse.class));
  verify(compensation2, never()).send(anyString(), any(SagaResponse.class));
}
 
Example #10
Source Project: cactoos   Author: yegor256   File: SortedTest.java    License: MIT License 6 votes vote down vote up
@Test
public void mustSortIntegerArrayAsSetInAscendingOrder() {
    new Assertion<>(
        "Must keep unique integer numbers sorted",
        new Sorted<>(
            Integer::compareTo,
            2, 1, 3, 2, 1
        ),
        new IsIterableContainingInOrder<>(
            new ListOf<Matcher<? super Integer>>(
                new IsEqual<>(1),
                new IsEqual<>(2),
                new IsEqual<>(3)
            )
        )
    ).affirm();
}
 
Example #11
Source Project: cactoos   Author: yegor256   File: SortedTest.java    License: MIT License 6 votes vote down vote up
@Test
public void mustSortIntegerIterableAsSetInDescendingOrder() {
    new Assertion<>(
        "Must keep unique integer numbers sorted in descending order",
        new Sorted<>(
            Comparator.reverseOrder(),
            2, 1, 3, 2, 1
        ),
        new IsIterableContainingInOrder<>(
            new ListOf<Matcher<? super Integer>>(
                new IsEqual<>(3),
                new IsEqual<>(2),
                new IsEqual<>(1)
            )
        )
    ).affirm();
}
 
Example #12
Source Project: cactoos   Author: yegor256   File: SortedTest.java    License: MIT License 6 votes vote down vote up
@Test
public void mustSortTextIterableAsSetUsingCustomCOmparator() {
    new Assertion<>(
        "Must keep unique integer numbers sorted in descending order",
        new Sorted<>(
            (first, second) -> {
                final String left = new UncheckedText(first).asString();
                final String right = new UncheckedText(second).asString();
                return left.compareTo(right);
            },
            new TextOf("cd"),
            new TextOf("ab"),
            new TextOf("gh"),
            new TextOf("ef")
        ),
        new IsIterableContainingInOrder<>(
            new ListOf<Matcher<? super Text>>(
                new IsEqual<>(new TextOf("ab")),
                new IsEqual<>(new TextOf("cd")),
                new IsEqual<>(new TextOf("ef")),
                new IsEqual<>(new TextOf("gh"))
            )
        )
    ).affirm();
}
 
Example #13
Source Project: cactoos   Author: yegor256   File: SortedTest.java    License: MIT License 6 votes vote down vote up
@Test
public void mustNotBeEqualToSortedSet() {
    new Assertion<>(
        "Sorted set must not be equal to the tested collection",
        new Sorted<>(
            Integer::compareTo,
            2, 1, 3, 2, 1
        ),
        new IsNot<>(
            new IsIterableContainingInOrder<>(
                new ListOf<Matcher<? super Integer>>(
                    new IsEqual<>(1),
                    new IsEqual<>(3),
                    new IsEqual<>(2)
                )
            ))
    ).affirm();
}
 
Example #14
Source Project: yuvi   Author: pinterest   File: ChunkImplTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMultipleTimeSeriesResponse() {
  setUp();
  final String testMetricName1 = "testMetric1";
  final List<String> testTags1 = Arrays.asList("host=h1", "dc=dc1");
  final List<String> testTags2 = Arrays.asList("host=h2", "dc=dc1");
  assertTrue(chunk.query(new Query("test", Collections.emptyList())).isEmpty());

  parseAndAddOpenTSDBMetric(
      makeMetricString(testMetricName1, "host=h1 dc=dc1", testTs, testValue), chunk);
  parseAndAddOpenTSDBMetric(
      makeMetricString(testMetricName1, "host=h2 dc=dc1", testTs, testValue), chunk);

  Point p1 = new Point(testTs, testValue);

  Assert.assertThat(chunk.query(Query.parse(testMetricName1 + " dc=dc1")),
      IsIterableContainingInOrder.contains(
          new TimeSeries(testMetricName1 + " dc=dc1 host=h1", Collections.singletonList(p1)),
          new TimeSeries(testMetricName1 + " dc=dc1 host=h2", Collections.singletonList(p1))));
}
 
Example #15
Source Project: yuvi   Author: pinterest   File: MetricsAndTagStoreImplTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testMultipleTimeSeriesResponse() {
  final String testMetricName1 = "testMetric1";
  final List<String> testTags1 = Arrays.asList("host=h1", "dc=dc1");
  final List<String> testTags2 = Arrays.asList("host=h2", "dc=dc1");
  assertTrue(ms.getSeries(new Query("test", Collections.emptyList())).isEmpty());

  final Metric testMetric1 = new Metric(testMetricName1, testTags1);
  final Metric testMetric2 = new Metric(testMetricName1, testTags2);

  ms.addPoint(testMetric1, ts, value);
  ms.addPoint(testMetric2, ts, value);
  Point p1 = new Point(ts, value);

  assertThat(ms.getSeries(Query.parse(testMetricName1 + " dc=dc1")),
      IsIterableContainingInOrder.contains(
          new TimeSeries(testMetricName1 + " dc=dc1 host=h1", Collections.singletonList(p1)),
          new TimeSeries(testMetricName1 + " dc=dc1 host=h2", Collections.singletonList(p1))));
}
 
Example #16
Source Project: monsoon   Author: groupon   File: TSDataTest.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void read() throws Exception {
    final List<TimeSeriesCollection> tsdata = create_tsdata_(3).collect(Collectors.toList());
    file_support.create_file(tmpfile, tsdata);

    final TSData fd = TSData.readonly(tmpfile);

    assertEquals(tsdata, fd.stream().collect(Collectors.toList()));

    assertEquals(Files.size(tmpfile), fd.getFileSize());
    assertEquals(tsdata.get(0).getTimestamp(), fd.getBegin());
    assertEquals(tsdata.get(tsdata.size() - 1).getTimestamp(), fd.getEnd());
    assertNotNull(fd.getFileChannel());
    assertEquals(tsdata.size(), fd.size());
    assertEquals(file_support.getMajor(), fd.getMajor());
    assertEquals(file_support.getMinor(), fd.getMinor());
    assertThat(fd, IsIterableContainingInOrder.contains(tsdata.stream().map(Matchers::equalTo).collect(Collectors.toList())));
}
 
Example #17
Source Project: monsoon   Author: groupon   File: UnmappedReadonlyTSDataFileTest.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void read() throws Exception {
    file_support.create_file(tmpfile, tsdata);

    final UnmappedReadonlyTSDataFile fd = UnmappedReadonlyTSDataFile.open(tmpfile);

    assertEquals(Files.size(tmpfile), fd.getFileSize());
    assertEquals(tsdata.get(0).getTimestamp(), fd.getBegin());
    assertEquals(tsdata.get(tsdata.size() - 1).getTimestamp(), fd.getEnd());
    assertTrue(fd.getFileChannel().isPresent());
    assertEquals(tsdata.size(), fd.size());
    assertEquals(file_support.getMajor(), fd.getMajor());
    assertEquals(file_support.getMinor(), fd.getMinor());
    assertThat(fd, IsIterableContainingInOrder.contains(tsdata.stream().map(Matchers::equalTo).collect(Collectors.toList())));
    assertThat(fd.streamReversed().collect(Collectors.toList()),
            IsIterableContainingInOrder.contains(expect_reversed.stream().map(Matchers::equalTo).collect(Collectors.toList())));
}
 
Example #18
Source Project: beam   Author: apache   File: BufferedElementCountingOutputStreamTest.java    License: Apache License 2.0 6 votes vote down vote up
private void verifyValues(List<byte[]> expectedValues, InputStream is) throws Exception {
  List<byte[]> values = new ArrayList<>();
  long count;
  do {
    count = VarInt.decodeLong(is);
    for (int i = 0; i < count; ++i) {
      values.add(ByteArrayCoder.of().decode(is));
    }
  } while (count > 0);

  assertEquals(terminatorValue, count);

  if (expectedValues.isEmpty()) {
    assertTrue(values.isEmpty());
  } else {
    assertThat(values, IsIterableContainingInOrder.contains(expectedValues.toArray()));
  }
}
 
Example #19
Source Project: credhub   Author: cloudfoundry-incubator   File: BaseCredentialRequestTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void whenNameContainsReDosAttack_shouldBeInvalid() {
  // language=JSON
  final String json = "{"
    + "\"type\":\"value\","
    + "\"name\":\"/foo/com/foo/com/foo/com/foo/com/foo/com/foo/com/foo/com/foo/com/foo/"
    + "com/foo/com/foo/com/foo/com/foo/com/foo/com/foo/com/foo/com/foo/com/foo/com/foo/"
    + "com/foo/com/foo/com/foo/com/foo/com/foo/com/foo/com/foo/com/foo/com/foo/com/foo/"
    + "com/foo/com/foo/com/\","

    + "\"value\":\"some-value\""
    + "}";
  final Set<ConstraintViolation<BaseCredentialSetRequest>> violations = JsonTestHelper
    .deserializeAndValidate(json, BaseCredentialSetRequest.class);

  MatcherAssert.assertThat(violations, IsIterableContainingInOrder.contains(JsonTestHelper.hasViolationWithMessage(ErrorMessages.Credential.INVALID_SLASH_IN_NAME)));
}
 
Example #20
Source Project: nexus-public   Author: sonatype   File: ExampleContentTestSupport.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected boolean matchesSafely(final T actual, final Description description) {
  List<Object> actualValues = extractors.stream()
      .map(extractor -> extractor.apply(actual))
      .collect(toList());

  List<Matcher<?>> matchers = extractors.stream()
      .map(extractor -> extractor.apply(expected))
      .map(v -> v != null ? is(v) : nullValue())
      .collect(toList());

  @SuppressWarnings({ "unchecked", "rawtypes" })
  // (use hamcrest class directly as javac picks the wrong static varargs method)
  boolean matches = new IsIterableContainingInOrder(matchers).matches(actualValues);
  if (!matches) {
    for (int i = 0; i < extractors.size(); i++) {
      if (i > 0) {
        description.appendText(" AND ");
      }
      matchers.get(i).describeMismatch(actualValues.get(i), description);
    }
  }
  return matches;
}
 
Example #21
Source Project: samza   Author: apache   File: StreamTaskIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSyncTaskWithSinglePartition() throws Exception {
  List<Integer> inputList = Arrays.asList(1, 2, 3, 4, 5);
  List<Integer> outputList = Arrays.asList(10, 20, 30, 40, 50);

  InMemorySystemDescriptor isd = new InMemorySystemDescriptor("test");

  InMemoryInputDescriptor<Integer> imid = isd
      .getInputDescriptor("input", new NoOpSerde<Integer>());

  InMemoryOutputDescriptor<Integer> imod = isd
      .getOutputDescriptor("output", new NoOpSerde<Integer>());

  TestRunner
      .of(MyStreamTestTask.class)
      .addInputStream(imid, inputList)
      .addOutputStream(imod, 1)
      .addExternalContext(new TestContext(10))
      .run(Duration.ofSeconds(1));

  Assert.assertThat(TestRunner.consumeStream(imod, Duration.ofMillis(1000)).get(0),
      IsIterableContainingInOrder.contains(outputList.toArray()));

}
 
Example #22
Source Project: samza   Author: apache   File: AsyncStreamTaskIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAsyncTaskWithSinglePartition() throws Exception {
  List<Integer> inputList = Arrays.asList(1, 2, 3, 4, 5);
  List<Integer> outputList = Arrays.asList(10, 20, 30, 40, 50);

  InMemorySystemDescriptor isd = new InMemorySystemDescriptor("async-test");

  InMemoryInputDescriptor<Integer> imid = isd
      .getInputDescriptor("ints", new NoOpSerde<Integer>());

  InMemoryOutputDescriptor imod = isd
      .getOutputDescriptor("ints-out", new NoOpSerde<>());

  TestRunner
      .of(MyAsyncStreamTask.class)
      .addInputStream(imid, inputList)
      .addOutputStream(imod, 1)
      .run(Duration.ofSeconds(2));

  Assert.assertThat(TestRunner.consumeStream(imod, Duration.ofMillis(1000)).get(0),
      IsIterableContainingInOrder.contains(outputList.toArray()));
}
 
Example #23
Source Project: flow   Author: vaadin   File: RouteUtilTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void expected_parent_layouts_are_found_for_route() {
    List<Class<? extends RouterLayout>> parentLayouts = RouteUtil
            .getParentLayouts(BaseRouteWithParentPrefixAndRouteAlias.class,
                    "parent");

    Assert.assertThat(
            "Get parent layouts for route \"\" with parent prefix \"parent\" gave wrong result.",
            parentLayouts, IsIterableContainingInOrder
                    .contains(new Class[] { RoutePrefixParent.class }));

    parentLayouts = RouteUtil.getParentLayouts(RootWithParents.class, "");

    Assert.assertThat(
            "Expected to receive MiddleParent and Parent classes as parents.",
            parentLayouts, IsIterableContainingInOrder.contains(
                    new Class[] { MiddleParent.class, Parent.class }));
}
 
Example #24
Source Project: flow   Author: vaadin   File: RouteUtilTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void absolute_route_gets_expected_parent_layouts() {
    List<Class<? extends RouterLayout>> parentLayouts = RouteUtil
            .getParentLayouts(AbsoluteRoute.class, "single");

    Assert.assertThat(
            "Get parent layouts for route \"\" with parent prefix \"parent\" gave wrong result.",
            parentLayouts, IsIterableContainingInOrder
                    .contains(new Class[] { RoutePrefixParent.class }));

    parentLayouts = RouteUtil.getParentLayouts(AbsoluteCenterRoute.class,
            "absolute/child");

    Assert.assertThat(
            "Expected to receive MiddleParent and Parent classes as parents.",
            parentLayouts,
            IsIterableContainingInOrder.contains(new Class[] {
                    AbsoluteCenterParent.class, RoutePrefixParent.class }));
}
 
Example #25
Source Project: flow   Author: vaadin   File: RouteUtilTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void abolute_route_alias_gets_expected_parent_layouts() {
    List<Class<? extends RouterLayout>> parentLayouts = RouteUtil
            .getParentLayouts(AbsoluteRoute.class, "alias");

    Assert.assertThat(
            "Get parent layouts for route \"\" with parent prefix \"parent\" gave wrong result.",
            parentLayouts, IsIterableContainingInOrder
                    .contains(new Class[] { RoutePrefixParent.class }));

    parentLayouts = RouteUtil.getParentLayouts(AbsoluteCenterRoute.class,
            "absolute/alias");

    Assert.assertThat(
            "Expected to receive MiddleParent and Parent classes as parents.",
            parentLayouts,
            IsIterableContainingInOrder.contains(new Class[] {
                    AbsoluteCenterParent.class, RoutePrefixParent.class }));

}
 
Example #26
Source Project: flow   Author: vaadin   File: RouteUtilTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test // 3424
public void parent_layouts_resolve_correctly_for_route_parent() {
    List<Class<? extends RouterLayout>> parentLayouts = RouteUtil
            .getParentLayouts(MultiTarget.class, "");

    Assert.assertThat(
            "Get parent layouts for route \"\" gave wrong result.",
            parentLayouts, IsIterableContainingInOrder
                    .contains(new Class[] { Parent.class }));

    parentLayouts = RouteUtil.getParentLayouts(MultiTarget.class, "alias");

    Assert.assertThat(
            "Get parent layouts for routeAlias \"alias\" gave wrong result.",
            parentLayouts, IsIterableContainingInOrder.contains(
                    new Class[] { MiddleParent.class, Parent.class }));

    parentLayouts = RouteUtil.getParentLayouts(SubLayout.class,
            "parent/sub");

    Assert.assertThat(
            "Get parent layouts for route \"parent/sub\" with parent Route + ParentLayout gave wrong result.",
            parentLayouts,
            IsIterableContainingInOrder.contains(new Class[] {
                    MultiTarget.class, RoutePrefixParent.class }));
}
 
Example #27
Source Project: levelup-java-examples   Author: leveluplunch   File: EnumsExample.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void transform_string_to_enum () {

	List<String> days = Lists.newArrayList(
			"WEDNESDAY", 
			"SUNDAY", 
			"MONDAY", 
			"TUESDAY", 
			"WEDNESDAY");
	
    Function<String, Day> valueOfFunction = Enums.valueOfFunction(Day.class);

	Iterable<Day> daysAsEnums = Iterables.transform(days, valueOfFunction);
	
	assertThat(daysAsEnums, IsIterableWithSize.<Day>iterableWithSize(5));
	assertThat(daysAsEnums, IsIterableContainingInOrder.
			<Day>contains(
					Day.WEDNESDAY, 
					Day.SUNDAY, 
					Day.MONDAY, 
					Day.TUESDAY, 
					Day.WEDNESDAY));

}
 
Example #28
Source Project: levelup-java-examples   Author: leveluplunch   File: EnumsExample.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void transform_string_to_enum_string_converter () {

	List<String> days = Lists.newArrayList(
			"WEDNESDAY", 
			"SUNDAY", 
			"MONDAY", 
			"TUESDAY", 
			"WEDNESDAY");
	
    Function<String, Day> valueOfFunction = Enums.stringConverter(Day.class);

	Iterable<Day> daysAsEnums = Iterables.transform(days, valueOfFunction);
	
	assertThat(daysAsEnums, IsIterableWithSize.<Day>iterableWithSize(5));
	assertThat(daysAsEnums, IsIterableContainingInOrder.
			<Day>contains(
					Day.WEDNESDAY, 
					Day.SUNDAY, 
					Day.MONDAY, 
					Day.TUESDAY, 
					Day.WEDNESDAY));
}
 
Example #29
Source Project: emissary   Author: NationalSecurityAgency   File: AgentsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Ignore
// TODO: stop mocking and run a server since we made it so easy
@Test
public void agents() throws Exception {
    // test
    Response response = target("agents").request().get();

    // verify
    assertThat(response.getStatus(), equalTo(200));
    AgentsResponseEntity entity = response.readEntity(AgentsResponseEntity.class);
    assertThat(entity.getErrors(), IsEmptyCollection.empty());
    assertThat(entity.getCluster(), IsEmptyCollection.empty());
    assertThat(entity.getLocal().getHost(), equalTo("localhost:8001"));
    assertThat(entity.getLocal().getAgents(), IsIterableContainingInOrder.contains(EXPECTED_AGENTS));
}
 
Example #30
Source Project: emissary   Author: NationalSecurityAgency   File: PeersCommandIT.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetPeersWithPort() throws IOException {
    // test
    Set<String> peers = PeersCommand.getPeers(HostAndPort.fromString(""), true);

    // verify
    assertThat(peers, IsIterableContainingInOrder.contains("localhost:7001", "localhost:8001", "localhost:9001"));
    assertThat(peers, IsIterableWithSize.iterableWithSize(3));
}