|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.nifi.provenance.store.iterator; |
| 19 | + |
| 20 | +import org.apache.nifi.provenance.ProvenanceEventRecord; |
| 21 | +import org.apache.nifi.provenance.TestUtil; |
| 22 | +import org.junit.jupiter.api.Test; |
| 23 | + |
| 24 | +import java.io.IOException; |
| 25 | +import java.util.Objects; |
| 26 | +import java.util.Optional; |
| 27 | + |
| 28 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 29 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 30 | + |
| 31 | +class EventIteratorTest { |
| 32 | + |
| 33 | + @Test |
| 34 | + void testCanCreateAndRetrieveUsingOfFactory() throws IOException { |
| 35 | + ProvenanceEventRecord event = TestUtil.createEvent(); |
| 36 | + EventIterator eventIterator = EventIterator.of(event); |
| 37 | + Optional<ProvenanceEventRecord> foundEvent = eventIterator.nextEvent(); |
| 38 | + assertTrue(foundEvent.isPresent()); |
| 39 | + assertEquals(foundEvent.get().getAttribute("uuid"), event.getAttribute("uuid")); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + void testEmptyReturnedWhenExhausted() throws IOException { |
| 44 | + EventIterator eventIterator = EventIterator.of(TestUtil.createEvent()); |
| 45 | + assertTrue(eventIterator.nextEvent().isPresent()); |
| 46 | + assertTrue(eventIterator.nextEvent().isEmpty()); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + void testCanFilterEvents() throws IOException { |
| 51 | + ProvenanceEventRecord eventOne = TestUtil.createEvent(); |
| 52 | + ProvenanceEventRecord eventTwo = TestUtil.createEvent(); |
| 53 | + |
| 54 | + EventIterator eventIterator = EventIterator.of(eventOne, eventTwo); |
| 55 | + // Filter out the first event |
| 56 | + EventIterator filteredIterator = eventIterator.filter((e) -> !Objects.equals(e.getAttribute("uuid"), eventOne.getAttribute("uuid"))); |
| 57 | + |
| 58 | + ProvenanceEventRecord foundEvent = filteredIterator.nextEvent().orElseThrow(); |
| 59 | + assertEquals(foundEvent.getAttribute("uuid"), eventTwo.getAttribute("uuid")); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + void testEmptyFactoryIsEmpty() throws IOException { |
| 64 | + EventIterator eventIterator = EventIterator.EMPTY; |
| 65 | + assertTrue(eventIterator.nextEvent().isEmpty()); |
| 66 | + } |
| 67 | +} |
0 commit comments