Search in sources :

Example 31 with WithMockUser

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())));
}
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 32 with WithMockUser

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())));
}
Also used : DiscordSnowflake(com.fredboat.backend.quarterdeck.rest.v1.transfer.DiscordSnowflake) Prefix(com.fredboat.backend.quarterdeck.db.entities.main.Prefix) WithMockUser(org.springframework.security.test.context.support.WithMockUser) BaseTest(com.fredboat.backend.quarterdeck.BaseTest) Test(org.junit.jupiter.api.Test)

Example 33 with WithMockUser

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)));
}
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 34 with WithMockUser

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())));
}
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 35 with WithMockUser

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"));
}
Also used : ClientRegistration(org.springframework.security.oauth2.client.registration.ClientRegistration) RegisteredOAuth2AuthorizedClient(org.springframework.security.oauth2.client.annotation.RegisteredOAuth2AuthorizedClient) OAuth2AuthorizedClient(org.springframework.security.oauth2.client.OAuth2AuthorizedClient) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Aggregations

WithMockUser (org.springframework.security.test.context.support.WithMockUser)3415 Test (org.junit.jupiter.api.Test)2107 Test (org.junit.Test)1226 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)865 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)427 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)409 MvcResult (org.springframework.test.web.servlet.MvcResult)304 ResultActions (org.springframework.test.web.servlet.ResultActions)278 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)275 Transactional (org.springframework.transaction.annotation.Transactional)220 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)179 User (io.github.jhipster.sample.domain.User)149 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)124 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