-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #715 from bytedance/add-jvmprobe-ut
add JVMProbe unittest
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 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
68 changes: 68 additions & 0 deletions
68
rasp/jvm/JVMProbe/src/test/java/com/security/smith/SmithProbeTest.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,68 @@ | ||
import java.io.InputStream; | ||
import java.io.Reader; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.List; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
|
||
import com.security.smith.log.AttachInfo; | ||
import com.security.smith.log.SmithLogger; | ||
import com.esotericsoftware.yamlbeans.YamlReader; | ||
import com.security.smith.client.MessageSerializer; | ||
import com.security.smith.client.MessageDeserializer; | ||
import com.security.smith.client.MessageDecoder; | ||
import com.security.smith.client.MessageEncoder; | ||
import com.security.smith.type.SmithClass; | ||
import com.security.smith.type.SmithMethod; | ||
import com.security.smith.ruleengine.JsRuleEngine; | ||
import com.security.smith.SmithProbe; | ||
import com.security.smith.client.message.Heartbeat; | ||
import com.lmax.disruptor.dsl.Disruptor; | ||
import com.lmax.disruptor.EventFactory; | ||
import com.security.smith.client.message.Trace; | ||
import com.security.smith.SmithProbeProxy; | ||
import com.security.smith.client.Client; | ||
import com.security.smith.client.Rule_Config; | ||
import com.security.smith.client.Rule_Mgr; | ||
|
||
|
||
public class SmithProbeTest { | ||
|
||
@Test | ||
void testInit() { | ||
// Mock dependencies | ||
AttachInfo attachInfoMock = mock(AttachInfo.class); | ||
SmithLogger smithLoggerMock = mock(SmithLogger.class); | ||
MessageSerializer messageSerializerMock = mock(MessageSerializer.class); | ||
MessageEncoder messageEncoderMock = mock(MessageEncoder.class); | ||
MessageDecoder messageDecoderMock = mock(MessageDecoder.class); | ||
Heartbeat heartbeatMock = mock(Heartbeat.class); | ||
Client clientMock = mock(Client.class); | ||
Disruptor<Trace> disruptorMock = mock(Disruptor.class); | ||
Rule_Mgr ruleMgrMock = mock(Rule_Mgr.class); | ||
Rule_Config ruleConfigMock = mock(Rule_Config.class); | ||
SmithProbeProxy smithProbeProxyMock = mock(SmithProbeProxy.class); | ||
JsRuleEngine jsRuleEngineMock = mock(JsRuleEngine.class); | ||
|
||
// Create instance of the class under test | ||
SmithProbe yourClass = mock(SmithProbe.class); | ||
|
||
// Set up mocks | ||
when(yourClass.getHeartbeat()).thenReturn(heartbeatMock); | ||
when(yourClass.getClient()).thenReturn(clientMock); | ||
when(yourClass.getDisruptor()).thenReturn(disruptorMock); | ||
when(yourClass.getRuleMgr()).thenReturn(ruleMgrMock); | ||
when(yourClass.getRuleConfig()).thenReturn(ruleConfigMock); | ||
when(yourClass.getSmithProxy()).thenReturn(smithProbeProxyMock); | ||
when(yourClass.getJsRuleEngine()).thenReturn(jsRuleEngineMock); | ||
|
||
doNothing().when(yourClass).init(); | ||
|
||
|
||
} | ||
} |