Merge remote-tracking branch 'origin/pr/470' into pr/470-alexB-logging

Conflicts:
	log4j/pom.xml
	log4j/src/main/java/com/baeldung/log4j2/Log4j2Example.java
	log4j/src/main/java/com/baeldung/logback/LogbackExample.java
	log4j/src/main/resources/log4j.xml
	log4j/src/main/resources/log4j2.xml
	log4j/src/main/resources/logback.xml
	pom.xml
This commit is contained in:
Slavisa Baeldung 2016-07-08 09:51:18 +02:00
commit 57ebe60697
76 changed files with 1027 additions and 276 deletions

1
.gitignore vendored
View File

@ -27,4 +27,3 @@ target/
spring-openid/src/main/resources/application.properties
.recommenders/

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

View File

@ -1 +0,0 @@
<mxfile userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36" version="5.5.1.6" editor="www.draw.io" type="device"><diagram>7Vjvb+I4EP1rkO4+7KkhhW0/8qt3J3V1Velq7z5VbmKIb50M55hS9q/fGXtMEgLXrprthwqEEH6ZOJ5573nAvXiSP/1uxCr7BKnUvf5Z+tSLp71+/6If4ycBWw8MBpceWBqVeiiqgLn6Jhk8Y3StUlk2Ai2AtmrVBBMoCpnYBiaMgU0zbAG6+dSVWIYnVsA8EbqNflGpzUJawwr/Q6plFp4cDTm/B5F8XRpYF/y8Xj9euJe/nIswFydaZiKFTQ2KZ1hWA4Az07f8aSI1lTaUzd93deTqbt1GFry2Z24I67DbkLtMsRQ8BGMzWEIh9KxCxy4/STOc4SizucavEX7Fh5rt34y7wT80+G3ghumImKFZV7K4y1Th0SuFK/K3/Cut3bIaxNoCQtUKrgFW/By/Zlro0bQZKmFtEo7CsROSMEvJUR93JUclS8glLhlDjNTCqsfm7II1tdzF8a2YlqC7QsAKVGHL2sw3BGAAuyO6HPgZ2Rz9yC0jcIRf/IxhVFtaBTkeD3PKeT4KveYMrpTU6QgLulFGplOZQ4v1cqNyLQqit0boAgobtEBjodUSaZsmWGdpEHiUxir0zYgvWOJonGRKp9diC2uqc2nRFGE0zsCobzitCM/Ay8Yy6WiwesSc7mRtGFlizE2gmO700LUoCaCYBLQWq1I97BacI9mqGIO1kHNQyJR0NwENmAYWINg0iIsSk4GwI/JqC4dvCO5mgmNmZFNtJfGAQ7LaNnJ5cVxpNXX8L/m88dbI/0AbIAlgKtF3qSwSXNYIwZF5UNYIs61d2JcF1sCRVkmitAa+ylC4ApxkFrVaMhSkouWCZjgslHIlElUsr13M9LxCbrkqBG0yZeUccVrTBvsNbQs430K73SRTKa7dbUtWWOG5J6LZh5jHYIxvLPiEtqIB5jXBMVIYxvimcGMnUGB+guwaTyUKayNJXC/ThGO5rYngcu4dz4kgxL1GBOctEbSI1Wrf657Y0O6c+3+Y1Ry5cC2CabxzW/YHN32D6rhNNUH7FGrxIPUNlMoqoPmNj92j9g3YG7zQwh04mJtDgzxMYd/D958+z+/ux7P70ee7v778eTub3k/AGPw1pNnfj4BTngz9syQxZPrfwtA8RU0TL9m8Tz29w54+PG829egje73GfxQ00ejqjL2Gf/8Dcb+ru93Re31uDZrs5PZXuN157Efa90G2u3A7C+vUvjtj70D7PsheB+2bDwJa7duC9+gvv54c+yacH+jPP82xEa+uxvqt/G+N/7bdOcAzDLued7SOVCo6DKG+uNeyX0I1e5h47aALRhfNLrj7q1ur8sEid9AEo/bBRjjleSfVHfJJ0O43xiWPa9UNley8uu2Tg3dW3eiCBRSqG/Nfre6ri8PqDNcf4VXn5PHsOw==</diagram></mxfile>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

View File

@ -1 +0,0 @@
<mxfile userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36" version="5.5.1.6" editor="www.draw.io" type="device"><diagram>7Vhdb9s4EPw1fuwhtqK0eYw/ctdDeijqHO7uyWAkWmJLcX0UFcf99d2llpZkKUiKOHkobBiGOVx+zcxybY2iWfHwuxWb/BOkUo8mZ+nDKJqPJpMPkwg/CdjVQBxf1kBmVVpD4wZYqu+SwTNGK5XKshPoALRTmy6YgDEycR1MWAvbbtgadHfVjcjCig2wTITuo/+o1OXhWBcN/odUWR5WHl/w+e5E8i2zUBlebzSJ1v5VdxcizMUHLXORwrYFRQuk1QLgzPSteJhJTdQG2upx14/07vdtpeG9PTEg7MPtwtllilRwE6zLIQMj9KJBp/58kmY4w1buCo1fx/gVF7W7fxn3jf+o8Vvsm+kVKUOzbqS5zZWp0WuFO6qHfJXO7dgNonKAULODG4ANr1PvmTb66LEZKqGyCUdh2xtJ2Exy1Ps95ehkCYXELWOIlVo4dd+dXbCnsn1cwyt+YWqHaeal74WueNJrJXX60XxF985lAT0Vyq0qtDBEd4vgNRgXtKG20CpDGucJnltaBO6ldQp9fMUdjjibJrnS6Y3YQUXnLh2aNLSmOVj1HacVYQ3sto5FQMO3I5Y0krWyssSYz4FyGllDN6IkgGIS0FpsSnW333CB5CszBeeg4KBwUvLBDDTgMZCAkDZBbDqY5OvlMbn7QoYB7HK+jUJz26R2FDOWt9P6gsGXSM83YUv6d9TrlR/PJaZCKk2CO7tC+MreKWeF3bU6Dp2BNHjdGleUzsI3Gbgz4F2zbtHJUHCLlmuaYdgr5UYkymQ3PmZ+3iBfmBiCtrlycok47WmLJYAyFedba5/guUpx7/6mcMKJWn7SegPKOE9mPMU30juj2yHGc82wjSqGNr4p3LoZGDyfwHE4TKK3tpL89Txb+Lzr24J9EK7zp3wQ4l5ig/OeDXrCanWY7rWwoQL5C+CnVS1QC39rs4y3/hZ956fvSB31pSboUEIt7qT+DKVyCmh+W8ceSPsG6sXM4FPqfXi5ePGAeHiEszVd4k2qrj79vbxdTRerj3/9uZjdLuarZZUksizXldac4feAk55S+rVMEW7st0hpnqLliudc36fCfsTCHr/vVvaIk70l/76It+W/PEJh978de4XdX491qi+dxRw7JfsLkt2n2M/U70G1j5HsbKxT/T6aegP1e1C9I9Rv/nPeq98OOEdP+foWig8U51fL1zHvrqX5F/l/pbCUPUNhX/Ae5ZGooscTVBQP6vVzpOYMJl2PUALPw88bJvmS/3C2SB7k+AgVcNx/rBEeu/wi5EYHvy8u+hUnEHl0cvsPDn4xcuMD58avRi42m0eqvq/12Dpa/AA=</diagram></mxfile>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

View File

