Skip to content

Commit 44f61fc

Browse files
Merge remote-tracking branch 'origin/master'
2 parents 4777c93 + 891f0ba commit 44f61fc

26 files changed

Lines changed: 896 additions & 11 deletions

File tree

‎jee7/pom.xml‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,16 @@
9898
<artifactId>shrinkwrap-resolver-impl-maven-archive</artifactId>
9999
<scope>test</scope>
100100
</dependency>
101-
101+
<dependency>
102+
<groupId>org.apache.httpcomponents</groupId>
103+
<artifactId>httpclient</artifactId>
104+
<version>4.5</version>
105+
</dependency>
106+
<dependency>
107+
<groupId>commons-io</groupId>
108+
<artifactId>commons-io</artifactId>
109+
<version>2.4</version>
110+
</dependency>
102111
<dependency>
103112
<groupId>com.sun.faces</groupId>
104113
<artifactId>jsf-api</artifactId>
@@ -378,5 +387,21 @@
378387
</dependency>
379388
</dependencies>
380389
</profile>
390+
<profile>
391+
<id>webdriver-chrome</id>
392+
<activation>
393+
<activeByDefault>true</activeByDefault>
394+
</activation>
395+
<properties>
396+
<browser>chrome</browser>
397+
</properties>
398+
</profile>
399+
400+
<profile>
401+
<id>webdriver-firefox</id>
402+
<properties>
403+
<browser>firefox</browser>
404+
</properties>
405+
</profile>
381406
</profiles>
382407
</project>

