Skip to content

Commit e5cdfa0

Browse files
committed
Add test with no admin
Signed-off-by: Etienne Homer <[email protected]>
1 parent fe22f3e commit e5cdfa0

File tree

4 files changed

+92
-2
lines changed

4 files changed

+92
-2
lines changed

src/main/java/org/gridsuite/useradmin/server/SwaggerConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public class SwaggerConfig {
2121
public OpenAPI openAPI() {
2222
return new OpenAPI()
2323
.info(new Info()
24-
.title("Short Circuit API")
25-
.description("This is the documentation of the short circuit REST API")
24+
.title("User Admin API")
25+
.description("This is the documentation of the user admin REST API")
2626
.version(UserAdminApi.API_VERSION));
2727
}
2828
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
}

src/test/java/org/gridsuite/useradmin/server/UserAdminTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.springframework.beans.factory.annotation.Autowired;
1717
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
1818
import org.springframework.boot.test.context.SpringBootTest;
19+
import org.springframework.test.context.ActiveProfiles;
1920
import org.springframework.test.context.ContextConfiguration;
2021
import org.springframework.test.context.junit4.SpringRunner;
2122
import org.springframework.test.web.servlet.MockMvc;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
spring:
2+
jpa:
3+
database: H2
4+
properties:
5+
dialect: org.hibernate.dialect.H2Dialect
6+
hibernate.format_sql: true
7+
hibernate.generate_statistics: true
8+
9+
logging:
10+
level:
11+
org.springframework.orm.jpa: DEBUG
12+
org.springframework.transaction: DEBUG
13+
org.hibernate.SQL: DEBUG
14+
org.hibernate.type.descriptor.sql.BasicBinder: TRACE
15+
16+
dbVendor: h2:mem
17+
query: ;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
18+
hostPort: ":"
19+
20+
useradmin:
21+
admins:
22+

0 commit comments

Comments
 (0)