2018-12-04 12:06:22 +01:00
|
|
|
package org.gcube.gcat.persistence.ckan;
|
|
|
|
|
2019-05-20 17:23:49 +02:00
|
|
|
import static org.junit.Assert.assertFalse;
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2018-12-04 12:06:22 +01:00
|
|
|
import org.gcube.gcat.ContextTest;
|
|
|
|
import org.junit.Assert;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2020-12-01 16:58:36 +01:00
|
|
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
2018-12-04 12:06:22 +01:00
|
|
|
|
|
|
|
public class CKANLicenseTest extends ContextTest {
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(CKANLicenseTest.class);
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void list() throws Exception {
|
|
|
|
CKANLicense license = new CKANLicense();
|
2019-09-16 14:50:08 +02:00
|
|
|
license.list(-1, -1);
|
2019-05-20 17:23:49 +02:00
|
|
|
JsonNode gotList = license.getJsonNodeResult();
|
2018-12-04 12:06:22 +01:00
|
|
|
Assert.assertTrue(gotList instanceof ArrayNode);
|
2019-05-20 17:23:49 +02:00
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
2018-12-04 12:06:22 +01:00
|
|
|
logger.debug("List :\n{}", mapper.writeValueAsString(gotList));
|
|
|
|
}
|
|
|
|
|
2019-05-20 17:23:49 +02:00
|
|
|
@Test
|
|
|
|
public void testCheckLicense() throws Exception {
|
|
|
|
ArrayNode arrayNode = CKANLicense.getLicenses();
|
2019-09-16 14:50:08 +02:00
|
|
|
for(JsonNode jsonNode : arrayNode) {
|
2019-05-20 17:23:49 +02:00
|
|
|
String licenseId = jsonNode.get(CKAN.ID_KEY).asText();
|
|
|
|
assertTrue(CKANLicense.checkLicenseId(arrayNode, licenseId));
|
|
|
|
logger.debug("'{}' is a valid License ID", licenseId);
|
|
|
|
}
|
|
|
|
List<String> invalidIds = new ArrayList<>();
|
|
|
|
invalidIds.add("InvaliLicense");
|
|
|
|
invalidIds.add("CCO");
|
|
|
|
for(String licenseId : invalidIds) {
|
|
|
|
assertFalse(CKANLicense.checkLicenseId(arrayNode, licenseId));
|
|
|
|
logger.debug("As expected '{}' is an INVALID License ID", licenseId);
|
|
|
|
}
|
|
|
|
}
|
2018-12-04 12:06:22 +01:00
|
|
|
}
|