|
3 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; |
4 | 4 | import static org.junit.jupiter.api.Assertions.assertFalse; |
5 | 5 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 6 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
6 | 7 |
|
7 | 8 | import java.security.GeneralSecurityException; |
8 | 9 | import java.security.NoSuchAlgorithmException; |
|
16 | 17 | import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; |
17 | 18 | import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariables; |
18 | 19 | import org.springframework.core.ParameterizedTypeReference; |
| 20 | +import org.springframework.http.HttpStatus; |
| 21 | +import org.springframework.web.client.RestClientResponseException; |
19 | 22 |
|
20 | 23 | import city.makeour.ngsi.v2.api.EntitiesApi; |
21 | 24 | import city.makeour.ngsi.v2.model.CreateEntityRequest; |
@@ -205,4 +208,52 @@ void testUpdateEntity_UpsertLogic() throws GeneralSecurityException, NoSuchAlgor |
205 | 208 |
|
206 | 209 | assertEquals("active", updatedEntity.get("status")); |
207 | 210 | } |
| 211 | + |
| 212 | + @Test |
| 213 | + @DisplayName("deleteEntityのテスト(ID+Type指定、IDのみ指定の2パターン)") |
| 214 | + @EnabledIfEnvironmentVariables({ |
| 215 | + @EnabledIfEnvironmentVariable(named = "TEST_COGNITO_USER_POOL_ID", matches = ".*"), |
| 216 | + @EnabledIfEnvironmentVariable(named = "TEST_COGNITO_CLIENT_ID", matches = ".*"), |
| 217 | + @EnabledIfEnvironmentVariable(named = "TEST_COGNITO_USERNAME", matches = ".*"), |
| 218 | + @EnabledIfEnvironmentVariable(named = "TEST_COGNITO_PASSWORD", matches = ".*") |
| 219 | + }) |
| 220 | + void testDeleteEntity() throws GeneralSecurityException, NoSuchAlgorithmException { |
| 221 | + // 1. セットアップ |
| 222 | + MocClient client = new MocClient(); |
| 223 | + client.setMocAuthInfo(System.getenv("TEST_COGNITO_USER_POOL_ID"), System.getenv("TEST_COGNITO_CLIENT_ID")); |
| 224 | + client.login(System.getenv("TEST_COGNITO_USERNAME"), System.getenv("TEST_COGNITO_PASSWORD")); |
| 225 | + |
| 226 | + String type = "TestDeleteType"; |
| 227 | + |
| 228 | + // ケース 1: deleteEntity(id, type) |
| 229 | + String id1 = "urn:ngsi-ld:TestDelete:1:" + UUID.randomUUID().toString(); |
| 230 | + |
| 231 | + // データ作成(既存のupdateEntityを利用して作成) |
| 232 | + client.updateEntity(id1, type, Map.of("value", 100)); |
| 233 | + |
| 234 | + // 削除実行(テスト対象) |
| 235 | + client.deleteEntity(id1, type).toBodilessEntity(); |
| 236 | + |
| 237 | + // 検証: 取得しようとして 404 Not Found になることを確認 |
| 238 | + RestClientResponseException ex1 = assertThrows(RestClientResponseException.class, () -> { |
| 239 | + client.getEntity(id1, type).toBodilessEntity(); |
| 240 | + }); |
| 241 | + assertEquals(HttpStatus.NOT_FOUND.value(), ex1.getStatusCode().value()); |
| 242 | + |
| 243 | + // ケース 2: deleteEntity(id) - IDのみでの削除 |
| 244 | + String id2 = "urn:ngsi-ld:TestDelete:2:" + UUID.randomUUID().toString(); |
| 245 | + |
| 246 | + // データ作成 |
| 247 | + client.updateEntity(id2, type, Map.of("value", 200)); |
| 248 | + |
| 249 | + // 削除実行(テスト対象) |
| 250 | + client.deleteEntity(id2).toBodilessEntity(); |
| 251 | + |
| 252 | + // 検証: 取得しようとして 404 Not Found になることを確認 |
| 253 | + RestClientResponseException ex2 = assertThrows(RestClientResponseException.class, () -> { |
| 254 | + client.getEntity(id2, type).toBodilessEntity(); |
| 255 | + }); |
| 256 | + assertEquals(HttpStatus.NOT_FOUND.value(), ex2.getStatusCode().value()); |
| 257 | + } |
| 258 | + |
208 | 259 | } |
0 commit comments