AMashenkov commented on code in PR #2494:
URL: https://github.com/apache/ignite-3/pull/2494#discussion_r1307434968


##########
modules/system-view/src/test/java/org/apache/ignite/internal/systemview/SystemViewTest.java:
##########
@@ -0,0 +1,255 @@
+/*
+ * 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.ignite.internal.systemview;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Supplier;
+import org.apache.ignite.internal.systemview.NodeSystemView.Builder;
+import org.apache.ignite.internal.util.AsyncCursor;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.function.Executable;
+
+/**
+ * Tests for {@link SystemView}.
+ */
+public class SystemViewTest {
+
+    /** Builds a cluster view. */
+    @Test
+    public void buildClusterView() {
+        Supplier<AsyncCursor<Dummy>> dataProvider = dataProvider();
+
+        ClusterSystemView<Dummy> view = ClusterSystemView.<Dummy>builder()
+                .name("view")
+                .addColumn("c1", int.class, (d) -> 0)
+                .addColumn("c2", Long.class, (d) -> 1L)
+                .dataProvider(dataProvider)
+                .build();
+
+        assertEquals("view", view.name(), "name");
+        assertEquals(2, view.columns().size(), "columns");
+
+        expectColumn(view.columns().get(0), "c1", int.class);
+        expectColumn(view.columns().get(1), "c2", Long.class);
+
+        assertSame(dataProvider, view.dataProvider(), "data provider");
+    }
+
+    /** Builds a node view. */
+    @Test
+    public void buildNodeView() {
+        Supplier<AsyncCursor<Dummy>> dataProvider = dataProvider();
+
+        NodeSystemView<Dummy> view = NodeSystemView.<Dummy>builder()
+                .name("view")
+                .addColumn("c1", int.class, (d) -> 0)
+                .addColumn("c2", Long.class, (d) -> 1L)
+                .nodeNameColumnAlias("node_name")
+                .dataProvider(dataProvider)
+                .build();
+
+        assertEquals("view", view.name(), "name");
+        assertEquals(2, view.columns().size(), "columns");
+
+        expectColumn(view.columns().get(0), "c1", int.class);
+        expectColumn(view.columns().get(1), "c2", Long.class);
+
+        assertSame(dataProvider, view.dataProvider(), "data provider");
+        assertEquals("node_name", view.nodeNameColumnAlias(), "node name 
column alias");
+    }
+
+    /** Reject a node view without node name alias. */
+    @Test
+    public void rejectNodeViewWithoutNodeNameColumnAlias() {
+        expectThrows(NullPointerException.class, () -> {
+            NodeSystemView.<Dummy>builder()
+                    .name("name")
+                    .addColumn("c1", int.class, (d) -> 0)
+                    .dataProvider(dataProvider())
+                    .build();
+        }, "nodeNameColumnAlias");
+    }
+
+    /**
+     * Tests for {@link NodeSystemView.Builder}.
+     */
+    @Nested
+    public class NodeViewBuilderTest extends 
BuilderTest<NodeSystemView<Dummy>, Builder<Dummy>> {
+
+        @Override
+        protected NodeSystemView.Builder<Dummy> newBuilder() {
+            return NodeSystemView.builder();
+        }
+    }
+
+    /**
+     * Tests for {@link ClusterSystemView.Builder}.
+     */
+    @Nested
+    public class ClusterViewBuilderTest extends 
BuilderTest<ClusterSystemView<Dummy>, ClusterSystemView.Builder<Dummy>> {
+
+        @Override
+        protected ClusterSystemView.Builder<Dummy> newBuilder() {
+            return ClusterSystemView.builder();
+        }
+    }
+
+    /**
+     * Common tests for view builder classes.
+     *
+     * @param <V> View type.
+     * @param <B> Builder type.
+     */
+    public abstract class BuilderTest<V extends SystemView<Dummy>,
+            B extends SystemView.SystemViewBuilder<V, Dummy, B>> {
+
+        protected abstract B newBuilder();
+
+        /** Reject a view with {@code null} name. */
+        @Test
+        public void rejectViewWithNullName() {
+            expectThrows(NullPointerException.class, () -> {

Review Comment:
   Also, I think we could validate that nodeNameColumnAlias refers to the 
column of `String.class` (or `UUID.class`) type .



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to