use of org.springframework.security.test.context.support.WithMockUser in project Backend by FredBoat.
the class PrefixControllerTest method testDelete.
// delete
@WithMockUser(roles = "ADMIN")
@Test
public void testDelete() throws Exception {
DiscordSnowflake guildId = generateUniqueSnowflakeId();
DiscordSnowflake botId = generateUniqueSnowflakeId();
this.mockMvc.perform(delete(urlTemplate, guildId, botId).contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)).andExpect(jsonPath("$.guildId", both(isA(String.class)).and(is(guildId.getSnowflakeId())))).andExpect(jsonPath("$.botId", both(isA(String.class)).and(is(botId.getSnowflakeId())))).andExpect(jsonPath("$.prefixes", hasItems(Prefix.DEFAULT_PREFIXES.toArray(new String[0])))).andExpect(jsonPath("$.prefixes.length()", is(Prefix.DEFAULT_PREFIXES.size())));
}
use of org.springframework.security.test.context.support.WithMockUser in project Backend by FredBoat.
the class PrefixControllerTest method testDeleteAll.
// test remove all prefixes
@WithMockUser(roles = "ADMIN")
@Test
public void testDeleteAll() throws Exception {
DiscordSnowflake guildId = generateUniqueSnowflakeId();
DiscordSnowflake botId = generateUniqueSnowflakeId();
String[] current = this.gson.fromJson(this.mockMvc.perform(get(urlTemplate, guildId, botId)).andReturn().getResponse().getContentAsString(), com.fredboat.backend.quarterdeck.rest.v1.transfer.Prefix.class).getPrefixes();
this.mockMvc.perform(delete(urlTemplate, guildId, botId).content(this.gson.toJson(current)).contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)).andExpect(jsonPath("$.guildId", both(isA(String.class)).and(is(guildId.getSnowflakeId())))).andExpect(jsonPath("$.botId", both(isA(String.class)).and(is(botId.getSnowflakeId())))).andExpect(jsonPath("$.prefixes", hasItems(Prefix.DEFAULT_PREFIXES.toArray(new String[0])))).andExpect(jsonPath("$.prefixes.length()", is(Prefix.DEFAULT_PREFIXES.size())));
}
use of org.springframework.security.test.context.support.WithMockUser in project Backend by FredBoat.
the class PrefixControllerTest method testAddSingle.
// test add single prefix
@WithMockUser(roles = "ADMIN")
@Test
public void testAddSingle() throws Exception {
DiscordSnowflake guildId = generateUniqueSnowflakeId();
DiscordSnowflake botId = generateUniqueSnowflakeId();
String[] addPrefix = { "this_is_a_prefix_in_an_array" };
this.mockMvc.perform(post(urlTemplate, guildId, botId).content(this.gson.toJson(addPrefix)).contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)).andExpect(jsonPath("$.guildId", both(isA(String.class)).and(is(guildId.getSnowflakeId())))).andExpect(jsonPath("$.botId", both(isA(String.class)).and(is(botId.getSnowflakeId())))).andExpect(jsonPath("$.prefixes", hasItems(Prefix.DEFAULT_PREFIXES.toArray(new String[0])))).andExpect(jsonPath("$.prefixes", hasItems(addPrefix))).andExpect(jsonPath("$.prefixes.length()", is(Prefix.DEFAULT_PREFIXES.size() + 1)));
}
use of org.springframework.security.test.context.support.WithMockUser in project Backend by FredBoat.
the class PrefixControllerTest method testDeleteMultiple.
// test remove multiple prefixes
@WithMockUser(roles = "ADMIN")
@Test
public void testDeleteMultiple() throws Exception {
DiscordSnowflake guildId = generateUniqueSnowflakeId();
DiscordSnowflake botId = generateUniqueSnowflakeId();
String[] addPrefixes = { "1", "2", "3", "4" };
this.mockMvc.perform(post(urlTemplate, guildId, botId).content(this.gson.toJson(addPrefixes)).contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)).andExpect(jsonPath("$.guildId", both(isA(String.class)).and(is(guildId.getSnowflakeId())))).andExpect(jsonPath("$.botId", both(isA(String.class)).and(is(botId.getSnowflakeId())))).andExpect(jsonPath("$.prefixes", hasItems(Prefix.DEFAULT_PREFIXES.toArray(new String[0])))).andExpect(jsonPath("$.prefixes", hasItems(addPrefixes))).andExpect(jsonPath("$.prefixes.length()", is(Prefix.DEFAULT_PREFIXES.size() + addPrefixes.length)));
this.mockMvc.perform(delete(urlTemplate, guildId, botId).content(this.gson.toJson(addPrefixes)).contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)).andExpect(jsonPath("$.guildId", both(isA(String.class)).and(is(guildId.getSnowflakeId())))).andExpect(jsonPath("$.botId", both(isA(String.class)).and(is(botId.getSnowflakeId())))).andExpect(jsonPath("$.prefixes", hasItems(Prefix.DEFAULT_PREFIXES.toArray(new String[0])))).andExpect(jsonPath("$.prefixes.length()", is(Prefix.DEFAULT_PREFIXES.size())));
}
use of org.springframework.security.test.context.support.WithMockUser in project spring-security by spring-projects.
the class OAuth2ClientBeanDefinitionParserTests method requestWhenAuthorizedClientFoundThenMethodArgumentResolved.
@WithMockUser
@Test
public void requestWhenAuthorizedClientFoundThenMethodArgumentResolved() throws Exception {
this.spring.configLocations(xml("AuthorizedClientArgumentResolver")).autowire();
ClientRegistration clientRegistration = this.clientRegistrationRepository.findByRegistrationId("google");
OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient(clientRegistration, "user", TestOAuth2AccessTokens.noScopes());
given(this.authorizedClientRepository.loadAuthorizedClient(any(), any(), any())).willReturn(authorizedClient);
this.mvc.perform(get("/authorized-client")).andExpect(status().isOk()).andExpect(content().string("resolved"));
}
Aggregations