-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...igurationserver/src/test/java/rocks/inspectit/ocelot/mappings/model/AgentMappingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package rocks.inspectit.ocelot.mappings.model; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.util.*; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class AgentMappingTest { | ||
|
||
private AgentMapping mapping; | ||
|
||
@BeforeEach | ||
public void beforeEach() { | ||
Map<String, String> attributes = new HashMap<>(); | ||
attributes.put("first", "01234"); | ||
attributes.put("second", "AnAttribute"); | ||
attributes.put("third", "\\d+"); | ||
List<String> sources = new ArrayList<>(); | ||
sources.add("/one"); | ||
sources.add("/two/a.yml"); | ||
sources.add("/two/b.yml"); | ||
mapping = new AgentMapping("test-mapping", sources, attributes); | ||
} | ||
|
||
@Nested | ||
class MatchesAttributes { | ||
|
||
@Test | ||
public void sameAttributes() { | ||
Map<String, String> attributes = ImmutableMap.of("first", "01234", "second", "AnAttribute", "third", "0"); | ||
|
||
boolean result = mapping.matchesAttributes(attributes); | ||
|
||
assertThat(result).isTrue(); | ||
} | ||
|
||
@Test | ||
public void differentCasing() { | ||
Map<String, String> attributes = ImmutableMap.of("first", "01234", "second", "anaTTribute", "third", "0"); | ||
|
||
boolean result = mapping.matchesAttributes(attributes); | ||
|
||
assertThat(result).isTrue(); | ||
} | ||
|
||
@Test | ||
public void differentAttributes() { | ||
Map<String, String> attributes = ImmutableMap.of("first", "00000", "second", "AnAttribute", "third", "0"); | ||
|
||
boolean result = mapping.matchesAttributes(attributes); | ||
|
||
assertThat(result).isFalse(); | ||
} | ||
|
||
@Test | ||
public void emptyAttributes() { | ||
Map<String, String> attributes = Collections.emptyMap(); | ||
|
||
boolean result = mapping.matchesAttributes(attributes); | ||
|
||
assertThat(result).isFalse(); | ||
} | ||
|
||
@Test | ||
public void wrongRegexAttribute() { | ||
Map<String, String> attributes = ImmutableMap.of("first", "01234", "second", "AnAttribute", "third", ""); | ||
|
||
boolean result = mapping.matchesAttributes(attributes); | ||
|
||
assertThat(result).isFalse(); | ||
} | ||
} | ||
|
||
} |