You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by pv...@apache.org on 2018/02/28 16:25:07 UTC

[13/20] nifi git commit: NIFI-4839 - Added abbreviation in simple output for name, description, and comments - Refactored so that commands produce a result which can then be written or used - Added support for back-referencing results, initially prototyp

http://git-wip-us.apache.org/repos/asf/nifi/blob/b68eebd4/nifi-toolkit/nifi-toolkit-cli/src/test/java/org/apache/nifi/toolkit/cli/impl/result/TestRegistryClientResult.java
----------------------------------------------------------------------
diff --git a/nifi-toolkit/nifi-toolkit-cli/src/test/java/org/apache/nifi/toolkit/cli/impl/result/TestRegistryClientResult.java b/nifi-toolkit/nifi-toolkit-cli/src/test/java/org/apache/nifi/toolkit/cli/impl/result/TestRegistryClientResult.java
new file mode 100644
index 0000000..17acacd
--- /dev/null
+++ b/nifi-toolkit/nifi-toolkit-cli/src/test/java/org/apache/nifi/toolkit/cli/impl/result/TestRegistryClientResult.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.toolkit.cli.impl.result;
+
+import org.apache.nifi.toolkit.cli.api.ResultType;
+import org.apache.nifi.web.api.dto.RegistryDTO;
+import org.apache.nifi.web.api.entity.RegistryClientEntity;
+import org.apache.nifi.web.api.entity.RegistryClientsEntity;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.nio.charset.StandardCharsets;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.UUID;
+
+public class TestRegistryClientResult {
+
+    private ByteArrayOutputStream outputStream;
+    private PrintStream printStream;
+
+    @Before
+    public void setup() {
+        this.outputStream = new ByteArrayOutputStream();
+        this.printStream = new PrintStream(outputStream, true);
+    }
+
+    @Test
+    public void testWriteSimpleRegistryClientsResult() throws IOException {
+        final RegistryDTO r1 = new RegistryDTO();
+        r1.setName("Registry 1");
+        r1.setUri("http://thisisalonglonglonglonglonglonglonglonglonguri.com:18080");
+        r1.setId(UUID.fromString("ea752054-22c6-4fc0-b851-967d9a3837cb").toString());
+
+        final RegistryDTO r2 = new RegistryDTO();
+        r2.setName("Registry 2 with a longer than usual name");
+        r2.setUri("http://localhost:18080");
+        r2.setId(UUID.fromString("ddf5f289-7502-46df-9798-4b0457c1816b").toString());
+
+        final RegistryClientEntity clientEntity1 = new RegistryClientEntity();
+        clientEntity1.setId(r1.getId());
+        clientEntity1.setComponent(r1);
+
+        final RegistryClientEntity clientEntity2 = new RegistryClientEntity();
+        clientEntity2.setId(r2.getId());
+        clientEntity2.setComponent(r2);
+
+        final Set<RegistryClientEntity> clientEntities = new HashSet<>();
+        clientEntities.add(clientEntity1);
+        clientEntities.add(clientEntity2);
+
+        final RegistryClientsEntity registryClientsEntity = new RegistryClientsEntity();
+        registryClientsEntity.setRegistries(clientEntities);
+
+        final RegistryClientsResult result = new RegistryClientsResult(ResultType.SIMPLE, registryClientsEntity);
+        result.write(printStream);
+
+        final String resultOut = new String(outputStream.toByteArray(), StandardCharsets.UTF_8);
+        //System.out.println(resultOut);
+
+        final String expected = "\n" +
+                "#   Name                                   Id                                     Uri                                                               \n" +
+                "-   ------------------------------------   ------------------------------------   ---------------------------------------------------------------   \n" +
+                "1   Registry 1                             ea752054-22c6-4fc0-b851-967d9a3837cb   http://thisisalonglonglonglonglonglonglonglonglonguri.com:18080   \n" +
+                "2   Registry 2 with a longer than usu...   ddf5f289-7502-46df-9798-4b0457c1816b   http://localhost:18080                                            \n" +
+                "\n";
+
+        Assert.assertEquals(expected, resultOut);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/nifi/blob/b68eebd4/nifi-toolkit/nifi-toolkit-cli/src/test/java/org/apache/nifi/toolkit/cli/impl/result/TestVersionedFlowSnapshotMetadataResult.java
----------------------------------------------------------------------
diff --git a/nifi-toolkit/nifi-toolkit-cli/src/test/java/org/apache/nifi/toolkit/cli/impl/result/TestVersionedFlowSnapshotMetadataResult.java b/nifi-toolkit/nifi-toolkit-cli/src/test/java/org/apache/nifi/toolkit/cli/impl/result/TestVersionedFlowSnapshotMetadataResult.java
new file mode 100644
index 0000000..48e1604
--- /dev/null
+++ b/nifi-toolkit/nifi-toolkit-cli/src/test/java/org/apache/nifi/toolkit/cli/impl/result/TestVersionedFlowSnapshotMetadataResult.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.toolkit.cli.impl.result;
+
+import org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata;
+import org.apache.nifi.toolkit.cli.api.ResultType;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.nio.charset.StandardCharsets;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.List;
+
+public class TestVersionedFlowSnapshotMetadataResult {
+
+    private ByteArrayOutputStream outputStream;
+    private PrintStream printStream;
+
+    @Before
+    public void setup() {
+        this.outputStream = new ByteArrayOutputStream();
+        this.printStream = new PrintStream(outputStream, true);
+    }
+
+    @Test
+    public void testWriteSimpleVersionedFlowSnapshotResult() throws ParseException, IOException {
+        final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
+
+        final VersionedFlowSnapshotMetadata vfs1 = new VersionedFlowSnapshotMetadata();
+        vfs1.setVersion(1);
+        vfs1.setAuthor("user1");
+        vfs1.setTimestamp(dateFormat.parse("2018-02-14T12:00:00").getTime());
+        vfs1.setComments("This is a long comment, longer than the display limit for comments");
+
+        final VersionedFlowSnapshotMetadata vfs2 = new VersionedFlowSnapshotMetadata();
+        vfs2.setVersion(2);
+        vfs2.setAuthor("user2");
+        vfs2.setTimestamp(dateFormat.parse("2018-02-14T12:30:00").getTime());
+        vfs2.setComments("This is v2");
+
+        final List<VersionedFlowSnapshotMetadata> versions = new ArrayList<>();
+        versions.add(vfs1);
+        versions.add(vfs2);
+
+        final VersionedFlowSnapshotMetadataResult result = new VersionedFlowSnapshotMetadataResult(ResultType.SIMPLE, versions);
+        result.write(printStream);
+
+        final String resultOut = new String(outputStream.toByteArray(), StandardCharsets.UTF_8);
+        //System.out.println(resultOut);
+
+        final String expected = "\n" +
+                "Ver   Date                         Author   Message                                    \n" +
+                "---   --------------------------   ------   ----------------------------------------   \n" +
+                "1     Wed, Feb 14 2018 12:00 EST   user1    This is a long comment, longer than t...   \n" +
+                "2     Wed, Feb 14 2018 12:30 EST   user2    This is v2                                 \n" +
+                "\n";
+
+        Assert.assertEquals(expected, resultOut);
+    }
+}

http://git-wip-us.apache.org/repos/asf/nifi/blob/b68eebd4/nifi-toolkit/nifi-toolkit-cli/src/test/java/org/apache/nifi/toolkit/cli/impl/result/TestVersionedFlowsResult.java
----------------------------------------------------------------------
diff --git a/nifi-toolkit/nifi-toolkit-cli/src/test/java/org/apache/nifi/toolkit/cli/impl/result/TestVersionedFlowsResult.java b/nifi-toolkit/nifi-toolkit-cli/src/test/java/org/apache/nifi/toolkit/cli/impl/result/TestVersionedFlowsResult.java
new file mode 100644
index 0000000..bc0bd06
--- /dev/null
+++ b/nifi-toolkit/nifi-toolkit-cli/src/test/java/org/apache/nifi/toolkit/cli/impl/result/TestVersionedFlowsResult.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.toolkit.cli.impl.result;
+
+import org.apache.nifi.registry.flow.VersionedFlow;
+import org.apache.nifi.toolkit.cli.api.ResultType;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+public class TestVersionedFlowsResult {
+
+    private ByteArrayOutputStream outputStream;
+    private PrintStream printStream;
+
+    @Before
+    public void setup() {
+        this.outputStream = new ByteArrayOutputStream();
+        this.printStream = new PrintStream(outputStream, true);
+    }
+
+    @Test
+    public void testWriteSimpleVersionedFlowsResult() throws IOException {
+        final VersionedFlow f1 = new VersionedFlow();
+        f1.setName("Flow 1");
+        f1.setDescription("This is flow 1");
+        f1.setIdentifier(UUID.fromString("ea752054-22c6-4fc0-b851-967d9a3837cb").toString());
+
+        final VersionedFlow f2 = new VersionedFlow();
+        f2.setName("Flow 2");
+        f2.setDescription(null);
+        f2.setIdentifier(UUID.fromString("ddf5f289-7502-46df-9798-4b0457c1816b").toString());
+
+        final List<VersionedFlow> flows = new ArrayList<>();
+        flows.add(f1);
+        flows.add(f2);
+
+        final VersionedFlowsResult result = new VersionedFlowsResult(ResultType.SIMPLE, flows);
+        result.write(printStream);
+
+        final String resultOut = new String(outputStream.toByteArray(), StandardCharsets.UTF_8);
+        //System.out.println(resultOut);
+
+        final String expected = "\n" +
+                "#   Name     Id                                     Description      \n" +
+                "-   ------   ------------------------------------   --------------   \n" +
+                "1   Flow 1   ea752054-22c6-4fc0-b851-967d9a3837cb   This is flow 1   \n" +
+                "2   Flow 2   ddf5f289-7502-46df-9798-4b0457c1816b   (empty)          \n" +
+                "\n";
+
+        Assert.assertEquals(expected, resultOut);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/nifi/blob/b68eebd4/nifi-toolkit/nifi-toolkit-cli/src/test/java/org/apache/nifi/toolkit/cli/impl/result/writer/TestDynamicTableWriter.java
----------------------------------------------------------------------
diff --git a/nifi-toolkit/nifi-toolkit-cli/src/test/java/org/apache/nifi/toolkit/cli/impl/result/writer/TestDynamicTableWriter.java b/nifi-toolkit/nifi-toolkit-cli/src/test/java/org/apache/nifi/toolkit/cli/impl/result/writer/TestDynamicTableWriter.java
new file mode 100644
index 0000000..49e9a64
--- /dev/null
+++ b/nifi-toolkit/nifi-toolkit-cli/src/test/java/org/apache/nifi/toolkit/cli/impl/result/writer/TestDynamicTableWriter.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.toolkit.cli.impl.result.writer;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.nio.charset.StandardCharsets;
+
+public class TestDynamicTableWriter {
+
+    private Table table;
+    private TableWriter tableWriter;
+
+    private ByteArrayOutputStream outputStream;
+    private PrintStream printStream;
+
+    @Before
+    public void setup() {
+        this.table = new Table.Builder()
+                .column("#", 3, 3, false)
+                .column("Name", 20, 36, true)
+                .column("Id", 36, 36, false)
+                .column("Description", 11, 40, true)
+                .build();
+
+        this.tableWriter = new DynamicTableWriter();
+
+        this.outputStream = new ByteArrayOutputStream();
+        this.printStream = new PrintStream(outputStream, true);
+    }
+
+    @Test
+    public void testWriteEmptyTable() {
+        tableWriter.write(table, printStream);
+
+        final String result = new String(outputStream.toByteArray(), StandardCharsets.UTF_8);
+        //System.out.println(result);
+
+        final String expected = "\n" +
+                "#     Name                   Id                                     Description   \n" +
+                "---   --------------------   ------------------------------------   -----------   \n" +
+                "\n";
+
+        Assert.assertEquals(expected, result);
+    }
+
+    @Test
+    public void testDynamicTableWriter() {
+        table.addRow(
+                "1",
+                "Bucket 1",
+                "12345-12345-12345-12345-12345-12345",
+                ""
+        );
+
+        table.addRow(
+                "2",
+                "Bucket 2 - This is a really really really long name",
+                "12345-12345-12345-12345-12345-12345",
+                "This is a really really really really really really really really really really long description"
+        );
+
+        table.addRow(
+                "3",
+                "Bucket 3",
+                "12345-12345-12345-12345-12345-12345",
+                null
+        );
+
+        tableWriter.write(table, printStream);
+
+        final String result = new String(outputStream.toByteArray(), StandardCharsets.UTF_8);
+        //System.out.println(result);
+
+        final String expected = "\n" +
+                "#   Name                                   Id                                    Description                                \n" +
+                "-   ------------------------------------   -----------------------------------   ----------------------------------------   \n" +
+                "1   Bucket 1                               12345-12345-12345-12345-12345-12345                                              \n" +
+                "2   Bucket 2 - This is a really reall...   12345-12345-12345-12345-12345-12345   This is a really really really really...   \n" +
+                "3   Bucket 3                               12345-12345-12345-12345-12345-12345   (empty)                                    \n" +
+                "\n";
+
+        Assert.assertEquals(expected, result);
+    }
+
+    @Test
+    public void testWhenAllDescriptionsAreEmpty() {
+        table.addRow("1", "Bucket 1", "12345-12345-12345-12345-12345-12345", null);
+        table.addRow("2", "Bucket 2", "12345-12345-12345-12345-12345-12345", null);
+        tableWriter.write(table, printStream);
+
+        final String result = new String(outputStream.toByteArray(), StandardCharsets.UTF_8);
+        //System.out.println(result);
+
+        final String expected ="\n" +
+                "#   Name       Id                                    Description   \n" +
+                "-   --------   -----------------------------------   -----------   \n" +
+                "1   Bucket 1   12345-12345-12345-12345-12345-12345   (empty)       \n" +
+                "2   Bucket 2   12345-12345-12345-12345-12345-12345   (empty)       \n" +
+                "\n";
+
+        Assert.assertEquals(expected, result);
+    }
+
+}
\ No newline at end of file