All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.n2oapp.framework.config.selective.ION2oMetadataTester Maven / Gradle / Ivy

There is a newer version: 7.28.2
Show newest version
package net.n2oapp.framework.config.selective;

import net.n2oapp.framework.api.metadata.aware.NamespaceUriAware;
import net.n2oapp.framework.api.metadata.io.NamespaceIO;
import net.n2oapp.framework.api.pack.MetadataPack;
import net.n2oapp.framework.api.pack.XmlIOBuilder;
import net.n2oapp.framework.config.util.FileSystemUtil;
import org.springframework.core.io.ClassPathResource;

import java.util.function.Consumer;
import java.util.stream.Stream;

/**
 * Сервис тестирования чтения/записи метаданных
 */
public class ION2oMetadataTester implements XmlIOBuilder {

    private XmlIOReader xmlIOReader = new XmlIOReader();

    public ION2oMetadataTester() {
    }

    public ION2oMetadataTester(XmlIOReader xmlIOReader) {
        this.xmlIOReader = xmlIOReader;
    }

    public ION2oMetadataTester addIO(NamespaceIO io) {
        this.xmlIOReader.addIO(io);
        return this;
    }

    public ION2oMetadataTester addPack(MetadataPack pack) {
        pack.build(this);
        return this;
    }

    public  boolean isCheck(String path, Consumer checker) {
        String source = FileSystemUtil.getContentFromResource(new ClassPathResource(path));
        T t = xmlIOReader.read(source);
        if (checker != null)
            checker.accept(t);
        return xmlIOReader.persistAndCompareWithSample(t, source);
    }

    public  boolean check(String path, Consumer checker) {
        boolean check = isCheck(path, checker);
        assert check;
        return true;
    }

    public boolean check(String path) {
        assert isCheck(path, null);
        return true;
    }

    @Override
    @SafeVarargs
    public final ION2oMetadataTester ios(NamespaceIO... ios) {
        Stream.of(ios).forEach(this::addIO);
        return this;
    }

    @Override
    @SafeVarargs
    public final ION2oMetadataTester packs(MetadataPack... packs) {
        Stream.of(packs).forEach(p -> p.build(this));
        return this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy