-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! feat: add NoAppMap to control test-case recording
- Loading branch information
Showing
5 changed files
with
43 additions
and
54 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
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
32 changes: 32 additions & 0 deletions
32
agent/src/main/java/com/appland/appmap/process/hooks/test/TestSupport.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,38 @@ | ||
package com.appland.appmap.process.hooks.test; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import com.appland.appmap.output.v1.Event; | ||
import com.appland.appmap.process.hooks.RecordingSupport; | ||
import com.appland.appmap.process.hooks.RecordingSupport.TestDetails; | ||
import com.appland.appmap.record.Recorder; | ||
import com.appland.appmap.transform.annotations.AnnotationUtil; | ||
import com.appland.appmap.util.ClassUtil; | ||
|
||
class TestSupport { | ||
static final String TEST_RECORDER_TYPE = "tests"; | ||
|
||
public static void startRecording(Event event, Recorder.Metadata metadata) { | ||
startRecording(new TestDetails(event), metadata); | ||
} | ||
|
||
static void startRecording(TestDetails details, Recorder.Metadata metadata) { | ||
StackTraceElement[] stack = Thread.currentThread().getStackTrace(); | ||
// stack[0] is getStackTrace, stack[1] is startReording, stack[2] is the | ||
// hook method, so stack[3] is the test method: | ||
Method testMethod = ClassUtil.findMethod(stack[3]); | ||
|
||
if (!isRecordingEnabled(testMethod)) { | ||
return; | ||
} | ||
|
||
RecordingSupport.startRecording(details, metadata); | ||
} | ||
|
||
private static boolean isRecordingEnabled(Method testMethod) { | ||
String noAppMap = "com.appland.appmap.annotation.NoAppMap"; | ||
boolean methodAnnotated = AnnotationUtil.hasAnnotation(noAppMap, testMethod); | ||
boolean classAnnotated = AnnotationUtil.hasAnnotation(noAppMap, testMethod.getDeclaringClass()); | ||
return !methodAnnotated && !classAnnotated; | ||
} | ||
} |