Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up JDK 11
uses: actions/setup-java@v5
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'
cache: maven

Expand Down
53 changes: 25 additions & 28 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
<description>Ministry of Magic — Registered Wizards Management Service</description>

<properties>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release>
<dropwizard.version>4.0.2</dropwizard.version>
<h2.version>2.2.224</h2.version>
<maven.compiler.release>17</maven.compiler.release>
<dropwizard.version>4.0.9</dropwizard.version>
<mainClass>org.ministry.magic.WizardRegistryApplication</mainClass>
</properties>

Expand All @@ -35,16 +33,23 @@
</dependencyManagement>

<dependencies>
<!-- Dropwizard Core -->
<!-- H2 Database -->
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>

<!-- Dropwizard JDBI3 -->
<!-- Swagger -->
<dependency>
<groupId>com.smoketurner</groupId>
<artifactId>dropwizard-swagger</artifactId>
<version>4.0.5-1</version>
</dependency>

<!-- Dropwizard Core -->
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-jdbi3</artifactId>
<artifactId>dropwizard-core</artifactId>
</dependency>

<!-- Dropwizard Database -->
Expand All @@ -65,18 +70,10 @@
<artifactId>dropwizard-jackson</artifactId>
</dependency>

<!-- Swagger -->
<dependency>
<groupId>com.smoketurner</groupId>
<artifactId>dropwizard-swagger</artifactId>
<version>4.0.5-1</version>
</dependency>

<!-- H2 Database -->
<!-- Dropwizard JDBI3 -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-jdbi3</artifactId>
</dependency>

<!-- Test Dependencies -->
Expand All @@ -86,18 +83,18 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -117,9 +114,9 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<version>3.15.0</version>
<configuration>
<release>11</release>
<release>17</release>
</configuration>
</plugin>
<plugin>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/ministry/magic/core/Wizard.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.ministry.magic.core;

import java.time.LocalDate;
import java.time.Instant;
import java.time.LocalDate;
import java.util.UUID;

