Skip to content

Commit

Permalink
Refactoring Model Profile Test (#750)
Browse files Browse the repository at this point in the history
* Validate Detector Action Handle request

Signed-off-by: Varun Jain <[email protected]>

* Validate Detector Action Handle request

Signed-off-by: Varun Jain <[email protected]>

* Validate Detector Action Handle request

Signed-off-by: Varun Jain <[email protected]>

* Validate Detector Action Handle request

Signed-off-by: Varun Jain <[email protected]>

* Validate Detector Action Handle request

Signed-off-by: Varun Jain <[email protected]>

* Validate Detector handle request

Signed-off-by: Varun Jain <[email protected]>

* Validate Detector Handle Request

Signed-off-by: Varun Jain <[email protected]>

* Validate Detector Handle Request

Signed-off-by: Varun Jain <[email protected]>

* Validate Detector Handle Request

Signed-off-by: Varun Jain <[email protected]>

* Model Profile Test

Signed-off-by: Varun Jain <[email protected]>

Signed-off-by: Varun Jain <[email protected]>
  • Loading branch information
vibrantvarun authored Dec 6, 2022
1 parent bda73f8 commit 68910ff
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/test/java/org/opensearch/ad/model/ModelProfileTests.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
}

0 comments on commit 68910ff

Please sign in to comment.