Skip to content

Commit

Permalink
Fix for #11 + full actuator info
Browse files Browse the repository at this point in the history
  • Loading branch information
FDelporte committed Jun 13, 2024
1 parent efd0f91 commit ede9281
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 92 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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));
}

}

0 comments on commit ede9281

Please sign in to comment.