PageRenderTime 29ms CodeModel.GetById 17ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/sigmah/src/test/java/org/sigmah/server/endpoint/gwtrpc/PartnerTest.java

http://sigma-h.googlecode.com/
Java | 70 lines | 48 code | 18 blank | 4 comment | 0 complexity | 10941a774a612480ed605e773683f611 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.endpoint.gwtrpc;
 7
 8import org.junit.Assert;
 9import org.junit.Test;
10import org.junit.runner.RunWith;
11import org.sigmah.server.dao.OnDataSet;
12import org.sigmah.shared.command.AddPartner;
13import org.sigmah.shared.command.GetSchema;
14import org.sigmah.shared.command.result.CreateResult;
15import org.sigmah.shared.dto.PartnerDTO;
16import org.sigmah.shared.dto.SchemaDTO;
17import org.sigmah.shared.exception.DuplicateException;
18import org.sigmah.test.InjectionSupport;
19
20@RunWith(InjectionSupport.class)
21@OnDataSet("/dbunit/sites-simple1.db.xml")
22public class PartnerTest extends CommandTestCase {
23    public static final int PEAR_PLUS_DB_ID = 2;
24    public static final int SOL_ID = 2;
25
26
27    @Test
28    public void testAddPartner() throws Exception {
29        PartnerDTO newPartner = new PartnerDTO();
30        newPartner.setName("Solidarites");
31
32        CreateResult cr = execute(new AddPartner(PEAR_PLUS_DB_ID, newPartner));
33
34        Assert.assertEquals(SOL_ID, cr.getNewId());
35
36        SchemaDTO schema = execute(new GetSchema());
37        PartnerDTO partner = schema.getDatabaseById(PEAR_PLUS_DB_ID).getPartnerById(SOL_ID);
38
39        Assert.assertNotNull(partner);
40        Assert.assertEquals(newPartner.getName(), partner.getName());
41    }
42
43    @Test
44    public void testAddNewPartner() throws Exception {
45        PartnerDTO newPartner = new PartnerDTO();
46        newPartner.setName("VDE");
47        newPartner.setFullName("Vision d'Espoir");
48
49        CreateResult cr = execute(new AddPartner(1, newPartner));
50
51
52        SchemaDTO schema = execute(new GetSchema());
53        PartnerDTO partner = schema.getDatabaseById(1).getPartnerById(cr.getNewId());
54
55        Assert.assertNotNull(partner);
56        Assert.assertEquals("VDE", partner.getName());
57        Assert.assertEquals("Vision d'Espoir", partner.getFullName());
58
59    }
60
61
62    @Test(expected = DuplicateException.class)
63    public void testAddDuplicatePartner() throws Exception {
64        PartnerDTO newPartner = new PartnerDTO();
65        newPartner.setName("NRC");
66        newPartner.setFullName("Norweigen Refugee Committe");
67
68        CreateResult cr = execute(new AddPartner(1, newPartner));
69    }
70}