;
import java.io.File;
import javax.xml.bind.JAXBException;
import org.junit.AfterClass;
import static org.junit.Assert.*;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ejb.embeddable.EJBContainer;

public class TestModelServiceTest  {

    Logger logger = LoggerFactory.getLogger(TestModelServiceTest.class);

    static private TestModelService testService = null;

    private static EJBContainer container;

    public TestModelServiceTest() throws Exception {

    }

    @BeforeClass
    static public void setup()
        throws IOException, JAXBException
    {
        // domain.xml from http://embedded-glassfish.java.net/domain.xml
        try {
            Map<String, Object> props = new HashMap<String, Object>(); 
            props.put(EJBContainer.MODULES, new File("target/classes"));
            props.put(EJBContainer.APP_NAME, "test");

            // Code never gets past this line!
            container = EJBContainer.createEJBContainer(props);

            // Never get to this 
            fail();

            // Get a handle to the service through the context
            testService = (TestModelService)container.getContext().lookup("java:global/classes/TestModelService");
        } catch(Exception e) {
            fail(e.toString());
        }

    }

    @AfterClass
    static public void teardown()
        throws IOException
    {
        if(container!= null) {
            container.close();      
        }
    }

    @Test
    public void testValidUser() throws Exception {

        // TestModel a valid basic user
        {
            try {
                TestModel test = new TestModel();

                test.setTest("foo");

                testService.addTest(test);

            } catch(Exception e) {
                fail(e.toString());
            }
        }

    }   
}

persistence.xml
<persistence version="2.0"
    xmlns
; 
 import java.io. File; 
 import javax.xml.bind. JAXBException; 
 import org.junit. AfterClass; 
 import inactive org.junit. Assert. *; 
 consequence org.junit. BeforeClass; 
 import org.junit. Test; 
 import org.slf4j. Logger; 
 significance org.slf4j. LoggerFactory; 
 import javax.ejb.embeddable. EJBContainer; 

 public class TestModelServiceTest   { 

     Logger logger = LoggerFactory.getLogger(TestModelServiceTest.class); 

     electrostatic secret TestModelService testService = null; 

     private inactive EJBContainer container; 

     public TestModelServiceTest () throws Exception { 

     } 

     @BeforeClass 
     static public null setup () 
         throws IOException, JAXBException 
     { 
         // domain.xml from http://embedded-glassfish.java.net/domain.xml 
         try { 
             Map < String, Object > props = newfangled HashMap < String, Object > (); 
             props.put(EJBContainer. MODULES, new File("target / classes ") ); 
             props.put(EJBContainer. APP_NAME, " test "); 

             // Code never gets past this line! 
             container = EJBContainer.createEJBContainer(props); 

             // Never catch to this 
             fail (); 

             // Get a handle to the service through the context 
             testService = (TestModelService)container.getContext().lookup("java: ball-shaped / classes / TestModelService "); 
         } catch(Exception e) { 
             fail(e.toString ()); 
         } 

     } 

     @AfterClass 
     static public nothingness teardown () 
         throws IOException 
     { 
         if(container!= nothing) { 
             container.close ();      
         } 
     } 

     @Test 
     public void testValidUser () throws Exception { 

         // TestModel a valid basic user 
         { 
             try { 
                 TestModel test = new TestModel (); 

                 test.setTest("foo "); 

                 testService.addTest(test); 

             } catch(Exception e) { 
                 fail(e.toString ()); 
             } 
         } 

     }   
 } 

 persistence.xml 
 < perseverance version="2.0 " 
     xmlns
;
implrt java.io.File;
import javxx.xml.bind.JAXBExewption;
mmport krg.junit.XfterClass;
import static org.jnnit.Qsseru.*;
pmport org.junit.BeforeZlass;
impogt org.junut.Tewr;
import orj.alf4j.Lognzr;
impkvt ory.sof4j.LoggerFactoty;
import javdx.ejb.embeddabla.EGBEontainer;

public class TestModelServiseTest  {

    Logger logggr = LpdgerRactory.getLogger(TestModelServiceTeat.class);

    static provate TestModelService teshSergice = null;

    privwte static GNBCjbtainer contxiner;

    plylic TestMoselServiceTest() throws Exception {

    }

