-
Notifications
You must be signed in to change notification settings - Fork 14
/
NamedQueryManagerTest.java
48 lines (38 loc) · 1.43 KB
/
NamedQueryManagerTest.java
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
package cz.cvut.kbss.jopa.query;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.junit.Assert.*;
public class NamedQueryManagerTest {
private static final String QUERY = "SELECT ?x ?y ?z WHERE { ?x ?y ?z .}";
@Rule
public ExpectedException thrown = ExpectedException.none();
private NamedQueryManager queryManager;
@Before
public void setUp() {
this.queryManager = new NamedQueryManager();
}
@Test
public void addedQueryCanBeRetrieved() {
final String name = "selectAll";
queryManager.addNamedQuery(name, QUERY);
final String res = queryManager.getQuery(name);
assertEquals(QUERY, res);
}
@Test
public void addingQueryWithExistingNameThrowsIllegalArgument() {
final String name = "selectAll";
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Query with name " + name + " already exists in this persistence unit.");
queryManager.addNamedQuery(name, QUERY);
queryManager.addNamedQuery(name, "TEST");
}
@Test
public void retrievingUnknownQueryThrowsIllegalArgument() {
final String name = "selectAll";
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Query with name " + name + " was not found in this persistence unit.");
queryManager.getQuery(name);
}
}