added tests and enabled the schema validation for upload
This commit is contained in:
Binary file not shown.
@@ -112,4 +112,12 @@ public abstract class AbstractRestTest extends AbstractTest {
|
||||
String className = this.getClass().getName();
|
||||
return getResponseText(httpResponse, () -> className + "-" + name + ".json");
|
||||
}
|
||||
|
||||
protected int customerCount() {
|
||||
return getCount("select count(*) from customer");
|
||||
}
|
||||
|
||||
protected int pictureCount() {
|
||||
return getCount("select count(*) from picture");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,10 +37,13 @@ public class CustomerPictureResourceTest extends AbstractRestTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
@Order(2)
|
||||
public void doAddCustomerPicture() throws IOException {
|
||||
LOG.info("doAddCustomerPicture");
|
||||
|
||||
|
||||
assertEquals(3, customerCount());
|
||||
assertEquals(5, pictureCount());
|
||||
|
||||
String authorization = getBasicHeader();
|
||||
LOG.info("authorization: " + authorization);
|
||||
String path = deploymentURL + PATH;
|
||||
@@ -51,10 +54,56 @@ public class CustomerPictureResourceTest extends AbstractRestTest {
|
||||
HttpResponse httpResponse = executeRequest(request);
|
||||
int code = httpResponse.getStatusLine().getStatusCode();
|
||||
assertEquals(200, code);
|
||||
|
||||
assertEquals(3, customerCount());
|
||||
assertEquals(6, pictureCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
public void doAddCustomerWithPicture() throws IOException {
|
||||
LOG.info("doAddCustomerWithPicture");
|
||||
|
||||
assertEquals(3, customerCount());
|
||||
assertEquals(6, pictureCount());
|
||||
|
||||
String authorization = getBasicHeader();
|
||||
LOG.info("authorization: " + authorization);
|
||||
String path = deploymentURL + PATH;
|
||||
Request request = Request.Post(path).addHeader("Accept", "application/json; charset=utf-8")
|
||||
.addHeader("Authorization", authorization)
|
||||
.bodyFile(new File(BASE_UPLOAD + "addNewCustomer.json"), ContentType.APPLICATION_JSON);
|
||||
|
||||
HttpResponse httpResponse = executeRequest(request);
|
||||
int code = httpResponse.getStatusLine().getStatusCode();
|
||||
assertEquals(200, code);
|
||||
|
||||
assertEquals(4, customerCount());
|
||||
assertEquals(7, pictureCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
public void doAddCustomerPictureWrongJson() throws IOException {
|
||||
LOG.info("doAddCustomerPictureWrongJson");
|
||||
|
||||
String authorization = getBasicHeader();
|
||||
LOG.info("authorization: " + authorization);
|
||||
String path = deploymentURL + PATH;
|
||||
Request request = Request.Post(path).addHeader("Accept", "application/json; charset=utf-8")
|
||||
.addHeader("Authorization", authorization)
|
||||
.bodyFile(new File(BASE_UPLOAD + "addWrong.json"), ContentType.APPLICATION_JSON);
|
||||
|
||||
HttpResponse httpResponse = executeRequest(request);
|
||||
int code = httpResponse.getStatusLine().getStatusCode();
|
||||
assertEquals(400, code);
|
||||
|
||||
String text = getResponseText(httpResponse, "doGetAll");
|
||||
System.out.println(text);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
@Order(1)
|
||||
public void doAddCustomerPictureNoAuth() throws IOException {
|
||||
LOG.info("doAddCustomerPictureNoAuth");
|
||||
|
||||
@@ -74,6 +123,6 @@ public class CustomerPictureResourceTest extends AbstractRestTest {
|
||||
test.username = "adm";
|
||||
test.password = "x1t0e7Pb49";
|
||||
|
||||
test.doAddCustomerPicture();
|
||||
test.doAddCustomerPictureWrongJson();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,13 +48,12 @@ public class CustomerResourceTest extends AbstractRestTest {
|
||||
HttpResponse httpResponse = executeRequest(request);
|
||||
int code = httpResponse.getStatusLine().getStatusCode();
|
||||
assertEquals(200, code);
|
||||
|
||||
|
||||
String text = getResponseText(httpResponse, "doGetAll");
|
||||
String expected = fileToString(BASE_DOWNLOAD + "doGetAll.json");
|
||||
jsonAssert(expected, text);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
public void doGetCustomer() throws IOException {
|
||||
@@ -62,14 +61,13 @@ public class CustomerResourceTest extends AbstractRestTest {
|
||||
|
||||
String authorization = getAuthorization();
|
||||
LOG.info("authorization: " + authorization);
|
||||
String path = deploymentURL + PATH +"/1";
|
||||
String path = deploymentURL + PATH + "/1";
|
||||
Request request = Request.Get(path).addHeader("Accept", "application/json; charset=utf-8")
|
||||
.addHeader("Authorization", authorization);
|
||||
|
||||
HttpResponse httpResponse = executeRequest(request);
|
||||
int code = httpResponse.getStatusLine().getStatusCode();
|
||||
assertEquals(200, code);
|
||||
|
||||
|
||||
String text = getResponseText(httpResponse, "doGetCustomer");
|
||||
String expected = fileToString(BASE_DOWNLOAD + "doGetCustomer.json");
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.junit.jupiter.api.TestMethodOrder;
|
||||
public class PictureResourceTest extends AbstractRestTest {
|
||||
private static final Log LOG = LogFactory.getLog(PictureResourceTest.class);
|
||||
private static final String PATH = "api/picture";
|
||||
|
||||
|
||||
@BeforeAll
|
||||
public static void init() {
|
||||
initDB();
|
||||
@@ -50,7 +50,7 @@ public class PictureResourceTest extends AbstractRestTest {
|
||||
|
||||
assertEquals(4, pictureCount());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
public void doDeleteNotFound() throws IOException {
|
||||
@@ -68,8 +68,5 @@ public class PictureResourceTest extends AbstractRestTest {
|
||||
|
||||
assertEquals(5, pictureCount());
|
||||
}
|
||||
|
||||
private int pictureCount() {
|
||||
return getCount("select count(*) from picture");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user