1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.persistence.dao.hibernate.media;
|
11
|
|
12
|
import static org.junit.Assert.assertEquals;
|
13
|
|
14
|
import java.io.FileNotFoundException;
|
15
|
import java.net.URI;
|
16
|
import java.net.URISyntaxException;
|
17
|
import java.util.UUID;
|
18
|
|
19
|
import org.hibernate.TypeMismatchException;
|
20
|
import org.junit.Assert;
|
21
|
import org.junit.Before;
|
22
|
import org.junit.Test;
|
23
|
import org.unitils.dbunit.annotation.DataSet;
|
24
|
import org.unitils.dbunit.annotation.ExpectedDataSet;
|
25
|
import org.unitils.spring.annotation.SpringBeanByType;
|
26
|
|
27
|
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
|
28
|
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
|
29
|
import eu.etaxonomy.cdm.persistence.dao.media.IMediaRepresentationPartDao;
|
30
|
import eu.etaxonomy.cdm.persistence.dao.term.IDefinedTermDao;
|
31
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
32
|
|
33
|
@DataSet
|
34
|
public class MediaRepresentationPartDaoImplTest extends CdmTransactionalIntegrationTest {
|
35
|
|
36
|
@SpringBeanByType
|
37
|
IMediaRepresentationPartDao dao;
|
38
|
|
39
|
@SpringBeanByType
|
40
|
IDefinedTermDao definedTermDao;
|
41
|
|
42
|
|
43
|
@Before
|
44
|
public void setUp() {
|
45
|
}
|
46
|
|
47
|
@Test
|
48
|
public void testCount() {
|
49
|
long numberOfMediaRepresentationParts = dao.count();
|
50
|
assertEquals("count should return 3",3,numberOfMediaRepresentationParts);
|
51
|
}
|
52
|
|
53
|
@Test
|
54
|
public void testFindByUuid() {
|
55
|
MediaRepresentationPart part = dao.findByUuid(UUID.fromString("e06a0f29-ef82-4ce3-8a94-dd98feae8f9e"));
|
56
|
Assert.assertNotNull("part should not be null", part);
|
57
|
try {
|
58
|
Assert.assertEquals("part URI should be http://www.test.de", new URI("http://www.test.de"), part.getUri());
|
59
|
} catch (URISyntaxException e) {
|
60
|
Assert.fail("No URISyntaxException should occurr");
|
61
|
}
|
62
|
|
63
|
MediaRepresentationPart part2 = dao.findByUuid(UUID.fromString("a07a0f29-ef82-3ce3-8a94-dd98feae8f9e"));
|
64
|
Assert.assertNotNull("part2 should not be null", part2);
|
65
|
try {
|
66
|
Assert.assertEquals("part URI should be http://www.test2.de", new URI("http://www.test2.de"), part2.getUri());
|
67
|
} catch (URISyntaxException e) {
|
68
|
Assert.fail("No URISyntaxException should occurr");
|
69
|
}
|
70
|
|
71
|
try {
|
72
|
MediaRepresentationPart part3 = dao.findByUuid(UUID.fromString("b48a0f26-2f42-3ce3-8a04-dd98feaa8e98"));
|
73
|
Assert.assertEquals("part URI should be http://www.test2.de", new URI("http://www.test2.de"), part3.getUri());
|
74
|
Assert.fail("A TypeMismatchException should occurr for http://www.fail.de");
|
75
|
} catch (Exception e) {
|
76
|
if (e instanceof TypeMismatchException){
|
77
|
//OK
|
78
|
}else{
|
79
|
Assert.fail("Only an URISyntaxException should occurr but exception was of type " + e.getClass().getName());
|
80
|
}
|
81
|
}
|
82
|
|
83
|
}
|
84
|
|
85
|
@Test
|
86
|
@ExpectedDataSet
|
87
|
public void testSave() {
|
88
|
try {
|
89
|
URI uri = new URI("http://www.test3.de");
|
90
|
|
91
|
MediaRepresentationPart part1 = MediaRepresentationPart.NewInstance(uri, 22);
|
92
|
//a representation is needed otherwise a not nullable exception is thrown (due to lucene index (?))
|
93
|
MediaRepresentation representation = MediaRepresentation.NewInstance();
|
94
|
representation.addRepresentationPart(part1);
|
95
|
dao.save(part1);
|
96
|
commit();
|
97
|
|
98
|
} catch (URISyntaxException e) {
|
99
|
Assert.fail("URI should be ok");
|
100
|
}
|
101
|
|
102
|
}
|
103
|
|
104
|
@Test
|
105
|
public void testLongUri() {
|
106
|
try {
|
107
|
URI uri = new URI("http://www.test3.de/woieoriuwoirwuwouroiwuowiuoiuwoieuroiuewroiououi/hdsfiuwhuehfhiuhiuhwihiuhew"+
|
108
|
"wereeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"+
|
109
|
"weeeeeeeeeeeeeeeeeeeeeee/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"+
|
110
|
"uizweiuzriuzewiurziuewui/weeeeeeeeeeeeeeeeeuiziuzwueziuzweiurziuwzriufsfdds");
|
111
|
|
112
|
MediaRepresentationPart part1 = MediaRepresentationPart.NewInstance(uri, 22);
|
113
|
//a representation is needed otherwise a not nullable exception is thrown (due to lucene index (?))
|
114
|
MediaRepresentation representation = MediaRepresentation.NewInstance();
|
115
|
representation.addRepresentationPart(part1);
|
116
|
dao.save(part1);
|
117
|
commit();
|
118
|
|
119
|
} catch (URISyntaxException e) {
|
120
|
Assert.fail("URI should be ok");
|
121
|
}
|
122
|
|
123
|
}
|
124
|
|
125
|
/* (non-Javadoc)
|
126
|
* @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData()
|
127
|
*/
|
128
|
@Override
|
129
|
public void createTestDataSet() throws FileNotFoundException {
|
130
|
// TODO Auto-generated method stub
|
131
|
|
132
|
}
|
133
|
|
134
|
}
|