net.openhft.chronicle.wire.utils.YamlTester Maven / Gradle / Ivy
/*
* Copyright 2016-2022 chronicle.software
*
* https://chronicle.software
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.openhft.chronicle.wire.utils;
import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.core.io.IORuntimeException;
import net.openhft.chronicle.wire.TextMethodTester;
import net.openhft.chronicle.wire.WireOut;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.util.*;
import java.util.function.Function;
/**
* The YamlTester interface provides utilities to perform testing on components using YAML configurations.
* It offers methods to run tests on given implementations using YAML files, compare them, and report any discrepancies.
* Two system properties can be set to influence the behavior of the tests:
*
*
* - regress.tests: If set to true, it overwrites the output YAML file instead of checking it.
* Though the test will still fail on an exception. This is useful to verify the reasonableness
* of the output changes while committing.
* - base.tests: If set to true, only the base tests are executed, skipping the generated tests.
*
*/
@Deprecated(/* to be moved in x.27 */)
public interface YamlTester {
/**
* System property to determine whether to overwrite the output YAML file.
*/
boolean REGRESS_TESTS = Jvm.getBoolean("regress.tests");
/**
* System property to determine whether to run only base tests.
*/
boolean BASE_TESTS = Jvm.getBoolean("base.tests");
/**
* Executes tests for a given implementation class using the specified YAML files. The method
* searches for a constructor in the implementation class that accepts a single interface argument
* and uses it to create an instance of the component.
*
* @param implClass Class of the implementation to be tested.
* @param path Directory path where the YAML files (in.yaml, out.yaml, and setup.yaml) are located.
* @return YamlTester instance containing the test results for comparison.
* @throws AssertionError If the test encounters issues or if the constructor doesn't match the expected format.
*/
@SuppressWarnings("unchecked")
static YamlTester runTest(Class> implClass, String path) throws AssertionError {
for (Constructor> cons : implClass.getDeclaredConstructors()) {
if (cons.getParameterCount() == 1) {
final Class>[] parameterTypes = cons.getParameterTypes();
if (parameterTypes[0].isInterface()) {
return runTest((Object out) -> {
try {
return cons.newInstance(out);
} catch (Exception e) {
throw new AssertionError(e);
}
}, (Class
© 2015 - 2025 Weber Informatics LLC | Privacy Policy