PageRenderTime 28ms CodeModel.GetById 11ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 1ms

/sigmah/src/test/java/org/sigmah/server/report/generator/SiteDataBinderTest.java

http://sigma-h.googlecode.com/
Java | 60 lines | 43 code | 13 blank | 4 comment | 0 complexity | 33eb04782437144182c91750b5d8a847 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.report.generator;
 7
 8import com.google.inject.Inject;
 9import org.junit.Assert;
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.domain.SiteData;
15import org.sigmah.shared.dao.SiteTableDAO;
16import org.sigmah.shared.domain.User;
17import org.sigmah.test.InjectionSupport;
18import org.sigmah.test.MockHibernateModule;
19import org.sigmah.test.Modules;
20
21import javax.persistence.EntityManager;
22import java.util.List;
23
24import static org.sigmah.shared.dao.Filter.filter;
25
26@RunWith(InjectionSupport.class)
27@Modules({MockHibernateModule.class})
28@OnDataSet("/dbunit/sites-simple1.db.xml")
29public class SiteDataBinderTest {
30
31    @Inject
32    private EntityManager em;
33
34    @Inject
35    private HibernateSiteTableDAO dao;
36
37    @Test
38    public void test() {
39
40        User owner = new User();
41        owner.setId(1);
42        
43        List<SiteData> sites = dao.query(owner,
44                filter().onSite(2),
45                null, new SiteDataBinder(), SiteTableDAO.RETRIEVE_ALL, 0, -1);
46
47        Assert.assertEquals("sites returned", 1, sites.size());
48
49        SiteData site = sites.get(0);
50
51        Assert.assertEquals("Ngshwe", site.getLocationName());
52        Assert.assertNull(site.getLocationAxe());
53        Assert.assertTrue("has coords", site.hasLatLong());
54        Assert.assertEquals(1.323, site.getLongitude(), 0.001);
55        Assert.assertEquals(28.232, site.getLatitude(), 0.001);
56        Assert.assertEquals("partner", "NRC", site.getPartnerName());
57        Assert.assertEquals("indicator 1", 3600, site.getIndicatorValue(1).intValue());
58        Assert.assertEquals("indicator 2", 1200, site.getIndicatorValue(2).intValue());
59    }
60}