Commit 7d521392 authored by Nicola Fulvio Calabria's avatar Nicola Fulvio Calabria
Browse files

added delete collection and test

parent d0350ddb
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ public class CollectionsDAO {
        });
    }

    Optional<NodeCollection> getNodeCollectionById(Long id) {
    public Optional<NodeCollection> getNodeCollectionById(Long id) {
        String sql = "SELECT collection_id, title, owner_id FROM collections\n"
                + "WHERE collection_id = ?";

@@ -66,7 +66,7 @@ public class CollectionsDAO {

    }
    
    List<NodeCollection> getUserNodeCollections(String userId) {
    public List<NodeCollection> getUserNodeCollections(String userId) {
        String sql = "SELECT collection_id, title, owner_id FROM collections\n"
                + "WHERE owner_id = ?";

@@ -83,6 +83,13 @@ public class CollectionsDAO {
        return nc;
    }
    
    public void deleteCollection(Long collectionId) {
        // TODO: this is just a stub for development.
        String sql  = "DELETE FROM collections WHERE collection_id = ?";
        
        jdbcTemplate.update(sql, collectionId);
    }

    private NodeCollection getNodeCollectionFromResultset(ResultSet rs)
            throws SQLException {
        NodeCollection nc = new NodeCollection(
+14 −1
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@
 */
package it.inaf.oats.vospace.persistence;

import it.inaf.oats.vospace.persistence.model.NodeCollection;
import java.util.List;
import javax.sql.DataSource;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -43,7 +45,18 @@ public class CollectionsDAOTest {
        collectionsDAO.createNewCollection("collection1", "pippo");
        collectionsDAO.createNewCollection("collection2", "pippo");
        
        assertEquals(2, collectionsDAO.getUserNodeCollections("pippo").size());
        List<NodeCollection> ncl = 
                collectionsDAO.getUserNodeCollections("pippo");
        
        assertEquals(2, ncl.size());
        
        for(NodeCollection nc : ncl) {
            collectionsDAO.deleteCollection(
                    nc.getId()
            );            
        }
        
        assertTrue(collectionsDAO.getUserNodeCollections("pippo").isEmpty());        
    }