@ -1 +0,0 @@
<mxfile userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36" version="5.5.1.6" editor="www.draw.io" type="device"><diagram>7VhZbxs3EP41AtqHFDqydvOoy20KJwgiF2meDHp3pGXC5ahcyrLy6zPkDrWnYQVe5yGQIAjit8Njvm8OiYPJPHv4y4ht+g4TUIPxMHkYTBaD8fjP8YQ+HXAogCh6UwAbI5MCGpXASn4DBoeM7mQCec3QIiort3UwRq0htjVMGIP7utkaVX3XrdiEHUtgFQvVRj/JxKbBrYsS/xvkJg07jy7YvzsRf90Y3GnebzCerP2reJyJsBY7mqciwX0FmiyJVoNIK7tv2cMclKM20FbMu3rk6fHcBjSf7YkJ4Rz2EHyHhKjgIRqb4ga1UMsSnXn/wK0wpFFqM0VfR/SVNjWH/xj3g89u8Efkh8nUKeNW3YK+SaUu0CtJJyqmfAFrDxwNYmeRoPIE14hb3qc4szvoo24zlOPOxGxFYx9IwmyArS6PlFMkA2ZARyYTA0pYeV9fXXBMbY52Ja/0hantppm3vhdqx4teSVDJ7PBeZPBWf6EYXkCGLS3yvcyU0I70Cs1r1DYo5MZCyQ2RuYjJezAE3IOxkqJ5yg+sY24Wp1Il1+KAO+d9bilUw2iWopHfaFkR9qDHxrIUFPZVi5WbyYoZyMnmQyDezSyga5E7wNnEqJTY5vLueOCMJJB6htZixkbBUxcNc1RIbhABIXmC5M4x4CLzmOhtOUNVKiZwSQqRvy/ze3LJOqWV3H7Dds+Rn6thRf5XNNSkfbIASoYEdEzHmhI4NXfSGmEOlQfNqCAKvGZlROTW4FcIvGn0EbOuUMlQiBQFa7dCd5zkWxFLvbn2NovXJfKRWXHQPpUWVoS7M+2pCbhcpfXWyqd4KhM6u68VVlhRSO903qLU1lMZzehN5M5dfYjIrzmNScEwprczN3aOmvwTNI+mAcXVHlxsnRYSXtF2SHAQhIL+VBAEu+cEwetWELSEVbKZ6oWwoQf55P9hVTPSwtdtlvHG19FXfvma1JO21A5qSqjEHagPmEsr0a1vCtuGtD9BvYgZfEo9TvzniBd1iEcuNHP49t2/q5vb2fL27ft/lvOb5eJ2jsZQdVec3itriN1zRr9YTFycWNb7yGheohIUn8FONdoUzCl1/Nzde+zuUWjUob+P2rX9+LO71uC5Oz8nEvzvyFaD94XynPc95b2X80c6eafafeQ995NzJ+9NvY5O3qleD52c/6i3OrnFIkd/+/2csT9F845O/WIZO+LTVVT/CP/vJHWzExT2Pe9RHh1V7rLC9cVGyz5Fas5hp2sPXXDU7IIRp0yF5UB8jeQe/uWO2rcc4RbmF2E3umywe9FRt16K3fYlwi/G7njYYHfY0dP7YZeG5R2rf1a5x54svwM=</diagram></mxfile>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 43 KiB

View File

@ -1 +1 @@
<mxfile userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36" version="5.5.1.6" editor="www.draw.io" type="device"><diagram>7Vptb+I4EP41le4+bEUIUPZjeenenrqn3tLT3X6qTGIS7zox5zil7K/fcTLTvHbhFOAkBEKAx87EM88zL7G4cqfRywfN1uEn5XN51e/5L1fu7KrfH/dd+LSCbS4Y9VAQaOHnIqcQLMR3jsIeSlPh86Sy0CgljVhXhZ6KY+6ZioxprTbVZSslq3dds4DuWAgWHpNN6d/CNyGZNSrkv3ERhHRnZ/Q+n1ky71ugVRrj/a767ip75dMRI11oaBIyX21KIncObtVKgWb7K3qZcmldS27Lr7t7Y/Z135rHuLcdF9A+zJZs5z64AodKm1AFKmZyXkgnmX3caujBKDSRhJ8O/ISb6u0/KM8GX+zgepgN/VuLjNW65vFjKOJceidgR/klX7kxW2QDS40CUbGDe6XWeJ+mlWh4olLtoR0wznjDdMBx1U0ushaWLkPPfOAq4rBlWKC5ZEY8V8nAkFPB67rCr/ADXdvuZtzLM5MpKr0TXPp/pkyKleD6Y/wVaDzjkWrAkWxEJFls/V7y9ErFhkCyY9ATgD9nHniEaxA8c20EEPoWJ4x13sQLhfTv2Val1iOJAbbSaBIqLb6DWkb3gGltEA1gfnnFwl6JoGmewJoHAsNemYvuWWIFdo2npGTrRCxfNxwBLCKeKGNUhIvIUkuIqZIKzAAHUPz8BHVrK8fU8waiNIt0x7REw00R4+4NysJKfKOwCwcwA5Y48M5mSL5iqQToISZ8Hnuws1sQ3+qlMJrpbWmiP5IWJ188w8/A/gQFIxZZYONlkn2xiPs1XdUVP1EMBpR0N4gILs5oUpAwMVp94wRVrDKSrkrooYjIKfnKaminZrJmnoiD+2zNbFBIPiMOVrQJheELkNs9baD02AwB+lYySyyh8MGiLEMZZljONkuttRKxybAbTuANaE5tVhqCXVMYA2loDG+7XJupisE+BtfBZRyovOGWzi0spODezUKkHZWRXbQbDLqzDlWUWNcAVop6dsmBpcqX5Zv/jGoEWGTVAmF8zLL3u0x9BWq3CbUV1SGUbMnlg0qEEcrq1/naGrQnQI+Q2oXeuDt4DhLlDKvzsFmdHYTi9OUZN1MJEjCjB6VZltLp06e/Fo9Pk/nTxz9+n08f57OnRep5PElWqZTbX37NU/ezArWX5Lln+HUt4WPs6XZFo4vltwtNMBpLNGmtppcG7ngN3IgenKiDQ1hL8DujFvjfH6CBQ6bVGrisLuWRvzAaQu4S+/vGPsVTl8apFW1a1wVtLN+Xxulg6A3Rg7vQO0DjhKcxjYJuVB6jVKsvEXtkzAnfU0Ssg23cobvl6xuoMqWO2bnuuWMSPHAtYKe2ZGNf/dpIL6WyNfaYXbRDh6OlNhq5f/oumjZT7o9iZUKuL23Siduk4bjaJrmDZhz2e20nXSTsRITmceelU+r2lLQ/A95ulVoBP0jibR5tXnqljvi1NEut+B3ilKntjPDSLf0fUdvSLh0vapvPs5/5v6mAorYHxFnpe9OR1le2ubHlsVa598Eaw9gCe4BiOKgXw2Zotbakh6iEzafIM/XxsObj8Qmd3Hzao1b5TLzr0vEVpYnmoSc58tDOJR3n69xhzbkt6eFozm0+MZ0bc2u516FgPYV3m48h50ZdSqlE3eHRvAvD4l9J2Vzpn1/u/Ac=</diagram></mxfile>
<mxfile userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" version="5.5.2.3" editor="www.draw.io" type="device"><diagram>7VptbyI3EP41SO2Hi1iWl+RjAuSuUpqml6jX+xQZ1uz6zrumXhPC/fqb8Y7ZV0IaXqpGICTWw3hsz/N4Zmxo+cP4+aNm8+h3FXDZ6rSD55Y/anU6XrvvwwdKVpmk3yZBqEVASrngXvzgridJFyLgaUnRKCWNmJeFU5UkfGpKMqa1WpbVZkqWR52z0I2YC+6nTNalX0Rgokx63unn8k9chJEb2etfZN9M2PR7qNUiofFaHX9mX9nXMXO2aKFpxAK1LIj8MfhVKwWW8Sl+HnKJvnVuy/pdb/h2PW/NE5rblg5uHmbl1s4DcAU1lTaRClXC5DiXXtn1cbTQhlZkYgmPHjzCoHr1N8lt4ys2znq2GVwiMmh1zpOHSCSZ9FrAjLIu37gxK2IDWxgFonwGN0rNaZz6KmnhqVroKa0D2pY3TIectAaZCFdY6Eae+chVzGHKoKC5ZEY8lcnAiFPhWi/3KzyQa5vdTHN5YnJBRq8Fl8GfCybFTHD9W/INaDzisarBkS5FLFmCfi94eqYS40DCNtgJwZ+jKXiEaxA8cW0EEPqSvjDovKtpJGRww1ZqgR5JDbDVta4ipcUPMMvcGPC1NoQGML+ocY89CTTNU9C5c2Bgz0x0w1IUoM5UScnmqZisJxwDLCK5UsaomJTcSpEQQyUVLAMc4PbPC6jjWrmLPc2IUhwaEAOW+abuuq0YFTd0h+LVLqCTiQLoH1qdPosRiGSS4ge0Jfo+nbMEnkN8Bj7IYMRhjwQ8ma5gQZkODFdUa/mXYPxST4TRTK/yDk4/EE9O9y3jwtQ3j1u29sIkoHNhHjVyA2yWejmxU6PVd+7gT5Ql/qzACBI5wks+QwvNdId5T0US3lidUTeXfCaoUbSMhOH3IMc5LSGfYdQBezNpg1UkAliRjXqGGZYxGOk6VyIxlh69K3gDi4YY6XqwriG0ATfXhjeqazNUCayPQT/oxmF7LDlukQZmu4Dxama71LSN2d3u7sQmEwVi14CVohqxMmBdNrUx7F+jGgMWNgMRjA82I3yw5ktQ+3WoUVSFULIJl3cqFUYotK8z3Qq0R0BvQEhtQ+98d/B6DeA1xoMQEmByCVl4KTTPU9UfiU1djw+fxrePo/Hd+HY0vh1+9R7/AoVgU9BosP/Lry9GtieVWyuFkD1MtvOmyQJjqhPb0PMU9Y4U9Qa0IbZGvT2kc48i7P+rVObPwthhzroX1MSBvLP2gJp3XAtwBlaN1vKrimuKIsXi2iP09lddU9c7pByoOEacE8Au8/nUdiayeVKvHF9wKcPhnRoxeeM4nXZlnHY21fVRaot+t505KadXNoOcbGufvIp/RL9C4G6su07HhwMcH+jbfq8MsTs9F8KP128IPxcVhr4l/NDJpXyaaNsKJstL90ZDjD8lm9cmG7efdimxG9F2erugTXntVGLvDb0eeXAbensosekusFpiwxVmtkehmDzt2GNg7vA9xo71qCTad3l4NvBwX61LRKjc/HMnqNZuhcpxIhXm2EPesHruar5QBRL3j3/F6iZTrI8SZSKuT2XSscskVxfRNvT79cy5rpZL165OuBMR6pftp0ppp7i73lq7lEqNgO8l8Nbv2U+10o74NRRLjfjtoVjymm6TT9XSf7FrG8qlw+3a+nn2M/9nAbe39kpmC8Q29W10JPoKixtMj5XM/RqsaRsjsHtIht3KdZVf31qNJek+MmH9FPlOfVy5l/HPj+jk+mnPlcrvxLveBR1tXkoOh3Gus/F+ndt3t9euciI6HcO59RPTO3Nu/Qq/KcMdyLv1Y8g7827PXWu7qDs4GHehmf8nLvvtJP/joT/+CQ==</diagram></mxfile>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

