FIX::fixed UserDto names

ADD::tried to add second test to see what was the problem, but no luck so far
This commit is contained in:
Sem van der Hoeven
2019-03-17 21:42:52 +01:00
parent 874b0bcd72
commit 282d2026ba

View File

@@ -1,46 +1,70 @@
//import greenify.common.UserDTO; import greenify.common.UserDto;
//import greenify.server.Application; import greenify.server.Application;
//import org.junit.Assert; import org.junit.Assert;
//import org.junit.Test; import org.junit.Test;
//import org.junit.runner.RunWith; import org.junit.runner.RunWith;
//import org.slf4j.Logger; import org.slf4j.Logger;
//import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
//import org.springframework.boot.web.server.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.web.server.LocalServerPort;
//import org.springframework.http.*; import org.springframework.http.HttpEntity;
//import org.springframework.test.context.junit4.SpringRunner; import org.springframework.http.HttpHeaders;
//import org.springframework.web.client.HttpStatusCodeException; import org.springframework.http.MediaType;
//import org.springframework.web.client.RestTemplate; import org.springframework.test.context.junit4.SpringRunner;
//import org.springframework.web.util.UriComponentsBuilder; import org.springframework.web.client.HttpClientErrorException;
// import org.springframework.web.client.HttpStatusCodeException;
//@RunWith(SpringRunner.class) import org.springframework.web.client.RestTemplate;
//@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) import org.springframework.web.util.UriComponentsBuilder;
//public class UserControllerTest {
// private static Logger logger = LoggerFactory.getLogger(UserControllerTest.class); @RunWith(SpringRunner.class)
// @SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
// @LocalServerPort public class UserControllerTest {
// private int port; private static Logger logger = LoggerFactory.getLogger(UserControllerTest.class);
//
// private RestTemplate restTemplate = new RestTemplate(); @LocalServerPort
// private int port;
// @Test
// public void registerUserTest() { private RestTemplate restTemplate = new RestTemplate();
// HttpHeaders headers = new HttpHeaders();
// headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); @Test
// UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:" + port + "/registerUser") public void registerUserTest() {
// .queryParam("name", "ceren") HttpHeaders headers = new HttpHeaders();
// .queryParam("password", "password"); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
// HttpEntity<?> entity = new HttpEntity<>(headers); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:" + port + "/registerUser")
// UserDTO user = this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class); .queryParam("name", "ceren")
// Assert.assertNotNull(user); .queryParam("password", "password");
// Assert.assertEquals(user.getId().longValue(), 1L); HttpEntity<?> entity = new HttpEntity<>(headers);
// try { UserDto user = this.restTemplate.getForObject(builder.build().encode().toUri(), UserDto.class);
// user = this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class); Assert.assertNotNull(user);
// Assert.fail("Error should be reported"); try {
// } catch (HttpStatusCodeException exception) { user = this.restTemplate.getForObject(builder.build().encode().toUri(), UserDto.class);
// int statusCode = exception.getStatusCode().value(); Assert.fail("Error should be reported");
// Assert.assertEquals(statusCode, 400); Assert.assertEquals(user.getId().longValue(), 1L);
// Assert.assertTrue(exception.getResponseBodyAsString().contains("User already exists")); } catch (HttpStatusCodeException exception) {
// } int statusCode = exception.getStatusCode().value();
// } Assert.assertEquals(statusCode, 400);
//} Assert.assertTrue(exception.getResponseBodyAsString().contains("User already exists"));
}
}
@Test
public void registerUserTest_ClientResponseErrorException() {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:" + port + "/registerUser")
.queryParam("name", "ceren")
.queryParam("password", "password");
HttpEntity<?> entity = new HttpEntity<>(headers);
UserDto user = this.restTemplate.getForObject(builder.build().encode().toUri(), UserDto.class);
Assert.assertNotNull(user);
try {
user = this.restTemplate.getForObject(builder.build().encode().toUri(), UserDto.class);
Assert.fail("Error should be reported");
Assert.assertEquals(user.getId().longValue(), 1L);
} catch (HttpClientErrorException exception) {
int statusCode = exception.getStatusCode().value();
Assert.assertEquals(statusCode, 400);
}
}
}