spmallette commented on code in PR #3433:
URL: https://github.com/apache/tinkerpop/pull/3433#discussion_r3305828174


##########
gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/pdt/ProviderDefinedTypeIntegrateTest.java:
##########
@@ -0,0 +1,286 @@
+/*
+ * 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.tinkerpop.gremlin.server.pdt;
+
+import org.apache.http.Consts;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+import org.apache.tinkerpop.gremlin.driver.Client;
+import org.apache.tinkerpop.gremlin.driver.Cluster;
+import org.apache.tinkerpop.gremlin.driver.RequestOptions;
+import org.apache.tinkerpop.gremlin.driver.Result;
+import org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection;
+import 
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import 
org.apache.tinkerpop.gremlin.server.AbstractGremlinServerIntegrationTest;
+import org.apache.tinkerpop.gremlin.server.TestClientFactory;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens;
+import org.apache.tinkerpop.gremlin.structure.io.pdt.ProviderDefinedType;
+import 
org.apache.tinkerpop.gremlin.structure.io.pdt.ProviderDefinedTypeAdapter;
+import 
org.apache.tinkerpop.gremlin.structure.io.pdt.ProviderDefinedTypeRegistry;
+import org.apache.tinkerpop.shaded.jackson.databind.JsonNode;
+import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper;
+import org.junit.After;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Supplier;
+
+import static 
org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Integration tests verifying that Provider Defined Types (PDT) flow 
end-to-end through gremlin-server.
+ * <p>
+ * The PDT serialization converts {@code @ProviderDefined}-annotated objects 
to {@link ProviderDefinedType}
+ * during GraphBinary serialization. On the client side, values are always 
deserialized as
+ * {@link ProviderDefinedType} (unless a {@code ProviderDefinedTypeAdapter} is 
registered).
+ */
+public class ProviderDefinedTypeIntegrateTest extends 
AbstractGremlinServerIntegrationTest {
+
+    private static final RequestOptions GROOVY = 
RequestOptions.build().language("gremlin-groovy").create();
+
+    private final Supplier<Graph> graphGetter =
+            () -> 
server.getServerGremlinExecutor().getGraphManager().getGraph("graph");
+
+    @After
+    public void cleanup() {
+        final Graph graph = graphGetter.get();
+        graph.traversal().V().hasLabel("location").drop().iterate();
+    }
+
+    @Test
+    public void shouldStoreAndRetrievePdtViaGremlinLang() throws Exception {
+        final Cluster cluster = TestClientFactory.build().create();
+        final Client client = cluster.connect();
+
+        try {
+            // Store a Point as a vertex property using gremlin-lang PDT 
literal
+            client.submit(
+                    "g.addV('location').property('point', PDT(\"Point\", 
[\"x\":1, \"y\":2])).iterate()").all().get();
+
+            // Retrieve the property value - it should come back as 
ProviderDefinedType
+            final List<Result> results = client.submit(
+                    "g.V().hasLabel('location').values('point')").all().get();
+
+            assertEquals(1, results.size());
+            final Object obj = results.get(0).getObject();
+            assertTrue("Expected ProviderDefinedType but got: " + 
obj.getClass().getName(),
+                    obj instanceof ProviderDefinedType);
+
+            final ProviderDefinedType pdt = (ProviderDefinedType) obj;
+            assertEquals("Point", pdt.getName());
+            assertEquals(2, pdt.getProperties().size());
+            assertEquals(1, pdt.getProperties().get("x"));
+            assertEquals(2, pdt.getProperties().get("y"));
+        } finally {
+            cluster.close();
+        }
+    }
+
+    @Test
+    public void shouldRetrievePdtViaBytecodeTraversal() throws Exception {
+        final Cluster cluster = TestClientFactory.build().create();
+        final Client client = cluster.connect();
+
+        try {
+            // Store via gremlin-lang PDT literal
+            client.submit(
+                    "g.addV('location').property('point', PDT(\"Point\", 
[\"x\":10, \"y\":20])).iterate()").all().get();
+
+            // Retrieve via bytecode traversal (gremlin-lang)

Review Comment:
   bytecode?



-- 
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