Concetto: Test AUnit
AUnit è un framework di test di Workday Studio che consente di sviluppare ed eseguire unit test per gli assembly. È possibile sviluppare test AUnit in Java utilizzando strutture di test create nei progetti di assembly. Gli schemi di struttura dei test Aunit supportano le seguenti funzionalità:
- Azioni
- Annotazioni
- Asserzioni
È possibile utilizzare queste funzionalità per creare test case per gli assembly.
Esempio:
package com.workday.training.aunit; import java.io.InputStream; import com.workday.aunit.AssemblyTestCase; import com.workday.aunit.actions.Action; import com.workday.aunit.actions.StandardAction; import com.workday.aunit.annotations.AssemblyTest; import com.workday.aunit.annotations.AssertAfter; import com.workday.aunit.annotations.AtComponent; import com.workday.aunit.annotations.UnitTest; @AssemblyTest(project = "AUnitTrainer", displayLabel = "Citizens of the Cloud") public class SimpleMediationTest extends AssemblyTestCase { @UnitTest(startComponent = "Simple-Mediation") public void testSimpleMediation() throws Exception { setMessagePart(0, "test/simple-input.xml", "text/xml"); } // Using the @AssertAfter annotation and the assertTrue assertion. // @AssertAfter(id = "Simple-Mediation", step="transform") public void verifySimpleMediation() throws Exception { assertTrue(compare( getTestResourceInputStream("test/simple-expected.xml"), "text/xml", (InputStream) getMediationContext().getMessage().getMessagePart(0, InputStream.class), "text/xml", Comparator.dom)); } @AtComponent(id="Next-Thing") public Action handleAfterMediation() throws Exception { return new StandardAction(Action.Type.terminate); } }
Annotazioni
Tutti i test unitari devono contenere un
@AssemblyTest
annotazione Questa annotazione identifica il test AUnit e consente di associare il test al progetto di assieme. Esempio:
@AssemblyTest(project = "AUnitTrainer")
Le annotazioni nei metodi di test definiscono il punto di partenza per uno unit test nella catena di elaborazione dell'assembly. Esempio:
@UnitTest(startComponent = "Simple-Mediation")
Asserzioni
Le asserzioni definiscono le condizioni di test booleane. Se un'asserzione non riesce, AUnit interrompe l'esecuzione dell'assembly e visualizza il risultato del test come errore. Se si verifica un'eccezione imprevista, AUnit interrompe l'esecuzione dell'assembly e visualizza il risultato del test come errore.
Esempio: l'esempio seguente utilizza un
@AssertAfter
annotazione e un assertTrue
per verificare se la parte del messaggio radice contiene l'XML previsto dopo l'esecuzione della mediazione.
@AssertAfter(id = "Simple-Mediation", step="transform") public void verifySimpleMediation() throws Exception { assertTrue(compare( getTestResourceInputStream("test/simple-expected.xml"), "text/xml", (InputStream) getMediationContext().getMessage().getMessagePart(0, InputStream.class), "text/xml", Comparator.dom)); }
Azioni
Le azioni definiscono i comportamenti del test AUnit quando l'esecuzione dell'assembly raggiunge un componente o un punto di uscita. Esempio:
@AtComponent(id="Next-Thing") public Action handleAfterMediation() throws Exception { return new StandardAction(Action.Type.terminate); }