-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
186 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
...data-rest/src/test/java/com/contentgrid/spring/data/rest/messages/TemplatePromptTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package com.contentgrid.spring.data.rest.messages; | ||
|
||
import com.contentgrid.spring.test.fixture.invoicing.InvoicingApplication; | ||
import com.contentgrid.spring.test.fixture.invoicing.model.Customer; | ||
import com.contentgrid.spring.test.fixture.invoicing.repository.CustomerRepository; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.hateoas.MediaTypes; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers; | ||
|
||
@SpringBootTest | ||
@ContextConfiguration(classes = { | ||
InvoicingApplication.class, | ||
}) | ||
@AutoConfigureMockMvc(printOnlyOnFailure = false) | ||
class TemplatePromptTest { | ||
@Autowired | ||
MockMvc mockMvc; | ||
|
||
@Autowired | ||
CustomerRepository customerRepository; | ||
|
||
Customer customer; | ||
|
||
@BeforeEach | ||
void setup() { | ||
customer = customerRepository.save(new Customer(UUID.randomUUID(), "Abc", "ABC", null, null, null, Set.of(), Set.of())); | ||
} | ||
|
||
@AfterEach | ||
void cleanup() { | ||
customerRepository.delete(customer); | ||
customer = null; | ||
} | ||
|
||
@Test | ||
void promptOnVatAndNameInHalForms() throws Exception { | ||
mockMvc.perform(MockMvcRequestBuilders.get("/profile/customers") | ||
.accept(MediaTypes.HAL_FORMS_JSON)) | ||
.andExpect(MockMvcResultMatchers.status().isOk()) | ||
.andExpect(MockMvcResultMatchers.content().json(""" | ||
{ | ||
_templates: { | ||
search: { | ||
method: "GET", | ||
contentType: "application/json", | ||
properties: [ | ||
{ | ||
prompt: "VAT number", | ||
name: "vat", | ||
type: "text" | ||
}, | ||
{ name: "content.size", type: "number" }, { name: "content.mimetype", type: "text" }, { name: "content.filename", type: "text" }, | ||
{ name: "invoices.number", type: "text" }, { name: "invoices.paid", type: "checkbox" }, { name: "invoices.orders.id" }, { name: "invoices.content.length", type: "number" } | ||
] | ||
}, | ||
create-form: { | ||
method: "POST", | ||
contentType: "application/json", | ||
properties: [ | ||
{ | ||
prompt: "Customer name", | ||
name: "name", | ||
type: "text" | ||
}, | ||
{ | ||
prompt: "VAT number", | ||
name: "vat", | ||
type: "text" | ||
}, | ||
{ | ||
name : "birthday", | ||
type : "datetime" | ||
}, | ||
{ | ||
name : "total_spend", | ||
type : "number" | ||
}, | ||
{ name: "content.mimetype", type: "text" }, { name: "content.filename", type: "text" }, | ||
{ name : "orders", type : "url" }, { name : "invoices", type : "url" } | ||
] | ||
} | ||
} | ||
} | ||
""")) | ||
; | ||
} | ||
|
||
@Test | ||
void titleOnVatAndNameInJsonSchema() throws Exception { | ||
mockMvc.perform(MockMvcRequestBuilders.get("/profile/customers") | ||
.accept("application/schema+json")) | ||
.andExpect(MockMvcResultMatchers.status().isOk()) | ||
.andExpect(MockMvcResultMatchers.content().json(""" | ||
{ | ||
title : "Customer", | ||
properties : { | ||
name : { | ||
title : "Customer name", | ||
readOnly : false, | ||
type : "string" | ||
}, | ||
vat : { | ||
title : "VAT number", | ||
readOnly : false, | ||
type : "string" | ||
}, | ||
birthday : { | ||
title : "Birthday", | ||
readOnly : false, | ||
type : "string", | ||
format : "date-time" | ||
}, | ||
total_spend : { | ||
title : "Total spend", | ||
readOnly : false, | ||
type : "integer" | ||
} | ||
} | ||
} | ||
""")) | ||
; | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
contentgrid-spring-data-rest/src/testFixtures/resources/rest-default-messages.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
com.contentgrid.spring.test.fixture.invoicing.model.Customer.vat._prompt=VAT number | ||
com.contentgrid.spring.test.fixture.invoicing.model.Customer.name._prompt=Customer name | ||
com.contentgrid.spring.test.fixture.invoicing.model.Customer.vat._title=VAT number | ||
com.contentgrid.spring.test.fixture.invoicing.model.Customer.name._title=Customer name |