‎jee7/src/main/webapp/ConvListVal.xhtml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</h:head>
99
<h:body>
1010
<h1>Testing converters</h1>
11-
<h:form id="myform">
11+
<h:form id="myForm">
1212
<h:outputLabel value="Age:"/>
1313
<h:inputText id="age" value="#{convListVal.age}">
1414
<f:converter converterId="javax.faces.Integer" />
@@ -19,13 +19,13 @@
1919
<h:inputText id="average" value="#{convListVal.average}">
2020
<f:converter converterId="javax.faces.Double" />
2121
</h:inputText>
22-
<h:message for="average" />
22+
<h:message id = "averageError" for="average" />
2323
<br/>
2424
<h:outputLabel value="Date:"/>
25-
<h:inputText id="MyDate" value="#{convListVal.myDate}">
25+
<h:inputText id="myDate" value="#{convListVal.myDate}">
2626
<f:convertDateTime pattern="dd/MM/yyyy" />
2727
</h:inputText>
28-
<h:message for="MyDate" />
28+
<h:message id="myDateError" for="myDate" />
2929
<br/>
3030
<h:outputText value="#{convListVal.myDate}">
3131
<f:convertDateTime dateStyle="full" locale="en"/>
@@ -41,7 +41,7 @@
4141
<h:inputText id="surname" value="#{convListVal.surname}">
4242
<f:validateLength minimum="5" maximum="10"/>
4343
</h:inputText>
44-
<h:message for="surname" errorStyle="color:red" />
44+
<h:message id="surnameError" for="surname" errorStyle="color:red" />
4545
</h:panelGroup>
4646
<br/>
4747
<h:commandButton id="send" value="submit" type="submit" />
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<faces-config
3+
xmlns="http://java.sun.com/xml/ns/javaee"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
6+
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
7+
version="2.0">
8+
<managed-bean>
9+
<managed-bean-name>convListVal</managed-bean-name>
10+
<managed-bean-class>com.baeldung.convListVal.ConvListVal</managed-bean-class>
11+
<managed-bean-scope>session</managed-bean-scope>
12+
</managed-bean>
13+
</faces-config>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
3+
<!-- The bare minimum needed for JSF 2.2 is a servlet 2.5 or later
4+
declaration (this uses 3.0) and the mapping for the FacesServlet.
5+
Setting PROJECT_STAGE to Development is highly recommended
6+
during initial development so that you get more helpful
7+
error messages. Whether you want server-side state saving
8+
(default) or client-side is a more complicated question:
9+
client-side uses more bandwidth but fewer server resources.
10+
Client-side also helps to avoid the dreaded view expired exceptions.
11+
12+
From JSF 2 and PrimeFaces tutorial
13+
at http://www.coreservlets.com/JSF-Tutorial/jsf2/
14+
-->
15+
<servlet>
16+
<servlet-name>Faces Servlet</servlet-name>
17+
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
18+
</servlet>
19+
<servlet-mapping>
20+
<servlet-name>Faces Servlet</servlet-name>
21+
<url-pattern>*.jsf</url-pattern>
22+
</servlet-mapping>
23+
<context-param>
24+
<param-name>javax.faces.PROJECT_STAGE</param-name>
25+
<param-value>Development</param-value>
26+
</context-param>
27+
<context-param>
28+
<description>State saving method: 'client' or 'server' (default). See JSF Specification section 2.5.2</description>
29+
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
30+
<param-value>client</param-value>
31+
</context-param>
32+
<!-- If you go to http://host/project/ (with no file name), it will
33+
try index.jsf first, welcome.jsf next, and so forth.
34+
-->
35+
<welcome-file-list>
36+
<welcome-file>index.jsf</welcome-file>
37+
<welcome-file>welcome.jsf</welcome-file>
38+
<welcome-file>index.html</welcome-file>
39+
<welcome-file>index.jsp</welcome-file>
40+
</welcome-file-list>
41+
</web-app>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package com.baeldung.convListVal;
2+
3+
import static org.jboss.arquillian.graphene.Graphene.guardHttp;
4+
5+
import java.io.File;
6+
import java.net.URL;
7+
8+
import org.jboss.arquillian.container.test.api.Deployment;
9+
import org.jboss.arquillian.container.test.api.RunAsClient;
10+
import org.jboss.arquillian.drone.api.annotation.Drone;
11+
import org.jboss.arquillian.junit.Arquillian;
12+
import org.jboss.arquillian.test.api.ArquillianResource;
13+
import org.jboss.shrinkwrap.api.ShrinkWrap;
14+
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
15+
import org.jboss.shrinkwrap.api.spec.WebArchive;
16+
import org.junit.Assert;
17+
import org.junit.Test;
18+
import org.junit.runner.RunWith;
19+
import org.openqa.selenium.By;
20+
import org.openqa.selenium.WebDriver;
21+
import org.openqa.selenium.WebElement;
22+
import org.openqa.selenium.support.FindBy;
23+
24+
@RunWith(Arquillian.class)
25+
public class ConvListValTest {
26+
27+
@ArquillianResource
28+
private URL deploymentUrl;
29+
30+
private static final String WEBAPP_SRC = "src/main/webapp";
31+
32+
@Deployment(testable = false)
33+
public static WebArchive createDeployment() {
34+
return ( ShrinkWrap.create(
35+
WebArchive.class, "jee7.war").
36+
addClasses(ConvListVal.class, MyListener.class)).
37+
addAsWebResource(new File(WEBAPP_SRC, "ConvListVal.xhtml")).
38+
addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
39+
}
40+
41+
@Drone
42+
WebDriver browser;
43+
44+
@ArquillianResource
45+
URL contextPath;
46+
47+
@FindBy(id="myForm:age")
48+
private WebElement ageInput;
49+
50+
@FindBy(id="myForm:average")
51+
private WebElement averageInput;
52+
53+
@FindBy(id="myForm:send")
54+
private WebElement sendButton;
55+
56+
@Test
57+
@RunAsClient
58+
public void givenAge_whenAgeInvalid_thenErrorMessage() throws Exception {
59+
browser.get(deploymentUrl.toExternalForm() + "ConvListVal.jsf");
60+
ageInput.sendKeys("stringage");
61+
guardHttp(sendButton).click();
62+
Assert.assertTrue("Show Age error message", browser.findElements(By.id("myForm:ageError")).size() > 0);
63+
}
64+
65+
@Test
66+
@RunAsClient
67+
public void givenAverage_whenAverageInvalid_thenErrorMessage() throws Exception {
68+
browser.get(deploymentUrl.toExternalForm() + "ConvListVal.jsf");
69+
averageInput.sendKeys("stringaverage");
70+
guardHttp(sendButton).click();
71+
Assert.assertTrue("Show Average error message", browser.findElements(By.id("myForm:averageError")).size() > 0);
72+
}
73+
74+
@Test
75+
@RunAsClient
76+
public void givenDate_whenDateInvalid_thenErrorMessage() throws Exception {
77+
browser.get(deploymentUrl.toExternalForm() + "ConvListVal.jsf");
78+
averageInput.sendKeys("123");
79+
guardHttp(sendButton).click();
80+
Assert.assertTrue("Show Date error message", browser.findElements(By.id("myForm:myDateError")).size() > 0);
81+
}
82+
83+
@Test
84+
@RunAsClient
85+
public void givenSurname_whenSurnameMinLenghtInvalid_thenErrorMessage() throws Exception {
86+
browser.get(deploymentUrl.toExternalForm() + "ConvListVal.jsf");
87+
averageInput.sendKeys("aaa");
88+
guardHttp(sendButton).click();
89+
Assert.assertTrue("Show Surname error message", browser.findElements(By.id("myForm:surnameError")).size() > 0);
90+
}
91+
92+
@Test
93+
@RunAsClient
94+
public void givenSurname_whenSurnameMaxLenghtInvalid_thenErrorMessage() throws Exception {
95+
browser.get(deploymentUrl.toExternalForm() + "ConvListVal.jsf");
96+
averageInput.sendKeys("aaaaabbbbbc");
97+
guardHttp(sendButton).click();
98+
Assert.assertTrue("Show Surname error message", browser.findElements(By.id("myForm:surnameError")).size() > 0);
99+
}
100+
101+
}

