Project

General

Profile

1
package eu.dnetlib.enabling.is.sn;
2

    
3
import java.util.Arrays;
4
import java.util.Collection;
5

    
6
import org.junit.Before;
7
import org.junit.Test;
8

    
9
import static org.junit.Assert.assertNotNull;
10
import static org.junit.Assert.assertNull;
11

    
12
/**
13
 * abstract subscription registry test.
14
 * 
15
 * @author marko
16
 * 
17
 */
18
public class AbstractSubscriptionRegistryTest {
19

    
20
	/**
21
	 * object under test.
22
	 */
23
	private transient AbstractSubscriptionRegistry registry;
24

    
25
	/**
26
	 * setup .
27
	 * 
28
	 * @throws Exception
29
	 */
30
	@Before
31
	public void setUp() {
32
		registry = new AbstractSubscriptionRegistry() {
33

    
34
			@Override
35
			protected Collection<String> getAcceptedPrefixes() {
36
				return Arrays.asList(new String[] { "CREATE", "DELETE", "UPDATE", "DEEP/SUB" });
37
			}
38
		};
39
	}
40

    
41
	/**
42
	 * test prefixes.
43
	 */
44
	@Test
45
	public void testMatchPrefix() {
46
		final SubscriptionRequest sub = new SubscriptionRequest();
47

    
48
		sub.setTopicExpression("CREATE/MyResourceType");
49
		assertNotNull("check create", registry.matchPrefix(sub));
50

    
51
		sub.setTopicExpression("DELETE/MyResourceType");
52
		assertNotNull("check delete", registry.matchPrefix(sub));
53

    
54
		sub.setTopicExpression("UPDATE/MyResourceType");
55
		assertNotNull("check update", registry.matchPrefix(sub));
56

    
57
		sub.setTopicExpression("VERIFY/MyResourceType");
58
		assertNull("check non declared prefix", registry.matchPrefix(sub));
59

    
60
		sub.setTopicExpression("UPDATED/MyResourceType");
61
		assertNull("check non delimited prefix", registry.matchPrefix(sub));
62

    
63
		sub.setTopicExpression("UPDATE");
64
		assertNotNull("check only prefix", registry.matchPrefix(sub));
65

    
66
		sub.setTopicExpression("DEEP/MyResourceType");
67
		assertNull("check deep", registry.matchPrefix(sub));
68

    
69
		sub.setTopicExpression("DEEP/SUB/MyResourceType");
70
		assertNotNull("check deep sub", registry.matchPrefix(sub));
71
	}
72

    
73
}
(1-1/4)