Search in sources :

Example 26 with WithMockUser

use of org.springframework.security.test.context.support.WithMockUser in project theskeleton by codenergic.

the class ProfileSocialRestControllerTest method testRemoveSocialConnection.

@Test
@WithMockUser("user123")
public void testRemoveSocialConnection() throws Exception {
    MockHttpServletRequestBuilder request = delete("/api/profile/socials").content(PROVIDER_ID).contentType(MediaType.APPLICATION_JSON);
    MockHttpServletResponse response = mockMvc.perform(request).andDo(document("user-profile-socials-remove")).andReturn().getResponse();
    assertThat(response.getStatus()).isEqualTo(200);
    verify(connectionRepository).removeConnections(PROVIDER_ID);
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 27 with WithMockUser

use of org.springframework.security.test.context.support.WithMockUser in project theskeleton by codenergic.

the class ProfileSocialRestControllerTest method testSocialConnections.

@Test
@WithMockUser("user123")
public void testSocialConnections() throws Exception {
    LinkedMultiValueMap<String, Connection<?>> connections = new LinkedMultiValueMap<>();
    connections.add(connection.getKey().getProviderId(), connection);
    when(connectionRepository.findAllConnections()).thenReturn(connections);
    MockHttpServletRequestBuilder request = get("/api/profile/socials").contentType(MediaType.APPLICATION_JSON);
    MockHttpServletResponse response = mockMvc.perform(request).andDo(document("user-profile-socials-list")).andReturn().getResponse();
    assertThat(response.getStatus()).isEqualTo(200);
    JsonNode jsonResponse = objectMapper.readTree(response.getContentAsByteArray());
    assertThat(jsonResponse.isObject()).isTrue();
    assertThat(jsonResponse.has(PROVIDER_ID)).isTrue();
    assertThat(jsonResponse.get(PROVIDER_ID).isObject()).isTrue();
    assertThat(jsonResponse.get(PROVIDER_ID).get("imageUrl").textValue()).isEqualTo(connection.getImageUrl());
    verify(connectionRepository).findAllConnections();
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) JsonNode(com.fasterxml.jackson.databind.JsonNode) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 28 with WithMockUser

use of org.springframework.security.test.context.support.WithMockUser in project Backend by FredBoat.

the class GuildConfigControllerTest method testDelete.

@WithMockUser(roles = "ADMIN")
@Test
public void testDelete() throws Exception {
    DiscordSnowflake guildId = generateUniqueSnowflakeId();
    this.mockMvc.perform(get(urlTemplate, guildId)).andExpect(jsonPath("$.language", is(equalToIgnoringCase(GuildConfig.DEFAULT_LANGAUGE.getCode()))));
    Map<String, Object> patchGuildConfig = new HashMap<>();
    patchGuildConfig.put("language", Language.DE_DE.getCode());
    MockHttpServletRequestBuilder patch = patch(urlTemplate, guildId).content(this.gson.toJson(patchGuildConfig)).contentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
    this.mockMvc.perform(patch).andExpect(jsonPath("$.language", is(equalToIgnoringCase(Language.DE_DE.getCode()))));
    this.mockMvc.perform(get(urlTemplate, guildId)).andExpect(jsonPath("$.language", is(equalToIgnoringCase(Language.DE_DE.getCode()))));
    this.mockMvc.perform(delete(urlTemplate, guildId)).andExpect(status().isOk()).andDo(document("guild/config/delete"));
    this.mockMvc.perform(get(urlTemplate, guildId)).andExpect(jsonPath("$.language", is(equalToIgnoringCase(GuildConfig.DEFAULT_LANGAUGE.getCode()))));
}
Also used : HashMap(java.util.HashMap) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) DiscordSnowflake(com.fredboat.backend.quarterdeck.rest.v1.transfer.DiscordSnowflake) WithMockUser(org.springframework.security.test.context.support.WithMockUser) BaseTest(com.fredboat.backend.quarterdeck.BaseTest) Test(org.junit.jupiter.api.Test)

Example 29 with WithMockUser

use of org.springframework.security.test.context.support.WithMockUser in project Backend by FredBoat.

the class GuildDataControllerTest method testGet.

@WithMockUser(roles = "ADMIN")
@Test
public void testGet() throws Exception {
    DiscordSnowflake guildId = generateUniqueSnowflakeId();
    this.mockMvc.perform(get(urlTemplate, guildId)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)).andExpect(jsonPath("$.guildId", both(isA(String.class)).and(is(guildId.getSnowflakeId())))).andExpect(jsonPath("$.helloSent", isA(String.class))).andDo(document("guild/data/get"));
}
Also used : DiscordSnowflake(com.fredboat.backend.quarterdeck.rest.v1.transfer.DiscordSnowflake) WithMockUser(org.springframework.security.test.context.support.WithMockUser) BaseTest(com.fredboat.backend.quarterdeck.BaseTest) Test(org.junit.jupiter.api.Test)

Example 30 with WithMockUser

use of org.springframework.security.test.context.support.WithMockUser in project Backend by FredBoat.

the class GuildDataControllerTest method testDelete.

@WithMockUser(roles = "ADMIN")
@Test
public void testDelete() throws Exception {
    DiscordSnowflake guildId = generateUniqueSnowflakeId();
    this.mockMvc.perform(get(urlTemplate, guildId)).andExpect(jsonPath("$.helloSent", is(Long.toString(GuildData.DEFAULT_HELLO_SENT_TIMESTAMP))));
    Map<String, Object> patchGuildData = new HashMap<>();
    long now = System.currentTimeMillis();
    patchGuildData.put("helloSent", now);
    MockHttpServletRequestBuilder patch = patch(urlTemplate, guildId).content(this.gson.toJson(patchGuildData)).contentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
    this.mockMvc.perform(patch).andExpect(jsonPath("$.helloSent", is(Long.toString(now))));
    this.mockMvc.perform(get(urlTemplate, guildId)).andExpect(jsonPath("$.helloSent", is(Long.toString(now))));
    this.mockMvc.perform(delete(urlTemplate, guildId)).andExpect(status().isOk()).andDo(document("guild/data/delete"));
    this.mockMvc.perform(get(urlTemplate, guildId)).andExpect(jsonPath("$.helloSent", is(Long.toString(GuildData.DEFAULT_HELLO_SENT_TIMESTAMP))));
}
Also used : HashMap(java.util.HashMap) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) DiscordSnowflake(com.fredboat.backend.quarterdeck.rest.v1.transfer.DiscordSnowflake) WithMockUser(org.springframework.security.test.context.support.WithMockUser) BaseTest(com.fredboat.backend.quarterdeck.BaseTest) Test(org.junit.jupiter.api.Test)

Aggregations

WithMockUser (org.springframework.security.test.context.support.WithMockUser)3191 Test (org.junit.jupiter.api.Test)1911 Test (org.junit.Test)1198 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)762 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)427 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)379 MvcResult (org.springframework.test.web.servlet.MvcResult)290 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)275 ResultActions (org.springframework.test.web.servlet.ResultActions)224 Transactional (org.springframework.transaction.annotation.Transactional)200 User (io.github.jhipster.sample.domain.User)138 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)136 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)130 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)130 Course (de.tum.in.www1.artemis.domain.Course)124 ArrayList (java.util.ArrayList)118 Exam (de.tum.in.www1.artemis.domain.exam.Exam)114 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)103 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)102 User (de.tum.in.www1.artemis.domain.User)95