|
3 | 3 | import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; |
4 | 4 | import static org.hamcrest.CoreMatchers.is; |
5 | 5 | import static org.hamcrest.Matchers.hasItem; |
| 6 | +import static org.hamcrest.Matchers.not; |
6 | 7 | import static org.junit.Assert.assertThat; |
7 | 8 |
|
8 | 9 | import java.util.List; |
|
15 | 16 | import org.rest.spring.client.ClientTestConfig; |
16 | 17 | import org.rest.spring.context.ContextTestConfig; |
17 | 18 | import org.rest.spring.testing.TestingTestConfig; |
| 19 | +import org.rest.util.IdUtil; |
18 | 20 | import org.springframework.beans.factory.annotation.Autowired; |
19 | 21 | import org.springframework.test.context.ContextConfiguration; |
20 | 22 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
@@ -88,23 +90,74 @@ public final void givenResourceExists_whenResourceIfSearchedByName_then200IsRece |
88 | 90 | assertThat( searchResponse.getStatusCode(), is( 200 ) ); |
89 | 91 | } |
90 | 92 |
|
91 | | - /* |
92 | | - |
93 | 93 | @Test |
94 | 94 | public final void givenResourceExists_whenResourceIfSearchedByNameAndUnmarshalled_thenNoException(){ |
95 | 95 | final Role existingResource = getTemplate().create( getTemplate().createNewEntity() ); |
96 | | - getTemplate().search( existingResource.getId() ); |
| 96 | + getTemplate().search( null, existingResource.getName() ); |
97 | 97 | } |
98 | 98 | @Test |
99 | 99 | public final void givenResourceExists_whenResourceIfSearchedByNameAndUnmarshalled_thenResourceIsFound(){ |
100 | 100 | final Role existingResource = getTemplate().create( getTemplate().createNewEntity() ); |
101 | 101 |
|
102 | 102 | // When |
103 | | - final List< Role > found = getTemplate().search( existingResource.getId() ); |
| 103 | + final List< Role > found = getTemplate().search( null, existingResource.getName() ); |
104 | 104 |
|
105 | 105 | // Then |
106 | 106 | assertThat( found, hasItem( existingResource ) ); |
107 | | - }*/ |
| 107 | + } |
| 108 | + |
| 109 | + // search - by id and name |
| 110 | + |
| 111 | + @Test |
| 112 | + public final void givenResourceExists_whenResourceIfSearchedByIdAndName_then200IsReceived(){ |
| 113 | + final Role existingResource = getTemplate().create( getTemplate().createNewEntity() ); |
| 114 | + |
| 115 | + // When |
| 116 | + final Response searchResponse = getTemplate().searchAsResponse( existingResource.getId(), existingResource.getName() ); |
| 117 | + |
| 118 | + // Then |
| 119 | + assertThat( searchResponse.getStatusCode(), is( 200 ) ); |
| 120 | + } |
| 121 | + @Test |
| 122 | + public final void givenResourceExists_whenResourceIfSearchedByIdAndNameAndUnmarshalled_thenResourceIsFound(){ |
| 123 | + final Role existingResource = getTemplate().create( getTemplate().createNewEntity() ); |
| 124 | + |
| 125 | + // When |
| 126 | + final List< Role > found = getTemplate().search( existingResource.getId(), existingResource.getName() ); |
| 127 | + |
| 128 | + // Then |
| 129 | + assertThat( found, hasItem( existingResource ) ); |
| 130 | + } |
| 131 | + @Test |
| 132 | + public final void givenResourceExists_whenResourceIfSearchedByIdAndWrongNameAndUnmarshalled_thenResourceIsFound(){ |
| 133 | + final Role existingResource = getTemplate().create( getTemplate().createNewEntity() ); |
| 134 | + |
| 135 | + // When |
| 136 | + final List< Role > found = getTemplate().search( existingResource.getId(), randomAlphabetic( 8 ) ); |
| 137 | + |
| 138 | + // Then |
| 139 | + assertThat( found, not( hasItem( existingResource ) ) ); |
| 140 | + } |
| 141 | + @Test |
| 142 | + public final void givenResourceExists_whenResourceIfSearchedByWrongIdAndCorrectNameAndUnmarshalled_thenResourceIsFound(){ |
| 143 | + final Role existingResource = getTemplate().create( getTemplate().createNewEntity() ); |
| 144 | + |
| 145 | + // When |
| 146 | + final List< Role > found = getTemplate().search( IdUtil.randomPositiveLong(), existingResource.getName() ); |
| 147 | + |
| 148 | + // Then |
| 149 | + assertThat( found, not( hasItem( existingResource ) ) ); |
| 150 | + } |
| 151 | + @Test |
| 152 | + public final void givenResourceExists_whenResourceIfSearchedByWrongIdAndWrongNameAndUnmarshalled_thenResourceIsFound(){ |
| 153 | + final Role existingResource = getTemplate().create( getTemplate().createNewEntity() ); |
| 154 | + |
| 155 | + // When |
| 156 | + final List< Role > found = getTemplate().search( IdUtil.randomPositiveLong(), randomAlphabetic( 8 ) ); |
| 157 | + |
| 158 | + // Then |
| 159 | + assertThat( found, not( hasItem( existingResource ) ) ); |
| 160 | + } |
108 | 161 |
|
109 | 162 | // template |
110 | 163 |
|
|
0 commit comments