From ede9281804e493bacb640c68a72d1ff40830ad88 Mon Sep 17 00:00:00 2001 From: Frank Delporte Date: Thu, 13 Jun 2024 18:17:08 +0200 Subject: [PATCH] Fix for #11 + full actuator info --- .../sample/app/ContextConfigurationTests.java | 36 --------------- .../boot/Pi4jActuatorConfiguration.java | 11 +---- .../boot/ContextAutoConfigurationTests.java | 46 ------------------- 3 files changed, 1 insertion(+), 92 deletions(-) diff --git a/pi4j-spring-boot-starter-sample-app/src/test/java/com/pi4j/spring/boot/sample/app/ContextConfigurationTests.java b/pi4j-spring-boot-starter-sample-app/src/test/java/com/pi4j/spring/boot/sample/app/ContextConfigurationTests.java index 698cc11..c4d38e2 100644 --- a/pi4j-spring-boot-starter-sample-app/src/test/java/com/pi4j/spring/boot/sample/app/ContextConfigurationTests.java +++ b/pi4j-spring-boot-starter-sample-app/src/test/java/com/pi4j/spring/boot/sample/app/ContextConfigurationTests.java @@ -1,14 +1,9 @@ package com.pi4j.spring.boot.sample.app; -import com.pi4j.context.Context; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.autoconfigure.AutoConfigurations.of; public class ContextConfigurationTests { @@ -22,37 +17,6 @@ public class ContextConfigurationTests { ); - @ParameterizedTest - @ValueSource(strings = {"armv6l", "armv7l", "armv8l", "aarch64"}) - void whenOsArchIsProvided_verifyContextExists(String propertyName) { - - this.contextRunner - .withPropertyValues(String.format("os.arch:%s", propertyName)) - .run(context -> { - - assertThat(context.getEnvironment().containsProperty("os.arch")).isTrue(); - assertThat(context.getEnvironment().getProperty("os.arch")).isEqualTo(propertyName); - assertThat(context).hasSingleBean(Context.class); - - }); - - } - - @Test - void whenOsArchIsNotExpected_verifyContextDoesNotExist() { - - this.contextRunner - .withPropertyValues("os.arch:other") - .run(context -> { - - assertThat(context.getEnvironment().containsProperty("os.arch")).isTrue(); - assertThat(context.getEnvironment().getProperty("os.arch")).isEqualTo("other"); - assertThat(context).doesNotHaveBean(Context.class); - - }); - - } - @SpringBootConfiguration @EnableAutoConfiguration static class TestConfiguration { diff --git a/pi4j-spring-boot/src/main/java/com/pi4j/spring/boot/Pi4jActuatorConfiguration.java b/pi4j-spring-boot/src/main/java/com/pi4j/spring/boot/Pi4jActuatorConfiguration.java index 25e6e4f..e261f14 100644 --- a/pi4j-spring-boot/src/main/java/com/pi4j/spring/boot/Pi4jActuatorConfiguration.java +++ b/pi4j-spring-boot/src/main/java/com/pi4j/spring/boot/Pi4jActuatorConfiguration.java @@ -55,29 +55,24 @@ public void contribute(Builder builder) { builder.withDetail("reading.volt.value", boardReading.getVoltValue()); builder.withDetail("reading.temperature.celsius", boardReading.getTemperatureInCelsius()); builder.withDetail("reading.temperature.fahrenheit", boardReading.getTemperatureInFahrenheit()); - builder.withDetail("reading.uptime", boardReading.getUptimeInfo()); + builder.withDetail("reading.uptime", boardReading.getUptimeInfo().trim()); try { - // TODO https://github.com/Pi4J/pi4j-springboot/issues/11 builder.withDetail("platform.name", context.platform().name()); - builder.withDetail("platform.value", context.platform().describe().value().toString()); } catch (Exception ex) { logger.error("Could not return the Pi4J Default Platform: {}", ex.getMessage()); } try { - // TODO https://github.com/Pi4J/pi4j-springboot/issues/11 for (var entry : context.platforms().all().entrySet()) { builder.withDetail("platform." + getAsKeyName(entry.getKey()) + ".name", entry.getValue().name()); builder.withDetail("platform." + getAsKeyName(entry.getKey()) + ".description", entry.getValue().description()); - builder.withDetail("platform." + getAsKeyName(entry.getKey()) + ".value", entry.getValue().describe().value().toString()); } } catch (Exception ex) { logger.error("Could not return the Pi4J Platforms: {}", ex.getMessage()); } try { - // TODO https://github.com/Pi4J/pi4j-springboot/issues/11 for (var entry : context.providers().all().entrySet()) { builder.withDetail("provider." + getAsKeyName(entry.getKey()) + ".name", entry.getValue().name()); builder.withDetail("provider." + getAsKeyName(entry.getKey()) + ".description", entry.getValue().description()); @@ -90,12 +85,8 @@ public void contribute(Builder builder) { try { for (var entry : context.registry().all().entrySet()) { builder.withDetail("registry." + getAsKeyName(entry.getKey()) + ".name", entry.getValue().name()); - builder.withDetail("registry." + getAsKeyName(entry.getKey()) + ".config.name", entry.getValue().config().name()); - builder.withDetail("registry." + getAsKeyName(entry.getKey()) + ".config.name", entry.getValue().config().platform()); - builder.withDetail("registry." + getAsKeyName(entry.getKey()) + ".config.provider", entry.getValue().config().provider()); builder.withDetail("registry." + getAsKeyName(entry.getKey()) + ".type.name", entry.getValue().type().name()); builder.withDetail("registry." + getAsKeyName(entry.getKey()) + ".description", entry.getValue().description()); - builder.withDetail("registry." + getAsKeyName(entry.getKey()) + ".value", entry.getValue().describe().value().toString()); } } catch (Exception ex) { logger.error("Could not return the Pi4J Registry: {}", ex.getMessage()); diff --git a/pi4j-spring-boot/src/test/java/com/pi4j/spring/boot/ContextAutoConfigurationTests.java b/pi4j-spring-boot/src/test/java/com/pi4j/spring/boot/ContextAutoConfigurationTests.java index 14edccb..bf4425a 100644 --- a/pi4j-spring-boot/src/test/java/com/pi4j/spring/boot/ContextAutoConfigurationTests.java +++ b/pi4j-spring-boot/src/test/java/com/pi4j/spring/boot/ContextAutoConfigurationTests.java @@ -1,10 +1,7 @@ package com.pi4j.spring.boot; -import com.pi4j.context.Context; -import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.autoconfigure.AutoConfigurations.of; public class ContextAutoConfigurationTests { @@ -17,47 +14,4 @@ public class ContextAutoConfigurationTests { ) ); - @Test - void whenOsArchIsNotExpected_verifyContextDoesNotExist() { - - this.contextRunner - .withPropertyValues("os.arch:other") - .run(context -> assertThat(context).doesNotHaveBean(Context.class)); - } - - @Test - void whenOsArchIsArmv6l_verifyContextExists() { - - this.contextRunner - .withPropertyValues("os.arch:armv6l") - .run(context -> assertThat(context).hasSingleBean(Context.class)); - } - - @Test - void whenOsArchIsArmv7l_verifyContextExists() { - - this.contextRunner - .withPropertyValues("os.arch:armv7l") - .run(context -> assertThat(context).hasSingleBean(Context.class)); - } - - @Test - void whenOsArchIsArmv8l_verifyContextExists() { - - this.contextRunner - .withPropertyValues("os.arch:armv8l") - .run(context -> assertThat(context).hasSingleBean(Context.class)); - } - - /* - * aarch64 will also match Apple M processors - */ - @Test - void whenOsArchIsAarch64_verifyContextExists() { - - this.contextRunner - .withPropertyValues("os.arch:aarch64") - .run(context -> assertThat(context).hasSingleBean(Context.class)); - } - }