gcat/src/test/java/org/gcube/gcat/rest/ProfileTest.java

57 lines
1.6 KiB
Java

package org.gcube.gcat.rest;
import java.util.Iterator;
import javax.ws.rs.core.MediaType;
import org.gcube.gcat.ContextTest;
import org.gcube.gcat.rest.Profile;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
public class ProfileTest extends ContextTest {
private static Logger logger = LoggerFactory.getLogger(ProfileTest.class);
@Test
public void list() throws Exception {
Profile profile = new Profile();
String ret = profile.list();
logger.debug("{}", ret);
}
@Test
public void read() throws Exception {
String profileID = "SoBigData.eu: Dataset Metadata NextNext";
Profile profile = new Profile();
String ret = profile.read(profileID, MediaType.APPLICATION_XML);
logger.debug("XML :\n{}", ret);
ret = profile.read(profileID, MediaType.APPLICATION_JSON);
logger.debug("JSON : \n{}", ret);
}
@Test
public void listRead() throws Exception {
Profile profile = new Profile();
String ret = profile.list();
ObjectMapper mapper = new ObjectMapper();
ArrayNode arrayNode = (ArrayNode) mapper.readTree(ret);
logger.debug("Found {} profiles", arrayNode.size());
Iterator<JsonNode> iterator = arrayNode.iterator();
while(iterator.hasNext()) {
String profileID = iterator.next().asText();
ret = profile.read(profileID, MediaType.APPLICATION_XML);
logger.debug("XML :\n{}", ret);
ret = profile.read(profileID, MediaType.APPLICATION_JSON);
logger.debug("JSON : \n{}", ret);
}
}
}