‎libraries/src/test/java/com/baeldung/flink/WordCountIntegrationTest.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
public class WordCountIntegrationTest {
25-
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
25+
private final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
2626

2727
@Test
2828
public void givenDataSet_whenExecuteWordCount_thenReturnWordCount() throws Exception {
@@ -65,8 +65,8 @@ public void givenDataSetOfComplexObjects_whenMapToGetOneField_thenReturnedListHa
6565
List<Integer> ages = personDataSource.map(p -> p.age).collect();
6666

6767
//then
68-
assertThat(ages.size()).isEqualTo(2);
69-
assertThat(ages.containsAll(Arrays.asList(23, 75))).isTrue();
68+
assertThat(ages).hasSize(2);
69+
assertThat(ages).contains(23, 75);
7070

7171
}
7272

@@ -110,8 +110,8 @@ public void giveTwoDataSets_whenJoinUsingId_thenProduceJoinedData() throws Excep
110110
.collect();
111111

112112
//then
113-
assertThat(joined.size()).isEqualTo(1);
114-
assertThat(joined.contains(new Tuple2<>(firstTransaction, address)));
113+
assertThat(joined).hasSize(1);
114+
assertThat(joined).contains(new Tuple2<>(firstTransaction, address));
115115

116116
}
117117

‎mybatis/pom.xml‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.baeldung</groupId>
8+
<artifactId>mybatis</artifactId>
9+
<version>1.0.0-SNAPSHOT</version>
10+
<properties>
11+
<junit.version>4.12</junit.version>
12+
<derby.version>10.13.1.1</derby.version>
13+
<mybatis.version>3.2.2</mybatis.version>
14+
</properties>
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.apache.derby</groupId>
18+
<artifactId>derby</artifactId>
19+
<version>${derby.version}</version>
20+
</dependency>
21+
<dependency>
22+
<groupId>org.mybatis</groupId>
23+
<artifactId>mybatis</artifactId>
24+
<version>${mybatis.version}</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>junit</groupId>
28+
<artifactId>junit</artifactId>
29+
<version>${junit.version}</version>
30+
<scope>test</scope>
31+
</dependency>
32+
</dependencies>
33+
34+
</project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.baeldung.mybatis.mapper;
2+
3+
import com.baeldung.mybatis.model.Address;
4+
import com.baeldung.mybatis.model.Person;
5+
import org.apache.ibatis.annotations.*;
6+
7+
8+
public interface AddressMapper {
9+
10+
@Insert("Insert into address (streetAddress,personId) values(#{streetAddress},#{personId})")
11+
@Options(useGeneratedKeys = true,flushCache=true )
12+
public Integer saveAddress(Address address);
13+
14+
@Select("SELECT addressId, streetAddress FROM Address WHERE addressId = #{addressId}")
15+
@Results(value = {
16+
@Result(property = "addressId", column = "addressId"),
17+
@Result(property = "streetAddress", column = "streetAddress"),
18+
@Result(property = "person", column = "personId",javaType =Person.class,one=@One(select = "getPerson"))
19+
})
20+
Address getAddresses(Integer addressID);
21+
22+
@Select("SELECT personId FROM address WHERE addressId = #{addressId})")
23+
Person getPerson(Integer personId);
24+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.baeldung.mybatis.mapper;
2+
3+
import com.baeldung.mybatis.model.Address;
4+
import com.baeldung.mybatis.model.Person;
5+
import com.baeldung.mybatis.utils.MyBatisUtil;
6+
import org.apache.ibatis.annotations.*;
7+
import org.apache.ibatis.mapping.StatementType;
8+
9+
import java.util.List;
10+
import java.util.Map;
11+
12+
13+
public interface PersonMapper {
14+
15+
@Insert("Insert into person(name) values (#{name})")
16+
public Integer save(Person person);
17+
18+
@Update("Update Person set name= #{name} where personId=#{personId}")
19+
public void updatePerson(Person person);
20+
21+
@Delete("Delete from Person where personId=#{personId}")
22+
public void deletePersonById(Integer personId);
23+
24+
@Select("SELECT person.personId, person.name FROM person WHERE person.personId = #{personId}")
25+
Person getPerson(Integer personId);
26+
27+
@Select("Select personId,name from Person where personId=#{personId}")
28+
@Results(value ={
29+
@Result(property = "personId", column = "personId"),
30+
@Result(property="name", column = "name"),
31+
@Result(property = "addresses",javaType = List.class,column = "personId",
32+
many=@Many(select = "getAddresses"))
33+
34+
})
35+
public Person getPersonById(Integer personId);
36+
37+
@Select("select addressId,streetAddress,personId from address where personId=#{personId}")
38+
public Address getAddresses(Integer personId);
39+
40+
@Select("select * from Person ")
41+
@MapKey("personId")
42+
Map<Integer,Person> getAllPerson();
43+
44+
@SelectProvider(type=MyBatisUtil.class,method="getPersonByName")
45+
public Person getPersonByName(String name);
46+
47+
48+
@Select(value= "{ CALL getPersonByProc( #{personId, mode=IN, jdbcType=INTEGER})}")
49+
@Options(statementType = StatementType.CALLABLE)
50+
public Person getPersonByProc(Integer personId);
51+
52+
}

0 commit comments

Comments
 (0)