diff --git a/jee7/.gitignore b/jee7/.gitignore new file mode 100644 index 0000000000..067348b3f4 --- /dev/null +++ b/jee7/.gitignore @@ -0,0 +1,5 @@ + +/classes/ +/.idea/ +/target/ +/jee7.iml diff --git a/jee7/pom.xml b/jee7/pom.xml index b5e0d80b6c..6858a05d17 100644 --- a/jee7/pom.xml +++ b/jee7/pom.xml @@ -6,8 +6,10 @@ com.baeldung jee7 1.0-SNAPSHOT + war JavaEE 7 Arquillian Archetype Sample + com.baeldung parent-modules @@ -174,6 +176,7 @@ maven-war-plugin ${maven-war-plugin.version} + webapp false diff --git a/jee7/src/main/webapp/WEB-INF/spring/security.xml b/jee7/src/main/webapp/WEB-INF/spring/security.xml new file mode 100644 index 0000000000..777cd9461f --- /dev/null +++ b/jee7/src/main/webapp/WEB-INF/spring/security.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jee7/src/main/webapp/WEB-INF/web.xml b/jee7/src/main/webapp/WEB-INF/web.xml index 11bd87cf99..1bcbb96e24 100644 --- a/jee7/src/main/webapp/WEB-INF/web.xml +++ b/jee7/src/main/webapp/WEB-INF/web.xml @@ -32,6 +32,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + index.jsf welcome.jsf diff --git a/jee7/src/main/webapp/index.jsp b/jee7/src/main/webapp/index.jsp new file mode 100644 index 0000000000..93fef9713d --- /dev/null +++ b/jee7/src/main/webapp/index.jsp @@ -0,0 +1,11 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + Index Page + + + Non-secured Index Page +
+ Login + + \ No newline at end of file diff --git a/jee7/src/main/webapp/secure.jsp b/jee7/src/main/webapp/secure.jsp new file mode 100644 index 0000000000..0cadd2cd4f --- /dev/null +++ b/jee7/src/main/webapp/secure.jsp @@ -0,0 +1,24 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://www.springframework.org/security/tags" prefix="sec" %> + + + + + Home Page + + +

Home Page

+ +

+ Hello
+ Roles: +

