Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 83a0b086 authored by Joze RIHTARSIC's avatar Joze RIHTARSIC
Browse files

fix gitlab failed plans

parent 5a9bd71b
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.type.CollectionType;
import eu.europa.ec.edelivery.smp.data.ui.UserRO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.mock.web.MockServletContext;
......@@ -38,6 +40,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
* @since 4.2
*/
public class MockMvcUtils {
public static Logger LOG = LoggerFactory.getLogger(MockMvcUtils.class);
static ObjectMapper mapper = JsonMapper.builder()
.findAndAddModules()
.build();
......@@ -52,6 +55,7 @@ public class MockMvcUtils {
public static final String SG_USER2_USERNAME = "test_user_hashed_pass";
public static final String SG_USER2_PASSWD = "test123";
public static final String MOCK_LOGGED_USER = "mock_logged_user";
public static RequestPostProcessor getHttpBasicSystemAdminCredentials() {
return httpBasic(SYS_ADMIN_USERNAME, SYS_ADMIN_PASSWD);
......@@ -110,9 +114,14 @@ public class MockMvcUtils {
.content("{\"username\":\"" + username + "\",\"password\":\"" + password + "\"}"))
.andExpect(status().isOk()).andReturn();
// assert successful login
UserRO userRO = mapper.readValue(result.getResponse().getContentAsString(), UserRO.class);
byte[] asByteArray = result.getResponse().getContentAsByteArray();
LOG.info("User logged with data: []", new String(asByteArray));
UserRO userRO = mapper.readValue(asByteArray, UserRO.class);
assertNotNull(userRO);
return (MockHttpSession) result.getRequest().getSession();
MockHttpSession session = (MockHttpSession)result.getRequest().getSession();
session.setAttribute(MOCK_LOGGED_USER, userRO);
return session;
}
/**
......@@ -129,6 +138,7 @@ public class MockMvcUtils {
.with(csrf()))
.andExpect(status().isOk()).andReturn();
byte[] asByteArray = result.getResponse().getContentAsByteArray();
LOG.info("User session validated with logged data: []", new String(asByteArray));
return mapper.readValue(asByteArray, UserRO.class);
}
......@@ -152,8 +162,8 @@ public class MockMvcUtils {
return mapper.readValue(result.getResponse().getContentAsString(), collectionType);
}
public static <T> T parseResponse(MvcResult result, Class<T> clazz) throws UnsupportedEncodingException, JsonProcessingException {
return mapper.readValue(result.getResponse().getContentAsString(), clazz);
public static <T> T parseResponse(MvcResult result, Class<T> clazz) throws IOException {
return mapper.readValue(result.getResponse().getContentAsByteArray(), clazz);
}
public static String serializeObject(Object object) throws JsonProcessingException {
......
......@@ -118,11 +118,13 @@ public class DomainAdminResourceIntegrationTest {
assertEquals(domainToUpdate.getDomainCode(), resultObject.getDomainCode());
assertEquals(EntityROStatus.UPDATED.getStatusNumber(), resultObject.getStatus());
}
@Test
public void updateDomainSmlIntegrationData() throws Exception {
String domainCode = "domainTwo";
MockHttpSession session = loginWithSystemAdmin(mvc);
UserRO userRO = MockMvcUtils.getLoggedUserData(mvc, session);
UserRO userRO = (UserRO)session.getAttribute(MOCK_LOGGED_USER);
DomainRO domainToUpdate = getDomain(domainCode, userRO, session);
domainToUpdate.setSmlSubdomain("NewCode");
domainToUpdate.setSmlClientKeyAlias("New alias");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment