package org.gbif.checklistbank.ws.resources;

import java.security.Permission;

import org.gbif.ws.app.Application;
import org.junit.Test;

import static org.junit.Assert.fail;


public class WsAppTest {

  /**
   * Test the startup of the webapp.
   * We expect a SecurityException raised as the Application stops because of missing configs.
   * But no NoSuchMethodError thrown by incompatible jackson we see with a wrong version introduced by solr
   */
  @Test(expected = SecurityException.class)
  public void testWsStartup() {
    // throw exception if Application exits
    System.setSecurityManager(new NoExitSecurityManager());
    Application.main(new String[]{});
  }

  private static class NoExitSecurityManager extends SecurityManager {
    @Override
    public void checkPermission(Permission perm) {
      // allow anything.
    }
    @Override
    public void checkPermission(Permission perm, Object context) {
      // allow anything.
    }

    @Override
    public void checkExit(int status) {
      super.checkExit(status);
      throw new SecurityException("Exit status " + status + " called");
    }
  }
}

@@ -109,16 +109,65 @@
 cation;%0A
+import org.junit.After;%0Aimport org.junit.Before;%0A
 import o
@@ -245,16 +245,256 @@
 ppTest %7B
+%0A  private SecurityManager sm;%0A%0A  @Before%0A  public void init()%7B%0A    sm = System.getSecurityManager();%0A    System.setSecurityManager(new NoExitSecurityManager());%0A  %7D%0A%0A  @After%0A  public void shutdown()%7B%0A    System.setSecurityManager(sm);%0A  %7D
 %0A%0A  /**%0A
@@ -547,24 +547,20 @@
 xpect a 
-Secur
+Ex
 it
-y
 Exceptio
@@ -754,24 +754,20 @@
 ected = 
-Secur
+Ex
 it
-y
 Exceptio
@@ -815,145 +815,204 @@
     
-// throw exception if Application exits%0A    System.setSecurityManager(new NoExitSecurityManager());%0A    Application.main(new String%5B%5D%7B%7D);
+Application.main(new String%5B%5D%7B%7D);%0A  %7D%0A%0A  public static class ExitException extends RuntimeException %7B%0A    public ExitException(int status) %7B%0A      super(%22Exit status %22 + status + %22 called%22);%0A    %7D
 %0A  %7D
@@ -1394,24 +1394,20 @@
 row new 
-Secur
+Ex
 it
-y
 Exceptio
@@ -1412,43 +1412,14 @@
 ion(
-%22Exit status %22 + status + %22 called%22
+status
 );%0A 

Remove custom security manager after test finishes