You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2023/03/31 04:14:50 UTC

[incubator-opendal] branch main updated: feat(bindings/java): add cucumber test (#1809)

This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new a65e3759 feat(bindings/java): add cucumber test (#1809)
a65e3759 is described below

commit a65e375954a6628709fd41d137da6d4d1d53d0f4
Author: An Li <ki...@gmail.com>
AuthorDate: Fri Mar 31 12:14:45 2023 +0800

    feat(bindings/java): add cucumber test (#1809)
    
    feat(bindings/java): add cucumber test case for memory
---
 bindings/java/pom.xml                              | 94 ++++++++++++++++++----
 bindings/java/src/lib.rs                           | 17 +++-
 .../src/main/java/org/apache/opendal/Operator.java | 16 ----
 .../java/org/apache/opendal/AsyncStepsTest.java    | 53 ++++++++++++
 .../test/java/org/apache/opendal/CucumberTest.java | 35 ++++++++
 .../test/java/org/apache/opendal/StepsTest.java    | 74 +++++++++++++++++
 .../org/apache/opendal/operator/OperatorTest.java  | 62 --------------
 7 files changed, 254 insertions(+), 97 deletions(-)

diff --git a/bindings/java/pom.xml b/bindings/java/pom.xml
index 54e141ef..5b542b5c 100644
--- a/bindings/java/pom.xml
+++ b/bindings/java/pom.xml
@@ -35,18 +35,56 @@
         <rust-maven-plugin.version>1.0.0</rust-maven-plugin.version>
     </properties>
 
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>io.cucumber</groupId>
+                <artifactId>cucumber-bom</artifactId>
+                <version>7.11.2</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+            <dependency>
+                <groupId>org.junit</groupId>
+                <artifactId>junit-bom</artifactId>
+                <version>5.9.2</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
     <dependencies>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <version>4.12</version>
-            <scope>test</scope>
-        </dependency>
         <dependency>
             <groupId>org.questdb</groupId>
             <artifactId>jar-jni</artifactId>
             <version>${rust-maven-plugin.version}</version>
         </dependency>
+        <dependency>
+            <groupId>io.cucumber</groupId>
+            <artifactId>cucumber-java</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>io.cucumber</groupId>
+            <artifactId>cucumber-junit-platform-engine</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.junit.platform</groupId>
+            <artifactId>junit-platform-suite</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+
     </dependencies>
 
     <build>
@@ -67,23 +105,47 @@
                             <goal>build</goal>
                         </goals>
                         <configuration>
-
                             <path>../java</path>
-
-
                             <release>true</release>
-
                             <copyTo>${project.build.directory}/classes/org/apache/opendal/rust/libs</copyTo>
-
                             <copyWithPlatformDir>true</copyWithPlatformDir>
-
-
                             <extraArgs>
                                 <extraArg>--color=always</extraArg>
                             </extraArgs>
-                            <environmentVariables>
-                                <REVERSED_STR_PREFIX>Great Scott, A reversed string!</REVERSED_STR_PREFIX>
-                            </environmentVariables>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.11.0</version>
+                <configuration>
+                    <encoding>UTF-8</encoding>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>3.0.0</version>
+            </plugin>
+            <plugin>
+                <groupId>com.coderplus.maven.plugins</groupId>
+                <artifactId>copy-rename-maven-plugin</artifactId>
+                <version>1.0</version>
+                <executions>
+                    <execution>
+                        <id>copy-file</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>copy</goal>
+                        </goals>
+                        <configuration>
+                            <sourceFile>../tests/features/binding.feature</sourceFile>
+                            <destinationFile>target/test-classes/features/binding.feature</destinationFile>
                         </configuration>
                     </execution>
                 </executions>
diff --git a/bindings/java/src/lib.rs b/bindings/java/src/lib.rs
index 370017bb..323f485a 100644
--- a/bindings/java/src/lib.rs
+++ b/bindings/java/src/lib.rs
@@ -38,10 +38,21 @@ pub extern "system" fn Java_org_apache_opendal_Operator_getOperator(
         .get_string(&input)
         .expect("Couldn't get java string!")
         .into();
-    let schema = Scheme::from_str(&input).unwrap();
+
+    let scheme = Scheme::from_str(&input).unwrap();
+
     let map = convert_map(&mut env, &params);
-    let operator = build_operator(schema, map).expect("Couldn't found operator");
-    Box::into_raw(Box::new(operator)) as *const i32
+    if let Ok(operator) = build_operator(scheme, map) {
+        Box::into_raw(Box::new(operator)) as *const i32
+    } else {
+        env.exception_clear().expect("Couldn't clear exception");
+        env.throw_new(
+            "java/lang/IllegalArgumentException",
+            "Unsupported operator.",
+        )
+        .expect("Couldn't throw exception");
+        std::ptr::null()
+    }
 }
 
 fn convert_map(env: &mut JNIEnv, params: &JObject) -> HashMap<String, String> {
diff --git a/bindings/java/src/main/java/org/apache/opendal/Operator.java b/bindings/java/src/main/java/org/apache/opendal/Operator.java
index 96df85a2..7a033bee 100644
--- a/bindings/java/src/main/java/org/apache/opendal/Operator.java
+++ b/bindings/java/src/main/java/org/apache/opendal/Operator.java
@@ -17,22 +17,6 @@
  * under the License.
  */
 
-// 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.opendal;
 
diff --git a/bindings/java/src/test/java/org/apache/opendal/AsyncStepsTest.java b/bindings/java/src/test/java/org/apache/opendal/AsyncStepsTest.java
new file mode 100644
index 00000000..fb3ed034
--- /dev/null
+++ b/bindings/java/src/test/java/org/apache/opendal/AsyncStepsTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.opendal;
+
+import io.cucumber.java.en.Given;
+import io.cucumber.java.en.Then;
+import io.cucumber.java.en.When;
+
+
+public class AsyncStepsTest {
+
+
+    @Given("A new OpenDAL Async Operator")
+    public void a_new_open_dal_async_operator() {
+    }
+
+    @When("Async write path {string} with content {string}")
+    public void async_write_path_test_with_content_hello_world(String fileName, String content) {
+    }
+
+    @Then("The async file {string} should exist")
+    public void the_async_file_test_should_exist(String fileName) {
+    }
+
+    @Then("The async file {string} entry mode must be file")
+    public void the_async_file_test_entry_mode_must_be_file(String fileName) {
+    }
+
+    @Then("The async file {string} content length must be {int}")
+    public void the_async_file_test_content_length_must_be_13(String fileName, int length) {
+    }
+
+    @Then("The async file {string} must have content {string}")
+    public void the_async_file_test_must_have_content_hello_world(String fileName, String content) {
+    }
+}
diff --git a/bindings/java/src/test/java/org/apache/opendal/CucumberTest.java b/bindings/java/src/test/java/org/apache/opendal/CucumberTest.java
new file mode 100644
index 00000000..785ac34c
--- /dev/null
+++ b/bindings/java/src/test/java/org/apache/opendal/CucumberTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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.opendal;
+
+import org.junit.platform.suite.api.ConfigurationParameter;
+import org.junit.platform.suite.api.IncludeEngines;
+import org.junit.platform.suite.api.SelectClasspathResource;
+import org.junit.platform.suite.api.Suite;
+
+import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
+
+@Suite
+@IncludeEngines("cucumber")
+@SelectClasspathResource("features")
+@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "org.apache.opendal")
+public class CucumberTest {
+
+}
\ No newline at end of file
diff --git a/bindings/java/src/test/java/org/apache/opendal/StepsTest.java b/bindings/java/src/test/java/org/apache/opendal/StepsTest.java
new file mode 100644
index 00000000..bca3c774
--- /dev/null
+++ b/bindings/java/src/test/java/org/apache/opendal/StepsTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.opendal;
+
+import io.cucumber.java.en.Given;
+import io.cucumber.java.en.Then;
+import io.cucumber.java.en.When;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class StepsTest {
+
+    Operator operator;
+
+    @Given("A new OpenDAL Blocking Operator")
+    public void a_new_open_dal_blocking_operator() {
+        Map<String, String> params = new HashMap<>();
+        params.put("root", "/tmp");
+        this.operator = new Operator("Memory", params);
+    }
+
+    @When("Blocking write path {string} with content {string}")
+    public void blocking_write_path_test_with_content_hello_world(String fileName, String content) {
+        this.operator.write(fileName, content);
+    }
+
+
+    @Then("The blocking file {string} should exist")
+    public void the_blocking_file_test_should_exist(String content) {
+
+    }
+
+
+    @Then("The blocking file {string} entry mode must be file")
+    public void the_blocking_file_test_entry_mode_must_be_file(String fileName) {
+
+    }
+
+    @Then("The blocking file {string} content length must be {int}")
+    public void the_blocking_file_test_content_length_must_be_13(String fileName, int length) {
+        String content = this.operator.read(fileName);
+
+        assertEquals(content.length(), length);
+    }
+
+    @Then("The blocking file {string} must have content {string}")
+    public void the_blocking_file_test_must_have_content_hello_world(String fileName, String content) {
+        String readContent = this.operator.read(fileName);
+
+        assertEquals(content, readContent);
+    }
+
+
+}
diff --git a/bindings/java/src/test/java/org/apache/opendal/operator/OperatorTest.java b/bindings/java/src/test/java/org/apache/opendal/operator/OperatorTest.java
deleted file mode 100644
index b72a4953..00000000
--- a/bindings/java/src/test/java/org/apache/opendal/operator/OperatorTest.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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.
- */
-
-// 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.opendal.operator;
-
-import org.apache.opendal.Operator;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class OperatorTest {
-
-    @Test
-    public void testBuilder() {
-        Map<String, String> params = new HashMap<>();
-        params.put("root", "/tmp");
-        Operator op = new Operator("Memory", params);
-
-        op.write("hello1.txt", "hello world");
-        String rs = op.read("hello1.txt");
-        op.delete("hello1.txt");
-
-        Assert.assertEquals(rs, "hello world");
-
-    }
-
-}
\ No newline at end of file