diff --git a/build.gradle b/build.gradle index d450c9acd..6cecc7fe2 100644 --- a/build.gradle +++ b/build.gradle @@ -479,15 +479,16 @@ List jacocoExclusions = [ // code for configuration, settings, etc is excluded from coverage 'org.opensearch.ad.AnomalyDetectorPlugin', + // rest layer is tested in integration testing mostly, difficult to mock all of it + 'org.opensearch.ad.rest.*', + 'org.opensearch.ad.model.ModelProfileOnNode', 'org.opensearch.ad.model.InitProgressProfile', 'org.opensearch.ad.model.ADTaskProfile', - 'org.opensearch.ad.model.AnomalyResultBucket', - 'org.opensearch.ad.model.EntityProfileName', 'org.opensearch.ad.rest.*', 'org.opensearch.ad.AnomalyDetectorJobRunner', - // Class containing just constants. Don't need to test + // Class containing just constants. Don't need to test 'org.opensearch.ad.constant.*', //'org.opensearch.ad.common.exception.AnomalyDetectionException', diff --git a/src/main/java/org/opensearch/ad/model/EntityProfileName.java b/src/main/java/org/opensearch/ad/model/EntityProfileName.java index bf6180f16..0d01df54e 100644 --- a/src/main/java/org/opensearch/ad/model/EntityProfileName.java +++ b/src/main/java/org/opensearch/ad/model/EntityProfileName.java @@ -15,6 +15,7 @@ import java.util.Set; import org.opensearch.ad.Name; +import org.opensearch.ad.constant.CommonErrorMessages; import org.opensearch.ad.constant.CommonName; public enum EntityProfileName implements Name { @@ -50,7 +51,7 @@ public static EntityProfileName getName(String name) { case CommonName.MODELS: return MODELS; default: - throw new IllegalArgumentException("Unsupported profile types"); + throw new IllegalArgumentException(CommonErrorMessages.UNSUPPORTED_PROFILE_TYPE); } } diff --git a/src/test/java/org/opensearch/ad/AnomalyDetectorProfileRunnerTests.java b/src/test/java/org/opensearch/ad/AnomalyDetectorProfileRunnerTests.java index 9a6276529..cc703da5d 100644 --- a/src/test/java/org/opensearch/ad/AnomalyDetectorProfileRunnerTests.java +++ b/src/test/java/org/opensearch/ad/AnomalyDetectorProfileRunnerTests.java @@ -638,6 +638,8 @@ public void testFailRCFPolling() throws IOException, InterruptedException { public void testInitProgressProfile() { InitProgressProfile progressOne = new InitProgressProfile("0%", 0, requiredSamples); InitProgressProfile progressTwo = new InitProgressProfile("0%", 0, requiredSamples); + InitProgressProfile progressThree = new InitProgressProfile("96%", 2, requiredSamples); assertTrue(progressOne.equals(progressTwo)); + assertFalse(progressOne.equals(progressThree)); } } diff --git a/src/test/java/org/opensearch/ad/model/AnomalyResultBucketTests.java b/src/test/java/org/opensearch/ad/model/AnomalyResultBucketTests.java index 55e2ce28d..4fdaa5e13 100644 --- a/src/test/java/org/opensearch/ad/model/AnomalyResultBucketTests.java +++ b/src/test/java/org/opensearch/ad/model/AnomalyResultBucketTests.java @@ -31,9 +31,21 @@ public void testSerializeAnomalyResultBucket() throws IOException { assertTrue(parsedAnomalyResultBucket.equals(anomalyResultBucket)); } + public void testAnomalyResultBucketEquals() { + Map keyOne = new HashMap<>(); + keyOne.put("test-field-1", "test-value-1"); + Map keyTwo = new HashMap<>(); + keyTwo.put("test-field-2", "test-value-2"); + AnomalyResultBucket testBucketOne = new AnomalyResultBucket(keyOne, 3, 0.5); + AnomalyResultBucket testBucketTwo = new AnomalyResultBucket(keyOne, 5, 0.75); + AnomalyResultBucket testBucketThree = new AnomalyResultBucket(keyTwo, 7, 0.2); + assertFalse(testBucketOne.equals(testBucketTwo)); + assertFalse(testBucketTwo.equals(testBucketThree)); + } + @SuppressWarnings("unchecked") public void testToXContent() throws IOException { - Map key = new HashMap() { + Map key = new HashMap<>() { { put("test-field-1", "test-value-1"); } diff --git a/src/test/java/org/opensearch/ad/transport/EntityProfileTests.java b/src/test/java/org/opensearch/ad/transport/EntityProfileTests.java index 2e47c9d8f..4267486e6 100644 --- a/src/test/java/org/opensearch/ad/transport/EntityProfileTests.java +++ b/src/test/java/org/opensearch/ad/transport/EntityProfileTests.java @@ -38,6 +38,7 @@ import org.opensearch.ad.cluster.HashRing; import org.opensearch.ad.common.exception.AnomalyDetectionException; import org.opensearch.ad.common.exception.JsonPathNotFoundException; +import org.opensearch.ad.constant.CommonErrorMessages; import org.opensearch.ad.constant.CommonName; import org.opensearch.ad.model.Entity; import org.opensearch.ad.model.EntityProfileName; @@ -372,4 +373,11 @@ public void testResponseHashCodeEquals() { set.add(response); assertTrue(set.contains(response)); } + + public void testEntityProfileName() { + assertEquals("state", EntityProfileName.getName(CommonName.STATE).getName()); + assertEquals("models", EntityProfileName.getName(CommonName.MODELS).getName()); + IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> EntityProfileName.getName("abc")); + assertEquals(exception.getMessage(), CommonErrorMessages.UNSUPPORTED_PROFILE_TYPE); + } }