/** * Constructs an {@link IterableAssert} for the value of the provided {@link PCollection } with * the specified reason. The provided PCollection must contain a single {@code Iterable<T>} value. */ public static <T> IterableAssert<T> thatSingletonIterable( String reason, PCollection<? extends Iterable<T>> actual) { @SuppressWarnings("unchecked") // Safe covariant cast PCollection<Iterable<T>> actualIterables = (PCollection<Iterable<T>>) actual; return new PCollectionSingletonIterableAssert<>( actualIterables, PAssertionSite.capture(reason)); }
public PCollectionContentsAssert( PCollection<T> actual, AssertionWindows rewindowingStrategy, SimpleFunction<Iterable<ValueInSingleWindow<T>>, Iterable<T>> paneExtractor, PAssertionSite site) { this.actual = actual; this.rewindowingStrategy = rewindowingStrategy; this.paneExtractor = paneExtractor; this.site = site; }
/** * Checks that the {@code Iterable} contains the expected elements, in any order. * * <p>Returns this {@code IterableAssert}. */ @Override public PCollectionContentsAssert<T> containsInAnyOrder(Iterable<T> expectedElements) { return satisfies(new AssertContainsInAnyOrderRelation<>(), expectedElements); }
/** * A {@link SerializableMatcher} with identical criteria to {@link Matchers#equalTo(Object)}. * * <p>The expected value of type {@code T} will be serialized using the provided {@link Coder}. It * is explicitly <i>not</i> required or expected to be serializable via Java serialization. */ public static <T> SerializableMatcher<T> equalTo(Coder<T> coder, T expected) { final SerializableSupplier<T> expectedSupplier = new SerializableViaCoder<>(coder, expected); return fromSupplier(() -> Matchers.equalTo(expectedSupplier.get())); }
/** * Constructs an {@link IterableAssert} for the elements of the provided {@link PCollection} with * the specified reason. */ public static <T> IterableAssert<T> that(String reason, PCollection<T> actual) { return new PCollectionContentsAssert<>(actual, PAssertionSite.capture(reason)); }
@Override public PCollectionContentsAssert<T> inCombinedNonLatePanes(BoundedWindow window) { return withPane(window, PaneExtractors.nonLatePanes()); }
@Override public PCollectionSingletonIterableAssert<T> inOnTimePane(BoundedWindow window) { return withPanes(window, PaneExtractors.onTimePane()); }
/** A {@link SerializableMatcher} that matches any {@link KV} with the specified value. */ public static <K, V extends Serializable> SerializableMatcher<KV<? extends K, ? extends V>> kvWithValue(V value) { return new KvValueMatcher<>(equalTo(value)); }
@Override public PCollectionContentsAssert<T> inEarlyPane(BoundedWindow window) { return withPane(window, PaneExtractors.earlyPanes()); }
@Override protected void afterUserCodeFinished() { super.afterUserCodeFinished(); verifyPipelineExecution(); } }
@Override public IterableAssert<T> inEarlyGlobalWindowPanes() { return withPanes(GlobalWindow.INSTANCE, PaneExtractors.earlyPanes()); }
@Override public PCollectionSingletonIterableAssert<T> containsInAnyOrder(Iterable<T> expectedElements) { return satisfies(new AssertContainsInAnyOrderRelation<>(), expectedElements); }
@Override public PCollectionViewAssert<ElemT, ViewT> notEqualTo(ViewT expectedValue) { return satisfies(new AssertNotEqualToRelation<>(), expectedValue); }
/** A {@link SerializableMatcher} that matches any {@link KV} with the specified key. */ public static <K extends Serializable, V> SerializableMatcher<KV<? extends K, ? extends V>> kvWithKey(K key) { return new KvKeyMatcher<>(equalTo(key)); }
/** * Applies an {@link AssertRelation} to check the provided relation against the value of this * assert and the provided expected value. * * <p>Returns this {@code SingletonAssert}. */ private PCollectionViewAssert<ElemT, ViewT> satisfies( AssertRelation<ViewT, ViewT> relation, final ViewT expectedValue) { return satisfies(new CheckRelationAgainstExpected<>(relation, expectedValue, coder)); }
/** * A {@link SerializableMatcher} with identical criteria to {@link Matchers#hasItem(Object)}. * * <p>The item of type {@code T} will be serialized using the provided {@link Coder}. It is * explicitly <i>not</i> required or expected to be serializable via Java serialization. */ public static <T> SerializableMatcher<Iterable<? super T>> hasItem(Coder<T> coder, T target) { final SerializableSupplier<T> targetSupplier = new SerializableViaCoder<>(coder, target); return fromSupplier(() -> Matchers.hasItem(targetSupplier.get())); }
/** * A {@link SerializableMatcher} that matches any {@link KV} with the specified value. * * <p>The value of type {@code V} will be serialized using the provided {@link Coder}. It is * explicitly <i>not</i> required or expected to be serializable via Java serialization. */ public static <K, V> SerializableMatcher<KV<? extends K, ? extends V>> kvWithValue( Coder<V> coder, V value) { return new KvValueMatcher<>(equalTo(coder, value)); }
@Override public IterableAssert<T> inEarlyGlobalWindowPanes() { return withPane(GlobalWindow.INSTANCE, PaneExtractors.earlyPanes()); }
/** * A {@link SerializableMatcher} with identical criteria to {@link * Matchers#greaterThanOrEqualTo(Comparable)}. * * <p>The target value of type {@code T} will be serialized using the provided {@link Coder}. It * is explicitly <i>not</i> required or expected to be serializable via Java serialization. */ public static <T extends Comparable<T> & Serializable> SerializableMatcher<T> greaterThanOrEqualTo(final Coder<T> coder, T target) { final SerializableSupplier<T> targetSupplier = new SerializableViaCoder<>(coder, target); return fromSupplier(() -> Matchers.greaterThanOrEqualTo(targetSupplier.get())); }
/** * A {@link SerializableMatcher} with identical criteria to {@link Matchers#lessThan(Comparable)}. * * <p>The target value of type {@code T} will be serialized using the provided {@link Coder}. It * is explicitly <i>not</i> required or expected to be serializable via Java serialization. */ public static <T extends Comparable<T>> SerializableMatcher<T> lessThan( Coder<T> coder, T target) { final SerializableSupplier<T> targetSupplier = new SerializableViaCoder<>(coder, target); return fromSupplier(() -> Matchers.lessThan(targetSupplier.get())); }