+ +
+ + +
+ + \ No newline at end of file diff --git a/kotlin/src/main/kotlin/com/baeldung/kotlin/Sealed.kt b/kotlin/src/main/kotlin/com/baeldung/kotlin/Sealed.kt new file mode 100644 index 0000000000..96e54716b3 --- /dev/null +++ b/kotlin/src/main/kotlin/com/baeldung/kotlin/Sealed.kt @@ -0,0 +1,19 @@ +package com.baeldung.kotlin + +sealed class Result { + abstract fun map(func: (S) -> R) : Result + abstract fun mapFailure(func: (F) -> R) : Result + abstract fun get() : S? +} + +data class Success(val success: S) : Result() { + override fun map(func: (S) -> R) : Result = Success(func(success)) + override fun mapFailure(func: (F) -> R): Result = Success(success) + override fun get(): S? = success +} + +data class Failure(val failure: F) : Result() { + override fun map(func: (S) -> R) : Result = Failure(failure) + override fun mapFailure(func: (F) -> R): Result = Failure(func(failure)) + override fun get(): S? = null +} diff --git a/kotlin/src/test/kotlin/com/baeldung/kotlin/SealedTest.kt b/kotlin/src/test/kotlin/com/baeldung/kotlin/SealedTest.kt new file mode 100644 index 0000000000..8c7509f653 --- /dev/null +++ b/kotlin/src/test/kotlin/com/baeldung/kotlin/SealedTest.kt @@ -0,0 +1,84 @@ +package com.baeldung.kotlin + +import org.junit.Assert +import org.junit.Test + +class SealedTest { + fun divide(a: Int, b: Int) : Result = when (b) { + 0 -> Failure("Division by zero") + else -> Success(a.toFloat() / b) + } + + @Test + fun testSuccess() { + val result = divide(10, 5) + Assert.assertEquals(Success(2.0f), result) + } + + @Test + fun testError() { + val result = divide(10, 0) + Assert.assertEquals(Failure("Division by zero"), result) + } + + @Test + fun testMatchOnSuccess() { + val result = divide(10, 5) + when (result) { + is Success -> { + // Expected + } + is Failure -> Assert.fail("Expected Success") + } + } + + @Test + fun testMatchOnError() { + val result = divide(10, 0) + when (result) { + is Failure -> { + // Expected + } + } + } + + @Test + fun testGetSuccess() { + val result = divide(10, 5) + Assert.assertEquals(2.0f, result.get()) + } + + @Test + fun testGetError() { + val result = divide(10, 0) + Assert.assertNull(result.get()) + } + + @Test + fun testMapOnSuccess() { + val result = divide(10, 5) + .map { "Result: $it" } + Assert.assertEquals(Success("Result: 2.0"), result) + } + + @Test + fun testMapOnError() { + val result = divide(10, 0) + .map { "Result: $it" } + Assert.assertEquals(Failure("Division by zero"), result) + } + + @Test + fun testMapFailureOnSuccess() { + val result = divide(10, 5) + .mapFailure { "Failure: $it" } + Assert.assertEquals(Success(2.0f), result) + } + + @Test + fun testMapFailureOnError() { + val result = divide(10, 0) + .mapFailure { "Failure: $it" } + Assert.assertEquals(Failure("Failure: Division by zero"), result) + } +} diff --git a/spring-mvc-simple/pom.xml b/spring-mvc-simple/pom.xml index 14590f3de4..8a51c04113 100644 --- a/spring-mvc-simple/pom.xml +++ b/spring-mvc-simple/pom.xml @@ -27,6 +27,7 @@ 3.0.7.RELEASE 2.4.12 2.3.23 + 1.2.5 @@ -114,6 +115,13 @@ groovy-templates ${groovy.version} + + + + de.neuland-bfi + spring-jade4j + ${jade.version} + diff --git a/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/JadeTemplateConfiguration.java b/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/JadeTemplateConfiguration.java new file mode 100644 index 0000000000..10345bac58 --- /dev/null +++ b/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/JadeTemplateConfiguration.java @@ -0,0 +1,39 @@ +package com.baeldung.spring.configuration; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.ViewResolver; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; + +import de.neuland.jade4j.JadeConfiguration; +import de.neuland.jade4j.spring.template.SpringTemplateLoader; +import de.neuland.jade4j.spring.view.JadeViewResolver; + +@Configuration +@EnableWebMvc +@ComponentScan(basePackages = { "com.baeldung.springmvcforms", "com.baeldung.spring.controller", "com.baeldung.spring.validator" }) +public class JadeTemplateConfiguration { + @Bean + public SpringTemplateLoader templateLoader() { + SpringTemplateLoader templateLoader = new SpringTemplateLoader(); + templateLoader.setBasePath("/WEB-INF/views/"); + templateLoader.setSuffix(".jade"); + return templateLoader; + } + + @Bean + public JadeConfiguration jadeConfiguration() { + JadeConfiguration configuration = new JadeConfiguration(); + configuration.setCaching(false); + configuration.setTemplateLoader(templateLoader()); + return configuration; + } + + @Bean + public ViewResolver viewResolver() { + JadeViewResolver viewResolver = new JadeViewResolver(); + viewResolver.setConfiguration(jadeConfiguration()); + return viewResolver; + } +} diff --git a/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/WebInitializer.java b/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/WebInitializer.java index 3e5b416191..d57d2c621a 100644 --- a/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/WebInitializer.java +++ b/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/WebInitializer.java @@ -18,6 +18,7 @@ public class WebInitializer implements WebApplicationInitializer { //ctx.register(ThymeleafConfiguration.class); //ctx.register(FreemarkerConfiguration.class); //ctx.register(GroovyConfiguration.class); + //ctx.register(JadeTemplateConfiguration.class); ctx.setServletContext(container); // Manage the lifecycle of the root application context diff --git a/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/UserController.java b/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/UserController.java index 55179938fc..b402a376c0 100644 --- a/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/UserController.java +++ b/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/UserController.java @@ -35,6 +35,12 @@ public class UserController { return "registration-groovy"; } + @GetMapping("/registration-jade") + public String getRegistrationJade(Model model) { + model.addAttribute("user", new User()); + return "registration-jade"; + } + @PostMapping("/register") @ResponseBody public void register(User user){ diff --git a/spring-mvc-simple/src/main/webapp/WEB-INF/views/registration-jade.jade b/spring-mvc-simple/src/main/webapp/WEB-INF/views/registration-jade.jade new file mode 100644 index 0000000000..44b6293ff0 --- /dev/null +++ b/spring-mvc-simple/src/main/webapp/WEB-INF/views/registration-jade.jade @@ -0,0 +1,11 @@ +doctype html +html + head + title User Registration + body + form(action="register" method="post" ) + label(for="email") Emailaaaaaaaa: + input(type="text" name="email") + label(for="password") Password: + input(type="password" name="password") + input(type="submit" value="Submit") \ No newline at end of file