1   /*
2    * Copyright 2006-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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 org.apache.commons.lang.NotImplementedException;
26  
27  import net.sourceforge.domian.entity.Entity;
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 net.sourceforge.domian.test.domain.Customer;
33  import static net.sourceforge.domian.test.domain.Testdata.femaleCustomer;
34  import static net.sourceforge.domian.test.domain.Testdata.maleCustomer;
35  
36  
37  public class NotImplementedRepositoryTest extends AbstractRepositoryTestCase {
38  
39      @Override
40      protected String getTestRepoRootPath() {
41          throw new UnsupportedOperationException(NOT_APPLICABLE_METHOD_MESSAGE);
42      }
43  
44      @Override
45      protected <T extends Entity> Repository<T> getRepository() {
46          return new NotImplementedRepository<T>();
47      }
48  
49      @Override
50      protected <T extends Entity> Repository<T> getRepository(Class<T> entityType, String repositoryId) {
51          throw new UnsupportedOperationException(NOT_APPLICABLE_METHOD_MESSAGE);
52      }
53  
54      /*
55      @Override
56      protected <T extends Entity> Repository<T> getFakeRepository() {
57          throw new NotImplementedException();
58      }
59      */
60  
61      @Override
62      protected <T extends Entity> PersistentRepository<T> getPersistentRepository(String repositoryId, PersistenceDefinition persistenceDefinition) {
63          throw new UnsupportedOperationException(NOT_APPLICABLE_METHOD_MESSAGE);
64      }
65  
66      @Override
67      protected <T extends Entity> PartitionRepository<T> getPartitionRepository() {
68          throw new UnsupportedOperationException(NOT_APPLICABLE_METHOD_MESSAGE);
69      }
70  
71      @Override
72      protected <T extends Entity> PartitionRepository<T> getPartitionRepository(Class<T> entityType, String repositoryId) {
73          throw new UnsupportedOperationException(NOT_APPLICABLE_METHOD_MESSAGE);
74      }
75  
76      @Override
77      protected <R extends Repository<? extends Entity>> void reset(R repository, int maxNumberOfEntitiesToPurge) {}
78  
79      @Override
80      protected List<PersistenceDefinition> getSupportedPersistenceDefinitions() {
81          throw new UnsupportedOperationException(NOT_APPLICABLE_METHOD_MESSAGE);
82      }
83  
84      @Test(expected = NotImplementedException.class)
85      public void shouldThrowExceptionForCountAllEntities() {
86          getRepository().count(allEntities());
87      }
88  
89      @Test(expected = NotImplementedException.class)
90      public void shouldThrowExceptionForCountAllEntitiesSpecifiedBy() {
91          getRepository().countAllEntitiesSpecifiedBy(createSpecificationFor(Customer.class));
92      }
93  
94      @Test(expected = NotImplementedException.class)
95      public void shouldThrowExceptionForCount() {
96          getRepository().count(all(Customer.class));
97      }
98  
99      @Test(expected = NotImplementedException.class)
100     public void shouldThrowExceptionForFindAllEntitiesSpecifiedBy() {
101         getRepository().findAllEntitiesSpecifiedBy(createSpecificationFor(Customer.class));
102     }
103 
104     @Test(expected = NotImplementedException.class)
105     public void shouldThrowExceptionForFind() {
106         getRepository().findAll(all(Customer.class));
107     }
108 
109     @Test(expected = NotImplementedException.class)
110     public void shouldThrowExceptionForFindSingleEntitiespecifiedBy() {
111         getRepository().findSingleEntitySpecifiedBy(createSpecificationFor(Customer.class));
112     }
113 
114     @Test(expected = NotImplementedException.class)
115     public void shouldThrowExceptionForFindSingle() {
116         getRepository().findSingle(the(Customer.class));
117     }
118 
119     @Test(expected = NotImplementedException.class)
120     public void shouldThrowExceptionForPut() {
121         getRepository().put(maleCustomer);
122     }
123 
124     @Test(expected = NotImplementedException.class)
125     public void shouldThrowExceptionForPutAll() {
126         Collection<Customer> customers = new ArrayList<Customer>();
127         customers.add(maleCustomer);
128         customers.add(femaleCustomer);
129         getRepository().putAll(customers);
130     }
131 
132     @Test(expected = NotImplementedException.class)
133     public void shouldThrowExceptionForRemoveAllEntities() {
134         getRepository().remove(allEntities());
135     }
136 
137     @Test(expected = NotImplementedException.class)
138     public void shouldThrowExceptionForRemoveAllEntitiesSpecifiedBy() {
139         getRepository().removeAllEntitiesSpecifiedBy(createSpecificationFor(Customer.class));
140     }
141 
142     @Test(expected = NotImplementedException.class)
143     public void shouldThrowExceptionForRemoveAll() {
144         getRepository().removeAll(all(Customer.class));
145     }
146 
147     @Test(expected = NotImplementedException.class)
148     public void shouldThrowExceptionForRemove() {
149         getRepository().remove(maleCustomer);
150     }
151 }