Merge branch 'master' of https://github.com/eugenp/tutorials into JAVA-1672
This commit is contained in:
commit
a14ec68229
|
@ -0,0 +1,20 @@
|
|||
package com.baeldung.firstword;
|
||||
|
||||
public class FirstWordGetter {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String input = "Roberto \"I wish you a bug-free day\"";
|
||||
System.out.println("Using split: " + getFirstWordUsingSplit(input));
|
||||
System.out.println("Using subString: " + getFirstWordUsingSubString(input));
|
||||
}
|
||||
|
||||
public static String getFirstWordUsingSubString(String input) {
|
||||
int index = input.contains(" ") ? input.indexOf(" ") : 0;
|
||||
return input.substring(0, index);
|
||||
}
|
||||
|
||||
public static String getFirstWordUsingSplit(String input) {
|
||||
String[] tokens = input.split(" ", 2);
|
||||
return tokens[0];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.baeldung.firstword;
|
||||
|
||||
import static com.baeldung.firstword.FirstWordGetter.getFirstWordUsingSplit;
|
||||
import static com.baeldung.firstword.FirstWordGetter.getFirstWordUsingSubString;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class FirstWordGetterUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenString_whenSplit_thenFirstWordIsReturned() {
|
||||
assertEquals("Roberto", getFirstWordUsingSplit("Roberto \"I wish you a bug-free day\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStringWithNoSpace_whenSplit_thenFirstWordIsReturned() {
|
||||
assertEquals("StringWithNoSpace", getFirstWordUsingSplit("StringWithNoSpace"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_whenPassedToSubstring_thenFirstWordIsReturned() {
|
||||
assertEquals("Roberto", getFirstWordUsingSubString("Roberto \"I wish you a bug-free day\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStringWithNoSpace_whenPassedToSubstring_thenFirstWordIsReturned() {
|
||||
assertEquals("", getFirstWordUsingSubString("StringWithNoSpace"));
|
||||
}
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
drop table if exists client;
|
||||
|
||||
create table client (
|
||||
id numeric,
|
||||
name varchar(50),
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package com.baeldung.startup;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
public class ResourceInitializer {
|
||||
|
||||
ResourceInitializer() throws Exception {
|
||||
// simulate resource init with random delay of a few seconds
|
||||
int randomDelay = ThreadLocalRandom.current().nextInt(5, 9);
|
||||
TimeUnit.SECONDS.sleep(randomDelay);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.baeldung.startup;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
|
||||
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
|
||||
|
||||
import static java.lang.Boolean.FALSE;
|
||||
|
||||
@SpringBootApplication(exclude = {
|
||||
SecurityAutoConfiguration.class,
|
||||
ManagementWebSecurityAutoConfiguration.class}
|
||||
)
|
||||
public class StartupTrackingApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// only load properties for this application
|
||||
System.setProperty("spring.config.location", "classpath:application-startup.properties");
|
||||
|
||||
SpringApplication app = new SpringApplication(StartupTrackingApplication.class);
|
||||
BufferingApplicationStartup startup = new BufferingApplicationStartup(2048);
|
||||
|
||||
if (shouldFilterSteps()) {
|
||||
startup.addFilter(startupStep -> startupStep.getName().matches("spring.beans.instantiate"));
|
||||
}
|
||||
|
||||
app.setApplicationStartup(startup);
|
||||
app.run(args);
|
||||
}
|
||||
|
||||
private static boolean shouldFilterSteps() {
|
||||
return Boolean.parseBoolean(
|
||||
System.getProperty("startup.steps.filter", FALSE.toString())
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
management.endpoints.web.exposure.include=startup
|
||||
|
||||
# JPA is not required for startup actuator endpoint
|
||||
spring.autoconfigure.exclude= org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, \
|
||||
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration, \
|
||||
org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration
|
Loading…
Reference in New Issue