Changeset 1358
- Timestamp:
- 05/23/11 11:44:00 (13 years ago)
- Location:
- ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/AbstractDescriptionDaoTest.java
r1348 r1358 1 1 package clarin.cmdi.componentregistry.impl.database; 2 2 3 import clarin.cmdi.componentregistry.model.AbstractDescription; 4 import clarin.cmdi.componentregistry.rest.RegistryTestHelper; 5 import java.text.DateFormat; 6 import java.util.Date; 3 import static org.junit.Assert.assertEquals; 4 import static org.junit.Assert.assertNotNull; 5 7 6 import java.util.List; 8 import org.apache.commons.lang.time.DateFormatUtils; 9 import org. apache.commons.lang.time.DateUtils;7 8 import org.junit.Test; 10 9 import org.junit.runner.RunWith; 11 import org.junit.Test;12 import static org.junit.Assert.assertNotNull;13 import static org.junit.Assert.assertEquals;14 15 10 import org.springframework.beans.factory.annotation.Autowired; 16 11 import org.springframework.jdbc.core.JdbcTemplate; … … 18 13 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 19 14 15 import clarin.cmdi.componentregistry.model.AbstractDescription; 16 import clarin.cmdi.componentregistry.rest.RegistryTestHelper; 17 20 18 /** 21 * 19 * 22 20 * @author Twan Goosen <twan.goosen@mpi.nl> 23 21 */ 24 22 @RunWith(SpringJUnit4ClassRunner.class) 25 @ContextConfiguration(locations = { "/applicationContext-database-impl.xml"})23 @ContextConfiguration(locations = { "/applicationContext-database-impl.xml" }) 26 24 public abstract class AbstractDescriptionDaoTest { 27 25 … … 74 72 @Test 75 73 public void testGetUserspaceDescriptions() throws Exception { 76 List<AbstractDescription> descriptions = getDao(). 77 getUserspaceDescriptions(-1); 74 List<AbstractDescription> descriptions = getDao().getUserspaceDescriptions(-1); 78 75 assertEquals(0, descriptions.size()); 79 76 } … … 88 85 int count = getDao().getPublicDescriptions().size(); 89 86 // insert 90 Number dbId =getDao().insertDescription(description, testComponent, true, null);87 getDao().insertDescription(description, testComponent, true, null); 91 88 assertEquals(count + 1, getDao().getPublicDescriptions().size()); 92 89 90 List deletedDescriptions = getDao().getDeletedDescriptions(null); 91 assertEquals(0, deletedDescriptions.size()); 92 93 93 // delete 94 getDao().setDeleted(d bId);94 getDao().setDeleted(description, true); 95 95 assertEquals(count, getDao().getPublicDescriptions().size()); 96 97 deletedDescriptions = getDao().getDeletedDescriptions(null); 98 assertEquals(1, deletedDescriptions.size()); 96 99 } 97 100 … … 105 108 description.setDomainName("MyDomain"); 106 109 description.setHref("http://MyHref"); 107 110 108 111 String testComponent = RegistryTestHelper.getComponentTestContentString(); 109 112 Number newId = getDao().insertDescription(description, testComponent, true, null); … … 112 115 description.setName("Noot"); 113 116 description.setDescription("AnotherDescription"); 114 117 description.setCreatorName("AnotherAap"); 115 118 description.setGroupName("AnotherGroup"); 116 119 description.setDomainName("AnotherDomain"); -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImplTest.java
r1352 r1358 1 1 package clarin.cmdi.componentregistry.impl.database; 2 2 3 import clarin.cmdi.componentregistry.ComponentRegistry; 4 import clarin.cmdi.componentregistry.ComponentRegistryException; 5 import clarin.cmdi.componentregistry.DeleteFailedException; 6 import clarin.cmdi.componentregistry.UserCredentials; 7 import clarin.cmdi.componentregistry.UserUnauthorizedException; 8 import clarin.cmdi.componentregistry.rest.RegistryTestHelper; 9 import clarin.cmdi.componentregistry.components.CMDComponentSpec; 10 import clarin.cmdi.componentregistry.model.ComponentDescription; 11 import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.*; 12 import clarin.cmdi.componentregistry.model.ProfileDescription; 13 import clarin.cmdi.componentregistry.model.UserMapping.User; 14 import clarin.cmdi.componentregistry.rest.DummyPrincipal; 3 import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.createTableComponentDescription; 4 import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.createTableProfileDescription; 5 import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.createTableRegistryUser; 6 import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.createTableXmlContent; 7 import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.resetDatabase; 8 import static org.junit.Assert.assertEquals; 9 import static org.junit.Assert.assertNotNull; 10 import static org.junit.Assert.assertNull; 11 import static org.junit.Assert.assertTrue; 12 import static org.junit.Assert.fail; 13 15 14 import java.io.ByteArrayOutputStream; 16 import java.io.IOException;17 15 import java.io.OutputStream; 18 16 import java.util.Calendar; 19 import javax.xml.bind.JAXBException; 17 20 18 import org.apache.commons.lang.time.DateFormatUtils; 21 19 import org.junit.Before; 22 20 import org.junit.Test; 23 import org.junit.Before;24 21 import org.junit.runner.RunWith; 25 import static org.junit.Assert.assertEquals;26 import static org.junit.Assert.assertNull;27 import static org.junit.Assert.assertNotNull;28 import static org.junit.Assert.assertTrue;29 import static org.junit.Assert.fail;30 22 import org.springframework.beans.factory.annotation.Autowired; 31 23 import org.springframework.jdbc.core.JdbcTemplate; 32 24 import org.springframework.test.context.ContextConfiguration; 33 25 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 26 27 import clarin.cmdi.componentregistry.ComponentRegistry; 28 import clarin.cmdi.componentregistry.DeleteFailedException; 29 import clarin.cmdi.componentregistry.UserCredentials; 30 import clarin.cmdi.componentregistry.UserUnauthorizedException; 31 import clarin.cmdi.componentregistry.components.CMDComponentSpec; 32 import clarin.cmdi.componentregistry.model.ComponentDescription; 33 import clarin.cmdi.componentregistry.model.ProfileDescription; 34 import clarin.cmdi.componentregistry.model.UserMapping.User; 35 import clarin.cmdi.componentregistry.rest.DummyPrincipal; 36 import clarin.cmdi.componentregistry.rest.RegistryTestHelper; 34 37 35 38 @RunWith(SpringJUnit4ClassRunner.class) … … 160 163 assertNull(registry.getMDProfile(description.getId())); 161 164 } 162 163 private ProfileDescription createProfile(ComponentRegistry register) throws IOException, JAXBException, DeleteFailedException, ComponentRegistryException { 165 166 @Test 167 public void testGetDeletedDescriptions() throws Exception { 168 User user = createUser(); 169 Number userId = userDao.insertUser(user); 170 ComponentRegistry registry = getComponentRegistryForUser(userId); 171 ComponentRegistry publicReg = getComponentRegistryForUser(null); 172 ProfileDescription desc1 = createProfile(registry); 173 ProfileDescription desc2 = createProfile(publicReg); 174 ComponentDescription desc3 = createComponent(registry); 175 ComponentDescription desc4 = createComponent(publicReg); 176 177 assertEquals(0, registry.getDeletedProfileDescriptions().size()); 178 assertEquals(0, publicReg.getDeletedProfileDescriptions().size()); 179 assertEquals(0, registry.getDeletedComponentDescriptions().size()); 180 assertEquals(0, publicReg.getDeletedComponentDescriptions().size()); 181 182 registry.deleteMDProfile(desc1.getId(), USER_CREDS.getPrincipal()); 183 184 assertEquals(1, registry.getDeletedProfileDescriptions().size()); 185 assertEquals(0, publicReg.getDeletedProfileDescriptions().size()); 186 assertEquals(0, registry.getDeletedComponentDescriptions().size()); 187 assertEquals(0, publicReg.getDeletedComponentDescriptions().size()); 188 189 publicReg.deleteMDProfile(desc2.getId(), USER_CREDS.getPrincipal()); 190 191 assertEquals(1, registry.getDeletedProfileDescriptions().size()); 192 assertEquals(1, publicReg.getDeletedProfileDescriptions().size()); 193 assertEquals(0, registry.getDeletedComponentDescriptions().size()); 194 assertEquals(0, publicReg.getDeletedComponentDescriptions().size()); 195 196 registry.deleteMDComponent(desc3.getId(), USER_CREDS.getPrincipal(), false); 197 198 assertEquals(1, registry.getDeletedProfileDescriptions().size()); 199 assertEquals(1, publicReg.getDeletedProfileDescriptions().size()); 200 assertEquals(1, registry.getDeletedComponentDescriptions().size()); 201 assertEquals(0, publicReg.getDeletedComponentDescriptions().size()); 202 203 publicReg.deleteMDComponent(desc4.getId(), USER_CREDS.getPrincipal(), false); 204 205 assertEquals(1, registry.getDeletedProfileDescriptions().size()); 206 assertEquals(1, publicReg.getDeletedProfileDescriptions().size()); 207 assertEquals(1, registry.getDeletedComponentDescriptions().size()); 208 assertEquals(1, publicReg.getDeletedComponentDescriptions().size()); 209 210 } 211 212 private ProfileDescription createProfile(ComponentRegistry register) throws Exception { 164 213 ProfileDescription description = ProfileDescription.createNewDescription(); 165 214 description.setName("Aap"); … … 296 345 } 297 346 298 private ComponentDescription createComponent(ComponentRegistry registry) throws IOException, DeleteFailedException, JAXBException, ComponentRegistryException {347 private ComponentDescription createComponent(ComponentRegistry registry) throws Exception { 299 348 ComponentDescription description = ComponentDescription. 300 349 createNewDescription();
Note: See TracChangeset
for help on using the changeset viewer.