Skip to content

Commit

Permalink
additional tests
Browse files Browse the repository at this point in the history
Signed-off-by: Amit Galitzky <[email protected]>
  • Loading branch information
amitgalitz committed Mar 16, 2022
1 parent 4b05832 commit 7f1e523
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -479,15 +479,16 @@ List<String> 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',
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/opensearch/ad/model/EntityProfileName.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,21 @@ public void testSerializeAnomalyResultBucket() throws IOException {
assertTrue(parsedAnomalyResultBucket.equals(anomalyResultBucket));
}

public void testAnomalyResultBucketEquals() {
Map<String, Object> keyOne = new HashMap<>();
keyOne.put("test-field-1", "test-value-1");
Map<String, Object> 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<String, Object> key = new HashMap<String, Object>() {
Map<String, Object> key = new HashMap<>() {
{
put("test-field-1", "test-value-1");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 7f1e523

Please sign in to comment.