PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/hippo/src/test/java/com/googlecode/hdbc/view/policy/ActiveExperimentsOutputPolicyTest.java

http://hdbc.googlecode.com/
Java | 46 lines | 35 code | 11 blank | 0 comment | 0 complexity | a546a047ed05ec0c4c5ce58915e1f7bc MD5 | raw file
 1package com.googlecode.hdbc.view.policy;
 2
 3import static org.junit.Assert.*;
 4
 5import java.util.ArrayList;
 6import java.util.HashMap;
 7import java.util.Map;
 8
 9import net.sf.json.JSONArray;
10import net.sf.json.JSONObject;
11
12import org.junit.Test;
13
14import com.googlecode.hdbc.controller.ModelAttributes;
15import com.googlecode.hdbc.model.factory.ExperimentDataFactory;
16import com.googlecode.hdbc.model.record.ExperimentData;
17
18public class ActiveExperimentsOutputPolicyTest {
19	private ExperimentDataFactory factory = new ExperimentDataFactory();
20	
21	@Test
22	public void testAnEmptyExperimentsList() {
23		Map<String, Object> model = new HashMap<String, Object>();
24		model.put(ModelAttributes.COLLECTION, new ArrayList<ExperimentData>());
25		
26		ActiveExperimentsOutputPolicy policy = new ActiveExperimentsOutputPolicy();
27		JSONObject jsn = (JSONObject) policy.customOutput(model);
28		String expected = "{\"data\":[]}";
29		assertEquals(expected, jsn.toString());
30	}
31	
32	@Test
33	public final void testAExperimentsListWithContents() {
34		Map<String, Object> model = new HashMap<String, Object>();
35		ArrayList<ExperimentData> exps = new ArrayList<ExperimentData>();
36		exps.add(factory.mkStdExperimentData());
37		exps.add(factory.mkStdExperimentData());
38		model.put(ModelAttributes.COLLECTION, exps);
39		
40		ActiveExperimentsOutputPolicy policy = new ActiveExperimentsOutputPolicy();
41		JSONObject jsn = (JSONObject) policy.customOutput(model);
42		
43		JSONArray data = jsn.getJSONArray("data");
44		assertEquals(2, data.size());
45	}
46}