Skip to content

Commit

Permalink
feat: create template class
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio Santana <[email protected]>
  • Loading branch information
otaviojava committed Nov 28, 2023
1 parent a8537e4 commit f6709f7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/src/main/java/expert/os/harperdb/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public CreateTableBuilder createTable(String schema){
return new CreateTableBuilder(schema, this);
}

public Template template(String database){
Objects.requireNonNull(database, "database is required");
return new Template(database, this);
}

boolean executeTableCreation(CreateTable operation) {
HttpRequest request = createRequest()
.POST(ofByteArray(INSTANCE.writeValueAsBytes(operation)))
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/expert/os/harperdb/Template.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package expert.os.harperdb;

public final class Template {
private final String database;
private final Server server;
Template(String database, Server server) {

this.database = database;
this.server = server;
}
}
15 changes: 15 additions & 0 deletions core/src/test/java/expert/os/harperdb/ServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ void shouldCreateTable() {
});
}

@Test
void shouldReturnNPEWhenTemplateIsNull() {
Server server = getServer();

Assertions.assertThrows(NullPointerException.class, () -> server.template(null));
}

@Test
void shouldCreateTemplate() {
Server server = getServer();

SoftAssertions.assertSoftly(softly -> {
softly.assertThat(server.template("test")).isNotNull();
});
}

private Server getServer() {
return ServerBuilder.of(container.host())
Expand Down

0 comments on commit f6709f7

Please sign in to comment.