-
Notifications
You must be signed in to change notification settings - Fork 639
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 #6156 from ant-media/fix/appCreation
Handle exception in App Creation
- Loading branch information
Showing
4 changed files
with
86 additions
and
30 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
51 changes: 51 additions & 0 deletions
51
src/test/java/org/red5/server/tomcat/TomcatLoaderTest.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,51 @@ | ||
package org.red5.server.tomcat; | ||
|
||
import jakarta.servlet.ServletContext; | ||
import jakarta.servlet.ServletException; | ||
import org.apache.catalina.Container; | ||
import org.apache.catalina.Context; | ||
import org.apache.catalina.Host; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class TomcatLoaderTest { | ||
|
||
/** | ||
* This Test checks handling of parse exception while creation | ||
* Previously if there is a parse exception while creating tomcat, it was not handled | ||
* and it cannot create any application after that exception | ||
*/ | ||
@Test | ||
public void testHandleParseException() { | ||
TomcatLoader tomcatLoader = spy(new TomcatLoader()); | ||
Host host = mock(Host.class); | ||
when(host.getName()).thenReturn("localhost"); | ||
|
||
Context context = mock(Context.class); | ||
try { | ||
doReturn(context).when(tomcatLoader).addContext(any(), any()); | ||
} catch (ServletException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
ServletContext servletContext = mock(ServletContext.class); | ||
when(context.getServletContext()).thenReturn(servletContext); | ||
|
||
when(servletContext.getRealPath("/")).thenThrow(new IllegalStateException("Parse Exception")); | ||
|
||
tomcatLoader.setBaseHost(host); | ||
|
||
final ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); | ||
|
||
try { | ||
//normally it didn't return in the bug case | ||
assertFalse(tomcatLoader.startWebApplication("test")); | ||
assertEquals(originalClassLoader, Thread.currentThread().getContextClassLoader()); | ||
} catch (ServletException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |