diff --git a/algorithms/pom.xml b/algorithms/pom.xml index 46a2b9d897..529af19686 100644 --- a/algorithms/pom.xml +++ b/algorithms/pom.xml @@ -10,9 +10,15 @@ 3.6.0 1.5.0 1.16.12 + 3.6.1 + + org.apache.commons + commons-math3 + ${commons-math3.version} + junit junit diff --git a/core-java/src/main/java/com/baeldung/primechecker/BigIntegerPrimeChecker.java b/algorithms/src/main/java/com/baeldung/algorithms/primechecker/BigIntegerPrimeChecker.java similarity index 84% rename from core-java/src/main/java/com/baeldung/primechecker/BigIntegerPrimeChecker.java rename to algorithms/src/main/java/com/baeldung/algorithms/primechecker/BigIntegerPrimeChecker.java index 1ac4fed63f..bd4708b661 100644 --- a/core-java/src/main/java/com/baeldung/primechecker/BigIntegerPrimeChecker.java +++ b/algorithms/src/main/java/com/baeldung/algorithms/primechecker/BigIntegerPrimeChecker.java @@ -1,4 +1,4 @@ -package com.baeldung.primechecker; +package com.baeldung.algorithms.primechecker; import java.math.BigInteger; diff --git a/core-java/src/main/java/com/baeldung/primechecker/BruteForcePrimeChecker.java b/algorithms/src/main/java/com/baeldung/algorithms/primechecker/BruteForcePrimeChecker.java similarity index 58% rename from core-java/src/main/java/com/baeldung/primechecker/BruteForcePrimeChecker.java rename to algorithms/src/main/java/com/baeldung/algorithms/primechecker/BruteForcePrimeChecker.java index 7a94479b8f..0dfcfa1505 100644 --- a/core-java/src/main/java/com/baeldung/primechecker/BruteForcePrimeChecker.java +++ b/algorithms/src/main/java/com/baeldung/algorithms/primechecker/BruteForcePrimeChecker.java @@ -1,4 +1,4 @@ -package com.baeldung.primechecker; +package com.baeldung.algorithms.primechecker; import java.util.stream.IntStream; @@ -6,7 +6,7 @@ public class BruteForcePrimeChecker implements PrimeChecker{ @Override public boolean isPrime(int number) { - return IntStream.range(2, number).filter(n -> (number % n == 0)).count() == 0; + return IntStream.range(2, number).noneMatch(n -> (number % n == 0)); } diff --git a/core-java/src/main/java/com/baeldung/primechecker/OptimisedPrimeChecker.java b/algorithms/src/main/java/com/baeldung/algorithms/primechecker/OptimisedPrimeChecker.java similarity index 68% rename from core-java/src/main/java/com/baeldung/primechecker/OptimisedPrimeChecker.java rename to algorithms/src/main/java/com/baeldung/algorithms/primechecker/OptimisedPrimeChecker.java index 40669f4181..f7e3e09be0 100644 --- a/core-java/src/main/java/com/baeldung/primechecker/OptimisedPrimeChecker.java +++ b/algorithms/src/main/java/com/baeldung/algorithms/primechecker/OptimisedPrimeChecker.java @@ -1,4 +1,4 @@ -package com.baeldung.primechecker; +package com.baeldung.algorithms.primechecker; import java.util.stream.IntStream; @@ -7,8 +7,7 @@ public class OptimisedPrimeChecker implements PrimeChecker{ @Override public boolean isPrime(int number) { return IntStream.range(2, (int)Math.sqrt(number) + 1) - .filter(n -> (number % n == 0)) - .count() == 0; + .noneMatch(n -> (number % n == 0)); } diff --git a/core-java/src/main/java/com/baeldung/primechecker/PrimeChecker.java b/algorithms/src/main/java/com/baeldung/algorithms/primechecker/PrimeChecker.java similarity index 64% rename from core-java/src/main/java/com/baeldung/primechecker/PrimeChecker.java rename to algorithms/src/main/java/com/baeldung/algorithms/primechecker/PrimeChecker.java index 22260268bc..f31af1ca4f 100644 --- a/core-java/src/main/java/com/baeldung/primechecker/PrimeChecker.java +++ b/algorithms/src/main/java/com/baeldung/algorithms/primechecker/PrimeChecker.java @@ -1,4 +1,4 @@ -package com.baeldung.primechecker; +package com.baeldung.algorithms.primechecker; public interface PrimeChecker { diff --git a/core-java/src/main/java/com/baeldung/primechecker/PrimesPrimeChecker.java b/algorithms/src/main/java/com/baeldung/algorithms/primechecker/PrimesPrimeChecker.java similarity index 82% rename from core-java/src/main/java/com/baeldung/primechecker/PrimesPrimeChecker.java rename to algorithms/src/main/java/com/baeldung/algorithms/primechecker/PrimesPrimeChecker.java index 0c6a636612..ee66d5d2ab 100644 --- a/core-java/src/main/java/com/baeldung/primechecker/PrimesPrimeChecker.java +++ b/algorithms/src/main/java/com/baeldung/algorithms/primechecker/PrimesPrimeChecker.java @@ -1,4 +1,4 @@ -package com.baeldung.primechecker; +package com.baeldung.algorithms.primechecker; import org.apache.commons.math3.primes.Primes; diff --git a/core-java/src/test/java/com/baeldung/primechecker/BigIntegerPrimeCheckerTest.java b/algorithms/src/test/java/com/baeldung/algorithms/primechecker/BigIntegerPrimeCheckerTest.java similarity index 75% rename from core-java/src/test/java/com/baeldung/primechecker/BigIntegerPrimeCheckerTest.java rename to algorithms/src/test/java/com/baeldung/algorithms/primechecker/BigIntegerPrimeCheckerTest.java index 6a5228cc50..95eb85749d 100644 --- a/core-java/src/test/java/com/baeldung/primechecker/BigIntegerPrimeCheckerTest.java +++ b/algorithms/src/test/java/com/baeldung/algorithms/primechecker/BigIntegerPrimeCheckerTest.java @@ -1,9 +1,12 @@ -package com.baeldung.primechecker; +package com.baeldung.algorithms.primechecker; import static org.junit.Assert.assertTrue; import org.junit.Test; +import com.baeldung.algorithms.primechecker.BigIntegerPrimeChecker; +import com.baeldung.algorithms.primechecker.PrimeChecker; + public class BigIntegerPrimeCheckerTest { PrimeChecker primeChecker = new BigIntegerPrimeChecker(); diff --git a/core-java/src/test/java/com/baeldung/primechecker/BruteForcePrimeCheckerTest.java b/algorithms/src/test/java/com/baeldung/algorithms/primechecker/BruteForcePrimeCheckerTest.java similarity index 82% rename from core-java/src/test/java/com/baeldung/primechecker/BruteForcePrimeCheckerTest.java rename to algorithms/src/test/java/com/baeldung/algorithms/primechecker/BruteForcePrimeCheckerTest.java index 7139373f5e..50af4ab05c 100644 --- a/core-java/src/test/java/com/baeldung/primechecker/BruteForcePrimeCheckerTest.java +++ b/algorithms/src/test/java/com/baeldung/algorithms/primechecker/BruteForcePrimeCheckerTest.java @@ -1,6 +1,9 @@ -package com.baeldung.primechecker; +package com.baeldung.algorithms.primechecker; import org.junit.Test; + +import com.baeldung.algorithms.primechecker.BruteForcePrimeChecker; + import static org.junit.Assert.*; public class BruteForcePrimeCheckerTest { diff --git a/core-java/src/test/java/com/baeldung/primechecker/OptimisedPrimeCheckerTest.java b/algorithms/src/test/java/com/baeldung/algorithms/primechecker/OptimisedPrimeCheckerTest.java similarity index 75% rename from core-java/src/test/java/com/baeldung/primechecker/OptimisedPrimeCheckerTest.java rename to algorithms/src/test/java/com/baeldung/algorithms/primechecker/OptimisedPrimeCheckerTest.java index bb4c06a53a..21ad55467f 100644 --- a/core-java/src/test/java/com/baeldung/primechecker/OptimisedPrimeCheckerTest.java +++ b/algorithms/src/test/java/com/baeldung/algorithms/primechecker/OptimisedPrimeCheckerTest.java @@ -1,9 +1,12 @@ -package com.baeldung.primechecker; +package com.baeldung.algorithms.primechecker; import static org.junit.Assert.assertTrue; import org.junit.Test; +import com.baeldung.algorithms.primechecker.OptimisedPrimeChecker; +import com.baeldung.algorithms.primechecker.PrimeChecker; + public class OptimisedPrimeCheckerTest { PrimeChecker primeChecker = new OptimisedPrimeChecker(); diff --git a/core-java/src/test/java/com/baeldung/primechecker/PrimesPrimeCheckerTest.java b/algorithms/src/test/java/com/baeldung/algorithms/primechecker/PrimesPrimeCheckerTest.java similarity index 75% rename from core-java/src/test/java/com/baeldung/primechecker/PrimesPrimeCheckerTest.java rename to algorithms/src/test/java/com/baeldung/algorithms/primechecker/PrimesPrimeCheckerTest.java index f8b194e855..63de593b44 100644 --- a/core-java/src/test/java/com/baeldung/primechecker/PrimesPrimeCheckerTest.java +++ b/algorithms/src/test/java/com/baeldung/algorithms/primechecker/PrimesPrimeCheckerTest.java @@ -1,9 +1,12 @@ -package com.baeldung.primechecker; +package com.baeldung.algorithms.primechecker; import static org.junit.Assert.assertTrue; import org.junit.Test; +import com.baeldung.algorithms.primechecker.PrimeChecker; +import com.baeldung.algorithms.primechecker.PrimesPrimeChecker; + public class PrimesPrimeCheckerTest { PrimeChecker primeChecker = new PrimesPrimeChecker(); diff --git a/jackson/src/test/java/com/baeldung/jackson/deserialization/JacksonMapDeserializeTest.java b/jackson/src/test/java/com/baeldung/jackson/deserialization/JacksonMapDeserializeTest.java index 04eb89306b..5021abaac1 100644 --- a/jackson/src/test/java/com/baeldung/jackson/deserialization/JacksonMapDeserializeTest.java +++ b/jackson/src/test/java/com/baeldung/jackson/deserialization/JacksonMapDeserializeTest.java @@ -18,13 +18,13 @@ public class JacksonMapDeserializeTest { private Map map; private Map cmap; + final ObjectMapper mapper = new ObjectMapper(); @Test public void whenSimpleMapDeserialize_thenCorrect() throws JsonParseException, JsonMappingException, IOException { final String jsonInput = "{\"key\": \"value\"}"; - final ObjectMapper mapper = new ObjectMapper(); TypeReference> typeRef = new TypeReference>() { }; @@ -38,7 +38,6 @@ public class JacksonMapDeserializeTest { throws JsonParseException, JsonMappingException, IOException { final String jsonInput = "{\"Abbott and Costello\":\"Comedy\"}"; - final ObjectMapper mapper = new ObjectMapper(); TypeReference> typeRef = new TypeReference>() { }; @@ -59,7 +58,6 @@ public class JacksonMapDeserializeTest { throws JsonParseException, JsonMappingException, IOException { final String jsonInput = "{\"Abbott and Costello\" : \"Comedy and 1940s\"}"; - final ObjectMapper mapper = new ObjectMapper(); TypeReference> typeRef = new TypeReference>() { }; diff --git a/jackson/src/test/java/com/baeldung/jackson/serialization/JacksonMapSerializeTest.java b/jackson/src/test/java/com/baeldung/jackson/serialization/JacksonMapSerializeTest.java index 841b12ca03..a5ee76f3b8 100644 --- a/jackson/src/test/java/com/baeldung/jackson/serialization/JacksonMapSerializeTest.java +++ b/jackson/src/test/java/com/baeldung/jackson/serialization/JacksonMapSerializeTest.java @@ -26,6 +26,8 @@ public class JacksonMapSerializeTest { @JsonSerialize(keyUsing = MyPairSerializer.class) private MyPair mapValue; + final ObjectMapper mapper = new ObjectMapper(); + @Test public void whenSimpleMapSerialize_thenCorrect() throws JsonProcessingException { @@ -33,7 +35,6 @@ public class JacksonMapSerializeTest { Map map = new HashMap<>(); map.put("key", "value"); - final ObjectMapper mapper = new ObjectMapper(); final String jsonResult = mapper.writeValueAsString(map); Assert.assertEquals("{\"key\":\"value\"}", jsonResult); @@ -47,7 +48,6 @@ public class JacksonMapSerializeTest { MyPair key = new MyPair("Abbott", "Costello"); map.put(key, "Comedy"); - final ObjectMapper mapper = new ObjectMapper(); final String jsonResult = mapper.writeValueAsString(map); Assert.assertEquals("{\"Abbott and Costello\":\"Comedy\"}", jsonResult); @@ -62,7 +62,6 @@ public class JacksonMapSerializeTest { mapValue = new MyPair("Comedy", "1940's"); cmap.put(mapKey, mapValue); - final ObjectMapper mapper = new ObjectMapper(); final String jsonResult = mapper.writeValueAsString(cmap); Assert.assertEquals("{\"Abbott and Costello\":\"Comedy and 1940's\"}", diff --git a/ratpack/src/main/java/com/baeldung/guice/Application.java b/ratpack/src/main/java/com/baeldung/guice/Application.java index 39d29b9b2b..4e837501da 100644 --- a/ratpack/src/main/java/com/baeldung/guice/Application.java +++ b/ratpack/src/main/java/com/baeldung/guice/Application.java @@ -2,6 +2,7 @@ package com.baeldung.guice; import com.baeldung.guice.config.DependencyModule; import com.baeldung.guice.service.DataPumpService; +import com.baeldung.guice.service.ServiceFactory; import com.baeldung.guice.service.impl.DataPumpServiceImpl; import ratpack.guice.Guice; @@ -15,8 +16,8 @@ public class Application { .start(server -> server.registry(Guice.registry(bindings -> bindings.module(DependencyModule.class))) .handlers(chain -> chain.get("randomString", ctx -> { DataPumpService dataPumpService = ctx.get(DataPumpService.class); - ctx.render(dataPumpService.generate().length()); - }))); + ctx.render(dataPumpService.generate()); + }).get("factory", ctx -> ctx.render(ServiceFactory.getInstance().generate())))); // RatpackServer.start(server -> server // .registry(Guice @@ -24,8 +25,8 @@ public class Application { // .handlers(chain -> chain.get("randomString", ctx -> { // DataPumpService dataPumpService = ctx.get(DataPumpService.class); // ctx.render(dataPumpService.generate()); -// }))); +// }).get("factory", ctx -> ctx.render(ServiceFactory.getInstance().generate())))); } -} +} \ No newline at end of file diff --git a/ratpack/src/main/java/com/baeldung/guice/service/DataPumpService.java b/ratpack/src/main/java/com/baeldung/guice/service/DataPumpService.java index 6adfec2365..01b7dbabef 100644 --- a/ratpack/src/main/java/com/baeldung/guice/service/DataPumpService.java +++ b/ratpack/src/main/java/com/baeldung/guice/service/DataPumpService.java @@ -1,9 +1,5 @@ package com.baeldung.guice.service; -import com.baeldung.guice.service.impl.DataPumpServiceImpl; -import com.google.inject.ImplementedBy; - -@ImplementedBy(DataPumpServiceImpl.class) public interface DataPumpService { String generate(); diff --git a/ratpack/src/main/java/com/baeldung/guice/service/ServiceFactory.java b/ratpack/src/main/java/com/baeldung/guice/service/ServiceFactory.java new file mode 100644 index 0000000000..d11beb1cb2 --- /dev/null +++ b/ratpack/src/main/java/com/baeldung/guice/service/ServiceFactory.java @@ -0,0 +1,20 @@ +package com.baeldung.guice.service; + +import com.baeldung.guice.service.impl.DataPumpServiceImpl; + +public class ServiceFactory { + + private static DataPumpService instance; + + public static void setInstance(DataPumpService dataPumpService) { + instance = dataPumpService; + } + + public static DataPumpService getInstance() { + if (instance == null) { + return new DataPumpServiceImpl(); + } + return instance; + } + +} diff --git a/spring-all/pom.xml b/spring-all/pom.xml index f28fe1f10d..a3a51425e2 100644 --- a/spring-all/pom.xml +++ b/spring-all/pom.xml @@ -43,6 +43,12 @@ spring-retry ${springretry.version} + + org.springframework.shell + spring-shell + ${org.springframework.shell.version} + + @@ -280,6 +286,7 @@ 4.3.4.RELEASE 4.2.0.RELEASE 1.1.5.RELEASE + 1.2.0.RELEASE 5.2.5.Final diff --git a/spring-all/src/main/java/org/baeldung/shell/Main.java b/spring-all/src/main/java/org/baeldung/shell/Main.java new file mode 100644 index 0000000000..3d9f7a5860 --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/shell/Main.java @@ -0,0 +1,10 @@ +package org.baeldung.shell; + +import java.io.IOException; +import org.springframework.shell.Bootstrap; + +public class Main { + public static void main(String[] args) throws IOException { + Bootstrap.main(args); + } +} diff --git a/spring-all/src/main/java/org/baeldung/shell/simple/SimpleBannerProvider.java b/spring-all/src/main/java/org/baeldung/shell/simple/SimpleBannerProvider.java new file mode 100644 index 0000000000..df7a48cd32 --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/shell/simple/SimpleBannerProvider.java @@ -0,0 +1,34 @@ +package org.baeldung.shell.simple; + +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; +import org.springframework.shell.plugin.support.DefaultBannerProvider; +import org.springframework.shell.support.util.OsUtils; +import org.springframework.stereotype.Component; + +@Component +@Order(Ordered.HIGHEST_PRECEDENCE) +public class SimpleBannerProvider extends DefaultBannerProvider { + + public String getBanner() { + StringBuffer buf = new StringBuffer(); + buf.append("=======================================").append(OsUtils.LINE_SEPARATOR); + buf.append("* Baeldung Shell *").append(OsUtils.LINE_SEPARATOR); + buf.append("=======================================").append(OsUtils.LINE_SEPARATOR); + buf.append("Version:").append(this.getVersion()); + return buf.toString(); + } + + public String getVersion() { + return "1.0.1"; + } + + public String getWelcomeMessage() { + return "Welcome to Baeldung CLI"; + } + + @Override + public String getProviderName() { + return "Baeldung Banner"; + } +} diff --git a/spring-all/src/main/java/org/baeldung/shell/simple/SimpleCLI.java b/spring-all/src/main/java/org/baeldung/shell/simple/SimpleCLI.java new file mode 100644 index 0000000000..0bbc62cf2c --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/shell/simple/SimpleCLI.java @@ -0,0 +1,81 @@ +package org.baeldung.shell.simple; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.net.URL; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.springframework.shell.Bootstrap; +import org.springframework.shell.core.CommandMarker; +import org.springframework.shell.core.annotation.CliAvailabilityIndicator; +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; +import org.springframework.stereotype.Component; + +@Component +public class SimpleCLI implements CommandMarker { + + private String getContentsOfUrlAsString(URL url) { + StringBuilder sb = new StringBuilder(); + try { + try (BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()))) { + String inputLine; + while ((inputLine = in.readLine()) != null) { + sb.append(inputLine); + } + } + } catch (IOException ex) { + sb.append("ERROR"); + } + return sb.toString(); + } + + @CliCommand( + value = {"web-get", "wg"}, + help = "Displays the contents of a URL." + ) + public String webGet( + @CliOption( + key = {"", "url"}, + help = "URL whose contents will be displayed." + ) URL url) { + return getContentsOfUrlAsString(url); + } + + @CliCommand( + value = {"web-save", "ws"}, + help = "Saves the contents of a URL.") + public String webSave( + @CliOption(key = {"", "url"}, help = "URL whose contents will be saved.") URL url, + @CliOption(key = {"out", "file"}, mandatory = true, help = "The name of the file.") String file) { + String contents = getContentsOfUrlAsString(url); + try (PrintWriter out = new PrintWriter(file)) { + out.write(contents); + } catch (FileNotFoundException ex) { + //Ignore + } + return "Done."; + } + + private boolean adminEnableExecuted = false; + + @CliAvailabilityIndicator(value = {"web-save"}) + public boolean isAdminEnabled() { + return adminEnableExecuted; + } + + @CliCommand(value = "admin-enable") + public String adminEnable() { + adminEnableExecuted = true; + return "Admin commands enabled."; + } + + @CliCommand(value = "admin-disable") + public String adminDisable() { + adminEnableExecuted = false; + return "Admin commands disabled."; + } +} diff --git a/spring-all/src/main/java/org/baeldung/shell/simple/SimpleHistoryFileNameProvider.java b/spring-all/src/main/java/org/baeldung/shell/simple/SimpleHistoryFileNameProvider.java new file mode 100644 index 0000000000..cef53adc69 --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/shell/simple/SimpleHistoryFileNameProvider.java @@ -0,0 +1,22 @@ +package org.baeldung.shell.simple; + +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; +import org.springframework.shell.plugin.support.DefaultHistoryFileNameProvider; +import org.springframework.stereotype.Component; + +@Component +@Order(Ordered.HIGHEST_PRECEDENCE) +public class SimpleHistoryFileNameProvider extends DefaultHistoryFileNameProvider { + + @Override + public String getHistoryFileName() { + return "baeldung-shell.log"; + } + + @Override + public String getProviderName() { + return "Baeldung History"; + } + +} diff --git a/spring-all/src/main/java/org/baeldung/shell/simple/SimplePromptProvider.java b/spring-all/src/main/java/org/baeldung/shell/simple/SimplePromptProvider.java new file mode 100644 index 0000000000..9a84954e05 --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/shell/simple/SimplePromptProvider.java @@ -0,0 +1,21 @@ +package org.baeldung.shell.simple; + +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; +import org.springframework.shell.plugin.support.DefaultPromptProvider; +import org.springframework.stereotype.Component; + +@Component +@Order(Ordered.HIGHEST_PRECEDENCE) +public class SimplePromptProvider extends DefaultPromptProvider { + + @Override + public String getPrompt() { + return "baeldung-shell>"; + } + + @Override + public String getProviderName() { + return "Baeldung Prompt"; + } +} diff --git a/spring-all/src/main/java/org/baeldung/shell/simple/SimpleURLConverter.java b/spring-all/src/main/java/org/baeldung/shell/simple/SimpleURLConverter.java new file mode 100644 index 0000000000..66bab5c488 --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/shell/simple/SimpleURLConverter.java @@ -0,0 +1,35 @@ +package org.baeldung.shell.simple; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; +import org.springframework.shell.core.Completion; +import org.springframework.shell.core.Converter; +import org.springframework.shell.core.MethodTarget; +import org.springframework.stereotype.Component; + +@Component +public class SimpleURLConverter implements Converter { + + @Override + public URL convertFromText(String value, Class requiredType, String optionContext) { + try { + return new URL(value); + } catch (MalformedURLException ex) { + //Ignore + } + return null; + } + + @Override + public boolean getAllPossibleValues(List completions, Class requiredType, + String existingData, String optionContext, MethodTarget target) { + return false; + } + + @Override + public boolean supports(Class requiredType, String optionContext) { + return URL.class.isAssignableFrom(requiredType); + } + +} diff --git a/spring-all/src/main/resources/META-INF/spring/spring-shell-plugin.xml b/spring-all/src/main/resources/META-INF/spring/spring-shell-plugin.xml new file mode 100644 index 0000000000..aea1a663c1 --- /dev/null +++ b/spring-all/src/main/resources/META-INF/spring/spring-shell-plugin.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/spring-all/src/test/java/org/baeldung/shell/simple/SimpleCLIUnitTest.java b/spring-all/src/test/java/org/baeldung/shell/simple/SimpleCLIUnitTest.java new file mode 100644 index 0000000000..0353083943 --- /dev/null +++ b/spring-all/src/test/java/org/baeldung/shell/simple/SimpleCLIUnitTest.java @@ -0,0 +1,86 @@ +package org.baeldung.shell.simple; + +import java.io.File; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.springframework.shell.Bootstrap; +import org.springframework.shell.core.CommandResult; +import org.springframework.shell.core.JLineShellComponent; + +public class SimpleCLIUnitTest { + + static JLineShellComponent shell; + + @BeforeClass + public static void startUp() throws InterruptedException { + Bootstrap bootstrap = new Bootstrap(); + shell = bootstrap.getJLineShellComponent(); + } + + @AfterClass + public static void shutdown() { + shell.stop(); + } + + public static JLineShellComponent getShell() { + return shell; + } + + @Test + public void givenCommandConfig_whenExecutingWebGetCommand_thenCorrectResult() { + + CommandResult resultWebSave = shell.executeCommand("web-get --url https://www.google.com"); + + Assert.assertTrue(resultWebSave.isSuccess()); + } + + @Test + public void givenCommandConfig_whenExecutingWebSaveCommand_thenCorrectResult() { + + shell.executeCommand("admin-enable"); + CommandResult result = shell.executeCommand("web-save --url https://www.google.com --out contents.txt"); + + Assert.assertArrayEquals( + new boolean[]{ + result.isSuccess(), + new File("contents.txt").exists()}, + new boolean[]{true, true}); + } + + @Test + public void givenCommandConfig_whenAdminEnableCommandExecuted_thenCorrectAvailability() { + + CommandResult resultAdminDisable = shell.executeCommand("admin-disable"); + CommandResult resultWebSaveUnavailable = shell.executeCommand("web-save --url https://www.google.com --out contents.txt"); + CommandResult resultAdminEnable = shell.executeCommand("admin-enable"); + CommandResult resultWebSaveAvailable = shell.executeCommand("web-save --url https://www.google.com --out contents.txt"); + + Assert.assertArrayEquals( + new boolean[]{ + resultAdminDisable.isSuccess(), + resultWebSaveUnavailable.isSuccess(), + resultAdminEnable.isSuccess(), + resultWebSaveAvailable.isSuccess()}, + new boolean[]{true, false, true, true}); + } + + @Test + public void givenCommandConfig_whenWebSaveCommandExecutedNoOutArgument_thenError() { + + shell.executeCommand("admin-enable"); + CommandResult resultWebSave = shell.executeCommand("web-save --url https://www.google.com"); + + Assert.assertEquals(resultWebSave.isSuccess(), false); + } + + @Test + public void givenCommandConfig_whenExecutingWebGetCommandWithDefaultArgument_thenCorrectResult() { + + CommandResult result = shell.executeCommand("web-get https://www.google.com"); + + Assert.assertEquals(result.isSuccess(), true); + } + +} diff --git a/spring-boot-auditing/.gitignore b/spring-boot-auditing/.gitignore deleted file mode 100644 index 31ce405488..0000000000 --- a/spring-boot-auditing/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/target/ -.settings/ -.classpath -.project -*.iml -.idea \ No newline at end of file diff --git a/spring-boot-auditing/pom.xml b/spring-boot-auditing/pom.xml deleted file mode 100644 index 0afbe0becc..0000000000 --- a/spring-boot-auditing/pom.xml +++ /dev/null @@ -1,198 +0,0 @@ - - 4.0.0 - com.baeldung - spring-boot-auditing - 0.0.1-SNAPSHOT - war - spring-boot-auditing - This is simple boot application for Spring boot auditing test - - - - org.springframework.boot - spring-boot-starter-parent - 1.5.2.RELEASE - - - - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - org.springframework.boot - spring-boot-starter-actuator - - - - org.springframework.boot - spring-boot-starter-security - - - - io.dropwizard.metrics - metrics-core - - - - com.h2database - h2 - - - - org.springframework.boot - spring-boot-starter-test - test - - - - org.springframework.boot - spring-boot-starter - - - com.jayway.jsonpath - json-path - test - - - org.springframework.boot - spring-boot-starter-mail - - - org.subethamail - subethasmtp - ${subethasmtp.version} - test - - - - org.webjars - bootstrap - ${bootstrap.version} - - - org.webjars - jquery - ${jquery.version} - - - - org.apache.tomcat - tomcat-servlet-api - ${tomee-servlet-api.version} - provided - - - - - - spring-boot - - - src/main/resources - true - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - - - - org.apache.maven.plugins - maven-war-plugin - - - - pl.project13.maven - git-commit-id-plugin - ${git-commit-id-plugin.version} - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*IntegrationTest.java - **/*LiveTest.java - - - - - - - - - - - integration - - - - org.apache.maven.plugins - maven-surefire-plugin - - - integration-test - - test - - - - **/*LiveTest.java - - - **/*IntegrationTest.java - - - - - - - json - - - - - - - - - - - UTF-8 - 1.8 - 4.3.7.RELEASE - 2.2.1 - 3.1.1 - 3.3.7-1 - 3.1.7 - 8.5.11 - - - diff --git a/spring-boot-auditing/src/main/java/org/baeldung/Application.java b/spring-boot-auditing/src/main/java/org/baeldung/Application.java deleted file mode 100755 index bf7b7bd1a6..0000000000 --- a/spring-boot-auditing/src/main/java/org/baeldung/Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.baeldung; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Application { - - public static void main(String[] args) throws Throwable { - SpringApplication.run(Application.class, args); - } - -} diff --git a/spring-boot-auditing/src/main/java/org/baeldung/MvcConfig.java b/spring-boot-auditing/src/main/java/org/baeldung/MvcConfig.java deleted file mode 100755 index fecb8c5c0b..0000000000 --- a/spring-boot-auditing/src/main/java/org/baeldung/MvcConfig.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.baeldung; - -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; - -@Configuration -public class MvcConfig extends WebMvcConfigurerAdapter { - - @Override - public void addViewControllers(ViewControllerRegistry registry) { - registry.addViewController("/home").setViewName("home"); - registry.addViewController("/").setViewName("home"); - registry.addViewController("/hello").setViewName("hello"); - registry.addViewController("/login").setViewName("login"); - } - -} diff --git a/spring-boot-auditing/src/main/java/org/baeldung/WebSecurityConfig.java b/spring-boot-auditing/src/main/java/org/baeldung/WebSecurityConfig.java deleted file mode 100755 index 9339d8e804..0000000000 --- a/spring-boot-auditing/src/main/java/org/baeldung/WebSecurityConfig.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.baeldung; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; - -@Configuration -@EnableWebSecurity -public class WebSecurityConfig extends WebSecurityConfigurerAdapter { - @Override - protected void configure(HttpSecurity http) throws Exception { - http - .authorizeRequests() - .antMatchers("/", "/home").permitAll() - .anyRequest().authenticated() - .and() - .formLogin() - .loginPage("/login") - .permitAll() - .and() - .logout() - .permitAll(); - } - - @Autowired - public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { - auth - .inMemoryAuthentication() - .withUser("user").password("password").roles("USER", "ACTUATOR"); - } -} diff --git a/spring-boot-auditing/src/main/resources/application.properties b/spring-boot-auditing/src/main/resources/application.properties deleted file mode 100644 index cf09473b60..0000000000 --- a/spring-boot-auditing/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -logging.level.org.springframework=INFO \ No newline at end of file diff --git a/spring-boot-auditing/src/main/resources/logback.xml b/spring-boot-auditing/src/main/resources/logback.xml deleted file mode 100644 index 78913ee76f..0000000000 --- a/spring-boot-auditing/src/main/resources/logback.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - - - - - - - \ No newline at end of file diff --git a/spring-boot-auditing/src/main/resources/templates/hello.html b/spring-boot-auditing/src/main/resources/templates/hello.html deleted file mode 100755 index 46feef7e2c..0000000000 --- a/spring-boot-auditing/src/main/resources/templates/hello.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - Hello World! - - -

Hello [[${#httpServletRequest.remoteUser}]]!

-
- -
- - \ No newline at end of file diff --git a/spring-boot-auditing/src/main/resources/templates/home.html b/spring-boot-auditing/src/main/resources/templates/home.html deleted file mode 100755 index fe4e8b337e..0000000000 --- a/spring-boot-auditing/src/main/resources/templates/home.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - Spring Security Example - - -

Welcome!

- -

Click here to see a greeting.

- - \ No newline at end of file diff --git a/spring-boot-auditing/src/main/resources/templates/login.html b/spring-boot-auditing/src/main/resources/templates/login.html deleted file mode 100755 index a1785313f5..0000000000 --- a/spring-boot-auditing/src/main/resources/templates/login.html +++ /dev/null @@ -1,20 +0,0 @@ - - - - Spring Security Example - - -
- Invalid username and password. -
-
- You have been logged out. -
-
-
-
-
-
- - \ No newline at end of file diff --git a/spring-security-core/pom.xml b/spring-security-core/pom.xml index a8ffce84b7..971f5a9d0f 100644 --- a/spring-security-core/pom.xml +++ b/spring-security-core/pom.xml @@ -32,6 +32,10 @@ org.springframework.boot spring-boot-starter-thymeleaf + + org.springframework.boot + spring-boot-starter-actuator + com.h2database h2 diff --git a/spring-boot-auditing/src/main/java/org/baeldung/auditing/ExposeAttemptedPathAuthorizationAuditListener.java b/spring-security-core/src/main/java/org/baeldung/auditing/ExposeAttemptedPathAuthorizationAuditListener.java similarity index 100% rename from spring-boot-auditing/src/main/java/org/baeldung/auditing/ExposeAttemptedPathAuthorizationAuditListener.java rename to spring-security-core/src/main/java/org/baeldung/auditing/ExposeAttemptedPathAuthorizationAuditListener.java diff --git a/spring-boot-auditing/src/main/java/org/baeldung/auditing/LoginAttemptsLogger.java b/spring-security-core/src/main/java/org/baeldung/auditing/LoginAttemptsLogger.java similarity index 72% rename from spring-boot-auditing/src/main/java/org/baeldung/auditing/LoginAttemptsLogger.java rename to spring-security-core/src/main/java/org/baeldung/auditing/LoginAttemptsLogger.java index 5be8cebfd3..bf0781bced 100644 --- a/spring-boot-auditing/src/main/java/org/baeldung/auditing/LoginAttemptsLogger.java +++ b/spring-security-core/src/main/java/org/baeldung/auditing/LoginAttemptsLogger.java @@ -15,11 +15,11 @@ public class LoginAttemptsLogger { @EventListener public void auditEventHappened(AuditApplicationEvent auditApplicationEvent) { AuditEvent auditEvent = auditApplicationEvent.getAuditEvent(); - LOGGER.debug("Principal " + auditEvent.getPrincipal() + " - " + auditEvent.getType()); + LOGGER.info("Principal " + auditEvent.getPrincipal() + " - " + auditEvent.getType()); WebAuthenticationDetails details = (WebAuthenticationDetails) auditEvent.getData().get("details"); - LOGGER.debug(" Remote IP address: " + details.getRemoteAddress()); - LOGGER.debug(" Session Id: " + details.getSessionId()); - LOGGER.debug(" Request URL: " + auditEvent.getData().get("requestUrl")); + LOGGER.info(" Remote IP address: " + details.getRemoteAddress()); + LOGGER.info(" Session Id: " + details.getSessionId()); + LOGGER.info(" Request URL: " + auditEvent.getData().get("requestUrl")); } } diff --git a/spring-security-core/src/main/java/org/baeldung/config/WebSecurityConfig.java b/spring-security-core/src/main/java/org/baeldung/config/WebSecurityConfig.java index 5441dac7f7..0b6cd34f3e 100644 --- a/spring-security-core/src/main/java/org/baeldung/config/WebSecurityConfig.java +++ b/spring-security-core/src/main/java/org/baeldung/config/WebSecurityConfig.java @@ -20,6 +20,9 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { - auth.inMemoryAuthentication().withUser("jim").password("jim").roles("USER").and().withUser("pam").password("pam").roles("USER").and().withUser("michael").password("michael").roles("MANAGER"); + auth.inMemoryAuthentication() + .withUser("jim").password("jim").roles("USER", "ACTUATOR") + .and().withUser("pam").password("pam").roles("USER") + .and().withUser("michael").password("michael").roles("MANAGER"); } } diff --git a/spring-state-machine/src/main/java/com/baeldung/spring/statemachine/config/SimpleStateMachineConfiguration.java b/spring-state-machine/src/main/java/com/baeldung/spring/statemachine/config/SimpleStateMachineConfiguration.java index f6c7991cf6..d1b1ce001c 100644 --- a/spring-state-machine/src/main/java/com/baeldung/spring/statemachine/config/SimpleStateMachineConfiguration.java +++ b/spring-state-machine/src/main/java/com/baeldung/spring/statemachine/config/SimpleStateMachineConfiguration.java @@ -1,9 +1,5 @@ package com.baeldung.spring.statemachine.config; -import java.util.Arrays; -import java.util.HashSet; -import java.util.logging.Logger; - import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.statemachine.action.Action; @@ -14,6 +10,10 @@ import org.springframework.statemachine.config.builders.StateMachineStateConfigu import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer; import org.springframework.statemachine.guard.Guard; +import java.util.Arrays; +import java.util.HashSet; +import java.util.logging.Logger; + @Configuration @EnableStateMachine public class SimpleStateMachineConfiguration extends StateMachineConfigurerAdapter { @@ -21,94 +21,126 @@ public class SimpleStateMachineConfiguration extends StateMachineConfigurerAdapt public static final Logger LOGGER = Logger.getLogger(SimpleStateMachineConfiguration.class.getName()); @Override - public void configure(StateMachineConfigurationConfigurer config) - throws Exception { + public void configure(StateMachineConfigurationConfigurer config) throws Exception { config - .withConfiguration() - .autoStartup(true) - .listener(new StateMachineListener()); + .withConfiguration() + .autoStartup(true) + .listener(new StateMachineListener()); } @Override public void configure(StateMachineStateConfigurer states) throws Exception { states - .withStates() - .initial("SI") - .end("SF") - .states(new HashSet<>(Arrays.asList("S1", "S2"))) - .stateEntry("S3", entryAction()) - .stateExit("S3", exitAction()) - .state("S4", executeAction(), errorAction()) - .stateDo("S5", executeAction()); + .withStates() + .initial("SI") + .end("SF") + .states(new HashSet<>(Arrays.asList("S1", "S2"))) + .stateEntry("S3", entryAction()) + .stateExit("S3", exitAction()) + .state("S4", executeAction(), errorAction()) + .stateDo("S5", executeAction()); } @Override public void configure(StateMachineTransitionConfigurer transitions) throws Exception { - transitions.withExternal() - .source("SI").target("S1").event("E1").action(initAction()) - .and().withExternal() - .source("S1").target("S2").event("E2") - .and().withExternal() - .source("SI").target("S3").event("E3") - .and().withExternal() - .source("S3").target("S4").event("E4") - .and().withExternal() - .source("S4").target("S5").event("E5") - .and().withExternal() - .source("S5").target("SF").event("end").guard(simpleGuard()); + transitions + .withExternal() + .source("SI") + .target("S1") + .event("E1") + .action(initAction()) + .and() + .withExternal() + .source("S1") + .target("S2") + .event("E2") + .and() + .withExternal() + .source("SI") + .target("S3") + .event("E3") + .and() + .withExternal() + .source("S3") + .target("S4") + .event("E4") + .and() + .withExternal() + .source("S4") + .target("S5") + .event("E5") + .and() + .withExternal() + .source("S5") + .target("SF") + .event("end") + .guard(simpleGuard()); } @Bean public Guard simpleGuard() { return (ctx) -> { - int approvalCount = (int) ctx.getExtendedState().getVariables().getOrDefault("approvalCount", 0); + int approvalCount = (int) ctx + .getExtendedState() + .getVariables() + .getOrDefault("approvalCount", 0); return approvalCount > 0; }; } @Bean public Action entryAction() { - return (ctx) -> { - LOGGER.info("Entry " + ctx.getTarget().getId()); - }; + return ctx -> LOGGER.info("Entry " + ctx + .getTarget() + .getId()); } @Bean public Action doAction() { - return (ctx) -> { - LOGGER.info("Do " + ctx.getTarget().getId()); - }; + return ctx -> LOGGER.info("Do " + ctx + .getTarget() + .getId()); } @Bean public Action executeAction() { - return (ctx) -> { - LOGGER.info("Execute " + ctx.getTarget().getId()); - int approvals = (int) ctx.getExtendedState().getVariables().getOrDefault("approvalCount", 0); + return ctx -> { + LOGGER.info("Execute " + ctx + .getTarget() + .getId()); + int approvals = (int) ctx + .getExtendedState() + .getVariables() + .getOrDefault("approvalCount", 0); approvals++; - ctx.getExtendedState().getVariables().put("approvalCount", approvals); + ctx + .getExtendedState() + .getVariables() + .put("approvalCount", approvals); }; } @Bean public Action exitAction() { - return (ctx) -> { - LOGGER.info("Exit " + ctx.getSource().getId() + " -> " + ctx.getTarget().getId()); - }; + return ctx -> LOGGER.info("Exit " + ctx + .getSource() + .getId() + " -> " + ctx + .getTarget() + .getId()); } @Bean public Action errorAction() { - return (ctx) -> { - LOGGER.info("Error " + ctx.getSource().getId() + ctx.getException()); - }; + return ctx -> LOGGER.info("Error " + ctx + .getSource() + .getId() + ctx.getException()); } @Bean public Action initAction() { - return (ctx) -> { - LOGGER.info(ctx.getTarget().getId()); - }; + return ctx -> LOGGER.info(ctx + .getTarget() + .getId()); } } \ No newline at end of file diff --git a/spring-state-machine/src/test/java/com/baeldung/spring/statemachine/ForkJoinStateMachineTest.java b/spring-state-machine/src/test/java/com/baeldung/spring/statemachine/ForkJoinStateMachineTest.java index 0de61da3bd..a9aca82a6e 100644 --- a/spring-state-machine/src/test/java/com/baeldung/spring/statemachine/ForkJoinStateMachineTest.java +++ b/spring-state-machine/src/test/java/com/baeldung/spring/statemachine/ForkJoinStateMachineTest.java @@ -6,6 +6,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.statemachine.StateMachine; import org.springframework.test.context.ContextConfiguration; @@ -21,7 +22,7 @@ import static org.junit.Assert.assertTrue; @ContextConfiguration(classes = ForkJoinStateMachineConfiguration.class) public class ForkJoinStateMachineTest { - @Resource + @Autowired private StateMachine stateMachine; @Before diff --git a/spring-state-machine/src/test/java/com/baeldung/spring/statemachine/HierarchicalStateMachineTest.java b/spring-state-machine/src/test/java/com/baeldung/spring/statemachine/HierarchicalStateMachineTest.java index 76105368d8..a2fa4f9160 100644 --- a/spring-state-machine/src/test/java/com/baeldung/spring/statemachine/HierarchicalStateMachineTest.java +++ b/spring-state-machine/src/test/java/com/baeldung/spring/statemachine/HierarchicalStateMachineTest.java @@ -6,6 +6,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.statemachine.StateMachine; import org.springframework.test.context.ContextConfiguration; @@ -20,7 +21,7 @@ import static org.junit.Assert.assertEquals; @ContextConfiguration(classes = HierarchicalStateMachineConfiguration.class) public class HierarchicalStateMachineTest { - @Resource + @Autowired private StateMachine stateMachine; @Before diff --git a/spring-state-machine/src/test/java/com/baeldung/spring/statemachine/JunctionStateMachineTest.java b/spring-state-machine/src/test/java/com/baeldung/spring/statemachine/JunctionStateMachineTest.java index b91e6af5c5..2b5130ab45 100644 --- a/spring-state-machine/src/test/java/com/baeldung/spring/statemachine/JunctionStateMachineTest.java +++ b/spring-state-machine/src/test/java/com/baeldung/spring/statemachine/JunctionStateMachineTest.java @@ -7,6 +7,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.statemachine.StateMachine; import org.springframework.test.context.ContextConfiguration; @@ -18,7 +19,7 @@ import javax.annotation.Resource; @ContextConfiguration(classes = JunctionStateMachineConfiguration.class) public class JunctionStateMachineTest { - @Resource + @Autowired private StateMachine stateMachine; @Before diff --git a/spring-state-machine/src/test/java/com/baeldung/spring/statemachine/StateEnumMachineTest.java b/spring-state-machine/src/test/java/com/baeldung/spring/statemachine/StateEnumMachineTest.java index cd9e58eb8e..19f24ede2d 100644 --- a/spring-state-machine/src/test/java/com/baeldung/spring/statemachine/StateEnumMachineTest.java +++ b/spring-state-machine/src/test/java/com/baeldung/spring/statemachine/StateEnumMachineTest.java @@ -8,6 +8,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.statemachine.StateMachine; import org.springframework.test.context.ContextConfiguration; @@ -22,7 +23,7 @@ import static org.junit.Assert.assertTrue; @ContextConfiguration(classes = SimpleEnumStateMachineConfiguration.class) public class StateEnumMachineTest { - @Resource + @Autowired private StateMachine stateMachine; @Before diff --git a/spring-state-machine/src/test/java/com/baeldung/spring/statemachine/StateMachineIntegrationTest.java b/spring-state-machine/src/test/java/com/baeldung/spring/statemachine/StateMachineIntegrationTest.java index 1c1ab58917..25df7c8cd3 100644 --- a/spring-state-machine/src/test/java/com/baeldung/spring/statemachine/StateMachineIntegrationTest.java +++ b/spring-state-machine/src/test/java/com/baeldung/spring/statemachine/StateMachineIntegrationTest.java @@ -7,6 +7,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.statemachine.StateMachine; @@ -21,7 +22,7 @@ import javax.annotation.Resource; @ContextConfiguration(classes = SimpleStateMachineConfiguration.class) public class StateMachineIntegrationTest { - @Resource + @Autowired private StateMachine stateMachine; @Before diff --git a/vertx/src/main/java/com/baledung/rest/RestServiceVerticle.java b/vertx/src/main/java/com/baeldung/rest/RestServiceVerticle.java similarity index 97% rename from vertx/src/main/java/com/baledung/rest/RestServiceVerticle.java rename to vertx/src/main/java/com/baeldung/rest/RestServiceVerticle.java index 802f74942e..1517a2f943 100644 --- a/vertx/src/main/java/com/baledung/rest/RestServiceVerticle.java +++ b/vertx/src/main/java/com/baeldung/rest/RestServiceVerticle.java @@ -1,4 +1,4 @@ -package com.baledung.rest; +package com.baeldung.rest; import com.baeldung.model.Article; diff --git a/vertx/src/main/conf/conf.json b/vertx/src/main/resources/conf/conf.json similarity index 100% rename from vertx/src/main/conf/conf.json rename to vertx/src/main/resources/conf/conf.json diff --git a/vertx/src/resources/logback.xml b/vertx/src/main/resources/logback.xml similarity index 100% rename from vertx/src/resources/logback.xml rename to vertx/src/main/resources/logback.xml diff --git a/vertx/src/test/java/com/baeldung/RestServiceVerticleIntegrationTest.java b/vertx/src/test/java/com/baeldung/RestServiceVerticleIntegrationTest.java index f08d9ffde1..40fa6c7220 100644 --- a/vertx/src/test/java/com/baeldung/RestServiceVerticleIntegrationTest.java +++ b/vertx/src/test/java/com/baeldung/RestServiceVerticleIntegrationTest.java @@ -5,7 +5,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import com.baledung.rest.RestServiceVerticle; +import com.baeldung.rest.RestServiceVerticle; import io.vertx.core.Vertx; import io.vertx.ext.unit.Async;