dnet-hadoop/dhp-schemas/src/test/java/eu/dnetlib/dhp/schema/oaf/MeasureTest.java

49 lines
1.4 KiB
Java
Raw Normal View History

2020-05-04 16:44:13 +02:00
package eu.dnetlib.dhp.schema.oaf;
import com.fasterxml.jackson.annotation.JsonInclude;
2020-05-04 17:02:40 +02:00
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.IOException;
2020-05-04 17:02:40 +02:00
import java.util.List;
2020-05-04 16:44:13 +02:00
public class MeasureTest {
public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper()
.setSerializationInclusion(JsonInclude.Include.NON_NULL);
@Test
public void testMeasureSerialization() throws IOException {
2020-05-04 17:02:40 +02:00
Measure popularity = new Measure();
popularity.setId("popularity");
popularity.setUnit(Lists.newArrayList(
unit("score", "0.5")));
2020-05-04 17:02:40 +02:00
Measure influence = new Measure();
influence.setId("influence");
influence.setUnit(Lists.newArrayList(
unit("score", "0.3")));
List<Measure> m = Lists.newArrayList(popularity, influence);
String s = OBJECT_MAPPER.writeValueAsString(m);
System.out.println(s);
2020-05-04 17:02:40 +02:00
List<Measure> mm = OBJECT_MAPPER.readValue(s, new TypeReference<List<Measure>>() { });
Assertions.assertNotNull(mm);
}
private KeyValue unit(String key, String value) {
KeyValue unit = new KeyValue();
unit.setKey(key);
unit.setValue(value);
return unit;
}
2020-05-04 16:44:13 +02:00
}