Project

General

Profile

Download (4.15 KB) Statistics
| Branch: | Tag: | Revision:
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
package eu.etaxonomy.cdm.persistence.dao.hibernate.media;
10

    
11
import static org.junit.Assert.assertEquals;
12

    
13
import java.io.FileNotFoundException;
14
import java.net.URISyntaxException;
15
import java.util.UUID;
16

    
17
import org.hibernate.TypeMismatchException;
18
import org.junit.Assert;
19
import org.junit.Test;
20
import org.unitils.dbunit.annotation.DataSet;
21
import org.unitils.dbunit.annotation.ExpectedDataSet;
22
import org.unitils.spring.annotation.SpringBeanByType;
23

    
24
import eu.etaxonomy.cdm.common.URI;
25
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
26
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
27
import eu.etaxonomy.cdm.persistence.dao.media.IMediaRepresentationPartDao;
28
import eu.etaxonomy.cdm.persistence.dao.term.IDefinedTermDao;
29
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
30

    
31
@DataSet
32
public class MediaRepresentationPartDaoImplTest extends CdmTransactionalIntegrationTest {
33

    
34
	@SpringBeanByType
35
	private IMediaRepresentationPartDao dao;
36

    
37
	@SpringBeanByType
38
	private IDefinedTermDao definedTermDao;
39

    
40
	@Test
41
	public void testCount() {
42
		long numberOfMediaRepresentationParts = dao.count();
43
		assertEquals("count should return 3",3,numberOfMediaRepresentationParts);
44
	}
45

    
46
	@Test
47
	public void testFindByUuid() {
48
		MediaRepresentationPart part = dao.findByUuid(UUID.fromString("e06a0f29-ef82-4ce3-8a94-dd98feae8f9e"));
49
		Assert.assertNotNull("part should not be null", part);
50
		try {
51
			Assert.assertEquals("part URI should be http://www.test.de", new URI("http://www.test.de"), part.getUri());
52
		} catch (URISyntaxException e) {
53
			Assert.fail("No URISyntaxException should occurr");
54
		}
55

    
56
		MediaRepresentationPart part2 = dao.findByUuid(UUID.fromString("a07a0f29-ef82-3ce3-8a94-dd98feae8f9e"));
57
		Assert.assertNotNull("part2 should not be null", part2);
58
		try {
59
			Assert.assertEquals("part URI should be http://www.test2.de", new URI("http://www.test2.de"), part2.getUri());
60
		} catch (URISyntaxException e) {
61
			Assert.fail("No URISyntaxException should occurr");
62
		}
63

    
64
		try {
65
			MediaRepresentationPart part3 = dao.findByUuid(UUID.fromString("b48a0f26-2f42-3ce3-8a04-dd98feaa8e98"));
66
			Assert.assertEquals("part URI should be http://www.test2.de", new URI("http://www.test2.de"), part3.getUri());
67
			Assert.fail("A TypeMismatchException should occurr for http://www.fail.de");
68
		} catch (Exception e) {
69
			if (e instanceof TypeMismatchException){
70
				//OK
71
			}else{
72
				Assert.fail("Only an URISyntaxException should occurr but exception was of type " + e.getClass().getName());
73
			}
74
		}
75
	}
76

    
77
	@Test
78
	@ExpectedDataSet
79
	public void testSave() {
80
		try {
81
			URI uri = new URI("http://www.test3.de");
82

    
83
			MediaRepresentationPart part1 = MediaRepresentationPart.NewInstance(uri, 22);
84
			//a representation is needed otherwise a not nullable exception is thrown (due to lucene index (?))
85
			MediaRepresentation representation = MediaRepresentation.NewInstance();
86
			representation.addRepresentationPart(part1);
87
			dao.save(part1);
88
			commit();
89

    
90
		} catch (URISyntaxException e) {
91
			Assert.fail("URI should be ok");
92
		}
93
	}
94

    
95
	@Test
96
	public void testLongUri() {
97
		try {
98
			URI uri = new URI("http://www.test3.de/woieoriuwoirwuwouroiwuowiuoiuwoieuroiuewroiououi/hdsfiuwhuehfhiuhiuhwihiuhew"+
99
					"wereeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"+
100
					"weeeeeeeeeeeeeeeeeeeeeee/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"+
101
					"uizweiuzriuzewiurziuewui/weeeeeeeeeeeeeeeeeuiziuzwueziuzweiurziuwzriufsfdds");
102

    
103
			MediaRepresentationPart part1 = MediaRepresentationPart.NewInstance(uri, 22);
104
			//a representation is needed otherwise a not nullable exception is thrown (due to lucene index (?))
105
			MediaRepresentation representation = MediaRepresentation.NewInstance();
106
			representation.addRepresentationPart(part1);
107
			dao.save(part1);
108
			commit();
109

    
110
		} catch (URISyntaxException e) {
111
			Assert.fail("URI should be ok");
112
		}
113

    
114
	}
115

    
116
    @Override
117
    public void createTestDataSet() throws FileNotFoundException {}
118

    
119
}
(2-2/2)