1 | /** |
2 | * |
3 | */ |
4 | package de.uka.ipd.sdq.sensorframework.dao.file.test; |
5 | |
6 | import static org.junit.Assert.assertEquals; |
7 | |
8 | import java.util.ArrayList; |
9 | import java.util.List; |
10 | |
11 | import junit.framework.JUnit4TestAdapter; |
12 | |
13 | import org.junit.BeforeClass; |
14 | import org.junit.Test; |
15 | |
16 | import de.uka.ipd.sdq.sensorframework.SensorFrameworkDataset; |
17 | import de.uka.ipd.sdq.sensorframework.entities.Experiment; |
18 | import de.uka.ipd.sdq.sensorframework.entities.ExperimentRun; |
19 | import de.uka.ipd.sdq.sensorframework.entities.Measurement; |
20 | import de.uka.ipd.sdq.sensorframework.entities.Sensor; |
21 | import de.uka.ipd.sdq.sensorframework.entities.TimeSpanSensor; |
22 | import de.uka.ipd.sdq.sensorframework.entities.dao.IDAOFactory; |
23 | |
24 | /** TODO this test is not yet a part of a JUnit test suite |
25 | * @author Ihssane El-Oudghiri |
26 | * |
27 | */ |
28 | public class FileFactoryTest { |
29 | |
30 | static IDAOFactory f; |
31 | |
32 | @BeforeClass |
33 | public static void setUpBeforClass() { |
34 | f = SensorFrameworkDataset.singleton().getDataSourceByID(2); |
35 | Experiment e = f.createExperimentDAO().addExperiment("Test"); |
36 | ExperimentRun er1 = e.addExperimentRun("TestRun1"); |
37 | ExperimentRun er2 = e.addExperimentRun("TestRun2"); |
38 | TimeSpanSensor s1 = e.addTimeSpanSensor("ATimeSpanSensor1"); |
39 | TimeSpanSensor s2 = e.addTimeSpanSensor("ATimeSpanSensor2"); |
40 | |
41 | double[] m1s1 = new double[] { 1.0, 2.0, 3.0, 4.0, 5.0 }; |
42 | double[] m1s2 = new double[] { 1.5, 2.5, 3.5, 4.5, 5.5 }; |
43 | double[] m2s1 = new double[] { 2.0, 2.0, 3.0, 1.0, 0.0, 7.4 }; |
44 | |
45 | for (double d : m1s1) |
46 | er1.addTimeSpanMeasurement(s1, d, d); |
47 | for (double d : m1s2) |
48 | er1.addTimeSpanMeasurement(s2, d, d); |
49 | for (double d : m2s1) |
50 | er2.addTimeSpanMeasurement(s1, d, d); |
51 | |
52 | f.finalizeAndClose(); |
53 | } |
54 | |
55 | @Test |
56 | public void loadExperiment() { |
57 | // IDAOFactory f = |
58 | // SensorFrameworkDataset.singleton().getDataSourceByID(2); |
59 | Experiment e1 = f.createExperimentDAO().get(0); |
60 | Experiment e2 = new ArrayList<Experiment>(f.createExperimentDAO() |
61 | .findByExperimentName("Test")).get(0); |
62 | assertEquals("Test", e1.getExperimentName()); |
63 | assertEquals(0, e1.getExperimentID()); |
64 | assertEquals(2, e1.getSensors().size()); |
65 | assertEquals(2, e1.getExperimentRuns().size()); |
66 | assertEquals("ATimeSpanSensor1", ((List<Sensor>) e1.getSensors()) |
67 | .get(0).getSensorName()); |
68 | assertEquals("ATimeSpanSensor2", ((List<Sensor>) e1.getSensors()) |
69 | .get(1).getSensorName()); |
70 | assertEquals("TestRun1", ((List<ExperimentRun>) e1.getExperimentRuns()) |
71 | .get(0).getExperimentDateTime()); |
72 | assertEquals("TestRun2", ((List<ExperimentRun>) e1.getExperimentRuns()) |
73 | .get(1).getExperimentDateTime()); |
74 | |
75 | assertEquals("Test", e2.getExperimentName()); |
76 | assertEquals(0, e2.getExperimentID()); |
77 | assertEquals(2, e2.getSensors().size()); |
78 | assertEquals(2, e2.getExperimentRuns().size()); |
79 | assertEquals("ATimeSpanSensor1", ((List<Sensor>) e2.getSensors()) |
80 | .get(0).getSensorName()); |
81 | assertEquals("ATimeSpanSensor2", ((List<Sensor>) e2.getSensors()) |
82 | .get(1).getSensorName()); |
83 | assertEquals("TestRun1", ((List<ExperimentRun>) e2.getExperimentRuns()) |
84 | .get(0).getExperimentDateTime()); |
85 | assertEquals("TestRun2", ((List<ExperimentRun>) e2.getExperimentRuns()) |
86 | .get(1).getExperimentDateTime()); |
87 | |
88 | } |
89 | |
90 | @Test |
91 | public void loadMeasurements() { |
92 | // IDAOFactory f = |
93 | // SensorFrameworkDataset.singleton().getDataSourceByID(2); |
94 | Experiment e1 = f.createExperimentDAO().get(0); |
95 | Sensor s1 = ((List<Sensor>) e1.getSensors()).get(0); |
96 | Sensor s2 = ((List<Sensor>) e1.getSensors()).get(1); |
97 | |
98 | ExperimentRun r1 = ((List<ExperimentRun>) e1.getExperimentRuns()) |
99 | .get(0); |
100 | ExperimentRun r2 = ((List<ExperimentRun>) e1.getExperimentRuns()) |
101 | .get(1); |
102 | |
103 | List<Measurement> m1s1 = (List<Measurement>) r1 |
104 | .getMeasurementsOfSensor(s1).getMeasurements(); |
105 | assertEquals(5, m1s1.size()); |
106 | double e = 10e-9; |
107 | assertEquals(1.0, m1s1.get(0).getEventTime(), e); |
108 | assertEquals(2.0, m1s1.get(1).getEventTime(), e); |
109 | assertEquals(3.0, m1s1.get(2).getEventTime(), e); |
110 | assertEquals(4.0, m1s1.get(3).getEventTime(), e); |
111 | assertEquals(5.0, m1s1.get(4).getEventTime(), e); |
112 | |
113 | List<Measurement> m1s2 = (List<Measurement>) r1 |
114 | .getMeasurementsOfSensor(s2).getMeasurements(); |
115 | assertEquals(5, m1s1.size()); |
116 | assertEquals(1.5, m1s2.get(0).getEventTime(), e); |
117 | assertEquals(2.5, m1s2.get(1).getEventTime(), e); |
118 | assertEquals(3.5, m1s2.get(2).getEventTime(), e); |
119 | assertEquals(4.5, m1s2.get(3).getEventTime(), e); |
120 | assertEquals(5.5, m1s2.get(4).getEventTime(), e); |
121 | |
122 | List<Measurement> m2s1 = (List<Measurement>) r2 |
123 | .getMeasurementsOfSensor(s1).getMeasurements(); |
124 | assertEquals(6, m2s1.size()); |
125 | assertEquals(2.0, m2s1.get(0).getEventTime(), e); |
126 | assertEquals(2.0, m2s1.get(1).getEventTime(), e); |
127 | assertEquals(3.0, m2s1.get(2).getEventTime(), e); |
128 | assertEquals(1.0, m2s1.get(3).getEventTime(), e); |
129 | assertEquals(0.0, m2s1.get(4).getEventTime(), e); |
130 | assertEquals(7.4, m2s1.get(5).getEventTime(), e); |
131 | } |
132 | |
133 | @Test |
134 | public void addExperiment() { |
135 | f = SensorFrameworkDataset.singleton().getDataSourceByID(2); |
136 | Experiment e2 = f.createExperimentDAO().addExperiment("Test2"); |
137 | |
138 | assertEquals(2, f.createExperimentDAO().getExperiments().size()); |
139 | assertEquals(1, e2.getExperimentID()); |
140 | |
141 | f.createExperimentDAO().removeExperiment(e2, false); |
142 | assertEquals(1, f.createExperimentDAO().getExperiments().size()); |
143 | f.finalizeAndClose(); |
144 | |
145 | } |
146 | |
147 | public static junit.framework.Test suite() { |
148 | return new JUnit4TestAdapter(FileFactoryTest.class); |
149 | } |
150 | |
151 | } |