Commit 7a06c927 authored by Matija Obreza's avatar Matija Obreza

JUnit tests updated

parent 47b67808
......@@ -477,12 +477,6 @@
<artifactId>freemarker</artifactId>
<version>2.3.23</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>2.0.2-beta</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
......@@ -538,18 +532,24 @@
</dependency>
<!--Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.19.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
......
......@@ -97,7 +97,7 @@ public class AccessionHistoryTest extends GenesysServicesTest {
assertThat("INSTCODE must match", accession.getInstituteCode(), is(INSTCODE));
assertThat("Institute#code must match", accession.getInstitute().getCode(), is(INSTCODE));
assertThat("ACCENUMB must match", accession.getAccessionNumber(), is(ACCENUMB));
assertThat("stoRage must match", accession.getAccessionId().getStorage(), contains(10, 20));
assertThat("storage must match", accession.getAccessionId().getStorage(), contains(10, 20));
UUID uuid = accession.getUuid();
// Delete accession
......
......@@ -56,7 +56,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.restdocs.RestDocumentation;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;
......@@ -85,7 +85,7 @@ public class SubsetRestControllerTest extends AbstractRestTest {
private static final String RIGHTS = "Test rights";
@Rule
public final RestDocumentation restDocumentation = new RestDocumentation("target/generated-snippets");
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("target/generated-snippets");
@Autowired
private WebApplicationContext webApplicationContext;
......
......@@ -33,7 +33,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.restdocs.RestDocumentation;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
......@@ -52,7 +52,7 @@ public class CropsControllerTest extends AbstractRestTest {
private static final Logger LOG = LoggerFactory.getLogger(CropsControllerTest.class);
@Rule
public final RestDocumentation restDocumentation = new RestDocumentation("target/generated-snippets");
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("target/generated-snippets");
@Autowired
WebApplicationContext webApplicationContext;
......@@ -144,6 +144,7 @@ public class CropsControllerTest extends AbstractRestTest {
fieldWithPath("otherNames").type(JsonFieldType.ARRAY).optional().description("Alternative spellings of the crop name"),
fieldWithPath("active").ignored(),
fieldWithPath("_class").ignored(),
fieldWithPath("_permissions.*").ignored(),
fieldWithPath("createdBy").ignored(),
fieldWithPath("createdDate").ignored(),
fieldWithPath("lastModifiedBy").ignored(),
......@@ -180,6 +181,7 @@ public class CropsControllerTest extends AbstractRestTest {
fieldWithPath("otherNames").type(JsonFieldType.ARRAY).optional().description("Alternative spellings of the crop name"),
fieldWithPath("active").ignored(),
fieldWithPath("_class").ignored(),
fieldWithPath("_permissions.*").ignored(),
fieldWithPath("createdBy").ignored(),
fieldWithPath("createdDate").ignored(),
fieldWithPath("lastModifiedBy").ignored(),
......
......@@ -45,7 +45,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.restdocs.RestDocumentation;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
......@@ -57,7 +57,7 @@ public class ApiCropsTest extends AbstractRestTest {
private static final Logger LOG = LoggerFactory.getLogger(ApiCropsTest.class);
@Rule
public final RestDocumentation restDocumentation = new RestDocumentation("target/generated-snippets");
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("target/generated-snippets");
@Autowired
WebApplicationContext webApplicationContext;
......@@ -124,7 +124,8 @@ public class ApiCropsTest extends AbstractRestTest {
.andDo(document("crop-create",
requestFields(fieldWithPath("shortName").description("Crop short name or code (e.g. maize)"), fieldWithPath("name").description("Crop name in English"),
fieldWithPath("otherNames").type(JsonFieldType.ARRAY).optional().description("Alternative spellings of the crop name"),
fieldWithPath("description").optional().description("Crop description in English")),
fieldWithPath("description").optional().description("Crop description in English")
),
responseFields(fieldWithPath("id").description("Autogenerated ID"), fieldWithPath("version").description("Record version"),
fieldWithPath("name").description("Crop name in English"), fieldWithPath("shortName").description("Crop short name or code (e.g. maize)"),
fieldWithPath("description").description("Crop description in English"),
......@@ -134,7 +135,7 @@ public class ApiCropsTest extends AbstractRestTest {
fieldWithPath("createdBy").ignored(),
fieldWithPath("active").type(JsonFieldType.BOOLEAN).description("Record is active"),
fieldWithPath("_class").ignored(),
fieldWithPath("_permissions").ignored(),
fieldWithPath("_permissions.*").ignored(),
fieldWithPath("createdDate").ignored(),
fieldWithPath("lastModifiedBy").ignored(),
fieldWithPath("lastModifiedDate").ignored())));
......@@ -159,7 +160,7 @@ public class ApiCropsTest extends AbstractRestTest {
fieldWithPath("rdfUri").type(JsonFieldType.STRING).optional().description("URI of RDF term describing the crop"),
fieldWithPath("i18n").type(JsonFieldType.STRING).optional().description("i18n map"), fieldWithPath("createdBy").ignored(),
fieldWithPath("_class").ignored(),
fieldWithPath("_permissions").ignored(),
fieldWithPath("_permissions.*").ignored(),
fieldWithPath("createdDate").ignored(),
fieldWithPath("lastModifiedBy").ignored(),
fieldWithPath("lastModifiedDate").ignored())));
......@@ -182,23 +183,7 @@ public class ApiCropsTest extends AbstractRestTest {
.andExpect(jsonPath("$.active", is(true)))
.andExpect(jsonPath("$.name", is("Rice")))
.andExpect(jsonPath("$.description", is("Crop description in EN")))
.andDo(document("crop-delete",
pathParameters(parameterWithName("shortName").description("Crop short name or code (e.g. maize)")),
responseFields(
fieldWithPath("id").description("Autogenerated ID"),
fieldWithPath("version").description("Record version"),
fieldWithPath("name").description("Crop name in English"),
fieldWithPath("shortName").description("Crop short name or code (e.g. maize)"),
fieldWithPath("description").description("Crop description in English"),
fieldWithPath("active").optional().description("Record is active"),
fieldWithPath("otherNames").type(JsonFieldType.ARRAY).optional().description("Alternative spellings of the crop name"),
fieldWithPath("rdfUri").type(JsonFieldType.STRING).optional().description("URI of RDF term describing the crop"),
fieldWithPath("i18n").type(JsonFieldType.STRING).optional().description("i18n map"), fieldWithPath("createdBy").ignored(),
fieldWithPath("_class").ignored(),
fieldWithPath("_permissions").ignored(),
fieldWithPath("createdDate").ignored(),
fieldWithPath("lastModifiedBy").ignored(),
fieldWithPath("lastModifiedDate").ignored())));
.andDo(document("crop-delete", pathParameters(parameterWithName("shortName").description("Crop short name or code (e.g. maize)"))));
LOG.info("Test deleteCropTest passed");
}
......
......@@ -62,7 +62,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.restdocs.RestDocumentation;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;
......@@ -78,7 +78,7 @@ public class ApiImagesDocsTest extends AbstractRestTest {
private static final Logger LOG = LoggerFactory.getLogger(ApiImagesDocsTest.class);
@Rule
public final RestDocumentation restDocumentation = new RestDocumentation("target/generated-snippets");
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("target/generated-snippets");
@Autowired
WebApplicationContext webApplicationContext;
......@@ -178,7 +178,9 @@ public class ApiImagesDocsTest extends AbstractRestTest {
fieldWithPath("width").description("Image width in pixels (autodetected)"), fieldWithPath("height").description("Image height in pixels (autodetected)"),
fieldWithPath("orientation").description("LANDSCAPE or PORTRAIT orientation of the image (autodetected)"),
// Ignored stuff
fieldWithPath("_class").ignored(), fieldWithPath("id").ignored(), fieldWithPath("title").ignored(), fieldWithPath("subject").ignored(), fieldWithPath("description").ignored(),
fieldWithPath("_class").ignored(),
fieldWithPath("_permissions.*").ignored(),
fieldWithPath("id").ignored(), fieldWithPath("title").ignored(), fieldWithPath("subject").ignored(), fieldWithPath("description").ignored(),
fieldWithPath("creator").ignored(), fieldWithPath("created").ignored(), fieldWithPath("rightsHolder").ignored(), fieldWithPath("accessRights").ignored(),
fieldWithPath("license").ignored(), fieldWithPath("extent").ignored(), fieldWithPath("bibliographicCitation").ignored(), fieldWithPath("createdDate").ignored(),
fieldWithPath("lastModifiedDate").ignored(), fieldWithPath("lastModifiedBy").ignored(), fieldWithPath("originalUrl").ignored(), fieldWithPath("dateRetrieved").ignored(), fieldWithPath("dateSubmitted").ignored(),
......@@ -220,7 +222,13 @@ public class ApiImagesDocsTest extends AbstractRestTest {
fieldWithPath("extent").description("Size (e.g. bytes, pages, inches, etc.) or duration (e.g. hours, minutes, days, etc.) of a resource"),
fieldWithPath("bibliographicCitation").description("Formal bibliographic citation for the resource"),
// ignored
fieldWithPath("active").ignored(), fieldWithPath("_class").ignored(), fieldWithPath("id").ignored(), fieldWithPath("thumbnailPath").ignored(), fieldWithPath("url").ignored(), fieldWithPath("storageFullPath").ignored()),
fieldWithPath("active").ignored(),
fieldWithPath("size").ignored(),
fieldWithPath("width").ignored(),
fieldWithPath("height").ignored(),
fieldWithPath("_class").ignored(),
fieldWithPath("_permissions.*").ignored(),
fieldWithPath("id").ignored(), fieldWithPath("thumbnailPath").ignored(), fieldWithPath("url").ignored(), fieldWithPath("storageFullPath").ignored()),
responseFields(fieldWithPath("uuid").ignored(), fieldWithPath("originalFilename").description("The original filename that you have provided"),
fieldWithPath("extension").ignored(), fieldWithPath("contentType").ignored(), fieldWithPath("path").ignored(),
fieldWithPath("filename").ignored(),
......@@ -243,8 +251,12 @@ public class ApiImagesDocsTest extends AbstractRestTest {
fieldWithPath("extent").description("Size (e.g. bytes, pages, inches, etc.) or duration (e.g. hours, minutes, days, etc.) of a resource"),
fieldWithPath("bibliographicCitation").description("Formal bibliographic citation for the resource"),
fieldWithPath("size").description("Image size in bytes"),
fieldWithPath("width").description("Image width in pixels"),
fieldWithPath("height").description("Image height in pixels"),
// ignored
fieldWithPath("_class").ignored(), fieldWithPath("id").ignored(), fieldWithPath("version").ignored(),
fieldWithPath("_class").ignored(),
fieldWithPath("_permissions.*").ignored(),
fieldWithPath("id").ignored(), fieldWithPath("version").ignored(),
fieldWithPath("createdDate").ignored(), fieldWithPath("createdBy").ignored(), fieldWithPath("lastModifiedDate").ignored(), fieldWithPath("lastModifiedBy").ignored(), fieldWithPath("originalUrl").ignored(), fieldWithPath("dateRetrieved").ignored(),
fieldWithPath("dateSubmitted").ignored(), fieldWithPath("modified").ignored(), fieldWithPath("active").ignored(), fieldWithPath("thumbnailPath").ignored(), fieldWithPath("url").ignored(), fieldWithPath("storageFullPath").ignored(), fieldWithPath("storagePath").ignored())));
......@@ -269,7 +281,9 @@ public class ApiImagesDocsTest extends AbstractRestTest {
fieldWithPath("orientation").description("LANDSCAPE or PORTRAIT orientation of the image (autodetected)"),
fieldWithPath("size").description("Image size in bytes"),
// Ignored stuff
fieldWithPath("_class").ignored(), fieldWithPath("id").ignored(), fieldWithPath("version").ignored(), fieldWithPath("title").ignored(), fieldWithPath("subject").ignored(), fieldWithPath("description").ignored(),
fieldWithPath("_class").ignored(),
fieldWithPath("_permissions.*").ignored(),
fieldWithPath("id").ignored(), fieldWithPath("version").ignored(), fieldWithPath("title").ignored(), fieldWithPath("subject").ignored(), fieldWithPath("description").ignored(),
fieldWithPath("creator").ignored(), fieldWithPath("created").ignored(), fieldWithPath("rightsHolder").ignored(), fieldWithPath("accessRights").ignored(),
fieldWithPath("license").ignored(), fieldWithPath("extent").ignored(), fieldWithPath("bibliographicCitation").ignored(), fieldWithPath("createdDate").ignored(), fieldWithPath("createdBy").ignored(),
fieldWithPath("lastModifiedDate").ignored(), fieldWithPath("lastModifiedBy").ignored(), fieldWithPath("originalUrl").ignored(), fieldWithPath("dateRetrieved").ignored(), fieldWithPath("dateSubmitted").ignored(),
......
......@@ -28,7 +28,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.restdocs.RestDocumentation;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;
......@@ -42,7 +42,7 @@ public class ApiRequestsDocsTest extends AbstractRestTest {
private static final Logger LOG = LoggerFactory.getLogger(ApiRequestsDocsTest.class);
@Rule
public final RestDocumentation restDocumentation = new RestDocumentation("target/generated-snippets");
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("target/generated-snippets");
@Autowired
WebApplicationContext webApplicationContext;
......@@ -104,10 +104,20 @@ public class ApiRequestsDocsTest extends AbstractRestTest {
.andDo(document("requests-inst-list", pathParameters(parameterWithName("instCode").description("Institute WIEWS code (e.g. NGA039)")),
requestParameters(parameterWithName("page").description("Page to request from the server")),
responseFields(fieldWithPath("content").description("Array containing request headers"),
fieldWithPath("content[0].uuid").description("Request UUID"),
fieldWithPath("content[0].version").ignored(),
fieldWithPath("content[0].instCode").description("WIEWS institute code"),
fieldWithPath("content[0].instEmail").description("Institute email address to which request was relayed"),
fieldWithPath("content[0].state").description("Request state"),
fieldWithPath("content[0].createdDate").description("Date when request was created"),
fieldWithPath("content[0].lastModifiedDate").ignored(),
fieldWithPath("content[0].lastReminderDate").description("Date when request was last relayed to specified email address"),
fieldWithPath("numberOfElements").description("Number of records in the content array"),
fieldWithPath("totalElements").description("Total number of requests in Genesys belonging to this institute"),
fieldWithPath("size").description("Page size"), fieldWithPath("number").description("Current page number"),
fieldWithPath("totalPages").description("Page count"), fieldWithPath("sort").description("Arrray sorting details"),
fieldWithPath("totalPages").description("Page count"),
fieldWithPath("sort").description("Arrray sorting details"),
fieldWithPath("sort[0].*").ignored(),
fieldWithPath("first").ignored(), fieldWithPath("last").ignored())));
}
......
......@@ -43,7 +43,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.restdocs.RestDocumentation;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
......@@ -53,7 +53,7 @@ public class BrAPITest extends AbstractRestTest {
private static final Logger LOG = LoggerFactory.getLogger(BrAPITest.class);
@Rule
public final RestDocumentation restDocumentation = new RestDocumentation("target/generated-snippets");
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("target/generated-snippets");
@Autowired
WebApplicationContext webApplicationContext;
......@@ -113,7 +113,11 @@ public class BrAPITest extends AbstractRestTest {
requestParameters(parameterWithName("pageSize").description("Requested page size. Default is 50 records per page."),
parameterWithName("page").description("The page to retrieve (0-based)")),
// request fields
responseFields(fieldWithPath("metadata").description("BrAPI v1 reponse metadata"), fieldWithPath("result").description("List of Genesys crop names"))));
responseFields(fieldWithPath("metadata").description("BrAPI v1 reponse metadata"),
fieldWithPath("metadata.status").description("If no status is reported, an empty list is returned"),
fieldWithPath("metadata.datafiles").description("Datafiles key contains a list of strings"),
fieldWithPath("metadata.pagination.*").ignored(),
fieldWithPath("result").description("List of Genesys crop names"))));
LOG.info("Test listCropsTest passed");
}
......@@ -143,7 +147,11 @@ public class BrAPITest extends AbstractRestTest {
parameterWithName("germplasmPUI").description("Return accessions where PUID matches provided value"),
parameterWithName("germplasmDbId").description("Return accessions where UUID matches provided value")),
// response fields
responseFields(fieldWithPath("metadata").description("BrAPI v1 reponse metadata"), fieldWithPath("result").description("List of BrAPI Germplasm records"))));
responseFields(fieldWithPath("metadata").description("BrAPI v1 reponse metadata"),
fieldWithPath("metadata.status").description("If no status is reported, an empty list is returned"),
fieldWithPath("metadata.datafiles").description("Datafiles key contains a list of strings"),
fieldWithPath("metadata.pagination.*").ignored(),
fieldWithPath("result").description("List of BrAPI Germplasm records"))));
}
......@@ -168,7 +176,13 @@ public class BrAPITest extends AbstractRestTest {
// path parameters
pathParameters(parameterWithName("germplasmID").description("UUID of accession record in Genesys")),
// response fields
responseFields(fieldWithPath("metadata").description("BrAPI v1 reponse metadata"), fieldWithPath("result").description("Single BrAPI Germplasm record"))));
responseFields(fieldWithPath("metadata").description("BrAPI v1 reponse metadata"),
fieldWithPath("metadata.status").description("If no status is reported, an empty list is returned"),
fieldWithPath("metadata.status[0].code").description("Error code"),
fieldWithPath("metadata.status[0].message").description("Error message"),
fieldWithPath("metadata.datafiles").description("Datafiles key contains a list of strings"),
fieldWithPath("metadata.pagination.*").ignored(),
fieldWithPath("result").description("Single BrAPI Germplasm record"))));
}
......
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