Skip to content

Commit

Permalink
refactoring: create server with http status
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 cbca428 commit da79f35
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions core/src/main/java/expert/os/harperdb/HttpStatus.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package expert.os.harperdb;

import java.net.http.HttpResponse;
import java.util.function.Supplier;

/**
Expand Down Expand Up @@ -32,4 +33,8 @@ enum HttpStatus implements Supplier<Integer> {
public Integer get() {
return status;
}

public boolean isEquals(HttpResponse<?> response) {
return this.status == response.statusCode();
}
}
4 changes: 2 additions & 2 deletions core/src/main/java/expert/os/harperdb/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ static Server of(URI host, Auth auth) {
*/
public boolean schema(String schema) {
Objects.requireNonNull(schema, "schema is required");
HttpRequest request = createRequest().POST(ofByteArray(INSTANCE.writeValueAsBytes(new CreateSchema("test"))))
HttpRequest request = createRequest().POST(ofByteArray(INSTANCE.writeValueAsBytes(new CreateSchema(schema))))
.build();

try {
HttpResponse<InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
return response.statusCode() == HTTP_STATUS_OK;
return HttpStatus.OK.isEquals(response);
} catch (IOException| InterruptedException e) {
throw new HarperDBException("There is an issue to create the schema: " + schema, e);
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/java/expert/os/harperdb/ServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ void shouldCreateSchema() {
void shouldNotCreateSchemaDuplicated() {
Server server = getServer();

boolean schema = server.schema("test");
boolean schema = server.schema("duplicated");
Assertions.assertTrue(schema);
Assertions.assertFalse(server.schema("test"));
Assertions.assertFalse(server.schema("duplicated"));
}

private Server getServer() {
Expand Down

0 comments on commit da79f35

Please sign in to comment.