Merge branches 'assertj-guava' and 'master' of https://github.com/eugenp/tutorials
|
@ -27,4 +27,3 @@ target/
|
||||||
|
|
||||||
spring-openid/src/main/resources/application.properties
|
spring-openid/src/main/resources/application.properties
|
||||||
.recommenders/
|
.recommenders/
|
||||||
|
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
apply plugin: 'java'
|
|
||||||
apply plugin: 'eclipse'
|
|
||||||
|
|
||||||
allprojects {
|
|
||||||
apply plugin: 'java'
|
|
||||||
sourceCompatibility = 1.6
|
|
||||||
targetCompatibility = 1.6
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
main {
|
|
||||||
resources.srcDirs = ["src/main/java","src/main/resources"]
|
|
||||||
}
|
|
||||||
test {
|
|
||||||
resources.srcDirs = ["src/main/java", "src/main/resources", "src/test/resources"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
configurations {
|
|
||||||
compile
|
|
||||||
}
|
|
||||||
|
|
||||||
test {
|
|
||||||
testLogging {
|
|
||||||
events 'started', 'passed'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
testCompile('junit:junit:4.11')
|
|
||||||
testCompile('org.mockito:mockito-all:1.10.19')
|
|
||||||
testCompile group: 'org.springframework', name: 'spring-test', version: '4.2.6.RELEASE'
|
|
||||||
testCompile group: 'org.springframework', name: 'spring-core', version: '4.2.6.RELEASE'
|
|
||||||
testCompile group: 'org.springframework', name: 'spring-beans', version: '4.2.6.RELEASE'
|
|
||||||
testCompile group: 'org.springframework', name: 'spring-context', version: '4.2.6.RELEASE'
|
|
||||||
testCompile group: 'javax.inject', name: 'javax.inject', version: '1'
|
|
||||||
|
|
||||||
testRuntime('junit:junit:4.11')
|
|
||||||
}
|
|
Before Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 23 KiB |
|
@ -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>
|
|
Before Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 19 KiB |
|
@ -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>
|
|
Before Width: | Height: | Size: 23 KiB |
|
@ -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>
|
|
Before Width: | Height: | Size: 36 KiB |
|
@ -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>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>
|
|
Before Width: | Height: | Size: 45 KiB |
Before Width: | Height: | Size: 17 KiB |
|
@ -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>
|
|
Before Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 19 KiB |
|
@ -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>
|
|
|
@ -1,81 +1,83 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
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>dependency-injection</artifactId>
|
<artifactId>dependency-injection</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
|
|
||||||
<name>@Resource vs @Inject vs @Autowired</name>
|
<name>Resource vs Inject vs Autowired</name>
|
||||||
<description>Accompanying the demonstration of the use of the annotations related to injection mechanisms, namely @Resource, @Inject, and @Autowired</description>
|
<description>Accompanying the demonstration of the use of the annotations related to injection mechanisms, namely
|
||||||
|
Resource, Inject, and Autowired
|
||||||
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.11</version>
|
<version>4.11</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-all</artifactId>
|
<artifactId>mockito-all</artifactId>
|
||||||
<version>1.10.19</version>
|
<version>1.10.19</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-test</artifactId>
|
<artifactId>spring-test</artifactId>
|
||||||
<version>4.2.6.RELEASE</version>
|
<version>4.2.6.RELEASE</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-core</artifactId>
|
<artifactId>spring-core</artifactId>
|
||||||
<version>4.2.6.RELEASE</version>
|
<version>4.2.6.RELEASE</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-beans</artifactId>
|
<artifactId>spring-beans</artifactId>
|
||||||
<version>4.2.6.RELEASE</version>
|
<version>4.2.6.RELEASE</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-context</artifactId>
|
<artifactId>spring-context</artifactId>
|
||||||
<version>4.2.6.RELEASE</version>
|
<version>4.2.6.RELEASE</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.inject</groupId>
|
<groupId>javax.inject</groupId>
|
||||||
<artifactId>javax.inject</artifactId>
|
<artifactId>javax.inject</artifactId>
|
||||||
<version>1</version>
|
<version>1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.6</source>
|
<source>1.8</source>
|
||||||
<target>1.6</target>
|
<target>1.8</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<includes>
|
<includes>
|
||||||
<include>**/*Demo.java</include>
|
<include>**/*Test.java</include>
|
||||||
</includes>
|
</includes>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>java.net</id>
|
<id>java.net</id>
|
||||||
<url>https://maven.java.net/content/repositories/releases/</url>
|
<url>https://maven.java.net/content/repositories/releases/</url>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -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 {
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.baeldung.configuration;
|
||||||
|
|
||||||
|
import com.baeldung.dependency.AnotherArbitraryDependency;
|
||||||
|
import com.baeldung.dependency.ArbitraryDependency;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class ApplicationContextTestAutowiredQualifier {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ArbitraryDependency autowiredFieldDependency() {
|
||||||
|
ArbitraryDependency autowiredFieldDependency = new ArbitraryDependency();
|
||||||
|
|
||||||
|
return autowiredFieldDependency;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ArbitraryDependency anotherAutowiredFieldDependency() {
|
||||||
|
ArbitraryDependency anotherAutowiredFieldDependency = new AnotherArbitraryDependency();
|
||||||
|
|
||||||
|
return anotherAutowiredFieldDependency;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.baeldung.configuration;
|
||||||
|
|
||||||
|
import com.baeldung.dependency.ArbitraryDependency;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class ApplicationContextTestAutowiredType {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ArbitraryDependency autowiredFieldDependency() {
|
||||||
|
ArbitraryDependency autowiredFieldDependency = new ArbitraryDependency();
|
||||||
|
return autowiredFieldDependency;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.baeldung.configuration;
|
||||||
|
|
||||||
|
import com.baeldung.dependency.ArbitraryDependency;
|
||||||
|
import com.baeldung.dependency.YetAnotherArbitraryDependency;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class ApplicationContextTestInjectName {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ArbitraryDependency yetAnotherFieldInjectDependency() {
|
||||||
|
ArbitraryDependency yetAnotherFieldInjectDependency = new YetAnotherArbitraryDependency();
|
||||||
|
return yetAnotherFieldInjectDependency;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.baeldung.configuration;
|
||||||
|
|
||||||
|
import com.baeldung.dependency.AnotherArbitraryDependency;
|
||||||
|
import com.baeldung.dependency.ArbitraryDependency;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class ApplicationContextTestInjectQualifier {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ArbitraryDependency defaultFile() {
|
||||||
|
ArbitraryDependency defaultFile = new ArbitraryDependency();
|
||||||
|
return defaultFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ArbitraryDependency namedFile() {
|
||||||
|
ArbitraryDependency namedFile = new AnotherArbitraryDependency();
|
||||||
|
return namedFile;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.baeldung.configuration;
|
||||||
|
|
||||||
|
import com.baeldung.dependency.ArbitraryDependency;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class ApplicationContextTestInjectType {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ArbitraryDependency injectDependency() {
|
||||||
|
ArbitraryDependency injectDependency = new ArbitraryDependency();
|
||||||
|
return injectDependency;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.baeldung.configuration;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class ApplicationContextTestResourceNameType {
|
||||||
|
|
||||||
|
@Bean(name = "namedFile")
|
||||||
|
public File namedFile() {
|
||||||
|
File namedFile = new File("namedFile.txt");
|
||||||
|
return namedFile;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.baeldung.configuration;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,8 @@
|
||||||
package com.baeldung.dependency;
|
package com.baeldung.dependency;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
public class AnotherArbitraryDependency extends ArbitraryDependency {
|
public class AnotherArbitraryDependency extends ArbitraryDependency {
|
||||||
|
|
||||||
private final String label = "Another Arbitrary Dependency";
|
private final String label = "Another Arbitrary Dependency";
|
|
@ -1,5 +1,8 @@
|
||||||
package com.baeldung.dependency;
|
package com.baeldung.dependency;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component(value = "autowiredFieldDependency")
|
||||||
public class ArbitraryDependency {
|
public class ArbitraryDependency {
|
||||||
|
|
||||||
private final String label = "Arbitrary Dependency";
|
private final String label = "Arbitrary Dependency";
|
|
@ -1,5 +1,8 @@
|
||||||
package com.baeldung.dependency;
|
package com.baeldung.dependency;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
public class YetAnotherArbitraryDependency extends ArbitraryDependency {
|
public class YetAnotherArbitraryDependency extends ArbitraryDependency {
|
||||||
|
|
||||||
private final String label = "Yet Another Arbitrary Dependency";
|
private final String label = "Yet Another Arbitrary Dependency";
|
|
@ -1,27 +1,29 @@
|
||||||
package com.baeldung.autowired;
|
package com.baeldung.autowired;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import com.baeldung.configuration.ApplicationContextTestAutowiredName;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import com.baeldung.dependency.ArbitraryDependency;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
|
|
||||||
import com.baeldung.dependency.ArbitraryDependency;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(locations={
|
@ContextConfiguration(
|
||||||
"/applicationContextTest-@Autowired-Name.xml"})
|
loader = AnnotationConfigContextLoader.class,
|
||||||
public class FieldAutowiredNameDemo {
|
classes = ApplicationContextTestAutowiredName.class)
|
||||||
|
public class FieldAutowiredNameTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ArbitraryDependency autowiredFieldDependency;
|
private ArbitraryDependency autowiredFieldDependency;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void autowiredFieldDependency_MUST_BE_AUTOWIRED_Correctly() {
|
public void givenAutowiredAnnotation_WhenOnField_ThenDependencyValid() {
|
||||||
assertNotNull(autowiredFieldDependency);
|
assertNotNull(autowiredFieldDependency);
|
||||||
assertEquals("Arbitrary Dependency", autowiredFieldDependency.toString());
|
assertEquals("Arbitrary Dependency", autowiredFieldDependency.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,26 +1,28 @@
|
||||||
package com.baeldung.autowired;
|
package com.baeldung.autowired;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import com.baeldung.configuration.ApplicationContextTestAutowiredType;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import com.baeldung.dependency.ArbitraryDependency;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
|
|
||||||
import com.baeldung.dependency.ArbitraryDependency;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(locations={
|
@ContextConfiguration(
|
||||||
"/applicationContextTest-@Autowired-Type.xml"})
|
loader = AnnotationConfigContextLoader.class,
|
||||||
public class FieldAutowiredDemo {
|
classes = ApplicationContextTestAutowiredType.class)
|
||||||
|
public class FieldAutowiredTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ArbitraryDependency fieldDependency;
|
private ArbitraryDependency fieldDependency;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fieldDependency_MUST_BE_AUTOWIRED_Correctly() {
|
public void givenAutowired_WhenSetOnField_ThenDependencyResolved() {
|
||||||
assertNotNull(fieldDependency);
|
assertNotNull(fieldDependency);
|
||||||
assertEquals("Arbitrary Dependency", fieldDependency.toString());
|
assertEquals("Arbitrary Dependency", fieldDependency.toString());
|
||||||
}
|
}
|
|
@ -1,21 +1,23 @@
|
||||||
package com.baeldung.autowired;
|
package com.baeldung.autowired;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import com.baeldung.configuration.ApplicationContextTestAutowiredQualifier;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import com.baeldung.dependency.ArbitraryDependency;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
|
|
||||||
import com.baeldung.dependency.ArbitraryDependency;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(locations={
|
@ContextConfiguration(
|
||||||
"/applicationContextTest-@Autowired-Qualifier.xml"})
|
loader = AnnotationConfigContextLoader.class,
|
||||||
public class FieldQualifierAutowiredDemo {
|
classes = ApplicationContextTestAutowiredQualifier.class)
|
||||||
|
public class FieldQualifierAutowiredTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("autowiredFieldDependency")
|
@Qualifier("autowiredFieldDependency")
|
||||||
|
@ -26,13 +28,13 @@ public class FieldQualifierAutowiredDemo {
|
||||||
private ArbitraryDependency fieldDependency2;
|
private ArbitraryDependency fieldDependency2;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fieldDependency1_MUST_BE_AUTOWIRED_Correctly() {
|
public void givenAutowiredQualifier_WhenOnField_ThenDep1Valid() {
|
||||||
assertNotNull(fieldDependency1);
|
assertNotNull(fieldDependency1);
|
||||||
assertEquals("Arbitrary Dependency", fieldDependency1.toString());
|
assertEquals("Arbitrary Dependency", fieldDependency1.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fieldDependency2_MUST_BE_AUTOWIRED_Correctly() {
|
public void givenAutowiredQualifier_WhenOnField_ThenDep2Valid() {
|
||||||
assertNotNull(fieldDependency2);
|
assertNotNull(fieldDependency2);
|
||||||
assertEquals("Another Arbitrary Dependency", fieldDependency2.toString());
|
assertEquals("Another Arbitrary Dependency", fieldDependency2.toString());
|
||||||
}
|
}
|
|
@ -1,29 +1,31 @@
|
||||||
package com.baeldung.inject;
|
package com.baeldung.inject;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import com.baeldung.configuration.ApplicationContextTestInjectName;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import com.baeldung.dependency.ArbitraryDependency;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Named;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
|
|
||||||
import com.baeldung.dependency.ArbitraryDependency;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(locations={
|
@ContextConfiguration(
|
||||||
"/applicationContextTest-@Inject-Name.xml"})
|
loader = AnnotationConfigContextLoader.class,
|
||||||
public class FieldByNameInjectDemo {
|
classes = ApplicationContextTestInjectName.class)
|
||||||
|
public class FieldByNameInjectTest {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named("yetAnotherFieldInjectDependency")
|
@Named("yetAnotherFieldInjectDependency")
|
||||||
private ArbitraryDependency yetAnotherFieldInjectDependency;
|
private ArbitraryDependency yetAnotherFieldInjectDependency;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void yetAnotherFieldInjectDependency_MUST_BE_INJECTED_Correctly() {
|
public void givenInjectQualifier_WhenSetOnField_ThenDependencyValid() {
|
||||||
assertNotNull(yetAnotherFieldInjectDependency);
|
assertNotNull(yetAnotherFieldInjectDependency);
|
||||||
assertEquals("Yet Another Arbitrary Dependency", yetAnotherFieldInjectDependency.toString());
|
assertEquals("Yet Another Arbitrary Dependency", yetAnotherFieldInjectDependency.toString());
|
||||||
}
|
}
|
|
@ -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());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.baeldung.inject;
|
||||||
|
|
||||||
|
import com.baeldung.configuration.ApplicationContextTestInjectType;
|
||||||
|
import com.baeldung.dependency.ArbitraryDependency;
|
||||||
|
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 javax.inject.Inject;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
@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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,22 +1,23 @@
|
||||||
package com.baeldung.inject;
|
package com.baeldung.inject;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import com.baeldung.configuration.ApplicationContextTestInjectQualifier;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import com.baeldung.dependency.ArbitraryDependency;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
|
|
||||||
import com.baeldung.dependency.ArbitraryDependency;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(locations={
|
@ContextConfiguration(loader = AnnotationConfigContextLoader.class,
|
||||||
"/applicationContextTest-@Inject-Qualifier.xml"})
|
classes = ApplicationContextTestInjectQualifier.class)
|
||||||
public class FieldQualifierInjectDemo {
|
public class FieldQualifierInjectTest {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Qualifier("defaultFile")
|
@Qualifier("defaultFile")
|
||||||
|
@ -27,13 +28,13 @@ public class FieldQualifierInjectDemo {
|
||||||
private ArbitraryDependency namedDependency;
|
private ArbitraryDependency namedDependency;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultDependency_MUST_BE_INJECTED_Successfully() {
|
public void givenInjectQualifier_WhenOnField_ThenDefaultFileValid() {
|
||||||
assertNotNull(defaultDependency);
|
assertNotNull(defaultDependency);
|
||||||
assertEquals("Arbitrary Dependency", defaultDependency.toString());
|
assertEquals("Arbitrary Dependency", defaultDependency.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void namedDependency_MUST_BE_INJECTED_Correctly() {
|
public void givenInjectQualifier_WhenOnField_ThenNamedFileValid() {
|
||||||
assertNotNull(defaultDependency);
|
assertNotNull(defaultDependency);
|
||||||
assertEquals("Another Arbitrary Dependency", namedDependency.toString());
|
assertEquals("Another Arbitrary Dependency", namedDependency.toString());
|
||||||
}
|
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.baeldung.resource;
|
||||||
|
|
||||||
|
import com.baeldung.configuration.ApplicationContextTestResourceNameType;
|
||||||
|
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 javax.annotation.Resource;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
@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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,43 +0,0 @@
|
||||||
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;
|
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ContextConfiguration(locations={
|
|
||||||
"/applicationContextTest-@Resource-Qualifier.xml"})
|
|
||||||
public class MethodByQualifierResourceDemo {
|
|
||||||
|
|
||||||
private File arbDependency;
|
|
||||||
private File anotherArbDependency;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void dependencies_MUST_BE_INJECTED_Correctly() {
|
|
||||||
assertNotNull(arbDependency);
|
|
||||||
assertEquals("namedFile.txt", arbDependency.getName());
|
|
||||||
assertNotNull(anotherArbDependency);
|
|
||||||
assertEquals("defaultFile.txt", anotherArbDependency.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
@Qualifier("namedFile")
|
|
||||||
public void setArbDependency(File arbDependency) {
|
|
||||||
this.arbDependency = arbDependency;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
@Qualifier("defaultFile")
|
|
||||||
public void setAnotherArbDependency(File anotherArbDependency) {
|
|
||||||
this.anotherArbDependency = anotherArbDependency;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.baeldung.resource;
|
||||||
|
|
||||||
|
import com.baeldung.configuration.ApplicationContextTestResourceQualifier;
|
||||||
|
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 javax.annotation.Resource;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration(
|
||||||
|
loader = AnnotationConfigContextLoader.class,
|
||||||
|
classes = ApplicationContextTestResourceQualifier.class)
|
||||||
|
public class MethodByQualifierResourceTest {
|
||||||
|
|
||||||
|
private File arbDependency;
|
||||||
|
private File anotherArbDependency;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenResourceQualifier_WhenSetter_ThenValidDependencies() {
|
||||||
|
assertNotNull(arbDependency);
|
||||||
|
assertEquals("namedFile.txt", arbDependency.getName());
|
||||||
|
assertNotNull(anotherArbDependency);
|
||||||
|
assertEquals("defaultFile.txt", anotherArbDependency.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
@Qualifier("namedFile")
|
||||||
|
public void setArbDependency(File arbDependency) {
|
||||||
|
this.arbDependency = arbDependency;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
@Qualifier("defaultFile")
|
||||||
|
public void setAnotherArbDependency(File anotherArbDependency) {
|
||||||
|
this.anotherArbDependency = anotherArbDependency;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,19 +1,23 @@
|
||||||
package com.baeldung.resource;
|
package com.baeldung.resource;
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
|
import com.baeldung.configuration.ApplicationContextTestResourceNameType;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(locations={
|
@ContextConfiguration(
|
||||||
"/applicationContextTest-@Resource-NameType.xml"})
|
loader = AnnotationConfigContextLoader.class,
|
||||||
public class SetterResourceInjectionDemo {
|
classes = ApplicationContextTestResourceNameType.class)
|
||||||
|
public class MethodByTypeResourceTest {
|
||||||
|
|
||||||
private File defaultFile;
|
private File defaultFile;
|
||||||
|
|
||||||
|
@ -23,7 +27,8 @@ public class SetterResourceInjectionDemo {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setter_MUST_INJECT_Resource() {
|
public void givenResourceAnnotation_WhenSetter_ThenValidDependency() {
|
||||||
assertNotNull(defaultFile);
|
assertNotNull(defaultFile);
|
||||||
|
assertEquals("namedFile.txt", defaultFile.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,29 +1,34 @@
|
||||||
package com.baeldung.resource;
|
package com.baeldung.resource;
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
|
import com.baeldung.configuration.ApplicationContextTestResourceNameType;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(locations={
|
@ContextConfiguration(
|
||||||
"/applicationContextTest-@Resource-NameType.xml"})
|
loader = AnnotationConfigContextLoader.class,
|
||||||
public class MethodResourceInjectionDemo {
|
classes = ApplicationContextTestResourceNameType.class)
|
||||||
|
public class MethodResourceInjectionTest {
|
||||||
|
|
||||||
private File defaultFile;
|
private File defaultFile;
|
||||||
|
|
||||||
@Resource(name="namedFile")
|
@Resource(name = "namedFile")
|
||||||
protected void setDefaultFile(File defaultFile) {
|
protected void setDefaultFile(File defaultFile) {
|
||||||
this.defaultFile = defaultFile;
|
this.defaultFile = defaultFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultFile_MUST_BE_INJECTED_Correctly() {
|
public void givenResourceAnnotation_WhenSetter_ThenDependencyValid() {
|
||||||
assertNotNull(defaultFile);
|
assertNotNull(defaultFile);
|
||||||
|
assertEquals("namedFile.txt", defaultFile.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,27 +1,29 @@
|
||||||
package com.baeldung.resource;
|
package com.baeldung.resource;
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
|
import com.baeldung.configuration.ApplicationContextTestResourceNameType;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(locations={
|
@ContextConfiguration(loader = AnnotationConfigContextLoader.class,
|
||||||
"/applicationContextTest-@Resource-NameType.xml"})
|
classes = ApplicationContextTestResourceNameType.class)
|
||||||
public class NamedResourceTest {
|
public class NamedResourceTest {
|
||||||
|
|
||||||
@Resource(name="namedFile")
|
@Resource(name = "namedFile")
|
||||||
private File testFile;
|
private File testFile;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void namedResource_MUST_FIND_SPECIFIED_File() {
|
public void givenResourceAnnotation_WhenOnField_THEN_DEPENDENCY_Found() {
|
||||||
assertNotNull(testFile);
|
assertNotNull(testFile);
|
||||||
assertTrue(testFile.getName().equals("namedFile.txt"));
|
assertEquals("namedFile.txt", testFile.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.baeldung.resource;
|
||||||
|
|
||||||
|
import com.baeldung.configuration.ApplicationContextTestResourceQualifier;
|
||||||
|
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 javax.annotation.Resource;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
@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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,20 +1,22 @@
|
||||||
package com.baeldung.resource;
|
package com.baeldung.resource;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import com.baeldung.configuration.ApplicationContextTestResourceNameType;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(locations={
|
@ContextConfiguration(loader = AnnotationConfigContextLoader.class,
|
||||||
"/applicationContextTest-@Resource-NameType.xml"})
|
classes = ApplicationContextTestResourceNameType.class)
|
||||||
public class MethodByTypeResourceDemo {
|
public class SetterResourceInjectionTest {
|
||||||
|
|
||||||
private File defaultFile;
|
private File defaultFile;
|
||||||
|
|
||||||
|
@ -24,7 +26,8 @@ public class MethodByTypeResourceDemo {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultFile_MUST_BE_INJECTED_Correctly() {
|
public void givenResourceAnnotation_WhenOnSetter_THEN_MUST_INJECT_Dependency() {
|
||||||
assertNotNull(defaultFile);
|
assertNotNull(defaultFile);
|
||||||
|
assertEquals("namedFile.txt", defaultFile.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,12 +0,0 @@
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:context="http://www.springframework.org/schema/context"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
|
||||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
|
||||||
http://www.springframework.org/schema/context
|
|
||||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
|
||||||
|
|
||||||
<bean id="autowiredFieldDependency" class="com.baeldung.dependency.ArbitraryDependency"/>
|
|
||||||
|
|
||||||
<bean id="anotherAutowiredFieldDependency" class="com.baeldung.dependency.AnotherArbitraryDependency"/>
|
|
||||||
</beans>
|
|
|
@ -1,12 +0,0 @@
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:context="http://www.springframework.org/schema/context"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
|
||||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
|
||||||
http://www.springframework.org/schema/context
|
|
||||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
|
||||||
|
|
||||||
<bean id="autowiredFieldDependency" class="com.baeldung.dependency.ArbitraryDependency"/>
|
|
||||||
|
|
||||||
<bean id="anotherAutowiredFieldDependency" class="com.baeldung.dependency.AnotherArbitraryDependency"/>
|
|
||||||
</beans>
|
|
|
@ -1,10 +0,0 @@
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:context="http://www.springframework.org/schema/context"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
|
||||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
|
||||||
http://www.springframework.org/schema/context
|
|
||||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
|
||||||
|
|
||||||
<bean id="autowiredFieldDependency" class="com.baeldung.dependency.ArbitraryDependency"/>
|
|
||||||
</beans>
|
|
|
@ -1,11 +0,0 @@
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:context="http://www.springframework.org/schema/context"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
|
||||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
|
||||||
http://www.springframework.org/schema/context
|
|
||||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
|
||||||
|
|
||||||
<bean id="yetAnotherFieldInjectDependency" class="com.baeldung.dependency.YetAnotherArbitraryDependency"/>
|
|
||||||
|
|
||||||
</beans>
|
|
|
@ -1,12 +0,0 @@
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:context="http://www.springframework.org/schema/context"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
|
||||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
|
||||||
http://www.springframework.org/schema/context
|
|
||||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
|
||||||
|
|
||||||
<bean id="defaultFile" class="com.baeldung.dependency.ArbitraryDependency"/>
|
|
||||||
|
|
||||||
<bean id="namedFile" class="com.baeldung.dependency.AnotherArbitraryDependency"/>
|
|
||||||
</beans>
|
|
|
@ -1,10 +0,0 @@
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:context="http://www.springframework.org/schema/context"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
|
||||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
|
||||||
http://www.springframework.org/schema/context
|
|
||||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
|
||||||
|
|
||||||
<bean id="injectDependency" class="com.baeldung.dependency.ArbitraryDependency"/>
|
|
||||||
</beans>
|
|
|
@ -1,12 +0,0 @@
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:context="http://www.springframework.org/schema/context"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
|
||||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
|
||||||
http://www.springframework.org/schema/context
|
|
||||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
|
||||||
|
|
||||||
<bean id="namedFile" class="java.io.File">
|
|
||||||
<constructor-arg value="namedFile.txt"/>
|
|
||||||
</bean>
|
|
||||||
</beans>
|
|
|
@ -1,16 +0,0 @@
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:context="http://www.springframework.org/schema/context"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
|
||||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
|
||||||
http://www.springframework.org/schema/context
|
|
||||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
|
||||||
|
|
||||||
<bean id="defaultFile" class="java.io.File">
|
|
||||||
<constructor-arg value="defaultFile.txt"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<bean id="namedFile" class="java.io.File">
|
|
||||||
<constructor-arg value="namedFile.txt"/>
|
|
||||||
</bean>
|
|
||||||
</beans>
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package org.baeldung.hamcrest;
|
||||||
|
|
||||||
|
public class Animal {
|
||||||
|
String name;
|
||||||
|
boolean wild;
|
||||||
|
String sound;
|
||||||
|
|
||||||
|
public Animal(String name, boolean wild, String sound) {
|
||||||
|
super();
|
||||||
|
this.name = name;
|
||||||
|
this.wild = wild;
|
||||||
|
this.sound = sound;
|
||||||
|
}
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
public boolean isWild() {
|
||||||
|
return wild;
|
||||||
|
}
|
||||||
|
public void setWild(boolean wild) {
|
||||||
|
this.wild = wild;
|
||||||
|
}
|
||||||
|
public String getSound() {
|
||||||
|
return sound;
|
||||||
|
}
|
||||||
|
public void setSound(String sound) {
|
||||||
|
this.sound = sound;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package org.baeldung.hamcrest;
|
||||||
|
|
||||||
|
public class Cat extends Animal {
|
||||||
|
|
||||||
|
public Cat() {
|
||||||
|
super("cat", false, "meow");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String makeSound() {
|
||||||
|
return getSound();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,340 @@
|
||||||
|
package org.baeldung.hamcrest;
|
||||||
|
|
||||||
|
import static org.baeldung.hamcrest.IsPositiveInteger.isAPositiveInteger;
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.hamcrest.Matchers.greaterThan;
|
||||||
|
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||||
|
import static org.hamcrest.Matchers.lessThan;
|
||||||
|
import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
||||||
|
import static org.hamcrest.Matchers.closeTo;
|
||||||
|
import static org.hamcrest.beans.HasProperty.hasProperty;
|
||||||
|
import static org.hamcrest.beans.HasPropertyWithValue.hasProperty;
|
||||||
|
import static org.hamcrest.beans.SamePropertyValuesAs.samePropertyValuesAs;
|
||||||
|
import static org.hamcrest.collection.IsArrayContaining.hasItemInArray;
|
||||||
|
import static org.hamcrest.collection.IsArrayContainingInAnyOrder.arrayContainingInAnyOrder;
|
||||||
|
import static org.hamcrest.collection.IsArrayContainingInOrder.arrayContaining;
|
||||||
|
import static org.hamcrest.collection.IsArrayWithSize.arrayWithSize;
|
||||||
|
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
|
||||||
|
import static org.hamcrest.collection.IsEmptyCollection.empty;
|
||||||
|
import static org.hamcrest.collection.IsIn.isIn;
|
||||||
|
import static org.hamcrest.collection.IsIn.isOneOf;
|
||||||
|
import static org.hamcrest.collection.IsMapContaining.hasKey;
|
||||||
|
import static org.hamcrest.collection.IsMapContaining.hasEntry;
|
||||||
|
import static org.hamcrest.collection.IsMapContaining.hasValue;
|
||||||
|
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
|
||||||
|
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
|
||||||
|
import static org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase;
|
||||||
|
import static org.hamcrest.text.IsEmptyString.isEmptyOrNullString;
|
||||||
|
import static org.hamcrest.text.IsEmptyString.isEmptyString;
|
||||||
|
import static org.hamcrest.text.IsEqualIgnoringWhiteSpace.equalToIgnoringWhiteSpace;
|
||||||
|
import static org.hamcrest.text.StringContainsInOrder.stringContainsInOrder;
|
||||||
|
import static org.hamcrest.object.HasToString.hasToString;
|
||||||
|
import static org.hamcrest.object.IsCompatibleType.typeCompatibleWith;
|
||||||
|
import static org.hamcrest.core.AllOf.allOf;
|
||||||
|
import static org.hamcrest.core.AnyOf.anyOf;
|
||||||
|
import static org.hamcrest.core.Every.everyItem;
|
||||||
|
import static org.hamcrest.core.Is.is;//class
|
||||||
|
import static org.hamcrest.core.IsInstanceOf.instanceOf;
|
||||||
|
import static org.hamcrest.core.IsNot.not;//matcher
|
||||||
|
import static org.hamcrest.core.IsNull.notNullValue;//without arg
|
||||||
|
import static org.hamcrest.core.IsSame.sameInstance;
|
||||||
|
import static org.hamcrest.core.StringContains.containsString;
|
||||||
|
import static org.hamcrest.core.StringEndsWith.endsWith;
|
||||||
|
import static org.hamcrest.core.StringStartsWith.startsWith;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class HamcrestMatcherTest {
|
||||||
|
@Test
|
||||||
|
public void given2Strings_whenEqual_thenCorrect() {
|
||||||
|
String a = "foo";
|
||||||
|
String b = "FOO";
|
||||||
|
assertThat(a, equalToIgnoringCase(b));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenBean_whenHasValue_thenCorrect() {
|
||||||
|
Person person = new Person("Baeldung", "New York");
|
||||||
|
assertThat(person, hasProperty("name"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenBean_whenHasCorrectValue_thenCorrect() {
|
||||||
|
Person person = new Person("Baeldung", "New York");
|
||||||
|
assertThat(person, hasProperty("address", equalTo("New York")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void given2Beans_whenHavingSameValues_thenCorrect() {
|
||||||
|
Person person1 = new Person("Baeldung", "New York");
|
||||||
|
Person person2 = new Person("Baeldung", "New York");
|
||||||
|
assertThat(person1, samePropertyValuesAs(person2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAList_whenChecksSize_thenCorrect() {
|
||||||
|
List<String> hamcrestMatchers = Arrays.asList("collections", "beans",
|
||||||
|
"text", "number");
|
||||||
|
assertThat(hamcrestMatchers, hasSize(4));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenArray_whenChecksSize_thenCorrect() {
|
||||||
|
String[] hamcrestMatchers = { "collections", "beans", "text", "number" };
|
||||||
|
assertThat(hamcrestMatchers, arrayWithSize(4));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAListAndValues_whenChecksListForGivenValues_thenCorrect() {
|
||||||
|
List<String> hamcrestMatchers = Arrays.asList("collections", "beans",
|
||||||
|
"text", "number");
|
||||||
|
assertThat(hamcrestMatchers,
|
||||||
|
containsInAnyOrder("beans", "text", "collections", "number"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAListAndValues_whenChecksListForGivenValuesWithOrder_thenCorrect() {
|
||||||
|
List<String> hamcrestMatchers = Arrays.asList("collections", "beans",
|
||||||
|
"text", "number");
|
||||||
|
assertThat(hamcrestMatchers,
|
||||||
|
contains("collections", "beans", "text", "number"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenArrayAndValue_whenValueFoundInArray_thenCorrect() {
|
||||||
|
String[] hamcrestMatchers = { "collections", "beans", "text", "number" };
|
||||||
|
assertThat(hamcrestMatchers, hasItemInArray("text"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenValueAndArray_whenValueIsOneOfArrayElements_thenCorrect() {
|
||||||
|
String[] hamcrestMatchers = { "collections", "beans", "text", "number" };
|
||||||
|
assertThat("text", isOneOf(hamcrestMatchers));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenArrayAndValues_whenValuesFoundInArray_thenCorrect() {
|
||||||
|
String[] hamcrestMatchers = { "collections", "beans", "text", "number" };
|
||||||
|
assertThat(
|
||||||
|
hamcrestMatchers,
|
||||||
|
arrayContainingInAnyOrder("beans", "collections", "number",
|
||||||
|
"text"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenArrayAndValues_whenValuesFoundInArrayInOrder_thenCorrect() {
|
||||||
|
String[] hamcrestMatchers = { "collections", "beans", "text", "number" };
|
||||||
|
assertThat(hamcrestMatchers,
|
||||||
|
arrayContaining("collections", "beans", "text", "number"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenCollection_whenEmpty_thenCorrect() {
|
||||||
|
List<String> emptyList = new ArrayList<>();
|
||||||
|
assertThat(emptyList, empty());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenValueAndArray_whenValueFoundInArray_thenCorrect() {
|
||||||
|
String[] array = new String[] { "collections", "beans", "text",
|
||||||
|
"number" };
|
||||||
|
assertThat("bean", isIn(array));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenMapAndKey_whenKeyFoundInMap_thenCorrect() {
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
map.put("blogname", "baeldung");
|
||||||
|
assertThat(map, hasKey("blogname"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenMapAndEntry_whenEntryFoundInMap_thenCorrect() {
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
map.put("blogname", "baeldung");
|
||||||
|
assertThat(map, hasEntry("blogname", "baeldung"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenMapAndValue_whenValueFoundInMap_thenCorrect() {
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
map.put("blogname", "baeldung");
|
||||||
|
assertThat(map, hasValue("baeldung"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenString_whenEmpty_thenCorrect() {
|
||||||
|
String str = "";
|
||||||
|
assertThat(str, isEmptyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenString_whenEmptyOrNull_thenCorrect() {
|
||||||
|
String str = null;
|
||||||
|
assertThat(str, isEmptyOrNullString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void given2Strings_whenEqualRegardlessWhiteSpace_thenCorrect() {
|
||||||
|
String str1 = "text";
|
||||||
|
String str2 = " text ";
|
||||||
|
assertThat(str1, equalToIgnoringWhiteSpace(str2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenString_whenContainsGivenSubstring_thenCorrect() {
|
||||||
|
String str = "calligraphy";
|
||||||
|
assertThat(str, stringContainsInOrder(Arrays.asList("call", "graph")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenBean_whenToStringReturnsRequiredString_thenCorrect() {
|
||||||
|
Person person = new Person("Barrack", "Washington");
|
||||||
|
String str = person.toString();
|
||||||
|
assertThat(person, hasToString(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void given2Classes_whenOneInheritsFromOther_thenCorrect() {
|
||||||
|
assertThat(Cat.class, typeCompatibleWith(Animal.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void given2Strings_whenIsEqualRegardlessWhiteSpace_thenCorrect() {
|
||||||
|
String str1 = "text";
|
||||||
|
String str2 = " text ";
|
||||||
|
assertThat(str1, is(equalToIgnoringWhiteSpace(str2)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void given2Strings_whenIsNotEqualRegardlessWhiteSpace_thenCorrect() {
|
||||||
|
String str1 = "text";
|
||||||
|
String str2 = " texts ";
|
||||||
|
assertThat(str1, not(equalToIgnoringWhiteSpace(str2)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void given2Strings_whenNotEqual_thenCorrect() {
|
||||||
|
String str1 = "text";
|
||||||
|
String str2 = "texts";
|
||||||
|
assertThat(str1, not(str2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void given2Strings_whenIsEqual_thenCorrect() {
|
||||||
|
String str1 = "text";
|
||||||
|
String str2 = "text";
|
||||||
|
assertThat(str1, is(str2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAStrings_whenContainsAnotherGivenString_thenCorrect() {
|
||||||
|
String str1 = "calligraphy";
|
||||||
|
String str2 = "call";
|
||||||
|
assertThat(str1, containsString(str2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAString_whenEndsWithAnotherGivenString_thenCorrect() {
|
||||||
|
String str1 = "calligraphy";
|
||||||
|
String str2 = "phy";
|
||||||
|
assertThat(str1, endsWith(str2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAString_whenStartsWithAnotherGivenString_thenCorrect() {
|
||||||
|
String str1 = "calligraphy";
|
||||||
|
String str2 = "call";
|
||||||
|
assertThat(str1, startsWith(str2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void given2Objects_whenSameInstance_thenCorrect() {
|
||||||
|
Cat cat = new Cat();
|
||||||
|
assertThat(cat, sameInstance(cat));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAnObject_whenInstanceOfGivenClass_thenCorrect() {
|
||||||
|
Cat cat = new Cat();
|
||||||
|
assertThat(cat, instanceOf(Cat.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenList_whenEachElementGreaterThan0_thenCorrect() {
|
||||||
|
List<Integer> list = Arrays.asList(1, 2, 3);
|
||||||
|
int baseCase = 0;
|
||||||
|
assertThat(list, everyItem(greaterThan(baseCase)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenString_whenNotNull_thenCorrect() {
|
||||||
|
String str = "notnull";
|
||||||
|
assertThat(str, notNullValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenString_whenMeetsAnyOfGivenConditions_thenCorrect() {
|
||||||
|
String str = "calligraphy";
|
||||||
|
String start = "call";
|
||||||
|
String end = "foo";
|
||||||
|
assertThat(str, anyOf(startsWith(start), containsString(end)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenString_whenMeetsAllOfGivenConditions_thenCorrect() {
|
||||||
|
String str = "calligraphy";
|
||||||
|
String start = "call";
|
||||||
|
String end = "foo";
|
||||||
|
assertThat(str, allOf(startsWith(start), endsWith(end)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenInteger_whenAPositiveValue_thenCorrect() {
|
||||||
|
int num = 1;
|
||||||
|
assertThat(num, isAPositiveInteger());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAnInteger_whenGreaterThan0_thenCorrect() {
|
||||||
|
int num = 1;
|
||||||
|
assertThat(num, greaterThan(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAnInteger_whenGreaterThanOrEqTo5_thenCorrect() {
|
||||||
|
int num = 5;
|
||||||
|
assertThat(num, greaterThanOrEqualTo(5));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAnInteger_whenLessThan0_thenCorrect() {
|
||||||
|
int num = -1;
|
||||||
|
assertThat(num, lessThan(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAnInteger_whenLessThanOrEqTo5_thenCorrect() {
|
||||||
|
assertThat(-1, lessThanOrEqualTo(5));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenADouble_whenCloseTo_thenCorrect() {
|
||||||
|
assertThat(1.2, closeTo(1, 0.5));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package org.baeldung.hamcrest;
|
||||||
|
|
||||||
|
import org.hamcrest.Description;
|
||||||
|
import org.hamcrest.Factory;
|
||||||
|
import org.hamcrest.Matcher;
|
||||||
|
import org.hamcrest.TypeSafeMatcher;
|
||||||
|
|
||||||
|
public class IsPositiveInteger extends TypeSafeMatcher<Integer> {
|
||||||
|
|
||||||
|
public void describeTo(Description description) {
|
||||||
|
description.appendText("a positive integer");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Factory
|
||||||
|
public static Matcher<Integer> isAPositiveInteger() {
|
||||||
|
return new IsPositiveInteger();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean matchesSafely(Integer integer) {
|
||||||
|
return integer > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package org.baeldung.hamcrest;
|
||||||
|
|
||||||
|
public class Person {
|
||||||
|
String name;
|
||||||
|
String address;
|
||||||
|
|
||||||
|
public Person(String personName, String personAddress) {
|
||||||
|
name = personName;
|
||||||
|
address = personAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAddress() {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddress(String address) {
|
||||||
|
this.address = address;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String str="[address:"+address+",name:"+name+"]";
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,7 +1,9 @@
|
||||||
=========
|
=========
|
||||||
|
|
||||||
## HttpClient 4.x Cookbooks and Examples
|
## HttpClient 4.x Cookbooks and Examples
|
||||||
|
|
||||||
|
###The Course
|
||||||
|
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||||
|
|
||||||
|
|
||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
## Jackson Cookbooks and Examples
|
## Jackson Cookbooks and Examples
|
||||||
|
|
||||||
|
###The Course
|
||||||
|
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||||
|
|
||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
- [Jackson Ignore Properties on Marshalling](http://www.baeldung.com/jackson-ignore-properties-on-serialization)
|
- [Jackson Ignore Properties on Marshalling](http://www.baeldung.com/jackson-ignore-properties-on-serialization)
|
||||||
- [Jackson – Unmarshall to Collection/Array](http://www.baeldung.com/jackson-collection-array)
|
- [Jackson – Unmarshall to Collection/Array](http://www.baeldung.com/jackson-collection-array)
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
###The Course
|
||||||
|
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
## REST Testing and Examples
|
## REST Testing and Examples
|
||||||
|
|
||||||
|
###The Course
|
||||||
|
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||||
|
|
||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
- [Test a REST API with Java](http://www.baeldung.com/2011/10/13/integration-testing-a-rest-api/)
|
- [Test a REST API with Java](http://www.baeldung.com/2011/10/13/integration-testing-a-rest-api/)
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
This project is used to replicate Spring Exceptions only.
|
This project is used to replicate Spring Exceptions only.
|
||||||
|
|
||||||
|
###The Course
|
||||||
|
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||||
|
|
||||||
### Relevant articles:
|
### Relevant articles:
|
||||||
- [Properties with Spring](http://www.baeldung.com/2012/02/06/properties-with-spring) - checkout the `org.baeldung.properties` package for all scenarios of properties injection and usage
|
- [Properties with Spring](http://www.baeldung.com/2012/02/06/properties-with-spring) - checkout the `org.baeldung.properties` package for all scenarios of properties injection and usage
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
###The Course
|
||||||
|
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
|
@ -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
|
||||||
|
```
|
||||||
|
|
|
@ -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>
|
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -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> {
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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>
|
After Width: | Height: | Size: 855 B |
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,6 @@
|
||||||
|
###The Course
|
||||||
|
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||||
|
|
||||||
# About this project
|
# About this project
|
||||||
This project contains examples from the [Introduction to Spring Data REST](http://www.baeldung.com/spring-data-rest-intro) article from Baeldung.
|
This project contains examples from the [Introduction to Spring Data REST](http://www.baeldung.com/spring-data-rest-intro) article from Baeldung.
|
||||||
|
|
||||||
|
|
|
@ -2,5 +2,8 @@
|
||||||
|
|
||||||
## Java Web Application
|
## Java Web Application
|
||||||
|
|
||||||
|
###The Course
|
||||||
|
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||||
|
|
||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
- [JSON API in a Java Web Application](http://www.baeldung.com/json-api-java-spring-web-app)
|
- [JSON API in a Java Web Application](http://www.baeldung.com/json-api-java-spring-web-app)
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
## Spring MVC with Java Configuration Example Project
|
## Spring MVC with Java Configuration Example Project
|
||||||
|
|
||||||
|
###The Course
|
||||||
|
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||||
|
|
||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
- [Spring Bean Annotations](http://www.baeldung.com/spring-bean-annotations)
|
- [Spring Bean Annotations](http://www.baeldung.com/spring-bean-annotations)
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
## Spring MVC with NO XML Configuration Example Project
|
## Spring MVC with NO XML Configuration Example Project
|
||||||
|
|
||||||
|
###The Course
|
||||||
|
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||||
|
|
||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
-
|
-
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
###The Course
|
||||||
|
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||||
|
|
||||||
## Spring MVC with XML Configuration Example Project
|
## Spring MVC with XML Configuration Example Project
|
||||||
- access a sample jsp page at: `http://localhost:8080/spring-mvc-xml/sample.html`
|
- access a sample jsp page at: `http://localhost:8080/spring-mvc-xml/sample.html`
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
###The Course
|
||||||
|
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
## Spring REST Example Project
|
## Spring REST Example Project
|
||||||
|
|
||||||
|
###The Course
|
||||||
|
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||||
|
|
||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
- [Spring @RequestMapping](http://www.baeldung.com/spring-requestmapping)
|
- [Spring @RequestMapping](http://www.baeldung.com/spring-requestmapping)
|
||||||
|
|
|
@ -146,6 +146,17 @@
|
||||||
<artifactId>spring-test</artifactId>
|
<artifactId>spring-test</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.protobuf</groupId>
|
||||||
|
<artifactId>protobuf-java</artifactId>
|
||||||
|
<version>2.6.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.esotericsoftware.kryo</groupId>
|
||||||
|
<artifactId>kryo</artifactId>
|
||||||
|
<version>2.24.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -254,4 +265,4 @@
|
||||||
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -3,11 +3,13 @@ package org.baeldung.config;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.baeldung.config.converter.KryoHttpMessageConverter;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
|
import org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter;
|
||||||
import org.springframework.http.converter.xml.MarshallingHttpMessageConverter;
|
import org.springframework.http.converter.xml.MarshallingHttpMessageConverter;
|
||||||
import org.springframework.oxm.xstream.XStreamMarshaller;
|
import org.springframework.oxm.xstream.XStreamMarshaller;
|
||||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||||
|
@ -33,7 +35,8 @@ public class WebConfig extends WebMvcConfigurerAdapter {
|
||||||
builder.indentOutput(true).dateFormat(new SimpleDateFormat("dd-MM-yyyy hh:mm"));
|
builder.indentOutput(true).dateFormat(new SimpleDateFormat("dd-MM-yyyy hh:mm"));
|
||||||
messageConverters.add(new MappingJackson2HttpMessageConverter(builder.build()));
|
messageConverters.add(new MappingJackson2HttpMessageConverter(builder.build()));
|
||||||
// messageConverters.add(new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build()));
|
// messageConverters.add(new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build()));
|
||||||
|
messageConverters.add(new ProtobufHttpMessageConverter());
|
||||||
|
messageConverters.add(new KryoHttpMessageConverter());
|
||||||
super.configureMessageConverters(messageConverters);
|
super.configureMessageConverters(messageConverters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
package org.baeldung.config.converter;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.baeldung.web.dto.Foo;
|
||||||
|
import org.springframework.http.HttpInputMessage;
|
||||||
|
import org.springframework.http.HttpOutputMessage;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.converter.AbstractHttpMessageConverter;
|
||||||
|
|
||||||
|
import com.esotericsoftware.kryo.Kryo;
|
||||||
|
import com.esotericsoftware.kryo.io.Input;
|
||||||
|
import com.esotericsoftware.kryo.io.Output;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An {@code HttpMessageConverter} that can read and write Kryo messages.
|
||||||
|
*/
|
||||||
|
public class KryoHttpMessageConverter extends AbstractHttpMessageConverter<Object> {
|
||||||
|
|
||||||
|
public static final MediaType KRYO = new MediaType("application", "x-kryo");
|
||||||
|
|
||||||
|
private static final ThreadLocal<Kryo> kryoThreadLocal = new ThreadLocal<Kryo>() {
|
||||||
|
@Override
|
||||||
|
protected Kryo initialValue() {
|
||||||
|
final Kryo kryo = new Kryo();
|
||||||
|
kryo.register(Foo.class, 1);
|
||||||
|
return kryo;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public KryoHttpMessageConverter() {
|
||||||
|
super(KRYO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean supports(final Class<?> clazz) {
|
||||||
|
return Object.class.isAssignableFrom(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object readInternal(final Class<? extends Object> clazz, final HttpInputMessage inputMessage) throws IOException {
|
||||||
|
final Input input = new Input(inputMessage.getBody());
|
||||||
|
return kryoThreadLocal.get().readClassAndObject(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void writeInternal(final Object object, final HttpOutputMessage outputMessage) throws IOException {
|
||||||
|
final Output output = new Output(outputMessage.getBody());
|
||||||
|
kryoThreadLocal.get().writeClassAndObject(output, object);
|
||||||
|
output.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected MediaType getDefaultContentType(final Object object) {
|
||||||
|
return KRYO;
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
|
||||||
import static org.apache.commons.lang3.RandomStringUtils.randomNumeric;
|
import static org.apache.commons.lang3.RandomStringUtils.randomNumeric;
|
||||||
|
|
||||||
import org.baeldung.web.dto.Foo;
|
import org.baeldung.web.dto.Foo;
|
||||||
|
import org.baeldung.web.dto.FooProtos;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
@ -38,4 +39,9 @@ public class FooController {
|
||||||
return foo;
|
return foo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.GET, value = "/foos/{id}", produces = { "application/x-protobuf" })
|
||||||
|
@ResponseBody
|
||||||
|
public FooProtos.Foo findProtoById(@PathVariable final long id) {
|
||||||
|
return FooProtos.Foo.newBuilder().setId(1).setName("Foo Name").build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,620 @@
|
||||||
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||||
|
// source: FooProtos.proto
|
||||||
|
|
||||||
|
package org.baeldung.web.dto;
|
||||||
|
|
||||||
|
public final class FooProtos {
|
||||||
|
private FooProtos() {}
|
||||||
|
public static void registerAllExtensions(
|
||||||
|
com.google.protobuf.ExtensionRegistry registry) {
|
||||||
|
}
|
||||||
|
public interface FooOrBuilder extends
|
||||||
|
// @@protoc_insertion_point(interface_extends:baeldung.Foo)
|
||||||
|
com.google.protobuf.MessageOrBuilder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <code>required int64 id = 1;</code>
|
||||||
|
*/
|
||||||
|
boolean hasId();
|
||||||
|
/**
|
||||||
|
* <code>required int64 id = 1;</code>
|
||||||
|
*/
|
||||||
|
long getId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <code>required string name = 2;</code>
|
||||||
|
*/
|
||||||
|
boolean hasName();
|
||||||
|
/**
|
||||||
|
* <code>required string name = 2;</code>
|
||||||
|
*/
|
||||||
|
java.lang.String getName();
|
||||||
|
/**
|
||||||
|
* <code>required string name = 2;</code>
|
||||||
|
*/
|
||||||
|
com.google.protobuf.ByteString
|
||||||
|
getNameBytes();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Protobuf type {@code baeldung.Foo}
|
||||||
|
*/
|
||||||
|
public static final class Foo extends
|
||||||
|
com.google.protobuf.GeneratedMessage implements
|
||||||
|
// @@protoc_insertion_point(message_implements:baeldung.Foo)
|
||||||
|
FooOrBuilder {
|
||||||
|
// Use Foo.newBuilder() to construct.
|
||||||
|
private Foo(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
|
||||||
|
super(builder);
|
||||||
|
this.unknownFields = builder.getUnknownFields();
|
||||||
|
}
|
||||||
|
private Foo(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }
|
||||||
|
|
||||||
|
private static final Foo defaultInstance;
|
||||||
|
public static Foo getDefaultInstance() {
|
||||||
|
return defaultInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Foo getDefaultInstanceForType() {
|
||||||
|
return defaultInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final com.google.protobuf.UnknownFieldSet unknownFields;
|
||||||
|
@java.lang.Override
|
||||||
|
public final com.google.protobuf.UnknownFieldSet
|
||||||
|
getUnknownFields() {
|
||||||
|
return this.unknownFields;
|
||||||
|
}
|
||||||
|
private Foo(
|
||||||
|
com.google.protobuf.CodedInputStream input,
|
||||||
|
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||||
|
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||||
|
initFields();
|
||||||
|
int mutable_bitField0_ = 0;
|
||||||
|
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
|
||||||
|
com.google.protobuf.UnknownFieldSet.newBuilder();
|
||||||
|
try {
|
||||||
|
boolean done = false;
|
||||||
|
while (!done) {
|
||||||
|
int tag = input.readTag();
|
||||||
|
switch (tag) {
|
||||||
|
case 0:
|
||||||
|
done = true;
|
||||||
|
break;
|
||||||
|
default: {
|
||||||
|
if (!parseUnknownField(input, unknownFields,
|
||||||
|
extensionRegistry, tag)) {
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 8: {
|
||||||
|
bitField0_ |= 0x00000001;
|
||||||
|
id_ = input.readInt64();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 18: {
|
||||||
|
com.google.protobuf.ByteString bs = input.readBytes();
|
||||||
|
bitField0_ |= 0x00000002;
|
||||||
|
name_ = bs;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
||||||
|
throw e.setUnfinishedMessage(this);
|
||||||
|
} catch (java.io.IOException e) {
|
||||||
|
throw new com.google.protobuf.InvalidProtocolBufferException(
|
||||||
|
e.getMessage()).setUnfinishedMessage(this);
|
||||||
|
} finally {
|
||||||
|
this.unknownFields = unknownFields.build();
|
||||||
|
makeExtensionsImmutable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static final com.google.protobuf.Descriptors.Descriptor
|
||||||
|
getDescriptor() {
|
||||||
|
return org.baeldung.web.dto.FooProtos.internal_static_baeldung_Foo_descriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
|
||||||
|
internalGetFieldAccessorTable() {
|
||||||
|
return org.baeldung.web.dto.FooProtos.internal_static_baeldung_Foo_fieldAccessorTable
|
||||||
|
.ensureFieldAccessorsInitialized(
|
||||||
|
org.baeldung.web.dto.FooProtos.Foo.class, org.baeldung.web.dto.FooProtos.Foo.Builder.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static com.google.protobuf.Parser<Foo> PARSER =
|
||||||
|
new com.google.protobuf.AbstractParser<Foo>() {
|
||||||
|
public Foo parsePartialFrom(
|
||||||
|
com.google.protobuf.CodedInputStream input,
|
||||||
|
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||||
|
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||||
|
return new Foo(input, extensionRegistry);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@java.lang.Override
|
||||||
|
public com.google.protobuf.Parser<Foo> getParserForType() {
|
||||||
|
return PARSER;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int bitField0_;
|
||||||
|
public static final int ID_FIELD_NUMBER = 1;
|
||||||
|
private long id_;
|
||||||
|
/**
|
||||||
|
* <code>required int64 id = 1;</code>
|
||||||
|
*/
|
||||||
|
public boolean hasId() {
|
||||||
|
return ((bitField0_ & 0x00000001) == 0x00000001);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* <code>required int64 id = 1;</code>
|
||||||
|
*/
|
||||||
|
public long getId() {
|
||||||
|
return id_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final int NAME_FIELD_NUMBER = 2;
|
||||||
|
private java.lang.Object name_;
|
||||||
|
/**
|
||||||
|
* <code>required string name = 2;</code>
|
||||||
|
*/
|
||||||
|
public boolean hasName() {
|
||||||
|
return ((bitField0_ & 0x00000002) == 0x00000002);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* <code>required string name = 2;</code>
|
||||||
|
*/
|
||||||
|
public java.lang.String getName() {
|
||||||
|
java.lang.Object ref = name_;
|
||||||
|
if (ref instanceof java.lang.String) {
|
||||||
|
return (java.lang.String) ref;
|
||||||
|
} else {
|
||||||
|
com.google.protobuf.ByteString bs =
|
||||||
|
(com.google.protobuf.ByteString) ref;
|
||||||
|
java.lang.String s = bs.toStringUtf8();
|
||||||
|
if (bs.isValidUtf8()) {
|
||||||
|
name_ = s;
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* <code>required string name = 2;</code>
|
||||||
|
*/
|
||||||
|
public com.google.protobuf.ByteString
|
||||||
|
getNameBytes() {
|
||||||
|
java.lang.Object ref = name_;
|
||||||
|
if (ref instanceof java.lang.String) {
|
||||||
|
com.google.protobuf.ByteString b =
|
||||||
|
com.google.protobuf.ByteString.copyFromUtf8(
|
||||||
|
(java.lang.String) ref);
|
||||||
|
name_ = b;
|
||||||
|
return b;
|
||||||
|
} else {
|
||||||
|
return (com.google.protobuf.ByteString) ref;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initFields() {
|
||||||
|
id_ = 0L;
|
||||||
|
name_ = "";
|
||||||
|
}
|
||||||
|
private byte memoizedIsInitialized = -1;
|
||||||
|
public final boolean isInitialized() {
|
||||||
|
byte isInitialized = memoizedIsInitialized;
|
||||||
|
if (isInitialized == 1) return true;
|
||||||
|
if (isInitialized == 0) return false;
|
||||||
|
|
||||||
|
if (!hasId()) {
|
||||||
|
memoizedIsInitialized = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!hasName()) {
|
||||||
|
memoizedIsInitialized = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
memoizedIsInitialized = 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeTo(com.google.protobuf.CodedOutputStream output)
|
||||||
|
throws java.io.IOException {
|
||||||
|
getSerializedSize();
|
||||||
|
if (((bitField0_ & 0x00000001) == 0x00000001)) {
|
||||||
|
output.writeInt64(1, id_);
|
||||||
|
}
|
||||||
|
if (((bitField0_ & 0x00000002) == 0x00000002)) {
|
||||||
|
output.writeBytes(2, getNameBytes());
|
||||||
|
}
|
||||||
|
getUnknownFields().writeTo(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int memoizedSerializedSize = -1;
|
||||||
|
public int getSerializedSize() {
|
||||||
|
int size = memoizedSerializedSize;
|
||||||
|
if (size != -1) return size;
|
||||||
|
|
||||||
|
size = 0;
|
||||||
|
if (((bitField0_ & 0x00000001) == 0x00000001)) {
|
||||||
|
size += com.google.protobuf.CodedOutputStream
|
||||||
|
.computeInt64Size(1, id_);
|
||||||
|
}
|
||||||
|
if (((bitField0_ & 0x00000002) == 0x00000002)) {
|
||||||
|
size += com.google.protobuf.CodedOutputStream
|
||||||
|
.computeBytesSize(2, getNameBytes());
|
||||||
|
}
|
||||||
|
size += getUnknownFields().getSerializedSize();
|
||||||
|
memoizedSerializedSize = size;
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 0L;
|
||||||
|
@java.lang.Override
|
||||||
|
protected java.lang.Object writeReplace()
|
||||||
|
throws java.io.ObjectStreamException {
|
||||||
|
return super.writeReplace();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(
|
||||||
|
com.google.protobuf.ByteString data)
|
||||||
|
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||||
|
return PARSER.parseFrom(data);
|
||||||
|
}
|
||||||
|
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(
|
||||||
|
com.google.protobuf.ByteString data,
|
||||||
|
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||||
|
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||||
|
return PARSER.parseFrom(data, extensionRegistry);
|
||||||
|
}
|
||||||
|
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(byte[] data)
|
||||||
|
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||||
|
return PARSER.parseFrom(data);
|
||||||
|
}
|
||||||
|
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(
|
||||||
|
byte[] data,
|
||||||
|
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||||
|
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||||
|
return PARSER.parseFrom(data, extensionRegistry);
|
||||||
|
}
|
||||||
|
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(java.io.InputStream input)
|
||||||
|
throws java.io.IOException {
|
||||||
|
return PARSER.parseFrom(input);
|
||||||
|
}
|
||||||
|
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(
|
||||||
|
java.io.InputStream input,
|
||||||
|
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||||
|
throws java.io.IOException {
|
||||||
|
return PARSER.parseFrom(input, extensionRegistry);
|
||||||
|
}
|
||||||
|
public static org.baeldung.web.dto.FooProtos.Foo parseDelimitedFrom(java.io.InputStream input)
|
||||||
|
throws java.io.IOException {
|
||||||
|
return PARSER.parseDelimitedFrom(input);
|
||||||
|
}
|
||||||
|
public static org.baeldung.web.dto.FooProtos.Foo parseDelimitedFrom(
|
||||||
|
java.io.InputStream input,
|
||||||
|
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||||
|
throws java.io.IOException {
|
||||||
|
return PARSER.parseDelimitedFrom(input, extensionRegistry);
|
||||||
|
}
|
||||||
|
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(
|
||||||
|
com.google.protobuf.CodedInputStream input)
|
||||||
|
throws java.io.IOException {
|
||||||
|
return PARSER.parseFrom(input);
|
||||||
|
}
|
||||||
|
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(
|
||||||
|
com.google.protobuf.CodedInputStream input,
|
||||||
|
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||||
|
throws java.io.IOException {
|
||||||
|
return PARSER.parseFrom(input, extensionRegistry);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Builder newBuilder() { return Builder.create(); }
|
||||||
|
public Builder newBuilderForType() { return newBuilder(); }
|
||||||
|
public static Builder newBuilder(org.baeldung.web.dto.FooProtos.Foo prototype) {
|
||||||
|
return newBuilder().mergeFrom(prototype);
|
||||||
|
}
|
||||||
|
public Builder toBuilder() { return newBuilder(this); }
|
||||||
|
|
||||||
|
@java.lang.Override
|
||||||
|
protected Builder newBuilderForType(
|
||||||
|
com.google.protobuf.GeneratedMessage.BuilderParent parent) {
|
||||||
|
Builder builder = new Builder(parent);
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Protobuf type {@code baeldung.Foo}
|
||||||
|
*/
|
||||||
|
public static final class Builder extends
|
||||||
|
com.google.protobuf.GeneratedMessage.Builder<Builder> implements
|
||||||
|
// @@protoc_insertion_point(builder_implements:baeldung.Foo)
|
||||||
|
org.baeldung.web.dto.FooProtos.FooOrBuilder {
|
||||||
|
public static final com.google.protobuf.Descriptors.Descriptor
|
||||||
|
getDescriptor() {
|
||||||
|
return org.baeldung.web.dto.FooProtos.internal_static_baeldung_Foo_descriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
|
||||||
|
internalGetFieldAccessorTable() {
|
||||||
|
return org.baeldung.web.dto.FooProtos.internal_static_baeldung_Foo_fieldAccessorTable
|
||||||
|
.ensureFieldAccessorsInitialized(
|
||||||
|
org.baeldung.web.dto.FooProtos.Foo.class, org.baeldung.web.dto.FooProtos.Foo.Builder.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct using org.baeldung.web.dto.FooProtos.Foo.newBuilder()
|
||||||
|
private Builder() {
|
||||||
|
maybeForceBuilderInitialization();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Builder(
|
||||||
|
com.google.protobuf.GeneratedMessage.BuilderParent parent) {
|
||||||
|
super(parent);
|
||||||
|
maybeForceBuilderInitialization();
|
||||||
|
}
|
||||||
|
private void maybeForceBuilderInitialization() {
|
||||||
|
if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static Builder create() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder clear() {
|
||||||
|
super.clear();
|
||||||
|
id_ = 0L;
|
||||||
|
bitField0_ = (bitField0_ & ~0x00000001);
|
||||||
|
name_ = "";
|
||||||
|
bitField0_ = (bitField0_ & ~0x00000002);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder clone() {
|
||||||
|
return create().mergeFrom(buildPartial());
|
||||||
|
}
|
||||||
|
|
||||||
|
public com.google.protobuf.Descriptors.Descriptor
|
||||||
|
getDescriptorForType() {
|
||||||
|
return org.baeldung.web.dto.FooProtos.internal_static_baeldung_Foo_descriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public org.baeldung.web.dto.FooProtos.Foo getDefaultInstanceForType() {
|
||||||
|
return org.baeldung.web.dto.FooProtos.Foo.getDefaultInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public org.baeldung.web.dto.FooProtos.Foo build() {
|
||||||
|
org.baeldung.web.dto.FooProtos.Foo result = buildPartial();
|
||||||
|
if (!result.isInitialized()) {
|
||||||
|
throw newUninitializedMessageException(result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public org.baeldung.web.dto.FooProtos.Foo buildPartial() {
|
||||||
|
org.baeldung.web.dto.FooProtos.Foo result = new org.baeldung.web.dto.FooProtos.Foo(this);
|
||||||
|
int from_bitField0_ = bitField0_;
|
||||||
|
int to_bitField0_ = 0;
|
||||||
|
if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
|
||||||
|
to_bitField0_ |= 0x00000001;
|
||||||
|
}
|
||||||
|
result.id_ = id_;
|
||||||
|
if (((from_bitField0_ & 0x00000002) == 0x00000002)) {
|
||||||
|
to_bitField0_ |= 0x00000002;
|
||||||
|
}
|
||||||
|
result.name_ = name_;
|
||||||
|
result.bitField0_ = to_bitField0_;
|
||||||
|
onBuilt();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder mergeFrom(com.google.protobuf.Message other) {
|
||||||
|
if (other instanceof org.baeldung.web.dto.FooProtos.Foo) {
|
||||||
|
return mergeFrom((org.baeldung.web.dto.FooProtos.Foo)other);
|
||||||
|
} else {
|
||||||
|
super.mergeFrom(other);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder mergeFrom(org.baeldung.web.dto.FooProtos.Foo other) {
|
||||||
|
if (other == org.baeldung.web.dto.FooProtos.Foo.getDefaultInstance()) return this;
|
||||||
|
if (other.hasId()) {
|
||||||
|
setId(other.getId());
|
||||||
|
}
|
||||||
|
if (other.hasName()) {
|
||||||
|
bitField0_ |= 0x00000002;
|
||||||
|
name_ = other.name_;
|
||||||
|
onChanged();
|
||||||
|
}
|
||||||
|
this.mergeUnknownFields(other.getUnknownFields());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean isInitialized() {
|
||||||
|
if (!hasId()) {
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!hasName()) {
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder mergeFrom(
|
||||||
|
com.google.protobuf.CodedInputStream input,
|
||||||
|
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||||
|
throws java.io.IOException {
|
||||||
|
org.baeldung.web.dto.FooProtos.Foo parsedMessage = null;
|
||||||
|
try {
|
||||||
|
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
|
||||||
|
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
||||||
|
parsedMessage = (org.baeldung.web.dto.FooProtos.Foo) e.getUnfinishedMessage();
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (parsedMessage != null) {
|
||||||
|
mergeFrom(parsedMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
private int bitField0_;
|
||||||
|
|
||||||
|
private long id_ ;
|
||||||
|
/**
|
||||||
|
* <code>required int64 id = 1;</code>
|
||||||
|
*/
|
||||||
|
public boolean hasId() {
|
||||||
|
return ((bitField0_ & 0x00000001) == 0x00000001);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* <code>required int64 id = 1;</code>
|
||||||
|
*/
|
||||||
|
public long getId() {
|
||||||
|
return id_;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* <code>required int64 id = 1;</code>
|
||||||
|
*/
|
||||||
|
public Builder setId(long value) {
|
||||||
|
bitField0_ |= 0x00000001;
|
||||||
|
id_ = value;
|
||||||
|
onChanged();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* <code>required int64 id = 1;</code>
|
||||||
|
*/
|
||||||
|
public Builder clearId() {
|
||||||
|
bitField0_ = (bitField0_ & ~0x00000001);
|
||||||
|
id_ = 0L;
|
||||||
|
onChanged();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private java.lang.Object name_ = "";
|
||||||
|
/**
|
||||||
|
* <code>required string name = 2;</code>
|
||||||
|
*/
|
||||||
|
public boolean hasName() {
|
||||||
|
return ((bitField0_ & 0x00000002) == 0x00000002);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* <code>required string name = 2;</code>
|
||||||
|
*/
|
||||||
|
public java.lang.String getName() {
|
||||||
|
java.lang.Object ref = name_;
|
||||||
|
if (!(ref instanceof java.lang.String)) {
|
||||||
|
com.google.protobuf.ByteString bs =
|
||||||
|
(com.google.protobuf.ByteString) ref;
|
||||||
|
java.lang.String s = bs.toStringUtf8();
|
||||||
|
if (bs.isValidUtf8()) {
|
||||||
|
name_ = s;
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
} else {
|
||||||
|
return (java.lang.String) ref;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* <code>required string name = 2;</code>
|
||||||
|
*/
|
||||||
|
public com.google.protobuf.ByteString
|
||||||
|
getNameBytes() {
|
||||||
|
java.lang.Object ref = name_;
|
||||||
|
if (ref instanceof String) {
|
||||||
|
com.google.protobuf.ByteString b =
|
||||||
|
com.google.protobuf.ByteString.copyFromUtf8(
|
||||||
|
(java.lang.String) ref);
|
||||||
|
name_ = b;
|
||||||
|
return b;
|
||||||
|
} else {
|
||||||
|
return (com.google.protobuf.ByteString) ref;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* <code>required string name = 2;</code>
|
||||||
|
*/
|
||||||
|
public Builder setName(
|
||||||
|
java.lang.String value) {
|
||||||
|
if (value == null) {
|
||||||
|
throw new NullPointerException();
|
||||||
|
}
|
||||||
|
bitField0_ |= 0x00000002;
|
||||||
|
name_ = value;
|
||||||
|
onChanged();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* <code>required string name = 2;</code>
|
||||||
|
*/
|
||||||
|
public Builder clearName() {
|
||||||
|
bitField0_ = (bitField0_ & ~0x00000002);
|
||||||
|
name_ = getDefaultInstance().getName();
|
||||||
|
onChanged();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* <code>required string name = 2;</code>
|
||||||
|
*/
|
||||||
|
public Builder setNameBytes(
|
||||||
|
com.google.protobuf.ByteString value) {
|
||||||
|
if (value == null) {
|
||||||
|
throw new NullPointerException();
|
||||||
|
}
|
||||||
|
bitField0_ |= 0x00000002;
|
||||||
|
name_ = value;
|
||||||
|
onChanged();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @@protoc_insertion_point(builder_scope:baeldung.Foo)
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
defaultInstance = new Foo(true);
|
||||||
|
defaultInstance.initFields();
|
||||||
|
}
|
||||||
|
|
||||||
|
// @@protoc_insertion_point(class_scope:baeldung.Foo)
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final com.google.protobuf.Descriptors.Descriptor
|
||||||
|
internal_static_baeldung_Foo_descriptor;
|
||||||
|
private static
|
||||||
|
com.google.protobuf.GeneratedMessage.FieldAccessorTable
|
||||||
|
internal_static_baeldung_Foo_fieldAccessorTable;
|
||||||
|
|
||||||
|
public static com.google.protobuf.Descriptors.FileDescriptor
|
||||||
|
getDescriptor() {
|
||||||
|
return descriptor;
|
||||||
|
}
|
||||||
|
private static com.google.protobuf.Descriptors.FileDescriptor
|
||||||
|
descriptor;
|
||||||
|
static {
|
||||||
|
java.lang.String[] descriptorData = {
|
||||||
|
"\n\017FooProtos.proto\022\010baeldung\"\037\n\003Foo\022\n\n\002id" +
|
||||||
|
"\030\001 \002(\003\022\014\n\004name\030\002 \002(\tB!\n\024org.baeldung.web" +
|
||||||
|
".dtoB\tFooProtos"
|
||||||
|
};
|
||||||
|
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
|
||||||
|
new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() {
|
||||||
|
public com.google.protobuf.ExtensionRegistry assignDescriptors(
|
||||||
|
com.google.protobuf.Descriptors.FileDescriptor root) {
|
||||||
|
descriptor = root;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
com.google.protobuf.Descriptors.FileDescriptor
|
||||||
|
.internalBuildGeneratedFileFrom(descriptorData,
|
||||||
|
new com.google.protobuf.Descriptors.FileDescriptor[] {
|
||||||
|
}, assigner);
|
||||||
|
internal_static_baeldung_Foo_descriptor =
|
||||||
|
getDescriptor().getMessageTypes().get(0);
|
||||||
|
internal_static_baeldung_Foo_fieldAccessorTable = new
|
||||||
|
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
|
||||||
|
internal_static_baeldung_Foo_descriptor,
|
||||||
|
new java.lang.String[] { "Id", "Name", });
|
||||||
|
}
|
||||||
|
|
||||||
|
// @@protoc_insertion_point(outer_class_scope)
|
||||||
|
}
|
|
@ -7,7 +7,9 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.baeldung.config.converter.KryoHttpMessageConverter;
|
||||||
import org.baeldung.web.dto.Foo;
|
import org.baeldung.web.dto.Foo;
|
||||||
|
import org.baeldung.web.dto.FooProtos;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpEntity;
|
||||||
|
@ -17,6 +19,7 @@ import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
|
import org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter;
|
||||||
import org.springframework.http.converter.xml.MarshallingHttpMessageConverter;
|
import org.springframework.http.converter.xml.MarshallingHttpMessageConverter;
|
||||||
import org.springframework.oxm.xstream.XStreamMarshaller;
|
import org.springframework.oxm.xstream.XStreamMarshaller;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
@ -94,6 +97,38 @@ public class SpringHttpMessageConvertersIntegrationTestsCase {
|
||||||
Assert.assertEquals(resource.getId(), fooResponse.getId());
|
Assert.assertEquals(resource.getId(), fooResponse.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenConsumingProtobuf_whenReadingTheFoo_thenCorrect() {
|
||||||
|
final String URI = BASE_URI + "foos/{id}";
|
||||||
|
|
||||||
|
final RestTemplate restTemplate = new RestTemplate();
|
||||||
|
restTemplate.setMessageConverters(Arrays.asList(new ProtobufHttpMessageConverter()));
|
||||||
|
final HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setAccept(Arrays.asList(ProtobufHttpMessageConverter.PROTOBUF));
|
||||||
|
final HttpEntity<String> entity = new HttpEntity<String>(headers);
|
||||||
|
|
||||||
|
final ResponseEntity<FooProtos.Foo> response = restTemplate.exchange(URI, HttpMethod.GET, entity, FooProtos.Foo.class, "1");
|
||||||
|
final FooProtos.Foo resource = response.getBody();
|
||||||
|
|
||||||
|
assertThat(resource, notNullValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenConsumingKryo_whenReadingTheFoo_thenCorrect() {
|
||||||
|
final String URI = BASE_URI + "foos/{id}";
|
||||||
|
|
||||||
|
final RestTemplate restTemplate = new RestTemplate();
|
||||||
|
restTemplate.setMessageConverters(Arrays.asList(new KryoHttpMessageConverter()));
|
||||||
|
final HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setAccept(Arrays.asList(KryoHttpMessageConverter.KRYO));
|
||||||
|
final HttpEntity<String> entity = new HttpEntity<String>(headers);
|
||||||
|
|
||||||
|
final ResponseEntity<Foo> response = restTemplate.exchange(URI, HttpMethod.GET, entity, Foo.class, "1");
|
||||||
|
final Foo resource = response.getBody();
|
||||||
|
|
||||||
|
assertThat(resource, notNullValue());
|
||||||
|
}
|
||||||
|
|
||||||
// UTIL
|
// UTIL
|
||||||
|
|
||||||
private List<HttpMessageConverter<?>> getMessageConverters() {
|
private List<HttpMessageConverter<?>> getMessageConverters() {
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
###The Course
|
||||||
|
The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
## Spring Security with Basic Authentication Example Project
|
## Spring Security with Basic Authentication Example Project
|
||||||
|
|
||||||
|
###The Course
|
||||||
|
The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
|
||||||
|
|
||||||
### Relevant Article:
|
### Relevant Article:
|
||||||
- [Spring Security - security none, filters none, access permitAll](http://www.baeldung.com/security-none-filters-none-access-permitAll)
|
- [Spring Security - security none, filters none, access permitAll](http://www.baeldung.com/security-none-filters-none-access-permitAll)
|
||||||
|
@ -9,4 +11,4 @@
|
||||||
|
|
||||||
|
|
||||||
### Notes
|
### Notes
|
||||||
- the project includes both views as well as a REST layer
|
- the project includes both views as well as a REST layer
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
###The Course
|
||||||
|
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
|
@ -0,0 +1,2 @@
|
||||||
|
###The Course
|
||||||
|
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
## Spring Security Login Example Project
|
## Spring Security Login Example Project
|
||||||
|
|
||||||
|
###The Course
|
||||||
|
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||||
|
|
||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
- [Spring Security Remember Me](http://www.baeldung.com/spring-security-remember-me)
|
- [Spring Security Remember Me](http://www.baeldung.com/spring-security-remember-me)
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
## Spring Security with Digest Authentication Example Project
|
## Spring Security with Digest Authentication Example Project
|
||||||
|
|
||||||
|
###The Course
|
||||||
|
The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
|
||||||
|
|
||||||
### Relevant Article:
|
### Relevant Article:
|
||||||
- [Spring Security Digest Authentication](http://www.baeldung.com/spring-security-digest-authentication)
|
- [Spring Security Digest Authentication](http://www.baeldung.com/spring-security-digest-authentication)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
|
||||||
## Spring Security with LDAP Example Project
|
## Spring Security with LDAP Example Project
|
||||||
|
|
||||||
|
###The Course
|
||||||
|
The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
|
||||||
|
|
||||||
### Relevant Article:
|
### Relevant Article:
|
||||||
- [Spring Security - security none, filters none, access permitAll](http://www.baeldung.com/security-none-filters-none-access-permitAll)
|
- [Spring Security - security none, filters none, access permitAll](http://www.baeldung.com/security-none-filters-none-access-permitAll)
|
||||||
|
|
|
@ -2,11 +2,13 @@
|
||||||
|
|
||||||
## Spring Security Login Example Project
|
## Spring Security Login Example Project
|
||||||
|
|
||||||
|
###The Course
|
||||||
|
The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
|
||||||
|
|
||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
- [Spring Security Form Login](http://www.baeldung.com/spring-security-login)
|
- [Spring Security Form Login](http://www.baeldung.com/spring-security-login)
|
||||||
- [Spring Security Logout](http://www.baeldung.com/spring-security-logout)
|
- [Spring Security Logout](http://www.baeldung.com/spring-security-logout)
|
||||||
- [Spring Security Expressions – hasRole Example](http://www.baeldung.com/spring-security-expressions-basic)
|
- [Spring Security Expressions – hasRole Example](http://www.baeldung.com/spring-security-expressions-basic)
|
||||||
|
|
||||||
|
|
||||||
### Build the Project
|
### Build the Project
|
||||||
|
|