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
public void list() throws Exception {
CKANLicense license = new CKANLicense();
license.list(-1,-1);
license.list(-1, -1);
JsonNode gotList = license.getJsonNodeResult();
Assert.assertTrue(gotList instanceof ArrayNode);
ObjectMapper mapper = new ObjectMapper();
@ -34,7 +34,7 @@ public class CKANLicenseTest extends ContextTest {
@Test
public void testCheckLicense() throws Exception {
ArrayNode arrayNode = CKANLicense.getLicenses();
for(JsonNode jsonNode : arrayNode){
for(JsonNode jsonNode : arrayNode) {
String licenseId = jsonNode.get(CKAN.ID_KEY).asText();
assertTrue(CKANLicense.checkLicenseId(arrayNode, 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 EXTRAS_TYPE_VALUE_VALUE = "TestEmptyProfile";
@Test
public void list() throws Exception {
CKANPackage ckanPackage = new CKANPackage();
ObjectMapper mapper = new ObjectMapper();
String ret = ckanPackage.list(-1,0);
String ret = ckanPackage.list(-1, 0);
JsonNode gotList = mapper.readTree(ret);
Assert.assertTrue(gotList instanceof ArrayNode);
logger.debug("List :\n{}", mapper.writeValueAsString(gotList));
@ -61,15 +60,19 @@ public class CKANPackageTest extends ContextTest {
@Test
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-test+test-test", false); // Fails for +
stringsToTest.put("t", false); // Fails because is too short. Min length is 2 characters
stringsToTest.put("te", 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
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()) {
boolean match = testString.matches(CKANPackage.NAME_REGEX);
@ -79,7 +82,6 @@ public class CKANPackageTest extends ContextTest {
}
protected CKANPackage createPackage(ObjectMapper mapper) throws Exception {
ObjectNode itemObjectNode = mapper.createObjectNode();
@ -159,7 +161,7 @@ public class CKANPackageTest extends ContextTest {
String readID = readItemObjectNode.get(CKANPackage.NAME_KEY).asText();
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";
((ObjectNode) readItemObjectNode).put(NOTES_KEY, updatedNotes);
@ -172,16 +174,15 @@ public class CKANPackageTest extends ContextTest {
((ObjectNode) readItemObjectNode).replace(CKANPackage.RESOURCES_KEY, resources);
ckanPackage = new CKANPackage();
ckanPackage = new CKANPackage();
ckanPackage.setName(ITEM_NAME_VALUE);
String updatedItem = ckanPackage.update(mapper.writeValueAsString(readItemObjectNode));
logger.trace(updatedItem);
JsonNode updatedItemObjectNode = mapper.readTree(updatedItem);
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);
((ObjectNode) updatedItemObjectNode).remove(CKANPackage.RESOURCES_KEY);
String secondUpdateItem = ckanPackage.update(mapper.writeValueAsString(updatedItemObjectNode));
@ -202,7 +203,7 @@ public class CKANPackageTest extends ContextTest {
Assert.assertTrue(gotPatchedNotes.compareTo(patchedNotes)==0);
*/
ckanPackage = new CKANPackage();
ckanPackage = new CKANPackage();
ckanPackage.setName(ITEM_NAME_VALUE);
ckanPackage.purge();
logger.debug("Item {} purge successfully", ITEM_NAME_VALUE);

View File

@ -46,7 +46,7 @@ public class CKANResourceTest extends ContextTest {
// @Test
public void testCopyStorageResource() throws Exception {
URL url = new URL("https://goo.gl/HcUWni");
URL url = new URL("https://goo.gl/HcUWni");
String itemID = UUID.randomUUID().toString();
CKANResource ckanResource = new CKANResource(itemID);
@ -84,16 +84,16 @@ public class CKANResourceTest extends ContextTest {
ckanResource.mimeType = "application/zip";
ckanResource.originalFileExtension = ".fskk";
String format = ckanResource.getFormat();
Assert.assertTrue(format.compareTo("fskk")==0);
String format = ckanResource.getFormat();
Assert.assertTrue(format.compareTo("fskk") == 0);
ckanResource.originalFileExtension = null;
format = ckanResource.getFormat();
Assert.assertTrue(format.compareTo("zip")==0);
format = ckanResource.getFormat();
Assert.assertTrue(format.compareTo("zip") == 0);
ckanResource.mimeType = "image/jpeg";
format = ckanResource.getFormat();
Assert.assertTrue(format.compareTo("jpg")==0);
format = ckanResource.getFormat();
Assert.assertTrue(format.compareTo("jpg") == 0);
}
}

View File

@ -23,11 +23,11 @@ public class CKANUserTest extends ContextTest {
user.setName(USERNAME);
return user;
}
@Test
public void list() throws Exception {
CKANUser ckanUser = getCKANUser();
String ret = ckanUser.list(-1,-1);
String ret = ckanUser.list(-1, -1);
logger.debug("{}", ret);
}
@ -53,7 +53,7 @@ public class CKANUserTest extends ContextTest {
String ret = ckanUser.read();
ObjectMapper mapper = new ObjectMapper();
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");
ret = ckanUser.update(ckanUser.getAsString(readUser));
logger.debug("{}", ret);
@ -65,14 +65,12 @@ public class CKANUserTest extends ContextTest {
ckanUser.delete(false);
}
@Test
public void testAddSpecialUserToOrganization() throws Exception {
CKANUser ckanUser = getCKANUser();
ckanUser.addUserToOrganization();
}
@Test
public void checkAndUpdateInformation() throws Exception {
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);
}
}

View File

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

View File

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

View File

@ -9,12 +9,10 @@ public class ConstantsTest extends ContextTest {
private static final Logger logger = LoggerFactory.getLogger(ConstantsTest.class);
@Test
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 URL SHORT_STORAGE_URL;
public static final String MIME_TYPE = "application/pdf";
static {
try {
ORIGINAL_STORAGE_URL = new URL(ORIGINAL_STORAGE_URL_STRING);
SHORT_STORAGE_URL = new URL(SHORT_URL_STRING);
}catch (Exception e) {
} catch(Exception e) {
throw new RuntimeException(e);
}
@ -63,7 +60,6 @@ public class CatalogueStorageHubManagementTest extends ContextTest {
protected StorageHubManagement storageHubManagement;
protected CatalogueMetadata catalogueMetadata;
public CatalogueStorageHubManagementTest() {
catalogueStorageHubManagement = new CatalogueStorageHubManagement();
storageHubManagement = catalogueStorageHubManagement.storageHubManagement;
@ -73,51 +69,49 @@ public class CatalogueStorageHubManagementTest extends ContextTest {
@Test
public void getFinalURL() {
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) {
Metadata gotMetadata = fileContainer.get().getMetadata();
Map<String, Object> gotMap = gotMetadata.getMap();
Map<String,Object> gotMap = gotMetadata.getMap();
CatalogueMetadata catalogueMetadata = new CatalogueMetadata(ITEM_ID);
Metadata expectedMetadata = catalogueMetadata.getMetadata(ORIGINAL_STORAGE_URL, fileContainer.get().getName(), RESOURCE_ID);
Map<String, Object> expectedMap = expectedMetadata.getMap();
Metadata expectedMetadata = catalogueMetadata.getMetadata(ORIGINAL_STORAGE_URL, fileContainer.get().getName(),
RESOURCE_ID);
Map<String,Object> expectedMap = expectedMetadata.getMap();
for(String key : gotMap.keySet()) {
String value = (String) gotMap.get(key);
if(key.compareTo(CatalogueMetadata.CATALOGUE_RESOURCE_REVISION_ID)==0) {
Assert.assertTrue(value.compareTo(version)==0);
}else {
if(key.compareTo(CatalogueMetadata.CATALOGUE_RESOURCE_REVISION_ID) == 0) {
Assert.assertTrue(value.compareTo(version) == 0);
} else {
String expectedValue = (String) expectedMap.get(key);
Assert.assertTrue(value.compareTo(expectedValue)==0);
Assert.assertTrue(value.compareTo(expectedValue) == 0);
}
}
}
@Test
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);
Assert.assertTrue(catalogueStorageHubManagement.getMimeType().compareTo(MIME_TYPE)==0);
Assert.assertTrue(catalogueStorageHubManagement.getMimeType().compareTo(MIME_TYPE) == 0);
FileContainer createdFileContainer = storageHubManagement.getCreatedFile();
String version = "2";
catalogueStorageHubManagement.renameFile(RESOURCE_ID, version);
checkMetadata(createdFileContainer, version);
version = "3";
catalogueStorageHubManagement.addRevisionID(RESOURCE_ID, version);
checkMetadata(createdFileContainer, version);
catalogueStorageHubManagement.deleteResourcePersistence(ITEM_ID, RESOURCE_ID, MIME_TYPE);
}