Formatted code

This commit is contained in:
Luca Frosini 2019-09-16 14:50:08 +02:00
parent 11cd97e1c7
commit f06002302c
9 changed files with 43 additions and 56 deletions

View File

@ -24,7 +24,7 @@ public class CKANLicenseTest extends ContextTest {
@Test @Test
public void list() throws Exception { public void list() throws Exception {
CKANLicense license = new CKANLicense(); CKANLicense license = new CKANLicense();
license.list(-1,-1); license.list(-1, -1);
JsonNode gotList = license.getJsonNodeResult(); JsonNode gotList = license.getJsonNodeResult();
Assert.assertTrue(gotList instanceof ArrayNode); Assert.assertTrue(gotList instanceof ArrayNode);
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
@ -34,7 +34,7 @@ public class CKANLicenseTest extends ContextTest {
@Test @Test
public void testCheckLicense() throws Exception { public void testCheckLicense() throws Exception {
ArrayNode arrayNode = CKANLicense.getLicenses(); ArrayNode arrayNode = CKANLicense.getLicenses();
for(JsonNode jsonNode : arrayNode){ for(JsonNode jsonNode : arrayNode) {
String licenseId = jsonNode.get(CKAN.ID_KEY).asText(); String licenseId = jsonNode.get(CKAN.ID_KEY).asText();
assertTrue(CKANLicense.checkLicenseId(arrayNode, licenseId)); assertTrue(CKANLicense.checkLicenseId(arrayNode, licenseId));
logger.debug("'{}' is a valid License ID", licenseId); logger.debug("'{}' is a valid License ID", licenseId);

View File

@ -29,12 +29,11 @@ public class CKANPackageTest extends ContextTest {
private static final String LICENSE_VALUE = "CC-BY-SA-4.0"; private static final String LICENSE_VALUE = "CC-BY-SA-4.0";
private static final String EXTRAS_TYPE_VALUE_VALUE = "TestEmptyProfile"; private static final String EXTRAS_TYPE_VALUE_VALUE = "TestEmptyProfile";
@Test @Test
public void list() throws Exception { public void list() throws Exception {
CKANPackage ckanPackage = new CKANPackage(); CKANPackage ckanPackage = new CKANPackage();
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
String ret = ckanPackage.list(-1,0); String ret = ckanPackage.list(-1, 0);
JsonNode gotList = mapper.readTree(ret); JsonNode gotList = mapper.readTree(ret);
Assert.assertTrue(gotList instanceof ArrayNode); Assert.assertTrue(gotList instanceof ArrayNode);
logger.debug("List :\n{}", mapper.writeValueAsString(gotList)); logger.debug("List :\n{}", mapper.writeValueAsString(gotList));
@ -61,15 +60,19 @@ public class CKANPackageTest extends ContextTest {
@Test @Test
public void testNameRegex() { public void testNameRegex() {
Map<String, Boolean> stringsToTest = new HashMap<>(); Map<String,Boolean> stringsToTest = new HashMap<>();
stringsToTest.put("Test", false); // Fails for T stringsToTest.put("Test", false); // Fails for T
stringsToTest.put("test-test+test-test", false); // Fails for + stringsToTest.put("test-test+test-test", false); // Fails for +
stringsToTest.put("t", false); // Fails because is too short. Min length is 2 characters stringsToTest.put("t", false); // Fails because is too short. Min length is 2 characters
stringsToTest.put("te", true); stringsToTest.put("te", true);
stringsToTest.put("test-test_test-test", true); stringsToTest.put("test-test_test-test", true);
stringsToTest.put("test-test_test-test_test-test_test-test_test-test_test-test_test-test_test-test_test-test_test-test_", true); stringsToTest.put(
"test-test_test-test_test-test_test-test_test-test_test-test_test-test_test-test_test-test_test-test_",
true);
// // Fails because is too long. Max length is 100 characters // // Fails because is too long. Max length is 100 characters
stringsToTest.put("test-test_test-test_test-test_test-test_test-test_test-test_test-test_test-test_test-test_test-test_t", false); stringsToTest.put(
"test-test_test-test_test-test_test-test_test-test_test-test_test-test_test-test_test-test_test-test_t",
false);
for(String testString : stringsToTest.keySet()) { for(String testString : stringsToTest.keySet()) {
boolean match = testString.matches(CKANPackage.NAME_REGEX); boolean match = testString.matches(CKANPackage.NAME_REGEX);
@ -79,7 +82,6 @@ public class CKANPackageTest extends ContextTest {
} }
protected CKANPackage createPackage(ObjectMapper mapper) throws Exception { protected CKANPackage createPackage(ObjectMapper mapper) throws Exception {
ObjectNode itemObjectNode = mapper.createObjectNode(); ObjectNode itemObjectNode = mapper.createObjectNode();
@ -159,7 +161,7 @@ public class CKANPackageTest extends ContextTest {
String readID = readItemObjectNode.get(CKANPackage.NAME_KEY).asText(); String readID = readItemObjectNode.get(CKANPackage.NAME_KEY).asText();
Assert.assertNotNull(readID); Assert.assertNotNull(readID);
Assert.assertTrue(ITEM_NAME_VALUE.compareTo(readID)==0); Assert.assertTrue(ITEM_NAME_VALUE.compareTo(readID) == 0);
String updatedNotes = "A research of Luca Frosini made during the PhD"; String updatedNotes = "A research of Luca Frosini made during the PhD";
((ObjectNode) readItemObjectNode).put(NOTES_KEY, updatedNotes); ((ObjectNode) readItemObjectNode).put(NOTES_KEY, updatedNotes);
@ -172,16 +174,15 @@ public class CKANPackageTest extends ContextTest {
((ObjectNode) readItemObjectNode).replace(CKANPackage.RESOURCES_KEY, resources); ((ObjectNode) readItemObjectNode).replace(CKANPackage.RESOURCES_KEY, resources);
ckanPackage = new CKANPackage(); ckanPackage = new CKANPackage();
ckanPackage.setName(ITEM_NAME_VALUE); ckanPackage.setName(ITEM_NAME_VALUE);
String updatedItem = ckanPackage.update(mapper.writeValueAsString(readItemObjectNode)); String updatedItem = ckanPackage.update(mapper.writeValueAsString(readItemObjectNode));
logger.trace(updatedItem); logger.trace(updatedItem);
JsonNode updatedItemObjectNode = mapper.readTree(updatedItem); JsonNode updatedItemObjectNode = mapper.readTree(updatedItem);
String gotUpdatedNotes = updatedItemObjectNode.get(NOTES_KEY).asText(); String gotUpdatedNotes = updatedItemObjectNode.get(NOTES_KEY).asText();
Assert.assertTrue(gotUpdatedNotes.compareTo(updatedNotes)==0); Assert.assertTrue(gotUpdatedNotes.compareTo(updatedNotes) == 0);
ckanPackage = new CKANPackage();
ckanPackage = new CKANPackage();
ckanPackage.setName(ITEM_NAME_VALUE); ckanPackage.setName(ITEM_NAME_VALUE);
((ObjectNode) updatedItemObjectNode).remove(CKANPackage.RESOURCES_KEY); ((ObjectNode) updatedItemObjectNode).remove(CKANPackage.RESOURCES_KEY);
String secondUpdateItem = ckanPackage.update(mapper.writeValueAsString(updatedItemObjectNode)); String secondUpdateItem = ckanPackage.update(mapper.writeValueAsString(updatedItemObjectNode));
@ -202,7 +203,7 @@ public class CKANPackageTest extends ContextTest {
Assert.assertTrue(gotPatchedNotes.compareTo(patchedNotes)==0); Assert.assertTrue(gotPatchedNotes.compareTo(patchedNotes)==0);
*/ */
ckanPackage = new CKANPackage(); ckanPackage = new CKANPackage();
ckanPackage.setName(ITEM_NAME_VALUE); ckanPackage.setName(ITEM_NAME_VALUE);
ckanPackage.purge(); ckanPackage.purge();
logger.debug("Item {} purge successfully", ITEM_NAME_VALUE); logger.debug("Item {} purge successfully", ITEM_NAME_VALUE);

View File

@ -84,16 +84,16 @@ public class CKANResourceTest extends ContextTest {
ckanResource.mimeType = "application/zip"; ckanResource.mimeType = "application/zip";
ckanResource.originalFileExtension = ".fskk"; ckanResource.originalFileExtension = ".fskk";
String format = ckanResource.getFormat(); String format = ckanResource.getFormat();
Assert.assertTrue(format.compareTo("fskk")==0); Assert.assertTrue(format.compareTo("fskk") == 0);
ckanResource.originalFileExtension = null; ckanResource.originalFileExtension = null;
format = ckanResource.getFormat(); format = ckanResource.getFormat();
Assert.assertTrue(format.compareTo("zip")==0); Assert.assertTrue(format.compareTo("zip") == 0);
ckanResource.mimeType = "image/jpeg"; ckanResource.mimeType = "image/jpeg";
format = ckanResource.getFormat(); format = ckanResource.getFormat();
Assert.assertTrue(format.compareTo("jpg")==0); Assert.assertTrue(format.compareTo("jpg") == 0);
} }
} }

View File

@ -27,7 +27,7 @@ public class CKANUserTest extends ContextTest {
@Test @Test
public void list() throws Exception { public void list() throws Exception {
CKANUser ckanUser = getCKANUser(); CKANUser ckanUser = getCKANUser();
String ret = ckanUser.list(-1,-1); String ret = ckanUser.list(-1, -1);
logger.debug("{}", ret); logger.debug("{}", ret);
} }
@ -53,7 +53,7 @@ public class CKANUserTest extends ContextTest {
String ret = ckanUser.read(); String ret = ckanUser.read();
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode readUser = mapper.readTree(ret); JsonNode readUser = mapper.readTree(ret);
((ObjectNode) readUser).put(CKANUser.EMAIL, USERNAME+"@gcube.ckan.org"); ((ObjectNode) readUser).put(CKANUser.EMAIL, USERNAME + "@gcube.ckan.org");
((ObjectNode) readUser).put("state", "active"); ((ObjectNode) readUser).put("state", "active");
ret = ckanUser.update(ckanUser.getAsString(readUser)); ret = ckanUser.update(ckanUser.getAsString(readUser));
logger.debug("{}", ret); logger.debug("{}", ret);
@ -65,14 +65,12 @@ public class CKANUserTest extends ContextTest {
ckanUser.delete(false); ckanUser.delete(false);
} }
@Test @Test
public void testAddSpecialUserToOrganization() throws Exception { public void testAddSpecialUserToOrganization() throws Exception {
CKANUser ckanUser = getCKANUser(); CKANUser ckanUser = getCKANUser();
ckanUser.addUserToOrganization(); ckanUser.addUserToOrganization();
} }
@Test @Test
public void checkAndUpdateInformation() throws Exception { public void checkAndUpdateInformation() throws Exception {
CKANUser ckanUser = CKANUserCache.getCurrrentCKANUser(); CKANUser ckanUser = CKANUserCache.getCurrrentCKANUser();

View File

@ -19,6 +19,4 @@ public class CKANUtilityTest extends ContextTest {
logger.debug("User {} has the following API key {}", CKANUser.getCKANUsername(), ckanAPI); logger.debug("User {} has the following API key {}", CKANUser.getCKANUsername(), ckanAPI);
} }
} }

View File

@ -25,7 +25,6 @@ public class ProfileTest extends ContextTest {
logger.debug("{}", arrayNode); logger.debug("{}", arrayNode);
} }
@Test @Test
public void read() throws Exception { public void read() throws Exception {
String profileID = "EmptyProfile"; String profileID = "EmptyProfile";
@ -75,8 +74,7 @@ public class ProfileTest extends ContextTest {
@Test @Test
public void testCreateUpdateDeleteGenericResource() throws Exception { public void testCreateUpdateDeleteGenericResource() throws Exception {
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(PROFILE_EXAMPLE_FILENAME); InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(PROFILE_EXAMPLE_FILENAME);
String xml = new BufferedReader(new InputStreamReader(inputStream)).lines() String xml = new BufferedReader(new InputStreamReader(inputStream)).lines().collect(Collectors.joining("\n"));
.collect(Collectors.joining("\n"));
logger.debug("Body\n{}", xml); logger.debug("Body\n{}", xml);
ISProfile profile = new ISProfile(); ISProfile profile = new ISProfile();
profile.createOrUpdate(PROFILE_NAME_EXAMPLE, xml); profile.createOrUpdate(PROFILE_NAME_EXAMPLE, xml);

View File

@ -16,7 +16,7 @@ public class ResourceTest extends ContextTest {
Resource resource = new Resource(); Resource resource = new Resource();
String itemID = ""; String itemID = "";
String resourceID = ""; String resourceID = "";
String ret = resource.read(itemID,resourceID); String ret = resource.read(itemID, resourceID);
logger.debug("{}", ret); logger.debug("{}", ret);
} }
} }

View File

@ -9,12 +9,10 @@ public class ConstantsTest extends ContextTest {
private static final Logger logger = LoggerFactory.getLogger(ConstantsTest.class); private static final Logger logger = LoggerFactory.getLogger(ConstantsTest.class);
@Test @Test
public void testGetApplicationToken() { public void testGetApplicationToken() {
logger.debug("Application token for Context {} is {}", ContextUtility.getCurrentContext(), Constants.getCatalogueApplicationToken()); logger.debug("Application token for Context {} is {}", ContextUtility.getCurrentContext(),
Constants.getCatalogueApplicationToken());
} }
} }

View File

@ -41,16 +41,13 @@ public class CatalogueStorageHubManagementTest extends ContextTest {
public static final String SHORT_URL_STRING = "https://goo.gl/HcUWni"; public static final String SHORT_URL_STRING = "https://goo.gl/HcUWni";
public static final URL SHORT_STORAGE_URL; public static final URL SHORT_STORAGE_URL;
public static final String MIME_TYPE = "application/pdf"; public static final String MIME_TYPE = "application/pdf";
static { static {
try { try {
ORIGINAL_STORAGE_URL = new URL(ORIGINAL_STORAGE_URL_STRING); ORIGINAL_STORAGE_URL = new URL(ORIGINAL_STORAGE_URL_STRING);
SHORT_STORAGE_URL = new URL(SHORT_URL_STRING); SHORT_STORAGE_URL = new URL(SHORT_URL_STRING);
}catch (Exception e) { } catch(Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -63,7 +60,6 @@ public class CatalogueStorageHubManagementTest extends ContextTest {
protected StorageHubManagement storageHubManagement; protected StorageHubManagement storageHubManagement;
protected CatalogueMetadata catalogueMetadata; protected CatalogueMetadata catalogueMetadata;
public CatalogueStorageHubManagementTest() { public CatalogueStorageHubManagementTest() {
catalogueStorageHubManagement = new CatalogueStorageHubManagement(); catalogueStorageHubManagement = new CatalogueStorageHubManagement();
storageHubManagement = catalogueStorageHubManagement.storageHubManagement; storageHubManagement = catalogueStorageHubManagement.storageHubManagement;
@ -73,51 +69,49 @@ public class CatalogueStorageHubManagementTest extends ContextTest {
@Test @Test
public void getFinalURL() { public void getFinalURL() {
URL finalURL = CKANResource.getFinalURL(SHORT_STORAGE_URL); URL finalURL = CKANResource.getFinalURL(SHORT_STORAGE_URL);
Assert.assertTrue(finalURL.toString().compareTo(ORIGINAL_STORAGE_URL_STRING)==0); Assert.assertTrue(finalURL.toString().compareTo(ORIGINAL_STORAGE_URL_STRING) == 0);
} }
protected void checkMetadata(FileContainer fileContainer, String version) { protected void checkMetadata(FileContainer fileContainer, String version) {
Metadata gotMetadata = fileContainer.get().getMetadata(); Metadata gotMetadata = fileContainer.get().getMetadata();
Map<String, Object> gotMap = gotMetadata.getMap(); Map<String,Object> gotMap = gotMetadata.getMap();
CatalogueMetadata catalogueMetadata = new CatalogueMetadata(ITEM_ID); CatalogueMetadata catalogueMetadata = new CatalogueMetadata(ITEM_ID);
Metadata expectedMetadata = catalogueMetadata.getMetadata(ORIGINAL_STORAGE_URL, fileContainer.get().getName(), RESOURCE_ID); Metadata expectedMetadata = catalogueMetadata.getMetadata(ORIGINAL_STORAGE_URL, fileContainer.get().getName(),
Map<String, Object> expectedMap = expectedMetadata.getMap(); RESOURCE_ID);
Map<String,Object> expectedMap = expectedMetadata.getMap();
for(String key : gotMap.keySet()) { for(String key : gotMap.keySet()) {
String value = (String) gotMap.get(key); String value = (String) gotMap.get(key);
if(key.compareTo(CatalogueMetadata.CATALOGUE_RESOURCE_REVISION_ID)==0) { if(key.compareTo(CatalogueMetadata.CATALOGUE_RESOURCE_REVISION_ID) == 0) {
Assert.assertTrue(value.compareTo(version)==0); Assert.assertTrue(value.compareTo(version) == 0);
}else { } else {
String expectedValue = (String) expectedMap.get(key); String expectedValue = (String) expectedMap.get(key);
Assert.assertTrue(value.compareTo(expectedValue)==0); Assert.assertTrue(value.compareTo(expectedValue) == 0);
} }
} }
} }
@Test @Test
public void testPersistence() throws Exception { public void testPersistence() throws Exception {
URL persistedURL = catalogueStorageHubManagement.ensureResourcePersistence(ORIGINAL_STORAGE_URL, ITEM_ID, RESOURCE_ID); URL persistedURL = catalogueStorageHubManagement.ensureResourcePersistence(ORIGINAL_STORAGE_URL, ITEM_ID,
RESOURCE_ID);
logger.debug("Publick Link of persisted file is {}", persistedURL); logger.debug("Publick Link of persisted file is {}", persistedURL);
Assert.assertTrue(catalogueStorageHubManagement.getMimeType().compareTo(MIME_TYPE)==0); Assert.assertTrue(catalogueStorageHubManagement.getMimeType().compareTo(MIME_TYPE) == 0);
FileContainer createdFileContainer = storageHubManagement.getCreatedFile(); FileContainer createdFileContainer = storageHubManagement.getCreatedFile();
String version = "2"; String version = "2";
catalogueStorageHubManagement.renameFile(RESOURCE_ID, version); catalogueStorageHubManagement.renameFile(RESOURCE_ID, version);
checkMetadata(createdFileContainer, version); checkMetadata(createdFileContainer, version);
version = "3"; version = "3";
catalogueStorageHubManagement.addRevisionID(RESOURCE_ID, version); catalogueStorageHubManagement.addRevisionID(RESOURCE_ID, version);
checkMetadata(createdFileContainer, version); checkMetadata(createdFileContainer, version);
catalogueStorageHubManagement.deleteResourcePersistence(ITEM_ID, RESOURCE_ID, MIME_TYPE); catalogueStorageHubManagement.deleteResourcePersistence(ITEM_ID, RESOURCE_ID, MIME_TYPE);
} }