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);
}
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();
}
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()))));
}
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"));
}
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))));
}
Aggregations