Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
6eaf0f7373
1
annotations/readme.md
Normal file
1
annotations/readme.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
core-java-9/src/test/java/com/baeldung/java9/README.MD
Normal file
1
core-java-9/src/test/java/com/baeldung/java9/README.MD
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
flyway-migration/README.MD
Normal file
1
flyway-migration/README.MD
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
@ -1,4 +1,5 @@
|
|||||||
<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">
|
<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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>selenium-junit-testng</artifactId>
|
<artifactId>selenium-junit-testng</artifactId>
|
||||||
@ -14,6 +15,17 @@
|
|||||||
<target>1.8</target>
|
<target>1.8</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.19.1</version>
|
||||||
|
<configuration>
|
||||||
|
<testSourceDirectory></testSourceDirectory>
|
||||||
|
<includes>
|
||||||
|
<include>Test*.java</include>
|
||||||
|
</includes>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -6,8 +6,7 @@ import org.openqa.selenium.firefox.FirefoxDriver;
|
|||||||
public class SeleniumExample {
|
public class SeleniumExample {
|
||||||
|
|
||||||
private WebDriver webDriver;
|
private WebDriver webDriver;
|
||||||
private final String url = "http://www.baeldung.com/";
|
private String url = "http://www.baeldung.com/";
|
||||||
private final String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
|
|
||||||
|
|
||||||
public SeleniumExample() {
|
public SeleniumExample() {
|
||||||
webDriver = new FirefoxDriver();
|
webDriver = new FirefoxDriver();
|
||||||
@ -18,12 +17,8 @@ public class SeleniumExample {
|
|||||||
webDriver.close();
|
webDriver.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getActualTitle() {
|
public String getTitle() {
|
||||||
return webDriver.getTitle();
|
return webDriver.getTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getExpectedTitle() {
|
|
||||||
return expectedTitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package test.java.com.baeldung.selenium.junit;
|
package test.java.com.baeldung.selenium.junit;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertNotNull;
|
||||||
import main.java.com.baeldung.selenium.SeleniumExample;
|
import main.java.com.baeldung.selenium.SeleniumExample;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
@ -10,6 +11,7 @@ import org.junit.Test;
|
|||||||
public class TestSeleniumWithJUnit {
|
public class TestSeleniumWithJUnit {
|
||||||
|
|
||||||
private SeleniumExample seleniumExample;
|
private SeleniumExample seleniumExample;
|
||||||
|
private String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@ -23,8 +25,8 @@ public class TestSeleniumWithJUnit {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
|
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
|
||||||
String expectedTitle = seleniumExample.getExpectedTitle();
|
String actualTitle = seleniumExample.getTitle();
|
||||||
String actualTitle = seleniumExample.getActualTitle();
|
assertNotNull(actualTitle);
|
||||||
assertEquals(actualTitle, expectedTitle);
|
assertEquals(actualTitle, expectedTitle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package test.java.com.baeldung.selenium.testng;
|
package test.java.com.baeldung.selenium.testng;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertNotNull;
|
||||||
import main.java.com.baeldung.selenium.SeleniumExample;
|
import main.java.com.baeldung.selenium.SeleniumExample;
|
||||||
|
|
||||||
import org.testng.annotations.AfterSuite;
|
import org.testng.annotations.AfterSuite;
|
||||||
@ -10,6 +11,7 @@ import org.testng.annotations.Test;
|
|||||||
public class TestSeleniumWithTestNG {
|
public class TestSeleniumWithTestNG {
|
||||||
|
|
||||||
private SeleniumExample seleniumExample;
|
private SeleniumExample seleniumExample;
|
||||||
|
private String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
|
||||||
|
|
||||||
@BeforeSuite
|
@BeforeSuite
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@ -23,8 +25,8 @@ public class TestSeleniumWithTestNG {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
|
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
|
||||||
String expectedTitle = seleniumExample.getExpectedTitle();
|
String actualTitle = seleniumExample.getTitle();
|
||||||
String actualTitle = seleniumExample.getActualTitle();
|
assertNotNull(actualTitle);
|
||||||
assertEquals(actualTitle, expectedTitle);
|
assertEquals(actualTitle, expectedTitle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
package com.baeldun.selenium.testng;
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
import static org.testng.Assert.assertNotNull;
|
|
||||||
|
|
||||||
import org.openqa.selenium.WebDriver;
|
|
||||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
|
||||||
import org.testng.annotations.AfterSuite;
|
|
||||||
import org.testng.annotations.BeforeSuite;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
public class TestSeleniumWithTestNG {
|
|
||||||
|
|
||||||
private WebDriver webDriver;
|
|
||||||
private final String url = "http://www.baeldung.com/";
|
|
||||||
private final String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
|
|
||||||
|
|
||||||
@BeforeSuite
|
|
||||||
public void setUp() {
|
|
||||||
webDriver = new FirefoxDriver();
|
|
||||||
webDriver.get(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterSuite
|
|
||||||
public void tearDown() {
|
|
||||||
webDriver.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
|
|
||||||
String actualTitleReturned = webDriver.getTitle();
|
|
||||||
assertNotNull(actualTitleReturned);
|
|
||||||
assertEquals(expectedTitle, actualTitleReturned);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
package com.baeldung.selenium.junit;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.openqa.selenium.WebDriver;
|
|
||||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
|
||||||
|
|
||||||
public class TestSeleniumWithJUnit {
|
|
||||||
|
|
||||||
private WebDriver webDriver;
|
|
||||||
private final String url = "http://www.baeldung.com/";
|
|
||||||
private final String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
webDriver = new FirefoxDriver();
|
|
||||||
webDriver.get(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() {
|
|
||||||
webDriver.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
|
|
||||||
String actualTitleReturned = webDriver.getTitle();
|
|
||||||
assertNotNull(actualTitleReturned);
|
|
||||||
assertEquals(expectedTitle, actualTitleReturned);
|
|
||||||
}
|
|
||||||
}
|
|
1
spring-cloud-data-flow/README.MD
Normal file
1
spring-cloud-data-flow/README.MD
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
spring-cloud/spring-cloud-bootstrap/README.MD
Normal file
1
spring-cloud/spring-cloud-bootstrap/README.MD
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
spring-cloud/spring-cloud-hystrix/README.MD
Normal file
1
spring-cloud/spring-cloud-hystrix/README.MD
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
spring-mvc-web-vs-initializer/README.MD
Normal file
1
spring-mvc-web-vs-initializer/README.MD
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
@ -0,0 +1,33 @@
|
|||||||
|
package com.baeldung.thymeleaf.controller;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller to test expression utility objects: dates,
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
public class ExpressionUtilityObjectsController {
|
||||||
|
|
||||||
|
@RequestMapping(value = "/objects", method = RequestMethod.GET)
|
||||||
|
public String getDates(Model model) {
|
||||||
|
model.addAttribute("date", new Date());
|
||||||
|
model.addAttribute("calendar", Calendar.getInstance());
|
||||||
|
model.addAttribute("num", Math.random() * 10);
|
||||||
|
model.addAttribute("string", "new text");
|
||||||
|
model.addAttribute("emptyString", "");
|
||||||
|
model.addAttribute("nullString", null);
|
||||||
|
model.addAttribute("array", new int[] { 1, 3, 4, 5 });
|
||||||
|
model.addAttribute("set", new HashSet<Integer>(Arrays.asList(1, 3, 8)));
|
||||||
|
return "objects.html";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
47
spring-thymeleaf/src/main/webapp/WEB-INF/views/objects.html
Normal file
47
spring-thymeleaf/src/main/webapp/WEB-INF/views/objects.html
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||||
|
xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Expression utility objects</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Date expression utility</h1>
|
||||||
|
<p th:text="${#dates.formatISO(date)}"></p>
|
||||||
|
<p th:text="${#dates.format(date, 'dd-MM-yyyy HH:mm')}"></p>
|
||||||
|
<p th:text="${#dates.dayOfWeekName(date)}"></p>
|
||||||
|
<p th:text="${#dates.createNow()}"></p>
|
||||||
|
<p th:text="${#dates.createToday()}"></p>
|
||||||
|
|
||||||
|
<h1>Calendar expression utility</h1>
|
||||||
|
<p th:text="${#calendars.formatISO(calendar)}"></p>
|
||||||
|
<p th:text="${#calendars.format(calendar, 'dd-MM-yyyy HH:mm')}"></p>
|
||||||
|
<p th:text="${#calendars.dayOfWeekName(calendar)}"></p>
|
||||||
|
<p th:text="${#calendars.createNow().getTime()}"></p>
|
||||||
|
<p th:text="${#calendars.createToday().getFirstDayOfWeek()}"></p>
|
||||||
|
|
||||||
|
<h1>Numbers expression utility</h1>
|
||||||
|
<p th:text="${#numbers.formatDecimal(num,2,3)}"></p>
|
||||||
|
<p th:text="${#numbers.formatDecimal(num,2,3,'COMMA')}"></p>
|
||||||
|
<p th:each="number: ${#numbers.sequence(0,2)}">
|
||||||
|
<span th:text="${number}"></span>
|
||||||
|
</p>
|
||||||
|
<p th:each="number: ${#numbers.sequence(0,4,2)}">
|
||||||
|
<span th:text="${number}"></span>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h1>Calendar expression utility</h1>
|
||||||
|
<p th:text="${#strings.isEmpty(string)}"></p>
|
||||||
|
<p th:text="${#strings.isEmpty(nullString)}"></p>
|
||||||
|
<p th:text="${#strings.defaultString(emptyString,'Empty String')}"></p>
|
||||||
|
<p th:text="${#strings.containsIgnoreCase(string,'new')}"></p>
|
||||||
|
<p th:text="${#strings.abbreviate(string,5)} "></p>
|
||||||
|
<p th:text="${#strings.capitalizeWords(string)}"></p>
|
||||||
|
|
||||||
|
<h1>Aggregates expression utility</h1>
|
||||||
|
<p th:text="${#aggregates.sum(array)}"></p>
|
||||||
|
<p th:text="${#aggregates.avg(array)}"></p>
|
||||||
|
<p th:text="${#aggregates.sum(set)}"></p>
|
||||||
|
<p th:text="${#aggregates.avg(set)}"></p>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,58 @@
|
|||||||
|
package com.baeldung.thymeleaf.controller;
|
||||||
|
|
||||||
|
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
|
||||||
|
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
||||||
|
|
||||||
|
import javax.servlet.Filter;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.mock.web.MockHttpSession;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
import org.springframework.test.context.web.WebAppConfiguration;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
import org.springframework.test.web.servlet.request.RequestPostProcessor;
|
||||||
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
||||||
|
import com.baeldung.thymeleaf.config.InitSecurity;
|
||||||
|
import com.baeldung.thymeleaf.config.WebApp;
|
||||||
|
import com.baeldung.thymeleaf.config.WebMVCConfig;
|
||||||
|
import com.baeldung.thymeleaf.config.WebMVCSecurity;
|
||||||
|
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@WebAppConfiguration
|
||||||
|
@ContextConfiguration(classes = { WebApp.class, WebMVCConfig.class, WebMVCSecurity.class, InitSecurity.class })
|
||||||
|
public class ExpressionUtilityObjectsControllerTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
WebApplicationContext wac;
|
||||||
|
@Autowired
|
||||||
|
MockHttpSession session;
|
||||||
|
|
||||||
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Filter springSecurityFilterChain;
|
||||||
|
|
||||||
|
protected RequestPostProcessor testUser() {
|
||||||
|
return user("user1").password("user1Pass").roles("USER");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
mockMvc = MockMvcBuilders.webAppContextSetup(wac).addFilters(springSecurityFilterChain).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetDates() throws Exception{
|
||||||
|
mockMvc.perform(get("/objects").with(testUser()).with(csrf())).andExpect(status().isOk()).andExpect(view().name("objects.html"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user