public class Wizard {
Expand Down
45 changes: 24 additions & 21 deletions src/main/java/org/ministry/magic/db/WizardDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@ public WizardDAO(Jdbi jdbi) {

public void createTable() {
jdbi.useHandle(handle -> handle.execute(
"CREATE TABLE IF NOT EXISTS wizards (" +
" id UUID PRIMARY KEY," +
" first_name VARCHAR(200) NOT NULL," +
" last_name VARCHAR(200) NOT NULL," +
" date_of_birth DATE NOT NULL," +
" house VARCHAR(50) NOT NULL," +
" patronus VARCHAR(200)," +
" wand_wood VARCHAR(100)," +
" wand_core VARCHAR(100)," +
" wand_length_inches DOUBLE," +
" status VARCHAR(20) NOT NULL DEFAULT 'ACTIVE'," +
" registered_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," +
" updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP" +
")"
"""
CREATE TABLE IF NOT EXISTS wizards (\
id UUID PRIMARY KEY,\
first_name VARCHAR(200) NOT NULL,\
last_name VARCHAR(200) NOT NULL,\
date_of_birth DATE NOT NULL,\
house VARCHAR(50) NOT NULL,\
patronus VARCHAR(200),\
wand_wood VARCHAR(100),\
wand_core VARCHAR(100),\
wand_length_inches DOUBLE,\
status VARCHAR(20) NOT NULL DEFAULT 'ACTIVE',\
registered_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP\
)"""
));
}

Expand All @@ -49,10 +50,11 @@ public Wizard insert(Wizard wizard) {
}

jdbi.useHandle(handle -> handle.createUpdate(
"INSERT INTO wizards (id, first_name, last_name, date_of_birth, house, " +
"patronus, wand_wood, wand_core, wand_length_inches, status, registered_at, updated_at) " +
"VALUES (:id, :firstName, :lastName, :dateOfBirth, :house, " +
":patronus, :wandWood, :wandCore, :wandLengthInches, :status, :registeredAt, :updatedAt)")
"""
INSERT INTO wizards (id, first_name, last_name, date_of_birth, house, \
patronus, wand_wood, wand_core, wand_length_inches, status, registered_at, updated_at) \
VALUES (:id, :firstName, :lastName, :dateOfBirth, :house, \
:patronus, :wandWood, :wandCore, :wandLengthInches, :status, :registeredAt, :updatedAt)""")
.bind("id", wizard.getId())
.bind("firstName", wizard.getFirstName())
.bind("lastName", wizard.getLastName())
Expand Down Expand Up @@ -120,9 +122,10 @@ public List<Wizard> searchByName(String query) {
public void update(Wizard wizard) {
wizard.setUpdatedAt(Instant.now());
jdbi.useHandle(handle -> handle.createUpdate(
"UPDATE wizards SET patronus = :patronus, wand_wood = :wandWood, " +
"wand_core = :wandCore, wand_length_inches = :wandLengthInches, " +
"status = :status, updated_at = :updatedAt WHERE id = :id")
"""
UPDATE wizards SET patronus = :patronus, wand_wood = :wandWood, \
wand_core = :wandCore, wand_length_inches = :wandLengthInches, \
status = :status, updated_at = :updatedAt WHERE id = :id""")
.bind("id", wizard.getId())
.bind("patronus", wizard.getPatronus())
.bind("wandWood", wizard.getWandWood())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package org.ministry.magic.resources;

import io.swagger.v3.oas.annotations.Operation;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.ministry.magic.api.CreateWizardRequest;
import org.ministry.magic.core.House;
import org.ministry.magic.core.WandCore;
Expand All @@ -15,6 +9,12 @@
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.ByteArrayInputStream;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.ministry.magic.resources;

import io.swagger.v3.oas.annotations.Operation;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.ministry.magic.api.CreateWizardRequest;
import org.ministry.magic.api.UpdateWizardRequest;
import org.ministry.magic.api.WizardResponse;
import org.ministry.magic.core.RegistrationStatus;
import org.ministry.magic.core.Wizard;
import org.ministry.magic.service.WizardService;

import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.net.URI;
import java.util.List;
import java.util.UUID;
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/org/ministry/magic/service/WizardService.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,11 @@ public long countActiveWizards() {
}

public String describeRegistrationEvent(Object event) {
if (event instanceof Wizard) {
Wizard w = (Wizard) event;
if (event instanceof Wizard w) {
return "Wizard registration: " + w.getFirstName() + " " + w.getLastName();
} else if (event instanceof String) {
String msg = (String) event;
} else if (event instanceof String msg) {
return "Registry message: " + msg;
} else if (event instanceof List) {
List list = (List) event;
} else if (event instanceof List list) {
return "Batch event: " + list.size() + " records";
}
return "Unknown event type";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
import io.dropwizard.testing.ResourceHelpers;
import io.dropwizard.testing.junit5.DropwizardAppExtension;
import io.dropwizard.testing.junit5.DropwizardExtensionsSupport;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.core.GenericType;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
Expand All @@ -19,6 +14,11 @@
import org.ministry.magic.core.House;
import org.ministry.magic.core.WandCore;

import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.core.GenericType;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.time.LocalDate;
import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -206,7 +206,7 @@ void notFoundForMissingWizard() {
}

@Test
void testSupportAccessible() {
void supportAccessible() {
assertThat(APP.getTestSupport()).isNotNull();
assertThat(APP.getTestSupport().getEnvironment()).isNotNull();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.ministry.magic;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.dropwizard.configuration.ConfigurationException;
import io.dropwizard.configuration.ConfigurationFactory;
import io.dropwizard.configuration.ConfigurationFactoryFactory;
import io.dropwizard.configuration.DefaultConfigurationFactoryFactory;
Expand All @@ -12,7 +11,6 @@
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -22,7 +20,7 @@ class WizardRegistryConfigurationTest {
private final Validator validator = Validation.buildDefaultValidatorFactory().getValidator();

@Test
void canDeserializeFromYaml() throws IOException, ConfigurationException {
void canDeserializeFromYaml() throws Exception {
ConfigurationFactoryFactory<WizardRegistryConfiguration> factoryFactory =
new DefaultConfigurationFactoryFactory<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class WizardServiceTest {
Expand Down
Loading