Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quarkus 36730 example - include json column in quickstart #1346

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package org.acme.hibernate.orm.panache.rest.entity;

import java.time.LocalDate;
import java.util.Map;

import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

import jakarta.persistence.Entity;
import jakarta.persistence.NamedQuery;
Expand All @@ -12,4 +16,7 @@
public class Person extends PanacheEntity {
public String name;
public LocalDate birthDate;

@JdbcTypeCode(SqlTypes.JSON)
public Map<String, Object> jsonAddress;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;

import java.util.HashMap;
import java.util.Map;

import org.apache.http.HttpStatus;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -62,12 +65,12 @@ void shouldListPersonsInDescending() {
@Test
void shouldListPersonsWithPageAndSize() {
given().accept(ContentType.JSON)
.and().queryParam("page", 0)
.and().queryParam("size", 1)
.when().get("/my-people/all")
.then().statusCode(200)
.and().body("id", contains(1))
.and().body("name", contains("John Johnson"));
.and().queryParam("page", 0)
.and().queryParam("size", 1)
.when().get("/my-people/all?sort=name")
.then().statusCode(200)
.and().body("id", contains(1))
.and().body("name", contains("John Johnson"));
}

@Test
Expand Down Expand Up @@ -113,4 +116,37 @@ void shouldDeleteNotBeExposed() {
given().when().delete("/my-people/1")
.then().statusCode(405);
}

@Test
void shouldUpdatePerson() {
given().accept(ContentType.JSON)
.when().get("/my-people/1")
.then().statusCode(200)
.and().body("id", is(equalTo(1)))
.and().body("name", is(equalTo("John Johnson")));

Person newPerson = new Person();
newPerson.id = 1L;
newPerson.name = "John Johnson";

Map<String, Object> jsonObject = new HashMap<>();
jsonObject.put("zipcode", 95014);
jsonObject.put("city", "cupertino");
newPerson.jsonAddress = jsonObject;

given().accept(ContentType.JSON)
.and().contentType(ContentType.JSON)
.and().body(newPerson)
.when().put("/my-people/1").then().statusCode(204);

// verify after updating that the new json address fields were stored
given().accept(ContentType.JSON)
.when().get("/my-people/1")
.then().statusCode(200)
.and().body("id", is(equalTo(1)))
.and().body("name", is(equalTo("John Johnson")))
.and().body("jsonAddress", is(equalTo(jsonObject)));

}

}