Skip to content

Commit

Permalink
do not run application for native test. remove unecessary property
Browse files Browse the repository at this point in the history
value.
  • Loading branch information
zhumin8 committed Sep 11, 2024
1 parent 59fba75 commit 279f843
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
1 change: 1 addition & 0 deletions spring-cloud-gcp-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
<it.secretmanager>true</it.secretmanager>
<it.datastore>true</it.datastore>
<it.firestore>true</it.firestore>
<it.firestore.native>true</it.firestore.native>
<it.kms>true</it.kms>
<it.bigquery>true</it.bigquery>
<it.metrics>true</it.metrics>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportRuntimeHints;

Expand All @@ -53,6 +54,7 @@ public static void main(String[] args) {
}

@Bean
@ConditionalOnProperty(name = "run.commandline.runner", havingValue = "true", matchIfMissing = true)
public CommandLineRunner commandLineRunner() {
return args -> {
writeDocumentFromMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,29 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@EnabledIfSystemProperty(named = "it.firestore", matches = "true")
@EnabledIfSystemProperty(named = "it.firestore.native", matches = "true")
@ExtendWith(SpringExtension.class)
@TestPropertySource("classpath:application-test.properties")
@SpringBootTest
@SpringBootTest(properties = "run.commandline.runner=off")
public class FirestoreSampleAppNativeIntegrationTests {

@Value("${spring.cloud.gcp.firestore.credentials.encoded-key:default}")
private String encodedKeyFromValue;

private final Logger logger =
LoggerFactory.getLogger(FirestoreSampleAppNativeIntegrationTests.class);
@Autowired private ApplicationContext applicationContext;

@Test
void credentialsPropertiesAreAccessibleTest() {
logger.info(
"This test is only needed for graalvm compilation test"
+ " to verify the encoded-key property is accessible."
+ " Turn on by it.firestore.native=true");
String encodedKeyFromAutoConfig =
applicationContext.getBean(GcpFirestoreProperties.class).getCredentials().getEncodedKey();

if (encodedKeyFromValue.equals("default")) {
// nothing to assert if not set.
logger.info("firestore.credentials.encoded-key is not set.");
} else {
// set this property only for graalvm test, verify it is correctly loaded in autoconfig
logger.info("encodedKey is read in. This should be the graalvm test.");
assertNotNull(encodedKeyFromAutoConfig);
}
assertNotNull(encodedKeyFromAutoConfig);
}
}

0 comments on commit 279f843

Please sign in to comment.