@@ -172,4 +172,109 @@ public void testBuildPluginDownloadURI() {
172172 assertTrue (uri .contains ("/rest/v2/plugins/" ));
173173 assertTrue (uri .contains ("/download" ));
174174 }
175+
176+ @ Test
177+ public void testDeployPlugin_saveReturnsNull () {
178+ when (pluginDeployer .getPluginNames ()).thenReturn (java .util .Collections .emptySet ());
179+ doReturn (null ).when (adminApp ).savePluginZip (anyString (), any (InputStream .class ));
180+
181+ boolean result = adminApp .deployPlugin ("test-plugin" , new ByteArrayInputStream (new byte []{1 }));
182+ assertFalse (result );
183+ }
184+
185+ @ Test
186+ public void testUndeployPlugin_deletesZipFile () throws Exception {
187+ when (pluginDeployer .unloadPluginFromZip (eq ("test-plugin" ), any (File .class )))
188+ .thenReturn (new Result (true , "removed" ));
189+
190+ // Create a fake zip so the delete path is exercised
191+ File pluginsDir = adminApp .getPluginsDir ();
192+ File fakeZip = new File (pluginsDir , "test-plugin.zip" );
193+ fakeZip .createNewFile ();
194+ assertTrue (fakeZip .exists ());
195+
196+ boolean result = adminApp .undeployPlugin ("test-plugin" );
197+ assertTrue (result );
198+
199+ // The zip should be deleted
200+ assertFalse ("ZIP file should be deleted after undeploy" , fakeZip .exists ());
201+ }
202+
203+ @ Test
204+ public void testGetAllPluginNames_combinesRegistryAndDeployer () {
205+ when (pluginDeployer .getPluginNames ()).thenReturn (
206+ new java .util .HashSet <>(java .util .Arrays .asList ("hot-loaded-plugin" )));
207+
208+ java .util .List <String > names = adminApp .getAllPluginNames ();
209+ assertNotNull (names );
210+ assertTrue (names .contains ("hot-loaded-plugin" ));
211+ }
212+
213+ @ Test
214+ public void testGetAllPluginNames_noDeployer () {
215+ adminApp .setPluginDeployer (null );
216+ java .util .List <String > names = adminApp .getAllPluginNames ();
217+ assertNotNull (names );
218+ }
219+
220+ @ Test
221+ public void testGetPluginsDir_createsIfNotExists () {
222+ // Reset spy to use real getPluginsDir
223+ AdminApplication realApp = new AdminApplication ();
224+ System .setProperty ("red5.root" , System .getProperty ("java.io.tmpdir" ) + "/ams-dir-test-" + System .nanoTime ());
225+ File dir = realApp .getPluginsDir ();
226+ assertNotNull (dir );
227+ assertTrue (dir .exists ());
228+ assertTrue (dir .isDirectory ());
229+ dir .delete ();
230+ new File (System .getProperty ("red5.root" )).delete ();
231+ }
232+
233+ @ Test
234+ public void testDeployPluginWithURL_invalidName () {
235+ boolean result = adminApp .deployPluginWithURL ("../bad" , "http://example.com/test.zip" , "key" );
236+ assertFalse (result );
237+ }
238+
239+ @ Test
240+ public void testDeployPluginWithURL_downloadFails () throws Exception {
241+ doReturn (null ).when (adminApp ).downloadPluginZip (anyString (), anyString (), anyString ());
242+ boolean result = adminApp .deployPluginWithURL ("test-plugin" , "http://example.com/test.zip" , "key" );
243+ assertFalse (result );
244+ }
245+
246+ @ Test
247+ public void testDeployPluginWithURL_loadFails () throws Exception {
248+ File fakeZip = new File (adminApp .getPluginsDir (), "test.zip" );
249+ fakeZip .createNewFile ();
250+ doReturn (fakeZip ).when (adminApp ).downloadPluginZip (anyString (), anyString (), anyString ());
251+ when (pluginDeployer .loadPluginFromZip (any (File .class ), any (File .class )))
252+ .thenReturn (new Result (false , "bad manifest" ));
253+
254+ boolean result = adminApp .deployPluginWithURL ("test-plugin" , "http://example.com/test.zip" , "key" );
255+ assertFalse (result );
256+ fakeZip .delete ();
257+ }
258+
259+ @ Test
260+ public void testDeployPluginWithURL_success () throws Exception {
261+ File fakeZip = new File (adminApp .getPluginsDir (), "test.zip" );
262+ fakeZip .createNewFile ();
263+ doReturn (fakeZip ).when (adminApp ).downloadPluginZip (anyString (), anyString (), anyString ());
264+ when (pluginDeployer .loadPluginFromZip (any (File .class ), any (File .class )))
265+ .thenReturn (new Result (true , "ok" ));
266+
267+ boolean result = adminApp .deployPluginWithURL ("test-plugin" , "http://example.com/test.zip" , "key" );
268+ assertTrue (result );
269+ fakeZip .delete ();
270+ }
271+
272+ @ Test
273+ public void testDeployPluginWithURL_exceptionHandled () throws Exception {
274+ doThrow (new RuntimeException ("network error" )).when (adminApp )
275+ .downloadPluginZip (anyString (), anyString (), anyString ());
276+
277+ boolean result = adminApp .deployPluginWithURL ("test-plugin" , "http://example.com/test.zip" , "key" );
278+ assertFalse (result );
279+ }
175280}
0 commit comments