33import static org .junit .Assert .assertEquals ;
44import static org .junit .Assert .assertTrue ;
55
6+ import org .baeldung .Application ;
67import org .baeldung .persistence .model .Foo ;
78import org .junit .Test ;
9+ import org .junit .runner .RunWith ;
10+ import org .springframework .boot .test .IntegrationTest ;
11+ import org .springframework .boot .test .SpringApplicationConfiguration ;
812import org .springframework .http .MediaType ;
13+ import org .springframework .test .context .junit4 .SpringJUnit4ClassRunner ;
14+ import org .springframework .test .context .web .WebAppConfiguration ;
915
1016import com .jayway .restassured .RestAssured ;
1117import com .jayway .restassured .authentication .FormAuthConfig ;
1218import com .jayway .restassured .response .Response ;
1319import com .jayway .restassured .specification .RequestSpecification ;
1420
21+ @ RunWith (SpringJUnit4ClassRunner .class )
22+ @ SpringApplicationConfiguration (classes = Application .class )
23+ @ WebAppConfiguration
24+ @ IntegrationTest ("server.port:8082" )
1525public class LiveTest {
1626
17- private final FormAuthConfig formAuthConfig = new FormAuthConfig ("http://localhost:8081 /login" , "username" , "password" );
27+ private final FormAuthConfig formAuthConfig = new FormAuthConfig ("http://localhost:8082 /login" , "username" , "password" );
1828
1929 @ Test
2030 public void givenUserWithReadPrivilegeAndHasPermission_whenGetFooById_thenOK () {
21- final Response response = givenAuth ("john" , "123" ).get ("http://localhost:8081 /foos/1" );
31+ final Response response = givenAuth ("john" , "123" ).get ("http://localhost:8082 /foos/1" );
2232 assertEquals (200 , response .getStatusCode ());
2333 assertTrue (response .asString ().contains ("id" ));
2434 }
2535
2636 @ Test
2737 public void givenUserWithNoWritePrivilegeAndHasPermission_whenPostFoo_thenForbidden () {
28- final Response response = givenAuth ("john" , "123" ).contentType (MediaType .APPLICATION_JSON_VALUE ).body (new Foo ("sample" )).post ("http://localhost:8081 /foos" );
38+ final Response response = givenAuth ("john" , "123" ).contentType (MediaType .APPLICATION_JSON_VALUE ).body (new Foo ("sample" )).post ("http://localhost:8082 /foos" );
2939 assertEquals (403 , response .getStatusCode ());
3040 }
3141
3242 @ Test
3343 public void givenUserWithWritePrivilegeAndHasPermission_whenPostFoo_thenOk () {
34- final Response response = givenAuth ("tom" , "111" ).contentType (MediaType .APPLICATION_JSON_VALUE ).body (new Foo ("sample" )).post ("http://localhost:8081 /foos" );
44+ final Response response = givenAuth ("tom" , "111" ).contentType (MediaType .APPLICATION_JSON_VALUE ).body (new Foo ("sample" )).post ("http://localhost:8082 /foos" );
3545 assertEquals (201 , response .getStatusCode ());
3646 assertTrue (response .asString ().contains ("id" ));
3747 }
@@ -40,22 +50,22 @@ public void givenUserWithWritePrivilegeAndHasPermission_whenPostFoo_thenOk() {
4050
4151 @ Test
4252 public void givenUserMemberInOrganization_whenGetOrganization_thenOK () {
43- final Response response = givenAuth ("john" , "123" ).get ("http://localhost:8081 /organizations/1" );
53+ final Response response = givenAuth ("john" , "123" ).get ("http://localhost:8082 /organizations/1" );
4454 assertEquals (200 , response .getStatusCode ());
4555 assertTrue (response .asString ().contains ("id" ));
4656 }
4757
4858 @ Test
4959 public void givenUserMemberNotInOrganization_whenGetOrganization_thenForbidden () {
50- final Response response = givenAuth ("john" , "123" ).get ("http://localhost:8081 /organizations/2" );
60+ final Response response = givenAuth ("john" , "123" ).get ("http://localhost:8082 /organizations/2" );
5161 assertEquals (403 , response .getStatusCode ());
5262 }
5363
5464 //
5565
5666 @ Test
5767 public void givenDisabledSecurityExpression_whenGetFooByName_thenError () {
58- final Response response = givenAuth ("john" , "123" ).get ("http://localhost:8081 /foos?name=sample" );
68+ final Response response = givenAuth ("john" , "123" ).get ("http://localhost:8082 /foos?name=sample" );
5969 assertEquals (500 , response .getStatusCode ());
6070 assertTrue (response .asString ().contains ("method hasAuthority() not allowed" ));
6171 }
0 commit comments