From 1236461cdde5ca5afebb25fc3cba07046cc5a61b Mon Sep 17 00:00:00 2001 From: TobiasNx Date: Thu, 23 May 2024 14:32:16 +0200 Subject: [PATCH] WIP --- .../org/metafacture/metafix/FindFixPaths.java | 29 +++-- .../metafacture/metafix/FindFixPathsTest.java | 102 ++++++++++++++++++ 2 files changed, 121 insertions(+), 10 deletions(-) create mode 100644 metafix/src/test/java/org/metafacture/metafix/FindFixPathsTest.java diff --git a/metafix/src/main/java/org/metafacture/metafix/FindFixPaths.java b/metafix/src/main/java/org/metafacture/metafix/FindFixPaths.java index 4364f345..b08853ba 100644 --- a/metafix/src/main/java/org/metafacture/metafix/FindFixPaths.java +++ b/metafix/src/main/java/org/metafacture/metafix/FindFixPaths.java @@ -43,17 +43,26 @@ @FluxCommand("find-fix-paths") public class FindFixPaths extends DefaultStreamPipe> { + + private final Metafix fix; + + try + { + this.fix = new Metafix("nothing()"); + this.fix.setRepeatedFieldsToEntities(true); + }catch( + final IOException e) + { + throw new MetafactureException(e); + } + final TripleFilter tripleFilter = new TripleFilter();tripleFilter.setObjectPattern(objectPattern); + public FindFixPaths(final String objectPattern) { - final Metafix fix; - try { - fix = new Metafix("nothing()"); - fix.setRepeatedFieldsToEntities(true); - } - catch (final IOException e) { - throw new MetafactureException(e); - } - final TripleFilter tripleFilter = new TripleFilter(); - tripleFilter.setObjectPattern(objectPattern); + + } + + @Override + protected void onSetReceiver() { fix .setReceiver(new StreamFlattener()) .setReceiver(new StreamToTriples()) diff --git a/metafix/src/test/java/org/metafacture/metafix/FindFixPathsTest.java b/metafix/src/test/java/org/metafacture/metafix/FindFixPathsTest.java new file mode 100644 index 00000000..b8f9e942 --- /dev/null +++ b/metafix/src/test/java/org/metafacture/metafix/FindFixPathsTest.java @@ -0,0 +1,102 @@ +/* + * Copyright 2023 Fabian Steeg, hbz + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.metafacture.metafix; + +import org.metafacture.framework.ObjectReceiver; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InOrder; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.exceptions.base.MockitoAssertionError; +import org.mockito.junit.jupiter.MockitoExtension; + +/** + * Tests for class {@link FindFixPaths}. + * + * @author Fabian Steeg + * + */ +@ExtendWith(MockitoExtension.class) +public final class FindFixPathsTest { + + private final FindFixPaths finder = new FindFixPaths(".*ETL.*"); + + @Mock + private ObjectReceiver receiver; + + public FindFixPathsTest() { + } + + @Test + public void testShouldListPaths() { + verify( + "3\t|\tb.*", + "2\t|\tc.*", + "1\t|\ta"); + } + + @Test + public void testShouldListPathsNoCount() { + verify( + "a", + "b.*", + "c.*"); + } + + @Test + public void testShouldListPathsUseIndex() { + verify( + "1\t|\ta", + "1\t|\tb.1", + "1\t|\tb.2", + "1\t|\tb.3", + "1\t|\tc.1", + "1\t|\tc.2"); + } + + private void processRecord() { + finder.setReceiver(receiver); + finder.startRecord(""); + finder.literal("a", "An ETL test"); + finder.literal("b", ""); + finder.literal("b", "Dummi"); + finder.literal("b", "Dog"); + finder.literal("c", ""); + finder.literal("c", "ETL what?"); + finder.endRecord(); + finder.closeStream(); + } + + private void verify(final String... result) throws MockitoAssertionError { + processRecord(); + try { + final InOrder ordered = Mockito.inOrder(receiver); + for (final String r : result) { + ordered.verify(receiver).process(r); + } + ordered.verify(receiver, Mockito.times(2)).closeStream(); + ordered.verifyNoMoreInteractions(); + Mockito.verifyNoMoreInteractions(receiver); + } catch (final MockitoAssertionError e) { + System.out.println(Mockito.mockingDetails(receiver).printInvocations()); + throw e; + } + } + +}