1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sourceforge.domian.repository;
17
18
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.List;
22
23 import org.junit.Test;
24
25 import net.sourceforge.domian.entity.Entity;
26 import net.sourceforge.domian.test.domain.Customer;
27
28 import static net.sourceforge.domian.specification.SpecificationFactory.all;
29 import static net.sourceforge.domian.specification.SpecificationFactory.allEntities;
30 import static net.sourceforge.domian.specification.SpecificationFactory.createSpecificationFor;
31 import static net.sourceforge.domian.specification.SpecificationFactory.the;
32 import static net.sourceforge.domian.test.domain.Testdata.femaleCustomer;
33 import static net.sourceforge.domian.test.domain.Testdata.maleCustomer;
34 import static org.junit.Assert.assertEquals;
35 import static org.junit.Assert.fail;
36
37
38 public class UnsupportedRepositoryTest extends AbstractRepositoryTestCase {
39
40 @Override
41 protected String getTestRepoRootPath() {
42 throw new UnsupportedOperationException(NOT_APPLICABLE_METHOD_MESSAGE);
43 }
44
45 @Override
46 protected <T extends Entity> Repository<T> getRepository() {
47 return new UnsupportedRepository<T>();
48 }
49
50 @Override
51 protected <T extends Entity> Repository<T> getRepository(Class<T> entityType, String repositoryId) {
52 throw new UnsupportedOperationException(NOT_APPLICABLE_METHOD_MESSAGE);
53 }
54
55
56
57
58
59
60
61
62 @Override
63 protected <T extends Entity> PersistentRepository<T> getPersistentRepository(String repositoryId, PersistenceDefinition persistenceDefinition) {
64 throw new UnsupportedOperationException(NOT_APPLICABLE_METHOD_MESSAGE);
65 }
66
67 @Override
68 protected <T extends Entity> PartitionRepository<T> getPartitionRepository() {
69 throw new UnsupportedOperationException(NOT_APPLICABLE_METHOD_MESSAGE);
70 }
71
72 @Override
73 protected <T extends Entity> PartitionRepository<T> getPartitionRepository(Class<T> entityType, String repositoryId) {
74 throw new UnsupportedOperationException(NOT_APPLICABLE_METHOD_MESSAGE);
75 }
76
77 @Override
78 protected <R extends Repository<? extends Entity>> void reset(R repository, int maxNumberOfEntitiesToPurge) {
79 throw new UnsupportedOperationException(NOT_APPLICABLE_METHOD_MESSAGE);
80 }
81
82 @Override
83 protected List<PersistenceDefinition> getSupportedPersistenceDefinitions() {
84 throw new UnsupportedOperationException(NOT_APPLICABLE_METHOD_MESSAGE);
85 }
86
87 @Test
88 public void shouldThrowExceptionWithMessageForAllMethods() {
89 try {
90 getRepository().count(allEntities());
91 fail("Should have thrown exception");
92
93 } catch (UnsupportedOperationException e) {
94 assertEquals("No operations are supported by this repository", e.getMessage());
95 }
96 }
97
98 @Test(expected = UnsupportedOperationException.class)
99 public void shouldThrowExceptionForCountAllEntities() {
100 getRepository().count(allEntities());
101 }
102
103 @Test(expected = UnsupportedOperationException.class)
104 public void shouldThrowExceptionForCountAllEntitiesSpecifiedBy() {
105 getRepository().countAllEntitiesSpecifiedBy(createSpecificationFor(Customer.class));
106 }
107
108 @Test(expected = UnsupportedOperationException.class)
109 public void shouldThrowExceptionForCount() {
110 getRepository().count(all(Customer.class));
111 }
112
113 @Test(expected = UnsupportedOperationException.class)
114 public void shouldThrowExceptionForFindAllEntitiesSpecifiedBy() {
115 getRepository().findAllEntitiesSpecifiedBy(createSpecificationFor(Customer.class));
116 }
117
118 @Test(expected = UnsupportedOperationException.class)
119 public void shouldThrowExceptionForFindAll() {
120 getRepository().findAll(createSpecificationFor(Customer.class));
121 }
122
123 @Test(expected = UnsupportedOperationException.class)
124 public void shouldThrowExceptionForFindSingleEntitiespecifiedBy() {
125 getRepository().findSingleEntitySpecifiedBy(createSpecificationFor(Customer.class));
126 }
127
128 @Test(expected = UnsupportedOperationException.class)
129 public void shouldThrowExceptionForFindSingle() {
130 getRepository().findSingle(the(Customer.class));
131 }
132
133 @Test(expected = UnsupportedOperationException.class)
134 public void shouldThrowExceptionForPut() {
135 getRepository().put(maleCustomer);
136 }
137
138 @Test(expected = UnsupportedOperationException.class)
139 public void shouldThrowExceptionForPutAll() {
140 Collection<Customer> customers = new ArrayList<Customer>();
141 customers.add(maleCustomer);
142 customers.add(femaleCustomer);
143 getRepository().putAll(customers);
144 }
145
146 @Test(expected = UnsupportedOperationException.class)
147 public void shouldThrowExceptionForRemoveAllEntities() {
148 getRepository().remove(allEntities());
149 }
150
151 @Test(expected = UnsupportedOperationException.class)
152 public void shouldThrowExceptionForRemoveAllEntitiesSpecifiedBy() {
153 getRepository().removeAllEntitiesSpecifiedBy(createSpecificationFor(Customer.class));
154 }
155
156 @Test(expected = UnsupportedOperationException.class)
157 public void shouldThrowExceptionForRemoveAll() {
158 getRepository().removeAll(all(Customer.class));
159 }
160
161 @Test(expected = UnsupportedOperationException.class)
162 public void shouldThrowExceptionForRemove() {
163 getRepository().remove(maleCustomer);
164 }
165 }