Commit d97f695e authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Gson removed

parent b6df252c
package lcsb.mapviewer.web;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*;
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
import static org.springframework.restdocs.request.RequestDocumentation.*;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.patch;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.entity.UrlEncodedFormEntity;
......@@ -15,33 +31,47 @@ import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.restdocs.payload.*;
import org.springframework.restdocs.payload.FieldDescriptor;
import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.restdocs.payload.RequestFieldsSnippet;
import org.springframework.restdocs.payload.ResponseFieldsSnippet;
import org.springframework.restdocs.request.ParameterDescriptor;
import org.springframework.restdocs.request.RequestParametersSnippet;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.RequestBuilder;
import com.google.gson.*;
import com.fasterxml.jackson.core.type.TypeReference;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lcsb.mapviewer.annotation.services.annotators.UniprotAnnotator;
import lcsb.mapviewer.api.users.UserRestImpl;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.species.*;
import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.Gene;
import lcsb.mapviewer.model.map.species.Protein;
import lcsb.mapviewer.model.security.Privilege;
import lcsb.mapviewer.model.security.PrivilegeType;
import lcsb.mapviewer.model.user.*;
import lcsb.mapviewer.model.user.ConfigurationElementType;
import lcsb.mapviewer.model.user.ResetPasswordToken;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.persist.dao.ProjectDao;
import lcsb.mapviewer.persist.dao.user.ResetPasswordTokenDao;
import lcsb.mapviewer.services.interfaces.*;
import lcsb.mapviewer.services.interfaces.IConfigurationService;
import lcsb.mapviewer.services.interfaces.IDataOverlayService;
import lcsb.mapviewer.services.interfaces.IUserService;
import lcsb.mapviewer.services.utils.EmailSender;
@RunWith(SpringJUnit4ClassRunner.class)
......@@ -277,7 +307,8 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
.andExpect(status().is2xxSuccessful())
.andReturn().getResponse().getContentAsString();
Map<?, ?> responseObject = new Gson().fromJson(response, Map.class);
Map<String, Object> responseObject = objectMapper.readValue(response, new TypeReference<Map<String, Object>>() {
});
List<?> privileges = (List<?>) responseObject.get("privileges");
assertEquals(0, privileges.size());
......@@ -906,10 +937,8 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
uploadPreferences.put("semantic-zooming-contains-multiple-overlays", true);
uploadPreferences.put("sbgn", true);
String body = new Gson().toJson(data);
RequestBuilder request = patch("/api/users/{login}:updatePreferences", TEST_USER_LOGIN)
.content(body)
.content(objectMapper.writeValueAsString(data))
.session(session);
mockMvc.perform(request)
......@@ -950,10 +979,8 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
parameters.add(createParameterClass("OUTPUT", 4, MiriamType.EC, null));
parameters.add(createParameterClass("OUTPUT", 5, MiriamType.ENTREZ, null));
String body = new Gson().toJson(data);
RequestBuilder request = patch("/api/users/{login}:updatePreferences", TEST_USER_LOGIN)
.content(body)
.content(objectMapper.writeValueAsString(data))
.session(session);
mockMvc.perform(request)
......@@ -985,10 +1012,8 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
annotations.put("require-at-least-one", true);
annotations.put("annotation-list", Arrays.asList(MiriamType.HGNC, MiriamType.HGNC_SYMBOL));
String body = new Gson().toJson(data);
RequestBuilder request = patch("/api/users/{login}:updatePreferences", TEST_USER_LOGIN)
.content(body)
.content(objectMapper.writeValueAsString(data))
.session(session);
mockMvc.perform(request)
......@@ -1016,10 +1041,8 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
preferences.put("element-valid-annotations", elementAnnotations);
elementAnnotations.put(Gene.class.getCanonicalName(), Arrays.asList(MiriamType.HGNC));
String body = new Gson().toJson(data);
RequestBuilder request = patch("/api/users/{login}:updatePreferences", TEST_USER_LOGIN)
.content(body)
.content(objectMapper.writeValueAsString(data))
.session(session);
mockMvc.perform(request)
......@@ -1048,10 +1071,8 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
preferences.put("gui-preferences", elementAnnotations);
elementAnnotations.put("admin-projects-datatable-order", "1-asc");
String body = new Gson().toJson(data);
RequestBuilder request = patch("/api/users/{login}:updatePreferences", TEST_USER_LOGIN)
.content(body)
.content(objectMapper.writeValueAsString(data))
.session(session);
mockMvc.perform(request)
......
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