Skip to content

Commit

Permalink
fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
USAMAWIZARD committed Jan 30, 2025
1 parent 271efcd commit 78b3317
Showing 1 changed file with 46 additions and 25 deletions.
71 changes: 46 additions & 25 deletions src/test/java/org/red5/server/stream/StreamServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,56 +21,66 @@
import static org.mockito.internal.util.MockUtil.resetMock;

public class StreamServiceTest {


//Start writing test codes for StreamService because we're encountering problems here time to time.

@Test
public void testPublishMetaData() {


StreamService streamService = Mockito.spy(new StreamService());


String streamId = "stream123";
String param = "token=12345";
String name = streamId + "?" + param;

IStreamCapableConnection connection = Mockito.mock(IStreamCapableConnection.class);
IScope scope = Mockito.mock(IScope.class);
Mockito.when(connection.getScope()).thenReturn(scope);


Map<String, Object> mockMap = Mockito.mock(Map.class);
Object customObject = new Object() {
@Override
public String toString() {
return streamId;
}
};
Mockito.doReturn(customObject).when(mockMap).get("path");
Mockito.doReturn(mockMap).when(connection).getConnectParams();

IContext context = Mockito.mock(IContext.class);
Mockito.when(scope.getContext()).thenReturn(context);

ApplicationContext appContext = Mockito.mock(ApplicationContext.class);
Mockito.when(context.getApplicationContext()).thenReturn(appContext);

IStreamSecurityService securityService = Mockito.mock(IStreamSecurityService.class);

Mockito.when(appContext.containsBean(IStreamSecurityService.BEAN_NAME)).thenReturn(true);
Mockito.when(appContext.getBean(IStreamSecurityService.BEAN_NAME)).thenReturn(securityService);


Set<IStreamPublishSecurity> publishSecuritySet = new HashSet<>();
IStreamPublishSecurity publishSecurity = Mockito.mock(IStreamPublishSecurity.class);

IStreamPublishSecurity publishSecurity = Mockito.mock(IStreamPublishSecurity.class);
Mockito.when(publishSecurity.isPublishAllowed(any(), any(), any(), any(), any())).thenReturn(false);

publishSecuritySet.add(publishSecurity);

Mockito.when(securityService.getStreamPublishSecurity()).thenReturn(publishSecuritySet);


Red5.setConnectionLocal(connection);

Mockito.doNothing().when(streamService).sendNSFailed(any(), any(), any(), any(), any());

streamService.publish(name, null);


Mockito.verify(streamService).sendNSFailed(any(), any(), any(), any(), any());

}

@Test
Expand All @@ -94,6 +104,16 @@ public void testPublishUrlSegmentParams() {

Mockito.when(connection.newBroadcastStream(any())).thenReturn(bs);

Map<String, Object> mockMap = Mockito.mock(Map.class);
Object customObject = new Object() {
@Override
public String toString() {
return "streamid";
}
};
Mockito.doReturn(customObject).when(mockMap).get("path");
Mockito.doReturn(mockMap).when(connection).getConnectParams();

IContext context = Mockito.mock(IContext.class);
Mockito.when(scope.getContext()).thenReturn(context);

Expand Down Expand Up @@ -131,4 +151,5 @@ public void testPublishUrlSegmentParams() {

}


}

0 comments on commit 78b3317

Please sign in to comment.