Skip to content

Commit

Permalink
Implement new BDD connection opening syntax (#412)
Browse files Browse the repository at this point in the history
## What is the goal of this PR?

We implement the new BDD connection/user connection syntax set up in typedb/typedb-behaviour#244.


## What are the changes implemented in this PR?

Update the BDD step definitions to reflect new syntax from the behaviour repository.
  • Loading branch information
flyingsilverfin authored Apr 21, 2023
1 parent cd20a76 commit df8bf6f
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 37 deletions.
4 changes: 2 additions & 2 deletions dependencies/vaticle/artifacts.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def vaticle_typedb_artifact():
artifact_name = "typedb-server-{platform}-{version}.{ext}",
tag_source = deployment["artifact.release"],
commit_source = deployment["artifact.snapshot"],
commit = "c78d79b00894a65dd94f219339419b278a9663dd",
commit = "c36d4deeb6a7f9b53dced92002e57c1df9963f7a",
)

def vaticle_typedb_cluster_artifact():
Expand All @@ -39,5 +39,5 @@ def vaticle_typedb_cluster_artifact():
artifact_name = "typedb-cluster-all-{platform}-{version}.{ext}",
tag_source = deployment_private["artifact.release"],
commit_source = deployment_private["artifact.snapshot"],
commit = "b00b9f016899b924fc8a083ff6183341a601f65e",
commit = "230757ad05e2b1a8cf78a3cb67d90d759de64a19",
)
2 changes: 1 addition & 1 deletion dependencies/vaticle/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def vaticle_typedb_behaviour():
git_repository(
name = "vaticle_typedb_behaviour",
remote = "https://github.com/vaticle/typedb-behaviour",
commit = "c75c64d42725163e62078218207efbcb2b5ed845" # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour
commit = "b4cbdd3aaf28428608fc88eae0852425df57fe25" # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour
)

def vaticle_factory_tracing():
Expand Down
12 changes: 9 additions & 3 deletions test/behaviour/concept/type/thingtype/ThingTypeSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

public class ThingTypeSteps {

private static final String UNRECOGNISED_VALUE = "Unrecognized value";
private static final String ILLEGAL_ARGUMENT = "Illegal argument.";

public static ThingType get_thing_type(RootLabel rootLabel, String typeLabel) {
switch (rootLabel) {
Expand All @@ -55,8 +55,10 @@ public static ThingType get_thing_type(RootLabel rootLabel, String typeLabel) {
return tx().concepts().getAttributeType(typeLabel);
case RELATION:
return tx().concepts().getRelationType(typeLabel);
case THING:
return tx().concepts().getRootThingType();
default:
throw new IllegalArgumentException(UNRECOGNISED_VALUE);
throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
}
}

Expand Down Expand Up @@ -94,7 +96,7 @@ public void put_thing_type(RootLabel rootLabel, String typeLabel) {
tx().concepts().putRelationType(typeLabel);
break;
default:
throw new IllegalArgumentException(UNRECOGNISED_VALUE);
throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
}
}

Expand Down Expand Up @@ -160,6 +162,8 @@ public void thing_type_set_supertype(RootLabel rootLabel, String typeLabel, Stri
RelationType relationSuperType = tx().concepts().getRelationType(superLabel);
tx().concepts().getRelationType(typeLabel).asRemote(tx()).setSupertype(relationSuperType);
break;
case THING:
throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
}
}

Expand All @@ -178,6 +182,8 @@ public void thing_type_set_supertype_throws_exception(RootLabel rootLabel, Strin
RelationType relationSuperType = tx().concepts().getRelationType(superLabel);
assertThrows(() -> tx().concepts().getRelationType(typeLabel).asRemote(tx()).setSupertype(relationSuperType));
break;
case THING:
throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
}
}

Expand Down
5 changes: 3 additions & 2 deletions test/behaviour/config/Parameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public LocalDateTime datetime(String dateTime) {
return LocalDateTime.parse(dateTime, formatter);
}

