From 68910ffa9d66f3b3fb6da7af9ea7df24821a56ce Mon Sep 17 00:00:00 2001 From: Varun Jain Date: Tue, 6 Dec 2022 12:09:54 -0800 Subject: [PATCH] Refactoring Model Profile Test (#750) * Validate Detector Action Handle request Signed-off-by: Varun Jain * Validate Detector Action Handle request Signed-off-by: Varun Jain * Validate Detector Action Handle request Signed-off-by: Varun Jain * Validate Detector Action Handle request Signed-off-by: Varun Jain * Validate Detector Action Handle request Signed-off-by: Varun Jain * Validate Detector handle request Signed-off-by: Varun Jain * Validate Detector Handle Request Signed-off-by: Varun Jain * Validate Detector Handle Request Signed-off-by: Varun Jain * Validate Detector Handle Request Signed-off-by: Varun Jain * Model Profile Test Signed-off-by: Varun Jain Signed-off-by: Varun Jain --- .../ad/model/ModelProfileTests.java | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/opensearch/ad/model/ModelProfileTests.java b/src/test/java/org/opensearch/ad/model/ModelProfileTests.java index a1122e565..f588aa55c 100644 --- a/src/test/java/org/opensearch/ad/model/ModelProfileTests.java +++ b/src/test/java/org/opensearch/ad/model/ModelProfileTests.java @@ -1,3 +1,14 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + package org.opensearch.ad.model; import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder; @@ -20,24 +31,25 @@ public void testToXContent() throws IOException { Entity.createSingleAttributeEntity(randomAlphaOfLength(5), randomAlphaOfLength(5)), 0 ); - XContentBuilder builder = jsonBuilder(); - builder.startObject(); - profile1.toXContent(builder, ToXContent.EMPTY_PARAMS); - builder.endObject(); + XContentBuilder builder = getBuilder(profile1); String json = Strings.toString(builder); assertTrue(JsonDeserializer.hasChildNode(json, CommonName.ENTITY_KEY)); assertFalse(JsonDeserializer.hasChildNode(json, CommonName.MODEL_SIZE_IN_BYTES)); ModelProfile profile2 = new ModelProfile(randomAlphaOfLength(5), null, 1); - builder = jsonBuilder(); - builder.startObject(); - profile2.toXContent(builder, ToXContent.EMPTY_PARAMS); - builder.endObject(); + builder = getBuilder(profile2); json = Strings.toString(builder); assertFalse(JsonDeserializer.hasChildNode(json, CommonName.ENTITY_KEY)); assertTrue(JsonDeserializer.hasChildNode(json, CommonName.MODEL_SIZE_IN_BYTES)); + } + private XContentBuilder getBuilder(ModelProfile profile) throws IOException { + XContentBuilder builder = jsonBuilder(); + builder.startObject(); + profile.toXContent(builder, ToXContent.EMPTY_PARAMS); + builder.endObject(); + return builder; } }