77 lines
2.7 KiB
Java
77 lines
2.7 KiB
Java
package org.gcube.application.geoportal.clients.serialization;
|
|
|
|
import ch.qos.logback.core.net.SyslogOutputStream;
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
import junit.framework.Assert;
|
|
import org.gcube.application.cms.tests.TestProfiles;
|
|
import org.gcube.application.geoportal.client.utils.Serialization;
|
|
import org.gcube.application.geoportal.common.model.JSONPathWrapper;
|
|
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
|
import org.gcube.application.geoportal.common.model.profile.Field;
|
|
import org.gcube.application.geoportal.common.model.profile.HandlerDeclaration;
|
|
import org.gcube.application.geoportal.common.model.profile.Profile;
|
|
import org.gcube.application.geoportal.common.utils.Files;
|
|
import org.junit.Test;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.nio.charset.Charset;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import static junit.framework.TestCase.assertEquals;
|
|
import static junit.framework.TestCase.assertTrue;
|
|
|
|
public class Profiles {
|
|
|
|
private static Profile readProfile(String file) throws IOException {
|
|
return Serialization.read(getJSON(file), Profile.class);
|
|
}
|
|
|
|
private static String getJSON(String file) throws IOException {
|
|
return Files.readFileAsString(
|
|
new File(TestProfiles.BASE_FOLDER,file).getAbsolutePath(), Charset.defaultCharset());
|
|
}
|
|
|
|
@Test
|
|
public void read () throws IOException {
|
|
for (Map.Entry<String, Profile> entry : TestProfiles.profiles.entrySet()) {
|
|
String s = entry.getKey();
|
|
Profile profile = entry.getValue();
|
|
System.out.println("Checking " + s);
|
|
|
|
validate(profile);
|
|
System.out.println(profile);
|
|
Profile converted = Serialization.convert(profile, Profile.class);
|
|
assertEquals(profile, converted);
|
|
JSONPathWrapper wrapper = new JSONPathWrapper(Serialization.asDocument(profile).toJson());
|
|
List<List> foundObjects = wrapper.getByPath("$." + Profile.HANDLERS, List.class);
|
|
|
|
foundObjects.get(0).forEach(o -> {
|
|
HandlerDeclaration h = Serialization.convert(o, HandlerDeclaration.class);
|
|
System.out.println(h);
|
|
validate(h);
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
|
|
private void validate(Profile profile){
|
|
assertTrue(profile.getId()!=null);
|
|
if(profile.getHandlers()!=null)
|
|
profile.getHandlers().forEach(handlerDeclaration -> validate(handlerDeclaration));
|
|
if(profile.getSchema()!=null)
|
|
validate(profile.getSchema());
|
|
|
|
}
|
|
private void validate(HandlerDeclaration handler){
|
|
assertTrue(handler.getId()!=null);
|
|
}
|
|
|
|
private void validate(Field f){
|
|
//assertTrue(f.getType()!=null);
|
|
|
|
}
|
|
}
|