unit test
This commit is contained in:
@@ -14,9 +14,6 @@ import marketing.heyday.hartmann.fotodocumentation.core.model.Questionnaire;
|
|||||||
import marketing.heyday.hartmann.fotodocumentation.core.model.QuestionnaireCustomer;
|
import marketing.heyday.hartmann.fotodocumentation.core.model.QuestionnaireCustomer;
|
||||||
import marketing.heyday.hartmann.fotodocumentation.core.utils.CalendarUtil;
|
import marketing.heyday.hartmann.fotodocumentation.core.utils.CalendarUtil;
|
||||||
import marketing.heyday.hartmann.fotodocumentation.core.utils.ExcelUtils;
|
import marketing.heyday.hartmann.fotodocumentation.core.utils.ExcelUtils;
|
||||||
import marketing.heyday.hartmann.fotodocumentation.core.utils.PdfUtils;
|
|
||||||
import marketing.heyday.hartmann.fotodocumentation.rest.vo.CustomerListValue;
|
|
||||||
import marketing.heyday.hartmann.fotodocumentation.rest.vo.CustomerValue;
|
|
||||||
import marketing.heyday.hartmann.fotodocumentation.rest.vo.QuestionnaireCustomerListValue;
|
import marketing.heyday.hartmann.fotodocumentation.rest.vo.QuestionnaireCustomerListValue;
|
||||||
import marketing.heyday.hartmann.fotodocumentation.rest.vo.QuestionnaireCustomerValue;
|
import marketing.heyday.hartmann.fotodocumentation.rest.vo.QuestionnaireCustomerValue;
|
||||||
|
|
||||||
@@ -65,11 +62,11 @@ public class QuestionnaireCustomerService extends AbstractService {
|
|||||||
Date startOfDay = calendarUtil.getStartOfDay(date);
|
Date startOfDay = calendarUtil.getStartOfDay(date);
|
||||||
Date endOfDay = calendarUtil.getEndOfDay(date);
|
Date endOfDay = calendarUtil.getEndOfDay(date);
|
||||||
|
|
||||||
Fetch<QuestionnaireCustomer, Questionnaire> picturesFetch = customerRoot.fetch("pictures", JoinType.LEFT);
|
Fetch<QuestionnaireCustomer, Questionnaire> picturesFetch = customerRoot.fetch("questionnaires", JoinType.LEFT);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Join<QuestionnaireCustomer, Questionnaire> pictures = (Join<QuestionnaireCustomer, Questionnaire>) picturesFetch;
|
Join<QuestionnaireCustomer, Questionnaire> pictures = (Join<QuestionnaireCustomer, Questionnaire>) picturesFetch;
|
||||||
|
|
||||||
var predicateDate = builder.between(pictures.get("pictureDate"), startOfDay, endOfDay);
|
var predicateDate = builder.between(pictures.get("questionnaireDate"), startOfDay, endOfDay);
|
||||||
predicates.add(predicateDate);
|
predicates.add(predicateDate);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package marketing.heyday.hartmann.fotodocumentation.rest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* <p>Copyright: Copyright (c) 2024</p>
|
||||||
|
* <p>Company: heyday Marketing GmbH</p>
|
||||||
|
* @author <a href="mailto:p.verboom@heyday.marketing">Patrick Verboom</a>
|
||||||
|
* @version 1.0
|
||||||
|
*
|
||||||
|
* created: 13 Nov 2024
|
||||||
|
*/
|
||||||
|
public abstract class AbstractFotoTest extends AbstractRestTest {
|
||||||
|
protected int customerCount() {
|
||||||
|
return getCount("select count(*) from customer");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int pictureCount() {
|
||||||
|
return getCount("select count(*) from picture");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package marketing.heyday.hartmann.fotodocumentation.rest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* <p>Copyright: Copyright (c) 2024</p>
|
||||||
|
* <p>Company: heyday Marketing GmbH</p>
|
||||||
|
* @author <a href="mailto:p.verboom@heyday.marketing">Patrick Verboom</a>
|
||||||
|
* @version 1.0
|
||||||
|
*
|
||||||
|
* created: 13 Nov 2024
|
||||||
|
*/
|
||||||
|
public abstract class AbstractQuestionnaireTest extends AbstractRestTest {
|
||||||
|
protected int customerCount() {
|
||||||
|
return getCount("select count(*) from questionnaire_customer");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int questionnaireCount() {
|
||||||
|
return getCount("select count(*) from questionnaire");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -112,12 +112,4 @@ public abstract class AbstractRestTest extends AbstractTest {
|
|||||||
String className = this.getClass().getName();
|
String className = this.getClass().getName();
|
||||||
return getResponseText(httpResponse, () -> className + "-" + name + ".json");
|
return getResponseText(httpResponse, () -> className + "-" + name + ".json");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int customerCount() {
|
|
||||||
return getCount("select count(*) from customer");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int pictureCount() {
|
|
||||||
return getCount("select count(*) from picture");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import org.junit.jupiter.api.TestMethodOrder;
|
|||||||
* created: 14 Nov 2024
|
* created: 14 Nov 2024
|
||||||
*/
|
*/
|
||||||
@TestMethodOrder(OrderAnnotation.class)
|
@TestMethodOrder(OrderAnnotation.class)
|
||||||
public class CustomerPictureResourceTest extends AbstractRestTest {
|
public class CustomerPictureResourceTest extends AbstractFotoTest {
|
||||||
private static final Log LOG = LogFactory.getLog(CustomerPictureResourceTest.class);
|
private static final Log LOG = LogFactory.getLog(CustomerPictureResourceTest.class);
|
||||||
private static final String PATH = "api/customer-picture";
|
private static final String PATH = "api/customer-picture";
|
||||||
private static final String BASE_UPLOAD = "src/test/resources/upload/";
|
private static final String BASE_UPLOAD = "src/test/resources/upload/";
|
||||||
@@ -64,11 +64,8 @@ public class CustomerPictureResourceTest extends AbstractRestTest {
|
|||||||
assertEquals(3, customerCount());
|
assertEquals(3, customerCount());
|
||||||
assertEquals(6, pictureCount());
|
assertEquals(6, pictureCount());
|
||||||
|
|
||||||
String authorization = getBasicHeader();
|
|
||||||
LOG.info("authorization: " + authorization);
|
|
||||||
String path = deploymentURL + PATH;
|
String path = deploymentURL + PATH;
|
||||||
Request request = Request.Post(path).addHeader("Accept", "application/json; charset=utf-8")
|
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);
|
.bodyFile(new File(BASE_UPLOAD + "addNewCustomer.json"), ContentType.APPLICATION_JSON);
|
||||||
|
|
||||||
HttpResponse httpResponse = executeRequest(request);
|
HttpResponse httpResponse = executeRequest(request);
|
||||||
@@ -84,11 +81,8 @@ public class CustomerPictureResourceTest extends AbstractRestTest {
|
|||||||
public void doAddCustomerPictureWrongJson() throws IOException {
|
public void doAddCustomerPictureWrongJson() throws IOException {
|
||||||
LOG.info("doAddCustomerPictureWrongJson");
|
LOG.info("doAddCustomerPictureWrongJson");
|
||||||
|
|
||||||
String authorization = getBasicHeader();
|
|
||||||
LOG.info("authorization: " + authorization);
|
|
||||||
String path = deploymentURL + PATH;
|
String path = deploymentURL + PATH;
|
||||||
Request request = Request.Post(path).addHeader("Accept", "application/json; charset=utf-8")
|
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);
|
.bodyFile(new File(BASE_UPLOAD + "addWrong.json"), ContentType.APPLICATION_JSON);
|
||||||
|
|
||||||
HttpResponse httpResponse = executeRequest(request);
|
HttpResponse httpResponse = executeRequest(request);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import org.junit.jupiter.api.TestMethodOrder;
|
|||||||
* created: 14 Nov 2024
|
* created: 14 Nov 2024
|
||||||
*/
|
*/
|
||||||
@TestMethodOrder(OrderAnnotation.class)
|
@TestMethodOrder(OrderAnnotation.class)
|
||||||
public class PictureResourceTest extends AbstractRestTest {
|
public class PictureResourceTest extends AbstractFotoTest {
|
||||||
private static final Log LOG = LogFactory.getLog(PictureResourceTest.class);
|
private static final Log LOG = LogFactory.getLog(PictureResourceTest.class);
|
||||||
private static final String PATH = "api/picture";
|
private static final String PATH = "api/picture";
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,233 @@
|
|||||||
|
package marketing.heyday.hartmann.fotodocumentation.rest;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.client.fluent.Request;
|
||||||
|
import org.junit.jupiter.api.*;
|
||||||
|
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* <p>Copyright: Copyright (c) 2024</p>
|
||||||
|
* <p>Company: heyday Marketing GmbH</p>
|
||||||
|
* @author <a href="mailto:p.verboom@heyday.marketing">Patrick Verboom</a>
|
||||||
|
* @version 1.0
|
||||||
|
*
|
||||||
|
* created: 14 Nov 2024
|
||||||
|
*/
|
||||||
|
@TestMethodOrder(OrderAnnotation.class)
|
||||||
|
public class QuestionnaireCustomerResourceTest extends AbstractRestTest {
|
||||||
|
private static final Log LOG = LogFactory.getLog(QuestionnaireCustomerResourceTest.class);
|
||||||
|
private static final String PATH = "api/questionnairecustomer";
|
||||||
|
private static final String BASE_DOWNLOAD = "json/QuestionnaireCustomerResourceTest-";
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
public static void init() {
|
||||||
|
initDB();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(1)
|
||||||
|
public void doGetAll() throws IOException {
|
||||||
|
LOG.info("doGetAll");
|
||||||
|
|
||||||
|
String authorization = getAuthorization();
|
||||||
|
LOG.info("authorization: " + authorization);
|
||||||
|
String path = deploymentURL + PATH;
|
||||||
|
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, "doGetAll");
|
||||||
|
String expected = fileToString(BASE_DOWNLOAD + "doGetAll.json");
|
||||||
|
jsonAssert(expected, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(1)
|
||||||
|
public void doGetAllStartWith() throws IOException {
|
||||||
|
LOG.info("doGetAllStartWith");
|
||||||
|
|
||||||
|
String authorization = getAuthorization();
|
||||||
|
LOG.info("authorization: " + authorization);
|
||||||
|
String path = deploymentURL + PATH + "?startsWith=M";
|
||||||
|
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, "doGetAllStartWith");
|
||||||
|
String expected = fileToString(BASE_DOWNLOAD + "doGetAllStartWith.json");
|
||||||
|
jsonAssert(expected, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(1)
|
||||||
|
public void doGetAllQueryText() throws IOException {
|
||||||
|
LOG.info("doGetAllQueryText");
|
||||||
|
|
||||||
|
String authorization = getAuthorization();
|
||||||
|
LOG.info("authorization: " + authorization);
|
||||||
|
String path = deploymentURL + PATH + "?query=2345";
|
||||||
|
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, "doGetAllQueryText");
|
||||||
|
String expected = fileToString(BASE_DOWNLOAD + "doGetAllQueryText.json");
|
||||||
|
jsonAssert(expected, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(1)
|
||||||
|
public void doGetAllQueryTextWithStart() throws IOException {
|
||||||
|
LOG.info("doGetAllQueryTextWithStart");
|
||||||
|
|
||||||
|
String authorization = getAuthorization();
|
||||||
|
LOG.info("authorization: " + authorization);
|
||||||
|
String path = deploymentURL + PATH + "?query=45&startsWith=M";
|
||||||
|
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, "doGetAllQueryTextWithStart");
|
||||||
|
String expected = fileToString(BASE_DOWNLOAD + "doGetAllQueryTextWithStart.json");
|
||||||
|
jsonAssert(expected, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(1)
|
||||||
|
public void doGetAllQueryDate1() throws IOException {
|
||||||
|
LOG.info("doGetAllQueryDate");
|
||||||
|
|
||||||
|
String authorization = getAuthorization();
|
||||||
|
LOG.info("authorization: " + authorization);
|
||||||
|
String path = deploymentURL + PATH + "?query=12.01.2026";
|
||||||
|
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, "doGetAllQueryDate");
|
||||||
|
String expected = fileToString(BASE_DOWNLOAD + "doGetAllQueryDate.json");
|
||||||
|
jsonAssert(expected, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(1)
|
||||||
|
public void doGetAllQueryDate2() throws IOException {
|
||||||
|
LOG.info("doGetAllQueryDate");
|
||||||
|
|
||||||
|
String authorization = getAuthorization();
|
||||||
|
LOG.info("authorization: " + authorization);
|
||||||
|
String query = URLEncoder.encode("12 Januar 2026", Charset.forName("utf-8"));
|
||||||
|
String path = deploymentURL + PATH + "?query=" + query;
|
||||||
|
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, "doGetAllQueryDate");
|
||||||
|
String expected = fileToString(BASE_DOWNLOAD + "doGetAllQueryDate.json");
|
||||||
|
jsonAssert(expected, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(1)
|
||||||
|
public void doGetAllQueryDate3() throws IOException {
|
||||||
|
LOG.info("doGetAllQueryDate");
|
||||||
|
|
||||||
|
String authorization = getAuthorization();
|
||||||
|
LOG.info("authorization: " + authorization);
|
||||||
|
String query = URLEncoder.encode("12. Januar 2026", Charset.forName("utf-8"));
|
||||||
|
String path = deploymentURL + PATH + "?query=" + query;
|
||||||
|
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, "doGetAllQueryDate");
|
||||||
|
String expected = fileToString(BASE_DOWNLOAD + "doGetAllQueryDate.json");
|
||||||
|
jsonAssert(expected, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(1)
|
||||||
|
public void doGetCustomer() throws IOException {
|
||||||
|
LOG.info("doGetCustomer");
|
||||||
|
|
||||||
|
String authorization = getAuthorization();
|
||||||
|
LOG.info("authorization: " + authorization);
|
||||||
|
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");
|
||||||
|
jsonAssert(expected, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(1)
|
||||||
|
@Disabled // FIXME: enable when we have implemented excel download
|
||||||
|
public void doDownload() throws IOException {
|
||||||
|
LOG.info("doDownload");
|
||||||
|
|
||||||
|
String authorization = getAuthorization();
|
||||||
|
LOG.info("authorization: " + authorization);
|
||||||
|
String path = deploymentURL + PATH + "/export/1";
|
||||||
|
Request request = Request.Get(path).addHeader("Accept", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||||
|
.addHeader("Authorization", authorization);
|
||||||
|
|
||||||
|
HttpResponse httpResponse = executeRequest(request);
|
||||||
|
int code = httpResponse.getStatusLine().getStatusCode();
|
||||||
|
assertEquals(200, code);
|
||||||
|
|
||||||
|
byte[] text = getResponse(httpResponse);
|
||||||
|
writeFile(text, "doDownload.pdf");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(1)
|
||||||
|
public void doDownloadNotExist() throws IOException {
|
||||||
|
LOG.info("doDownloadNotExist");
|
||||||
|
|
||||||
|
String authorization = getAuthorization();
|
||||||
|
LOG.info("authorization: " + authorization);
|
||||||
|
String path = deploymentURL + PATH + "/export/9999";
|
||||||
|
Request request = Request.Get(path).addHeader("Accept", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||||
|
.addHeader("Authorization", authorization);
|
||||||
|
|
||||||
|
HttpResponse httpResponse = executeRequest(request);
|
||||||
|
int code = httpResponse.getStatusLine().getStatusCode();
|
||||||
|
assertEquals(404, code);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package marketing.heyday.hartmann.fotodocumentation.rest;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.client.fluent.Request;
|
||||||
|
import org.apache.http.entity.ContentType;
|
||||||
|
import org.junit.jupiter.api.*;
|
||||||
|
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* <p>Copyright: Copyright (c) 2024</p>
|
||||||
|
* <p>Company: heyday Marketing GmbH</p>
|
||||||
|
* @author <a href="mailto:p.verboom@heyday.marketing">Patrick Verboom</a>
|
||||||
|
* @version 1.0
|
||||||
|
*
|
||||||
|
* created: 14 Nov 2024
|
||||||
|
*/
|
||||||
|
@TestMethodOrder(OrderAnnotation.class)
|
||||||
|
public class QuestionnairePublishResourceTest extends AbstractQuestionnaireTest {
|
||||||
|
private static final Log LOG = LogFactory.getLog(QuestionnairePublishResourceTest.class);
|
||||||
|
private static final String PATH = "api/questionnaire-publish";
|
||||||
|
private static final String BASE_UPLOAD = "src/test/resources/upload/";
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
public static void init() {
|
||||||
|
initDB();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(2)
|
||||||
|
@Disabled // FIXME: enable when implemented
|
||||||
|
public void doAddCustomerdoAddQuestionniare() throws IOException {
|
||||||
|
LOG.info("doAddCustomerdoAddQuestionniare");
|
||||||
|
|
||||||
|
assertEquals(3, customerCount());
|
||||||
|
assertEquals(5, questionnaireCount());
|
||||||
|
|
||||||
|
String path = deploymentURL + PATH;
|
||||||
|
Request request = Request.Post(path).addHeader("Accept", "application/json; charset=utf-8")
|
||||||
|
.bodyFile(new File(BASE_UPLOAD + "add.json"), ContentType.APPLICATION_JSON);
|
||||||
|
|
||||||
|
HttpResponse httpResponse = executeRequest(request);
|
||||||
|
int code = httpResponse.getStatusLine().getStatusCode();
|
||||||
|
assertEquals(200, code);
|
||||||
|
|
||||||
|
assertEquals(3, customerCount());
|
||||||
|
assertEquals(6, questionnaireCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(3)
|
||||||
|
@Disabled // FIXME: enable when implemented
|
||||||
|
public void doAddCustomerWithQuestionnaire() throws IOException {
|
||||||
|
LOG.info("doAddCustomerWithQuestionnaire");
|
||||||
|
|
||||||
|
assertEquals(3, customerCount());
|
||||||
|
assertEquals(6, questionnaireCount());
|
||||||
|
|
||||||
|
String path = deploymentURL + PATH;
|
||||||
|
Request request = Request.Post(path).addHeader("Accept", "application/json; charset=utf-8")
|
||||||
|
.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, questionnaireCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(1)
|
||||||
|
@Disabled // FIXME: enable when implemented
|
||||||
|
public void doAddCustomerWithQuestionnaireWrongJson() throws IOException {
|
||||||
|
LOG.info("doAddCustomerWithQuestionnaireWrongJson");
|
||||||
|
|
||||||
|
String path = deploymentURL + PATH;
|
||||||
|
Request request = Request.Post(path).addHeader("Accept", "application/json; charset=utf-8")
|
||||||
|
.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
package marketing.heyday.hartmann.fotodocumentation.rest;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.client.fluent.Request;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||||
|
import org.junit.jupiter.api.Order;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* <p>Copyright: Copyright (c) 2024</p>
|
||||||
|
* <p>Company: heyday Marketing GmbH</p>
|
||||||
|
* @author <a href="mailto:p.verboom@heyday.marketing">Patrick Verboom</a>
|
||||||
|
* @version 1.0
|
||||||
|
*
|
||||||
|
* created: 14 Nov 2024
|
||||||
|
*/
|
||||||
|
@TestMethodOrder(OrderAnnotation.class)
|
||||||
|
public class QuestionnaireResourceTest extends AbstractQuestionnaireTest {
|
||||||
|
private static final Log LOG = LogFactory.getLog(QuestionnaireResourceTest.class);
|
||||||
|
private static final String PATH = "api/questionnaire";
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
public static void init() {
|
||||||
|
initDB();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(3)
|
||||||
|
public void doDelete() throws IOException {
|
||||||
|
LOG.info("doDelete");
|
||||||
|
|
||||||
|
assertEquals(5, questionnaireCount());
|
||||||
|
|
||||||
|
String path = deploymentURL + PATH + "/1";
|
||||||
|
Request request = Request.Delete(path).addHeader("Accept", "application/json; charset=utf-8")
|
||||||
|
.addHeader("Authorization", getAuthorization());
|
||||||
|
|
||||||
|
HttpResponse httpResponse = executeRequest(request);
|
||||||
|
int code = httpResponse.getStatusLine().getStatusCode();
|
||||||
|
assertEquals(200, code);
|
||||||
|
|
||||||
|
assertEquals(4, questionnaireCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(2)
|
||||||
|
public void doDeleteNotFound() throws IOException {
|
||||||
|
LOG.info("doDeleteNotFound");
|
||||||
|
|
||||||
|
assertEquals(5, questionnaireCount());
|
||||||
|
|
||||||
|
String path = deploymentURL + PATH + "/6000";
|
||||||
|
Request request = Request.Delete(path).addHeader("Accept", "application/json; charset=utf-8")
|
||||||
|
.addHeader("Authorization", getAuthorization());
|
||||||
|
|
||||||
|
HttpResponse httpResponse = executeRequest(request);
|
||||||
|
int code = httpResponse.getStatusLine().getStatusCode();
|
||||||
|
assertEquals(404, code);
|
||||||
|
|
||||||
|
assertEquals(5, questionnaireCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(1)
|
||||||
|
public void doEvaluation() throws IOException {
|
||||||
|
LOG.info("doEvaluation");
|
||||||
|
|
||||||
|
assertEquals(0, getCount("select count(*) from questionnaire where questionnaire_id = 1 and evaluation = 3"));
|
||||||
|
|
||||||
|
String path = deploymentURL + PATH + "/evaluation/1?evaluation=3";
|
||||||
|
Request request = Request.Put(path).addHeader("Accept", "application/json; charset=utf-8")
|
||||||
|
.addHeader("Authorization", getAuthorization());
|
||||||
|
|
||||||
|
HttpResponse httpResponse = executeRequest(request);
|
||||||
|
int code = httpResponse.getStatusLine().getStatusCode();
|
||||||
|
assertEquals(200, code);
|
||||||
|
|
||||||
|
assertEquals(1, getCount("select count(*) from questionnaire where questionnaire_id = 1 and evaluation = 3"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(1)
|
||||||
|
public void doEvaluationNotFound() throws IOException {
|
||||||
|
LOG.info("doEvaluationNotFound");
|
||||||
|
|
||||||
|
String path = deploymentURL + PATH + "/evaluation/6000?evaluation=3";
|
||||||
|
Request request = Request.Put(path).addHeader("Accept", "application/json; charset=utf-8")
|
||||||
|
.addHeader("Authorization", getAuthorization());
|
||||||
|
|
||||||
|
HttpResponse httpResponse = executeRequest(request);
|
||||||
|
int code = httpResponse.getStatusLine().getStatusCode();
|
||||||
|
assertEquals(404, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(1)
|
||||||
|
public void doEvaluationWrongValue() throws IOException {
|
||||||
|
LOG.info("doEvaluationWrongValue");
|
||||||
|
|
||||||
|
String path = deploymentURL + PATH + "/evaluation/1?evaluation=4";
|
||||||
|
Request request = Request.Put(path).addHeader("Accept", "application/json; charset=utf-8")
|
||||||
|
.addHeader("Authorization", getAuthorization());
|
||||||
|
|
||||||
|
HttpResponse httpResponse = executeRequest(request);
|
||||||
|
int code = httpResponse.getStatusLine().getStatusCode();
|
||||||
|
assertEquals(400, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(1)
|
||||||
|
public void doEvaluationWrongValue2() throws IOException {
|
||||||
|
LOG.info("doEvaluationWrongValue2");
|
||||||
|
|
||||||
|
String path = deploymentURL + PATH + "/evaluation/1?evaluation=0";
|
||||||
|
Request request = Request.Put(path).addHeader("Accept", "application/json; charset=utf-8")
|
||||||
|
.addHeader("Authorization", getAuthorization());
|
||||||
|
|
||||||
|
HttpResponse httpResponse = executeRequest(request);
|
||||||
|
int code = httpResponse.getStatusLine().getStatusCode();
|
||||||
|
assertEquals(400, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(1)
|
||||||
|
public void doEvaluationNoValue() throws IOException {
|
||||||
|
LOG.info("doEvaluationNoValue");
|
||||||
|
|
||||||
|
String path = deploymentURL + PATH + "/evaluation/1";
|
||||||
|
Request request = Request.Put(path).addHeader("Accept", "application/json; charset=utf-8")
|
||||||
|
.addHeader("Authorization", getAuthorization());
|
||||||
|
|
||||||
|
HttpResponse httpResponse = executeRequest(request);
|
||||||
|
int code = httpResponse.getStatusLine().getStatusCode();
|
||||||
|
assertEquals(400, code);
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,8 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"name": "Schmidt Apotheke",
|
||||||
|
"customerNumber": "3456",
|
||||||
|
"lastUpdateDate": 1768212570000
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "Meier Apotheke",
|
||||||
|
"customerNumber": "2345",
|
||||||
|
"lastUpdateDate": 1767607770000
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "Meier Apotheke",
|
||||||
|
"customerNumber": "2345",
|
||||||
|
"lastUpdateDate": 1767607770000
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "Müller Apotheke",
|
||||||
|
"customerNumber": "1234",
|
||||||
|
"lastUpdateDate": 1767348570000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "Meier Apotheke",
|
||||||
|
"customerNumber": "2345",
|
||||||
|
"lastUpdateDate": 1767607770000
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "Müller Apotheke",
|
||||||
|
"customerNumber": "1234",
|
||||||
|
"city": "Hannover",
|
||||||
|
"zip": "12345",
|
||||||
|
"questionnaires": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"comment": "good looking picture 1",
|
||||||
|
"category": null,
|
||||||
|
"questionnaireDate": 1767262170000,
|
||||||
|
"username": "verboomp",
|
||||||
|
"evaluation": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"comment": "good looking picture 2",
|
||||||
|
"category": null,
|
||||||
|
"questionnaireDate": 1767348570000,
|
||||||
|
"username": "verboomp",
|
||||||
|
"evaluation": 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "Müller Apotheke",
|
||||||
|
"customerNumber": "1234",
|
||||||
|
"lastUpdateDate": 1767348570000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "Meier Apotheke",
|
||||||
|
"customerNumber": "2345",
|
||||||
|
"lastUpdateDate": 1767607770000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"name": "Schmidt Apotheke",
|
||||||
|
"customerNumber": "3456",
|
||||||
|
"lastUpdateDate": 1768212570000
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import 'package:fotodocumentation/controller/base_controller.dart';
|
import 'package:fotodocumentation/controller/base_controller.dart';
|
||||||
import 'package:fotodocumentation/dto/customer_dto.dart';
|
import 'package:fotodocumentation/dto/customer_dto.dart';
|
||||||
|
|
||||||
abstract interface class CustomerController {
|
abstract interface class FotoCustomerController {
|
||||||
Future<List<CustomerListDto>> getAll(String query, String startsWith);
|
Future<List<CustomerListDto>> getAll(String query, String startsWith);
|
||||||
|
|
||||||
Future<CustomerDto?> get({required int id});
|
Future<CustomerDto?> get({required int id});
|
||||||
@@ -9,7 +9,7 @@ abstract interface class CustomerController {
|
|||||||
Future<List<int>> export({required int customerId, int? pictureId});
|
Future<List<int>> export({required int customerId, int? pictureId});
|
||||||
}
|
}
|
||||||
|
|
||||||
class CustomerControllerImpl extends BaseController implements CustomerController {
|
class FotoCustomerControllerImpl extends BaseController implements FotoCustomerController {
|
||||||
final String path = "customer";
|
final String path = "customer";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:fotodocumentation/controller/base_controller.dart';
|
import 'package:fotodocumentation/controller/base_controller.dart';
|
||||||
import 'package:fotodocumentation/controller/customer_controller.dart';
|
import 'package:fotodocumentation/controller/foto_customer_controller.dart';
|
||||||
import 'package:fotodocumentation/dto/customer_dto.dart';
|
import 'package:fotodocumentation/dto/customer_dto.dart';
|
||||||
import 'package:fotodocumentation/l10n/app_localizations.dart';
|
import 'package:fotodocumentation/l10n/app_localizations.dart';
|
||||||
import 'package:fotodocumentation/pages/ui_utils/component/general_error_widget.dart';
|
import 'package:fotodocumentation/pages/ui_utils/component/general_error_widget.dart';
|
||||||
@@ -21,7 +21,7 @@ class FotoCustomerListWidget extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _FotoCustomerListWidgetState extends State<FotoCustomerListWidget> {
|
class _FotoCustomerListWidgetState extends State<FotoCustomerListWidget> {
|
||||||
CustomerController get _customerController => DiContainer.get();
|
FotoCustomerController get _customerController => DiContainer.get();
|
||||||
GeneralStyle get _generalStyle => DiContainer.get();
|
GeneralStyle get _generalStyle => DiContainer.get();
|
||||||
|
|
||||||
final _searchController = TextEditingController();
|
final _searchController = TextEditingController();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:fotodocumentation/controller/base_controller.dart';
|
import 'package:fotodocumentation/controller/base_controller.dart';
|
||||||
import 'package:fotodocumentation/controller/customer_controller.dart';
|
import 'package:fotodocumentation/controller/foto_customer_controller.dart';
|
||||||
import 'package:fotodocumentation/controller/picture_controller.dart';
|
import 'package:fotodocumentation/controller/picture_controller.dart';
|
||||||
import 'package:fotodocumentation/dto/customer_dto.dart';
|
import 'package:fotodocumentation/dto/customer_dto.dart';
|
||||||
import 'package:fotodocumentation/dto/picture_dto.dart';
|
import 'package:fotodocumentation/dto/picture_dto.dart';
|
||||||
@@ -26,7 +26,7 @@ class FotoCustomerWidget extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _FotoCustomerWidgetState extends State<FotoCustomerWidget> {
|
class _FotoCustomerWidgetState extends State<FotoCustomerWidget> {
|
||||||
CustomerController get _customerController => DiContainer.get();
|
FotoCustomerController get _customerController => DiContainer.get();
|
||||||
PictureController get _pictureController => DiContainer.get();
|
PictureController get _pictureController => DiContainer.get();
|
||||||
GeneralStyle get _generalStyle => DiContainer.get();
|
GeneralStyle get _generalStyle => DiContainer.get();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:fotodocumentation/controller/base_controller.dart';
|
import 'package:fotodocumentation/controller/base_controller.dart';
|
||||||
import 'package:fotodocumentation/controller/customer_controller.dart';
|
import 'package:fotodocumentation/controller/foto_customer_controller.dart';
|
||||||
import 'package:fotodocumentation/controller/picture_controller.dart';
|
import 'package:fotodocumentation/controller/picture_controller.dart';
|
||||||
import 'package:fotodocumentation/dto/customer_dto.dart';
|
import 'package:fotodocumentation/dto/customer_dto.dart';
|
||||||
import 'package:fotodocumentation/dto/picture_dto.dart';
|
import 'package:fotodocumentation/dto/picture_dto.dart';
|
||||||
@@ -26,7 +26,7 @@ class FotoPictureWidget extends StatefulWidget {
|
|||||||
|
|
||||||
class _FotoPictureWidgetState extends State<FotoPictureWidget> {
|
class _FotoPictureWidgetState extends State<FotoPictureWidget> {
|
||||||
GeneralStyle get _generalStyle => DiContainer.get();
|
GeneralStyle get _generalStyle => DiContainer.get();
|
||||||
CustomerController get _customerController => DiContainer.get();
|
FotoCustomerController get _customerController => DiContainer.get();
|
||||||
PictureController get _pictureController => DiContainer.get();
|
PictureController get _pictureController => DiContainer.get();
|
||||||
|
|
||||||
late CustomerDto _customerDto;
|
late CustomerDto _customerDto;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import 'package:fotodocumentation/controller/customer_controller.dart';
|
import 'package:fotodocumentation/controller/foto_customer_controller.dart';
|
||||||
import 'package:fotodocumentation/controller/login_controller.dart';
|
import 'package:fotodocumentation/controller/login_controller.dart';
|
||||||
import 'package:fotodocumentation/controller/picture_controller.dart';
|
import 'package:fotodocumentation/controller/picture_controller.dart';
|
||||||
import 'package:fotodocumentation/controller/questionnaire_controller.dart';
|
import 'package:fotodocumentation/controller/questionnaire_controller.dart';
|
||||||
@@ -26,7 +26,7 @@ class DiContainer {
|
|||||||
DiContainer.instance.put(HttpClientUtils, HttpCLientUtilsImpl());
|
DiContainer.instance.put(HttpClientUtils, HttpCLientUtilsImpl());
|
||||||
DiContainer.instance.put(UrlUtils, UrlUtilsImpl());
|
DiContainer.instance.put(UrlUtils, UrlUtilsImpl());
|
||||||
DiContainer.instance.put(LoginController, LoginControllerImpl());
|
DiContainer.instance.put(LoginController, LoginControllerImpl());
|
||||||
DiContainer.instance.put(CustomerController, CustomerControllerImpl());
|
DiContainer.instance.put(FotoCustomerController, FotoCustomerControllerImpl());
|
||||||
DiContainer.instance.put(PictureController, PictureControllerImpl());
|
DiContainer.instance.put(PictureController, PictureControllerImpl());
|
||||||
|
|
||||||
DiContainer.instance.put(QuestionnaireCustomerController, QuestionnaireCustomerControllerImpl());
|
DiContainer.instance.put(QuestionnaireCustomerController, QuestionnaireCustomerControllerImpl());
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:fotodocumentation/controller/base_controller.dart';
|
import 'package:fotodocumentation/controller/base_controller.dart';
|
||||||
import 'package:fotodocumentation/controller/customer_controller.dart';
|
import 'package:fotodocumentation/controller/foto_customer_controller.dart';
|
||||||
import 'package:fotodocumentation/dto/customer_dto.dart';
|
import 'package:fotodocumentation/dto/customer_dto.dart';
|
||||||
import 'package:fotodocumentation/utils/di_container.dart';
|
import 'package:fotodocumentation/utils/di_container.dart';
|
||||||
import 'package:fotodocumentation/utils/http_client_utils.dart';
|
import 'package:fotodocumentation/utils/http_client_utils.dart';
|
||||||
@@ -17,7 +17,7 @@ void main() {
|
|||||||
when(jwtTokenStorage.getAccessToken()).thenAnswer((_) => null);
|
when(jwtTokenStorage.getAccessToken()).thenAnswer((_) => null);
|
||||||
DiContainer.instance.put(JwtTokenStorage, jwtTokenStorage);
|
DiContainer.instance.put(JwtTokenStorage, jwtTokenStorage);
|
||||||
|
|
||||||
CustomerController controller = CustomerControllerImpl();
|
FotoCustomerController controller = FotoCustomerControllerImpl();
|
||||||
|
|
||||||
group('PictureControllerTest', () {
|
group('PictureControllerTest', () {
|
||||||
test('returns a list of customers', () async {
|
test('returns a list of customers', () async {
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:fotodocumentation/controller/base_controller.dart';
|
||||||
|
import 'package:fotodocumentation/controller/questionnaire_customer_controller.dart';
|
||||||
|
import 'package:fotodocumentation/dto/questionnaire_customer_dto.dart';
|
||||||
|
import 'package:fotodocumentation/utils/di_container.dart';
|
||||||
|
import 'package:fotodocumentation/utils/http_client_utils.dart';
|
||||||
|
import 'package:fotodocumentation/utils/jwt_token_storage.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:mockito/mockito.dart';
|
||||||
|
|
||||||
|
import '../testing/test_http_client_utils.dart';
|
||||||
|
import '../testing/test_utils.mocks.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
DiContainer.instance.initState();
|
||||||
|
var jwtTokenStorage = MockJwtTokenStorage();
|
||||||
|
when(jwtTokenStorage.getAccessToken()).thenAnswer((_) => null);
|
||||||
|
DiContainer.instance.put(JwtTokenStorage, jwtTokenStorage);
|
||||||
|
|
||||||
|
QuestionnaireCustomerController controller = QuestionnaireCustomerControllerImpl();
|
||||||
|
|
||||||
|
group('PictureControllerTest', () {
|
||||||
|
test('returns a list of customers', () async {
|
||||||
|
final client = MockClient();
|
||||||
|
DiContainer.instance.put(HttpClientUtils, TestHttpCLientUtilsImpl(client));
|
||||||
|
when(client.get(Uri.parse('http://localhost:8080/api/questionnairecustomer?query=&startsWith='), headers: {"Accept-Language": "en-US"})).thenAnswer((_) async => http.Response(_customersJson, 200));
|
||||||
|
|
||||||
|
var dtos = await controller.getAll("", "");
|
||||||
|
expect(dtos, isA<List<QuestionnaireCustomerListDto>>());
|
||||||
|
expect(dtos.length, 3);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('throws an exception if the http call completes with an error', () async {
|
||||||
|
final client = MockClient();
|
||||||
|
DiContainer.instance.put(HttpClientUtils, TestHttpCLientUtilsImpl(client));
|
||||||
|
|
||||||
|
when(client.get(Uri.parse('http://localhost:8080/api/questionnairecustomer?query=&startsWith='), headers: {"Accept-Language": "en-US"})).thenAnswer((_) async => http.Response('Not Found', 404));
|
||||||
|
|
||||||
|
expect(() async => await controller.getAll("", ""), throwsA(isA<ServerError>()));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test('returns a customer', () async {
|
||||||
|
final client = MockClient();
|
||||||
|
DiContainer.instance.put(HttpClientUtils, TestHttpCLientUtilsImpl(client));
|
||||||
|
|
||||||
|
when(client.get(Uri.parse('http://localhost:8080/api/questionnairecustomer/4'), headers: {"Accept-Language": "en-US"}))
|
||||||
|
.thenAnswer((_) async => http.Response(_customerJson, 200));
|
||||||
|
|
||||||
|
var dto = await controller.get(id: 4);
|
||||||
|
expect(dto, isA<QuestionnaireCustomerListDto>());
|
||||||
|
});
|
||||||
|
|
||||||
|
test('export a customer', () async {
|
||||||
|
final client = MockClient();
|
||||||
|
DiContainer.instance.put(HttpClientUtils, TestHttpCLientUtilsImpl(client));
|
||||||
|
|
||||||
|
when(client.get(Uri.parse('http://localhost:8080/api/questionnairecustomer/export/4'), headers: {"Accept-Language": "en-US"}))
|
||||||
|
.thenAnswer((_) async => http.Response(_customerJson, 200));
|
||||||
|
|
||||||
|
var dto = await controller.export(customerId: 4);
|
||||||
|
expect(dto, isA<List<int>>());
|
||||||
|
});
|
||||||
|
|
||||||
|
test('export a customer picture', () async {
|
||||||
|
final client = MockClient();
|
||||||
|
DiContainer.instance.put(HttpClientUtils, TestHttpCLientUtilsImpl(client));
|
||||||
|
|
||||||
|
when(client.get(Uri.parse('http://localhost:8080/api/questionnairecustomer/export/4?picture=1'), headers: {"Accept-Language": "en-US"}))
|
||||||
|
.thenAnswer((_) async => http.Response(_customerJson, 200));
|
||||||
|
|
||||||
|
var dto = await controller.export(customerId: 4, questionnaireId: 1);
|
||||||
|
expect(dto, isA<List<int>>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
String _customersJson = '''[
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "Müller Apotheke",
|
||||||
|
"customerNumber": "1234",
|
||||||
|
"lastUpdateDate": 1729764570000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "Meier Apotheke",
|
||||||
|
"customerNumber": "2345",
|
||||||
|
"lastUpdateDate": 1729764570000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"name": "Schmidt Apotheke",
|
||||||
|
"customerNumber": "3456",
|
||||||
|
"lastUpdateDate": 1729764570000
|
||||||
|
}
|
||||||
|
]''';
|
||||||
|
|
||||||
|
String _customerJson = '''{
|
||||||
|
"id": 1,
|
||||||
|
"name": "Müller Apotheke",
|
||||||
|
"customerNumber": "1234",
|
||||||
|
"pictures": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"comment": "good looking picture 1",
|
||||||
|
"category": null,
|
||||||
|
"pictureDate": 1729764570000,
|
||||||
|
"evaluation": 1,
|
||||||
|
"username": "verboomp",
|
||||||
|
"imageUrl": "",
|
||||||
|
"normalSizeUrl": "",
|
||||||
|
"thumbnailSizeUrl": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"comment": "good looking picture 2",
|
||||||
|
"category": null,
|
||||||
|
"pictureDate": 1729764570000,
|
||||||
|
"evaluation": 1,
|
||||||
|
"username": "verboomp",
|
||||||
|
"imageUrl": "",
|
||||||
|
"normalSizeUrl": "",
|
||||||
|
"thumbnailSizeUrl": ""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}''';
|
||||||
|
|
||||||
@@ -6,7 +6,7 @@ import 'package:fotodocumentation/utils/global_router.dart';
|
|||||||
import 'package:fotodocumentation/utils/login_credentials.dart';
|
import 'package:fotodocumentation/utils/login_credentials.dart';
|
||||||
import 'package:mockito/mockito.dart';
|
import 'package:mockito/mockito.dart';
|
||||||
|
|
||||||
import 'package:fotodocumentation/controller/customer_controller.dart';
|
import 'package:fotodocumentation/controller/foto_customer_controller.dart';
|
||||||
import 'package:fotodocumentation/dto/customer_dto.dart';
|
import 'package:fotodocumentation/dto/customer_dto.dart';
|
||||||
import 'package:fotodocumentation/utils/di_container.dart';
|
import 'package:fotodocumentation/utils/di_container.dart';
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ Future<void> _searchtest(WidgetTester tester) async {
|
|||||||
String searchText = 'Henk';
|
String searchText = 'Henk';
|
||||||
|
|
||||||
var controller = MockCustomerController();
|
var controller = MockCustomerController();
|
||||||
DiContainer.instance.put(CustomerController, controller);
|
DiContainer.instance.put(FotoCustomerController, controller);
|
||||||
|
|
||||||
when(controller.getAll("", "")).thenAnswer((_) async => _list);
|
when(controller.getAll("", "")).thenAnswer((_) async => _list);
|
||||||
when(controller.getAll(searchText, "")).thenAnswer((_) async => [_list.first]);
|
when(controller.getAll(searchText, "")).thenAnswer((_) async => [_list.first]);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import 'package:fotodocumentation/utils/global_router.dart';
|
|||||||
import 'package:fotodocumentation/utils/login_credentials.dart';
|
import 'package:fotodocumentation/utils/login_credentials.dart';
|
||||||
import 'package:mockito/mockito.dart';
|
import 'package:mockito/mockito.dart';
|
||||||
|
|
||||||
import 'package:fotodocumentation/controller/customer_controller.dart';
|
import 'package:fotodocumentation/controller/foto_customer_controller.dart';
|
||||||
import 'package:fotodocumentation/controller/picture_controller.dart';
|
import 'package:fotodocumentation/controller/picture_controller.dart';
|
||||||
import 'package:fotodocumentation/dto/customer_dto.dart';
|
import 'package:fotodocumentation/dto/customer_dto.dart';
|
||||||
import 'package:fotodocumentation/utils/di_container.dart';
|
import 'package:fotodocumentation/utils/di_container.dart';
|
||||||
@@ -28,7 +28,7 @@ void main() {
|
|||||||
var controller = MockCustomerController();
|
var controller = MockCustomerController();
|
||||||
var pictureController = MockPictureController();
|
var pictureController = MockPictureController();
|
||||||
DiContainer.instance.put(PictureController, pictureController);
|
DiContainer.instance.put(PictureController, pictureController);
|
||||||
DiContainer.instance.put(CustomerController, controller);
|
DiContainer.instance.put(FotoCustomerController, controller);
|
||||||
|
|
||||||
when(controller.get(id: 1)).thenAnswer((_) async => _dto);
|
when(controller.get(id: 1)).thenAnswer((_) async => _dto);
|
||||||
when(controller.getAll("", "")).thenAnswer((_) async => _list);
|
when(controller.getAll("", "")).thenAnswer((_) async => _list);
|
||||||
@@ -51,7 +51,7 @@ void main() {
|
|||||||
var controller = MockCustomerController();
|
var controller = MockCustomerController();
|
||||||
var pictureController = MockPictureController();
|
var pictureController = MockPictureController();
|
||||||
DiContainer.instance.put(PictureController, pictureController);
|
DiContainer.instance.put(PictureController, pictureController);
|
||||||
DiContainer.instance.put(CustomerController, controller);
|
DiContainer.instance.put(FotoCustomerController, controller);
|
||||||
|
|
||||||
when(controller.get(id: 1)).thenAnswer((_) async => _dto);
|
when(controller.get(id: 1)).thenAnswer((_) async => _dto);
|
||||||
when(controller.getAll("", "")).thenAnswer((_) async => _list);
|
when(controller.getAll("", "")).thenAnswer((_) async => _list);
|
||||||
@@ -83,7 +83,7 @@ void main() {
|
|||||||
var controller = MockCustomerController();
|
var controller = MockCustomerController();
|
||||||
var pictureController = MockPictureController();
|
var pictureController = MockPictureController();
|
||||||
DiContainer.instance.put(PictureController, pictureController);
|
DiContainer.instance.put(PictureController, pictureController);
|
||||||
DiContainer.instance.put(CustomerController, controller);
|
DiContainer.instance.put(FotoCustomerController, controller);
|
||||||
|
|
||||||
when(controller.get(id: 1)).thenAnswer((_) async => _dto);
|
when(controller.get(id: 1)).thenAnswer((_) async => _dto);
|
||||||
when(controller.getAll("", "")).thenAnswer((_) async => _list);
|
when(controller.getAll("", "")).thenAnswer((_) async => _list);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_image_test_utils/image_test/image_test_io.dart';
|
import 'package:flutter_image_test_utils/image_test/image_test_io.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:fotodocumentation/controller/customer_controller.dart';
|
import 'package:fotodocumentation/controller/foto_customer_controller.dart';
|
||||||
import 'package:fotodocumentation/dto/customer_dto.dart' show CustomerDto, CustomerListDto;
|
import 'package:fotodocumentation/dto/customer_dto.dart' show CustomerDto, CustomerListDto;
|
||||||
import 'package:fotodocumentation/dto/picture_dto.dart';
|
import 'package:fotodocumentation/dto/picture_dto.dart';
|
||||||
import 'package:fotodocumentation/pages/foto/customer/foto_picture_fullscreen_dialog.dart';
|
import 'package:fotodocumentation/pages/foto/customer/foto_picture_fullscreen_dialog.dart';
|
||||||
@@ -69,7 +69,7 @@ void main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
mockCustomerController = MockCustomerController();
|
mockCustomerController = MockCustomerController();
|
||||||
DiContainer.instance.put(CustomerController, mockCustomerController);
|
DiContainer.instance.put(FotoCustomerController, mockCustomerController);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('PictureWidget', () {
|
group('PictureWidget', () {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import 'package:http/http.dart' as http;
|
|||||||
import 'package:mockito/annotations.dart';
|
import 'package:mockito/annotations.dart';
|
||||||
import 'package:mockito/mockito.dart';
|
import 'package:mockito/mockito.dart';
|
||||||
|
|
||||||
import 'package:fotodocumentation/controller/customer_controller.dart';
|
import 'package:fotodocumentation/controller/foto_customer_controller.dart';
|
||||||
import 'package:fotodocumentation/controller/login_controller.dart';
|
import 'package:fotodocumentation/controller/login_controller.dart';
|
||||||
import 'package:fotodocumentation/controller/picture_controller.dart';
|
import 'package:fotodocumentation/controller/picture_controller.dart';
|
||||||
import 'package:fotodocumentation/l10n/app_localizations.dart';
|
import 'package:fotodocumentation/l10n/app_localizations.dart';
|
||||||
@@ -63,7 +63,7 @@ Future<void> pumpAppConfig(WidgetTester tester, String initialLocation) async {
|
|||||||
@GenerateMocks([
|
@GenerateMocks([
|
||||||
LoginCredentials,
|
LoginCredentials,
|
||||||
LoginController,
|
LoginController,
|
||||||
CustomerController,
|
FotoCustomerController,
|
||||||
PictureController,
|
PictureController,
|
||||||
JwtTokenStorage,
|
JwtTokenStorage,
|
||||||
http.Client,
|
http.Client,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import 'dart:convert' as _i14;
|
|||||||
import 'dart:typed_data' as _i15;
|
import 'dart:typed_data' as _i15;
|
||||||
import 'dart:ui' as _i5;
|
import 'dart:ui' as _i5;
|
||||||
|
|
||||||
import 'package:fotodocumentation/controller/customer_controller.dart' as _i9;
|
import 'package:fotodocumentation/controller/foto_customer_controller.dart' as _i9;
|
||||||
import 'package:fotodocumentation/controller/login_controller.dart' as _i6;
|
import 'package:fotodocumentation/controller/login_controller.dart' as _i6;
|
||||||
import 'package:fotodocumentation/controller/picture_controller.dart' as _i11;
|
import 'package:fotodocumentation/controller/picture_controller.dart' as _i11;
|
||||||
import 'package:fotodocumentation/dto/customer_dto.dart' as _i10;
|
import 'package:fotodocumentation/dto/customer_dto.dart' as _i10;
|
||||||
@@ -188,7 +188,7 @@ class MockLoginController extends _i1.Mock implements _i6.LoginController {
|
|||||||
///
|
///
|
||||||
/// See the documentation for Mockito's code generation for more information.
|
/// See the documentation for Mockito's code generation for more information.
|
||||||
class MockCustomerController extends _i1.Mock
|
class MockCustomerController extends _i1.Mock
|
||||||
implements _i9.CustomerController {
|
implements _i9.FotoCustomerController {
|
||||||
MockCustomerController() {
|
MockCustomerController() {
|
||||||
_i1.throwOnMissingStub(this);
|
_i1.throwOnMissingStub(this);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user