PageRenderTime 23ms CodeModel.GetById 13ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/sigmah/src/test/java/org/sigmah/server/servlet/ExportIntegrationTest.java

http://sigma-h.googlecode.com/
Java | 77 lines | 52 code | 18 blank | 7 comment | 2 complexity | 8596573e177ecd06419a44f70035faef MD5 | raw file
 1/*
 2 * All Sigmah code is released under the GNU General Public License v3
 3 * See COPYRIGHT.txt and LICENSE.txt.
 4 */
 5
 6package org.sigmah.server.servlet;
 7
 8import com.google.inject.Inject;
 9import org.hibernate.ejb.HibernateEntityManager;
10import org.junit.Test;
11import org.junit.runner.RunWith;
12import org.sigmah.server.dao.OnDataSet;
13import org.sigmah.server.dao.hibernate.HibernateSiteTableDAO;
14import org.sigmah.server.endpoint.export.Export;
15import org.sigmah.server.endpoint.gwtrpc.CommandTestCase;
16import org.sigmah.shared.command.GetSchema;
17import org.sigmah.shared.command.handler.GetSchemaHandler;
18import org.sigmah.shared.dao.SQLDialect;
19import org.sigmah.shared.dao.SiteTableDAO;
20import org.sigmah.shared.domain.User;
21import org.sigmah.shared.dto.ActivityDTO;
22import org.sigmah.shared.dto.SchemaDTO;
23import org.sigmah.shared.dto.UserDatabaseDTO;
24import org.sigmah.test.InjectionSupport;
25
26import javax.persistence.EntityManager;
27import javax.persistence.EntityManagerFactory;
28import java.io.File;
29import java.io.FileOutputStream;
30
31/**
32 * @author Alex Bertram
33 */
34@RunWith(InjectionSupport.class)
35@OnDataSet("/dbunit/sites-simple1.db.xml")
36public class ExportIntegrationTest extends CommandTestCase {
37
38    @Inject
39    private EntityManagerFactory emf;
40
41    @Inject
42    private SQLDialect dialect;
43
44    @Inject
45    private GetSchemaHandler getSchemaHandler;
46
47
48    @Test
49    public void fullTest() throws Throwable {
50
51
52        User user = new User();
53        user.setId(1);
54        user.setName("Alex");
55
56        EntityManager em = emf.createEntityManager();
57        SchemaDTO schema = (SchemaDTO) getSchemaHandler.execute(new GetSchema(), user);
58        SiteTableDAO siteDAO = new HibernateSiteTableDAO((HibernateEntityManager)em, dialect);
59
60        Export export = new Export(user, siteDAO);
61        for (UserDatabaseDTO db : schema.getDatabases()) {
62            for (ActivityDTO activity : db.getActivities()) {
63                export.export(activity);
64            }
65        }
66
67        File outputDir = new File("target/report-test/");
68        outputDir.mkdirs();
69
70        FileOutputStream fos = new FileOutputStream("target/report-test/ExportTest.xls");
71        export.getBook().write(fos);
72        fos.close();
73
74    }
75
76
77}