Unverified Commit cb0dcc0f authored by Selvakumar Kamatchinathan's avatar Selvakumar Kamatchinathan Committed by GitHub
Browse files

Merge pull request #13 from selvaebi/T2D-236

T2D-236 phenotype description and type addition
parents a91cb7b8 9b6b41d9
...@@ -19,6 +19,7 @@ package uk.ac.ebi.ampt2d.registry.entities; ...@@ -19,6 +19,7 @@ package uk.ac.ebi.ampt2d.registry.entities;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener; import org.springframework.data.jpa.domain.support.AuditingEntityListener;
...@@ -29,16 +30,17 @@ import javax.persistence.EntityListeners; ...@@ -29,16 +30,17 @@ import javax.persistence.EntityListeners;
import javax.persistence.EnumType; import javax.persistence.EnumType;
import javax.persistence.Enumerated; import javax.persistence.Enumerated;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import java.time.ZonedDateTime; import java.util.Date;
@Entity @Entity
@EntityListeners({AuditingEntityListener.class, EntityEventListener.class}) @EntityListeners({AuditingEntityListener.class, EntityEventListener.class})
public class Phenotype implements IdentifiableEntity<String> { public class Phenotype implements IdentifiableEntity<String> {
public enum Group { public enum Group {
ANTHROPOMETRIC, ANTHROPOMETRIC,
CARDIOVASCULAR, CARDIOVASCULAR,
GLYCEMIC, GLYCEMIC,
...@@ -47,7 +49,13 @@ public class Phenotype implements IdentifiableEntity<String> { ...@@ -47,7 +49,13 @@ public class Phenotype implements IdentifiableEntity<String> {
HEPATIC HEPATIC
} }
@ApiModelProperty(position = 1) public enum Type {
DICHOTOMOUS,
MULTICHOTOMOUS,
CONTINUOUS
}
@ApiModelProperty(position = 1, required = true)
@JsonProperty @JsonProperty
@NotNull @NotNull
@Size(min = 1, max = 255) @Size(min = 1, max = 255)
...@@ -55,19 +63,52 @@ public class Phenotype implements IdentifiableEntity<String> { ...@@ -55,19 +63,52 @@ public class Phenotype implements IdentifiableEntity<String> {
@Column(nullable = false, unique = true, updatable = false) @Column(nullable = false, unique = true, updatable = false)
private String id; private String id;
@ApiModelProperty(position = 3) @ApiModelProperty(position = 2, required = true)
@JsonProperty @JsonProperty
@NotNull @NotNull
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
@Column(nullable = false) @Column(nullable = false)
private Group phenotypeGroup; private Group phenotypeGroup;
@ApiModelProperty(position = 3, required = true)
@NotNull
@NotBlank
@JsonProperty
@Column(nullable = false, columnDefinition = "TEXT")
private String description;
@ApiModelProperty(position = 4, required = true)
@JsonProperty
@NotNull
@Enumerated(EnumType.STRING)
@Column(nullable = false)
private Type type;
@ApiModelProperty(position = 5, required = true)
@JsonProperty
@NotNull
@Column(nullable = false)
private String allowedValues;
@CreatedDate @CreatedDate
@Column(updatable = false) @Column(updatable = false)
private ZonedDateTime createdDate; @Temporal(TemporalType.TIMESTAMP)
private Date createdDate;
@LastModifiedDate @LastModifiedDate
private ZonedDateTime lastModifiedDate; @Temporal(TemporalType.TIMESTAMP)
private Date lastModifiedDate;
public Phenotype() {
}
public Phenotype(String id, Group phenotypeGroup, String description, Type type, String allowedValues) {
this.id = id;
this.phenotypeGroup = phenotypeGroup;
this.description = description;
this.type = type;
this.allowedValues = allowedValues;
}
public String getId() { public String getId() {
return id; return id;
......
...@@ -30,9 +30,11 @@ import javax.persistence.EntityListeners; ...@@ -30,9 +30,11 @@ import javax.persistence.EntityListeners;
import javax.persistence.EnumType; import javax.persistence.EnumType;
import javax.persistence.Enumerated; import javax.persistence.Enumerated;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import java.time.ZonedDateTime; import java.util.Date;
@Entity @Entity
@EntityListeners({AuditingEntityListener.class, EntityEventListener.class}) @EntityListeners({AuditingEntityListener.class, EntityEventListener.class})
...@@ -97,10 +99,22 @@ public class Property implements IdentifiableEntity<String> { ...@@ -97,10 +99,22 @@ public class Property implements IdentifiableEntity<String> {
@CreatedDate @CreatedDate
@Column(updatable = false) @Column(updatable = false)
private ZonedDateTime createdDate; @Temporal(TemporalType.TIMESTAMP)
private Date createdDate;
@LastModifiedDate @LastModifiedDate
private ZonedDateTime lastModifiedDate; @Temporal(TemporalType.TIMESTAMP)
private Date lastModifiedDate;
public Property() {
}
public Property(String id, Type type, Meaning meaning, String description) {
this.id = id;
this.type = type;
this.meaning = meaning;
this.description = description;
}
public String getId() { public String getId() {
return id; return id;
......
CREATE TABLE IF NOT EXISTS phenotype ( CREATE TABLE IF NOT EXISTS phenotype (
id VARCHAR(255) NOT NULL, id VARCHAR(255) NOT NULL,
created_date BINARY(255), allowed_values VARCHAR(255) NOT NULL,
last_modified_date BINARY(255), created_date TIMESTAMP,
description TEXT NOT NULL,
last_modified_date TIMESTAMP,
phenotype_group VARCHAR(255) NOT NULL, phenotype_group VARCHAR(255) NOT NULL,
type VARCHAR(255) NOT NULL,
PRIMARY KEY (id) PRIMARY KEY (id)
); );
CREATE TABLE IF NOT EXISTS property ( CREATE TABLE IF NOT EXISTS property (
id VARCHAR(255) NOT NULL, id VARCHAR(255) NOT NULL,
created_date BINARY(255), created_date TIMESTAMP,
description TEXT NOT NULL, description TEXT NOT NULL,
last_modified_date BINARY(255), last_modified_date TIMESTAMP,
meaning VARCHAR(255) NOT NULL, meaning VARCHAR(255) NOT NULL,
type VARCHAR(255) NOT NULL, type VARCHAR(255) NOT NULL,
PRIMARY KEY (id) PRIMARY KEY (id)
......
...@@ -21,13 +21,17 @@ import org.junit.Before; ...@@ -21,13 +21,17 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.json.JacksonTester;
import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.MvcResult;
import uk.ac.ebi.ampt2d.registry.entities.Phenotype;
import uk.ac.ebi.ampt2d.registry.entities.Property;
import uk.ac.ebi.ampt2d.registry.repositories.PhenotypeRepository; import uk.ac.ebi.ampt2d.registry.repositories.PhenotypeRepository;
import uk.ac.ebi.ampt2d.registry.repositories.PropertyRepository; import uk.ac.ebi.ampt2d.registry.repositories.PropertyRepository;
import uk.ac.ebi.ampt2d.registry.service.mail.MailService; import uk.ac.ebi.ampt2d.registry.service.mail.MailService;
...@@ -46,6 +50,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. ...@@ -46,6 +50,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(properties = {"security.enabled=true", "spring.jpa.hibernate.ddl-auto=none"}) @SpringBootTest(properties = {"security.enabled=true", "spring.jpa.hibernate.ddl-auto=none"})
@AutoConfigureMockMvc @AutoConfigureMockMvc
@AutoConfigureJsonTesters
@DirtiesContext(classMode = AFTER_CLASS) @DirtiesContext(classMode = AFTER_CLASS)
public class PropertyRegistryServiceApplicationTests { public class PropertyRegistryServiceApplicationTests {
...@@ -61,6 +66,12 @@ public class PropertyRegistryServiceApplicationTests { ...@@ -61,6 +66,12 @@ public class PropertyRegistryServiceApplicationTests {
@Autowired @Autowired
private PropertyRepository propertyRepository; private PropertyRepository propertyRepository;
@Autowired
private JacksonTester<Phenotype> phenotypeJacksonTester;
@Autowired
private JacksonTester<Property> propertyJacksonTester;
@MockBean @MockBean
private MailService mailService; private MailService mailService;
...@@ -89,9 +100,9 @@ public class PropertyRegistryServiceApplicationTests { ...@@ -89,9 +100,9 @@ public class PropertyRegistryServiceApplicationTests {
} }
private String postTestPhenotype() throws Exception { private String postTestPhenotype() throws Exception {
String content = "{\"id\":\"BMI\"," + "\"phenotypeGroup\":\"ANTHROPOMETRIC\"}"; Phenotype phenotype = new Phenotype("BMI", Phenotype.Group.ANTHROPOMETRIC, "Body Mass Index",
Phenotype.Type.CONTINUOUS, "nn.nn");
return postTestEntity("/phenotypes", content); return postTestEntity("/phenotypes", phenotypeJacksonTester.write(phenotype).getJson());
} }
@Test @Test
...@@ -126,13 +137,14 @@ public class PropertyRegistryServiceApplicationTests { ...@@ -126,13 +137,14 @@ public class PropertyRegistryServiceApplicationTests {
public void shouldUpdatePhenotype() throws Exception { public void shouldUpdatePhenotype() throws Exception {
String location = postTestPhenotype(); String location = postTestPhenotype();
mockMvc.perform(put(location).with(oAuthHelper.bearerToken("testEditor@gmail.com")) mockMvc.perform(patch(location).with(oAuthHelper.bearerToken("testEditor@gmail.com"))
.content("{\"id\":\"BMI\"," + "\"phenotypeGroup\":\"RENAL\"}")) .content("{\"id\":\"BMI\"," + "\"phenotypeGroup\":\"RENAL\"," + "\"allowedValues\":\"nn.nnnn\"}"))
.andExpect(status().is2xxSuccessful()); .andExpect(status().is2xxSuccessful());
mockMvc.perform(get(location).with(oAuthHelper.bearerToken("testUser@gmail.com"))) mockMvc.perform(get(location).with(oAuthHelper.bearerToken("testUser@gmail.com")))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.phenotypeGroup").value("RENAL")); .andExpect(jsonPath("$.phenotypeGroup").value("RENAL"))
.andExpect(jsonPath("$.allowedValues").value("nn.nnnn"));
} }
@Test @Test
...@@ -160,12 +172,9 @@ public class PropertyRegistryServiceApplicationTests { ...@@ -160,12 +172,9 @@ public class PropertyRegistryServiceApplicationTests {
} }
private String postTestProperty() throws Exception { private String postTestProperty() throws Exception {
String content = "{\"id\":\"CALL_RATE\"," + Property property = new Property("CALL_RATE", Property.Type.FLOAT, Property.Meaning.CALL_RATE, "calling rate");
"\"type\":\"FLOAT\"," +
"\"meaning\":\"CALL_RATE\"," +
"\"description\":\"calling rate\"}";
return postTestEntity("/properties", content); return postTestEntity("/properties", propertyJacksonTester.write(property).getJson());
} }
@Test @Test
...@@ -201,21 +210,20 @@ public class PropertyRegistryServiceApplicationTests { ...@@ -201,21 +210,20 @@ public class PropertyRegistryServiceApplicationTests {
public void shouldUpdateProperty() throws Exception { public void shouldUpdateProperty() throws Exception {
String location = postTestProperty(); String location = postTestProperty();
mockMvc.perform(put(location).with(oAuthHelper.bearerToken("testEditor@gmail.com")).content( Property property = new Property("CALL_RATE", Property.Type.DOUBLE, Property.Meaning.CALL_RATE, "calling rate");
"{\"id\":\"CALL_RATE\"," +
"\"type\":\"DOUBLE\"," + mockMvc.perform(put(location).with(oAuthHelper.bearerToken("testEditor@gmail.com"))
"\"meaning\":\"CALL_RATE\"," + .content(propertyJacksonTester.write(property).getJson())).andExpect(status().isNoContent());
"\"description\":\"call rate\"}")).andExpect(
status().isNoContent());
mockMvc.perform(get(location).with(oAuthHelper.bearerToken("testUser@gmail.com"))) mockMvc.perform(get(location).with(oAuthHelper.bearerToken("testUser@gmail.com")))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.type").value("DOUBLE")) .andExpect(jsonPath("$.type").value("DOUBLE"))
.andExpect(jsonPath("$.meaning").value("CALL_RATE")) .andExpect(jsonPath("$.meaning").value("CALL_RATE"))
.andExpect(jsonPath("$.description").value("call rate")); .andExpect(jsonPath("$.description").value("calling rate"));
} }
@Test @Test
public void shouldPartiallyUpdateProperty() throws Exception { public void shouldPartiallyUpdateProperty() throws Exception {
String location = postTestProperty(); String location = postTestProperty();
...@@ -245,17 +253,12 @@ public class PropertyRegistryServiceApplicationTests { ...@@ -245,17 +253,12 @@ public class PropertyRegistryServiceApplicationTests {
@Test @Test
public void testPaging() throws Exception { public void testPaging() throws Exception {
String content1 = "{\"id\":\"CALL_RATE\"," + Property property1 = new Property("CALL_RATE", Property.Type.DOUBLE, Property.Meaning.CALL_RATE, "calling rate");
"\"type\":\"FLOAT\"," + Property property2 = new Property("MAF", Property.Type.FLOAT, Property.Meaning.MAF, "MAF");
"\"meaning\":\"CALL_RATE\"," +
"\"description\":\"calling rate\"}"; postTestEntity("/properties", propertyJacksonTester.write(property1).getJson());
postTestEntity("/properties", content1);
String content2 = "{\"id\":\"MAF\"," +
"\"type\":\"FLOAT\"," +
"\"meaning\":\"MAF\"," +
"\"description\":\"MAF\"}";
postTestEntity("/properties", content2); postTestEntity("/properties", propertyJacksonTester.write(property2).getJson());
mockMvc.perform(get("/properties?size=1").with(oAuthHelper.bearerToken("testUser@gmail.com"))) mockMvc.perform(get("/properties?size=1").with(oAuthHelper.bearerToken("testUser@gmail.com")))
.andExpect(status().isOk()) .andExpect(status().isOk())
...@@ -279,12 +282,14 @@ public class PropertyRegistryServiceApplicationTests { ...@@ -279,12 +282,14 @@ public class PropertyRegistryServiceApplicationTests {
mockMvc.perform(get("/swagger-resources/")).andExpect(status().isOk()); mockMvc.perform(get("/swagger-resources/")).andExpect(status().isOk());
mockMvc.perform(get("/webjars/springfox-swagger-ui/fonts/open-sans-v15-latin-regular.woff2")).andExpect(status().isOk()); mockMvc.perform(get("/webjars/springfox-swagger-ui/fonts/open-sans-v15-latin-regular.woff2")).andExpect(status().isOk());
String propertyContent = "{\"id\":\"CALL_RATE\"," + Property property = new Property("CALL_RATE", Property.Type.DOUBLE, Property.Meaning.CALL_RATE, "calling rate");
"\"type\":\"FLOAT\"," + Phenotype phenotype1 = new Phenotype("BMI", Phenotype.Group.ANTHROPOMETRIC, "Body Mass Index",
"\"meaning\":\"CALL_RATE\"," + Phenotype.Type.CONTINUOUS, "nn.nn");
"\"description\":\"calling rate\"}"; Phenotype phenotype2 = new Phenotype("BMI", Phenotype.Group.RENAL, "Body Mass Index",
Phenotype.Type.CONTINUOUS, "nn.nn");
String phenotypeContent = "{\"id\":\"BMI\"," + "\"phenotypeGroup\":\"ANTHROPOMETRIC\"}"; String propertyContent = propertyJacksonTester.write(property).getJson();
String phenotypeContent = phenotypeJacksonTester.write(phenotype1).getJson();
//POST can be performed by EDITOR or ADMIN only //POST can be performed by EDITOR or ADMIN only
mockMvc.perform(post("/properties").with(oAuthHelper.bearerToken("testUser@gmail.com")) mockMvc.perform(post("/properties").with(oAuthHelper.bearerToken("testUser@gmail.com"))
...@@ -311,7 +316,7 @@ public class PropertyRegistryServiceApplicationTests { ...@@ -311,7 +316,7 @@ public class PropertyRegistryServiceApplicationTests {
mockMvc.perform(patch("/phenotypes/BMI").with(oAuthHelper.bearerToken("testEditor@gmail.com")) mockMvc.perform(patch("/phenotypes/BMI").with(oAuthHelper.bearerToken("testEditor@gmail.com"))
.content("{\"phenotypeGroup\": \"GLYCEMIC\"}")).andExpect(status().isNoContent()); .content("{\"phenotypeGroup\": \"GLYCEMIC\"}")).andExpect(status().isNoContent());
mockMvc.perform(put("/phenotypes/BMI").with(oAuthHelper.bearerToken("testAdmin@gmail.com")) mockMvc.perform(put("/phenotypes/BMI").with(oAuthHelper.bearerToken("testAdmin@gmail.com"))
.content("{\"phenotypeGroup\": \"GLYCEMIC\"}")).andExpect(status().isNoContent()); .content(phenotypeJacksonTester.write(phenotype2).getJson())).andExpect(status().isNoContent());
mockMvc.perform(delete("/properties/CALL_RATE").with(oAuthHelper.bearerToken("testUser@gmail.com"))) mockMvc.perform(delete("/properties/CALL_RATE").with(oAuthHelper.bearerToken("testUser@gmail.com")))
.andExpect(status().isForbidden()); .andExpect(status().isForbidden());
mockMvc.perform(delete("/properties/CALL_RATE").with(oAuthHelper.bearerToken("testEditor@gmail.com"))) mockMvc.perform(delete("/properties/CALL_RATE").with(oAuthHelper.bearerToken("testEditor@gmail.com")))
...@@ -329,4 +334,4 @@ public class PropertyRegistryServiceApplicationTests { ...@@ -329,4 +334,4 @@ public class PropertyRegistryServiceApplicationTests {
.content(propertyContent)).andExpect(status().isCreated()); .content(propertyContent)).andExpect(status().isCreated());
} }
} }
\ No newline at end of file
...@@ -20,11 +20,14 @@ package uk.ac.ebi.ampt2d.registry; ...@@ -20,11 +20,14 @@ package uk.ac.ebi.ampt2d.registry;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.json.JacksonTester;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import uk.ac.ebi.ampt2d.registry.entities.Phenotype;
import static org.springframework.test.annotation.DirtiesContext.ClassMode.BEFORE_CLASS; import static org.springframework.test.annotation.DirtiesContext.ClassMode.BEFORE_CLASS;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
...@@ -34,16 +37,20 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. ...@@ -34,16 +37,20 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(properties = {"mail.notify=true", "spring.mail.host=invalid_host"}) @SpringBootTest(properties = {"mail.notify=true", "spring.mail.host=invalid_host"})
@AutoConfigureMockMvc @AutoConfigureMockMvc
@AutoConfigureJsonTesters
@DirtiesContext(classMode = BEFORE_CLASS) @DirtiesContext(classMode = BEFORE_CLASS)
public class RegistryUpdateNotificationFailure { public class RegistryUpdateNotificationFailure {
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Autowired
private JacksonTester<Phenotype> phenotypeJacksonTester;
@Test @Test
public void testPhenotypeEvent() throws Exception { public void testPhenotypeEvent() throws Exception {
String phenotypeContent = "{\"id\":\"BMI\"," + "\"phenotypeGroup\":\"ANTHROPOMETRIC\"}"; Phenotype phenotype = new Phenotype("BMI", Phenotype.Group.ANTHROPOMETRIC, "Body Mass Index", Phenotype.Type.CONTINUOUS, "nn.nn");
mockMvc.perform(post("/phenotypes").content(phenotypeContent)) mockMvc.perform(post("/phenotypes").content(phenotypeJacksonTester.write(phenotype).getJson()))
.andExpect(status().isInternalServerError()) .andExpect(status().isInternalServerError())
.andExpect(content().string("An automated email could not be sent, please contact user@domain")); .andExpect(content().string("An automated email could not be sent, please contact user@domain"));
} }
......
...@@ -21,12 +21,16 @@ import org.junit.Before; ...@@ -21,12 +21,16 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.json.JacksonTester;
import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import uk.ac.ebi.ampt2d.registry.entities.Phenotype;
import uk.ac.ebi.ampt2d.registry.entities.Property;
import uk.ac.ebi.ampt2d.registry.service.mail.MailService; import uk.ac.ebi.ampt2d.registry.service.mail.MailService;
import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyString;
...@@ -43,6 +47,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. ...@@ -43,6 +47,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@SpringBootTest @SpringBootTest
@AutoConfigureMockMvc @AutoConfigureMockMvc
@DirtiesContext(classMode = BEFORE_CLASS) @DirtiesContext(classMode = BEFORE_CLASS)
@AutoConfigureJsonTesters
public class RegistryUpdateNotificationTest { public class RegistryUpdateNotificationTest {
@Autowired @Autowired
...@@ -51,6 +56,12 @@ public class RegistryUpdateNotificationTest { ...@@ -51,6 +56,12 @@ public class RegistryUpdateNotificationTest {
@MockBean @MockBean
private MailService mailService; private MailService mailService;
@Autowired
private JacksonTester<Phenotype> phenotypeJacksonTester;
@Autowired
private JacksonTester<Property> propertyJacksonTester;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
doNothing().when(mailService).send(anyString()); doNothing().when(mailService).send(anyString());
...@@ -58,8 +69,8 @@ public class RegistryUpdateNotificationTest { ...@@ -58,8 +69,8 @@ public class RegistryUpdateNotificationTest {
@Test @Test
public void testPhenotypeEvent() throws Exception { public void testPhenotypeEvent() throws Exception {
String phenotypeContent = "{\"id\":\"BMI\"," + "\"phenotypeGroup\":\"ANTHROPOMETRIC\"}"; Phenotype phenotype = new Phenotype("BMI", Phenotype.Group.ANTHROPOMETRIC, "Body Mass Index", Phenotype.Type.CONTINUOUS, "nn.nn");
mockMvc.perform(post("/phenotypes").content(phenotypeContent)) mockMvc.perform(post("/phenotypes").content(phenotypeJacksonTester.write(phenotype).getJson()))
.andExpect(status().isCreated()); .andExpect(status().isCreated