Skip to content
Snippets Groups Projects
Commit 7d521392 authored by Nicola Fulvio Calabria's avatar Nicola Fulvio Calabria
Browse files

added delete collection and test

parent d0350ddb
No related branches found
No related tags found
No related merge requests found
...@@ -43,7 +43,7 @@ public class CollectionsDAO { ...@@ -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" String sql = "SELECT collection_id, title, owner_id FROM collections\n"
+ "WHERE collection_id = ?"; + "WHERE collection_id = ?";
...@@ -66,7 +66,7 @@ public class CollectionsDAO { ...@@ -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" String sql = "SELECT collection_id, title, owner_id FROM collections\n"
+ "WHERE owner_id = ?"; + "WHERE owner_id = ?";
...@@ -83,6 +83,13 @@ public class CollectionsDAO { ...@@ -83,6 +83,13 @@ public class CollectionsDAO {
return nc; 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) private NodeCollection getNodeCollectionFromResultset(ResultSet rs)
throws SQLException { throws SQLException {
NodeCollection nc = new NodeCollection( NodeCollection nc = new NodeCollection(
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
*/ */
package it.inaf.oats.vospace.persistence; package it.inaf.oats.vospace.persistence;
import it.inaf.oats.vospace.persistence.model.NodeCollection;
import java.util.List;
import javax.sql.DataSource; import javax.sql.DataSource;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
...@@ -43,7 +45,18 @@ public class CollectionsDAOTest { ...@@ -43,7 +45,18 @@ public class CollectionsDAOTest {
collectionsDAO.createNewCollection("collection1", "pippo"); collectionsDAO.createNewCollection("collection1", "pippo");
collectionsDAO.createNewCollection("collection2", "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());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment