Merge remote-tracking branch 'upstream/master'
This commit is contained in:
		
						commit
						37a88d6aaa
					
				
							
								
								
									
										50
									
								
								annotations/annotation-processing/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								annotations/annotation-processing/pom.xml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,50 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||
|          xmlns="http://maven.apache.org/POM/4.0.0" | ||||
|          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||
|     <modelVersion>4.0.0</modelVersion> | ||||
| 
 | ||||
|     <parent> | ||||
|         <groupId>com.baeldung</groupId> | ||||
|         <version>1.0.0-SNAPSHOT</version> | ||||
|         <artifactId>annotations</artifactId> | ||||
|         <relativePath>../</relativePath> | ||||
|     </parent> | ||||
| 
 | ||||
|     <artifactId>annotation-processing</artifactId> | ||||
| 
 | ||||
|     <properties> | ||||
|         <auto-service.version>1.0-rc2</auto-service.version> | ||||
|         <maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version> | ||||
|     </properties> | ||||
| 
 | ||||
|     <dependencies> | ||||
| 
 | ||||
|         <dependency> | ||||
|             <groupId>com.google.auto.service</groupId> | ||||
|             <artifactId>auto-service</artifactId> | ||||
|             <version>${auto-service.version}</version> | ||||
|             <scope>provided</scope> | ||||
|         </dependency> | ||||
| 
 | ||||
|     </dependencies> | ||||
| 
 | ||||
|     <build> | ||||
| 
 | ||||
|         <plugins> | ||||
| 
 | ||||
|             <plugin> | ||||
|                 <groupId>org.apache.maven.plugins</groupId> | ||||
|                 <artifactId>maven-compiler-plugin</artifactId> | ||||
|                 <version>${maven-compiler-plugin.version}</version> | ||||
|                 <configuration> | ||||
|                     <source>1.8</source> | ||||
|                     <target>1.8</target> | ||||
|                 </configuration> | ||||
|             </plugin> | ||||
| 
 | ||||
|         </plugins> | ||||
| 
 | ||||
|     </build> | ||||
| 
 | ||||
| </project> | ||||
| @ -0,0 +1,132 @@ | ||||
| package com.baeldung.annotation.processor; | ||||
| 
 | ||||
| import java.io.IOException; | ||||
| import java.io.PrintWriter; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import java.util.Set; | ||||
| import java.util.stream.Collectors; | ||||
| import javax.annotation.processing.*; | ||||
| import javax.lang.model.SourceVersion; | ||||
| import javax.lang.model.element.Element; | ||||
| import javax.lang.model.element.TypeElement; | ||||
| import javax.lang.model.type.ExecutableType; | ||||
| import javax.tools.Diagnostic; | ||||
| import javax.tools.JavaFileObject; | ||||
| 
 | ||||
| import com.google.auto.service.AutoService; | ||||
| 
 | ||||
