1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
package net.sourceforge.subsonic.dao;
import java.util.List;
import net.sourceforge.subsonic.domain.Player;
import net.sourceforge.subsonic.domain.Transcoding;
/**
* Unit test of {@link TranscodingDao}.
*
* @author Sindre Mehus
*/
public class TranscodingDaoTestCase extends DaoTestCaseBase {
@Override
protected void setUp() throws Exception {
getJdbcTemplate().execute("delete from transcoding2");
}
public void testCreateTranscoding() {
Transcoding transcoding = new Transcoding(null, "name", "sourceFormats", "targetFormat", "step1", "step2", "step3", false);
transcodingDao.createTranscoding(transcoding);
Transcoding newTranscoding = transcodingDao.getAllTranscodings().get(0);
assertTranscodingEquals(transcoding, newTranscoding);
}
public void testUpdateTranscoding() {
Transcoding transcoding = new Transcoding(null, "name", "sourceFormats", "targetFormat", "step1", "step2", "step3", false);
transcodingDao.createTranscoding(transcoding);
transcoding = transcodingDao.getAllTranscodings().get(0);
transcoding.setName("newName");
transcoding.setSourceFormats("newSourceFormats");
transcoding.setTargetFormat("newTargetFormats");
transcoding.setStep1("newStep1");
transcoding.setStep2("newStep2");
transcoding.setStep3("newStep3");
transcoding.setDefaultActive(true);
transcodingDao.updateTranscoding(transcoding);
Transcoding newTranscoding = transcodingDao.getAllTranscodings().get(0);
assertTranscodingEquals(transcoding, newTranscoding);
}
public void testDeleteTranscoding() {
assertEquals("Wrong number of transcodings.", 0, transcodingDao.getAllTranscodings().size());
transcodingDao.createTranscoding(new Transcoding(null, "name", "sourceFormats", "targetFormat", "step1", "step2", "step3", true));
assertEquals("Wrong number of transcodings.", 1, transcodingDao.getAllTranscodings().size());
transcodingDao.createTranscoding(new Transcoding(null, "name", "sourceFormats", "targetFormat", "step1", "step2", "step3", true));
assertEquals("Wrong number of transcodings.", 2, transcodingDao.getAllTranscodings().size());
transcodingDao.deleteTranscoding(transcodingDao.getAllTranscodings().get(0).getId());
assertEquals("Wrong number of transcodings.", 1, transcodingDao.getAllTranscodings().size());
transcodingDao.deleteTranscoding(transcodingDao.getAllTranscodings().get(0).getId());
assertEquals("Wrong number of transcodings.", 0, transcodingDao.getAllTranscodings().size());
}
public void testPlayerTranscoding() {
Player player = new Player();
playerDao.createPlayer(player);
transcodingDao.createTranscoding(new Transcoding(null, "name", "sourceFormats", "targetFormat", "step1", "step2", "step3", false));
transcodingDao.createTranscoding(new Transcoding(null, "name", "sourceFormats", "targetFormat", "step1", "step2", "step3", false));
transcodingDao.createTranscoding(new Transcoding(null, "name", "sourceFormats", "targetFormat", "step1", "step2", "step3", false));
Transcoding transcodingA = transcodingDao.getAllTranscodings().get(0);
Transcoding transcodingB = transcodingDao.getAllTranscodings().get(1);
Transcoding transcodingC = transcodingDao.getAllTranscodings().get(2);
List<Transcoding> activeTranscodings = transcodingDao.getTranscodingsForPlayer(player.getId());
assertEquals("Wrong number of transcodings.", 0, activeTranscodings.size());
transcodingDao.setTranscodingsForPlayer(player.getId(), new int[]{transcodingA.getId()});
activeTranscodings = transcodingDao.getTranscodingsForPlayer(player.getId());
assertEquals("Wrong number of transcodings.", 1, activeTranscodings.size());
assertTranscodingEquals(transcodingA, activeTranscodings.get(0));
transcodingDao.setTranscodingsForPlayer(player.getId(), new int[]{transcodingB.getId(), transcodingC.getId()});
activeTranscodings = transcodingDao.getTranscodingsForPlayer(player.getId());
assertEquals("Wrong number of transcodings.", 2, activeTranscodings.size());
assertTranscodingEquals(transcodingB, activeTranscodings.get(0));
assertTranscodingEquals(transcodingC, activeTranscodings.get(1));
transcodingDao.setTranscodingsForPlayer(player.getId(), new int[0]);
activeTranscodings = transcodingDao.getTranscodingsForPlayer(player.getId());
assertEquals("Wrong number of transcodings.", 0, activeTranscodings.size());
}
public void testCascadingDeletePlayer() {
Player player = new Player();
playerDao.createPlayer(player);
transcodingDao.createTranscoding(new Transcoding(null, "name", "sourceFormats", "targetFormat", "step1", "step2", "step3", true));
Transcoding transcoding = transcodingDao.getAllTranscodings().get(0);
transcodingDao.setTranscodingsForPlayer(player.getId(), new int[]{transcoding.getId()});
List<Transcoding> activeTranscodings = transcodingDao.getTranscodingsForPlayer(player.getId());
assertEquals("Wrong number of transcodings.", 1, activeTranscodings.size());
playerDao.deletePlayer(player.getId());
activeTranscodings = transcodingDao.getTranscodingsForPlayer(player.getId());
assertEquals("Wrong number of transcodings.", 0, activeTranscodings.size());
}
public void testCascadingDeleteTranscoding() {
Player player = new Player();
playerDao.createPlayer(player);
transcodingDao.createTranscoding(new Transcoding(null, "name", "sourceFormats", "targetFormat", "step1", "step2", "step3", true));
Transcoding transcoding = transcodingDao.getAllTranscodings().get(0);
transcodingDao.setTranscodingsForPlayer(player.getId(), new int[]{transcoding.getId()});
List<Transcoding> activeTranscodings = transcodingDao.getTranscodingsForPlayer(player.getId());
assertEquals("Wrong number of transcodings.", 1, activeTranscodings.size());
transcodingDao.deleteTranscoding(transcoding.getId());
activeTranscodings = transcodingDao.getTranscodingsForPlayer(player.getId());
assertEquals("Wrong number of transcodings.", 0, activeTranscodings.size());
}
private void assertTranscodingEquals(Transcoding expected, Transcoding actual) {
assertEquals("Wrong name.", expected.getName(), actual.getName());
assertEquals("Wrong source formats.", expected.getSourceFormats(), actual.getSourceFormats());
assertEquals("Wrong target format.", expected.getTargetFormat(), actual.getTargetFormat());
assertEquals("Wrong step 1.", expected.getStep1(), actual.getStep1());
assertEquals("Wrong step 2.", expected.getStep2(), actual.getStep2());
assertEquals("Wrong step 3.", expected.getStep3(), actual.getStep3());
assertEquals("Wrong default active.", expected.isDefaultActive(), actual.isDefaultActive());
}
}
|