diff --git a/.github/workflows/maven-build.yml b/.github/workflows/maven-build.yml index 7d4bc5c..3574760 100644 --- a/.github/workflows/maven-build.yml +++ b/.github/workflows/maven-build.yml @@ -28,7 +28,7 @@ jobs: java-version: ${{ matrix.java }} distribution: 'temurin' - name: Build with Maven - run: mvn -B install -Dgpg.skip=true --file pom.xml + run: mvn clean -B install -Dgpg.skip=true --file pom.xml - name: Upload surefire artifact uses: actions/upload-artifact@v4 if: failure() diff --git a/core/src/main/java/tech/illuin/wombat/core/activity/commons/TimeRange.java b/core/src/main/java/tech/illuin/wombat/core/activity/commons/TimeRange.java index bf4822e..3e014c9 100644 --- a/core/src/main/java/tech/illuin/wombat/core/activity/commons/TimeRange.java +++ b/core/src/main/java/tech/illuin/wombat/core/activity/commons/TimeRange.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import tech.illuin.wombat.core.activity.commons.validation.ValidTimeRange; import java.time.Duration; import java.time.Instant; @@ -12,6 +13,7 @@ import java.util.Collections; import java.util.List; +@ValidTimeRange public record TimeRange( @JsonProperty("start") Instant start, @JsonProperty("end") Instant end, diff --git a/core/src/main/java/tech/illuin/wombat/core/activity/commons/validation/TimeRangeValidator.java b/core/src/main/java/tech/illuin/wombat/core/activity/commons/validation/TimeRangeValidator.java new file mode 100644 index 0000000..72972ec --- /dev/null +++ b/core/src/main/java/tech/illuin/wombat/core/activity/commons/validation/TimeRangeValidator.java @@ -0,0 +1,16 @@ +package tech.illuin.wombat.core.activity.commons.validation; + +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; +import tech.illuin.wombat.core.activity.commons.TimeRange; + +public class TimeRangeValidator implements ConstraintValidator +{ + @Override + public boolean isValid(TimeRange value, ConstraintValidatorContext context) + { + if (value == null) + return true; + return value.start() != null && value.end() != null && value.start().isBefore(value.end()); + } +} diff --git a/core/src/main/java/tech/illuin/wombat/core/activity/commons/validation/ValidTimeRange.java b/core/src/main/java/tech/illuin/wombat/core/activity/commons/validation/ValidTimeRange.java new file mode 100644 index 0000000..38a7090 --- /dev/null +++ b/core/src/main/java/tech/illuin/wombat/core/activity/commons/validation/ValidTimeRange.java @@ -0,0 +1,23 @@ +package tech.illuin.wombat.core.activity.commons.validation; + +import jakarta.validation.Constraint; +import jakarta.validation.Payload; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = TimeRangeValidator.class) +@Documented +public @interface ValidTimeRange +{ + String message() default "TimeRange must have non-null start and end, and start must be before end"; + + Class[] groups() default {}; + + Class[] payload() default {}; +} diff --git a/core/src/main/java/tech/illuin/wombat/core/asset/Asset.java b/core/src/main/java/tech/illuin/wombat/core/asset/Asset.java index a03790b..9172c3e 100644 --- a/core/src/main/java/tech/illuin/wombat/core/asset/Asset.java +++ b/core/src/main/java/tech/illuin/wombat/core/asset/Asset.java @@ -7,7 +7,7 @@ import tech.illuin.wombat.core.asset.profile.AssetProfile; import tech.illuin.wombat.core.asset.type.AssetType; -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type", visible = true) public interface Asset { @NotNull @Valid diff --git a/core/src/main/java/tech/illuin/wombat/core/asset/AssetIdentity.java b/core/src/main/java/tech/illuin/wombat/core/asset/AssetIdentity.java index bf99932..d72d021 100644 --- a/core/src/main/java/tech/illuin/wombat/core/asset/AssetIdentity.java +++ b/core/src/main/java/tech/illuin/wombat/core/asset/AssetIdentity.java @@ -4,30 +4,44 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import jakarta.validation.constraints.NotBlank; +import tech.illuin.wombat.core.asset.type.AssetType; import java.util.Objects; +/** + * Identifies an asset, and names its {@link AssetType}. Embedded in an {@link Asset}, its {@code type} is the asset's + * own {@code type} property, which also selects the asset's class. + */ @JsonIgnoreProperties(ignoreUnknown = true) public record AssetIdentity( @NotBlank @JsonProperty("id") String id, @NotBlank @JsonProperty("environmentId") @JsonAlias("environment-id") String environmentId, - @NotBlank @JsonProperty("name") String name + @NotBlank @JsonProperty("name") String name, + @NotBlank @JsonProperty("type") String assetType ) { public AssetIdentity { Objects.requireNonNull(id, "id must not be null"); Objects.requireNonNull(environmentId, "environmentId must not be null"); Objects.requireNonNull(name, "name must not be null"); + Objects.requireNonNull(assetType, "assetType must not be null"); if (id.isBlank()) throw new IllegalArgumentException("id must not be blank"); if (environmentId.isBlank()) throw new IllegalArgumentException("environmentId must not be blank"); if (name.isBlank()) throw new IllegalArgumentException("name must not be blank"); + if (assetType.isBlank()) + throw new IllegalArgumentException("assetType must not be blank"); } - public static AssetIdentity of(String id, String environmentId, String name) + public static AssetIdentity of(String id, String environmentId, String name, String assetType) { - return new AssetIdentity(id, environmentId, name); + return new AssetIdentity(id, environmentId, name, assetType); + } + + public static AssetIdentity of(String id, String environmentId, String name, AssetType assetType) + { + return new AssetIdentity(id, environmentId, name, assetType.name()); } } diff --git a/core/src/main/java/tech/illuin/wombat/core/asset/SimulatedAsset.java b/core/src/main/java/tech/illuin/wombat/core/asset/SimulatedAsset.java index 3580695..f6b3aae 100644 --- a/core/src/main/java/tech/illuin/wombat/core/asset/SimulatedAsset.java +++ b/core/src/main/java/tech/illuin/wombat/core/asset/SimulatedAsset.java @@ -11,6 +11,6 @@ public interface SimulatedAsset extends Asset @Override default AssetIdentity identity() { - return AssetIdentity.of("simulated-asset", "simulated-environment", "simulated-asset"); + return AssetIdentity.of("simulated-asset", "simulated-environment", "simulated-asset", this.type()); } } diff --git a/core/src/main/java/tech/illuin/wombat/core/source/data/MetricData.java b/core/src/main/java/tech/illuin/wombat/core/source/data/MetricData.java index e4b4087..f0c7edb 100644 --- a/core/src/main/java/tech/illuin/wombat/core/source/data/MetricData.java +++ b/core/src/main/java/tech/illuin/wombat/core/source/data/MetricData.java @@ -1,7 +1,14 @@ package tech.illuin.wombat.core.source.data; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import tech.illuin.wombat.core.asset.type.ServiceFamily; +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "family") +@JsonSubTypes({ + @JsonSubTypes.Type(value = KubernetesData.class, name = "KUBERNETES_CONTAINER"), + @JsonSubTypes.Type(value = LLMData.class, name = "LLM"), +}) public interface MetricData { String serviceId(); diff --git a/core/src/test/java/tech/illuin/wombat/core/WombatCoreTest.java b/core/src/test/java/tech/illuin/wombat/core/WombatCoreTest.java index c06c7b3..0f19f12 100644 --- a/core/src/test/java/tech/illuin/wombat/core/WombatCoreTest.java +++ b/core/src/test/java/tech/illuin/wombat/core/WombatCoreTest.java @@ -190,7 +190,7 @@ private record SourceableAsset(String assetId) implements Asset, Monitorable @Override public AssetIdentity identity() { - return AssetIdentity.of(this.assetId, "env", this.assetId); + return AssetIdentity.of(this.assetId, "env", this.assetId, this.type()); } @Override @@ -218,7 +218,7 @@ private record ModeledAsset(String assetId) implements Asset @Override public AssetIdentity identity() { - return AssetIdentity.of(this.assetId, "env", this.assetId); + return AssetIdentity.of(this.assetId, "env", this.assetId, this.type()); } @Override diff --git a/core/src/test/java/tech/illuin/wombat/core/activity/commons/validation/TimeRangeValidatorTest.java b/core/src/test/java/tech/illuin/wombat/core/activity/commons/validation/TimeRangeValidatorTest.java new file mode 100644 index 0000000..99a2405 --- /dev/null +++ b/core/src/test/java/tech/illuin/wombat/core/activity/commons/validation/TimeRangeValidatorTest.java @@ -0,0 +1,52 @@ +package tech.illuin.wombat.core.activity.commons.validation; + +import org.junit.jupiter.api.Test; +import tech.illuin.wombat.core.activity.commons.TimeRange; + +import java.time.Instant; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class TimeRangeValidatorTest +{ + private final TimeRangeValidator validator = new TimeRangeValidator(); + + @Test + void nullRangeIsValid() + { + assertTrue(this.validator.isValid(null, null)); + } + + @Test + void missingEndpointsAreInvalid() + { + Instant instant = Instant.parse("2026-01-01T00:00:00Z"); + TimeRange missingStart = mock(TimeRange.class); + when(missingStart.end()).thenReturn(instant); + TimeRange missingEnd = mock(TimeRange.class); + when(missingEnd.start()).thenReturn(instant); + + assertFalse(this.validator.isValid(missingStart, null)); + assertFalse(this.validator.isValid(missingEnd, null)); + } + + @Test + void equalOrReversedEndpointsAreInvalid() + { + Instant instant = Instant.parse("2026-01-01T00:00:00Z"); + + assertFalse(this.validator.isValid(new TimeRange(instant, instant), null)); + assertFalse(this.validator.isValid(new TimeRange(instant.plusSeconds(1), instant), null)); + } + + @Test + void increasingEndpointsAreValid() + { + Instant start = Instant.parse("2026-01-01T00:00:00Z"); + + assertTrue(this.validator.isValid(new TimeRange(start, start.plusSeconds(1)), null)); + } +} \ No newline at end of file diff --git a/core/src/test/java/tech/illuin/wombat/core/asset/AssetIdentityTest.java b/core/src/test/java/tech/illuin/wombat/core/asset/AssetIdentityTest.java index e243c6e..3536d3a 100644 --- a/core/src/test/java/tech/illuin/wombat/core/asset/AssetIdentityTest.java +++ b/core/src/test/java/tech/illuin/wombat/core/asset/AssetIdentityTest.java @@ -1,6 +1,9 @@ package tech.illuin.wombat.core.asset; import org.junit.jupiter.api.Test; +import tech.illuin.wombat.core.asset.type.ActivityRegime; +import tech.illuin.wombat.core.asset.type.AssetType; +import tech.illuin.wombat.core.asset.type.ServiceFamily; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -8,43 +11,58 @@ class AssetIdentityTest { + private static final AssetType TYPE = AssetType.of("tech.illuin", "wombat-module", "llm-static", ActivityRegime.MODELED, ServiceFamily.LLM); + private static final String TYPE_NAME = TYPE.name(); + @Test void of_constructsValidAssetIdentity() { - AssetIdentity identity = AssetIdentity.of("asset-1", "env-prod", "my-asset"); + AssetIdentity identity = AssetIdentity.of("asset-1", "env-prod", "my-asset", TYPE_NAME); assertEquals("asset-1", identity.id()); assertEquals("env-prod", identity.environmentId()); assertEquals("my-asset", identity.name()); + assertEquals(TYPE_NAME, identity.assetType()); + } + + @Test + void of_namesTheGivenAssetType() + { + assertEquals(AssetIdentity.of("asset-1", "env-prod", "my-asset", TYPE_NAME), AssetIdentity.of("asset-1", "env-prod", "my-asset", TYPE)); } @Test void equalityAndHashCode_matchByValues() { - AssetIdentity id1 = AssetIdentity.of("asset-1", "env-prod", "my-asset"); - AssetIdentity id2 = new AssetIdentity("asset-1", "env-prod", "my-asset"); - AssetIdentity id3 = AssetIdentity.of("asset-2", "env-prod", "my-asset"); - AssetIdentity id4 = AssetIdentity.of("asset-1", "env-dev", "my-asset"); - AssetIdentity id5 = AssetIdentity.of("asset-1", "env-prod", "other-asset"); + AssetIdentity id1 = AssetIdentity.of("asset-1", "env-prod", "my-asset", TYPE_NAME); + AssetIdentity id2 = new AssetIdentity("asset-1", "env-prod", "my-asset", TYPE_NAME); + AssetIdentity id3 = AssetIdentity.of("asset-2", "env-prod", "my-asset", TYPE_NAME); + AssetIdentity id4 = AssetIdentity.of("asset-1", "env-dev", "my-asset", TYPE_NAME); + AssetIdentity id5 = AssetIdentity.of("asset-1", "env-prod", "other-asset", TYPE_NAME); + AssetIdentity id6 = AssetIdentity.of("asset-1", "env-prod", "my-asset", "tech.illuin.wombat-module.other"); assertEquals(id1, id2); assertEquals(id1.hashCode(), id2.hashCode()); assertNotEquals(id1, id3); assertNotEquals(id1, id4); assertNotEquals(id1, id5); + assertNotEquals(id1, id6); } @Test void constructor_rejectsNullOrBlankFields() { - assertThrows(NullPointerException.class, () -> new AssetIdentity(null, "env-prod", "my-asset")); - assertThrows(NullPointerException.class, () -> new AssetIdentity("asset-1", null, "my-asset")); - assertThrows(NullPointerException.class, () -> new AssetIdentity("asset-1", "env-prod", null)); - - assertThrows(IllegalArgumentException.class, () -> new AssetIdentity("", "env-prod", "my-asset")); - assertThrows(IllegalArgumentException.class, () -> new AssetIdentity(" ", "env-prod", "my-asset")); - assertThrows(IllegalArgumentException.class, () -> new AssetIdentity("asset-1", "", "my-asset")); - assertThrows(IllegalArgumentException.class, () -> new AssetIdentity("asset-1", " ", "my-asset")); - assertThrows(IllegalArgumentException.class, () -> new AssetIdentity("asset-1", "env-prod", "")); - assertThrows(IllegalArgumentException.class, () -> new AssetIdentity("asset-1", "env-prod", " ")); + assertThrows(NullPointerException.class, () -> new AssetIdentity(null, "env-prod", "my-asset", TYPE_NAME)); + assertThrows(NullPointerException.class, () -> new AssetIdentity("asset-1", null, "my-asset", TYPE_NAME)); + assertThrows(NullPointerException.class, () -> new AssetIdentity("asset-1", "env-prod", null, TYPE_NAME)); + assertThrows(NullPointerException.class, () -> new AssetIdentity("asset-1", "env-prod", "my-asset", null)); + + assertThrows(IllegalArgumentException.class, () -> new AssetIdentity("", "env-prod", "my-asset", TYPE_NAME)); + assertThrows(IllegalArgumentException.class, () -> new AssetIdentity(" ", "env-prod", "my-asset", TYPE_NAME)); + assertThrows(IllegalArgumentException.class, () -> new AssetIdentity("asset-1", "", "my-asset", TYPE_NAME)); + assertThrows(IllegalArgumentException.class, () -> new AssetIdentity("asset-1", " ", "my-asset", TYPE_NAME)); + assertThrows(IllegalArgumentException.class, () -> new AssetIdentity("asset-1", "env-prod", "", TYPE_NAME)); + assertThrows(IllegalArgumentException.class, () -> new AssetIdentity("asset-1", "env-prod", " ", TYPE_NAME)); + assertThrows(IllegalArgumentException.class, () -> new AssetIdentity("asset-1", "env-prod", "my-asset", "")); + assertThrows(IllegalArgumentException.class, () -> new AssetIdentity("asset-1", "env-prod", "my-asset", " ")); } } diff --git a/core/src/test/java/tech/illuin/wombat/core/connector/boavizta/impact/BoaviztaEvaluationResolverTest.java b/core/src/test/java/tech/illuin/wombat/core/connector/boavizta/impact/BoaviztaEvaluationResolverTest.java index 09c2016..6811968 100644 --- a/core/src/test/java/tech/illuin/wombat/core/connector/boavizta/impact/BoaviztaEvaluationResolverTest.java +++ b/core/src/test/java/tech/illuin/wombat/core/connector/boavizta/impact/BoaviztaEvaluationResolverTest.java @@ -131,7 +131,7 @@ private record TestAsset(AssetType type, AssetProfile profile) implements Asset @Override public AssetIdentity identity() { - return AssetIdentity.of("asset", "env", "Asset"); + return AssetIdentity.of("asset", "env", "Asset", this.type()); } } } diff --git a/core/src/test/java/tech/illuin/wombat/core/connector/ecologits/impact/EcologitsEvaluationResolverTest.java b/core/src/test/java/tech/illuin/wombat/core/connector/ecologits/impact/EcologitsEvaluationResolverTest.java index c0dcea6..2f7f7ef 100644 --- a/core/src/test/java/tech/illuin/wombat/core/connector/ecologits/impact/EcologitsEvaluationResolverTest.java +++ b/core/src/test/java/tech/illuin/wombat/core/connector/ecologits/impact/EcologitsEvaluationResolverTest.java @@ -118,7 +118,7 @@ private record TestAsset(AssetType type, AssetProfile profile) implements Asset @Override public AssetIdentity identity() { - return AssetIdentity.of("asset", "env", "Asset"); + return AssetIdentity.of("asset", "env", "Asset", this.type()); } } } diff --git a/core/src/test/java/tech/illuin/wombat/core/source/AssetMonitorTest.java b/core/src/test/java/tech/illuin/wombat/core/source/AssetMonitorTest.java index a411ef9..20d66b7 100644 --- a/core/src/test/java/tech/illuin/wombat/core/source/AssetMonitorTest.java +++ b/core/src/test/java/tech/illuin/wombat/core/source/AssetMonitorTest.java @@ -191,7 +191,7 @@ private record TestAsset(String assetId, AssetType type, Period period) implemen @Override public AssetIdentity identity() { - return AssetIdentity.of(this.assetId, "env", this.assetId); + return AssetIdentity.of(this.assetId, "env", this.assetId, this.type()); } @Override diff --git a/core/src/test/java/tech/illuin/wombat/core/source/data/MetricDataTest.java b/core/src/test/java/tech/illuin/wombat/core/source/data/MetricDataTest.java new file mode 100644 index 0000000..3612b45 --- /dev/null +++ b/core/src/test/java/tech/illuin/wombat/core/source/data/MetricDataTest.java @@ -0,0 +1,48 @@ +package tech.illuin.wombat.core.source.data; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; +import tech.illuin.wombat.core.activity.commons.Country; +import tech.illuin.wombat.core.asset.profile.LLMProvider; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; + +class MetricDataTest +{ + private static final ObjectMapper MAPPER = new ObjectMapper(); + + private static final KubernetesData KUBERNETES = new KubernetesData("api", "cluster", "namespace", "pod", 100.0, 2048.0); + private static final LLMData LLM = new LLMData("chat", LLMProvider.mistralai, "mistral-large-latest", Country.ofCode("FRA").orElseThrow(), 120L, 1L); + + @Test + void metricData_isTaggedWithItsFamily() + { + JsonNode kubernetes = MAPPER.valueToTree(KUBERNETES); + + assertEquals("KUBERNETES_CONTAINER", kubernetes.get("family").asText()); + assertEquals("LLM", MAPPER.valueToTree(LLM).get("family").asText()); + assertFalse(kubernetes.has("serviceFamily")); + } + + @Test + void metricData_roundTripsToItsVariant() throws Exception + { + for (MetricData data : List.of(KUBERNETES, LLM)) + assertEquals(data, MAPPER.readValue(MAPPER.writeValueAsString(data), MetricData.class)); + } + + @Test + void familyNames_matchTheServiceFamilyOfEachVariant() + { + for (JsonSubTypes.Type type : MetricData.class.getAnnotation(JsonSubTypes.class).value()) + { + MetricData sample = List.of(KUBERNETES, LLM).stream().filter(type.value()::isInstance).findFirst().orElseThrow(); + assertEquals(sample.serviceFamily().name(), type.name()); + } + } +} diff --git a/core/src/test/java/tech/illuin/wombat/core/source/persistence/micrometer/mapped/KubernetesMapperTest.java b/core/src/test/java/tech/illuin/wombat/core/source/persistence/micrometer/mapped/KubernetesMapperTest.java index ca86d96..f5364cc 100644 --- a/core/src/test/java/tech/illuin/wombat/core/source/persistence/micrometer/mapped/KubernetesMapperTest.java +++ b/core/src/test/java/tech/illuin/wombat/core/source/persistence/micrometer/mapped/KubernetesMapperTest.java @@ -20,7 +20,7 @@ class KubernetesMapperTest { private static final AssetType TYPE_KUBERNETES = AssetType.of("tech.illuin", "wombat-module", "kubernetes-prometheus", ActivityRegime.MEASURED, ServiceFamily.KUBERNETES_CONTAINER); - private static final AssetIdentity IDENTITY = AssetIdentity.of("asset-1", "env-1", "Asset 1"); + private static final AssetIdentity IDENTITY = AssetIdentity.of("asset-1", "env-1", "Asset 1", TYPE_KUBERNETES); private final KubernetesMapper mapper = new KubernetesMapper(); diff --git a/core/src/test/java/tech/illuin/wombat/core/source/persistence/micrometer/mapped/LLMMapperTest.java b/core/src/test/java/tech/illuin/wombat/core/source/persistence/micrometer/mapped/LLMMapperTest.java index 0a682b7..b71fd0c 100644 --- a/core/src/test/java/tech/illuin/wombat/core/source/persistence/micrometer/mapped/LLMMapperTest.java +++ b/core/src/test/java/tech/illuin/wombat/core/source/persistence/micrometer/mapped/LLMMapperTest.java @@ -22,7 +22,7 @@ class LLMMapperTest { private static final AssetType TYPE_LLM = AssetType.of("tech.illuin", "wombat-module", "llm-prometheus", ActivityRegime.MEASURED, ServiceFamily.LLM); - private static final AssetIdentity IDENTITY = AssetIdentity.of("asset-1", "env-1", "Asset 1"); + private static final AssetIdentity IDENTITY = AssetIdentity.of("asset-1", "env-1", "Asset 1", TYPE_LLM); private final LLMMapper mapper = new LLMMapper(); diff --git a/module/src/test/java/tech/illuin/wombat/module/AssetJsonTest.java b/module/src/test/java/tech/illuin/wombat/module/AssetJsonTest.java new file mode 100644 index 0000000..3e9df4e --- /dev/null +++ b/module/src/test/java/tech/illuin/wombat/module/AssetJsonTest.java @@ -0,0 +1,88 @@ +package tech.illuin.wombat.module; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; +import com.fasterxml.jackson.databind.jsontype.NamedType; +import org.junit.jupiter.api.Test; +import tech.illuin.wombat.core.activity.commons.Country; +import tech.illuin.wombat.core.asset.Asset; +import tech.illuin.wombat.core.asset.AssetIdentity; +import tech.illuin.wombat.core.asset.profile.LLMProvider; +import tech.illuin.wombat.module.llm_static.LLMStaticAsset; +import tech.illuin.wombat.module.llm_static.LLMStaticModule; +import tech.illuin.wombat.module.llm_static.LLMStaticProfile; +import tech.illuin.wombat.module.llm_static.scenario.ConstantScenario; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; + +/** + * The {@code type} property of an asset both selects its class and is its identity's {@link AssetIdentity#assetType()}. + */ +class AssetJsonTest +{ + private static final String TYPE = LLMStaticModule.TYPE.name(); + + private static final LLMStaticAsset ASSET = new LLMStaticAsset( + AssetIdentity.of("llm", "env", "LLM", LLMStaticModule.TYPE), + new LLMStaticProfile(List.of(new LLMStaticProfile.ModelConfig( + LLMProvider.mistralai, "mistral-large-latest", Country.FRANCE, List.of(new ConstantScenario(500, 1000, null)) + ))) + ); + + @Test + void read_fillsTheIdentityTypeFromTheTypeProperty() throws Exception + { + Asset asset = register(JsonMapper.builder().build()).readValue(""" + { + "type": "%s", + "id": "llm", + "environment-id": "env", + "name": "LLM", + "profile": { + "models": [{ + "provider": "mistralai", + "model": "mistral-large-latest", + "location": "FRA", + "scenarios": [{"type": "constant", "output-token-per-request": 500, "request-per-year": 1000}] + }] + } + } + """.formatted(TYPE), Asset.class); + + LLMStaticAsset read = assertInstanceOf(LLMStaticAsset.class, asset); + assertEquals(AssetIdentity.of("llm", "env", "LLM", TYPE), read.identity()); + } + + @Test + void write_emitsTheTypePropertyOnce() throws Exception + { + ObjectMapper mapper = register(JsonMapper.builder().build()); + String json = mapper.writeValueAsString(ASSET); + + JsonNode node = mapper.readTree(json); + assertEquals(TYPE, node.get("type").asText()); + assertEquals(1, json.split("\"type\":\"" + TYPE + "\"", -1).length - 1); + assertEquals(ASSET, mapper.readValue(json, Asset.class)); + } + + @Test + void identity_writesItsTypeOnItsOwn() throws Exception + { + ObjectMapper mapper = JsonMapper.builder().build(); + AssetIdentity identity = ASSET.identity(); + + assertEquals(TYPE, mapper.readTree(mapper.writeValueAsString(identity)).get("type").asText()); + assertEquals(identity, mapper.readValue(mapper.writeValueAsString(identity), AssetIdentity.class)); + } + + private static M register(M mapper) + { + mapper.findAndRegisterModules(); + mapper.registerSubtypes(new NamedType(LLMStaticAsset.class, TYPE)); + return mapper; + } +} diff --git a/module/src/test/java/tech/illuin/wombat/module/kubernetes_static/activity/KubernetesStaticActivityResolverTest.java b/module/src/test/java/tech/illuin/wombat/module/kubernetes_static/activity/KubernetesStaticActivityResolverTest.java index aac5cdd..1616bd3 100644 --- a/module/src/test/java/tech/illuin/wombat/module/kubernetes_static/activity/KubernetesStaticActivityResolverTest.java +++ b/module/src/test/java/tech/illuin/wombat/module/kubernetes_static/activity/KubernetesStaticActivityResolverTest.java @@ -1,6 +1,7 @@ package tech.illuin.wombat.module.kubernetes_static.activity; import org.junit.jupiter.api.Test; +import tech.illuin.wombat.module.kubernetes_static.KubernetesStaticModule; import tech.illuin.wombat.core.activity.commons.AssetActivity; import tech.illuin.wombat.core.activity.commons.Country; import tech.illuin.wombat.core.activity.commons.TimeRange; @@ -34,7 +35,7 @@ public class KubernetesStaticActivityResolverTest void resolvesConstantLoadIntoRelativeUsage() { KubernetesStaticAsset asset = new KubernetesStaticAsset( - new AssetIdentity("k8s-static-1", "env-test", "Static Cluster 1"), + AssetIdentity.of("k8s-static-1", "env-test", "Static Cluster 1", KubernetesStaticModule.TYPE), new KubernetesStaticProfile( ServerProvider.aws, "m5.xlarge", @@ -71,7 +72,7 @@ void resolvesSuperposedScenariosAcrossTimeSlots() { // Combine baseline (0.10), diurnal (0.10 -> 0.75, 09:00 - 18:00), batch (0.0 -> 0.90, 02:00 - 04:00) KubernetesStaticAsset asset = new KubernetesStaticAsset( - new AssetIdentity("k8s-static-2", "env-test", "Static Cluster 2"), + AssetIdentity.of("k8s-static-2", "env-test", "Static Cluster 2", KubernetesStaticModule.TYPE), new KubernetesStaticProfile( ServerProvider.aws, "c5.2xlarge", @@ -113,7 +114,7 @@ void resolvesSuperposedScenariosAcrossTimeSlots() void resolvesActivityForMultiNodeClusterWithoutPreMultiplyingLoad() { KubernetesStaticAsset asset = new KubernetesStaticAsset( - new AssetIdentity("k8s-static-3", "env-test", "Multi-Node Static Cluster"), + AssetIdentity.of("k8s-static-3", "env-test", "Multi-Node Static Cluster", KubernetesStaticModule.TYPE), new KubernetesStaticProfile( ServerProvider.aws, "m5.2xlarge", @@ -135,7 +136,7 @@ void resolvesActivityForMultiNodeClusterWithoutPreMultiplyingLoad() AssetActivity activity = result.get(); assertEquals(1, activity.activity().size()); - KubernetesActivityData k8sData = (KubernetesActivityData) activity.activity().get(0); + KubernetesActivityData k8sData = (KubernetesActivityData) activity.activity().getFirst(); assertEquals(ActivityRegime.MODELED, k8sData.regime()); // Emits single-node relative load 0.50 assertEquals(CPUUsage.relative(0.50), k8sData.cpuUsage()); @@ -145,7 +146,7 @@ void resolvesActivityForMultiNodeClusterWithoutPreMultiplyingLoad() void resolvesDailyResolutionWithHourlySampling() { KubernetesStaticAsset asset = new KubernetesStaticAsset( - new AssetIdentity("k8s-static-daily", "env-test", "Daily Static Cluster"), + AssetIdentity.of("k8s-static-daily", "env-test", "Daily Static Cluster", KubernetesStaticModule.TYPE), new KubernetesStaticProfile( ServerProvider.aws, "c5.2xlarge", diff --git a/module/src/test/java/tech/illuin/wombat/module/llm_anthropic/LLMAnthropicModuleTest.java b/module/src/test/java/tech/illuin/wombat/module/llm_anthropic/LLMAnthropicModuleTest.java index c44dd27..9f2d90d 100644 --- a/module/src/test/java/tech/illuin/wombat/module/llm_anthropic/LLMAnthropicModuleTest.java +++ b/module/src/test/java/tech/illuin/wombat/module/llm_anthropic/LLMAnthropicModuleTest.java @@ -65,7 +65,7 @@ void defaultsToThePublicApiUrl() private static LLMAnthropicAsset asset() { return new LLMAnthropicAsset( - AssetIdentity.of("a", "env", "A"), null, null, "ANTHROPIC_ADMIN_KEY", + AssetIdentity.of("a", "env", "A", LLMAnthropicModule.TYPE), null, null, "ANTHROPIC_ADMIN_KEY", new LLMAnthropicProfile(FRANCE, 500, null, null, null) ); } diff --git a/module/src/test/java/tech/illuin/wombat/module/llm_anthropic/activity/LLMAnthropicActivityResolverTest.java b/module/src/test/java/tech/illuin/wombat/module/llm_anthropic/activity/LLMAnthropicActivityResolverTest.java index d5aa2e4..6f33442 100644 --- a/module/src/test/java/tech/illuin/wombat/module/llm_anthropic/activity/LLMAnthropicActivityResolverTest.java +++ b/module/src/test/java/tech/illuin/wombat/module/llm_anthropic/activity/LLMAnthropicActivityResolverTest.java @@ -1,6 +1,7 @@ package tech.illuin.wombat.module.llm_anthropic.activity; import org.junit.jupiter.api.Test; +import tech.illuin.wombat.module.llm_anthropic.LLMAnthropicModule; import tech.illuin.wombat.core.activity.WombatActivityException; import tech.illuin.wombat.core.activity.commons.AssetActivity; import tech.illuin.wombat.core.activity.commons.TimeRange; @@ -40,7 +41,7 @@ class LLMAnthropicActivityResolverTest private final AnthropicAdminClient client = mock(AnthropicAdminClient.class); private final LLMAnthropicAsset asset = new LLMAnthropicAsset( - AssetIdentity.of("claude", "prod", "Claude"), null, null, "ANTHROPIC_ADMIN_KEY", + AssetIdentity.of("claude", "prod", "Claude", LLMAnthropicModule.TYPE), null, null, "ANTHROPIC_ADMIN_KEY", new LLMAnthropicProfile(FRANCE, 500, List.of("claude-opus-5-5"), null, null) ); private final LLMAnthropicActivityResolver resolver = new LLMAnthropicActivityResolver(multi(this.client)); @@ -101,7 +102,7 @@ void producesOneActivityPerResolutionSlotFromASingleReport() throws WombatActivi assertEquals(this.asset.identity(), activity.assetIdentity()); assertEquals(3, activity.activity().size()); - LLMActivityData h0 = (LLMActivityData) activity.activity().get(0); + LLMActivityData h0 = (LLMActivityData) activity.activity().getFirst(); assertEquals(new TimeRange(START, START.plusSeconds(3600), Duration.ofHours(1)), h0.range()); assertEquals(1000, h0.services().get("claude-opus-5-5").outputTokenCount()); assertEquals(250, h0.services().get("claude-haiku-5-5").outputTokenCount()); diff --git a/module/src/test/java/tech/illuin/wombat/module/llm_anthropic/connector/AnthropicMultiClientConfigTest.java b/module/src/test/java/tech/illuin/wombat/module/llm_anthropic/connector/AnthropicMultiClientConfigTest.java index 64b4bda..440dae7 100644 --- a/module/src/test/java/tech/illuin/wombat/module/llm_anthropic/connector/AnthropicMultiClientConfigTest.java +++ b/module/src/test/java/tech/illuin/wombat/module/llm_anthropic/connector/AnthropicMultiClientConfigTest.java @@ -3,6 +3,7 @@ import feign.Request; import feign.Response; import org.junit.jupiter.api.Test; +import tech.illuin.wombat.module.llm_anthropic.LLMAnthropicModule; import tech.illuin.wombat.core.asset.AssetIdentity; import tech.illuin.wombat.core.asset.Environment; import tech.illuin.wombat.core.context.ResolvedContext; @@ -56,7 +57,7 @@ void sendsAdminHeadersAndExpandsArrayParameters() }; LLMAnthropicAsset asset = new LLMAnthropicAsset( - AssetIdentity.of("claude", "prod", "Claude"), null, null, "ANTHROPIC_ADMIN_KEY", + AssetIdentity.of("claude", "prod", "Claude", LLMAnthropicModule.TYPE), null, null, "ANTHROPIC_ADMIN_KEY", new LLMAnthropicProfile(FRANCE, 500, null, null, null) ); ResolvedContext context = new ResolvedContext( diff --git a/module/src/test/java/tech/illuin/wombat/module/llm_prometheus/LLMPrometheusAssetTest.java b/module/src/test/java/tech/illuin/wombat/module/llm_prometheus/LLMPrometheusAssetTest.java index 134ea87..ceabc19 100644 --- a/module/src/test/java/tech/illuin/wombat/module/llm_prometheus/LLMPrometheusAssetTest.java +++ b/module/src/test/java/tech/illuin/wombat/module/llm_prometheus/LLMPrometheusAssetTest.java @@ -47,7 +47,7 @@ void aUsernameWithoutAPasswordVariableIsRejected() private static LLMPrometheusAsset asset(String username, String passwordEnv) { return new LLMPrometheusAsset( - AssetIdentity.of("p", "env", "P"), "http://prometheus", null, username, passwordEnv, Period.ZERO, + AssetIdentity.of("p", "env", "P", LLMPrometheusModule.TYPE), "http://prometheus", null, username, passwordEnv, Period.ZERO, new LLMPrometheusProfile(LLMProvider.mistralai, "m", FRANCE, new LLMPrometheusProfile.DynamicProfile("q")) ); } diff --git a/module/src/test/java/tech/illuin/wombat/module/llm_prometheus/LLMPrometheusModuleTest.java b/module/src/test/java/tech/illuin/wombat/module/llm_prometheus/LLMPrometheusModuleTest.java index c889b2a..fa9ee84 100644 --- a/module/src/test/java/tech/illuin/wombat/module/llm_prometheus/LLMPrometheusModuleTest.java +++ b/module/src/test/java/tech/illuin/wombat/module/llm_prometheus/LLMPrometheusModuleTest.java @@ -47,7 +47,7 @@ void sourcingABasicAuthAssetFailsWhenItsVariableIsUnset() // Proves the module builds its clients from the context's resolver: the credential is read from the // environment at source creation, never from the asset the reconciler persisted. LLMPrometheusAsset asset = new LLMPrometheusAsset( - AssetIdentity.of("p", "env", "P"), + AssetIdentity.of("p", "env", "P", LLMPrometheusModule.TYPE), "http://prometheus", null, "user", "PROM_PASSWORD", Period.ZERO, new LLMPrometheusProfile(LLMProvider.mistralai, "m", FRANCE, new LLMPrometheusProfile.DynamicProfile("q")) ); diff --git a/module/src/test/java/tech/illuin/wombat/module/llm_prometheus/connector/PrometheusMultiClientConfigTest.java b/module/src/test/java/tech/illuin/wombat/module/llm_prometheus/connector/PrometheusMultiClientConfigTest.java index ed53a98..6d2d70d 100644 --- a/module/src/test/java/tech/illuin/wombat/module/llm_prometheus/connector/PrometheusMultiClientConfigTest.java +++ b/module/src/test/java/tech/illuin/wombat/module/llm_prometheus/connector/PrometheusMultiClientConfigTest.java @@ -1,6 +1,7 @@ package tech.illuin.wombat.module.llm_prometheus.connector; import org.junit.jupiter.api.Test; +import tech.illuin.wombat.module.llm_prometheus.LLMPrometheusModule; import tech.illuin.wombat.core.asset.AssetIdentity; import tech.illuin.wombat.core.asset.Environment; import tech.illuin.wombat.core.asset.profile.LLMProvider; @@ -62,7 +63,7 @@ private static WombatContext context(Map environment, LLMPrometh private static LLMPrometheusAsset asset(String id, String username, String passwordEnv) { return new LLMPrometheusAsset( - AssetIdentity.of(id, "env", id), + AssetIdentity.of(id, "env", id, LLMPrometheusModule.TYPE), "http://prometheus", null, username, passwordEnv, Period.ZERO, new LLMPrometheusProfile(LLMProvider.mistralai, "m", FRANCE, new LLMPrometheusProfile.DynamicProfile("q")) ); diff --git a/module/src/test/java/tech/illuin/wombat/module/llm_prometheus/source/LLMPrometheusSourceTest.java b/module/src/test/java/tech/illuin/wombat/module/llm_prometheus/source/LLMPrometheusSourceTest.java index e542453..df82387 100644 --- a/module/src/test/java/tech/illuin/wombat/module/llm_prometheus/source/LLMPrometheusSourceTest.java +++ b/module/src/test/java/tech/illuin/wombat/module/llm_prometheus/source/LLMPrometheusSourceTest.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.databind.node.TextNode; import org.junit.jupiter.api.Test; +import tech.illuin.wombat.module.llm_prometheus.LLMPrometheusModule; import tech.illuin.wombat.core.activity.commons.Country; import tech.illuin.wombat.core.asset.AssetIdentity; import tech.illuin.wombat.core.asset.profile.LLMProvider; @@ -36,7 +37,7 @@ void sample_emitsLLMDataWithProviderModelAndLocation() new LLMPrometheusProfile.DynamicProfile("sum(vllm:num_tokens_total)") ); LLMPrometheusAsset asset = new LLMPrometheusAsset( - AssetIdentity.of("llm-prom", "prod", "Prom LLM"), + AssetIdentity.of("llm-prom", "prod", "Prom LLM", LLMPrometheusModule.TYPE), "http://localhost:9090", null, null, null, Period.ZERO, profile ); diff --git a/module/src/test/java/tech/illuin/wombat/module/llm_static/activity/LLMStaticActivityResolverTest.java b/module/src/test/java/tech/illuin/wombat/module/llm_static/activity/LLMStaticActivityResolverTest.java index cf2e5d2..b0f2307 100644 --- a/module/src/test/java/tech/illuin/wombat/module/llm_static/activity/LLMStaticActivityResolverTest.java +++ b/module/src/test/java/tech/illuin/wombat/module/llm_static/activity/LLMStaticActivityResolverTest.java @@ -1,6 +1,7 @@ package tech.illuin.wombat.module.llm_static.activity; import org.junit.jupiter.api.Test; +import tech.illuin.wombat.module.llm_static.LLMStaticModule; import tech.illuin.wombat.core.activity.commons.AssetActivity; import tech.illuin.wombat.core.activity.commons.AssetFilter; import tech.illuin.wombat.core.activity.commons.Country; @@ -52,7 +53,7 @@ void resolve_multiModelStaticProfile_computesActivityForEachModel() ); LLMStaticProfile profile = new LLMStaticProfile(List.of(m1, m2)); - LLMStaticAsset asset = new LLMStaticAsset(AssetIdentity.of("llm-asset", "test-env", "Test Static Asset"), profile); + LLMStaticAsset asset = new LLMStaticAsset(AssetIdentity.of("llm-asset", "test-env", "Test Static Asset", LLMStaticModule.TYPE), profile); // 100 seconds range TimeRange range = new TimeRange(Instant.ofEpochSecond(0), Instant.ofEpochSecond(100)); @@ -88,7 +89,7 @@ void resolve_multiModelStaticProfile_computesActivityForEachModel() void resolvesConstantScenarioAcrossTimeSlots() { LLMStaticAsset asset = new LLMStaticAsset( - new AssetIdentity("llm-static-1", "env-test", "Static LLM 1"), + AssetIdentity.of("llm-static-1", "env-test", "Static LLM 1", LLMStaticModule.TYPE), new LLMStaticProfile( LLMProvider.openai, "gpt-4o", @@ -129,7 +130,7 @@ void resolvesSuperposedScenariosAcrossTimeSlots() int batchTotalRequests = (int) (63_072_000 * (2.0 / 24.0) * 1.0); LLMStaticAsset asset = new LLMStaticAsset( - new AssetIdentity("llm-static-2", "env-test", "Static LLM 2"), + AssetIdentity.of("llm-static-2", "env-test", "Static LLM 2", LLMStaticModule.TYPE), new LLMStaticProfile( LLMProvider.openai, "gpt-4o", @@ -188,7 +189,7 @@ void resolvesFilteredModelsWithAssetFilter() ); LLMStaticProfile profile = new LLMStaticProfile(List.of(m1, m2)); - LLMStaticAsset asset = new LLMStaticAsset(AssetIdentity.of("llm-asset", "test-env", "Test Static Asset"), profile); + LLMStaticAsset asset = new LLMStaticAsset(AssetIdentity.of("llm-asset", "test-env", "Test Static Asset", LLMStaticModule.TYPE), profile); TimeRange range = new TimeRange(Instant.ofEpochSecond(0), Instant.ofEpochSecond(100)); AssetFilter filter = new AssetFilter(new AssetFilter.Environment("test-env", Set.of(new AssetFilter.Asset("llm-asset", Set.of("mistral-large-latest"))))); @@ -210,7 +211,7 @@ void resolvesDailyResolutionWithHourlySampling() int userTotalRequests = (int) (31_536_000 * (9.0 / 24.0) * (2.0 / Math.PI)); LLMStaticAsset asset = new LLMStaticAsset( - new AssetIdentity("llm-static-daily", "env-test", "Daily Static LLM"), + AssetIdentity.of("llm-static-daily", "env-test", "Daily Static LLM", LLMStaticModule.TYPE), new LLMStaticProfile( LLMProvider.openai, "gpt-4o", @@ -261,7 +262,7 @@ void resolvesDailyResolutionWithHourlySampling() void resolvesSevenDayAggregateBatchActivityScenario() { LLMStaticAsset asset = new LLMStaticAsset( - new AssetIdentity("llm-batch-7d", "env-test", "Batch 7D Asset"), + AssetIdentity.of("llm-batch-7d", "env-test", "Batch 7D Asset", LLMStaticModule.TYPE), new LLMStaticProfile( LLMProvider.openai, "gpt-4o", @@ -293,7 +294,7 @@ void resolvesFullYearSummationForUserActivityScenario() { int targetAnnualRequests = 100_000; LLMStaticAsset asset = new LLMStaticAsset( - new AssetIdentity("llm-user-year", "env-test", "User Year Asset"), + AssetIdentity.of("llm-user-year", "env-test", "User Year Asset", LLMStaticModule.TYPE), new LLMStaticProfile( LLMProvider.openai, "gpt-4o", @@ -324,7 +325,7 @@ void resolvesFullYearSummationForBatchActivityScenario() { int targetAnnualRequests = 50_000; LLMStaticAsset asset = new LLMStaticAsset( - new AssetIdentity("llm-batch-year", "env-test", "Batch Year Asset"), + AssetIdentity.of("llm-batch-year", "env-test", "Batch Year Asset", LLMStaticModule.TYPE), new LLMStaticProfile( LLMProvider.openai, "gpt-4o", @@ -356,7 +357,7 @@ void resolvesFullYearSummationWithMonthApplicabilityFilter() ApplicabilityFilter janFilter = new ApplicabilityFilter(Set.of(), Set.of(JANUARY)); LLMStaticAsset asset = new LLMStaticAsset( - new AssetIdentity("llm-jan-asset", "env-test", "Jan Only Asset"), + AssetIdentity.of("llm-jan-asset", "env-test", "Jan Only Asset", LLMStaticModule.TYPE), new LLMStaticProfile( LLMProvider.openai, "gpt-4o", @@ -401,7 +402,7 @@ void resolvesFullYearSummationWithWeekdayApplicabilityFilter() ); LLMStaticAsset asset = new LLMStaticAsset( - new AssetIdentity("llm-weekday-asset", "env-test", "Weekday Asset"), + AssetIdentity.of("llm-weekday-asset", "env-test", "Weekday Asset", LLMStaticModule.TYPE), new LLMStaticProfile( LLMProvider.openai, "gpt-4o", diff --git a/module/src/test/java/tech/illuin/wombat/module/llm_vertexai/LLMVertexAIAssetTest.java b/module/src/test/java/tech/illuin/wombat/module/llm_vertexai/LLMVertexAIAssetTest.java index ff1a883..68d30eb 100644 --- a/module/src/test/java/tech/illuin/wombat/module/llm_vertexai/LLMVertexAIAssetTest.java +++ b/module/src/test/java/tech/illuin/wombat/module/llm_vertexai/LLMVertexAIAssetTest.java @@ -2,7 +2,6 @@ import org.junit.jupiter.api.Test; import tech.illuin.wombat.core.asset.AssetIdentity; -import tech.illuin.wombat.core.activity.commons.Country; import java.util.Set; import java.util.List; @@ -48,7 +47,7 @@ void declaresTheLLMVertexAIAssetType() private static LLMVertexAIAsset asset(String credentialsKey) { - return new LLMVertexAIAsset(AssetIdentity.of("g", "env", "G"), "https://monitoring.googleapis.com", "projects/my-project", credentialsKey, + return new LLMVertexAIAsset(AssetIdentity.of("g", "env", "G", LLMVertexAIModule.TYPE), "https://monitoring.googleapis.com", "projects/my-project", credentialsKey, new LLMVertexAIProfile(500, List.of("gemini-2.5-flash"))); } } diff --git a/module/src/test/java/tech/illuin/wombat/module/llm_vertexai/LLMVertexAIModuleTest.java b/module/src/test/java/tech/illuin/wombat/module/llm_vertexai/LLMVertexAIModuleTest.java index d044392..63246ff 100644 --- a/module/src/test/java/tech/illuin/wombat/module/llm_vertexai/LLMVertexAIModuleTest.java +++ b/module/src/test/java/tech/illuin/wombat/module/llm_vertexai/LLMVertexAIModuleTest.java @@ -2,7 +2,6 @@ import org.junit.jupiter.api.Test; import tech.illuin.wombat.core.activity.WombatActivityResolver; -import tech.illuin.wombat.core.activity.commons.Country; import tech.illuin.wombat.core.asset.AssetIdentity; import tech.illuin.wombat.core.asset.Environment; import tech.illuin.wombat.core.context.ResolvedContext; @@ -71,7 +70,7 @@ private static ResolvedContext context(Map environment, LLMVerte private static LLMVertexAIAsset asset(String credentialsKey) { - return new LLMVertexAIAsset(AssetIdentity.of("g", "env", "G"), "https://monitoring.googleapis.com", "projects/my-project", credentialsKey, + return new LLMVertexAIAsset(AssetIdentity.of("g", "env", "G", LLMVertexAIModule.TYPE), "https://monitoring.googleapis.com", "projects/my-project", credentialsKey, new LLMVertexAIProfile(500, List.of("gemini-2.5-flash"))); } } diff --git a/module/src/test/java/tech/illuin/wombat/module/llm_vertexai/activity/LLMVertexAIActivityResolverTest.java b/module/src/test/java/tech/illuin/wombat/module/llm_vertexai/activity/LLMVertexAIActivityResolverTest.java index 19c3214..10250e9 100644 --- a/module/src/test/java/tech/illuin/wombat/module/llm_vertexai/activity/LLMVertexAIActivityResolverTest.java +++ b/module/src/test/java/tech/illuin/wombat/module/llm_vertexai/activity/LLMVertexAIActivityResolverTest.java @@ -4,6 +4,7 @@ import feign.FeignException; import feign.Request; import org.junit.jupiter.api.Test; +import tech.illuin.wombat.module.llm_vertexai.LLMVertexAIModule; import tech.illuin.wombat.core.activity.WombatActivityException; import tech.illuin.wombat.core.activity.commons.AssetActivity; import tech.illuin.wombat.core.activity.commons.AssetFilter; @@ -45,7 +46,7 @@ class LLMVertexAIActivityResolverTest private final GoogleClient client = mock(GoogleClient.class); private final LLMVertexAIAsset asset = new LLMVertexAIAsset( - AssetIdentity.of("llm-google", "prod", "Google LLM"), "https://monitoring.googleapis.com", PROJECT, null, + AssetIdentity.of("llm-google", "prod", "Google LLM", LLMVertexAIModule.TYPE), "https://monitoring.googleapis.com", PROJECT, null, new LLMVertexAIProfile(500, List.of(MODEL)) ); private final LLMVertexAIActivityResolver resolver = new LLMVertexAIActivityResolver(multi(this.client)); diff --git a/module/src/test/java/tech/illuin/wombat/module/llm_vertexai/connector/GoogleMultiClientConfigTest.java b/module/src/test/java/tech/illuin/wombat/module/llm_vertexai/connector/GoogleMultiClientConfigTest.java index 4510519..5e213da 100644 --- a/module/src/test/java/tech/illuin/wombat/module/llm_vertexai/connector/GoogleMultiClientConfigTest.java +++ b/module/src/test/java/tech/illuin/wombat/module/llm_vertexai/connector/GoogleMultiClientConfigTest.java @@ -3,9 +3,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.sun.net.httpserver.HttpServer; import org.junit.jupiter.api.Test; +import tech.illuin.wombat.module.llm_vertexai.LLMVertexAIModule; import tech.illuin.wombat.core.asset.AssetIdentity; import tech.illuin.wombat.core.asset.Environment; -import tech.illuin.wombat.core.activity.commons.Country; import tech.illuin.wombat.core.context.ResolvedContext; import tech.illuin.wombat.core.context.WombatContext; import tech.illuin.wombat.core.secret.EnvironmentSecretResolver; @@ -121,7 +121,7 @@ private static WombatContext context(Map environment, LLMVertexA private static LLMVertexAIAsset asset(String id, String credentialsKey) { - return new LLMVertexAIAsset(AssetIdentity.of(id, "env", id), "https://monitoring.googleapis.com", "projects/my-project", credentialsKey, + return new LLMVertexAIAsset(AssetIdentity.of(id, "env", id, LLMVertexAIModule.TYPE), "https://monitoring.googleapis.com", "projects/my-project", credentialsKey, new LLMVertexAIProfile(500, List.of("gemini-2.5-flash"))); } diff --git a/pom.xml b/pom.xml index ade9a76..1d35740 100644 --- a/pom.xml +++ b/pom.xml @@ -60,6 +60,7 @@ UTF-8 UTF-8 true + 53 13.17 @@ -168,6 +169,9 @@ org.apache.maven.plugins maven-surefire-plugin ${maven-surefire.version} + + @{argLine} -javaagent:${settings.localRepository}/org/mockito/mockito-core/${mockito.version}/mockito-core-${mockito.version}.jar +