From 0fd8c03ef6e34a099eab723bba26890e4fe8b062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Chirose=E2=80=9D?= Date: Wed, 17 Sep 2025 11:38:59 +0900 Subject: [PATCH 1/6] getEntity added --- src/main/java/city/makeour/moc/MocClient.java | 5 +++ .../java/city/makeour/moc/MocClientTest.java | 32 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/main/java/city/makeour/moc/MocClient.java b/src/main/java/city/makeour/moc/MocClient.java index fedfcdd..1edca5a 100644 --- a/src/main/java/city/makeour/moc/MocClient.java +++ b/src/main/java/city/makeour/moc/MocClient.java @@ -92,4 +92,9 @@ public void setFiwareService(String fiwareService) { public ResponseSpec createEntity(String contentType, Object body) { return this.client.createEntity(contentType, body); } + + public ResponseSpec getEntity(String entityId, String type, String attrs, String metadata, String options) { + return this.entities().retrieveEntityWithResponseSpec(entityId, type, attrs, metadata, options); + } + } diff --git a/src/test/java/city/makeour/moc/MocClientTest.java b/src/test/java/city/makeour/moc/MocClientTest.java index 403a04c..000b5ec 100644 --- a/src/test/java/city/makeour/moc/MocClientTest.java +++ b/src/test/java/city/makeour/moc/MocClientTest.java @@ -16,6 +16,7 @@ import city.makeour.ngsi.v2.api.EntitiesApi; import city.makeour.ngsi.v2.model.CreateEntityRequest; import city.makeour.ngsi.v2.model.ListEntitiesResponse; +import city.makeour.ngsi.v2.model.RetrieveEntityResponse; class MocClientTest { @@ -94,6 +95,7 @@ void testSetMocAuthInfo() throws GeneralSecurityException, NoSuchAlgorithmExcept @EnabledIfEnvironmentVariable(named = "TEST_COGNITO_USERNAME", matches = ".*"), @EnabledIfEnvironmentVariable(named = "TEST_COGNITO_PASSWORD", matches = ".*") }) + void testAuth() throws GeneralSecurityException, NoSuchAlgorithmException { String cognitoUserPoolId = System.getenv("TEST_COGNITO_USER_POOL_ID"); String cognitoClientId = System.getenv("TEST_COGNITO_CLIENT_ID"); @@ -113,4 +115,34 @@ void testAuth() throws GeneralSecurityException, NoSuchAlgorithmException { client.entities().createEntity("application/json", entity, "keyValues"); } + + @Test + @DisplayName("エンティティを作成・取得できるかのテスト(最小版)") + @EnabledIfEnvironmentVariables({ + @EnabledIfEnvironmentVariable(named = "TEST_COGNITO_USER_POOL_ID", matches = ".*"), + @EnabledIfEnvironmentVariable(named = "TEST_COGNITO_CLIENT_ID", matches = ".*"), + @EnabledIfEnvironmentVariable(named = "TEST_COGNITO_USERNAME", matches = ".*"), + @EnabledIfEnvironmentVariable(named = "TEST_COGNITO_PASSWORD", matches = ".*") + }) + void testCreateAndGetEntity_Minimal() throws GeneralSecurityException, NoSuchAlgorithmException { + MocClient client = new MocClient(); + client.setMocAuthInfo(System.getenv("TEST_COGNITO_USER_POOL_ID"), System.getenv("TEST_COGNITO_CLIENT_ID")); + client.login(System.getenv("TEST_COGNITO_USERNAME"), System.getenv("TEST_COGNITO_PASSWORD")); + + // 作成&取得 + String entityId = "urn:ngsi-ld:TestEntity:" + UUID.randomUUID().toString(); + CreateEntityRequest entity = new CreateEntityRequest(); + entity.setType("TestEntity"); + entity.setId(entityId); + + // 作成を実行 + client.entities().createEntity("application/json", entity, null); + + // getEntityの呼び出し、レスポンスの変換 + RetrieveEntityResponse retrievedEntity = client.getEntity(entityId) + .body(RetrieveEntityResponse.class); + + assertNotNull(retrievedEntity); + assertEquals(entityId, retrievedEntity.getId()); + } } From 5122fc435d0287729b374c9013a4da9ec61d952a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Chirose=E2=80=9D?= Date: Wed, 1 Oct 2025 10:39:30 +0900 Subject: [PATCH 2/6] MocClientTest revised --- src/test/java/city/makeour/moc/MocClientTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/city/makeour/moc/MocClientTest.java b/src/test/java/city/makeour/moc/MocClientTest.java index 000b5ec..8a02c10 100644 --- a/src/test/java/city/makeour/moc/MocClientTest.java +++ b/src/test/java/city/makeour/moc/MocClientTest.java @@ -139,8 +139,9 @@ void testCreateAndGetEntity_Minimal() throws GeneralSecurityException, NoSuchAlg client.entities().createEntity("application/json", entity, null); // getEntityの呼び出し、レスポンスの変換 - RetrieveEntityResponse retrievedEntity = client.getEntity(entityId) - .body(RetrieveEntityResponse.class); + RetrieveEntityResponse retrievedEntity = client + .getEntity(entityId, "TestEntity", null, null, null) + .body(RetrieveEntityResponse.class); assertNotNull(retrievedEntity); assertEquals(entityId, retrievedEntity.getId()); From 579be55830f6eb8c9de7ca04bdb5c5ca8ed9a494 Mon Sep 17 00:00:00 2001 From: mohirose <143729590+mohirose@users.noreply.github.com> Date: Wed, 1 Oct 2025 11:19:39 +0900 Subject: [PATCH 3/6] Update src/test/java/city/makeour/moc/MocClientTest.java Co-authored-by: Shugo USHIO --- src/test/java/city/makeour/moc/MocClientTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/city/makeour/moc/MocClientTest.java b/src/test/java/city/makeour/moc/MocClientTest.java index 8a02c10..d6fa07c 100644 --- a/src/test/java/city/makeour/moc/MocClientTest.java +++ b/src/test/java/city/makeour/moc/MocClientTest.java @@ -136,7 +136,7 @@ void testCreateAndGetEntity_Minimal() throws GeneralSecurityException, NoSuchAlg entity.setId(entityId); // 作成を実行 - client.entities().createEntity("application/json", entity, null); + client.entities().createEntity("application/json", entity, "keyValues"); // getEntityの呼び出し、レスポンスの変換 RetrieveEntityResponse retrievedEntity = client From af26255102768cfa570534717321ccf6042e7e64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Chirose=E2=80=9D?= Date: Wed, 1 Oct 2025 12:02:48 +0900 Subject: [PATCH 4/6] keyValues added --- src/main/java/city/makeour/moc/MocClient.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/city/makeour/moc/MocClient.java b/src/main/java/city/makeour/moc/MocClient.java index 1edca5a..c9b7681 100644 --- a/src/main/java/city/makeour/moc/MocClient.java +++ b/src/main/java/city/makeour/moc/MocClient.java @@ -94,7 +94,15 @@ public ResponseSpec createEntity(String contentType, Object body) { } public ResponseSpec getEntity(String entityId, String type, String attrs, String metadata, String options) { - return this.entities().retrieveEntityWithResponseSpec(entityId, type, attrs, metadata, options); + return this.entities().retrieveEntityWithResponseSpec(entityId, type, attrs, metadata, "keyValues"); + } + + public ResponseSpec getEntity(String entityId, String type, String attrs) { + return this.entities().retrieveEntityWithResponseSpec(entityId, type, attrs, null, "keyValues"); + } + + public ResponseSpec getEntity(String entityId, String type) { + return this.entities().retrieveEntityWithResponseSpec(entityId, type, null, null, "keyValues"); } } From 1b8bf663511178dd87b00c605d7e2cf731953186 Mon Sep 17 00:00:00 2001 From: Shugo USHIO Date: Wed, 8 Oct 2025 11:07:27 +0900 Subject: [PATCH 5/6] Update src/test/java/city/makeour/moc/MocClientTest.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/test/java/city/makeour/moc/MocClientTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/city/makeour/moc/MocClientTest.java b/src/test/java/city/makeour/moc/MocClientTest.java index d6fa07c..acc9b68 100644 --- a/src/test/java/city/makeour/moc/MocClientTest.java +++ b/src/test/java/city/makeour/moc/MocClientTest.java @@ -145,5 +145,5 @@ void testCreateAndGetEntity_Minimal() throws GeneralSecurityException, NoSuchAlg assertNotNull(retrievedEntity); assertEquals(entityId, retrievedEntity.getId()); - } + } } From b3a279ead11b043ddd58e8a209c4c9f7c0546810 Mon Sep 17 00:00:00 2001 From: Shugo USHIO Date: Wed, 8 Oct 2025 11:07:48 +0900 Subject: [PATCH 6/6] Update src/main/java/city/makeour/moc/MocClient.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/main/java/city/makeour/moc/MocClient.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/main/java/city/makeour/moc/MocClient.java b/src/main/java/city/makeour/moc/MocClient.java index c9b7681..e0d34af 100644 --- a/src/main/java/city/makeour/moc/MocClient.java +++ b/src/main/java/city/makeour/moc/MocClient.java @@ -93,14 +93,55 @@ public ResponseSpec createEntity(String contentType, Object body) { return this.client.createEntity(contentType, body); } + /** + * Retrieves an entity with the specified parameters. + * + * @param entityId The ID of the entity to retrieve. + * @param type The type of the entity. + * @param attrs Comma-separated list of attribute names to include in the response. If null, all attributes are returned. + * @param metadata Comma-separated list of metadata names to include. If null, all metadata is returned. + * @param options Options to modify the response format (e.g., "keyValues" for simplified representation). + * @return The response specification for the entity retrieval request. + * + *

+ * Use this overload to fully customize the entity retrieval, including which attributes, + * metadata, and options are used. The {@code options} parameter allows you to control + * the response format; for example, "keyValues" returns a simplified JSON object. + *

+ */ public ResponseSpec getEntity(String entityId, String type, String attrs, String metadata, String options) { return this.entities().retrieveEntityWithResponseSpec(entityId, type, attrs, metadata, "keyValues"); } + /** + * Retrieves an entity with the specified ID, type, and attributes. + * + * @param entityId The ID of the entity to retrieve. + * @param type The type of the entity. + * @param attrs Comma-separated list of attribute names to include in the response. If null, all attributes are returned. + * @return The response specification for the entity retrieval request. + * + *

+ * This overload defaults {@code metadata} to {@code null} (all metadata) and {@code options} to {@code "keyValues"} + * for a simplified response format. + *

+ */ public ResponseSpec getEntity(String entityId, String type, String attrs) { return this.entities().retrieveEntityWithResponseSpec(entityId, type, attrs, null, "keyValues"); } + /** + * Retrieves an entity with the specified ID and type. + * + * @param entityId The ID of the entity to retrieve. + * @param type The type of the entity. + * @return The response specification for the entity retrieval request. + * + *

+ * This overload defaults {@code attrs} and {@code metadata} to {@code null} (all attributes and metadata), + * and {@code options} to {@code "keyValues"} for a simplified response format. + *

+ */ public ResponseSpec getEntity(String entityId, String type) { return this.entities().retrieveEntityWithResponseSpec(entityId, type, null, null, "keyValues"); }