Skip to content

Commit

Permalink
feat(bindings/java): add cucumber test (#1809)
Browse files Browse the repository at this point in the history
feat(bindings/java): add cucumber test case for memory
  • Loading branch information
kidylee authored Mar 31, 2023
1 parent 8fe859a commit a65e375
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 97 deletions.
94 changes: 78 additions & 16 deletions bindings/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down
17 changes: 14 additions & 3 deletions bindings/java/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
16 changes: 0 additions & 16 deletions bindings/java/src/main/java/org/apache/opendal/Operator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
53 changes: 53 additions & 0 deletions bindings/java/src/test/java/org/apache/opendal/AsyncStepsTest.java
Original file line number Diff line number Diff line change
@@ -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) {
}
}
35 changes: 35 additions & 0 deletions bindings/java/src/test/java/org/apache/opendal/CucumberTest.java
Original file line number Diff line number Diff line change
@@ -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 {

}
74 changes: 74 additions & 0 deletions bindings/java/src/test/java/org/apache/opendal/StepsTest.java
Original file line number Diff line number Diff line change
@@ -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);
}


}

This file was deleted.

0 comments on commit a65e375

Please sign in to comment.