Project

General

Profile

1
package eu.dnetlib.enabling.is.registry.schema;
2

    
3
import static org.mockito.Matchers.anyString;
4
import static org.mockito.Mockito.when;
5

    
6
import java.io.StringWriter;
7

    
8
import org.apache.commons.io.IOUtils;
9
import org.junit.Before;
10
import org.junit.Test;
11
import org.junit.runner.RunWith;
12
import org.mockito.Mock;
13
import org.mockito.junit.MockitoJUnitRunner;
14

    
15
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
16
import eu.dnetlib.enabling.tools.StreamOpaqueResource;
17

    
18
/**
19
 * test resource schema dao.
20
 * 
21
 * @author marko
22
 * 
23
 */
24
@RunWith(MockitoJUnitRunner.class)
25
public class ResourceSchemaDAOImplTest {
26

    
27
	/**
28
	 * instance under test.
29
	 */
30
	private transient ResourceSchemaDAOImpl dao;
31

    
32
	/**
33
	 * lookup service.
34
	 */
35
	@Mock
36
	private transient ISLookUpService lookupService;
37

    
38
	/**
39
	 * prepare common stuff.
40
	 * 
41
	 * @throws Exception
42
	 *             shouldn't happen
43
	 */
44
	@Before
45
	public void setUp() throws Exception {
46
		final StringWriter writer = new StringWriter();
47
		IOUtils.copy(getClass().getResourceAsStream("schema.xsd"), writer);
48

    
49
		when(lookupService.getResourceTypeSchema(anyString())).thenReturn(writer.getBuffer().toString());
50

    
51
		dao = new ResourceSchemaDAOImpl();
52
		dao.setIsLookup(lookupService);
53

    
54
	}
55

    
56
	/**
57
	 * test dao by validating a resource.
58
	 * 
59
	 * @throws Exception
60
	 *             shouldn't happen
61
	 */
62
	@Test
63
	public void testGetResourceSchema() throws Exception { // NOPMD
64
		final OpaqueResourceValidatorImpl validator = new OpaqueResourceValidatorImpl();
65
		validator.setSchemaDao(dao);
66

    
67
		validator.validate(new StreamOpaqueResource(getClass().getResourceAsStream("valid-profile.xml")));
68
	}
69

    
70
}
(2-2/2)