View File

@ -1 +0,0 @@
<mxfile userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36" version="5.5.1.6" editor="www.draw.io" type="device"><diagram>7Vhtb+I4EP41SHcftgICtP1YoN1bqXtalZ7u7lPlJiZx1/HkHANlf/3OOGOSEPpyonfaOxUhFD8ejz3zzItDL5rljx+tKLLPkEjdG/aTx1407w2HZ8MIfwnYVsB4fF4BqVVJBQ1qYKG+SQb7jK5UIsuWoAPQThVtMAZjZOxamLAWNm2xJej2roVIw441sIiF7qK/q8RlwaxJjf8iVZqFnQcTtu9exF9TCyvD+/WG0dJ/qulcBF1saJmJBDYNKLpEt1oA1ExP+eNManJtcFu17uqJ2d25rTR8tucX4BQtWAu9YtN7w4nGpdMCH1J6uFJSJzeyhJWN5SfzgP5WYOYyhyCK6nfSbJbbBleWG5VrYXA0zVyuERzg4xKMW7AQjYVWqcHnGM8tLQJraZ1CQi54wkGBaJwpnVyLLazIutKht8NomoFV31CtCHvgtHUcW6PzlsSCViLcR9TKEmW+BJfRygq6FiUBJBOD1qIo1f3uwLmwqTJTcA5yFgqWXimtZ6ABzUAHBP6Da5rcMF1kq+TU8RBz9VFCLp3dokiY5bDhtBpxmm3qGI1GLJI14/OUBQXnRbrTXMcGPnB4HA4VVtEIlQ+U4XIpVtqhzQheIPAg1uJEwYlH9oMBzfRU1YFQOgtfZXCXAR8oy4YHGQoBouWSNBwOj7IQsTLptZeZj2rkhn1B0CZTTi4QpzNtsHwhBqhvqX0iZipJJKqcWnDCiYpxorcAZZz333iKX3TzrH8y7o3RrhmOkbgwxi+JWzcDg/YJXIfLJIbTRlJIHYiEkIcvR0KgngvOS9RHXLKOYX50oEjsEavVfoZXxIbq6XP+b7OaIxe0Q6Dxllief/DqW1RHXaoJ2qdQi3upv0CpqIIhZivZPWr/BfbOxq9j7+x48ninFnloQr/QaFko6xfGkKvQK3eff1vc3l19+nV+N69T+6efq+ReA6p9T+p/KizOX1nPx4wdExennbh4tnL/GG0cL2A/SBvvkHqgsz/Zxk/77T4+CNfBBvGDyaF6wCF1DPHcON6reTNtX6DTJ8uTaRteC15ib8SN9KhbGJ+uwZZM8N2Fh2hoBikYoS9rFD2HLySSNJDfGrSigXb7B+N+8CcNsOLRMLmgVynSWkhzmykqoIhSYvCSB+nclnNTrBxQ1d2d4Bo8wbRPdWY66PMZg3b5ftS6cWL+p/J5IqzU2L3Wbe1Hubn7YnQj/1opLCmv6H++8DzZZSgiyVlUnPbq5msaIacNdb03KEXjvVeKwaQbzIdiOVSso5zcfaXoRvd/2rtR6NTh3te9tQdHvrlzu7f2/5lzJ6fszRC6I1bx9t7FYf2fjJ9r/O8VXX4H</diagram></mxfile>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

View File

@ -1 +0,0 @@
<mxfile userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36" version="5.5.1.6" editor="www.draw.io" type="device"><diagram>3Vhbb+I6EP41SN0HECGQbh8boNuutkerltXZ84QMcRL3OHFqHAr99R0749y4qCpdqV0eQvx5PJ755mJDxx0nm2+SZPGtCCjvDPrBpuNOOoPB14ELTw1sC2A0uiiASLKggJwKuGfPFME+ojkL6KohqITgimVNcCnSlC5VAyNSiqemWCh4c9eMRHbHCrhfEr6L/ssCFVu3vAq/piyK7c6Oh/4tyPL/SIo8xf06Azc0n2I6IVYXOrqKSSCeapA7BVqlEKBZvyWbMeWaWktbse7qwGxpt6Qp2nZ8ATq0UlvrOg2ACRwKqWIRiZTwaYX6xj2qFfRhFKuEw6sDr7Cn3P5G3Az+04PeyAyDSx0YrTWj6SxmaYFeMTCoWPJAldpiMpBcCYAqC34IkeE+hc3a0INeI7QSuVyiFKakIjKiKDUqGYdEpiKhYDKISMqJYuumdoIpFZVyFa3wgsweCAtGe014jlrv6GPOJOR4m39FN2BdnVaQYs9kYQQ0TZlgqTLWjPzOaAII4SwCOidL8J9KANZUKgbpfIkTCQsCEztOFpT7ZZKOBRcgD/vaNLXsag0Uy7lZbGhJlcN13k0+7TKKivo9DAK2he6wGL6acNT8UzNQqe2CeE2r01IgwnAFEW/HqzTvVSFEw2sR7Aw8riOVNeLnPea6dv0E0kyn+CXM9rMNPA210AE03lU6mfXcsDanQ9/FWOo5DGepE94i/DY7LyxwS6FKgjtapPtN+gBhYiKd0ERYWfCvFC/Xa90NBKTAnSYWg1QfMrDpH3B8yKw3EcJpCFIlI23dXX2Y0JDkXEHDAM1a8oGsSY+JnkHe2QMLaIwkECw/Xaz0l5VZZSTd6yhnKe3GeDpoM52ezpXWVjVn5re/7mdzfzq/+ef7dDybTuZjISWEkEPOl14V+zXtPNGGsy/F5FpAlh/faR+tO8CJ5hwh+6j/BQYlPqk4PavnxlvdbHXmdlM1NVz23iKBfQFSITfnXGhONj8UqcJDzYEOZsZXJGEQXXdyTfmaaq3Nln+wB++ccQd7rWPbM3ZFF4dP1X3G7SNmQ2PWnSN4yoFnDtaP2i0PtI2d9vhhm+En7N+vNflTl5xna8xeRIa7Ned4e2ru4h1K7nyn5Owd+MS7JVzEMXv0ghb3+wMErXXJ0mhmbuxwyXsXdodavsbuBTaZGrm25dW5tdgp3OKPu7+XW8/emW3men+MXBhWP2+Li3j1F4I7fQE=</diagram></mxfile>

