-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
410 additions
and
111 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
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
77 changes: 76 additions & 1 deletion
77
...gent/instrumentation/hook/configuration/resolver/MethodHookConfigurationResolverTest.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 |
---|---|---|
@@ -1,6 +1,81 @@ | ||
/* (C) 2024 */ | ||
package rocks.inspectit.gepard.agent.instrumentation.hook.configuration.resolver; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.isMethod; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.Set; | ||
import net.bytebuddy.description.method.MethodDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import rocks.inspectit.gepard.agent.instrumentation.hook.configuration.MethodHookConfiguration; | ||
import rocks.inspectit.gepard.agent.internal.instrumentation.model.ClassInstrumentationConfiguration; | ||
import rocks.inspectit.gepard.agent.internal.instrumentation.model.rules.InstrumentationRule; | ||
import rocks.inspectit.gepard.config.model.instrumentation.rules.RuleTracingConfiguration; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class MethodHookConfigurationResolverTest { | ||
// TODO | ||
|
||
@Mock private MethodDescription methodDescription; | ||
|
||
@Mock private InstrumentationRule activeRule; | ||
|
||
@Mock private ClassInstrumentationConfiguration classConfiguration; | ||
|
||
private final MethodHookConfigurationResolver resolver = new MethodHookConfigurationResolver(); | ||
|
||
private final String methodName = "method"; | ||
|
||
private final ElementMatcher.Junction<MethodDescription> matcher = isMethod(); | ||
|
||
@BeforeEach | ||
void beforeEach() { | ||
when(methodDescription.getName()).thenReturn(methodName); | ||
when(activeRule.methodMatcher()).thenReturn(matcher); | ||
when(classConfiguration.activeRules()).thenReturn(Set.of(activeRule)); | ||
} | ||
|
||
@Test | ||
void shouldResolveConfigWithEnabledTracing() { | ||
RuleTracingConfiguration tracing = new RuleTracingConfiguration(true); | ||
|
||
when(methodDescription.isMethod()).thenReturn(true); | ||
when(activeRule.tracing()).thenReturn(tracing); | ||
|
||
MethodHookConfiguration hookConfig = resolver.resolve(methodDescription, classConfiguration); | ||
boolean tracingEnabled = hookConfig.tracing().getStartSpan(); | ||
|
||
assertEquals(methodName, hookConfig.methodName()); | ||
assertTrue(tracingEnabled); | ||
} | ||
|
||
@Test | ||
void shouldResolveConfigWithoutEnabledTracing() { | ||
RuleTracingConfiguration tracing = RuleTracingConfiguration.NO_TRACING; | ||
|
||
when(methodDescription.isMethod()).thenReturn(true); | ||
when(activeRule.tracing()).thenReturn(tracing); | ||
|
||
MethodHookConfiguration hookConfig = resolver.resolve(methodDescription, classConfiguration); | ||
boolean tracingEnabled = hookConfig.tracing().getStartSpan(); | ||
|
||
assertEquals(methodName, hookConfig.methodName()); | ||
assertFalse(tracingEnabled); | ||
} | ||
|
||
@Test | ||
void shouldResolveConfigWithoutEnabledTracingWhenNoRulesMatch() { | ||
when(methodDescription.isMethod()).thenReturn(false); | ||
|
||
MethodHookConfiguration hookConfig = resolver.resolve(methodDescription, classConfiguration); | ||
boolean tracingEnabled = hookConfig.tracing().getStartSpan(); | ||
|
||
assertEquals(methodName, hookConfig.methodName()); | ||
assertFalse(tracingEnabled); | ||
} | ||
} |
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
Oops, something went wrong.