| @SupportedAnnotationTypes("com.baeldung.annotation.processor.BuilderProperty") | ||||
| @SupportedSourceVersion(SourceVersion.RELEASE_8) | ||||
| @AutoService(Processor.class) | ||||
| public class BuilderProcessor extends AbstractProcessor { | ||||
| 
 | ||||
|     @Override | ||||
|     public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { | ||||
|         for (TypeElement annotation : annotations) { | ||||
| 
 | ||||
|             Set<? extends Element> annotatedElements = roundEnv.getElementsAnnotatedWith(annotation); | ||||
| 
 | ||||
|             Map<Boolean, List<Element>> annotatedMethods = annotatedElements.stream() | ||||
|                     .collect(Collectors.partitioningBy(element -> | ||||
|                             ((ExecutableType) element.asType()).getParameterTypes().size() == 1 | ||||
|                                     && element.getSimpleName().toString().startsWith("set"))); | ||||
| 
 | ||||
|             List<Element> setters = annotatedMethods.get(true); | ||||
|             List<Element> otherMethods = annotatedMethods.get(false); | ||||
| 
 | ||||
|             otherMethods.forEach(element -> | ||||
|                     processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, | ||||
|                             "@BuilderProperty must be applied to a setXxx method with a single argument", element)); | ||||
| 
 | ||||
|             if (setters.isEmpty()) { | ||||
|                 continue; | ||||
|             } | ||||
| 
 | ||||
|             String className = ((TypeElement) setters.get(0).getEnclosingElement()).getQualifiedName().toString(); | ||||
| 
 | ||||
|             Map<String, String> setterMap = setters.stream().collect(Collectors.toMap( | ||||
|                     setter -> setter.getSimpleName().toString(), | ||||
|                     setter -> ((ExecutableType) setter.asType()) | ||||
|                             .getParameterTypes().get(0).toString() | ||||
|             )); | ||||
| 
 | ||||
|             try { | ||||
|                 writeBuilderFile(className, setterMap); | ||||
|             } catch (IOException e) { | ||||
|                 e.printStackTrace(); | ||||
|             } | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     private void writeBuilderFile(String className, Map<String, String> setterMap) throws IOException { | ||||
| 
 | ||||
|         String packageName = null; | ||||
|         int lastDot = className.lastIndexOf('.'); | ||||
|         if (lastDot > 0) { | ||||
|             packageName = className.substring(0, lastDot); | ||||
|         } | ||||
| 
 | ||||
|         String simpleClassName = className.substring(lastDot + 1); | ||||
|         String builderClassName = className + "Builder"; | ||||
|         String builderSimpleClassName = builderClassName.substring(lastDot + 1); | ||||
| 
 | ||||
|         JavaFileObject builderFile = processingEnv.getFiler().createSourceFile(builderClassName); | ||||
|         try (PrintWriter out = new PrintWriter(builderFile.openWriter())) { | ||||
| 
 | ||||
|             if (packageName != null) { | ||||
|                 out.print("package "); | ||||
|                 out.print(packageName); | ||||
|                 out.println(";"); | ||||
|                 out.println(); | ||||
|             } | ||||
| 
 | ||||
|             out.print("public class "); | ||||
|             out.print(builderSimpleClassName); | ||||
|             out.println(" {"); | ||||
|             out.println(); | ||||
| 
 | ||||
|             out.print("    private "); | ||||
|             out.print(simpleClassName); | ||||
|             out.print(" object = new "); | ||||
|             out.print(simpleClassName); | ||||
|             out.println("();"); | ||||
|             out.println(); | ||||
| 
 | ||||
|             out.print("    public "); | ||||
|             out.print(simpleClassName); | ||||
|             out.println(" build() {"); | ||||
|             out.println("        return object;"); | ||||
|             out.println("    }"); | ||||
|             out.println(); | ||||
| 
 | ||||
|             setterMap.entrySet().forEach(setter -> { | ||||
|                 String methodName = setter.getKey(); | ||||
|                 String argumentType = setter.getValue(); | ||||
| 
 | ||||
|                 out.print("    public "); | ||||
|                 out.print(builderSimpleClassName); | ||||
|                 out.print(" "); | ||||
|                 out.print(methodName); | ||||
| 
 | ||||
|                 out.print("("); | ||||
| 
 | ||||
|                 out.print(argumentType); | ||||
|                 out.println(" value) {"); | ||||
|                 out.print("        object."); | ||||
|                 out.print(methodName); | ||||
|                 out.println("(value);"); | ||||
|                 out.println("        return this;"); | ||||
|                 out.println("    }"); | ||||
|                 out.println(); | ||||
|             }); | ||||
| 
 | ||||
|             out.println("}"); | ||||
| 
 | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,8 @@ | ||||
| package com.baeldung.annotation.processor; | ||||
| 
 | ||||
| import java.lang.annotation.*; | ||||
| 
 | ||||
| @Target(ElementType.METHOD) | ||||
| @Retention(RetentionPolicy.SOURCE) | ||||
| public @interface BuilderProperty { | ||||
| } | ||||
							
								
								
									
										51
									
								
								annotations/annotation-user/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								annotations/annotation-user/pom.xml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,51 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||||
|          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||
|          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||
|     <modelVersion>4.0.0</modelVersion> | ||||
| 
 | ||||
|     <parent> | ||||
|         <artifactId>annotations</artifactId> | ||||
|         <groupId>com.baeldung</groupId> | ||||
|         <version>1.0.0-SNAPSHOT</version> | ||||
|         <relativePath>../</relativePath> | ||||
|     </parent> | ||||
| 
 | ||||
|     <artifactId>annotation-user</artifactId> | ||||
| 
 | ||||
|     <dependencies> | ||||
| 
 | ||||
|         <dependency> | ||||
|             <groupId>com.baeldung</groupId> | ||||
|             <artifactId>annotation-processing</artifactId> | ||||
|             <version>${project.parent.version}</version> | ||||
|         </dependency> | ||||
| 
 | ||||
|         <dependency> | ||||
|             <groupId>junit</groupId> | ||||
|             <artifactId>junit</artifactId> | ||||
|             <version>4.12</version> | ||||
|             <scope>test</scope> | ||||
|         </dependency> | ||||
| 
 | ||||
|     </dependencies> | ||||
| 
 | ||||
|     <build> | ||||
| 
 | ||||
|         <plugins> | ||||
| 
 | ||||
|             <plugin> | ||||
|                 <groupId>org.apache.maven.plugins</groupId> | ||||
|                 <artifactId>maven-compiler-plugin</artifactId> | ||||
|                 <version>3.5.1</version> | ||||
|                 <configuration> | ||||
|                     <source>1.8</source> | ||||
|                     <target>1.8</target> | ||||
|                 </configuration> | ||||
|             </plugin> | ||||
| 
 | ||||
|         </plugins> | ||||
| 
 | ||||
|     </build> | ||||
| 
 | ||||
| </project> | ||||
| @ -0,0 +1,29 @@ | ||||
| package com.baeldung.annotation; | ||||
| 
 | ||||
| import com.baeldung.annotation.processor.BuilderProperty; | ||||
| 
 | ||||
| public class Person { | ||||
| 
 | ||||
|     private int age; | ||||
| 
 | ||||
|     private String name; | ||||
| 
 | ||||
|     public int getAge() { | ||||
|         return age; | ||||
|     } | ||||
| 
 | ||||
|     @BuilderProperty | ||||
|     public void setAge(int age) { | ||||
|         this.age = age; | ||||
|     } | ||||
| 
 | ||||
|     public String getName() { | ||||
|         return name; | ||||
|     } | ||||
| 
 | ||||
|     @BuilderProperty | ||||
|     public void setName(String name) { | ||||
|         this.name = name; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,22 @@ | ||||
| package com.baeldung.annotation; | ||||
| 
 | ||||
| import org.junit.Test; | ||||
| 
 | ||||
| import static org.junit.Assert.assertEquals; | ||||
| 
 | ||||
| public class PersonBuilderTest { | ||||
| 
 | ||||
|     @Test | ||||
|     public void whenBuildPersonWithBuilder_thenObjectHasPropertyValues() { | ||||
| 
 | ||||
|         Person person = new PersonBuilder() | ||||
|                 .setAge(25) | ||||
|                 .setName("John") | ||||
|                 .build(); | ||||
| 
 | ||||
|         assertEquals(25, person.getAge()); | ||||
|         assertEquals("John", person.getName()); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @ -2,14 +2,19 @@ | ||||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||||
|          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||
|          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||
|     <parent> | ||||
|         <artifactId>parent-modules</artifactId> | ||||
|         <groupId>com.baeldung</groupId> | ||||
|         <version>1.0.0-SNAPSHOT</version> | ||||
|     </parent> | ||||
|     <modelVersion>4.0.0</modelVersion> | ||||
| 
 | ||||
|     <groupId>com.baeldung.spring.cloud</groupId> | ||||
|     <artifactId>spring-cloud-integration</artifactId> | ||||
|     <version>1.0.0-SNAPSHOT</version> | ||||
|     <artifactId>annotations</artifactId> | ||||
|     <packaging>pom</packaging> | ||||
| 
 | ||||
|     <modules> | ||||
|         <module>part-1</module> | ||||
|         <module>annotation-processing</module> | ||||
|         <module>annotation-user</module> | ||||
|     </modules> | ||||
| 
 | ||||
| </project> | ||||
| @ -11,4 +11,14 @@ | ||||
| - [Lambda Expressions and Functional Interfaces: Tips and Best Practices](http://www.baeldung.com/java-8-lambda-expressions-tips) | ||||
| - [The Double Colon Operator in Java 8](http://www.baeldung.com/java-8-double-colon-operator) | ||||
| - [Java 8 Streams Advanced](http://www.baeldung.com/java-8-streams) | ||||
| - [Java 8 Collectors](http://www.baeldung.com/java-8-collectors) | ||||
| - [Java 8 Collectors](http://www.baeldung.com/java-8-collectors) | ||||
| - [Convert String to int or Integer in Java](http://www.baeldung.com/java-convert-string-to-int-or-integer) | ||||
| - [Convert char to String in Java](http://www.baeldung.com/java-convert-char-to-string) | ||||
| - [Guide to Java 8’s Functional Interfaces](http://www.baeldung.com/java-8-functional-interfaces) | ||||
| - [Guide To CompletableFuture](http://www.baeldung.com/java-completablefuture) | ||||
| - [Introduction to Thread Pools in Java](http://www.baeldung.com/thread-pool-java-and-guava) | ||||
| - [Guide to Java 8 Collectors](http://www.baeldung.com/java-8-collectors) | ||||
| - [The Java 8 Stream API Tutorial](http://www.baeldung.com/java-8-streams) | ||||
| - [New Features in Java 8](http://www.baeldung.com/java-8-new-features) | ||||
| - [Introduction to Java 8 Streams](http://www.baeldung.com/java-8-streams-introduction) | ||||
| - [Guide to the Fork/Join Framework in Java](http://www.baeldung.com/java-fork-join) | ||||
|  | ||||
| @ -1,9 +1,10 @@ | ||||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||
|          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||
|     <modelVersion>4.0.0</modelVersion> | ||||
| 
 | ||||
|     <groupId>com.baeldung</groupId> | ||||
|     <version>1.0.0-SNAPSHOT</version> | ||||
|     <artifactId>core-java8</artifactId> | ||||
|     <version>0.1-SNAPSHOT</version> | ||||
| 
 | ||||
|     <name>core-java8</name> | ||||
| 
 | ||||
| @ -111,6 +112,9 @@ | ||||
|     </build> | ||||
| 
 | ||||
|     <properties> | ||||
| 
 | ||||
|         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||||
| 
 | ||||
|         <!-- logging --> | ||||
|         <org.slf4j.version>1.7.13</org.slf4j.version> | ||||
|         <logback.version>1.0.13</logback.version> | ||||
|  | ||||
							
								
								
									
										1
									
								
								core-java-8/src/main/resources/fileTest.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								core-java-8/src/main/resources/fileTest.txt
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | ||||
| Hello World from fileTest.txt!!! | ||||
| @ -0,0 +1,78 @@ | ||||
| package com.baeldung.file; | ||||
| 
 | ||||
| import org.hamcrest.Matchers; | ||||
| import org.junit.Assert; | ||||
| import org.junit.Test; | ||||
| 
 | ||||
| import java.io.BufferedReader; | ||||
| import java.io.IOException; | ||||
| import java.io.InputStream; | ||||
| import java.io.InputStreamReader; | ||||
| import java.net.URL; | ||||
| import java.net.URLConnection; | ||||
| 
 | ||||
| import static org.hamcrest.CoreMatchers.containsString; | ||||
| 
 | ||||
| public class FileOperationsTest { | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenFileName_whenUsingClassloader_thenFileData() throws IOException { | ||||
|         String expectedData = "Hello World from fileTest.txt!!!"; | ||||
| 
 | ||||
|         ClassLoader classLoader = getClass().getClassLoader(); | ||||
|         InputStream inputStream = classLoader.getResourceAsStream("fileTest.txt"); | ||||
|         String data = readFromInputStream(inputStream); | ||||
| 
 | ||||
|         Assert.assertThat(data, containsString(expectedData)); | ||||
| } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenFileNameAsAbsolutePath_whenUsingClasspath_thenFileData() throws IOException { | ||||
|         String expectedData = "Hello World from fileTest.txt!!!"; | ||||
| 
 | ||||
|         Class clazz = FileOperationsTest.class; | ||||
|         InputStream inputStream = clazz.getResourceAsStream("/fileTest.txt"); | ||||
|         String data = readFromInputStream(inputStream); | ||||
| 
 | ||||
|         Assert.assertThat(data, containsString(expectedData)); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenURLName_whenUsingURL_thenFileData() throws IOException { | ||||
|         String expectedData = "Baeldung"; | ||||
| 
 | ||||
|         URL urlObject = new URL("http://www.baeldung.com/"); | ||||
|         URLConnection urlConnection = urlObject.openConnection(); | ||||
| 
 | ||||
|         InputStream inputStream = urlConnection.getInputStream(); | ||||
|         String data = readFromInputStream(inputStream); | ||||
| 
 | ||||
|         Assert.assertThat(data, containsString(expectedData)); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenFileName_whenUsingJarFile_thenFileData() throws IOException { | ||||
|         String expectedData = "BSD License"; | ||||
| 
 | ||||
|         Class clazz = Matchers.class; | ||||
|         InputStream inputStream = clazz.getResourceAsStream("/LICENSE.txt"); | ||||
|         String data = readFromInputStream(inputStream); | ||||
| 
 | ||||
|         Assert.assertThat(data, containsString(expectedData)); | ||||
|     } | ||||
| 
 | ||||
|     private String readFromInputStream(InputStream inputStream) throws IOException { | ||||
|         InputStreamReader inputStreamReader = new InputStreamReader(inputStream); | ||||
|         BufferedReader bufferedReader = new BufferedReader(inputStreamReader); | ||||
|         StringBuilder resultStringBuilder = new StringBuilder(); | ||||
|         String line; | ||||
|         while ((line = bufferedReader.readLine()) != null) { | ||||
|             resultStringBuilder.append(line); | ||||
|             resultStringBuilder.append("\n"); | ||||
|         } | ||||
|         bufferedReader.close(); | ||||
|         inputStreamReader.close(); | ||||
|         inputStream.close(); | ||||
|         return resultStringBuilder.toString(); | ||||
|     } | ||||
| } | ||||
| @ -21,7 +21,7 @@ public class JavaFolderSizeTest { | ||||
|     @Before | ||||
|     public void init() { | ||||
|         final String separator = File.separator; | ||||
|         path = "src" + separator + "test" + separator + "resources"; | ||||
|         path = String.format("src%stest%sresources", separator, separator); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
| @ -79,7 +79,9 @@ public class JavaFolderSizeTest { | ||||
|         final File folder = new File(path); | ||||
| 
 | ||||
|         final Iterable<File> files = com.google.common.io.Files.fileTreeTraverser().breadthFirstTraversal(folder); | ||||
|         final long size = StreamSupport.stream(files.spliterator(), false).filter(f -> f.isFile()).mapToLong(File::length).sum(); | ||||
|         final long size = StreamSupport.stream(files.spliterator(), false) | ||||
|           .filter(File::isFile) | ||||
|           .mapToLong(File::length).sum(); | ||||
| 
 | ||||
|         assertEquals(expectedSize, size); | ||||
|     } | ||||
| @ -101,13 +103,11 @@ public class JavaFolderSizeTest { | ||||
|         long length = 0; | ||||
|         final File[] files = folder.listFiles(); | ||||
| 
 | ||||
|         final int count = files.length; | ||||
| 
 | ||||
|         for (int i = 0; i < count; i++) { | ||||
|             if (files[i].isFile()) { | ||||
|                 length += files[i].length(); | ||||
|         for (File file : files) { | ||||
|             if (file.isFile()) { | ||||
|                 length += file.length(); | ||||
|             } else { | ||||
|                 length += getFolderSize(files[i]); | ||||
|                 length += getFolderSize(file); | ||||
|             } | ||||
|         } | ||||
|         return length; | ||||
|  | ||||
| @ -0,0 +1,47 @@ | ||||
| package com.baeldung.util; | ||||
| 
 | ||||
| import static org.junit.Assert.assertEquals; | ||||
| 
 | ||||
| import java.time.Instant; | ||||
| import java.time.LocalDate; | ||||
| import java.time.LocalTime; | ||||
| import java.time.temporal.ChronoField; | ||||
| import java.util.Calendar; | ||||
| import java.util.GregorianCalendar; | ||||
| 
 | ||||
| import org.junit.Test; | ||||
| 
 | ||||
| public class CurrentDateTimeTest { | ||||
| 
 | ||||
|     @Test | ||||
|     public void shouldReturnCurrentDate() { | ||||
| 
 | ||||
|         final LocalDate now = LocalDate.now(); | ||||
|         final Calendar calendar = GregorianCalendar.getInstance(); | ||||
| 
 | ||||
|         assertEquals("10-10-2010".length(), now.toString().length()); | ||||
|         assertEquals(calendar.get(Calendar.DATE), now.get(ChronoField.DAY_OF_MONTH)); | ||||
|         assertEquals(calendar.get(Calendar.MONTH), now.get(ChronoField.MONTH_OF_YEAR) - 1); | ||||
|         assertEquals(calendar.get(Calendar.YEAR), now.get(ChronoField.YEAR)); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void shouldReturnCurrentTime() { | ||||
| 
 | ||||
|         final LocalTime now = LocalTime.now(); | ||||
|         final Calendar calendar = GregorianCalendar.getInstance(); | ||||
| 
 | ||||
|         assertEquals(calendar.get(Calendar.HOUR_OF_DAY), now.get(ChronoField.HOUR_OF_DAY)); | ||||
|         assertEquals(calendar.get(Calendar.MINUTE), now.get(ChronoField.MINUTE_OF_HOUR)); | ||||
|         assertEquals(calendar.get(Calendar.SECOND), now.get(ChronoField.SECOND_OF_MINUTE)); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void shouldReturnCurrentTimestamp() { | ||||
| 
 | ||||
|         final Instant now = Instant.now(); | ||||
|         final Calendar calendar = GregorianCalendar.getInstance(); | ||||
| 
 | ||||
|         assertEquals(calendar.getTimeInMillis() / 1000, now.getEpochSecond()); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										13
									
								
								core-java-8/src/test/resources/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										13
									
								
								core-java-8/src/test/resources/.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -1,13 +0,0 @@ | ||||
| *.class | ||||
| 
 | ||||
| #folders# | ||||
| /target | ||||
| /neoDb* | ||||
| /data | ||||
| /src/main/webapp/WEB-INF/classes | ||||
| */META-INF/* | ||||
| 
 | ||||
| # Packaged files # | ||||
| *.jar | ||||
| *.war | ||||
| *.ear | ||||
							
								
								
									
										1
									
								
								core-java-8/src/test/resources/test.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								core-java-8/src/test/resources/test.txt
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | ||||
| Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse facilisis neque sed turpis venenatis, non dignissim risus volutpat. | ||||
| @ -60,12 +60,8 @@ | ||||
| 				<configuration> | ||||
| 					<source>1.9</source> | ||||
| 					<target>1.9</target> | ||||
| 
 | ||||
| 					<verbose>true</verbose> | ||||
| 					<!-- <executable>C:\develop\jdks\jdk-9_ea122\bin\javac</executable>  | ||||
| 						<compilerVersion>1.9</compilerVersion> --> | ||||
| 				</configuration> | ||||
| 
 | ||||
| 			</plugin> | ||||
| 
 | ||||
| 			<plugin> | ||||
| @ -85,12 +81,7 @@ | ||||
| 
 | ||||
| 
 | ||||
| 		<!-- maven plugins --> | ||||
| 		<!--  | ||||
| 		<maven-war-plugin.version>2.6</maven-war-plugin.version> | ||||
| 		maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version> --> | ||||
| 		<maven-compiler-plugin.version>3.6-jigsaw-SNAPSHOT</maven-compiler-plugin.version> | ||||
| 
 | ||||
| 		 | ||||
| 		<maven-compiler-plugin.version>3.6-jigsaw-SNAPSHOT</maven-compiler-plugin.version>	 | ||||
| 		<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version> | ||||
| 
 | ||||
| 		<!-- testing --> | ||||
|  | ||||
| @ -42,6 +42,19 @@ public class Java9OptionalsStreamTest { | ||||
|         assertEquals("bar", filteredList.get(1)); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void filterOutPresentOptionalsWithFlatMap2() { | ||||
|         assertEquals(4, listOfOptionals.size()); | ||||
| 
 | ||||
|         List<String> filteredList = listOfOptionals.stream() | ||||
|           .flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty)) | ||||
|           .collect(Collectors.toList()); | ||||
|         assertEquals(2, filteredList.size()); | ||||
| 
 | ||||
|         assertEquals("foo", filteredList.get(0)); | ||||
|         assertEquals("bar", filteredList.get(1)); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void filterOutPresentOptionalsWithJava9() { | ||||
|         assertEquals(4, listOfOptionals.size()); | ||||
|  | ||||
| @ -1,6 +1,5 @@ | ||||
| package com.baeldung.java9; | ||||
| 
 | ||||
| import static org.junit.Assert.assertTrue; | ||||
| 
 | ||||
| import static org.junit.Assert.assertEquals; | ||||
| import static org.junit.Assert.assertSame; | ||||
| 
 | ||||
|  | ||||
| @ -0,0 +1,21 @@ | ||||
| package com.baeldung.java9; | ||||
| 
 | ||||
| import java.util.Optional; | ||||
| import java.util.stream.Stream; | ||||
| 
 | ||||
| import org.junit.Test; | ||||
| import static org.junit.Assert.assertEquals; | ||||
| 
 | ||||
| public class OptionalToStreamTest { | ||||
| 
 | ||||
|     @Test | ||||
|     public void testOptionalToStream() { | ||||
|         Optional<String> op = Optional.ofNullable("String value"); | ||||
|         Stream<String> strOptionalStream = op.stream(); | ||||
|         Stream<String> filteredStream = strOptionalStream.filter((str) -> { | ||||
|             return str != null && str.startsWith("String"); | ||||
|         }); | ||||
|         assertEquals(1, filteredStream.count()); | ||||
| 
 | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,26 @@ | ||||
| package com.baeldung.java9; | ||||
| 
 | ||||
| import java.util.Set; | ||||
| import org.junit.Test; | ||||
| 
 | ||||
| import static org.junit.Assert.assertEquals; | ||||
| 
 | ||||
| public class SetExamplesTest { | ||||
| 
 | ||||
|     @Test | ||||
|     public void testUnmutableSet() { | ||||
|         Set<String> strKeySet = Set.of("key1", "key2", "key3"); | ||||
|         try { | ||||
|             strKeySet.add("newKey"); | ||||
|         } catch (UnsupportedOperationException uoe) { | ||||
|         } | ||||
|         assertEquals(strKeySet.size(), 3); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void testArrayToSet() { | ||||
|         Integer[] intArray = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; | ||||
|         Set<Integer> intSet = Set.of(intArray); | ||||
|         assertEquals(intSet.size(), intArray.length); | ||||
|     } | ||||
| } | ||||
| @ -123,6 +123,12 @@ | ||||
|             <version>${mockito.version}</version> | ||||
|             <scope>test</scope> | ||||
|         </dependency> | ||||
|          | ||||
|         <dependency> | ||||
|             <groupId>commons-codec</groupId> | ||||
|             <artifactId>commons-codec</artifactId> | ||||
|             <version>1.10</version> | ||||
|         </dependency> | ||||
| 
 | ||||
|     </dependencies> | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										27
									
								
								core-java/src/main/java/com/baeldung/java/regex/Result.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								core-java/src/main/java/com/baeldung/java/regex/Result.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,27 @@ | ||||
| package com.baeldung.java.regex; | ||||
| 
 | ||||
| public class Result { | ||||
|     private boolean found = false; | ||||
|     private int count = 0; | ||||
| 
 | ||||
|     public Result() { | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     public boolean isFound() { | ||||
|         return found; | ||||
|     } | ||||
| 
 | ||||
|     public void setFound(boolean found) { | ||||
|         this.found = found; | ||||
|     } | ||||
| 
 | ||||
|     public int getCount() { | ||||
|         return count; | ||||
|     } | ||||
| 
 | ||||
|     public void setCount(int count) { | ||||
|         this.count = count; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,65 @@ | ||||
| package org.baeldung.equalshashcode.entities; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashSet; | ||||
| import java.util.List; | ||||
| import java.util.Set; | ||||
| 
 | ||||
| public class ComplexClass { | ||||
| 
 | ||||
|     private List<?> genericList; | ||||
|     private Set<Integer> integerSet; | ||||
| 
 | ||||
|     public ComplexClass(ArrayList<?> genericArrayList, HashSet<Integer> integerHashSet) { | ||||
|         super(); | ||||
|         this.genericList = genericArrayList; | ||||
|         this.integerSet = integerHashSet; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public int hashCode() { | ||||
|         final int prime = 31; | ||||
|         int result = 1; | ||||
|         result = prime * result + ((genericList == null) ? 0 : genericList.hashCode()); | ||||
|         result = prime * result + ((integerSet == null) ? 0 : integerSet.hashCode()); | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public boolean equals(Object obj) { | ||||
|         if (this == obj) | ||||
|             return true; | ||||
|         if (obj == null) | ||||
|             return false; | ||||
|         if (!(obj instanceof ComplexClass)) | ||||
|             return false; | ||||
|         ComplexClass other = (ComplexClass) obj; | ||||
|         if (genericList == null) { | ||||
|             if (other.genericList != null) | ||||
|                 return false; | ||||
|         } else if (!genericList.equals(other.genericList)) | ||||
|             return false; | ||||
|         if (integerSet == null) { | ||||
|             if (other.integerSet != null) | ||||
|                 return false; | ||||
|         } else if (!integerSet.equals(other.integerSet)) | ||||
|             return false; | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     protected List<?> getGenericList() { | ||||
|         return genericList; | ||||
|     } | ||||
| 
 | ||||
|     protected void setGenericArrayList(List<?> genericList) { | ||||
|         this.genericList = genericList; | ||||
|     } | ||||
| 
 | ||||
|     protected Set<Integer> getIntegerSet() { | ||||
|         return integerSet; | ||||
|     } | ||||
| 
 | ||||
|     protected void setIntegerSet(Set<Integer> integerSet) { | ||||
|         this.integerSet = integerSet; | ||||
|     } | ||||
| } | ||||
| @ -11,13 +11,11 @@ public class Rectangle extends Shape { | ||||
| 
 | ||||
|     @Override | ||||
|     public double area() { | ||||
|         // A = w * l | ||||
|         return width * length; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public double perimeter() { | ||||
|         // P = 2(w + l) | ||||
|         return 2 * (width + length); | ||||
|     } | ||||
| 
 | ||||
							
								
								
									
										503
									
								
								core-java/src/test/java/com/baeldung/java/regex/RegexTest.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										503
									
								
								core-java/src/test/java/com/baeldung/java/regex/RegexTest.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,503 @@ | ||||
| package com.baeldung.java.regex; | ||||
| 
 | ||||
| import static org.junit.Assert.*; | ||||
| 
 | ||||
| import java.util.regex.Matcher; | ||||
| import java.util.regex.Pattern; | ||||
| 
 | ||||
| import org.junit.Test; | ||||
| 
 | ||||
| public class RegexTest { | ||||
|     private static Pattern pattern; | ||||
|     private static Matcher matcher; | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenText_whenSimpleRegexMatches_thenCorrect() { | ||||
|         Result result = runTest("foo", "foo"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 1); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenText_whenSimpleRegexMatchesTwice_thenCorrect() { | ||||
|         Result result = runTest("foo", "foofoo"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 2); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenText_whenMatchesWithDotMetach_thenCorrect() { | ||||
|         Result result = runTest(".", "foo"); | ||||
|         assertTrue(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenRepeatedText_whenMatchesOnceWithDotMetach_thenCorrect() { | ||||
|         Result result = runTest("foo.", "foofoo"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 1); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenORSet_whenMatchesAny_thenCorrect() { | ||||
|         Result result = runTest("[abc]", "b"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 1); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenORSet_whenMatchesAnyAndAll_thenCorrect() { | ||||
|         Result result = runTest("[abc]", "cab"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 3); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenORSet_whenMatchesAllCombinations_thenCorrect() { | ||||
|         Result result = runTest("[bcr]at", "bat cat rat"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 3); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenNORSet_whenMatchesNon_thenCorrect() { | ||||
|         Result result = runTest("[^abc]", "g"); | ||||
|         assertTrue(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenNORSet_whenMatchesAllExceptElements_thenCorrect() { | ||||
|         Result result = runTest("[^bcr]at", "sat mat eat"); | ||||
|         assertTrue(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenUpperCaseRange_whenMatchesUpperCase_thenCorrect() { | ||||
|         Result result = runTest("[A-Z]", "Two Uppercase alphabets 34 overall"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 2); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenLowerCaseRange_whenMatchesLowerCase_thenCorrect() { | ||||
|         Result result = runTest("[a-z]", "Two Uppercase alphabets 34 overall"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 26); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenBothLowerAndUpperCaseRange_whenMatchesAllLetters_thenCorrect() { | ||||
|         Result result = runTest("[a-zA-Z]", "Two Uppercase alphabets 34 overall"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 28); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenNumberRange_whenMatchesAccurately_thenCorrect() { | ||||
|         Result result = runTest("[1-5]", "Two Uppercase alphabets 34 overall"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 2); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenNumberRange_whenMatchesAccurately_thenCorrect2() { | ||||
|         Result result = runTest("[30-35]", "Two Uppercase alphabets 34 overall"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 1); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenTwoSets_whenMatchesUnion_thenCorrect() { | ||||
|         Result result = runTest("[1-3[7-9]]", "123456789"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 6); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenTwoSets_whenMatchesIntersection_thenCorrect() { | ||||
|         Result result = runTest("[1-6&&[3-9]]", "123456789"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 4); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenSetWithSubtraction_whenMatchesAccurately_thenCorrect() { | ||||
|         Result result = runTest("[0-9&&[^2468]]", "123456789"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 5); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenDigits_whenMatches_thenCorrect() { | ||||
|         Result result = runTest("\\d", "123"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 3); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenNonDigits_whenMatches_thenCorrect() { | ||||
|         Result result = runTest("\\D", "a6c"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 2); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenWhiteSpace_whenMatches_thenCorrect() { | ||||
|         Result result = runTest("\\s", "a c"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 1); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenNonWhiteSpace_whenMatches_thenCorrect() { | ||||
|         Result result = runTest("\\S", "a c"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 2); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenWordCharacter_whenMatches_thenCorrect() { | ||||
|         Result result = runTest("\\w", "hi!"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 2); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenNonWordCharacter_whenMatches_thenCorrect() { | ||||
|         Result result = runTest("\\W", "hi!"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 1); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenZeroOrOneQuantifier_whenMatches_thenCorrect() { | ||||
|         Result result = runTest("\\a?", "hi"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 3); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenZeroOrOneQuantifier_whenMatches_thenCorrect2() { | ||||
|         Result result = runTest("\\a{0,1}", "hi"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 3); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenZeroOrManyQuantifier_whenMatches_thenCorrect() { | ||||
|         Result result = runTest("\\a*", "hi"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 3); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenZeroOrManyQuantifier_whenMatches_thenCorrect2() { | ||||
|         Result result = runTest("\\a{0,}", "hi"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 3); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenOneOrManyQuantifier_whenMatches_thenCorrect() { | ||||
|         Result result = runTest("\\a+", "hi"); | ||||
|         assertFalse(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenOneOrManyQuantifier_whenMatches_thenCorrect2() { | ||||
|         Result result = runTest("\\a{1,}", "hi"); | ||||
|         assertFalse(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenBraceQuantifier_whenMatches_thenCorrect() { | ||||
|         Result result = runTest("a{3}", "aaaaaa"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 2); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenBraceQuantifier_whenFailsToMatch_thenCorrect() { | ||||
|         Result result = runTest("a{3}", "aa"); | ||||
|         assertFalse(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenBraceQuantifierWithRange_whenMatches_thenCorrect() { | ||||
|         Result result = runTest("a{2,3}", "aaaa"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 1); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenBraceQuantifierWithRange_whenMatchesLazily_thenCorrect() { | ||||
|         Result result = runTest("a{2,3}?", "aaaa"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 2); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenCapturingGroup_whenMatches_thenCorrect() { | ||||
|         Result result = runTest("(\\d\\d)", "12"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 1); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenCapturingGroup_whenMatches_thenCorrect2() { | ||||
|         Result result = runTest("(\\d\\d)", "1212"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 2); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenCapturingGroup_whenMatches_thenCorrect3() { | ||||
|         Result result = runTest("(\\d\\d)(\\d\\d)", "1212"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 1); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenCapturingGroup_whenMatchesWithBackReference_thenCorrect() { | ||||
|         Result result = runTest("(\\d\\d)\\1", "1212"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 1); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenCapturingGroup_whenMatchesWithBackReference_thenCorrect2() { | ||||
|         Result result = runTest("(\\d\\d)\\1\\1\\1", "12121212"); | ||||
|         assertTrue(result.isFound()); | ||||
|         assertEquals(result.getCount(), 1); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenCapturingGroupAndWrongInput_whenMatchFailsWithBackReference_thenCorrect() { | ||||
|         Result result = runTest("(\\d\\d)\\1", "1213"); | ||||
|         assertFalse(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenText_whenMatchesAtBeginning_thenCorrect() { | ||||
|         Result result = runTest("^dog", "dogs are friendly"); | ||||
|         assertTrue(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenTextAndWrongInput_whenMatchFailsAtBeginning_thenCorrect() { | ||||
|         Result result = runTest("^dog", "are dogs are friendly?"); | ||||
|         assertFalse(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenText_whenMatchesAtEnd_thenCorrect() { | ||||
|         Result result = runTest("dog$", "Man's best friend is a dog"); | ||||
|         assertTrue(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenTextAndWrongInput_whenMatchFailsAtEnd_thenCorrect() { | ||||
|         Result result = runTest("dog$", "is a dog man's best friend?"); | ||||
|         assertFalse(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenText_whenMatchesAtWordBoundary_thenCorrect() { | ||||
|         Result result = runTest("\\bdog\\b", "a dog is friendly"); | ||||
|         assertTrue(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenText_whenMatchesAtWordBoundary_thenCorrect2() { | ||||
|         Result result = runTest("\\bdog\\b", "dog is man's best friend"); | ||||
|         assertTrue(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenWrongText_whenMatchFailsAtWordBoundary_thenCorrect() { | ||||
|         Result result = runTest("\\bdog\\b", "snoop dogg is a rapper"); | ||||
|         assertFalse(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenText_whenMatchesAtWordAndNonBoundary_thenCorrect() { | ||||
|         Result result = runTest("\\bdog\\B", "snoop dogg is a rapper"); | ||||
|         assertTrue(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenRegexWithoutCanonEq_whenMatchFailsOnEquivalentUnicode_thenCorrect() { | ||||
|         Result result = runTest("\u00E9", "\u0065\u0301"); | ||||
|         assertFalse(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenRegexWithCanonEq_whenMatchesOnEquivalentUnicode_thenCorrect() { | ||||
|         Result result = runTest("\u00E9", "\u0065\u0301", Pattern.CANON_EQ); | ||||
|         assertTrue(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenRegexWithDefaultMatcher_whenMatchFailsOnDifferentCases_thenCorrect() { | ||||
|         Result result = runTest("dog", "This is a Dog"); | ||||
|         assertFalse(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenRegexWithCaseInsensitiveMatcher_whenMatchesOnDifferentCases_thenCorrect() { | ||||
|         Result result = runTest("dog", "This is a Dog", Pattern.CASE_INSENSITIVE); | ||||
|         assertTrue(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenRegexWithEmbeddedCaseInsensitiveMatcher_whenMatchesOnDifferentCases_thenCorrect() { | ||||
|         Result result = runTest("(?i)dog", "This is a Dog"); | ||||
|         assertTrue(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenRegexWithComments_whenMatchFailsWithoutFlag_thenCorrect() { | ||||
|         Result result = runTest("dog$  #check for word dog at end of text", "This is a dog"); | ||||
|         assertFalse(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenRegexWithComments_whenMatchesWithFlag_thenCorrect() { | ||||
|         Result result = runTest("dog$  #check for word dog at end of text", "This is a dog", Pattern.COMMENTS); | ||||
|         assertTrue(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenRegexWithComments_whenMatchesWithEmbeddedFlag_thenCorrect() { | ||||
|         Result result = runTest("(?x)dog$  #check for word dog at end of text", "This is a dog"); | ||||
|         assertTrue(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenRegexWithLineTerminator_whenMatchFails_thenCorrect() { | ||||
|         Pattern pattern = Pattern.compile("(.*)"); | ||||
|         Matcher matcher = pattern.matcher("this is a text" + System.getProperty("line.separator") + " continued on another line"); | ||||
|         matcher.find(); | ||||
|         assertEquals("this is a text", matcher.group(1)); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenRegexWithLineTerminator_whenMatchesWithDotall_thenCorrect() { | ||||
|         Pattern pattern = Pattern.compile("(.*)", Pattern.DOTALL); | ||||
|         Matcher matcher = pattern.matcher("this is a text" + System.getProperty("line.separator") + " continued on another line"); | ||||
|         matcher.find(); | ||||
|         assertEquals("this is a text" + System.getProperty("line.separator") + " continued on another line", matcher.group(1)); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenRegexWithLineTerminator_whenMatchesWithEmbeddedDotall_thenCorrect() { | ||||
|         Pattern pattern = Pattern.compile("(?s)(.*)"); | ||||
|         Matcher matcher = pattern.matcher("this is a text" + System.getProperty("line.separator") + " continued on another line"); | ||||
|         matcher.find(); | ||||
|         assertEquals("this is a text" + System.getProperty("line.separator") + " continued on another line", matcher.group(1)); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenRegex_whenMatchesWithoutLiteralFlag_thenCorrect() { | ||||
|         Result result = runTest("(.*)", "text"); | ||||
|         assertTrue(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenRegex_whenMatchFailsWithLiteralFlag_thenCorrect() { | ||||
|         Result result = runTest("(.*)", "text", Pattern.LITERAL); | ||||
|         assertFalse(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenRegex_whenMatchesWithLiteralFlag_thenCorrect() { | ||||
|         Result result = runTest("(.*)", "text(.*)", Pattern.LITERAL); | ||||
|         assertTrue(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenRegex_whenMatchFailsWithoutMultilineFlag_thenCorrect() { | ||||
|         Result result = runTest("dog$", "This is a dog" + System.getProperty("line.separator") + "this is a fox"); | ||||
|         assertFalse(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenRegex_whenMatchesWithMultilineFlag_thenCorrect() { | ||||
|         Result result = runTest("dog$", "This is a dog" + System.getProperty("line.separator") + "this is a fox", Pattern.MULTILINE); | ||||
|         assertTrue(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenRegex_whenMatchesWithEmbeddedMultilineFlag_thenCorrect() { | ||||
|         Result result = runTest("(?m)dog$", "This is a dog" + System.getProperty("line.separator") + "this is a fox"); | ||||
|         assertTrue(result.isFound()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenMatch_whenGetsIndices_thenCorrect() { | ||||
|         Pattern pattern = Pattern.compile("dog"); | ||||
|         Matcher matcher = pattern.matcher("This dog is mine"); | ||||
|         matcher.find(); | ||||
|         assertEquals(5, matcher.start()); | ||||
|         assertEquals(8, matcher.end()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void whenStudyMethodsWork_thenCorrect() { | ||||
|         Pattern pattern = Pattern.compile("dog"); | ||||
|         Matcher matcher = pattern.matcher("dogs are friendly"); | ||||
|         assertTrue(matcher.lookingAt()); | ||||
|         assertFalse(matcher.matches()); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void whenMatchesStudyMethodWorks_thenCorrect() { | ||||
|         Pattern pattern = Pattern.compile("dog"); | ||||
|         Matcher matcher = pattern.matcher("dog"); | ||||
|         assertTrue(matcher.matches()); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void whenReplaceFirstWorks_thenCorrect() { | ||||
|         Pattern pattern = Pattern.compile("dog"); | ||||
|         Matcher matcher = pattern.matcher("dogs are domestic animals, dogs are friendly"); | ||||
|         String newStr = matcher.replaceFirst("cat"); | ||||
|         assertEquals("cats are domestic animals, dogs are friendly", newStr); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void whenReplaceAllWorks_thenCorrect() { | ||||
|         Pattern pattern = Pattern.compile("dog"); | ||||
|         Matcher matcher = pattern.matcher("dogs are domestic animals, dogs are friendly"); | ||||
|         String newStr = matcher.replaceAll("cat"); | ||||
|         assertEquals("cats are domestic animals, cats are friendly", newStr); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     public synchronized static Result runTest(String regex, String text) { | ||||
|         pattern = Pattern.compile(regex); | ||||
|         matcher = pattern.matcher(text); | ||||
|         Result result = new Result(); | ||||
|         while (matcher.find()) | ||||
|             result.setCount(result.getCount() + 1); | ||||
|         if (result.getCount() > 0) | ||||
|             result.setFound(true); | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
|     public synchronized static Result runTest(String regex, String text, int flags) { | ||||
|         pattern = Pattern.compile(regex, flags); | ||||
|         matcher = pattern.matcher(text); | ||||
|         Result result = new Result(); | ||||
|         while (matcher.find()) | ||||
|             result.setCount(result.getCount() + 1); | ||||
|         if (result.getCount() > 0) | ||||
|             result.setFound(true); | ||||
|         return result; | ||||
|     } | ||||
| } | ||||
| @ -22,11 +22,10 @@ public class ComplexClassTest { | ||||
|         strArrayListD.add("pqr"); | ||||
|         ComplexClass dObject = new ComplexClass(strArrayListD, new HashSet<Integer>(45, 67)); | ||||
| 
 | ||||
|         // equals() | ||||
|         Assert.assertTrue(aObject.equals(bObject) && bObject.equals(aObject)); | ||||
|         // hashCode() | ||||
| 
 | ||||
|         Assert.assertTrue(aObject.hashCode() == bObject.hashCode()); | ||||
|         // non-equal objects are not equals() and have different hashCode() | ||||
| 
 | ||||
|         Assert.assertFalse(aObject.equals(dObject)); | ||||
|         Assert.assertFalse(aObject.hashCode() == dObject.hashCode()); | ||||
|     } | ||||
| @ -12,11 +12,10 @@ public class PrimitiveClassTest { | ||||
|         PrimitiveClass bObject = new PrimitiveClass(false, 2); | ||||
|         PrimitiveClass dObject = new PrimitiveClass(true, 2); | ||||
| 
 | ||||
|         // equals() | ||||
|         Assert.assertTrue(aObject.equals(bObject) && bObject.equals(aObject)); | ||||
|         // hashCode() | ||||
| 
 | ||||
|         Assert.assertTrue(aObject.hashCode() == bObject.hashCode()); | ||||
|         // non-equal objects are not equals() and have different hashCode() | ||||
| 
 | ||||
|         Assert.assertFalse(aObject.equals(dObject)); | ||||
|         Assert.assertFalse(aObject.hashCode() == dObject.hashCode()); | ||||
|     } | ||||
| @ -15,11 +15,10 @@ public class SquareClassTest { | ||||
| 
 | ||||
|         Square dObject = new Square(20, Color.BLUE); | ||||
| 
 | ||||
|         // equals() | ||||
|         Assert.assertTrue(aObject.equals(bObject) && bObject.equals(aObject)); | ||||
|         // hashCode() | ||||
| 
 | ||||
|         Assert.assertTrue(aObject.hashCode() == bObject.hashCode()); | ||||
|         // non-equal objects are not equals() and have different hashCode() | ||||
| 
 | ||||
|         Assert.assertFalse(aObject.equals(dObject)); | ||||
|         Assert.assertFalse(aObject.hashCode() == dObject.hashCode()); | ||||
|     } | ||||
| @ -0,0 +1,90 @@ | ||||
| package org.baeldung.java.md5; | ||||
| 
 | ||||
| import static org.junit.Assert.*; | ||||
| 
 | ||||
| import java.nio.file.Files; | ||||
| import java.nio.file.Path; | ||||
| import java.nio.file.Paths; | ||||
| import java.security.MessageDigest; | ||||
| import java.security.NoSuchAlgorithmException; | ||||
| 
 | ||||
| import javax.xml.bind.DatatypeConverter; | ||||
| 
 | ||||
| import org.apache.commons.codec.digest.DigestUtils; | ||||
| import org.junit.Before; | ||||
| import org.junit.Test; | ||||
| 
 | ||||
| import com.google.common.hash.HashCode; | ||||
| import com.google.common.hash.Hashing; | ||||
| 
 | ||||
| import java.io.File; | ||||
| import java.io.IOException; | ||||
| import java.nio.*; | ||||
| import static org.assertj.core.api.Assertions.assertThat; | ||||
| 
 | ||||
| 
 | ||||
| public class JavaMD5Test { | ||||
| 
 | ||||
|      | ||||
|     String filename = "src/test/resources/test_md5.txt"; | ||||
|     String checksum = "5EB63BBBE01EEED093CB22BB8F5ACDC3"; | ||||
|      | ||||
|     String hash = "35454B055CC325EA1AF2126E27707052"; | ||||
|     String password = "ILoveJava"; | ||||
|      | ||||
|      | ||||
|      | ||||
|     @Test | ||||
|     public void givenPassword_whenHashing_thenVerifying() throws NoSuchAlgorithmException { | ||||
|         String hash = "35454B055CC325EA1AF2126E27707052"; | ||||
|         String password = "ILoveJava"; | ||||
|          | ||||
|         MessageDigest md = MessageDigest.getInstance("MD5"); | ||||
|         md.update(password.getBytes()); | ||||
|         byte[] digest = md.digest(); | ||||
|         String myHash = DatatypeConverter.printHexBinary(digest).toUpperCase(); | ||||
|          | ||||
|         assertThat(myHash.equals(hash)).isTrue(); | ||||
|     } | ||||
|      | ||||
|     @Test | ||||
|     public void givenFile_generatingChecksum_thenVerifying() throws NoSuchAlgorithmException, IOException { | ||||
|         String filename = "src/test/resources/test_md5.txt"; | ||||
|         String checksum = "5EB63BBBE01EEED093CB22BB8F5ACDC3"; | ||||
|          | ||||
|         MessageDigest md = MessageDigest.getInstance("MD5"); | ||||
|         md.update(Files.readAllBytes(Paths.get(filename))); | ||||
|         byte[] digest = md.digest(); | ||||
|         String myChecksum = DatatypeConverter | ||||
|             .printHexBinary(digest).toUpperCase(); | ||||
|          | ||||
|         assertThat(myChecksum.equals(checksum)).isTrue(); | ||||
|     } | ||||
|      | ||||
|     @Test | ||||
|     public void givenPassword_whenHashingUsingCommons_thenVerifying()  { | ||||
|         String hash = "35454B055CC325EA1AF2126E27707052"; | ||||
|         String password = "ILoveJava"; | ||||
| 
 | ||||
|         String md5Hex = DigestUtils | ||||
|             .md5Hex(password).toUpperCase(); | ||||
|          | ||||
|         assertThat(md5Hex.equals(hash)).isTrue(); | ||||
|     } | ||||
|      | ||||
|      | ||||
|     @Test | ||||
|     public void givenFile_whenChecksumUsingGuava_thenVerifying() throws IOException { | ||||
|         String filename = "src/test/resources/test_md5.txt"; | ||||
|         String checksum = "5EB63BBBE01EEED093CB22BB8F5ACDC3"; | ||||
|          | ||||
|         HashCode hash = com.google.common.io.Files | ||||
|             .hash(new File(filename), Hashing.md5()); | ||||
|         String myChecksum = hash.toString() | ||||
|             .toUpperCase(); | ||||
|          | ||||
|         assertThat(myChecksum.equals(checksum)).isTrue(); | ||||
|     } | ||||
|      | ||||
| 
 | ||||
| } | ||||
| @ -1,63 +0,0 @@ | ||||
| package org.baeldung.equalshashcode.entities; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashSet; | ||||
| 
 | ||||
| public class ComplexClass { | ||||
| 
 | ||||
|     private ArrayList<?> genericArrayList; | ||||
|     private HashSet<Integer> integerHashSet; | ||||
| 
 | ||||
|     public ComplexClass(ArrayList<?> genericArrayList, HashSet<Integer> integerHashSet) { | ||||
|         super(); | ||||
|         this.genericArrayList = genericArrayList; | ||||
|         this.integerHashSet = integerHashSet; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public int hashCode() { | ||||
|         final int prime = 31; | ||||
|         int result = 1; | ||||
|         result = prime * result + ((genericArrayList == null) ? 0 : genericArrayList.hashCode()); | ||||
|         result = prime * result + ((integerHashSet == null) ? 0 : integerHashSet.hashCode()); | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public boolean equals(Object obj) { | ||||
|         if (this == obj) | ||||
|             return true; | ||||
|         if (obj == null) | ||||
|             return false; | ||||
|         if (!(obj instanceof ComplexClass)) | ||||
|             return false; | ||||
|         ComplexClass other = (ComplexClass) obj; | ||||
|         if (genericArrayList == null) { | ||||
|             if (other.genericArrayList != null) | ||||
|                 return false; | ||||
|         } else if (!genericArrayList.equals(other.genericArrayList)) | ||||
|             return false; | ||||
|         if (integerHashSet == null) { | ||||
|             if (other.integerHashSet != null) | ||||
|                 return false; | ||||
|         } else if (!integerHashSet.equals(other.integerHashSet)) | ||||
|             return false; | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     protected ArrayList<?> getGenericArrayList() { | ||||
|         return genericArrayList; | ||||
|     } | ||||
| 
 | ||||
|     protected void setGenericArrayList(ArrayList<?> genericArrayList) { | ||||
|         this.genericArrayList = genericArrayList; | ||||
|     } | ||||
| 
 | ||||
|     protected HashSet<Integer> getIntegerHashSet() { | ||||
|         return integerHashSet; | ||||
|     } | ||||
| 
 | ||||
|     protected void setIntegerHashSet(HashSet<Integer> integerHashSet) { | ||||
|         this.integerHashSet = integerHashSet; | ||||
|     } | ||||
| } | ||||
										
											Binary file not shown.
										
									
								
							| Before Width: | Height: | Size: 9.3 KiB | 
| @ -1,35 +0,0 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||||
|          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||
|          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||
|     <modelVersion>4.0.0</modelVersion> | ||||
| 
 | ||||
|     <groupId>com.baeldung.enterprise.patterns</groupId> | ||||
|     <artifactId>enterprise-patterns-parent</artifactId> | ||||
|     <packaging>pom</packaging> | ||||
|     <modules> | ||||
|         <module>front-controller-pattern</module> | ||||
|     </modules> | ||||
| 
 | ||||
|     <parent> | ||||
|         <groupId>com.baeldung</groupId> | ||||
|         <artifactId>parent-modules</artifactId> | ||||
|         <version>1.0.0-SNAPSHOT</version> | ||||
|     </parent> | ||||
| 
 | ||||
|     <build> | ||||
|         <pluginManagement> | ||||
|             <plugins> | ||||
|                 <plugin> | ||||
|                     <groupId>org.apache.maven.plugins</groupId> | ||||
|                     <artifactId>maven-compiler-plugin</artifactId> | ||||
|                     <version>3.5.1</version> | ||||
|                     <configuration> | ||||
|                         <source>1.8</source> | ||||
|                         <target>1.8</target> | ||||
|                     </configuration> | ||||
|                 </plugin> | ||||
|             </plugins> | ||||
|         </pluginManagement> | ||||
|     </build> | ||||
| </project> | ||||
| @ -4,15 +4,10 @@ | ||||
|          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||
|     <modelVersion>4.0.0</modelVersion> | ||||
| 
 | ||||
|     <artifactId>front-controller-pattern</artifactId> | ||||
|     <groupId>com.baeldung.enterprise.patterns</groupId> | ||||
|     <artifactId>patterns</artifactId> | ||||
|     <packaging>war</packaging> | ||||
| 
 | ||||
|     <parent> | ||||
|         <artifactId>enterprise-patterns-parent</artifactId> | ||||
|         <groupId>com.baeldung.enterprise.patterns</groupId> | ||||
|         <version>1.0.0-SNAPSHOT</version> | ||||
|     </parent> | ||||
| 
 | ||||
|     <dependencies> | ||||
|         <dependency> | ||||
|             <groupId>javax.servlet</groupId> | ||||
| @ -22,11 +17,22 @@ | ||||
|         </dependency> | ||||
|     </dependencies> | ||||
| 
 | ||||
|     <parent> | ||||
|         <groupId>com.baeldung</groupId> | ||||
|         <artifactId>parent-modules</artifactId> | ||||
|         <version>1.0.0-SNAPSHOT</version> | ||||
|     </parent> | ||||
| 
 | ||||
|     <build> | ||||
|         <plugins> | ||||
|             <plugin> | ||||
|                 <groupId>org.apache.maven.plugins</groupId> | ||||
|                 <artifactId>maven-compiler-plugin</artifactId> | ||||
|                 <version>3.5.1</version> | ||||
|                 <configuration> | ||||
|                     <source>1.8</source> | ||||
|                     <target>1.8</target> | ||||
|                 </configuration> | ||||
|             </plugin> | ||||
|             <plugin> | ||||
|                 <groupId>org.eclipse.jetty</groupId> | ||||
| @ -22,24 +22,17 @@ public class FrontControllerServlet extends HttpServlet { | ||||
| 
 | ||||
|     private FrontCommand getCommand(HttpServletRequest request) { | ||||
|         try { | ||||
|             return (FrontCommand) getCommandClass(request) | ||||
|               .asSubclass(FrontCommand.class) | ||||
|               .newInstance(); | ||||
|         } catch (Exception e) { | ||||
|             throw new RuntimeException("Failed to get command!", e); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private Class getCommandClass(HttpServletRequest request) { | ||||
|         try { | ||||
|             return Class.forName( | ||||
|             Class type = Class.forName( | ||||
|               String.format( | ||||
|                 "com.baeldung.enterprise.patterns.front.controller.commands.%sCommand", | ||||
|                 request.getParameter("command") | ||||
|               ) | ||||
|             ); | ||||
|         } catch (ClassNotFoundException e) { | ||||
|             return UnknownCommand.class; | ||||
|             return (FrontCommand) type | ||||
|               .asSubclass(FrontCommand.class) | ||||
|               .newInstance(); | ||||
|         } catch (Exception e) { | ||||
|             return new UnknownCommand(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								patterns/src/main/resources/front controller.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								patterns/src/main/resources/front controller.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 5.2 KiB | 
| @ -1,5 +1,5 @@ | ||||
| @startuml | ||||
| 
 | ||||
| scale 1.5 | ||||
| class Handler { | ||||
| doGet | ||||
| doPost | ||||
							
								
								
									
										5
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								pom.xml
									
									
									
									
									
								
							| @ -30,7 +30,7 @@ | ||||
|         <module>dependency-injection</module> | ||||
|         <module>deltaspike</module> | ||||
| 
 | ||||
|         <module>enterprise-patterns</module> | ||||
|         <module>patterns</module> | ||||
|         <module>feign-client</module> | ||||
|         <!-- <module>gatling</module> --> <!-- not meant to run as part of the standard build --> | ||||
| 
 | ||||
| @ -91,12 +91,12 @@ | ||||
|         <module>spring-hibernate3</module> | ||||
|         <module>spring-hibernate4</module> | ||||
|         <module>spring-jpa</module> | ||||
|         <module>spring-jpa-jndi</module> | ||||
|         <module>spring-katharsis</module> | ||||
|         <module>spring-mockito</module> | ||||
|         <module>spring-mvc-java</module> | ||||
|         <module>spring-mvc-no-xml</module> | ||||
|         <module>spring-mvc-xml</module> | ||||
| 	<module>spring-mvc-tiles</module> | ||||
|         <module>spring-openid</module> | ||||
|         <module>spring-protobuf</module> | ||||
|         <module>spring-quartz</module> | ||||
| @ -133,6 +133,7 @@ | ||||
|         <module>wicket</module> | ||||
|         <module>xstream</module> | ||||
|         <module>java-cassandra</module> | ||||
|         <module>annotations</module> | ||||
|     </modules> | ||||
| 
 | ||||
| </project> | ||||
|  | ||||
| @ -1,8 +1,18 @@ | ||||
| ## The Module Holds Sources for the Following Articles | ||||
| 
 | ||||
| - [Quick Intro to Spring Cloud Configuration](http://www.baeldung.com/spring-cloud-configuration) | ||||
| - [Dockerizing a Spring Boot Application](http://www.baeldung.com/dockerizing-spring-boot-application) | ||||
| 
 | ||||
|    Spring Cloud Config is Spring’s client/server approach for storing and serving distributed configurations across multiple applications and environments. | ||||
| 
 | ||||
|    In this write-up, we’ll focus on an example of how to setup a Git-backed config server, use it in a simple REST application server and setup a secure environment including encrypted property values. | ||||
| 
 | ||||
| - [Introduction to Spring Cloud Netflix – Eureka](http://www.baeldung.com/spring-cloud-netflix-eureka) | ||||
| 
 | ||||
|   In this article, we’ll introduce client-side service discovery via “Spring Cloud Netflix Eureka“. | ||||
| 
 | ||||
|   Client-side service discovery allows services to find and communicate with each other without hardcoding hostname and port. The only ‘fixed point’ in such an architecture consists of a service registry with which each service has to register. | ||||
| 
 | ||||
| - [Intro to Spring Cloud Netflix - Hystrix](http://www.baeldung.com/spring-cloud-netflix-hystrix) | ||||
| - [Dockerizing a Spring Boot Application](http://www.baeldung.com/dockerizing-spring-boot-application) | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -10,7 +10,7 @@ | ||||
|         <module>spring-cloud-config</module> | ||||
|         <module>spring-cloud-eureka</module> | ||||
|         <module>spring-cloud-hystrix</module> | ||||
|         <module>spring-cloud-integration</module> | ||||
|         <module>spring-cloud-bootstrap</module> | ||||
|     </modules> | ||||
|     <packaging>pom</packaging> | ||||
| 
 | ||||
|  | ||||
| @ -6,7 +6,7 @@ | ||||
| 
 | ||||
|     <parent> | ||||
|         <groupId>com.baeldung.spring.cloud</groupId> | ||||
|         <artifactId>spring-cloud-integration</artifactId> | ||||
|         <artifactId>spring-cloud</artifactId> | ||||
|         <version>1.0.0-SNAPSHOT</version> | ||||
|     </parent> | ||||
| 
 | ||||
| @ -17,9 +17,9 @@ | ||||
|         <module>resource</module> | ||||
|     </modules> | ||||
| 
 | ||||
|     <artifactId>part-1</artifactId> | ||||
| 
 | ||||
|     <artifactId>spring-cloud-integration</artifactId> | ||||
|     <version>1.0.0-SNAPSHOT</version> | ||||
|     <packaging>pom</packaging> | ||||
| 
 | ||||
|      | ||||
| </project> | ||||
| @ -1,7 +1,7 @@ | ||||
| ## Spring Data Neo4j | ||||
| 
 | ||||
| ### Relevant Articles: | ||||
| - [Introduction to Spring Data Neo4j](http://www.baeldung.com/spring-data-neo4j-tutorial) | ||||
| - [Introduction to Spring Data Neo4j](http://www.baeldung.com/spring-data-neo4j-intro) | ||||
| 
 | ||||
| ### Build the Project with Tests Running | ||||
| ``` | ||||
|  | ||||
							
								
								
									
										13
									
								
								spring-jpa-jndi/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										13
									
								
								spring-jpa-jndi/.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -1,13 +0,0 @@ | ||||
| *.class | ||||
| 
 | ||||
| #folders# | ||||
| /target | ||||
| /neoDb* | ||||
| /data | ||||
| /src/main/webapp/WEB-INF/classes | ||||
| */META-INF/* | ||||
| 
 | ||||
| # Packaged files # | ||||
| *.jar | ||||
| *.war | ||||
| *.ear | ||||
| @ -1,7 +0,0 @@ | ||||
| ========= | ||||
| 
 | ||||
| ## Spring JPA using JNDI Project | ||||
| 
 | ||||
| 
 | ||||
| ### Relevant Articles:  | ||||
| - [Spring Persistence (Hibernate and JPA) with a JNDI datasource](http://www.baeldung.com/spring-jpa-fndi) | ||||
| @ -1,145 +0,0 @@ | ||||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||
|     <modelVersion>4.0.0</modelVersion> | ||||
| 
 | ||||
|     <groupId>com.baeldung</groupId> | ||||
|     <artifactId>spring-jpa-jndi</artifactId> | ||||
|     <version>0.1-SNAPSHOT</version> | ||||
|     <packaging>war</packaging> | ||||
| 
 | ||||
|     <name>spring-jpa-jndi</name> | ||||
| 
 | ||||
|     <dependencies> | ||||
| 
 | ||||
|         <!-- Spring --> | ||||
| 
 | ||||
|         <dependency> | ||||
|             <groupId>org.springframework</groupId> | ||||
|             <artifactId>spring-orm</artifactId> | ||||
|             <version>${org.springframework.version}</version> | ||||
|         </dependency> | ||||
|         <dependency> | ||||
|             <groupId>org.springframework</groupId> | ||||
|             <artifactId>spring-context</artifactId> | ||||
|             <version>${org.springframework.version}</version> | ||||
|         </dependency> | ||||
|         <dependency> | ||||
| 		    <groupId>org.springframework</groupId> | ||||
| 		    <artifactId>spring-webmvc</artifactId> | ||||
| 		    <version>${org.springframework.version}</version> | ||||
| 		</dependency> | ||||
| 		 | ||||
| 		<!-- web --> | ||||
| 		<dependency> | ||||
| 			<groupId>javax.servlet</groupId> | ||||
| 			<artifactId>jstl</artifactId> | ||||
| 			<version>${javax.servlet.jstl.version}</version> | ||||
| 		</dependency> | ||||
| 		<dependency> | ||||
| 			<groupId>javax.servlet</groupId> | ||||
| 			<artifactId>servlet-api</artifactId> | ||||
| 			<version>${javax.servlet.servlet-api.version}</version> | ||||
| 		</dependency> | ||||
| 
 | ||||
|         <!-- persistence --> | ||||
| 
 | ||||
|         <dependency> | ||||
|             <groupId>org.hibernate</groupId> | ||||
|             <artifactId>hibernate-entitymanager</artifactId> | ||||
|             <version>${hibernate.version}</version> | ||||
|         </dependency> | ||||
|         <dependency> | ||||
|             <groupId>xml-apis</groupId> | ||||
|             <artifactId>xml-apis</artifactId> | ||||
|             <version>1.4.01</version> | ||||
|         </dependency> | ||||
|         <dependency> | ||||
|             <groupId>org.javassist</groupId> | ||||
|             <artifactId>javassist</artifactId> | ||||
|             <version>${javassist.version}</version> | ||||
|         </dependency> | ||||
|         <dependency> | ||||
|             <groupId>org.springframework.data</groupId> | ||||
|             <artifactId>spring-data-jpa</artifactId> | ||||
|             <version>${spring-data-jpa.version}</version> | ||||
|         </dependency> | ||||
| 
 | ||||
|         <!-- validation --> | ||||
| 
 | ||||
|         <dependency> | ||||
|             <groupId>org.hibernate</groupId> | ||||
|             <artifactId>hibernate-validator</artifactId> | ||||
|             <version>${hibernate-validator.version}</version> | ||||
|         </dependency> | ||||
|         <dependency> | ||||
|             <groupId>javax.el</groupId> | ||||
|             <artifactId>javax.el-api</artifactId> | ||||
|             <version>2.2.5</version> | ||||
|         </dependency> | ||||
| 
 | ||||
|     </dependencies> | ||||
| 
 | ||||
|     <build> | ||||
|         <finalName>spring-jpa-jndi</finalName> | ||||
|         <resources> | ||||
|             <resource> | ||||
|                 <directory>src/main/resources</directory> | ||||
|                 <filtering>true</filtering> | ||||
|             </resource> | ||||
|         </resources> | ||||
| 
 | ||||
|         <plugins> | ||||
| 
 | ||||
|             <plugin> | ||||
|                 <groupId>org.apache.maven.plugins</groupId> | ||||
|                 <artifactId>maven-compiler-plugin</artifactId> | ||||
|                 <version>${maven-compiler-plugin.version}</version> | ||||
|                 <configuration> | ||||
|                     <source>1.8</source> | ||||
|                     <target>1.8</target> | ||||
|                 </configuration> | ||||
|             </plugin> | ||||
|              | ||||
|             <plugin> | ||||
|                 <groupId>org.apache.maven.plugins</groupId> | ||||
|                 <artifactId>maven-war-plugin</artifactId> | ||||
|                 <version>${maven-war-plugin.version}</version> | ||||
|                 <configuration> | ||||
|                     <warSourceDirectory>src/main/webapp</warSourceDirectory> | ||||
|                     <failOnMissingWebXml>false</failOnMissingWebXml> | ||||
|                 </configuration> | ||||
|             </plugin> | ||||
| 
 | ||||
|         </plugins> | ||||
| 
 | ||||
|     </build> | ||||
| 
 | ||||
|     <properties> | ||||
|         <!-- Spring --> | ||||
|         <org.springframework.version>4.3.2.RELEASE</org.springframework.version> | ||||
|         <javassist.version>3.20.0-GA</javassist.version> | ||||
|          | ||||
|         <!-- web --> | ||||
|         <javax.servlet.jstl.version>1.2</javax.servlet.jstl.version> | ||||
|         <javax.servlet.servlet-api.version>2.5</javax.servlet.servlet-api.version> | ||||
| 
 | ||||
|         <!-- persistence --> | ||||
|         <hibernate.version>4.3.11.Final</hibernate.version> | ||||
|         <spring-data-jpa.version>1.8.2.RELEASE</spring-data-jpa.version> | ||||
|         <h2.version>1.4.192</h2.version> | ||||
| 
 | ||||
|         <!-- logging --> | ||||
|         <org.slf4j.version>1.7.13</org.slf4j.version> | ||||
|         <logback.version>1.1.3</logback.version> | ||||
| 
 | ||||
|         <!-- various --> | ||||
|         <hibernate-validator.version>5.2.2.Final</hibernate-validator.version> | ||||
| 
 | ||||
|         <!-- maven plugins --> | ||||
|         <maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version> | ||||
|         <maven-resources-plugin.version>2.7</maven-resources-plugin.version> | ||||
|         <maven-war-plugin.version>2.4</maven-war-plugin.version> | ||||
|         <!-- <maven-war-plugin.version>2.6</maven-war-plugin.version> --> | ||||
| 
 | ||||
|     </properties> | ||||
| 
 | ||||
| </project> | ||||
| @ -1,22 +0,0 @@ | ||||
| package org.baeldung.persistence.dao; | ||||
| 
 | ||||
| import java.util.List; | ||||
| 
 | ||||
| import javax.persistence.EntityManager; | ||||
| import javax.persistence.PersistenceContext; | ||||
| 
 | ||||
| import org.baeldung.persistence.model.Foo; | ||||
| import org.springframework.stereotype.Repository; | ||||
| 
 | ||||
| @Repository | ||||
| public class FooDao { | ||||
| 
 | ||||
|     @PersistenceContext | ||||
|     private EntityManager entityManager; | ||||
| 
 | ||||
|     @SuppressWarnings("unchecked") | ||||
|     public List<Foo> findAll() { | ||||
|         return entityManager.createQuery("from " + Foo.class.getName()).getResultList(); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @ -1,34 +0,0 @@ | ||||
| package org.baeldung.persistence.model; | ||||
| 
 | ||||
| import javax.persistence.Column; | ||||
| import javax.persistence.Entity; | ||||
| import javax.persistence.GeneratedValue; | ||||
| import javax.persistence.GenerationType; | ||||
| import javax.persistence.Id; | ||||
| 
 | ||||
| @Entity | ||||
| public class Foo { | ||||
| 
 | ||||
|     @Id | ||||
|     @GeneratedValue(strategy = GenerationType.AUTO) | ||||
|     @Column(name = "ID") | ||||
|     private long id; | ||||
|     @Column(name = "NAME") | ||||
|     private String name; | ||||
| 
 | ||||
|     public long getId() { | ||||
|         return id; | ||||
|     } | ||||
| 
 | ||||
|     public void setId(final int id) { | ||||
|         this.id = id; | ||||
|     } | ||||
| 
 | ||||
|     public String getName() { | ||||
|         return name; | ||||
|     } | ||||
| 
 | ||||
|     public void setName(final String name) { | ||||
|         this.name = name; | ||||
|     } | ||||
| } | ||||
| @ -1,22 +0,0 @@ | ||||
| package org.baeldung.persistence.service; | ||||
| 
 | ||||
| import java.util.List; | ||||
| 
 | ||||
| import org.baeldung.persistence.dao.FooDao; | ||||
| import org.baeldung.persistence.model.Foo; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | ||||
| import org.springframework.transaction.annotation.Transactional; | ||||
| 
 | ||||
| @Service | ||||
| @Transactional | ||||
| public class FooService { | ||||
| 
 | ||||
|     @Autowired | ||||
|     private FooDao dao; | ||||
| 
 | ||||
|     public List<Foo> findAll() { | ||||
|         return dao.findAll(); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @ -1,20 +0,0 @@ | ||||
| <configuration> | ||||
| 
 | ||||
| 	<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||||
| 		<encoder> | ||||
| 			<pattern>web - %date [%thread] %-5level %logger{36} - %message%n | ||||
| 			</pattern> | ||||
| 		</encoder> | ||||
| 	</appender> | ||||
| 
 | ||||
| 	<logger name="org.springframework" level="WARN" /> | ||||
| 	<logger name="org.springframework.transaction" level="WARN" /> | ||||
| 
 | ||||
| 	<!-- in order to debug some marshalling issues, this needs to be TRACE --> | ||||
| 	<logger name="org.springframework.web.servlet.mvc" level="WARN" /> | ||||
| 
 | ||||
| 	<root level="INFO"> | ||||
| 		<appender-ref ref="STDOUT" /> | ||||
| 	</root> | ||||
| 
 | ||||
| </configuration> | ||||
| @ -4,6 +4,7 @@ | ||||
|     <groupId>com.baeldung</groupId> | ||||
|     <artifactId>spring-jpa</artifactId> | ||||
|     <version>0.1-SNAPSHOT</version> | ||||
|     <packaging>war</packaging> | ||||
| 
 | ||||
|     <name>spring-jpa</name> | ||||
| 
 | ||||
| @ -21,6 +22,11 @@ | ||||
|             <artifactId>spring-context</artifactId> | ||||
|             <version>${org.springframework.version}</version> | ||||
|         </dependency> | ||||
|         <dependency> | ||||
| 		    <groupId>org.springframework</groupId> | ||||
| 		    <artifactId>spring-webmvc</artifactId> | ||||
| 		    <version>${org.springframework.version}</version> | ||||
| 		</dependency> | ||||
| 
 | ||||
|         <!-- persistence --> | ||||
| 
 | ||||
| @ -73,6 +79,18 @@ | ||||
|             <artifactId>javax.el-api</artifactId> | ||||
|             <version>2.2.5</version> | ||||
|         </dependency> | ||||
|          | ||||
|         <!-- web --> | ||||
| 		<dependency> | ||||
| 			<groupId>javax.servlet</groupId> | ||||
| 			<artifactId>jstl</artifactId> | ||||
| 			<version>${javax.servlet.jstl.version}</version> | ||||
| 		</dependency> | ||||
| 		<dependency> | ||||
| 			<groupId>javax.servlet</groupId> | ||||
| 			<artifactId>servlet-api</artifactId> | ||||
| 			<version>${javax.servlet.servlet-api.version}</version> | ||||
| 		</dependency> | ||||
| 
 | ||||
|         <!-- utils --> | ||||
| 
 | ||||
| @ -147,6 +165,16 @@ | ||||
|                     <target>1.8</target> | ||||
|                 </configuration> | ||||
|             </plugin> | ||||
|              | ||||
|             <plugin> | ||||
|                 <groupId>org.apache.maven.plugins</groupId> | ||||
|                 <artifactId>maven-war-plugin</artifactId> | ||||
|                 <version>${maven-war-plugin.version}</version> | ||||
|                 <configuration> | ||||
|                     <warSourceDirectory>src/main/webapp</warSourceDirectory> | ||||
|                     <failOnMissingWebXml>false</failOnMissingWebXml> | ||||
|                 </configuration> | ||||
|             </plugin> | ||||
| 
 | ||||
|             <plugin> | ||||
|                 <groupId>org.apache.maven.plugins</groupId> | ||||
| @ -197,6 +225,10 @@ | ||||
|         <mysql-connector-java.version>5.1.38</mysql-connector-java.version> | ||||
|         <spring-data-jpa.version>1.10.2.RELEASE</spring-data-jpa.version> | ||||
|         <h2.version>1.4.192</h2.version> | ||||
|          | ||||
|         <!-- web --> | ||||
|         <javax.servlet.jstl.version>1.2</javax.servlet.jstl.version> | ||||
|         <javax.servlet.servlet-api.version>2.5</javax.servlet.servlet-api.version> | ||||
| 
 | ||||
|         <!-- logging --> | ||||
|         <org.slf4j.version>1.7.13</org.slf4j.version> | ||||
| @ -224,6 +256,7 @@ | ||||
|         <maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version> | ||||
|         <maven-resources-plugin.version>2.7</maven-resources-plugin.version> | ||||
|         <cargo-maven2-plugin.version>1.4.18</cargo-maven2-plugin.version> | ||||
|         <maven-war-plugin.version>2.4</maven-war-plugin.version> | ||||
|         <!-- <maven-war-plugin.version>2.6</maven-war-plugin.version> --> | ||||
| 
 | ||||
|     </properties> | ||||
|  | ||||
| @ -36,7 +36,7 @@ public class PersistenceJNDIConfig { | ||||
|     } | ||||
| 
 | ||||
|     @Bean | ||||
|     public LocalContainerEntityManagerFactoryBean entityManagerFactory() { | ||||
|     public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws NamingException { | ||||
|         final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); | ||||
|         em.setDataSource(dataSource()); | ||||
|         em.setPackagesToScan(new String[] { "org.baeldung.persistence.model" }); | ||||
| @ -46,12 +46,8 @@ public class PersistenceJNDIConfig { | ||||
|     } | ||||
| 
 | ||||
|     @Bean | ||||
|     public DataSource dataSource() { | ||||
|         try { | ||||
|             return (DataSource) new JndiTemplate().lookup(env.getProperty("jdbc.url")); | ||||
|         } catch (NamingException e) { | ||||
|             throw new IllegalArgumentException("Error looking up JNDI datasource", e); | ||||
|         } | ||||
|     public DataSource dataSource() throws NamingException { | ||||
|         return (DataSource) new JndiTemplate().lookup(env.getProperty("jdbc.url")); | ||||
|     } | ||||
| 
 | ||||
|     @Bean | ||||
							
								
								
									
										85
									
								
								spring-mvc-tiles/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										85
									
								
								spring-mvc-tiles/pom.xml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,85 @@ | ||||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||
| 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||
| 	<modelVersion>4.0.0</modelVersion> | ||||
| 	<groupId>com.baeldung</groupId> | ||||
| 	<artifactId>spring-mvc-tiles</artifactId> | ||||
| 	<version>0.0.1-SNAPSHOT</version> | ||||
| 	<packaging>war</packaging> | ||||
| 	<name>spring-mvc-tiles</name> | ||||
| 	<description>Integrating Spring MVC with Apache Tiles</description> | ||||
| 
 | ||||
| 	<properties> | ||||
| 		<springframework.version>4.3.2.RELEASE</springframework.version> | ||||
| 		<apachetiles.version>3.0.5</apachetiles.version> | ||||
| 	</properties> | ||||
| 
 | ||||
| 	<dependencies> | ||||
| 		<!-- Spring --> | ||||
| 		<dependency> | ||||
| 			<groupId>org.springframework</groupId> | ||||
| 			<artifactId>spring-core</artifactId> | ||||
| 			<version>${springframework.version}</version> | ||||
| 		</dependency> | ||||
| 		<dependency> | ||||
| 			<groupId>org.springframework</groupId> | ||||
| 			<artifactId>spring-web</artifactId> | ||||
| 			<version>${springframework.version}</version> | ||||
| 		</dependency> | ||||
| 		<dependency> | ||||
| 			<groupId>org.springframework</groupId> | ||||
| 			<artifactId>spring-webmvc</artifactId> | ||||
| 			<version>${springframework.version}</version> | ||||
| 		</dependency> | ||||
| 		<!-- Apache Tiles --> | ||||
| 		<dependency> | ||||
| 			<groupId>org.apache.tiles</groupId> | ||||
| 			<artifactId>tiles-jsp</artifactId> | ||||
| 			<version>${apachetiles.version}</version> | ||||
| 		</dependency> | ||||
| 
 | ||||
| 		<!-- Servlet+JSP+JSTL --> | ||||
| 		<dependency> | ||||
| 			<groupId>javax.servlet</groupId> | ||||
| 			<artifactId>javax.servlet-api</artifactId> | ||||
| 			<version>3.1.0</version> | ||||
| 		</dependency> | ||||
| 		<dependency> | ||||
| 			<groupId>javax.servlet.jsp</groupId> | ||||
| 			<artifactId>javax.servlet.jsp-api</artifactId> | ||||
| 			<version>2.3.1</version> | ||||
| 		</dependency> | ||||
| 		<dependency> | ||||
| 			<groupId>javax.servlet</groupId> | ||||
| 			<artifactId>jstl</artifactId> | ||||
| 			<version>1.2</version> | ||||
| 		</dependency> | ||||
| 
 | ||||
| 	</dependencies> | ||||
| 
 | ||||
| 	<build> | ||||
| 		<pluginManagement> | ||||
| 			<plugins> | ||||
| 				<plugin> | ||||
| 					<groupId>org.apache.maven.plugins</groupId> | ||||
| 					<artifactId>maven-compiler-plugin</artifactId> | ||||
| 					<version>3.2</version> | ||||
| 					<configuration> | ||||
| 						<source>1.7</source> | ||||
| 						<target>1.7</target> | ||||
| 					</configuration> | ||||
| 				</plugin> | ||||
| 				<plugin> | ||||
| 					<groupId>org.apache.maven.plugins</groupId> | ||||
| 					<artifactId>maven-war-plugin</artifactId> | ||||
| 					<version>2.4</version> | ||||
| 					<configuration> | ||||
| 						<warSourceDirectory>src/main/webapp</warSourceDirectory> | ||||
| 						<warName>spring-mvc-tiles</warName> | ||||
| 						<failOnMissingWebXml>false</failOnMissingWebXml> | ||||
| 					</configuration> | ||||
| 				</plugin> | ||||
| 			</plugins> | ||||
| 		</pluginManagement> | ||||
| 		<finalName>spring-mvc-tiles</finalName> | ||||
| 	</build> | ||||
| </project> | ||||
| @ -0,0 +1,47 @@ | ||||
| package com.baeldung.tiles.springmvc; | ||||
| 
 | ||||
| import org.springframework.context.annotation.Bean; | ||||
| import org.springframework.context.annotation.ComponentScan; | ||||
| import org.springframework.context.annotation.Configuration; | ||||
| import org.springframework.web.servlet.config.annotation.EnableWebMvc; | ||||
| import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | ||||
| import org.springframework.web.servlet.config.annotation.ViewResolverRegistry; | ||||
| import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | ||||
| import org.springframework.web.servlet.view.tiles3.TilesConfigurer; | ||||
| import org.springframework.web.servlet.view.tiles3.TilesViewResolver; | ||||
| 
 | ||||
| @Configuration | ||||
| @EnableWebMvc | ||||
| @ComponentScan(basePackages = "com.baeldung.tiles.springmvc") | ||||
| public class ApplicationConfiguration extends WebMvcConfigurerAdapter { | ||||
| 
 | ||||
|     /** | ||||
|      * Configure TilesConfigurer. | ||||
|      */ | ||||
|     @Bean | ||||
|     public TilesConfigurer tilesConfigurer() { | ||||
|         TilesConfigurer tilesConfigurer = new TilesConfigurer(); | ||||
|         tilesConfigurer.setDefinitions(new String[] { "/WEB-INF/views/**/tiles.xml" }); | ||||
|         tilesConfigurer.setCheckRefresh(true); | ||||
|         return tilesConfigurer; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Configure ViewResolvers to deliver views. | ||||
|      */ | ||||
|     @Override | ||||
|     public void configureViewResolvers(ViewResolverRegistry registry) { | ||||
|         TilesViewResolver viewResolver = new TilesViewResolver(); | ||||
|         registry.viewResolver(viewResolver); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Configure ResourceHandlers to serve static resources | ||||
|      */ | ||||
| 
 | ||||
|     @Override | ||||
|     public void addResourceHandlers(ResourceHandlerRegistry registry) { | ||||
|         registry.addResourceHandler("/static/**").addResourceLocations("/static/"); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,26 @@ | ||||
| package com.baeldung.tiles.springmvc; | ||||
| 
 | ||||
| import org.springframework.stereotype.Controller; | ||||
| import org.springframework.ui.ModelMap; | ||||
| import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.RequestMethod; | ||||
| 
 | ||||
| @Controller | ||||
| @RequestMapping("/") | ||||
| public class ApplicationController { | ||||
| 
 | ||||
|     @RequestMapping(value = { "/" }, method = RequestMethod.GET) | ||||
|     public String homePage(ModelMap model) { | ||||
|         return "home"; | ||||
|     } | ||||
| 
 | ||||
|     @RequestMapping(value = { "/apachetiles" }, method = RequestMethod.GET) | ||||
|     public String productsPage(ModelMap model) { | ||||
|         return "apachetiles"; | ||||
|     } | ||||
| 
 | ||||
|     @RequestMapping(value = { "/springmvc" }, method = RequestMethod.GET) | ||||
|     public String contactUsPage(ModelMap model) { | ||||
|         return "springmvc"; | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,22 @@ | ||||
| package com.baeldung.tiles.springmvc; | ||||
| 
 | ||||
| import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; | ||||
| 
 | ||||
| public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { | ||||
| 
 | ||||
|     @Override | ||||
|     protected Class<?>[] getRootConfigClasses() { | ||||
|         return new Class[] { ApplicationConfiguration.class }; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     protected Class<?>[] getServletConfigClasses() { | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     protected String[] getServletMappings() { | ||||
|         return new String[] { "/" }; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,12 @@ | ||||
| <%@ page language="java" contentType="text/html; charset=ISO-8859-1" | ||||
|     pageEncoding="ISO-8859-1"%> | ||||
| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ||||
| <html> | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | ||||
| <title>Apache Tiles</title> | ||||
| </head> | ||||
| <body> | ||||
| <h2>Tiles with Spring MVC Demo</h2> | ||||
| </body> | ||||
| </html> | ||||
| @ -0,0 +1,12 @@ | ||||
| <%@ page language="java" contentType="text/html; charset=ISO-8859-1" | ||||
|     pageEncoding="ISO-8859-1"%> | ||||
| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ||||
| <html> | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | ||||
| <title>Home</title> | ||||
| </head> | ||||
| <body> | ||||
| <h2>Welcome to Apache Tiles integration with Spring MVC</h2> | ||||
| </body> | ||||
| </html> | ||||
| @ -0,0 +1,12 @@ | ||||
| <%@ page language="java" contentType="text/html; charset=ISO-8859-1" | ||||
|     pageEncoding="ISO-8859-1"%> | ||||
| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ||||
| <html> | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | ||||
| <title>Spring MVC</title> | ||||
| </head> | ||||
| <body> | ||||
| <h2>Spring MVC configured to work with Apache Tiles</h2> | ||||
| </body> | ||||
| </html> | ||||
| @ -0,0 +1,25 @@ | ||||
| <%@ page language="java" contentType="text/html; charset=ISO-8859-1" | ||||
| 	pageEncoding="ISO-8859-1"%> | ||||
| <%@ page isELIgnored="false"%> | ||||
| <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> | ||||
| <%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%> | ||||
| 
 | ||||
| <html> | ||||
| 
 | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | ||||
| <title><tiles:getAsString name="title" /></title> | ||||
| <link href="<c:url value='/static/css/app.css' />" rel="stylesheet"></link> | ||||
| </head> | ||||
| 
 | ||||
| <body> | ||||
|     <div class="flex-container"> | ||||
|         <tiles:insertAttribute name="header" /> | ||||
|         <tiles:insertAttribute name="menu" /> | ||||
|         <article class="article"> | ||||
| 		    <tiles:insertAttribute name="body" /> | ||||
|         </article> | ||||
|     <tiles:insertAttribute name="footer" /> | ||||
|     </div> | ||||
| </body> | ||||
| </html> | ||||
| @ -0,0 +1,2 @@ | ||||
| 
 | ||||
| <footer>copyright © Baeldung</footer> | ||||
| @ -0,0 +1,3 @@ | ||||
| <header> | ||||
|   <h1>Welcome to Spring MVC integration with Apache Tiles</h1> | ||||
| </header> | ||||
| @ -0,0 +1,8 @@ | ||||
| <nav class="nav"> | ||||
|     <a href="${pageContext.request.contextPath}/"></a> | ||||
|     <ul id="menu"> | ||||
|        <li><a href="${pageContext.request.contextPath}/">Home</a></li> | ||||
|        <li><a href="${pageContext.request.contextPath}/springmvc">SpringMVC</a></li> | ||||
|        <li><a href="${pageContext.request.contextPath}/apachetiles">ApacheTiles</a></li> | ||||
|     </ul> | ||||
| </nav> | ||||
| @ -0,0 +1,34 @@ | ||||
| <?xml version="1.0" encoding="UTF-8" ?> | ||||
| <!DOCTYPE tiles-definitions PUBLIC  "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"  "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">   | ||||
|   | ||||
| <tiles-definitions>   | ||||
|    | ||||
|    <!-- Template Definition --> | ||||
|    <definition name="template-def" | ||||
|        template="/WEB-INF/views/tiles/layouts/defaultLayout.jsp">   | ||||
|        <put-attribute name="title" value="" />   | ||||
|        <put-attribute name="header" value="/WEB-INF/views/tiles/templates/defaultHeader.jsp" />   | ||||
|        <put-attribute name="menu" value="/WEB-INF/views/tiles/templates/defaultMenu.jsp" />   | ||||
|        <put-attribute name="body" value="" />   | ||||
|        <put-attribute name="footer" value="/WEB-INF/views/tiles/templates/defaultFooter.jsp" />   | ||||
|    </definition>   | ||||
|    | ||||
|    <!-- Main Page --> | ||||
|    <definition name="home" extends="template-def">   | ||||
|        <put-attribute name="title" value="Welcome" />   | ||||
|        <put-attribute name="body" value="/WEB-INF/views/pages/home.jsp" />   | ||||
|    </definition>   | ||||
|   | ||||
|    <!-- Apache Tiles Page --> | ||||
|    <definition name="apachetiles" extends="template-def">   | ||||
|        <put-attribute name="title" value="ApacheTiles" />   | ||||
|        <put-attribute name="body" value="/WEB-INF/views/pages/apachetiles.jsp" />   | ||||
|    </definition>   | ||||
|         | ||||
|    <!-- Spring MVC Page --> | ||||
|    <definition name="springmvc" extends="template-def">   | ||||
|        <put-attribute name="title" value="SpringMVC" />   | ||||
|        <put-attribute name="body" value="/WEB-INF/views/pages/springmvc.jsp" />   | ||||
|    </definition>   | ||||
|    | ||||
| </tiles-definitions> | ||||
							
								
								
									
										36
									
								
								spring-mvc-tiles/src/main/webapp/static/css/app.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								spring-mvc-tiles/src/main/webapp/static/css/app.css
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,36 @@ | ||||
| .flex-container { | ||||
|     display: -webkit-flex; | ||||
|     display: flex; | ||||
|     -webkit-flex-flow: row wrap; | ||||
|     flex-flow: row wrap; | ||||
|     text-align: center; | ||||
| } | ||||
| 
 | ||||
| .flex-container > * { | ||||
|     padding: 15px; | ||||
|     -webkit-flex: 1 100%; | ||||
|     flex: 1 100%; | ||||
| } | ||||
| 
 | ||||
| .article { | ||||
|     text-align: left; | ||||
| } | ||||
| 
 | ||||
| header {background: black;color:white;} | ||||
| footer {background: #aaa;color:white;} | ||||
| .nav {background:#eee;} | ||||
| 
 | ||||
| .nav ul { | ||||
|     list-style-type: none; | ||||
|  padding: 0; | ||||
| } | ||||
|     | ||||
| .nav ul a { | ||||
|  text-decoration: none; | ||||
| } | ||||
| 
 | ||||
| @media all and (min-width: 768px) { | ||||
|     .nav {text-align:left;-webkit-flex: 1 auto;flex:1 auto;-webkit-order:1;order:1;} | ||||
|     .article {-webkit-flex:5 0px;flex:5 0px;-webkit-order:2;order:2;} | ||||
|     footer {-webkit-order:3;order:3;} | ||||
| } | ||||
| @ -31,9 +31,8 @@ public class SessionTimerInterceptor extends HandlerInterceptorAdapter { | ||||
| 		request.setAttribute("executionTime", startTime); | ||||
| 		if (UserInterceptor.isUserLogged()) { | ||||
| 			session = request.getSession(); | ||||
| 			log.info("Who is logged in: " + SecurityContextHolder.getContext().getAuthentication().getName()); | ||||
| 			log.info("Time since last request in this session: " | ||||
| 					+ (System.currentTimeMillis() - request.getSession().getLastAccessedTime()) + " ms"); | ||||
| 			log.info("Time since last request in this session: {} ms", | ||||
| 					System.currentTimeMillis() - request.getSession().getLastAccessedTime()); | ||||
| 			if (System.currentTimeMillis() - session.getLastAccessedTime() > MAX_INACTIVE_SESSION_TIME) { | ||||
| 				log.warn("Logging out, due to inactive session"); | ||||
| 				SecurityContextHolder.clearContext(); | ||||
| @ -52,6 +51,6 @@ public class SessionTimerInterceptor extends HandlerInterceptorAdapter { | ||||
| 			final ModelAndView model) throws Exception { | ||||
| 		log.info("Post handle method - check execution time of handling"); | ||||
| 		long startTime = (Long) request.getAttribute("executionTime"); | ||||
| 		log.info("Execution time for handling the request was: " + (System.currentTimeMillis() - startTime) + " ms"); | ||||
| 		log.info("Execution time for handling the request was: {} ms", System.currentTimeMillis() - startTime); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -5,185 +5,186 @@ | ||||
| 	<artifactId>spring-thymeleaf</artifactId> | ||||
| 	<version>0.1-SNAPSHOT</version> | ||||
| 	<packaging>war</packaging> | ||||
| 	<properties> | ||||
| 		<java-version>1.7</java-version> | ||||
| 		<!-- spring --> | ||||
| 		<org.springframework-version>4.3.3.RELEASE</org.springframework-version> | ||||
| 		<javax.servlet-version>3.0.1</javax.servlet-version> | ||||
| 		<!-- logging --> | ||||
| 		<org.slf4j.version>1.7.12</org.slf4j.version> | ||||
| 		<logback.version>1.1.3</logback.version> | ||||
| 		<!-- thymeleaf --> | ||||
| 		<org.thymeleaf-version>2.1.4.RELEASE</org.thymeleaf-version> | ||||
| 		<!-- validation --> | ||||
| 		<javax.validation-version>1.1.0.Final</javax.validation-version> | ||||
| 		<org.hibernate-version>5.1.2.Final</org.hibernate-version> | ||||
| 	    <properties> | ||||
|         <java-version>1.8</java-version> | ||||
|         <!-- spring --> | ||||
|         <org.springframework-version>4.3.3.RELEASE</org.springframework-version> | ||||
|         <javax.servlet-version>3.0.1</javax.servlet-version> | ||||
|         <!-- logging --> | ||||
|         <org.slf4j.version>1.7.12</org.slf4j.version> | ||||
|         <logback.version>1.1.3</logback.version> | ||||
|         <!-- thymeleaf --> | ||||
|         <org.thymeleaf-version>3.0.1.RELEASE</org.thymeleaf-version> | ||||
|         <!-- validation --> | ||||
|         <javax.validation-version>1.1.0.Final</javax.validation-version> | ||||
|         <org.hibernate-version>5.1.2.Final</org.hibernate-version> | ||||
| 
 | ||||
| 		<!-- Maven plugins --> | ||||
| 		<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version> | ||||
| 		<maven-war-plugin.version>2.6</maven-war-plugin.version> | ||||
| 		<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version> | ||||
| 		<cargo-maven2-plugin.version>1.4.18</cargo-maven2-plugin.version> | ||||
| 	</properties> | ||||
|         <!-- Maven plugins --> | ||||
|         <maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version> | ||||
|         <maven-war-plugin.version>2.6</maven-war-plugin.version> | ||||
|         <maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version> | ||||
|         <cargo-maven2-plugin.version>1.4.18</cargo-maven2-plugin.version> | ||||
|     </properties> | ||||
| 
 | ||||
| 	<dependencies> | ||||
| 		<!-- Spring --> | ||||
| 		<dependency> | ||||
| 			<groupId>org.springframework</groupId> | ||||
| 			<artifactId>spring-context</artifactId> | ||||
| 			<version>${org.springframework-version}</version> | ||||
| 			<exclusions> | ||||
| 				<!-- Exclude Commons Logging in favor of SLF4j --> | ||||
| 				<exclusion> | ||||
| 					<groupId>commons-logging</groupId> | ||||
| 					<artifactId>commons-logging</artifactId> | ||||
| 				</exclusion> | ||||
| 			</exclusions> | ||||
| 		</dependency> | ||||
| 		<dependency> | ||||
| 			<groupId>org.springframework</groupId> | ||||
| 			<artifactId>spring-webmvc</artifactId> | ||||
| 			<version>${org.springframework-version}</version> | ||||
| 		</dependency> | ||||
| 		<!-- Spring Security --> | ||||
| 		<dependency> | ||||
| 			<groupId>org.springframework.security</groupId> | ||||
| 			<artifactId>spring-security-web</artifactId> | ||||
| 			<version>4.1.3.RELEASE</version> | ||||
| 		</dependency> | ||||
| 		<dependency> | ||||
| 			<groupId>org.springframework.security</groupId> | ||||
| 			<artifactId>spring-security-config</artifactId> | ||||
| 			<version>4.1.3.RELEASE</version> | ||||
| 		</dependency> | ||||
| 		<!-- Thymeleaf --> | ||||
| 		<dependency> | ||||
| 			<groupId>org.thymeleaf</groupId> | ||||
| 			<artifactId>thymeleaf</artifactId> | ||||
| 			<version>${org.thymeleaf-version}</version> | ||||
| 		</dependency> | ||||
| 		<dependency> | ||||
| 			<groupId>org.thymeleaf</groupId> | ||||
| 			<artifactId>thymeleaf-spring4</artifactId> | ||||
| 			<version>${org.thymeleaf-version}</version> | ||||
| 		</dependency> | ||||
| 		<!-- Logging --> | ||||
| 		<!-- logging --> | ||||
| 		<dependency> | ||||
| 			<groupId>org.slf4j</groupId> | ||||
| 			<artifactId>slf4j-api</artifactId> | ||||
| 			<version>${org.slf4j.version}</version> | ||||
| 		</dependency> | ||||
| 		<dependency> | ||||
| 			<groupId>ch.qos.logback</groupId> | ||||
| 			<artifactId>logback-classic</artifactId> | ||||
| 			<version>${logback.version}</version> | ||||
| 			<!-- <scope>runtime</scope> --> | ||||
| 		</dependency> | ||||
| 		<dependency> | ||||
| 			<groupId>org.slf4j</groupId> | ||||
| 			<artifactId>jcl-over-slf4j</artifactId> | ||||
| 			<version>${org.slf4j.version}</version> | ||||
| 			<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl --> | ||||
| 		</dependency> | ||||
| 		<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly --> | ||||
| 			<groupId>org.slf4j</groupId> | ||||
| 			<artifactId>log4j-over-slf4j</artifactId> | ||||
| 			<version>${org.slf4j.version}</version> | ||||
| 		</dependency> | ||||
| 		<!-- Servlet --> | ||||
| 		<dependency> | ||||
| 			<groupId>javax.servlet</groupId> | ||||
| 			<artifactId>javax.servlet-api</artifactId> | ||||
| 			<version>${javax.servlet-version}</version> | ||||
| 			<scope>provided</scope> | ||||
| 		</dependency> | ||||
| 		<!-- Validation --> | ||||
| 		<dependency> | ||||
| 			<groupId>javax.validation</groupId> | ||||
| 			<artifactId>validation-api</artifactId> | ||||
| 			<version>${javax.validation-version}</version> | ||||
| 		</dependency> | ||||
| 		<dependency> | ||||
| 			<groupId>org.hibernate</groupId> | ||||
| 			<artifactId>hibernate-validator</artifactId> | ||||
| 			<version>${org.hibernate-version}</version> | ||||
| 		</dependency> | ||||
| 		<!-- test scoped --> | ||||
|     <dependencies> | ||||
|         <!-- Spring --> | ||||
|         <dependency> | ||||
|             <groupId>org.springframework</groupId> | ||||
|             <artifactId>spring-context</artifactId> | ||||
|             <version>${org.springframework-version}</version> | ||||
|             <exclusions> | ||||
|                 <!-- Exclude Commons Logging in favor of SLF4j --> | ||||
|                 <exclusion> | ||||
|                     <groupId>commons-logging</groupId> | ||||
|                     <artifactId>commons-logging</artifactId> | ||||
|                 </exclusion> | ||||
|             </exclusions> | ||||
|         </dependency> | ||||
|         <dependency> | ||||
|             <groupId>org.springframework</groupId> | ||||
|             <artifactId>spring-webmvc</artifactId> | ||||
|             <version>${org.springframework-version}</version> | ||||
|         </dependency> | ||||
|         <!-- Spring Security --> | ||||
|         <dependency> | ||||
|             <groupId>org.springframework.security</groupId> | ||||
|             <artifactId>spring-security-web</artifactId> | ||||
|             <version>4.1.3.RELEASE</version> | ||||
|         </dependency> | ||||
|         <dependency> | ||||
|             <groupId>org.springframework.security</groupId> | ||||
|             <artifactId>spring-security-config</artifactId> | ||||
|             <version>4.1.3.RELEASE</version> | ||||
|         </dependency> | ||||
|         <!-- Thymeleaf --> | ||||
|         <dependency> | ||||
|             <groupId>org.thymeleaf</groupId> | ||||
|             <artifactId>thymeleaf</artifactId> | ||||
|             <version>${org.thymeleaf-version}</version> | ||||
|         </dependency> | ||||
|         <dependency> | ||||
|             <groupId>org.thymeleaf</groupId> | ||||
|             <artifactId>thymeleaf-spring4</artifactId> | ||||
|             <version>${org.thymeleaf-version}</version> | ||||
|         </dependency> | ||||
|         <!-- Logging --> | ||||
|         <dependency> | ||||
|             <groupId>org.slf4j</groupId> | ||||
|             <artifactId>slf4j-api</artifactId> | ||||
|             <version>${org.slf4j.version}</version> | ||||
|         </dependency> | ||||
|         <dependency> | ||||
|             <groupId>ch.qos.logback</groupId> | ||||
|             <artifactId>logback-classic</artifactId> | ||||
|             <version>${logback.version}</version> | ||||
|             <!-- <scope>runtime</scope> --> | ||||
|         </dependency> | ||||
|         <dependency> | ||||
|             <groupId>org.slf4j</groupId> | ||||
|             <artifactId>jcl-over-slf4j</artifactId> | ||||
|             <version>${org.slf4j.version}</version> | ||||
|             <!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl --> | ||||
|         </dependency> | ||||
|         <dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly --> | ||||
|             <groupId>org.slf4j</groupId> | ||||
|             <artifactId>log4j-over-slf4j</artifactId> | ||||
|             <version>${org.slf4j.version}</version> | ||||
|         </dependency> | ||||
|         <!-- Servlet --> | ||||
|         <dependency> | ||||
|             <groupId>javax.servlet</groupId> | ||||
|             <artifactId>javax.servlet-api</artifactId> | ||||
|             <version>${javax.servlet-version}</version> | ||||
|             <scope>provided</scope> | ||||
|         </dependency> | ||||
|         <!-- Validation --> | ||||
|         <dependency> | ||||
|             <groupId>javax.validation</groupId> | ||||
|             <artifactId>validation-api</artifactId> | ||||
|             <version>${javax.validation-version}</version> | ||||
|         </dependency> | ||||
|         <dependency> | ||||
|             <groupId>org.hibernate</groupId> | ||||
|             <artifactId>hibernate-validator</artifactId> | ||||
|             <version>${org.hibernate-version}</version> | ||||
|         </dependency> | ||||
|         <!-- test scoped --> | ||||
| 
 | ||||
| 		<dependency> | ||||
| 			<groupId>org.springframework</groupId> | ||||
| 			<artifactId>spring-test</artifactId> | ||||
| 			<version>4.1.3.RELEASE</version> | ||||
| 			<scope>test</scope> | ||||
| 		</dependency> | ||||
|         <dependency> | ||||
|             <groupId>org.springframework</groupId> | ||||
|             <artifactId>spring-test</artifactId> | ||||
|             <version>4.1.3.RELEASE</version> | ||||
|             <scope>test</scope> | ||||
|         </dependency> | ||||
| 
 | ||||
| 		<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-test --> | ||||
| 		<dependency> | ||||
| 			<groupId>org.springframework.security</groupId> | ||||
| 			<artifactId>spring-security-test</artifactId> | ||||
| 			<version>4.1.3.RELEASE</version> | ||||
| 			<scope>test</scope> | ||||
| 		</dependency> | ||||
|         <!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-test --> | ||||
|         <dependency> | ||||
|             <groupId>org.springframework.security</groupId> | ||||
|             <artifactId>spring-security-test</artifactId> | ||||
|             <version>4.1.3.RELEASE</version> | ||||
|             <scope>test</scope> | ||||
|         </dependency> | ||||
| 
 | ||||
| 		<!-- https://mvnrepository.com/artifact/junit/junit --> | ||||
| 		<dependency> | ||||
| 			<groupId>junit</groupId> | ||||
| 			<artifactId>junit</artifactId> | ||||
| 			<version>4.12</version> | ||||
| 			<scope>test</scope> | ||||
| 		</dependency> | ||||
|         <!-- https://mvnrepository.com/artifact/junit/junit --> | ||||
|         <dependency> | ||||
|             <groupId>junit</groupId> | ||||
|             <artifactId>junit</artifactId> | ||||
|             <version>4.12</version> | ||||
|             <scope>test</scope> | ||||
|         </dependency> | ||||
| 
 | ||||
| 	</dependencies> | ||||
| 	<build> | ||||
| 		<plugins> | ||||
| 			<plugin> | ||||
| 				<groupId>org.apache.maven.plugins</groupId> | ||||
| 				<artifactId>maven-compiler-plugin</artifactId> | ||||
| 				<version>${maven-compiler-plugin.version}</version> | ||||
| 				<configuration> | ||||
| 					<source>${java-version}</source> | ||||
| 					<target>${java-version}</target> | ||||
| 				</configuration> | ||||
| 			</plugin> | ||||
| 			<plugin> | ||||
| 				<groupId>org.apache.maven.plugins</groupId> | ||||
| 				<artifactId>maven-war-plugin</artifactId> | ||||
| 				<version>${maven-war-plugin.version}</version> | ||||
| 				<configuration> | ||||
| 					<failOnMissingWebXml>false</failOnMissingWebXml> | ||||
| 				</configuration> | ||||
| 			</plugin> | ||||
| 			<plugin> | ||||
| 				<groupId>org.apache.maven.plugins</groupId> | ||||
| 				<artifactId>maven-surefire-plugin</artifactId> | ||||
| 				<version>${maven-surefire-plugin.version}</version> | ||||
| 				<configuration> | ||||
| 					<excludes> | ||||
| 					</excludes> | ||||
| 					<systemPropertyVariables> | ||||
| 					</systemPropertyVariables> | ||||
| 				</configuration> | ||||
| 			</plugin> | ||||
| 			<plugin> | ||||
| 				<groupId>org.codehaus.cargo</groupId> | ||||
| 				<artifactId>cargo-maven2-plugin</artifactId> | ||||
| 				<version>${cargo-maven2-plugin.version}</version> | ||||
| 				<configuration> | ||||
| 					<wait>true</wait> | ||||
| 					<container> | ||||
| 						<containerId>jetty8x</containerId> | ||||
| 						<type>embedded</type> | ||||
| 						<systemProperties> | ||||
| 						</systemProperties> | ||||
| 					</container> | ||||
| 					<configuration> | ||||
| 						<properties> | ||||
| 							<cargo.servlet.port>8082</cargo.servlet.port> | ||||
| 						</properties> | ||||
| 					</configuration> | ||||
| 				</configuration> | ||||
| 			</plugin> | ||||
| 		</plugins> | ||||
| 	</build> | ||||
|     </dependencies> | ||||
| 
 | ||||
|     <build> | ||||
|         <plugins> | ||||
|             <plugin> | ||||
|                 <groupId>org.apache.maven.plugins</groupId> | ||||
|                 <artifactId>maven-compiler-plugin</artifactId> | ||||
|                 <version>${maven-compiler-plugin.version}</version> | ||||
|                 <configuration> | ||||
|                     <source>${java-version}</source> | ||||
|                     <target>${java-version}</target> | ||||
|                 </configuration> | ||||
|             </plugin> | ||||
|             <plugin> | ||||
|                 <groupId>org.apache.maven.plugins</groupId> | ||||
|                 <artifactId>maven-war-plugin</artifactId> | ||||
|                 <version>${maven-war-plugin.version}</version> | ||||
|                 <configuration> | ||||
|                     <failOnMissingWebXml>false</failOnMissingWebXml> | ||||
|                 </configuration> | ||||
|             </plugin> | ||||
|             <plugin> | ||||
|                 <groupId>org.apache.maven.plugins</groupId> | ||||
|                 <artifactId>maven-surefire-plugin</artifactId> | ||||
|                 <version>${maven-surefire-plugin.version}</version> | ||||
|                 <configuration> | ||||
|                     <excludes> | ||||
|                     </excludes> | ||||
|                     <systemPropertyVariables> | ||||
|                     </systemPropertyVariables> | ||||
|                 </configuration> | ||||
|             </plugin> | ||||
|             <plugin> | ||||
|                 <groupId>org.codehaus.cargo</groupId> | ||||
|                 <artifactId>cargo-maven2-plugin</artifactId> | ||||
|                 <version>${cargo-maven2-plugin.version}</version> | ||||
|                 <configuration> | ||||
|                     <wait>true</wait> | ||||
|                     <container> | ||||
|                         <containerId>jetty8x</containerId> | ||||
|                         <type>embedded</type> | ||||
|                         <systemProperties> | ||||
|                         </systemProperties> | ||||
|                     </container> | ||||
|                     <configuration> | ||||
|                         <properties> | ||||
|                             <cargo.servlet.port>8082</cargo.servlet.port> | ||||
|                         </properties> | ||||
|                     </configuration> | ||||
|                 </configuration> | ||||
|             </plugin> | ||||
|         </plugins> | ||||
|     </build> | ||||
|      | ||||
| </project> | ||||
|  | ||||
Some files were not shown because too many files have changed in this diff Show More
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user