Search in sources :

Example 51 with WithMockUser

use of org.springframework.security.test.context.support.WithMockUser in project spring-security by spring-projects.

the class EnableWebFluxSecurityTests method authenticationPrincipalArgumentResolverWhenSpelThenWorks.

@Test
@WithMockUser
public void authenticationPrincipalArgumentResolverWhenSpelThenWorks() {
    this.spring.register(AuthenticationPrincipalConfig.class).autowire();
    // @formatter:off
    WebTestClient client = WebTestClient.bindToApplicationContext(this.spring.getContext()).build();
    client.get().uri("/spel").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("user");
// @formatter:on
}
Also used : WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 52 with WithMockUser

use of org.springframework.security.test.context.support.WithMockUser in project xm-ms-entity by xm-online.

the class XmEntityResourceExtendedIntTest method getAllXmEntitiesByTypeKeyNo.

@Test
@Transactional
@WithMockUser(authorities = "SUPER-ADMIN")
public void getAllXmEntitiesByTypeKeyNo() throws Exception {
    XmEntity entity = createEntityComplexPersisted(em);
    // Get all the xmEntityList
    performGet("/api/xm-entities?sort=id,desc&typeKey=PRICE").andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)).andExpect(jsonPath("$.[*].id").value(everyItem(nullValue())));
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 53 with WithMockUser

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

the class PlatformIT method testEntityListener.

@WithMockUser(username = USERNAME)
@Test(singleThreaded = true)
public void testEntityListener() {
    populateUserPermissions();
    List<Entity> refEntities = testHarness.createTestRefEntities(refEntityTypeDynamic, 6);
    List<Entity> entities = testHarness.createTestEntities(entityTypeDynamic, 2, refEntities).collect(toList());
    runAsSystem(() -> {
        dataService.add(refEntityTypeDynamic.getId(), refEntities.stream());
        dataService.add(entityTypeDynamic.getId(), entities.stream());
        waitForIndexToBeStable(entityTypeDynamic, indexService, LOG);
    });
    AtomicInteger updateCalled = new AtomicInteger(0);
    EntityListener listener = new EntityListener() {

        @Override
        public Object getEntityId() {
            return entities.get(0).getIdValue();
        }

        @Override
        public void postUpdate(Entity entity) {
            updateCalled.incrementAndGet();
            assertEquals(entity.getIdValue(), entities.get(0).getIdValue());
        }
    };
    try {
        // Test that the listener is being called
        entityListenersService.addEntityListener(entityTypeDynamic.getId(), listener);
        dataService.update(entityTypeDynamic.getId(), entities.stream());
        assertEquals(updateCalled.get(), 1);
        waitForIndexToBeStable(entityTypeDynamic, indexService, LOG);
        assertPresent(entityTypeDynamic, entities);
    } finally {
        // Test that the listener is actually removed and not called anymore
        entityListenersService.removeEntityListener(entityTypeDynamic.getId(), listener);
        updateCalled.set(0);
        dataService.update(entityTypeDynamic.getId(), entities.stream());
        assertEquals(updateCalled.get(), 0);
        waitForIndexToBeStable(entityTypeDynamic, indexService, LOG);
        assertPresent(entityTypeDynamic, entities);
    }
}
Also used : EntityListener(org.molgenis.data.listeners.EntityListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) WithMockUser(org.springframework.security.test.context.support.WithMockUser)

Example 54 with WithMockUser

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

the class DataServiceIT method testGetEntityType.

@WithMockUser(username = USERNAME_READ)
@Test(groups = "readtest")
public void testGetEntityType() {
    EntityType entityType = dataService.getEntityType(DataServiceIT.entityType.getId());
    assertNotNull(entityType);
    assertTrue(EntityUtils.equals(entityType, DataServiceIT.entityType));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 55 with WithMockUser

use of org.springframework.security.test.context.support.WithMockUser in project ranger by apache.

the class RangerKylinAuthorizerTest method adminProjectAllWithAdminPermission.

/**
 * kylin admin all projects success
 */
@Test
@WithMockUser(username = KYLIN, roles = { ROLE_USER })
public void adminProjectAllWithAdminPermission() {
    for (ProjectInstance project : uuid2Projects.values()) {
        boolean result = aclEvaluate.hasProjectAdminPermission(project);
        Assert.assertTrue(result);
    }
}
Also used : ProjectInstance(org.apache.kylin.metadata.project.ProjectInstance) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.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