Commit 8b8d5d50 authored by Matija Obreza's avatar Matija Obreza

Merge branch '28-accession-details-as-json' into 'master'

Resolve "Accession details as JSON"

Closes #28

See merge request !8
parents bd39b807 8c9455f9
......@@ -71,7 +71,7 @@
<servlet-api.version>2.5</servlet-api.version>
<jsp-api.version>2.1</jsp-api.version>
<spring.framework.version>4.2.5.RELEASE</spring.framework.version>
<spring.framework.version>4.3.8.RELEASE</spring.framework.version>
<spring.data.release-train>Hopper-SR1</spring.data.release-train>
<spring.security.version>4.0.4.RELEASE</spring.security.version>
<spring.security.oauth2.version>1.0.5.RELEASE</spring.security.oauth2.version>
......@@ -88,10 +88,10 @@
<aspectj.version>1.7.2</aspectj.version>
<mysql.version>5.1.31</mysql.version>
<hazelcast.version>3.6.6</hazelcast.version>
<hazelcast.version>3.8.1</hazelcast.version>
<oval.version>1.81</oval.version>
<jackson.version>2.2.1</jackson.version>
<jackson.version>2.6.4</jackson.version>
<jaxb-api.version>2.2.12</jaxb-api.version>
<!--Container -->
......@@ -373,11 +373,6 @@
<artifactId>hazelcast-spring</artifactId>
<version>${hazelcast.version}</version>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-cloud</artifactId>
<version>${hazelcast.version}</version>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-hibernate4</artifactId>
......
......@@ -23,6 +23,7 @@ import java.util.UUID;
import org.genesys2.server.filerepository.model.ImageGallery;
import org.genesys2.server.filerepository.service.ImageGalleryService;
import org.genesys2.server.model.dataset.DS;
import org.genesys2.server.model.elastic.AccessionDetails;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.genesys.PDCI;
......@@ -41,11 +42,13 @@ import org.genesys2.server.service.impl.NonUniqueAccessionException;
import org.genesys2.server.service.impl.PDCICalculator;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/acn")
......@@ -73,15 +76,23 @@ public class AccessionController extends BaseController {
@Autowired
private StatisticsService statisticsService;
@Autowired
private InstituteFilesService instituteFilesService;
@Autowired
private ImageGalleryService imageGalleryService;
@RequestMapping("/id/{accessionId}")
@RequestMapping(value = "/id/{accessionId}", produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody AccessionDetails viewJson(ModelMap model, @PathVariable(value = "accessionId") long accessionId) {
AccessionDetails ad = genesysService.getAccessionDetails(accessionId);
if (ad == null) {
throw new ResourceNotFoundException();
}
return ad;
}
@RequestMapping(value = "/id/{accessionId}")
public String view(ModelMap model, @PathVariable(value = "accessionId") long accessionId) {
_logger.debug("Viewing ACN " + accessionId);
final Accession accession = genesysService.getAccession(accessionId);
......
......@@ -192,7 +192,7 @@ public class CropsController extends RestController {
* @throws AuthorizationException
*/
@RequestMapping(value = "/rebuild", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody String rebuild() {
public @ResponseBody ApiResult rebuild() {
cropService.rebuildTaxonomies();
return JSON_OK;
}
......@@ -204,7 +204,7 @@ public class CropsController extends RestController {
* @throws AuthorizationException
*/
@RequestMapping(value = "{shortName}/rebuild", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody String rebuildCrop(@PathVariable("shortName") String shortName) {
public @ResponseBody ApiResult rebuildCrop(@PathVariable("shortName") String shortName) {
LOG.info("Updating crop rules for " + shortName);
final Crop crop = cropService.getCrop(shortName);
if (crop == null)
......
......@@ -71,7 +71,7 @@ public class OAuthManagementController extends RequestsController {
@RequestMapping("/token/at/{tokenId}/remove")
@PreAuthorize("hasRole('ADMINISTRATOR')")
@ResponseBody
public String removeAccessToken(@PathVariable("tokenId") long tokenId) {
public ApiResult removeAccessToken(@PathVariable("tokenId") long tokenId) {
tokenStore.removeAccessToken(tokenId);
return JSON_OK;
}
......@@ -79,7 +79,7 @@ public class OAuthManagementController extends RequestsController {
@PreAuthorize("hasRole('ADMINISTRATOR')")
@RequestMapping("/token/rt/{tokenId}/remove")
@ResponseBody
public String removeRefreshToken(@PathVariable("tokenId") long tokenId) {
public ApiResult removeRefreshToken(@PathVariable("tokenId") long tokenId) {
tokenStore.removeRefreshToken(tokenId);
return JSON_OK;
......@@ -88,7 +88,7 @@ public class OAuthManagementController extends RequestsController {
@PreAuthorize("hasRole('ADMINISTRATOR')")
@RequestMapping("/token/{clientId:.+}/remove-all-at")
@ResponseBody
public String removeAllAccessTokens(@PathVariable("clientId") String clientId) {
public ApiResult removeAllAccessTokens(@PathVariable("clientId") String clientId) {
final Collection<OAuth2AccessToken> tokens = tokenStore.findTokensByClientId(clientId);
for (final OAuth2AccessToken token : tokens) {
......@@ -101,7 +101,7 @@ public class OAuthManagementController extends RequestsController {
@PreAuthorize("hasRole('ADMINISTRATOR')")
@RequestMapping("/token/{clientId:.+}/remove-all-rt")
@ResponseBody
public String removeAllRefreshTokens(@PathVariable("clientId") String clientId) {
public ApiResult removeAllRefreshTokens(@PathVariable("clientId") String clientId) {
final Collection<OAuthRefreshToken> tokens = tokenStore.findRefreshTokensByClientId(clientId);
for (final OAuthRefreshToken token : tokens) {
......@@ -144,7 +144,7 @@ public class OAuthManagementController extends RequestsController {
@PreAuthorize("hasAnyRole('VETTEDUSER','ADMINISTRATOR')")
@RequestMapping(value = "/delete-client", method = RequestMethod.POST)
@ResponseBody
public String deleteClient(@RequestBody OAuthClientDetails requestClient) {
public ApiResult deleteClient(@RequestBody OAuthClientDetails requestClient) {
final OAuthClientDetails clientDetails = clientDetailsService.getClientDetails(requestClient.getId());
LOG.info("Deleting client " + clientDetails.getClientId());
clientDetailsService.removeClient(clientDetails);
......
......@@ -35,8 +35,16 @@ import org.springframework.web.bind.annotation.ResponseBody;
public abstract class RestController {
protected final Log LOG = LogFactory.getLog(getClass());
protected static final String JSON_OK = "{\"result\":true}";
protected static final ApiResult JSON_OK = new ApiResult(true);
public static class ApiResult {
public boolean result = false;
public ApiResult(boolean b) {
result=b;
}
}
public RestController() {
super();
}
......
......@@ -110,7 +110,7 @@ public class UsersController extends RestController {
@RequestMapping(value = "/user/data", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE})
@ResponseBody
public String updateData(@RequestBody UserChangedDataJson userData) throws PasswordPolicyException, UserException {
public ApiResult updateData(@RequestBody UserChangedDataJson userData) throws PasswordPolicyException, UserException {
final User user = userService.getUserByUuid(userData.getUuid());
if (user == null) {
......@@ -150,7 +150,7 @@ public class UsersController extends RestController {
@RequestMapping(value = "/user/roles", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE})
@ResponseBody
public String updateRoles(@RequestBody UserChangedDataJson userData) {
public ApiResult updateRoles(@RequestBody UserChangedDataJson userData) {
final User user = userService.getUserByUuid(userData.getUuid());
if (user == null) {
throw new ResourceNotFoundException();
......@@ -162,7 +162,7 @@ public class UsersController extends RestController {
@RequestMapping(value = "user/{uuid:.+}/send", method = RequestMethod.GET)
@ResponseBody
public String sendEmail(@PathVariable("uuid") String uuid) {
public ApiResult sendEmail(@PathVariable("uuid") String uuid) {
final User user = userService.getUserByUuid(uuid);
emailVerificationService.sendVerificationEmail(user);
......@@ -172,7 +172,7 @@ public class UsersController extends RestController {
@RequestMapping("user/{uuid:.+}/vetted-user")
@ResponseBody
public String addRoleVettedUser(@PathVariable("uuid") String uuid) {
public ApiResult addRoleVettedUser(@PathVariable("uuid") String uuid) {
userService.addVettedUserRole(uuid);
return JSON_OK;
}
......
......@@ -40,7 +40,7 @@ import org.springframework.context.annotation.Import;
@Configuration
@EnableCaching
@Import({ HazelcastConfigAWS.class, HazelcastConfigCacher.class })
@Import({ HazelcastConfigCacher.class })
public abstract class HazelcastConfig {
protected final Logger LOG = LoggerFactory.getLogger(HazelcastConfig.class);
......
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.spring.config;
import com.hazelcast.config.AwsConfig;
import com.hazelcast.config.Config;
import com.hazelcast.config.GroupConfig;
import com.hazelcast.config.JoinConfig;
import com.hazelcast.config.NetworkConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.ManagedContext;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
@Configuration
@Profile("aws")
public class HazelcastConfigAWS extends HazelcastConfig {
@Value("${hazelcast.aws.region}")
private String region;
@Value("${hazelcast.aws.access-key}")
private String accessKey;
@Value("${hazelcast.aws.secret-key}")
private String secretKey;
@Value("${hazelcast.aws.security-group}")
private String securityGroupName;
@Bean
public HazelcastInstance hazelcast(ManagedContext managedContext) {
Config cfg = new Config();
cfg.setManagedContext(managedContext);
cfg.setInstanceName(instanceName);
GroupConfig groupConfig = cfg.getGroupConfig();
groupConfig.setName(name);
groupConfig.setPassword(password);
cfg.setProperty("hazelcast.merge.first.run.delay.seconds", "5");
cfg.setProperty("hazelcast.merge.next.run.delay.seconds", "5");
cfg.setProperty("hazelcast.logging.type", "log4j");
cfg.setProperty("hazelcast.icmp.enabled", "true");
NetworkConfig network = cfg.getNetworkConfig();
network.setPort(hazelPort);
network.setPortAutoIncrement(false);
if (StringUtils.isNotBlank(hazelPublicAddress)) {
System.out.println("Hazelcast: Using public address " + hazelPublicAddress);
network.setPublicAddress(hazelPublicAddress);
}
if (StringUtils.isNotBlank(hazelInterfaces)) {
for (String hazelInterface : hazelInterfaces.split(",")) {
System.out.println("Hazelcast: Adding single interface " + hazelInterface);
network.getInterfaces().addInterface(hazelInterface);
}
}
JoinConfig join = network.getJoin();
join.getMulticastConfig().setEnabled(false);
AwsConfig awsConfig = join.getAwsConfig();
awsConfig.setEnabled(true);
awsConfig.setRegion(region);
awsConfig.setAccessKey(accessKey);
awsConfig.setSecretKey(secretKey);
awsConfig.setConnectionTimeoutSeconds(20);
awsConfig.setSecurityGroupName(securityGroupName);
configureHazelcast(cfg);
HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);
return instance;
}
}
......@@ -99,13 +99,14 @@ public class SpringCacheConfig {
final Properties properties = new Properties();
properties.setProperty("use-client", "false");
properties.setProperty("map-name", "jetty-sessions");
properties.setProperty("session-ttl-seconds", "21600");
// Not allowed in HZ-3.8.1
// properties.setProperty("session-ttl-seconds", "21600");
properties.setProperty("sticky-session", "false");
properties.setProperty("cookie-name", "hz-session-id");
properties.setProperty("cookie-domain", cookieDomain);
properties.setProperty("cookie-secure", cookieSecure);
properties.setProperty("cookie-http-only", cookieHttpOnly);
properties.setProperty("debug", "true");
// properties.setProperty("debug", "true");
properties.setProperty("instance-name", instanceName);
properties.setProperty("shutdown-on-destroy", "true");
return properties;
......
......@@ -99,7 +99,7 @@ public class ApiCropsTest extends AbstractRestTest {
public void listCropsTest() throws Exception {
LOG.info("Start test-method listCropsTest");
mockMvc.perform(get("/api/v0/crops").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON))
mockMvc.perform(get("/api/v0/crops").contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", hasSize(1))).andExpect(jsonPath("$[0].id", is(notNullValue()))).andExpect(jsonPath("$[0].version", is(0)))
.andExpect(jsonPath("$[0].shortName", is("maize"))).andExpect(jsonPath("$[0].i18n", is(nullValue()))).andExpect(jsonPath("$[0].name", is("Maize")))
.andExpect(jsonPath("$[0].description", is("Crop description in EN"))).andDo(document("crop-list"));
......@@ -111,12 +111,12 @@ public class ApiCropsTest extends AbstractRestTest {
public void createCropTest() throws Exception {
LOG.info("Start test-method createCropTest");
mockMvc.perform(post("/api/v0/crops").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(new Object() {
mockMvc.perform(post("/api/v0/crops").contentType(MediaType.APPLICATION_JSON_UTF8).content(objectMapper.writeValueAsString(new Object() {
public String shortName = "rice";
public String name = "Rice";
public String description = "Crop description in EN";
public String[] otherNames = { "ris", "riž" };
}))).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)).andExpect(jsonPath("$.id", is(notNullValue())))
}))).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$.id", is(notNullValue())))
.andExpect(jsonPath("$.version", is(0))).andExpect(jsonPath("$.shortName", is("rice"))).andExpect(jsonPath("$.i18n", is(nullValue())))
.andExpect(jsonPath("$.name", is("Rice"))).andExpect(jsonPath("$.description", is("Crop description in EN")))
.andDo(document("crop-create",
......@@ -138,8 +138,8 @@ public class ApiCropsTest extends AbstractRestTest {
public void getCropTest() throws Exception {
LOG.info("Start test-method getCropTest");
mockMvc.perform(get("/api/v0/crops/{shortName}", crop.getShortName()).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andExpect(jsonPath("$.id", is(notNullValue()))).andExpect(jsonPath("$.version", is(0)))
mockMvc.perform(get("/api/v0/crops/{shortName}", crop.getShortName()).contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$.id", is(notNullValue()))).andExpect(jsonPath("$.version", is(0)))
.andExpect(jsonPath("$.shortName", is("maize"))).andExpect(jsonPath("$.i18n", is(nullValue()))).andExpect(jsonPath("$.name", is("Maize")))
.andExpect(jsonPath("$.description", is("Crop description in EN")))
.andDo(document("crop-get", pathParameters(parameterWithName("shortName").description("Crop short name or code (e.g. maize)")),
......@@ -160,8 +160,8 @@ public class ApiCropsTest extends AbstractRestTest {
createCropTest();
mockMvc.perform(delete("/api/v0/crops/{shortName}", "rice").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andExpect(jsonPath("$.id", is(nullValue()))).andExpect(jsonPath("$.version", is(0)))
mockMvc.perform(delete("/api/v0/crops/{shortName}", "rice").contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$.id", is(nullValue()))).andExpect(jsonPath("$.version", is(0)))
.andExpect(jsonPath("$.shortName", is("rice"))).andExpect(jsonPath("$.i18n", is(nullValue()))).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)"))));
......@@ -173,8 +173,8 @@ public class ApiCropsTest extends AbstractRestTest {
public void getCropDescriptorsTest() throws Exception {
LOG.info("Start test-method getCropDescriptorsTest");
mockMvc.perform(get("/api/v0/crops/{shortName}/descriptors", crop.getShortName()).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andExpect(jsonPath("$.content", hasSize(0)))
mockMvc.perform(get("/api/v0/crops/{shortName}/descriptors", crop.getShortName()).contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$.content", hasSize(0)))
// .andExpect(jsonPath("$.lastPage", is(true)))
.andExpect(jsonPath("$.numberOfElements", is(0))).andExpect(jsonPath("$.totalElements", is(0))).andExpect(jsonPath("$.number", is(0)))
// .andExpect(jsonPath("$.firstPage", is(true)))
......@@ -188,8 +188,8 @@ public class ApiCropsTest extends AbstractRestTest {
public void getCropRulesTest() throws Exception {
LOG.info("Start test-method getCropRulesTest");
mockMvc.perform(get("/api/v0/crops/{shortName}/rules", crop.getShortName()).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andExpect(jsonPath("$", hasSize(1))).andExpect(jsonPath("$[0].id", is(notNullValue())))
mockMvc.perform(get("/api/v0/crops/{shortName}/rules", crop.getShortName()).contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$", hasSize(1))).andExpect(jsonPath("$[0].id", is(notNullValue())))
.andExpect(jsonPath("$[0].included", is(true))).andExpect(jsonPath("$[0].genus", is("Zea"))).andExpect(jsonPath("$[0].species", is("mays")))
.andExpect(jsonPath("$[0].subtaxa", is(nullValue())))
.andDo(document("crop-rules-list", pathParameters(parameterWithName("shortName").description("Crop short name or code (e.g. maize)"))));
......@@ -212,8 +212,8 @@ public class ApiCropsTest extends AbstractRestTest {
cropRule.setSubtaxa("var. foobaria");
cropRules.add(cropRule);
mockMvc.perform(put("/api/v0/crops/{shortName}/rules", crop.getShortName()).contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(cropRules)))
.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)).andExpect(jsonPath("$", hasSize(1)))
mockMvc.perform(put("/api/v0/crops/{shortName}/rules", crop.getShortName()).contentType(MediaType.APPLICATION_JSON_UTF8).content(objectMapper.writeValueAsString(cropRules)))
.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$", hasSize(1)))
.andExpect(jsonPath("$[0].id", is(notNullValue()))).andExpect(jsonPath("$[0].included", is(true))).andExpect(jsonPath("$[0].genus", is("Zea")))
.andExpect(jsonPath("$[0].species", is("mays"))).andExpect(jsonPath("$[0].subtaxa", is("var. foobaria")))
.andDo(document("crop-rules-update", pathParameters(parameterWithName("shortName").description("Crop short name or code (e.g. maize)")),
......@@ -229,8 +229,8 @@ public class ApiCropsTest extends AbstractRestTest {
public void getCropTaxaTest() throws Exception {
LOG.info("Start test-method getCropTaxaTest");
mockMvc.perform(get("/api/v0/crops/{shortName}/taxa", crop.getShortName()).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andExpect(jsonPath("$.content", hasSize(0)))
mockMvc.perform(get("/api/v0/crops/{shortName}/taxa", crop.getShortName()).contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$.content", hasSize(0)))
// .andExpect(jsonPath("$.lastPage", is(true)))
.andExpect(jsonPath("$.numberOfElements", is(0))).andExpect(jsonPath("$.totalElements", is(0))).andExpect(jsonPath("$.number", is(0)))
// .andExpect(jsonPath("$.firstPage", is(true)))
......@@ -249,8 +249,8 @@ public class ApiCropsTest extends AbstractRestTest {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(JSON_OK);
mockMvc.perform(post("/api/v0/crops/rebuild").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andExpect(content().string(objectMapper.writeValueAsString(jsonNode)));
mockMvc.perform(post("/api/v0/crops/rebuild").contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(content().string(objectMapper.writeValueAsString(jsonNode)));
LOG.info("Test rebuildTest passed");
}
......@@ -264,8 +264,8 @@ public class ApiCropsTest extends AbstractRestTest {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(JSON_OK);
mockMvc.perform(post("/api/v0/crops/{shortName}/rebuild", crop.getShortName()).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andExpect(content().string(objectMapper.writeValueAsString(jsonNode)));
mockMvc.perform(post("/api/v0/crops/{shortName}/rebuild", crop.getShortName()).contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(content().string(objectMapper.writeValueAsString(jsonNode)));
LOG.info("Test rebuildCropTest passed");
}
......
......@@ -114,8 +114,8 @@ public class ApiImagesDocsTest extends AbstractRestTest {
@Test
public void testListGalleries() throws UnsupportedEncodingException, Exception {
mockMvc.perform(get("/api/v0/img/{instCode}/_galleries", TEST_INSTCODE).param("page", "1").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andDo(r -> {
mockMvc.perform(get("/api/v0/img/{instCode}/_galleries", TEST_INSTCODE).param("page", "1").contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andDo(r -> {
LOG.info("Institute galleries: " + r.getResponse().getContentAsString());
}).andExpect(jsonPath("$.content", hasSize(0))).andExpect(jsonPath("$.totalElements", is(0))).andExpect(jsonPath("$.last", is(true)))
.andDo(document("img-instgallery-list", pathParameters(parameterWithName("instCode").description("Institute WIEWS code (e.g. NGA039)")),
......@@ -131,7 +131,7 @@ public class ApiImagesDocsTest extends AbstractRestTest {
public void testUploadImage1() throws UnsupportedEncodingException, Exception {
final StringBuilder sb = new StringBuilder();
mockMvc.perform(put("/api/v0/img/{instCode}/acn/{acceNumb}/", TEST_INSTCODE, ACCENUMB).param("originalFilename", image1.getOriginalFilename()).contentType(MediaType.IMAGE_JPEG_VALUE)
.content(image1.getImageBytes())).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)).andDo(r -> {
.content(image1.getImageBytes())).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andDo(r -> {
LOG.info("Image PUT response: " + r.getResponse().getContentAsString());
RepositoryImage ri = objectMapper.readValue(r.getResponse().getContentAsString(), RepositoryImage.class);
LOG.info(ri);
......@@ -174,8 +174,8 @@ public class ApiImagesDocsTest extends AbstractRestTest {
ri.setSubject(ACCENUMB);
ri.setTitle("Leaf of " + ACCENUMB);
ri.setExtent("4000x2000 pixels, 10MB");
mockMvc.perform(put("/api/v0/img/{instCode}/acn/{acceNumb}/{uuid}/_metadata", TEST_INSTCODE, ACCENUMB, uuid).contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.content(objectMapper.writeValueAsString(ri))).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)).andDo(r -> {
mockMvc.perform(put("/api/v0/img/{instCode}/acn/{acceNumb}/{uuid}/_metadata", TEST_INSTCODE, ACCENUMB, uuid).contentType(MediaType.APPLICATION_JSON_UTF8)
.content(objectMapper.writeValueAsString(ri))).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andDo(r -> {
LOG.info("Image metadata put: " + r.getResponse().getContentAsString());
})
.andDo(document("img-instgallery-metadata-put",
......@@ -220,7 +220,7 @@ public class ApiImagesDocsTest extends AbstractRestTest {
fieldWithPath("dateSubmitted").ignored(), fieldWithPath("modified").ignored())));
mockMvc.perform(get("/api/v0/img/{instCode}/acn/{acceNumb}/{uuid}/_metadata", TEST_INSTCODE, ACCENUMB, uuid)).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andDo(r -> {
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andDo(r -> {
LOG.info("Image metadata: " + r.getResponse().getContentAsString());
})
.andDo(document("img-instgallery-metadata-get",
......@@ -244,7 +244,7 @@ public class ApiImagesDocsTest extends AbstractRestTest {
fieldWithPath("lastModifiedDate").ignored(), fieldWithPath("originalUrl").ignored(), fieldWithPath("dateRetrieved").ignored(), fieldWithPath("dateSubmitted").ignored(),
fieldWithPath("modified").ignored())));
mockMvc.perform(get("/api/v0/img/{instCode}/acn/{acceNumb}/_list", TEST_INSTCODE, ACCENUMB)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)).andDo(r -> {
mockMvc.perform(get("/api/v0/img/{instCode}/acn/{acceNumb}/_list", TEST_INSTCODE, ACCENUMB)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andDo(r -> {
LOG.info("Listing image UUIDs: " + r.getResponse().getContentAsString());
}).andDo(document("img-instgallery-accelist",
pathParameters(parameterWithName("instCode").description("Institute WIEWS code (e.g. NGA039)"), parameterWithName("acceNumb").description("Existing ACCENUMB in the institute"))));
......
......@@ -98,7 +98,7 @@ public class ApiRequestsDocsTest extends AbstractRestTest {
@Test
public void listRequestsTest() throws Exception {
mockMvc.perform(get("/api/v0/requests/{instCode}", TEST_INSTCODE).param("page", "0")).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andDo(r -> {
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andDo(r -> {
System.err.println(r.getResponse().getContentAsString());
}).andExpect(jsonPath("$.size", is(10))).andExpect(jsonPath("$.first", is(true)))
.andDo(document("requests-inst-list", pathParameters(parameterWithName("instCode").description("Institute WIEWS code (e.g. NGA039)")),
......@@ -114,8 +114,8 @@ public class ApiRequestsDocsTest extends AbstractRestTest {
// /requests/{instCode}/r/{uuid:.{36}}
@Test
public void getRequestInfoTest() throws Exception {
mockMvc.perform(get("/api/v0/requests//{instCode}/r/{uuid}", TEST_INSTCODE, requestUuid.toString()).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andDo(r -> {
mockMvc.perform(get("/api/v0/requests//{instCode}/r/{uuid}", TEST_INSTCODE, requestUuid.toString()).contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andDo(r -> {
System.err.println(r.getResponse().getContentAsString());
})
// .andExpect(jsonPath("$", hasSize(1)))
......
......@@ -96,7 +96,7 @@ public class BrAPITest extends AbstractRestTest {
public void crops() throws Exception {
LOG.info("Start test-method listCropsTest");
mockMvc.perform(get("/brapi/v1/crops?page=0&pageSize=2").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON))
mockMvc.perform(get("/brapi/v1/crops?page=0&pageSize=2").contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
// peek
.andDo(r -> {
System.err.println(r.getResponse().getContentAsString());
......@@ -121,8 +121,8 @@ public class BrAPITest extends AbstractRestTest {
@Test
public void germplasmSearch() throws Exception {
mockMvc.perform(get("/brapi/v1/germplasm-search?page=0&pageSize=2&germplasmName=&germplasmDbId=&germplasmPUI=").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
mockMvc.perform(get("/brapi/v1/germplasm-search?page=0&pageSize=2&germplasmName=&germplasmDbId=&germplasmPUI=").contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
// peek
.andDo(r -> {
System.err.println(r.getResponse().getContentAsString());
......@@ -150,9 +150,9 @@ public class BrAPITest extends AbstractRestTest {
@Test
public void germplasm() throws Exception {
mockMvc.perform(get("/brapi/v1/germplasm/{germplasmID}", "cd8c1217-4503-4859-813b-32251f0c8eba").contentType(MediaType.APPLICATION_JSON))
mockMvc.perform(get("/brapi/v1/germplasm/{germplasmID}", "cd8c1217-4503-4859-813b-32251f0c8eba").contentType(MediaType.APPLICATION_JSON_UTF8))
// response
// .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON))
// .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
// peek
.andDo(r -> {
System.err.println(r.getResponse().getContentAsString());
......
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