|
| 1 | +/* |
| 2 | + * Copyright © 2021-present Arcade Data Ltd (info@arcadedata.com) |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + * SPDX-FileCopyrightText: 2021-present Arcade Data Ltd (info@arcadedata.com) |
| 17 | + * SPDX-License-Identifier: Apache-2.0 |
| 18 | + */ |
| 19 | +package com.arcadedb.gremlin; |
| 20 | + |
| 21 | +import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine; |
| 22 | +import org.apache.tinkerpop.gremlin.jsr223.CoreGremlinPlugin; |
| 23 | +import org.apache.tinkerpop.gremlin.jsr223.Customizer; |
| 24 | +import org.junit.jupiter.api.Test; |
| 25 | + |
| 26 | +import javax.script.ScriptException; |
| 27 | + |
| 28 | +import static org.assertj.core.api.Assertions.assertThat; |
| 29 | + |
| 30 | +/** |
| 31 | + * Verifies that the Gremlin Groovy script engine initialises correctly with the TinkerPop |
| 32 | + * core imports. With Groovy 5 (incompatible with TinkerPop 3.8.x) this fails with |
| 33 | + * "The name valueOf is already declared" because {@code ImportGroovyCustomizer} adds a |
| 34 | + * wildcard static import ({@code import static Enum.*}) for every enum in |
| 35 | + * {@link org.apache.tinkerpop.gremlin.jsr223.CoreImports}, and Groovy 5 rejects duplicate |
| 36 | + * {@code valueOf} symbols introduced by multiple such imports. |
| 37 | + * |
| 38 | + * <p>Regression test for <a href="https://github.com/ArcadeData/arcadedb/issues/3724">#3724</a>. |
| 39 | + */ |
| 40 | +class GremlinGroovyEngineTest { |
| 41 | + |
| 42 | + @Test |
| 43 | + void groovyEngineInitializesWithCoreImports() throws ScriptException { |
| 44 | + final Customizer[] customizers = CoreGremlinPlugin.instance() |
| 45 | + .getCustomizers("gremlin-groovy") |
| 46 | + .orElse(new Customizer[0]); |
| 47 | + |
| 48 | + final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(customizers); |
| 49 | + |
| 50 | + // A successful eval proves the engine started without "valueOf is already declared" |
| 51 | + assertThat(engine.eval("1 + 1")).isEqualTo(2); |
| 52 | + } |
| 53 | +} |
0 commit comments