Newer
Older
package it.inaf.oats.vospace.persistence;
import java.util.ArrayList;
import java.util.List;
import javax.sql.DataSource;
import net.ivoa.xml.vospace.v2.ContainerNode;
Sara Bertocco
committed
import net.ivoa.xml.vospace.v2.DataNode;
Sonia Zorba
committed
import net.ivoa.xml.vospace.v2.Node;
import net.ivoa.xml.vospace.v2.Property;
import net.ivoa.xml.vospace.v2.View;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {DataSourceConfig.class})
@TestPropertySource(locations = "classpath:test.properties")
public class NodeDAOTest {
@Autowired
private DataSource dataSource;
private NodeDAO dao;
@BeforeEach
public void init() {
dao = new NodeDAO(dataSource);
}
Sara Bertocco
committed
@Test
public void testCreateNode() {
DataNode dataNode = new DataNode();
Sara Bertocco
committed
dataNode.setUri("vos://example.com!vospace/mydata1");
dataNode.setAccepts(getViews());
dataNode.setProvides(getViews());
dataNode.setBusy(true);
Sara Bertocco
committed
dao.createNode(dataNode);
DataNode retrievedNode = (DataNode) dao.listNode("/mydata1").get();
assertEquals(retrievedNode.getAccepts().get(0).getUri(), dataNode.getAccepts().get(0).getUri());
assertEquals(retrievedNode.getProvides().get(0).getUri(), dataNode.getProvides().get(0).getUri());
Sara Bertocco
committed
}
@Test
public void testListNode() {
ContainerNode root = (ContainerNode) dao.listNode("/").get();
Sonia Zorba
committed
assertEquals(2, root.getNodes().size());
assertEquals("group1 group2", getProperty(root.getNodes().get(0), "ivo://ivoa.net/vospace/core#groupread"));
}
private String getProperty(Node node, String uri) {
for (Property property : node.getProperties()) {
if (uri.equals(property.getUri())) {
return property.getValue();
}
}
return null;
private List<View> getViews() {
View view = new View();
view.setUri("urn:myview");
List<View> views = new ArrayList<>();
views.add(view);
return views;
}