use of com.bakdata.conquery.io.jackson.Injectable in project conquery by bakdata.
the class SerializationTests method treeConcept.
@Test
public void treeConcept() throws IOException, JSONException {
Dataset dataset = new Dataset();
dataset.setName("datasetName");
TreeConcept concept = new TreeConcept();
concept.setDataset(dataset);
concept.setLabel("conceptLabel");
concept.setName("conceptName");
Table table = new Table();
Column column = new Column();
column.setLabel("colLabel");
column.setName("colName");
column.setType(MajorTypeId.STRING);
column.setTable(table);
Column dateColumn = new Column();
dateColumn.setLabel("colLabel2");
dateColumn.setName("colName2");
dateColumn.setType(MajorTypeId.DATE);
dateColumn.setTable(table);
table.setColumns(new Column[] { column, dateColumn });
table.setDataset(dataset);
table.setLabel("tableLabel");
table.setName("tableName");
column.setTable(table);
ConceptTreeConnector connector = new ConceptTreeConnector();
connector.setConcept(concept);
connector.setLabel("connLabel");
connector.setName("connName");
connector.setColumn(column);
concept.setConnectors(List.of(connector));
ValidityDate valDate = new ValidityDate();
valDate.setColumn(dateColumn);
valDate.setConnector(connector);
valDate.setLabel("valLabel");
valDate.setName("valName");
connector.setValidityDates(List.of(valDate));
CentralRegistry registry = new CentralRegistry();
registry.register(dataset);
registry.register(concept);
registry.register(column);
registry.register(dateColumn);
registry.register(table);
registry.register(connector);
registry.register(valDate);
final Validator validator = Validators.newValidator();
concept.setValidator(validator);
SerializationTestUtil.forType(TreeConcept.class).registry(registry).injectables(new Injectable() {
@Override
public MutableInjectableValues inject(MutableInjectableValues values) {
return values.add(Validator.class, validator);
}
}).test(concept);
}
use of com.bakdata.conquery.io.jackson.Injectable in project conquery by bakdata.
the class SerializationTests method table.
@Test
public void table() throws JSONException, IOException {
Dataset dataset = new Dataset();
dataset.setName("datasetName");
Table table = new Table();
Column column = new Column();
column.setLabel("colLabel");
column.setName("colName");
column.setType(MajorTypeId.STRING);
column.setTable(table);
table.setColumns(new Column[] { column });
table.setDataset(dataset);
table.setLabel("tableLabel");
table.setName("tableName");
CentralRegistry registry = new CentralRegistry();
registry.register(dataset);
registry.register(table);
registry.register(column);
final Validator validator = Validators.newValidator();
SerializationTestUtil.forType(Table.class).registry(registry).injectables(new Injectable() {
@Override
public MutableInjectableValues inject(MutableInjectableValues values) {
return values.add(Validator.class, validator);
}
}).test(table);
}
use of com.bakdata.conquery.io.jackson.Injectable in project conquery by bakdata.
the class SerializationTestUtil method test.
private void test(T value, T expected, ObjectMapper mapper) throws IOException {
if (registry != null) {
mapper = new SingletonNamespaceCollection(registry, registry).injectIntoNew(mapper);
}
for (Injectable injectable : injectables) {
mapper = injectable.injectIntoNew(mapper);
}
ObjectWriter writer = mapper.writerFor(type).withView(InternalOnly.class);
ObjectReader reader = mapper.readerFor(type).withView(InternalOnly.class);
ValidatorHelper.failOnError(log, validator.validate(value));
byte[] src = writer.writeValueAsBytes(value);
T copy = reader.readValue(src);
if (expected == null && copy == null) {
return;
}
ValidatorHelper.failOnError(log, validator.validate(copy));
// because IdentifiableImp cashes the hash
if (value instanceof IdentifiableImpl) {
assertThat(copy.hashCode()).isEqualTo(value.hashCode());
}
RecursiveComparisonAssert<?> ass = assertThat(copy).as("Unequal after copy.").usingRecursiveComparison();
ass.isEqualTo(expected);
}
use of com.bakdata.conquery.io.jackson.Injectable in project conquery by bakdata.
the class SerializationTests method bucketCompoundDateRange.
@Test
public void bucketCompoundDateRange() throws JSONException, IOException {
Dataset dataset = new Dataset();
dataset.setName("datasetName");
Table table = new Table();
Column startCol = new Column();
startCol.setName("startCol");
startCol.setType(MajorTypeId.DATE);
startCol.setTable(table);
Column endCol = new Column();
endCol.setLabel("endLabel");
endCol.setName("endCol");
endCol.setType(MajorTypeId.DATE);
endCol.setTable(table);
Column compoundCol = new Column();
compoundCol.setName("compoundCol");
compoundCol.setType(MajorTypeId.DATE_RANGE);
compoundCol.setTable(table);
table.setColumns(new Column[] { startCol, endCol, compoundCol });
table.setDataset(dataset);
table.setName("tableName");
Import imp = new Import(table);
imp.setName("importTest");
DateRangeTypeCompound compoundStore = new DateRangeTypeCompound(startCol.getName(), endCol.getName(), new BitSetStore(BitSet.valueOf(new byte[] { 0b1000 }), new BitSet(), 4));
// 0b1000 is a binary representation of 8 so that the 4th is set to make sure that BitSet length is 4.
ColumnStore startStore = new IntegerDateStore(new ShortArrayStore(new short[] { 1, 2, 3, 4 }, Short.MIN_VALUE));
ColumnStore endStore = new IntegerDateStore(new ShortArrayStore(new short[] { 5, 6, 7, 8 }, Short.MIN_VALUE));
Bucket bucket = new Bucket(0, 1, 4, new ColumnStore[] { startStore, endStore, compoundStore }, Collections.emptySet(), new int[0], new int[0], imp);
compoundStore.setParent(bucket);
CentralRegistry registry = new CentralRegistry();
registry.register(dataset);
registry.register(startCol);
registry.register(endCol);
registry.register(compoundCol);
registry.register(table);
registry.register(imp);
registry.register(bucket);
final Validator validator = Validators.newValidator();
SerializationTestUtil.forType(Bucket.class).registry(registry).injectables(new Injectable() {
@Override
public MutableInjectableValues inject(MutableInjectableValues values) {
return values.add(Validator.class, validator);
}
}).test(bucket);
}
use of com.bakdata.conquery.io.jackson.Injectable in project conquery by bakdata.
the class GroovyIndexedTest method init.
@BeforeAll
public static void init() throws IOException, JSONException, ConfigurationException {
ObjectNode node = Jackson.MAPPER.readerFor(ObjectNode.class).readValue(In.resource(GroovyIndexedTest.class, CONCEPT_SOURCE).asStream());
// load concept tree from json
CentralRegistry registry = new CentralRegistry();
Table table = new Table();
table.setName("the_table");
Dataset dataset = new Dataset();
dataset.setName("the_dataset");
registry.register(dataset);
table.setDataset(dataset);
Column column = new Column();
column.setName("the_column");
column.setType(MajorTypeId.STRING);
table.setColumns(new Column[] { column });
column.setTable(table);
registry.register(table);
registry.register(column);
// Prepare Serdes injections
final Validator validator = Validators.newValidator();
final ObjectReader conceptReader = new Injectable() {
@Override
public MutableInjectableValues inject(MutableInjectableValues values) {
return values.add(Validator.class, validator);
}
}.injectInto(registry.injectIntoNew(dataset.injectIntoNew(Jackson.MAPPER))).readerFor(Concept.class);
// load tree twice to to avoid references
indexedConcept = conceptReader.readValue(node);
indexedConcept.setDataset(dataset);
indexedConcept.initElements();
TreeChildPrefixIndex.putIndexInto(indexedConcept);
oldConcept = conceptReader.readValue(node);
oldConcept.setDataset(dataset);
oldConcept.initElements();
}
Aggregations