1+ /*
2+ * Licensed to the Apache Software Foundation (ASF) under one
3+ * or more contributor license agreements. See the NOTICE file
4+ * distributed with this work for additional information
5+ * regarding copyright ownership. The ASF licenses this file
6+ * to you under the Apache License, Version 2.0 (the
7+ * "License"); you may not use this file except in compliance
8+ * with the License. You may obtain a copy of the License at
9+ *
10+ * http://www.apache.org/licenses/LICENSE-2.0
11+ *
12+ * Unless required by applicable law or agreed to in writing,
13+ * software distributed under the License is distributed on an
14+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+ * KIND, either express or implied. See the License for the
16+ * specific language governing permissions and limitations
17+ * under the License.
18+ */
19+
20+ package org .apache .tinkerpop .gremlin .jsr223 ;
21+
22+ import org .apache .tinkerpop .gremlin .process .traversal .Bytecode ;
23+ import org .apache .tinkerpop .gremlin .process .traversal .P ;
24+ import org .apache .tinkerpop .gremlin .process .traversal .Traversal ;
25+ import org .apache .tinkerpop .gremlin .process .traversal .dsl .graph .GraphTraversalSource ;
26+ import org .apache .tinkerpop .gremlin .structure .util .empty .EmptyGraph ;
27+ import org .junit .Test ;
28+
29+ import static org .junit .Assert .assertEquals ;
30+
31+ public class JavaTranslatorTest {
32+ private GraphTraversalSource g = EmptyGraph .instance ().traversal ();
33+ private JavaTranslator <GraphTraversalSource , Traversal .Admin <?, ?>> translator = JavaTranslator .of (EmptyGraph .instance ().traversal ());
34+
35+ @ Test
36+ public void shouldTranslateHasWithObjectThirdArgValue () {
37+ final Bytecode bytecode = new Bytecode ();
38+ bytecode .addStep ("E" );
39+ bytecode .addStep ("has" , "knows" , "weight" , 1.0 );
40+ final Traversal .Admin <?, ?> translation = translator .translate (bytecode );
41+ assertEquals (g .E ().has ("knows" , "weight" , 1.0 ).asAdmin (), translation );
42+ }
43+
44+ @ Test
45+ public void shouldTranslateHasWithPredicateThirdArgValue () {
46+ final Bytecode bytecode = new Bytecode ();
47+ bytecode .addStep ("E" );
48+ bytecode .addStep ("has" , "knows" , "weight" , P .eq (1.0 ));
49+ final Traversal .Admin <?, ?> translation = translator .translate (bytecode );
50+ assertEquals (g .E ().has ("knows" , "weight" , P .eq (1.0 )).asAdmin (), translation );
51+ }
52+
53+ @ Test
54+ public void shouldTranslateHasWithNullThirdArgValue () {
55+ final Bytecode bytecode = new Bytecode ();
56+ bytecode .addStep ("E" );
57+ bytecode .addStep ("has" , "knows" , "weight" , null );
58+ final Traversal .Admin <?, ?> translation = translator .translate (bytecode );
59+ assertEquals (g .E ().has ("knows" , "weight" , (String ) null ).asAdmin (), translation );
60+ }
61+
62+ @ Test
63+ public void shouldTranslateHasWithObjectSecondArgValue () {
64+ final Bytecode bytecode = new Bytecode ();
65+ bytecode .addStep ("E" );
66+ bytecode .addStep ("has" , "weight" , 1.0 );
67+ final Traversal .Admin <?, ?> translation = translator .translate (bytecode );
68+ assertEquals (g .E ().has ("weight" , 1.0 ).asAdmin (), translation );
69+ }
70+
71+ @ Test
72+ public void shouldTranslateHasWithPredicateSecondArgValue () {
73+ final Bytecode bytecode = new Bytecode ();
74+ bytecode .addStep ("E" );
75+ bytecode .addStep ("has" , "weight" , P .eq (1.0 ));
76+ final Traversal .Admin <?, ?> translation = translator .translate (bytecode );
77+ assertEquals (g .E ().has ("weight" , P .eq (1.0 )).asAdmin (), translation );
78+ }
79+
80+ @ Test
81+ public void shouldTranslateHasWithNullSecondArgValue () {
82+ final Bytecode bytecode = new Bytecode ();
83+ bytecode .addStep ("E" );
84+ bytecode .addStep ("has" , "weight" , null );
85+ final Traversal .Admin <?, ?> translation = translator .translate (bytecode );
86+ assertEquals (g .E ().has ("weight" , (String ) null ).asAdmin (), translation );
87+ }
88+
89+ }
0 commit comments