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