ExportRecipeTest.java 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* ===================================================================
  2. * ExportRecipeTest.java
  3. *
  4. * Created Feb 24, 2005 11:23:24 AM
  5. *
  6. * Copyright (c) 2005 Matt Magoffin (spamsqr@msqr.us)
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  21. * 02111-1307 USA
  22. * ===================================================================
  23. * $Id: ExportRecipeTest.java 60 2009-05-11 09:18:28Z msqr $
  24. * ===================================================================
  25. */
  26. package magoffin.matt.ieat.biz.test;
  27. import java.io.ByteArrayOutputStream;
  28. import java.util.Locale;
  29. import magoffin.matt.ieat.biz.BizContext;
  30. import magoffin.matt.ieat.biz.RecipeIOBiz;
  31. import magoffin.matt.ieat.domain.Recipe;
  32. import magoffin.matt.ieat.test.AbstractSpringEnabledTest;
  33. /**
  34. * Test case for exporting a recipe.
  35. *
  36. * @author Matt Magoffin (spamsqr@msqr.us)
  37. * @version $Revision: 60 $ $Date: 2009-05-11 21:18:28 +1200 (Mon, 11 May 2009) $
  38. */
  39. public class ExportRecipeTest extends AbstractSpringEnabledTest {
  40. /**
  41. * Test exporting.
  42. *
  43. * @throws Exception if any error occurs
  44. */
  45. public void testExport() throws Exception {
  46. doTestWithRecipe(new TestWithRecipe() {
  47. public void test(Recipe recipe, BizContext context) throws Exception {
  48. RecipeIOBiz rioBiz = getRecipeIOBiz();
  49. String[] formats = rioBiz.getSupportedExportFormats();
  50. assertNotNull("The supported formats array should not be null.", formats);
  51. for ( int i = 0; i < formats.length; i++ ) {
  52. String format = formats[i];
  53. ByteArrayOutputStream out = new ByteArrayOutputStream();
  54. rioBiz.exportRecipe(recipe, Locale.getDefault(), out, format);
  55. assertTrue("The recipe should export somethihng", out.size() > 0);
  56. if ( log.isDebugEnabled() ) {
  57. log.debug("Exported recipe as:\n" +out.toString());
  58. }
  59. }
  60. }
  61. });
  62. }
  63. /**
  64. * @return the RecipeIOBiz
  65. */
  66. protected RecipeIOBiz getRecipeIOBiz() {
  67. return (RecipeIOBiz)getContext().getBean("recipeIOBiz");
  68. }
  69. }