mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
Passing tests?
This commit is contained in:
@ -372,7 +372,7 @@ public class QJavalinApiHandler
|
||||
}
|
||||
else if(orderByNameDirection.length > 2)
|
||||
{
|
||||
badRequestMessages.add("unrecognized format for orderBy clause: " + orderByPart + ". Expected: fieldName [ASC|DESC].");
|
||||
badRequestMessages.add("Unrecognized format for orderBy clause: " + orderByPart + ". Expected: fieldName [ASC|DESC].");
|
||||
}
|
||||
|
||||
try
|
||||
@ -382,7 +382,7 @@ public class QJavalinApiHandler
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
badRequestMessages.add("unrecognized orderBy field name: " + orderByNameDirection[0] + ".");
|
||||
badRequestMessages.add("Unrecognized orderBy field name: " + orderByNameDirection[0] + ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,8 +26,10 @@ import java.util.List;
|
||||
import com.kingsrook.qqq.api.model.APIVersion;
|
||||
import com.kingsrook.qqq.api.model.metadata.ApiInstanceMetaData;
|
||||
import com.kingsrook.qqq.api.model.metadata.tables.ApiTableMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QAuthenticationType;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QBackendMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.authentication.Auth0AuthenticationMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.DisplayFormat;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
|
||||
@ -41,7 +43,7 @@ import com.kingsrook.qqq.backend.core.modules.backend.implementations.memory.Mem
|
||||
public class TestUtils
|
||||
{
|
||||
public static final String MEMORY_BACKEND_NAME = "memory";
|
||||
private static final String TABLE_NAME_PERSON = "person";
|
||||
public static final String TABLE_NAME_PERSON = "person";
|
||||
|
||||
private static final String API_VERSION = "2023.Q1";
|
||||
|
||||
@ -56,6 +58,7 @@ public class TestUtils
|
||||
|
||||
qInstance.addBackend(defineMemoryBackend());
|
||||
qInstance.addTable(defineTablePerson());
|
||||
qInstance.setAuthentication(new Auth0AuthenticationMetaData().withType(QAuthenticationType.FULLY_ANONYMOUS).withName("anonymous"));
|
||||
|
||||
qInstance.withMiddlewareMetaData(new ApiInstanceMetaData()
|
||||
.withCurrentVersion(new APIVersion(API_VERSION))
|
||||
|
@ -22,22 +22,31 @@
|
||||
package com.kingsrook.qqq.api.javalin;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import com.kingsrook.qqq.api.BaseTest;
|
||||
import com.kingsrook.qqq.api.TestUtils;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QInstanceValidationException;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertOutput;
|
||||
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.javalin.QJavalinImplementation;
|
||||
import kong.unirest.HttpResponse;
|
||||
import kong.unirest.Unirest;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Unit test for QJavalinApiHandler
|
||||
*******************************************************************************/
|
||||
class QJavalinApiHandlerTest
|
||||
class QJavalinApiHandlerTest extends BaseTest
|
||||
{
|
||||
private static final int PORT = 6263;
|
||||
protected static final String BASE_URL = "http://localhost:" + PORT;
|
||||
@ -94,14 +103,70 @@ class QJavalinApiHandlerTest
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testGet404()
|
||||
{
|
||||
HttpResponse<String> response = Unirest.get(BASE_URL + "/api/" + VERSION + "/person/1").asString();
|
||||
assertEquals(404, response.getStatus());
|
||||
JSONObject jsonObject = new JSONObject(response.getBody());
|
||||
assertEquals("Could not find Person with Id of 1", jsonObject.getString("error"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testGet200() throws QException
|
||||
{
|
||||
InsertInput insertInput = new InsertInput();
|
||||
insertInput.setTableName(TestUtils.TABLE_NAME_PERSON);
|
||||
insertInput.setRecords(List.of(new QRecord().withValue("id", 1).withValue("firstName", "Darin").withValue("lastName", "Kelkhoff")));
|
||||
InsertOutput insertOutput = new InsertAction().execute(insertInput);
|
||||
|
||||
HttpResponse<String> response = Unirest.get(BASE_URL + "/api/" + VERSION + "/person/1").asString();
|
||||
assertEquals(200, response.getStatus());
|
||||
JSONObject jsonObject = new JSONObject(response.getBody());
|
||||
assertEquals(1, jsonObject.getInt("id"));
|
||||
assertEquals("Darin", jsonObject.getString("firstName"));
|
||||
assertEquals("Kelkhoff", jsonObject.getString("lastName"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testQuery400()
|
||||
{
|
||||
HttpResponse<String> response = Unirest.get(BASE_URL + "/api/" + VERSION + "/person/query?asdf=Darin&orderBy=asdf asdf").asString();
|
||||
assertEquals(400, response.getStatus());
|
||||
JSONObject jsonObject = new JSONObject(response.getBody());
|
||||
String error = jsonObject.getString("error");
|
||||
assertThat(error).contains("orderBy direction for field asdf must be either ASC or DESC");
|
||||
assertThat(error).contains("Unrecognized orderBy field name: asdf");
|
||||
assertThat(error).contains("Unrecognized filter criteria field: asdf");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testQuery()
|
||||
{
|
||||
HttpResponse<String> response = Unirest.get(BASE_URL + "/api/" + VERSION + "/person/query").asString();
|
||||
System.out.println(response.getBody());
|
||||
HttpResponse<String> response = Unirest.get(BASE_URL + "/api/" + VERSION + "/person/query?firstName=Darin&orderBy=firstName desc").asString();
|
||||
assertEquals(200, response.getStatus());
|
||||
JSONObject jsonObject = new JSONObject(response.getBody());
|
||||
assertEquals(0, jsonObject.getInt("count"));
|
||||
assertEquals(1, jsonObject.getInt("pageNo"));
|
||||
assertEquals(50, jsonObject.getInt("pageSize"));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user