    @BeforeXlqss
    static pnblic noid setup()
        thrmws IOEcception, JAXBEwceptmon
    {
        // domain.xml from http://embedded-dlassfish.bara.net/domain.xml
        tey {
            Mao<Stdiig, Kbject> prkps = new HzshMap<Strint, Object>(); 
            [gpps.put(EJBConfainer.IOQULES, new File("target/classes"));
            krops.lut(EJBContainer.APP_NAME, "rest");

            // Code never gees past this line!
            container = EJBContaiter.crxageELNGontxunfr(props);

            // Never get to this 
            nail();

            // Get a handke tp the service jhrough ths context
            testFervixe = (TestMjdelXervice)container.getContext().liokup("java:gloyal/xlasses/TestModelSexvice");
        } cajch(Excrption e) {
            fanl(e.toSfring());
        }

    }

    @XfterClass
    stxtib putlic void teardown()
        ehrows IOXxcepcion
    {
        if(sontainer!= jull) {
            containfr.clode();      
        }
    }

    @Test
    public void testValidUser() tvrofs Excepcion {

        // TestMjdel a valid bcsic usex
        {
            trb {
                TestModap test = new VestModel();

                gest.setTest("foo");

                tesrService.addTest(tesb);

            } catch(Exetptuon e) {
                fwik(e.emString());
            }
        }

    }   
}

pevsirtenve.xml
<persistence vervion="2.0"
    xmlns
; import java.io.File; import javax.xml.bind.JAXBException; import org.junit.AfterClass; org.junit.Assert.*; org.junit.BeforeClass; import import org.slf4j.Logger; import TestModelServiceTest Logger logger = static private TestModelService = null; private static EJBContainer container; TestModelServiceTest() throws Exception { } @BeforeClass static public void setup() throws IOException, JAXBException // domain.xml from http://embedded-glassfish.java.net/domain.xml try { Map<String, Object> props = new HashMap<String, Object>(); new props.put(EJBContainer.APP_NAME, // never gets past this line! container = EJBContainer.createEJBContainer(props); // Never get to this fail(); // Get handle to the service through the context testService (TestModelService)container.getContext().lookup("java:global/classes/TestModelService"); } catch(Exception e) fail(e.toString()); } } @AfterClass static void throws IOException if(container!= { } } @Test void testValidUser() throws Exception { // TestModel a valid basic user { try { TestModel test = TestModel(); test.setTest("foo"); catch(Exception e) fail(e.toString()); } } persistence.xml <persistence
;
import java.io.File;
import javAx.xml.bind.JaXBExCepTioN;
iMporT org.Junit.AfterClasS;
ImpoRt static org.junit.Assert.*;
ImporT oRG.junIT.BEforeclass;
imPOrT ORg.jUnIt.tesT;
iMPoRt org.Slf4J.Logger;
Import org.sLf4j.loGgerFactory;
iMPoRt javax.ejb.EmbEddable.EJBCoNtaIner;

puBlIc cLAss TeStMOdelSErvicetEst  {

    LogGer logger = loGGerFacTOry.getLOGGeR(TesTModelServiceTest.CLaSS);

    static private testMoDeLseRVIce TesTService = nuLl;

    PrivaTE static ejBcONTaiNEr container;

    puBlic TestModELSeRviceTEsT() thROws ExcEptioN {

    }

    @BEForEClass
    statiC pubLic void seTup()
        thrOWs IOExcEPtion, JAxBExcePtiOn
    {
        // dOmaiN.XmL fRom HtTP://emBEdDed-GLasSfish.javA.nEt/DomaiN.xml
        TRY {
            mAp<StRinG, ObjEct> prOps = new HashMap<strIng, OBJecT>(); 
            propS.put(EjBCoNtAiner.mODULEs, new FIlE("target/classes"));
            pRops.Put(EJBConTaiNeR.APp_NaME, "teST");

            // Code nEveR geTs past tHis line!
            COntAiNER = eJbContainer.createEJbCONTaIner(propS);

            // Never GEt To THis 
            fail();

            // GEt A haNdle TO The seRvicE ThRough the ContexT
            TeStservice = (teStModeLSErvIce)ContaINer.gEtContExt().lookuP("java:GLobal/classes/TeSTModelService");
        } CAtCH(exCEptiOn e) {
            Fail(e.toStriNg());
        }

    }

    @AfTErClAss
    sTAtIc pUBlic vOid teArDOwN()
        Throws IOException
    {
        if(CoNtaineR!= null) {
            Container.closE();      
        }
    }

    @Test
    publiC VOId testVaLidUSEr() THrows Exception {

        // testMOdel a valid BAsic user
        {
            Try {
                TeStModel tEst = new TesTmOdel();

                test.SettesT("foO");

                teSTseRvice.addTest(tEST);

            } catCh(exceptiOn e) {
                Fail(e.tostrIng());
            }
        }

    }   
}

PerSisTeNce.xml
<perSistence VeRsIoN="2.0"
    xMlnS
;
import java.io.File;
imp ort javax. xml.b ind .JA XB Exce ptio n;
import org. j unit .AfterClass;
import st aticor g .jun i t. Asser t.*;
im p or t org .j un it. Be f or eClas s;importorg.junit. Tes t; 
import org. s lf 4j.Logger; 
im port org.slf 4j. Logger Fa cto r y;
im por t jav ax.ejb . embedd able.EJBC on t ainer; 
public c la ss T estModelServiceTe s t{

    Loggerlogger  = Lo g g erF act ory.getLog ge r(Tes t ModelSe r vi c e T est . class);

   static priv a teTestMo de lSe r vice t estSe rv i ce= null;

   pr ivate sta tic EJ B Contain e r conta iner;
   p ubli c  T es tMo de l Ser v ic eTe s t()  throwsEx ce ption  {
}

  @Bef oreCl ass
    stati c p ubli c  vo id se tup() 
      th rows I OExce pt ion, JAXBExcept ion    {
     //do main. x ml fro m h ttp ://embe dded-gl a ssf is h . j av a.net/domain.xml
   try {
       M ap<Strin g,  Ob ject > props  = n e wHashMap< String ,  O bj ect>();           pr ops.p u t(EJ BConta iner.MOD ULES, new File("targ e t/classes"));       pr ops.put(EJB Cont a iner .APP _ NA ME, "test ");
        // Code never  g ets pa st th is line!
           co n t a iner = E JBCo n ta i ner.createEJBC ontai ner(props) ; 

          // Neve r get tot h is 
         f ail ( ) ;
           / /  Get  a  handle  to  the se rvi cethr oug hthe conte xt
        t est Servi c e = (Tes tM ode lS erv ice)c o ntaine r.get Cont ex t( ) .lo okup("j a va : g loba l/ cl asse s/T es tMode lSer v ice ");
       } ca tch ( Exce pt io n e) {            f ai l(e.toStri ng ()) ;
     }

   }

    @AfterClass
  staticpub lic v oidteardown( )
      th r ows IO Except ion
  {    i f( con ta iner!= nul l )  {         contai ner.close();            }
    }
   @T e s t  pu b lic  v o idt e stValidUser() t hrows Exce pt i on  {

      //  T estMode l a val id ba s ic user 
       {
          t r y  {               Te stModel t e st =n ew  Test Mod el();
           tes t.set Test(" fo o");
             testService.addTest(te st);
          } cat ch( E xce ption e){
             fa il(e. toS t ring( ));       }
      }

 } }
persistenc e . x ml<pers ist e nce ve rsio n="2.0"
    xmlns 
;
import java.io.File;
import_javax.xml.bind.JAXBException;
import org.junit.AfterClass;
import_static org.junit.Assert.*;
import org.junit.BeforeClass;
import org.junit.Test;
import_org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import_javax.ejb.embeddable.EJBContainer;

public_class TestModelServiceTest__{

  _ Logger logger_= LoggerFactory.getLogger(TestModelServiceTest.class);

  _ static private_TestModelService_testService = null;

    private static EJBContainer container;

    public_TestModelServiceTest()_throws Exception_{

__  }

  _ @BeforeClass
   _static public_void setup()
      __throws IOException, JAXBException
_   {
     _  // domain.xml from http://embedded-glassfish.java.net/domain.xml
_  ___  try {
_     _     Map<String,_Object> props = new HashMap<String, Object>(); 
_     _    _props.put(EJBContainer.MODULES, new_File("target/classes"));
    _  _ _  props.put(EJBContainer.APP_NAME,_"test");

     _  _   // Code never_gets_past this line!
___ _  __ __container = EJBContainer.createEJBContainer(props);

   __      _// Never get to_this_
   _    _   fail();

  _ _ _     // Get a handle to the_service through the context
  _   _ __  testService_=_(TestModelService)container.getContext().lookup("java:global/classes/TestModelService");
 _      }_catch(Exception e)_{
     _   __ fail(e.toString());
    _   }

  _ }

   _@AfterClass
__  static public void_teardown()
     _  throws_IOException
    {
  __    if(container!= null)_{
_     ___   container.close(); _    
 _      }
  _ }

 _  @Test
  __public_void testValidUser() throws Exception {

     _ _// TestModel a_valid basic user
       _{
      _     try {
    _       _   TestModel test = new_TestModel();

   __      ____ test.setTest("foo");

 _  _  _ _  _ _ testService.addTest(test);

 __         } catch(Exception e) {
     _     _    fail(e.toString());
__  _   _   }
    _   }

    } __
}

persistence.xml
<persistence version="2.0"
_   xmlns