@ParameterType("entity|attribute|relation")
@ParameterType("entity|attribute|relation|thing")
public RootLabel root_label(String type) {
return RootLabel.of(type);
}
Expand Down Expand Up @@ -134,7 +134,8 @@ public List<TypeDBTransaction.Type> transaction_types(List<String> values) {
public enum RootLabel {
ENTITY("entity"),
ATTRIBUTE("attribute"),
RELATION("relation");
RELATION("relation"),
THING("thing");

private final String label;

Expand Down
8 changes: 7 additions & 1 deletion test/behaviour/connection/ConnectionStepsBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.vaticle.typedb.client.api.TypeDBSession;
import com.vaticle.typedb.client.api.TypeDBTransaction;
import com.vaticle.typedb.common.test.TypeDBSingleton;
import io.cucumber.java.en.When;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -113,7 +114,12 @@ void after() {

abstract TypeDBOptions createOptions();

abstract void open_connection();
abstract void connection_opens_with_default_authentication();

void connection_closes() {
client.close();
client = null;
}

void connection_has_been_opened() {
assertNotNull(client);
Expand Down
47 changes: 25 additions & 22 deletions test/behaviour/connection/ConnectionStepsCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,38 @@ TypeDBOptions createOptions() {
}

@Override
@When("open connection")
public void open_connection() {
@When("connection opens with default authentication")
public void connection_opens_with_default_authentication() {
client = createTypeDBClient(TypeDBSingleton.getTypeDBRunner().address());
}

@When("connection opens with authentication: {word}, {word}")
public void connection_opens_with_authentication(String username, String password) {
if (client != null) {
client.close();
client = null;
}

client = createTypeDBClient(TypeDBSingleton.getTypeDBRunner().address(), username, password, false);
}

@When("connection opens with authentication: {word}, {word}; throws exception")
public void connection_opens_with_authentication_throws_exception(String username, String password) {
assertThrows(() -> createTypeDBClient(TypeDBSingleton.getTypeDBRunner().address(), username, password, false));
}

@Override
@Given("connection has been opened")
public void connection_has_been_opened() {
super.connection_has_been_opened();
}

@Override
@When("connection closes")
public void connection_closes() {
super.connection_closes();
}

@Given("typedb has configuration")
public void typedb_has_configuration(Map<String, String> map) {
TypeDBSingleton.deleteTypeDBRunner();
Expand Down Expand Up @@ -109,27 +131,8 @@ public void typedb_stops() {
TypeDBSingleton.getTypeDBRunner().stop();
}

@When("user connect: {word}, {word}")
public void user_connect(String username, String password) {
if (client != null) {
client.close();
client = null;
}

client = createTypeDBClient(TypeDBSingleton.getTypeDBRunner().address(), username, password, false);
}

@When("user disconnect")
public void disconnect_current_user() {
client.close();
client = null;
}

@When("user connect: {word}, {word}; throws exception")
public void user_connect_throws_exception(String username, String password) {
assertThrows(() -> createTypeDBClient(TypeDBSingleton.getTypeDBRunner().address(), username, password, false));
}

@Override
@Given("connection does not have any database")
public void connection_does_not_have_any_database() {
super.connection_does_not_have_any_database();
Expand Down
20 changes: 14 additions & 6 deletions test/behaviour/connection/ConnectionStepsCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ TypeDBOptions createOptions() {
return TypeDBOptions.core();
}

@Override
@When("open connection")
public void open_connection() {
client = createTypeDBClient(TypeDBSingleton.getTypeDBRunner().address());
}

@When("typedb starts")
public void typedb_starts() {
TypeDBRunner runner = TypeDBSingleton.getTypeDBRunner();
Expand All @@ -87,11 +81,25 @@ public void typedb_stops() {
TypeDBSingleton.getTypeDBRunner().stop();
}

@Override
@When("connection opens with default authentication")
public void connection_opens_with_default_authentication() {
client = createTypeDBClient(TypeDBSingleton.getTypeDBRunner().address());
}

@Override
@When("connection closes")
public void connection_closes() {
super.connection_closes();
}

@Override
@Given("connection has been opened")
public void connection_has_been_opened() {
super.connection_has_been_opened();
}

@Override
@Given("connection does not have any database")
public void connection_does_not_have_any_database() {
super.connection_does_not_have_any_database();
Expand Down

0 comments on commit df8bf6f

Please sign in to comment.