/*
 * JSPTem - use jsp's for all your templating!
 * Copyright (c) 2006, Paul Tuckey
 * All rights reserved.
 *
 * JSPTem is based on GNUJSP
 * Copyright (C) 1999, Yaroslav Faybishenko <yaroslav@cs.berkeley.edu>
 *
 * Each copy or derived work must preserve the copyright notice and this
 * notice unmodified.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
package org.tuckey.jsptem;

import com.sample.generated.GeneratedCustomerOrder;
import junit.framework.TestCase;

import javax.servlet.ServletException;
import java.io.File;
import java.io.IOException;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;

public class JspTemTest extends TestCase {

    public void testJspTem() throws IOException, ServletException {

        String emailShouldLookLike = "\n" +
                "Hi Bob,\n" +
                "\n" +
                "Items you ordered:\n" +
                "\n" +
                "    - French Stick\n" +
                "    - Apple\n" +
                "\n" +
                "\n" +
                "Regards,\n" +
                "Sample Company.";

        ByteArrayOutputStream myStream = new ByteArrayOutputStream();
        File myFile = new File("generated-src/sample-output.txt");

        GeneratedCustomerOrder customerOrderEmail = new GeneratedCustomerOrder();
        ArrayList items = new ArrayList();
        items.add("French Stick");
        items.add("Apple");
        customerOrderEmail.setItemsOrdered(items);
        customerOrderEmail.setName("Bob");

        // to a file
        customerOrderEmail.writeToFile(myFile);

        // to a string
        String orderEmail = customerOrderEmail.writeToString();

        // to a stream
        customerOrderEmail.writeToStream(myStream);

        assertEquals(emailShouldLookLike, orderEmail);
    }


}
