Changeset 1358


Ignore:
Timestamp:
05/23/11 11:44:00 (13 years ago)
Author:
patdui
Message:
  • added getDeletedDescription test
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  
    11package clarin.cmdi.componentregistry.impl.database;
    22
    3 import clarin.cmdi.componentregistry.model.AbstractDescription;
    4 import clarin.cmdi.componentregistry.rest.RegistryTestHelper;
    5 import java.text.DateFormat;
    6 import java.util.Date;
     3import static org.junit.Assert.assertEquals;
     4import static org.junit.Assert.assertNotNull;
     5
    76import java.util.List;
    8 import org.apache.commons.lang.time.DateFormatUtils;
    9 import org.apache.commons.lang.time.DateUtils;
     7
     8import org.junit.Test;
    109import org.junit.runner.RunWith;
    11 import org.junit.Test;
    12 import static org.junit.Assert.assertNotNull;
    13 import static org.junit.Assert.assertEquals;
    14 
    1510import org.springframework.beans.factory.annotation.Autowired;
    1611import org.springframework.jdbc.core.JdbcTemplate;
     
    1813import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    1914
     15import clarin.cmdi.componentregistry.model.AbstractDescription;
     16import clarin.cmdi.componentregistry.rest.RegistryTestHelper;
     17
    2018/**
    21  *
     19 * 
    2220 * @author Twan Goosen <twan.goosen@mpi.nl>
    2321 */
    2422@RunWith(SpringJUnit4ClassRunner.class)
    25 @ContextConfiguration(locations = {"/applicationContext-database-impl.xml"})
     23@ContextConfiguration(locations = { "/applicationContext-database-impl.xml" })
    2624public abstract class AbstractDescriptionDaoTest {
    2725
     
    7472    @Test
    7573    public void testGetUserspaceDescriptions() throws Exception {
    76         List<AbstractDescription> descriptions = getDao().
    77                 getUserspaceDescriptions(-1);
     74        List<AbstractDescription> descriptions = getDao().getUserspaceDescriptions(-1);
    7875        assertEquals(0, descriptions.size());
    7976    }
     
    8885        int count = getDao().getPublicDescriptions().size();
    8986        // insert
    90         Number dbId = getDao().insertDescription(description, testComponent, true, null);
     87        getDao().insertDescription(description, testComponent, true, null);
    9188        assertEquals(count + 1, getDao().getPublicDescriptions().size());
    9289
     90        List deletedDescriptions = getDao().getDeletedDescriptions(null);
     91        assertEquals(0, deletedDescriptions.size());
     92
    9393        // delete
    94         getDao().setDeleted(dbId);
     94        getDao().setDeleted(description, true);
    9595        assertEquals(count, getDao().getPublicDescriptions().size());
     96       
     97        deletedDescriptions = getDao().getDeletedDescriptions(null);
     98        assertEquals(1, deletedDescriptions.size());
    9699    }
    97100
     
    105108        description.setDomainName("MyDomain");
    106109        description.setHref("http://MyHref");
    107        
     110
    108111        String testComponent = RegistryTestHelper.getComponentTestContentString();
    109112        Number newId = getDao().insertDescription(description, testComponent, true, null);
     
    112115        description.setName("Noot");
    113116        description.setDescription("AnotherDescription");
    114                 description.setCreatorName("AnotherAap");
     117        description.setCreatorName("AnotherAap");
    115118        description.setGroupName("AnotherGroup");
    116119        description.setDomainName("AnotherDomain");
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImplTest.java

    r1352 r1358  
    11package clarin.cmdi.componentregistry.impl.database;
    22
    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;
     3import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.createTableComponentDescription;
     4import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.createTableProfileDescription;
     5import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.createTableRegistryUser;
     6import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.createTableXmlContent;
     7import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.resetDatabase;
     8import static org.junit.Assert.assertEquals;
     9import static org.junit.Assert.assertNotNull;
     10import static org.junit.Assert.assertNull;
     11import static org.junit.Assert.assertTrue;
     12import static org.junit.Assert.fail;
     13
    1514import java.io.ByteArrayOutputStream;
    16 import java.io.IOException;
    1715import java.io.OutputStream;
    1816import java.util.Calendar;
    19 import javax.xml.bind.JAXBException;
     17
    2018import org.apache.commons.lang.time.DateFormatUtils;
    21 
     19import org.junit.Before;
    2220import org.junit.Test;
    23 import org.junit.Before;
    2421import 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;
    3022import org.springframework.beans.factory.annotation.Autowired;
    3123import org.springframework.jdbc.core.JdbcTemplate;
    3224import org.springframework.test.context.ContextConfiguration;
    3325import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
     26
     27import clarin.cmdi.componentregistry.ComponentRegistry;
     28import clarin.cmdi.componentregistry.DeleteFailedException;
     29import clarin.cmdi.componentregistry.UserCredentials;
     30import clarin.cmdi.componentregistry.UserUnauthorizedException;
     31import clarin.cmdi.componentregistry.components.CMDComponentSpec;
     32import clarin.cmdi.componentregistry.model.ComponentDescription;
     33import clarin.cmdi.componentregistry.model.ProfileDescription;
     34import clarin.cmdi.componentregistry.model.UserMapping.User;
     35import clarin.cmdi.componentregistry.rest.DummyPrincipal;
     36import clarin.cmdi.componentregistry.rest.RegistryTestHelper;
    3437
    3538@RunWith(SpringJUnit4ClassRunner.class)
     
    160163        assertNull(registry.getMDProfile(description.getId()));
    161164    }
    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 {
    164213        ProfileDescription description = ProfileDescription.createNewDescription();
    165214        description.setName("Aap");
     
    296345    }
    297346
    298     private ComponentDescription createComponent(ComponentRegistry registry) throws IOException, DeleteFailedException, JAXBException, ComponentRegistryException {
     347    private ComponentDescription createComponent(ComponentRegistry registry) throws Exception {
    299348        ComponentDescription description = ComponentDescription.
    300349                createNewDescription();
Note: See TracChangeset for help on using the changeset viewer.