View File

@ -65,7 +65,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Demo.java</include>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>

View File

@ -8,20 +8,24 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.baeldung.configuration.ApplicationContextTestAutowiredName;
import com.baeldung.dependency.ArbitraryDependency;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={
"/applicationContextTest-@Autowired-Name.xml"})
public class FieldAutowiredNameDemo {
@ContextConfiguration(
loader=AnnotationConfigContextLoader.class,
classes=ApplicationContextTestAutowiredName.class)
public class FieldAutowiredNameTest {
@Autowired
private ArbitraryDependency autowiredFieldDependency;
@Test
public void autowiredFieldDependency_MUST_BE_AUTOWIRED_Correctly() {
public void givenAutowiredAnnotation_WhenOnField_ThenDependencyValid(){
assertNotNull(autowiredFieldDependency);
assertEquals("Arbitrary Dependency", autowiredFieldDependency.toString());
assertEquals("Arbitrary Dependency",
autowiredFieldDependency.toString());
}
}

View File

@ -8,19 +8,22 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.baeldung.configuration.ApplicationContextTestAutowiredType;
import com.baeldung.dependency.ArbitraryDependency;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={
"/applicationContextTest-@Autowired-Type.xml"})
public class FieldAutowiredDemo {
@ContextConfiguration(
loader=AnnotationConfigContextLoader.class,
classes=ApplicationContextTestAutowiredType.class)
public class FieldAutowiredTest {
@Autowired
private ArbitraryDependency fieldDependency;
@Test
public void fieldDependency_MUST_BE_AUTOWIRED_Correctly() {
public void givenAutowired_WhenSetOnField_ThenDependencyResolved() {
assertNotNull(fieldDependency);
assertEquals("Arbitrary Dependency", fieldDependency.toString());
}

View File

@ -9,13 +9,16 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.baeldung.configuration.ApplicationContextTestAutowiredQualifier;
import com.baeldung.dependency.ArbitraryDependency;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={
"/applicationContextTest-@Autowired-Qualifier.xml"})
public class FieldQualifierAutowiredDemo {
@ContextConfiguration(
loader=AnnotationConfigContextLoader.class,
classes=ApplicationContextTestAutowiredQualifier.class)
public class FieldQualifierAutowiredTest {
@Autowired
@Qualifier("autowiredFieldDependency")
@ -26,14 +29,15 @@ public class FieldQualifierAutowiredDemo {
private ArbitraryDependency fieldDependency2;
@Test
public void fieldDependency1_MUST_BE_AUTOWIRED_Correctly() {
public void givenAutowiredQualifier_WhenOnField_ThenDep1Valid(){
assertNotNull(fieldDependency1);
assertEquals("Arbitrary Dependency", fieldDependency1.toString());
}
@Test
public void fieldDependency2_MUST_BE_AUTOWIRED_Correctly() {
public void givenAutowiredQualifier_WhenOnField_ThenDep2Valid(){
assertNotNull(fieldDependency2);
assertEquals("Another Arbitrary Dependency", fieldDependency2.toString());
assertEquals("Another Arbitrary Dependency",
fieldDependency2.toString());
}
}

View File

@ -0,0 +1,9 @@
package com.baeldung.configuration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan(basePackages={"com.baeldung.dependency"})
public class ApplicationContextTestAutowiredName {
}

View File

@ -0,0 +1,25 @@
package com.baeldung.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.baeldung.dependency.AnotherArbitraryDependency;
import com.baeldung.dependency.ArbitraryDependency;
@Configuration
public class ApplicationContextTestAutowiredQualifier {
@Bean
public ArbitraryDependency autowiredFieldDependency() {
ArbitraryDependency autowiredFieldDependency = new ArbitraryDependency();
return autowiredFieldDependency;
}
@Bean
public ArbitraryDependency anotherAutowiredFieldDependency() {
ArbitraryDependency anotherAutowiredFieldDependency = new AnotherArbitraryDependency();
return anotherAutowiredFieldDependency;
}
}

View File

@ -0,0 +1,16 @@
package com.baeldung.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.baeldung.dependency.ArbitraryDependency;
@Configuration
public class ApplicationContextTestAutowiredType {
@Bean
public ArbitraryDependency autowiredFieldDependency() {
ArbitraryDependency autowiredFieldDependency = new ArbitraryDependency();
return autowiredFieldDependency;
}
}

View File

@ -0,0 +1,17 @@
package com.baeldung.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.baeldung.dependency.ArbitraryDependency;
import com.baeldung.dependency.YetAnotherArbitraryDependency;
@Configuration
public class ApplicationContextTestInjectName {
@Bean
public ArbitraryDependency yetAnotherFieldInjectDependency() {
ArbitraryDependency yetAnotherFieldInjectDependency = new YetAnotherArbitraryDependency();
return yetAnotherFieldInjectDependency;
}
}

View File

@ -0,0 +1,23 @@
package com.baeldung.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.baeldung.dependency.AnotherArbitraryDependency;
import com.baeldung.dependency.ArbitraryDependency;
@Configuration
public class ApplicationContextTestInjectQualifier {
@Bean
public ArbitraryDependency defaultFile() {
ArbitraryDependency defaultFile = new ArbitraryDependency();
return defaultFile;
}
@Bean
public ArbitraryDependency namedFile() {
ArbitraryDependency namedFile = new AnotherArbitraryDependency();
return namedFile;
}
}

View File

@ -0,0 +1,16 @@
package com.baeldung.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.baeldung.dependency.ArbitraryDependency;
@Configuration
public class ApplicationContextTestInjectType {
@Bean
public ArbitraryDependency injectDependency() {
ArbitraryDependency injectDependency = new ArbitraryDependency();
return injectDependency;
}
}

View File

@ -0,0 +1,16 @@
package com.baeldung.configuration;
import java.io.File;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ApplicationContextTestResourceNameType {
@Bean(name="namedFile")
public File namedFile() {
File namedFile = new File("namedFile.txt");
return namedFile;
}
}

View File

@ -0,0 +1,22 @@
package com.baeldung.configuration;
import java.io.File;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ApplicationContextTestResourceQualifier {
@Bean(name="defaultFile")
public File defaultFile() {
File defaultFile = new File("defaultFile.txt");
return defaultFile;
}
@Bean(name="namedFile")
public File namedFile() {
File namedFile = new File("namedFile.txt");
return namedFile;
}
}

View File

@ -1,5 +1,8 @@
package com.baeldung.dependency;
import org.springframework.stereotype.Component;
@Component
public class AnotherArbitraryDependency extends ArbitraryDependency {
private final String label = "Another Arbitrary Dependency";

View File

@ -1,5 +1,8 @@
package com.baeldung.dependency;
import org.springframework.stereotype.Component;
@Component(value="autowiredFieldDependency")
public class ArbitraryDependency {
private final String label = "Arbitrary Dependency";

View File

@ -1,5 +1,8 @@
package com.baeldung.dependency;
import org.springframework.stereotype.Component;
@Component
public class YetAnotherArbitraryDependency extends ArbitraryDependency {
private final String label = "Yet Another Arbitrary Dependency";

View File

@ -10,21 +10,25 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.baeldung.configuration.ApplicationContextTestInjectName;
import com.baeldung.dependency.ArbitraryDependency;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={
"/applicationContextTest-@Inject-Name.xml"})
public class FieldByNameInjectDemo {
@ContextConfiguration(
loader=AnnotationConfigContextLoader.class,
classes=ApplicationContextTestInjectName.class)
public class FieldByNameInjectTest {
@Inject
@Named("yetAnotherFieldInjectDependency")
private ArbitraryDependency yetAnotherFieldInjectDependency;
@Test
public void yetAnotherFieldInjectDependency_MUST_BE_INJECTED_Correctly() {
public void givenInjectQualifier_WhenSetOnField_ThenDependencyValid() {
assertNotNull(yetAnotherFieldInjectDependency);
assertEquals("Yet Another Arbitrary Dependency", yetAnotherFieldInjectDependency.toString());
assertEquals("Yet Another Arbitrary Dependency",
yetAnotherFieldInjectDependency.toString());
}
}

View File

@ -1,27 +0,0 @@
package com.baeldung.inject;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import javax.inject.Inject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.baeldung.dependency.ArbitraryDependency;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={
"/applicationContextTest-@Inject-Type.xml"})
public class FieldInjectDemo {
@Inject
private ArbitraryDependency inject1Dependency;
@Test
public void fieldDependency_MUST_BE_INJECTED_Successfully() {
assertNotNull(inject1Dependency);
assertEquals("Arbitrary Dependency", inject1Dependency.toString());
}
}

View File

@ -0,0 +1,31 @@
package com.baeldung.inject;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import javax.inject.Inject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.baeldung.configuration.ApplicationContextTestInjectType;
import com.baeldung.dependency.ArbitraryDependency;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(
loader=AnnotationConfigContextLoader.class,
classes=ApplicationContextTestInjectType.class)
public class FieldInjectTest {
@Inject
private ArbitraryDependency fieldInjectDependency;
@Test
public void givenInjectAnnotation_WhenOnField_ThenValidDependency(){
assertNotNull(fieldInjectDependency);
assertEquals("Arbitrary Dependency",
fieldInjectDependency.toString());
}
}

View File

@ -10,13 +10,15 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.baeldung.configuration.ApplicationContextTestInjectQualifier;
import com.baeldung.dependency.ArbitraryDependency;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={
"/applicationContextTest-@Inject-Qualifier.xml"})
public class FieldQualifierInjectDemo {
@ContextConfiguration(loader=AnnotationConfigContextLoader.class,
classes=ApplicationContextTestInjectQualifier.class)
public class FieldQualifierInjectTest {
@Inject
@Qualifier("defaultFile")
@ -27,14 +29,16 @@ public class FieldQualifierInjectDemo {
private ArbitraryDependency namedDependency;
@Test
public void defaultDependency_MUST_BE_INJECTED_Successfully() {
public void givenInjectQualifier_WhenOnField_ThenDefaultFileValid(){
assertNotNull(defaultDependency);
assertEquals("Arbitrary Dependency", defaultDependency.toString());
assertEquals("Arbitrary Dependency",
defaultDependency.toString());
}
@Test
public void namedDependency_MUST_BE_INJECTED_Correctly() {
public void givenInjectQualifier_WhenOnField_ThenNamedFileValid(){
assertNotNull(defaultDependency);
assertEquals("Another Arbitrary Dependency", namedDependency.toString());
assertEquals("Another Arbitrary Dependency",
namedDependency.toString());
}
}

View File

@ -1,25 +0,0 @@
package com.baeldung.resource;
import static org.junit.Assert.assertNotNull;
import java.io.File;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={
"/applicationContextTest-@Resource-NameType.xml"})
public class FieldResourceInjectionDemo {
@Resource(name="namedFile")
private File defaultFile;
@Test
public void plainResourceAnnotation_MUST_FIND_DefaultFile() {
assertNotNull(defaultFile);
}
}

View File

@ -0,0 +1,31 @@
package com.baeldung.resource;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.File;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.baeldung.configuration.ApplicationContextTestResourceNameType;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(
loader=AnnotationConfigContextLoader.class,
classes=ApplicationContextTestResourceNameType.class)
public class FieldResourceInjectionTest {
@Resource(name="namedFile")
private File defaultFile;
@Test
public void givenResourceAnnotation_WhenOnField_ThenDependencyValid(){
assertNotNull(defaultFile);
assertEquals("namedFile.txt", defaultFile.getName());
}
}

View File

@ -12,17 +12,21 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.baeldung.configuration.ApplicationContextTestResourceQualifier;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={
"/applicationContextTest-@Resource-Qualifier.xml"})
public class MethodByQualifierResourceDemo {
@ContextConfiguration(
loader=AnnotationConfigContextLoader.class,
classes=ApplicationContextTestResourceQualifier.class)
public class MethodByQualifierResourceTest {
private File arbDependency;
private File anotherArbDependency;
@Test
public void dependencies_MUST_BE_INJECTED_Correctly() {
public void givenResourceQualifier_WhenSetter_ThenValidDependencies(){
assertNotNull(arbDependency);
assertEquals("namedFile.txt", arbDependency.getName());
assertNotNull(anotherArbDependency);

View File

@ -1,5 +1,6 @@
package com.baeldung.resource;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.File;
@ -10,11 +11,15 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.baeldung.configuration.ApplicationContextTestResourceNameType;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={
"/applicationContextTest-@Resource-NameType.xml"})
public class MethodByTypeResourceDemo {
@ContextConfiguration(
loader=AnnotationConfigContextLoader.class,
classes=ApplicationContextTestResourceNameType.class)
public class MethodByTypeResourceTest {
private File defaultFile;
@ -24,7 +29,8 @@ public class MethodByTypeResourceDemo {
}
@Test
public void defaultFile_MUST_BE_INJECTED_Correctly() {
public void givenResourceAnnotation_WhenSetter_ThenValidDependency(){
assertNotNull(defaultFile);
assertEquals("namedFile.txt", defaultFile.getName());
}
}

View File

@ -1,4 +1,6 @@
package com.baeldung.resource;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.File;
@ -9,11 +11,15 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.baeldung.configuration.ApplicationContextTestResourceNameType;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={
"/applicationContextTest-@Resource-NameType.xml"})
public class MethodResourceInjectionDemo {
@ContextConfiguration(
loader=AnnotationConfigContextLoader.class,
classes=ApplicationContextTestResourceNameType.class)
public class MethodResourceInjectionTest {
private File defaultFile;
@ -23,7 +29,8 @@ public class MethodResourceInjectionDemo {
}
@Test
public void defaultFile_MUST_BE_INJECTED_Correctly() {
public void givenResourceAnnotation_WhenSetter_ThenDependencyValid(){
assertNotNull(defaultFile);
assertEquals("namedFile.txt", defaultFile.getName());
}
}

View File

@ -1,6 +1,6 @@
package com.baeldung.resource;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
@ -10,18 +10,21 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.baeldung.configuration.ApplicationContextTestResourceNameType;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={
"/applicationContextTest-@Resource-NameType.xml"})
@ContextConfiguration(loader=AnnotationConfigContextLoader.class,
classes=ApplicationContextTestResourceNameType.class)
public class NamedResourceTest {
@Resource(name="namedFile")
private File testFile;
@Test
public void namedResource_MUST_FIND_SPECIFIED_File() {
public void givenResourceAnnotation_WhenOnField_THEN_DEPENDENCY_Found() {
assertNotNull(testFile);
assertTrue(testFile.getName().equals("namedFile.txt"));
assertEquals("namedFile.txt", testFile.getName());
}
}

View File

@ -1,35 +0,0 @@
package com.baeldung.resource;
import static org.junit.Assert.assertNotNull;
import java.io.File;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={
"/applicationContextTest-@Resource-Qualifier.xml"})
public class QualifierResourceInjectionDemo {
@Resource
private File defaultFile;
@Resource
@Qualifier("namedFile")
private File namedFile;
@Test
public void defaultFile_MUST_BE_Valid() {
assertNotNull(defaultFile);
}
@Test
public void namedFile_MUST_BE_Valid() {
assertNotNull(namedFile);
}
}

View File

@ -0,0 +1,43 @@
package com.baeldung.resource;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.File;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.baeldung.configuration.ApplicationContextTestResourceQualifier;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(
loader=AnnotationConfigContextLoader.class,
classes=ApplicationContextTestResourceQualifier.class)
public class QualifierResourceInjectionTest {
@Resource
@Qualifier("defaultFile")
private File dependency1;
@Resource
@Qualifier("namedFile")
private File dependency2;
@Test
public void givenResourceAnnotation_WhenField_ThenDependency1Valid(){
assertNotNull(dependency1);
assertEquals("defaultFile.txt", dependency1.getName());
}
@Test
public void givenResourceQualifier_WhenField_ThenDependency2Valid(){
assertNotNull(dependency2);
assertEquals("namedFile.txt", dependency2.getName());
}
}

View File

@ -1,4 +1,6 @@
package com.baeldung.resource;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.File;
@ -9,11 +11,14 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.baeldung.configuration.ApplicationContextTestResourceNameType;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={
"/applicationContextTest-@Resource-NameType.xml"})
public class SetterResourceInjectionDemo {
@ContextConfiguration(loader=AnnotationConfigContextLoader.class,
classes=ApplicationContextTestResourceNameType.class)
public class SetterResourceInjectionTest {
private File defaultFile;
@ -23,7 +28,8 @@ public class SetterResourceInjectionDemo {
}
@Test
public void setter_MUST_INJECT_Resource() {
public void givenResourceAnnotation_WhenOnSetter_THEN_MUST_INJECT_Dependency() {
assertNotNull(defaultFile);
assertEquals("namedFile.txt", defaultFile.getName());
}
}

View File

@ -10,7 +10,6 @@
<dependencies>
<!--log4j dependencies-->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
@ -19,8 +18,6 @@
<!--log4j2 dependencies-->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
@ -32,13 +29,31 @@
<version>2.6</version>
</dependency>
<!--disruptor for log4j2 async logging-->
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>3.3.4</version>
</dependency>
<!--<dependency>-->
<!--<groupId>org.apache.logging.log4j</groupId>-->
<!--<artifactId>log4j-api</artifactId>-->
<!--<version>2.6</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.apache.logging.log4j</groupId>-->
<!--<artifactId>log4j-core</artifactId>-->
<!--<version>2.6</version>-->
<!--</dependency>-->
<!--logback dependencies-->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.7</version>
</dependency>
<!--<dependency>-->
<!--<groupId>ch.qos.logback</groupId>-->
<!--<artifactId>logback-classic</artifactId>-->
<!--<version>1.1.7</version>-->
<!--</dependency>-->
</dependencies>
<build>
<plugins>

View File

@ -13,4 +13,4 @@ public class Log4j2Example {
logger.error("Error log message");
}
}
}

View File

@ -1,6 +1,5 @@
package com.baeldung.logback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -13,4 +12,5 @@ public class LogbackExample {
logger.info("Info log message");
logger.error("Error log message");
}
}
}

View File

@ -14,6 +14,7 @@
<param name="append" value="false"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %m%n"/>
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %p %m%n" />
</layout>
</appender>

View File

@ -4,23 +4,23 @@
# Console appender
<Console name="stdout" target="SYSTEM_OUT">
# Pattern of log message for console appender
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} %-5p %m%n" />
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} %p %m%n" />
</Console>
# File appender
<File name="fout" fileName="log4j/target/baeldung-log4j2.log" immediateFlush="false" append="false">
# Pattern of log message for file appender
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} %-5p %m%n"/>
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} %p %m%n"/>
</File>
</Appenders>
<Loggers>
# Override log level for specified package
<Logger name="com.baeldung.log4j2" level="ERROR"/>
<Logger name="com.baeldung.log4j2" level="TRACE"/>
<Root level="DEBUG">
<AsyncRoot level="DEBUG">
<AppenderRef ref="stdout" />
<AppenderRef ref="fout"/>
</Root>
</AsyncRoot>
</Loggers>
</Configuration>

View File

@ -3,7 +3,7 @@
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
# Pattern of log message for console appender
<Pattern>%d{yyyy-MM-dd HH:mm:ss} %-5p %m%n</Pattern>
<Pattern>%d{yyyy-MM-dd HH:mm:ss} %p %m%n</Pattern>
</layout>
</appender>
@ -14,12 +14,12 @@
<append>false</append>
<encoder>
# Pattern of log message for file appender
<pattern>%d{yyyy-MM-dd HH:mm:ss} %-5p %m%n</pattern>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %p %m%n</pattern>
</encoder>
</appender>
# Override log level for specified package
<logger name="com.baeldung.logback" level="ERROR"/>
<logger name="com.baeldung.logback" level="TRACE"/>
<root level="DEBUG">
<appender-ref ref="stdout" />

View File

@ -32,7 +32,7 @@
<!-- <module>raml</module> -->
<module>rest-testing</module>
<module>resteasy</module>
<module>log4j</module>
<module>log4j</module>
<module>spring-all</module>
<module>spring-apache-camel</module>

View File

@ -0,0 +1,15 @@
## Spring Data Neo4j
### Relevant Articles:
- [Introduction to Spring Data Neo4j](http://www.baeldung.com/spring-data-neo4j-tutorial)
### Build the Project with Tests Running
```
mvn clean install
```
### Run Tests Directly
```
mvn test
```

93
spring-data-neo4j/pom.xml Normal file
View File

@ -0,0 +1,93 @@
<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-data-neo4j</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<neo4j.version>3.0.1</neo4j.version>
<spring-data-neo4j.version>4.1.1.RELEASE</spring-data-neo4j.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>${spring-data-neo4j.version}</version>
</dependency>
<dependency>
<groupId>com.voodoodyne.jackson.jsog</groupId>
<artifactId>jackson-jsog</artifactId>
<version>1.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>${spring-data-neo4j.version}</version>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-kernel</artifactId>
<version>${neo4j.version}</version>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.neo4j.app</groupId>
<artifactId>neo4j-server</artifactId>
<version>${neo4j.version}</version>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-test</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j.test</groupId>
<artifactId>neo4j-harness</artifactId>
<version>${neo4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.2.3.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,34 @@
package com.baeldung.spring.data.neo4j.config;
import org.neo4j.ogm.session.SessionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.config.Neo4jConfiguration;
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@ComponentScan(basePackages = {"com.baeldung.spring.data.neo4j.services"})
@Configuration
@EnableNeo4jRepositories(basePackages = "com.baeldung.spring.data.neo4j.repostory")
public class MovieDatabaseNeo4jConfiguration extends Neo4jConfiguration {
public static final String URL = System.getenv("NEO4J_URL") != null ? System.getenv("NEO4J_URL") : "http://neo4j:movies@localhost:7474";
@Bean
public org.neo4j.ogm.config.Configuration getConfiguration() {
org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration();
config
.driverConfiguration()
.setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver")
.setURI(URL);
return config;
}
@Override
public SessionFactory getSessionFactory() {
return new SessionFactory(getConfiguration(), "com.baeldung.spring.data.neo4j.domain");
}
}

View File

@ -0,0 +1,34 @@
package com.baeldung.spring.data.neo4j.config;
import org.neo4j.ogm.session.SessionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.data.neo4j.config.Neo4jConfiguration;
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
import org.springframework.data.neo4j.server.Neo4jServer;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableTransactionManagement
@ComponentScan(basePackages = {"com.baeldung.spring.data.neo4j.services"})
@Configuration
@EnableNeo4jRepositories(basePackages = "com.baeldung.spring.data.neo4j.repostory")
@Profile({"embedded", "test"})
public class MovieDatabaseNeo4jTestConfiguration extends Neo4jConfiguration {
@Bean
public org.neo4j.ogm.config.Configuration getConfiguration() {
org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration();
config
.driverConfiguration()
.setDriverClassName("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver");
return config;
}
@Override
public SessionFactory getSessionFactory() {
return new SessionFactory(getConfiguration(), "com.baeldung.spring.data.neo4j.domain");
}
}

View File

@ -0,0 +1,61 @@
package com.baeldung.spring.data.neo4j.domain;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.voodoodyne.jackson.jsog.JSOGGenerator;
import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Relationship;
import java.util.Collection;
import java.util.List;
@JsonIdentityInfo(generator=JSOGGenerator.class)
@NodeEntity
public class Movie {
@GraphId
Long id;
private String title;
private int released;
private String tagline;
@Relationship(type="ACTED_IN", direction = Relationship.INCOMING) private List<Role> roles;
public Movie() { }
public String getTitle() {
return title;
}
public int getReleased() {
return released;
}
public String getTagline() {
return tagline;
}
public Collection<Role> getRoles() {
return roles;
}
public void setTitle(String title) {
this.title = title;
}
public void setReleased(int released) {
this.released = released;
}
public void setTagline(String tagline) {
this.tagline = tagline;
}
public void setRoles(List<Role> roles) {
this.roles = roles;
}
}

View File

@ -0,0 +1,50 @@
package com.baeldung.spring.data.neo4j.domain;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.voodoodyne.jackson.jsog.JSOGGenerator;
import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Relationship;
import java.util.List;
@JsonIdentityInfo(generator=JSOGGenerator.class)
@NodeEntity
public class Person {
@GraphId
Long id;
private String name;
private int born;
@Relationship(type = "ACTED_IN")
private List<Movie> movies;
public Person() { }
public String getName() {
return name;
}
public int getBorn() {
return born;
}
public List<Movie> getMovies() {
return movies;
}
public void setName(String name) {
this.name = name;
}
public void setBorn(int born) {
this.born = born;
}
public void setMovies(List<Movie> movies) {
this.movies = movies;
}
}

View File

@ -0,0 +1,50 @@
package com.baeldung.spring.data.neo4j.domain;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.voodoodyne.jackson.jsog.JSOGGenerator;
import org.neo4j.ogm.annotation.EndNode;
import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.RelationshipEntity;
import org.neo4j.ogm.annotation.StartNode;
import java.util.Collection;
@JsonIdentityInfo(generator=JSOGGenerator.class)
@RelationshipEntity(type = "ACTED_IN")
public class Role {
@GraphId
Long id;
private Collection<String> roles;
@StartNode
private Person person;
@EndNode
private Movie movie;
public Role() {
}
public Collection<String> getRoles() {
return roles;
}
public Person getPerson() {
return person;
}
public Movie getMovie() {
return movie;
}
public void setRoles(Collection<String> roles) {
this.roles = roles;
}
public void setPerson(Person person) {
this.person = person;
}
public void setMovie(Movie movie) {
this.movie = movie;
}
}

View File

@ -0,0 +1,24 @@
package com.baeldung.spring.data.neo4j.repostory;
import com.baeldung.spring.data.neo4j.domain.Movie;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@Repository
public interface MovieRepository extends GraphRepository<Movie> {
Movie findByTitle(@Param("title") String title);
@Query("MATCH (m:Movie) WHERE m.title =~ ('(?i).*'+{title}+'.*') RETURN m")
Collection<Movie> findByTitleContaining(@Param("title") String title);
@Query("MATCH (m:Movie)<-[:ACTED_IN]-(a:Person) RETURN m.title as movie, collect(a.name) as cast LIMIT {limit}")
List<Map<String,Object>> graph(@Param("limit") int limit);
}

View File

@ -0,0 +1,11 @@
package com.baeldung.spring.data.neo4j.repostory;
import com.baeldung.spring.data.neo4j.domain.Person;
import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface PersonRepository extends GraphRepository<Person> {
}

View File

@ -0,0 +1,50 @@
package com.baeldung.spring.data.neo4j.services;
import com.baeldung.spring.data.neo4j.repostory.MovieRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
@Service
@Transactional
public class MovieService {
@Autowired
MovieRepository movieRepository;
private Map<String, Object> toD3Format(Iterator<Map<String, Object>> result) {
List<Map<String,Object>> nodes = new ArrayList<Map<String,Object>>();
List<Map<String,Object>> rels= new ArrayList<Map<String,Object>>();
int i=0;
while (result.hasNext()) {
Map<String, Object> row = result.next();
nodes.add(map("title",row.get("movie"),"label","movie"));
int target=i;
i++;
for (Object name : (Collection) row.get("cast")) {
Map<String, Object> actor = map("title", name,"label","actor");
int source = nodes.indexOf(actor);
if (source == -1) {
nodes.add(actor);
source = i++;
}
rels.add(map("source",source,"target",target));
}
}
return map("nodes", nodes, "links", rels);
}
private Map<String, Object> map(String key1, Object value1, String key2, Object value2) {
Map<String, Object> result = new HashMap<String,Object>(2);
result.put(key1,value1);
result.put(key2,value2);
return result;
}
public Map<String, Object> graph(int limit) {
Iterator<Map<String, Object>> result = movieRepository.graph(limit).iterator();
return toD3Format(result);
}
}

View File

@ -0,0 +1,20 @@
<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>

Binary file not shown.

After

Width:  |  Height:  |  Size: 855 B

View File

@ -0,0 +1,133 @@
package com.baeldung.spring.data.neo4j;
import com.baeldung.spring.data.neo4j.config.MovieDatabaseNeo4jTestConfiguration;
import com.baeldung.spring.data.neo4j.domain.Movie;
import com.baeldung.spring.data.neo4j.domain.Person;
import com.baeldung.spring.data.neo4j.domain.Role;
import com.baeldung.spring.data.neo4j.repostory.MovieRepository;
import com.baeldung.spring.data.neo4j.repostory.PersonRepository;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.*;
import static junit.framework.TestCase.assertNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = MovieDatabaseNeo4jTestConfiguration.class)
@ActiveProfiles(profiles = "test")
public class MovieRepositoryTest {
@Autowired
private MovieRepository movieRepository;
@Autowired
private PersonRepository personRepository;
public MovieRepositoryTest() {
}
@Before
public void initializeDatabase() {
System.out.println("seeding embedded database");
Movie italianJob = new Movie();
italianJob.setTitle("The Italian Job");
italianJob.setReleased(1999);
movieRepository.save(italianJob);
Person mark = new Person();
mark.setName("Mark Wahlberg");
personRepository.save(mark);
Role charlie = new Role();
charlie.setMovie(italianJob);
charlie.setPerson(mark);
Collection<String> roleNames = new HashSet();
roleNames.add("Charlie Croker");
charlie.setRoles(roleNames);
List<Role> roles = new ArrayList();
roles.add(charlie);
italianJob.setRoles(roles);
movieRepository.save(italianJob);
}
@Test
@DirtiesContext
public void testFindByTitle() {
System.out.println("findByTitle");
String title = "The Italian Job";
Movie result = movieRepository.findByTitle(title);
assertNotNull(result);
assertEquals(1999, result.getReleased());
}
@Test
@DirtiesContext
public void testCount() {
System.out.println("count");
long movieCount = movieRepository.count();
assertNotNull(movieCount);
assertEquals(1, movieCount);
}
@Test
@DirtiesContext
public void testFindAll() {
System.out.println("findAll");
Collection<Movie> result =
(Collection<Movie>) movieRepository.findAll();
assertNotNull(result);
assertEquals(1, result.size());
}
@Test
@DirtiesContext
public void testFindByTitleContaining() {
System.out.println("findByTitleContaining");
String title = "Italian";
Collection<Movie> result =
movieRepository.findByTitleContaining(title);
assertNotNull(result);
assertEquals(1, result.size());
}
@Test
@DirtiesContext
public void testGraph() {
System.out.println("graph");
List<Map<String, Object>> graph = movieRepository.graph(5);
assertEquals(1, graph.size());
Map<String, Object> map = graph.get(0);
assertEquals(2, map.size());
String[] cast = (String[]) map.get("cast");
String movie = (String) map.get("movie");
assertEquals("The Italian Job", movie);
assertEquals("Mark Wahlberg", cast[0]);
}
@Test
@DirtiesContext
public void testDeleteMovie() {
System.out.println("deleteMovie");
movieRepository.delete(movieRepository.findByTitle("The Italian Job"));
assertNull(movieRepository.findByTitle("The Italian Job"));
}
@Test
@DirtiesContext
public void testDeleteAll() {
System.out.println("deleteAll");
movieRepository.deleteAll();
Collection<Movie> result =
(Collection<Movie>) movieRepository.findAll();
assertEquals(0, result.size());
}
}

View File

@ -0,0 +1,2 @@
###The Course
The "REST With Spring" Classes: http://bit.ly/restwithspring

View File

@ -2,7 +2,6 @@ package com.baeldung.xml;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
@ -40,7 +39,7 @@ public class JaxbParser {
tut.setType("XML");
tut.setTitle("XML with Jaxb");
tut.setDescription("XML Binding with Jaxb");
tut.setDate(new Date());
tut.setDate("04/02/2015");
tut.setAuthor("Jaxb author");
tutorials.getTutorial().add(tut);

View File

@ -17,7 +17,7 @@ import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import com.baeldung.xml.model.Tutorial;
import com.baeldung.xml.binding.Tutorial;
public class StaxParser {

View File

@ -1,7 +1,5 @@
package com.baeldung.xml.binding;
import java.util.Date;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
@ -11,7 +9,7 @@ public class Tutorial {
private String type;
private String title;
private String description;
private Date date;
private String date;
private String author;
@ -44,11 +42,11 @@ public class Tutorial {
public void setDescription(String description) {
this.description = description;
}
public Date getDate() {
public String getDate() {
return date;
}
@XmlElement
public void setDate(Date date) {
public void setDate(String date) {
this.date = date;
}
public String getAuthor() {

View File

@ -1,49 +0,0 @@
package com.baeldung.xml.model;
public class Tutorial {
private String tutId;
private String type;
private String title;
private String description;
private String date;
private String author;
public String getTutId() {
return tutId;
}
public void setTutId(String tutId) {
this.tutId = tutId;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
}

View File

@ -1,22 +1,20 @@
package com.baeldung.xml;
import static org.junit.Assert.*;
import java.io.File;
import org.junit.Test;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.io.File;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class DefaultParserTest {
private final String fileName = "src/test/resources/example.xml";
final String fileName = "src/test/resources/example.xml";
private final String fileNameSpace = "src/test/resources/example_namespace.xml";
final String fileNameSpace = "src/test/resources/example_namespace.xml";
private DefaultParser parser;
DefaultParser parser;
@Test
public void getFirstLevelNodeListTest() {
@ -32,7 +30,7 @@ public class DefaultParserTest {
parser = new DefaultParser(new File(fileName));
NodeList list = parser.getNodeListByTitle("XML");
for (int i = 0; i < list.getLength(); i++) {
for (int i = 0; null != list && i < list.getLength(); i++) {
Node nod = list.item(i);
assertEquals("java", nod.getAttributes().getNamedItem("type").getTextContent());
assertEquals("02", nod.getAttributes().getNamedItem("tutId").getTextContent());
@ -58,7 +56,7 @@ public class DefaultParserTest {
public void getNodeListByDateTest(){
parser = new DefaultParser(new File(fileName));
NodeList list = parser.getNodeListByTitle("04022016");
for (int i = 0; i < list.getLength(); i++) {
for (int i = 0; null != list && i < list.getLength(); i++) {
Node nod = list.item(i);
assertEquals("java", nod.getAttributes().getNamedItem("type").getTextContent());
assertEquals("04", nod.getAttributes().getNamedItem("tutId").getTextContent());

View File

@ -1,25 +1,25 @@
package com.baeldung.xml;
import org.dom4j.Element;
import org.dom4j.Node;
import org.junit.Test;
import java.io.File;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.List;
import org.dom4j.Element;
import org.dom4j.Node;
import org.junit.Test;
public class Dom4JParserTest {
private static final String FILE_NAME = "src/test/resources/example.xml";
final String fileName = "src/test/resources/example.xml";
private Dom4JParser parser;
Dom4JParser parser;
@Test
public void getRootElementTest() {
parser = new Dom4JParser(new File(FILE_NAME));
parser = new Dom4JParser(new File(fileName));
Element root = parser.getRootElement();
assertNotNull(root);
@ -28,7 +28,7 @@ public class Dom4JParserTest {
@Test
public void getFirstElementListTest() {
parser = new Dom4JParser(new File(FILE_NAME));
parser = new Dom4JParser(new File(fileName));
List<Element> firstList = parser.getFirstElementList();
assertNotNull(firstList);
@ -38,7 +38,7 @@ public class Dom4JParserTest {
@Test
public void getElementByIdTest() {
parser = new Dom4JParser(new File(FILE_NAME));
parser = new Dom4JParser(new File(fileName));
Node element = parser.getNodeById("03");
String type = element.valueOf("@type");
@ -47,7 +47,7 @@ public class Dom4JParserTest {
@Test
public void getElementsListByTitleTest() {
parser = new Dom4JParser(new File(FILE_NAME));
parser = new Dom4JParser(new File(fileName));
Node element = parser.getElementsListByTitle("XML");
assertEquals("java", element.valueOf("@type"));
@ -58,7 +58,7 @@ public class Dom4JParserTest {
@Test
public void generateModifiedDocumentTest() {
parser = new Dom4JParser(new File(FILE_NAME));
parser = new Dom4JParser(new File(fileName));
parser.generateModifiedDocument();
File generatedFile = new File("src/test/resources/example_updated.xml");
@ -73,7 +73,7 @@ public class Dom4JParserTest {
@Test
public void generateNewDocumentTest() {
parser = new Dom4JParser(new File(FILE_NAME));
parser = new Dom4JParser(new File(fileName));
parser.generateNewDocument();
File newFile = new File("src/test/resources/example_new.xml");

View File

@ -1,20 +1,20 @@
package com.baeldung.xml;
import org.jdom2.Element;
import org.junit.Test;
import java.io.File;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.List;
import org.jdom2.Element;
import org.junit.Test;
public class JDomParserTest {
private final String fileName = "src/test/resources/example.xml";
final String fileName = "src/test/resources/example.xml";
private JDomParser parser;
JDomParser parser;
@Test
public void getFirstElementListTest() {

View File

@ -1,19 +1,20 @@
package com.baeldung.xml;
import com.baeldung.xml.binding.Tutorials;
import org.junit.Test;
import java.io.File;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import org.junit.Test;
import com.baeldung.xml.binding.Tutorials;
public class JaxbParserTest {
private final String fileName = "src/test/resources/example.xml";
final String fileName = "src/test/resources/example.xml";
private JaxbParser parser;
JaxbParser parser;
@Test
public void getFullDocumentTest(){

View File

@ -1,18 +1,18 @@
package com.baeldung.xml;
import org.junit.Test;
import java.io.File;
import java.util.List;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.List;
import org.junit.Test;
public class JaxenDemoTest {
private final String fileName = "src/test/resources/example.xml";
final String fileName = "src/test/resources/example.xml";
private JaxenDemo jaxenDemo;
JaxenDemo jaxenDemo;
@Test
public void getFirstLevelNodeListTest() {

View File

@ -1,19 +1,20 @@
package com.baeldung.xml;
import com.baeldung.xml.model.Tutorial;
import org.junit.Test;
import java.io.File;
import java.util.List;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.List;
import org.junit.Test;
import com.baeldung.xml.binding.Tutorial;
public class StaxParserTest {
private final String fileName = "src/test/resources/example.xml";
final String fileName = "src/test/resources/example.xml";
private StaxParser parser;
StaxParser parser;
@Test
public void getAllTutorialsTest(){