|
| 1 | +/** |
| 2 | + * Copyright (c) 2022, RTE (http://www.rte-france.com) |
| 3 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 | + */ |
| 7 | +package org.gridsuite.useradmin.server; |
| 8 | + |
| 9 | +import com.fasterxml.jackson.core.type.TypeReference; |
| 10 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 11 | +import org.gridsuite.useradmin.server.repository.UserAdminRepository; |
| 12 | +import org.gridsuite.useradmin.server.repository.UserInfosEntity; |
| 13 | +import org.junit.Before; |
| 14 | +import org.junit.Test; |
| 15 | +import org.junit.runner.RunWith; |
| 16 | +import org.springframework.beans.factory.annotation.Autowired; |
| 17 | +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; |
| 18 | +import org.springframework.boot.test.context.SpringBootTest; |
| 19 | +import org.springframework.test.context.ActiveProfiles; |
| 20 | +import org.springframework.test.context.ContextConfiguration; |
| 21 | +import org.springframework.test.context.junit4.SpringRunner; |
| 22 | +import org.springframework.test.web.servlet.MockMvc; |
| 23 | + |
| 24 | +import java.util.List; |
| 25 | +import java.util.UUID; |
| 26 | + |
| 27 | +import static org.junit.Assert.assertEquals; |
| 28 | +import static org.springframework.http.MediaType.APPLICATION_JSON; |
| 29 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; |
| 30 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
| 31 | + |
| 32 | +/** |
| 33 | + * @author Etienne Homer <etienne.homer at rte-france.com> |
| 34 | + */ |
| 35 | +@RunWith(SpringRunner.class) |
| 36 | +@AutoConfigureMockMvc |
| 37 | +@SpringBootTest |
| 38 | +@ContextConfiguration(classes = {UserAdminApplication.class}) |
| 39 | +@ActiveProfiles("no-admin") |
| 40 | +public class NoAdminTest { |
| 41 | + |
| 42 | + @Autowired |
| 43 | + private MockMvc mockMvc; |
| 44 | + |
| 45 | + @Autowired |
| 46 | + ObjectMapper objectMapper = new ObjectMapper(); |
| 47 | + |
| 48 | + @Autowired |
| 49 | + private UserAdminRepository repository; |
| 50 | + |
| 51 | + private void cleanDB() { |
| 52 | + repository.deleteAll(); |
| 53 | + } |
| 54 | + |
| 55 | + @Before |
| 56 | + public void setup() { |
| 57 | + cleanDB(); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + public void testNoAdmin()throws Exception { |
| 62 | + |
| 63 | + mockMvc.perform(head("/" + UserAdminApi.API_VERSION + "/users/{sub}", "NOT_REGISTERED_USER")) |
| 64 | + .andExpect(status().isOk()) |
| 65 | + .andReturn(); |
| 66 | + } |
| 67 | +} |
0 commit comments