|
| 1 | +/* |
| 2 | + * Fusion Studio API - API for Fusion Studio |
| 3 | + * Copyright © 2017 Evolved Binary ([email protected]) |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU Affero General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU Affero General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Affero General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | +package com.fusiondb.studio.api; |
| 19 | + |
| 20 | +import io.restassured.response.ExtractableResponse; |
| 21 | +import io.restassured.response.Response; |
| 22 | +import org.junit.jupiter.api.Test; |
| 23 | + |
| 24 | +import java.util.Map; |
| 25 | + |
| 26 | +import static com.evolvedbinary.j8fu.tuple.Tuple.Tuple; |
| 27 | +import static com.fusiondb.studio.api.API.*; |
| 28 | +import static io.restassured.RestAssured.given; |
| 29 | +import static io.restassured.http.ContentType.JSON; |
| 30 | +import static org.apache.http.HttpStatus.*; |
| 31 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 32 | + |
| 33 | +public class UserIT { |
| 34 | + |
| 35 | + @Test |
| 36 | + public void createUser() { |
| 37 | + createUser("123"); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void disableUser() { |
| 42 | + final String userId = "456"; |
| 43 | + |
| 44 | + // 1. create the user |
| 45 | + createUser(userId); |
| 46 | + |
| 47 | + // 2. update the user |
| 48 | + final Map<String, Object> requestBody = mapOf( |
| 49 | + Tuple("userName", "user" + userId), |
| 50 | + Tuple("enabled", false) |
| 51 | + ); |
| 52 | + given(). |
| 53 | + auth().preemptive().basic(DEFAULT_ADMIN_USERNAME, DEFAULT_ADMIN_PASSWORD). |
| 54 | + contentType(JSON). |
| 55 | + body(requestBody). |
| 56 | + when(). |
| 57 | + put(getApiBaseUri() + "/user/user" + userId). |
| 58 | + then(). |
| 59 | + statusCode(SC_NO_CONTENT); |
| 60 | + |
| 61 | + // get user |
| 62 | + final ExtractableResponse<Response> userResponse = getUser(userId); |
| 63 | + |
| 64 | + // check they are now disabled |
| 65 | + assertFalse(userResponse.jsonPath().getBoolean("enabled")); |
| 66 | + } |
| 67 | + |
| 68 | + private ExtractableResponse<Response> getUser(final String userId) { |
| 69 | + return |
| 70 | + given(). |
| 71 | + auth().preemptive().basic(DEFAULT_ADMIN_USERNAME, DEFAULT_ADMIN_PASSWORD). |
| 72 | + contentType(JSON). |
| 73 | + when(). |
| 74 | + get(getApiBaseUri() + "/user/user" + userId). |
| 75 | + then(). |
| 76 | + statusCode(SC_OK) |
| 77 | + .extract(); |
| 78 | + } |
| 79 | + |
| 80 | + private void createUser(final String userId) { |
| 81 | + final Map<String, Object> requestBody = mapOf( |
| 82 | + Tuple("userName", "user" + userId), |
| 83 | + Tuple("password", "user" + userId), |
| 84 | + Tuple("metadata", arrayOf( |
| 85 | + mapOf( |
| 86 | + Tuple("key", "http://axschema.org/namePerson"), |
| 87 | + Tuple("value", "User " + userId) |
| 88 | + ), |
| 89 | + mapOf( |
| 90 | + Tuple("key", "http://axschema.org/pref/language"), |
| 91 | + Tuple("value", "en") |
| 92 | + ) |
| 93 | + )) |
| 94 | + ); |
| 95 | + |
| 96 | + given(). |
| 97 | + auth().preemptive().basic(DEFAULT_ADMIN_USERNAME, DEFAULT_ADMIN_PASSWORD). |
| 98 | + contentType(JSON). |
| 99 | + body(requestBody). |
| 100 | + when(). |
| 101 | + put(getApiBaseUri() + "/user/user" + userId). |
| 102 | + then(). |
| 103 | + statusCode(SC_NO_CONTENT); |
| 104 | + } |
| 105 | +} |
0 commit comments