Add failure test to DependencyResolverTest
All checks were successful
build-and-test / test (push) Successful in 1m15s
build-and-test / build (push) Successful in 1m26s
build-and-test / generate-javadoc (push) Successful in 1m25s

This commit is contained in:
JeremyStar™ 2024-09-01 21:21:26 +02:00
parent 25c9f45817
commit fbcb00c481
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D

View file

@ -19,6 +19,7 @@
package de.staropensource.sosengine.base.srctests.utility; package de.staropensource.sosengine.base.srctests.utility;
import de.staropensource.sosengine.base.Engine;
import de.staropensource.sosengine.base.exception.dependency.UnmetDependenciesException; import de.staropensource.sosengine.base.exception.dependency.UnmetDependenciesException;
import de.staropensource.sosengine.base.implementation.versioning.OneNumberVersioningSystem; import de.staropensource.sosengine.base.implementation.versioning.OneNumberVersioningSystem;
import de.staropensource.sosengine.base.srctests.TestBase; import de.staropensource.sosengine.base.srctests.TestBase;
@ -32,6 +33,8 @@ import org.junit.jupiter.params.provider.ValueSource;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/** /**
* Tests the class {@link DependencyResolver}. * Tests the class {@link DependencyResolver}.
*/ */
@ -42,7 +45,7 @@ class DependencyResolverTest extends TestBase {
@ValueSource(ints = { @ValueSource(ints = {
0, 1, 2, 3 0, 1, 2, 3
}) })
void testResolve(int layers) throws UnmetDependenciesException { void testResolve(int layers) {
if (isRestricted()) return; if (isRestricted()) return;
getLogger().testCall("testResolve", layers); getLogger().testCall("testResolve", layers);
@ -244,6 +247,221 @@ class DependencyResolverTest extends TestBase {
.build() .build()
); );
// Vector 7 // Vector 7
dependencies.add("test6<7900");
vectors.add(
new DependencyVector.Builder()
.setIdentifier("test7")
.setVersion("110")
.setVersioningSystem(OneNumberVersioningSystem.class)
.setDependencies(dependencies)
.build()
);
}
default -> {
getLogger().error("layers=" + layers + " is unimplemented");
throw new IllegalStateException("layers=" + layers + " is unimplemented");
}
}
resolver.addVectors(vectors);
try {
resolver.resolve();
} catch (UnmetDependenciesException exception) {
getLogger().error("Dependency resolution failed: Unmet dependencies found:");
for (DependencyVector vector : exception.getUnmetDependencies().keySet())
getLogger().error("-> " + vector.getIdentifier() + "=" + vector.getVersion() + ": " + exception.getUnmetDependencies().get(vector));
}
}
@ParameterizedTest
@DisplayName("resolve (failures)")
@ValueSource(ints = {
1, 2, 3
})
void testResolveWithFailure(int layers) {
if (isRestricted()) return;
getLogger().testCall("testResolveWithFailure", layers);
DependencyResolver resolver = new DependencyResolver();
Set<@NotNull DependencyVector> vectors = new HashSet<>();
Set<@NotNull String> dependencies = new HashSet<>();
switch (layers) {
case 1 -> {
// Vector 0
vectors.add(
new DependencyVector.Builder()
.setIdentifier("test0")
.setVersion("49")
.setVersioningSystem(OneNumberVersioningSystem.class)
.build()
);
// Vector 1
dependencies.add("test0>49");
vectors.add(
new DependencyVector.Builder()
.setIdentifier("test1")
.setVersion("999")
.setVersioningSystem(OneNumberVersioningSystem.class)
.setDependencies(dependencies)
.build()
);
// Vector 2
dependencies = new HashSet<>();
dependencies.add("test0=48");
vectors.add(
new DependencyVector.Builder()
.setIdentifier("test2")
.setVersion("666")
.setVersioningSystem(OneNumberVersioningSystem.class)
.setDependencies(dependencies)
.build()
);
// Vector 3
dependencies.add("test2>600<650");
vectors.add(
new DependencyVector.Builder()
.setIdentifier("test3")
.setVersion("6978")
.setVersioningSystem(OneNumberVersioningSystem.class)
.setDependencies(dependencies)
.build()
);
}
case 2 -> {
// Vector 0
vectors.add(
new DependencyVector.Builder()
.setIdentifier("test0")
.setVersion("49")
.setVersioningSystem(OneNumberVersioningSystem.class)
.build()
);
// Vector 1
dependencies.add("testNULL");
vectors.add(
new DependencyVector.Builder()
.setIdentifier("test1")
.setVersion("999")
.setVersioningSystem(OneNumberVersioningSystem.class)
.setDependencies(dependencies)
.build()
);
// Vector 2
dependencies = new HashSet<>();
dependencies.add("test1>999");
vectors.add(
new DependencyVector.Builder()
.setIdentifier("test2")
.setVersion("666")
.setVersioningSystem(OneNumberVersioningSystem.class)
.setDependencies(dependencies)
.build()
);
// Vector 3
vectors.add(
new DependencyVector.Builder()
.setIdentifier("test3")
.setVersion("49")
.setVersioningSystem(OneNumberVersioningSystem.class)
.build()
);
// Vector 4
dependencies = new HashSet<>();
dependencies.add("test3=50");
vectors.add(
new DependencyVector.Builder()
.setIdentifier("test4")
.setVersion("999")
.setVersioningSystem(OneNumberVersioningSystem.class)
.setDependencies(dependencies)
.build()
);
// Vector 5
dependencies.add("test4<998>990");
vectors.add(
new DependencyVector.Builder()
.setIdentifier("test5")
.setVersion("6978")
.setVersioningSystem(OneNumberVersioningSystem.class)
.setDependencies(dependencies)
.build()
);
}
case 3 -> {
// Vector 0
vectors.add(
new DependencyVector.Builder()
.setIdentifier("test0")
.setVersion("49")
.setVersioningSystem(OneNumberVersioningSystem.class)
.build()
);
// Vector 1
dependencies.add("shrek");
vectors.add(
new DependencyVector.Builder()
.setIdentifier("test1")
.setVersion("999")
.setVersioningSystem(OneNumberVersioningSystem.class)
.setDependencies(dependencies)
.build()
);
// Vector 2
dependencies = new HashSet<>();
dependencies.add("test1");
vectors.add(
new DependencyVector.Builder()
.setIdentifier("test2")
.setVersion("666")
.setVersioningSystem(OneNumberVersioningSystem.class)
.setDependencies(dependencies)
.build()
);
// Vector 3
dependencies = new HashSet<>();
dependencies.add("test2<600");
vectors.add(
new DependencyVector.Builder()
.setIdentifier("test3")
.setVersion("666")
.setVersioningSystem(OneNumberVersioningSystem.class)
.setDependencies(dependencies)
.build()
);
// Vector 4
vectors.add(
new DependencyVector.Builder()
.setIdentifier("test4")
.setVersion("49")
.setVersioningSystem(OneNumberVersioningSystem.class)
.build()
);
// Vector 5
dependencies = new HashSet<>();
dependencies.add("test4>50");
vectors.add(
new DependencyVector.Builder()
.setIdentifier("test5")
.setVersion("999")
.setVersioningSystem(OneNumberVersioningSystem.class)
.setDependencies(dependencies)
.build()
);
// Vector 6
dependencies.add("test5>998<100");
vectors.add(
new DependencyVector.Builder()
.setIdentifier("test6")
.setVersion("6978")
.setVersioningSystem(OneNumberVersioningSystem.class)
.setDependencies(dependencies)
.build()
);
// Vector 7
dependencies.add("test6>7900"); dependencies.add("test6>7900");
vectors.add( vectors.add(
new DependencyVector.Builder() new DependencyVector.Builder()
@ -263,15 +481,14 @@ class DependencyResolverTest extends TestBase {
resolver.addVectors(vectors); resolver.addVectors(vectors);
try { try {
resolver.resolve(); resolver.resolve();
} catch (Throwable throwable) { } catch (UnmetDependenciesException exception) {
if (throwable instanceof UnmetDependenciesException exception) { getLogger().error("Dependency resolution failed (great!): Unmet dependencies found:");
getLogger().error("Dependency resolution failed: Unmet dependencies found:");
for (DependencyVector vector : exception.getUnmetDependencies().keySet()) for (DependencyVector vector : exception.getUnmetDependencies().keySet())
getLogger().error("-> " + vector.getIdentifier() + "=" + vector.getVersion() + ": " + exception.getUnmetDependencies().get(vector)); getLogger().error("-> " + vector.getIdentifier() + "=" + vector.getVersion() + ": " + exception.getUnmetDependencies().get(vector));
} else
getLogger().error("Dependency resolution failed: " + throwable.getMessage());
throw throwable; return;
} }
assertNotNull(Engine.getInstance(), "Dependency resolution succeeded (layers=" + layers + ")");
} }
} }