Search in sources :

Example 1 with TestCase

use of com.google.firebase.firestore.conformance.model.TestCase in project firebase-android-sdk by firebase.

the class TestCaseConverter method convertTestCases.

public List<TestCase> convertTestCases(DatastoreTestTrace.TestTrace trace) {
    List<TestCase> testCases = new ArrayList<>();
    for (DatastoreTestTrace.DatastoreAction action : trace.getActionList()) {
        if (actionFilter.test(action)) {
            TestCase.Builder builder = TestCase.Builder.builder();
            DatastoreTestTrace.FirestoreV1Action firestoreAction = action.getFirestoreV1Action();
            List<Collection> collections = convertDatabaseContents(firestoreAction);
            StructuredQuery queryProto = firestoreAction.getRunQuery().getRequest().getStructuredQuery();
            String parentPath = ResourcePath.fromString(firestoreAction.getRunQuery().getRequest().getParent()).popFirst(5).toString();
            Query query = convertQuery(queryProto, parentPath);
            // Add query collection to contents if there are no pre-existing documents.
            if (collections.isEmpty()) {
                collections.add(Collection.Builder.builder().setName(query.getCollection()).build());
            }
            builder.setCollections(collections);
            builder.setQuery(query);
            // Convert results.
            builder.setException(firestoreAction.hasStatus());
            if (!firestoreAction.hasStatus()) {
                Result.Builder result = Result.Builder.builder();
                List<RunQueryResponse> responses = firestoreAction.getRunQuery().getResponseList();
                result.setDocuments(responses.stream().filter(r -> r.hasDocument()).map(r -> r.getDocument()).collect(Collectors.toList()));
                builder.setResult(result.build());
            }
            builder.setName(String.format("%s_%d", trace.getTraceId(), action.getActionId()));
            testCases.add(builder.build());
        }
    }
    return testCases;
}
Also used : StructuredQuery(com.google.firestore.v1.StructuredQuery) StructuredQuery(com.google.firestore.v1.StructuredQuery) DatastoreTestTrace(com.google.apphosting.datastore.testing.DatastoreTestTrace) Document(com.google.firestore.v1.Document) Where(com.google.firebase.firestore.conformance.model.Where) ResourcePath(com.google.firebase.firestore.model.ResourcePath) QueryFilter(com.google.firebase.firestore.conformance.model.QueryFilter) Collectors(java.util.stream.Collectors) Order(com.google.firebase.firestore.conformance.model.Order) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) Value(com.google.firestore.v1.Value) Result(com.google.firebase.firestore.conformance.model.Result) Cursor(com.google.firestore.v1.Cursor) Query(com.google.firebase.firestore.conformance.model.Query) Collection(com.google.firebase.firestore.conformance.model.Collection) RunQueryResponse(com.google.firestore.v1.RunQueryResponse) DocumentKey(com.google.firebase.firestore.model.DocumentKey) TestCase(com.google.firebase.firestore.conformance.model.TestCase) StructuredQuery(com.google.firestore.v1.StructuredQuery) Query(com.google.firebase.firestore.conformance.model.Query) ArrayList(java.util.ArrayList) DatastoreTestTrace(com.google.apphosting.datastore.testing.DatastoreTestTrace) Result(com.google.firebase.firestore.conformance.model.Result) TestCase(com.google.firebase.firestore.conformance.model.TestCase) RunQueryResponse(com.google.firestore.v1.RunQueryResponse) Collection(com.google.firebase.firestore.conformance.model.Collection)

Example 2 with TestCase

use of com.google.firebase.firestore.conformance.model.TestCase in project firebase-android-sdk by firebase.

the class ConformanceTest method run.

@Test
public void run() throws Exception {
    for (TestCase testCase : testCases) {
        ConformanceRuntime runtime = new ConformanceRuntime(firestore, Source.CACHE);
        executeTestCases(testCase, runtime);
    }
}
Also used : TestCase(com.google.firebase.firestore.conformance.model.TestCase) ConformanceRuntime(com.google.firebase.firestore.conformance.ConformanceRuntime) Test(org.junit.Test)

Aggregations

TestCase (com.google.firebase.firestore.conformance.model.TestCase)2 DatastoreTestTrace (com.google.apphosting.datastore.testing.DatastoreTestTrace)1 ConformanceRuntime (com.google.firebase.firestore.conformance.ConformanceRuntime)1 Collection (com.google.firebase.firestore.conformance.model.Collection)1 Order (com.google.firebase.firestore.conformance.model.Order)1 Query (com.google.firebase.firestore.conformance.model.Query)1 QueryFilter (com.google.firebase.firestore.conformance.model.QueryFilter)1 Result (com.google.firebase.firestore.conformance.model.Result)1 Where (com.google.firebase.firestore.conformance.model.Where)1 DocumentKey (com.google.firebase.firestore.model.DocumentKey)1 ResourcePath (com.google.firebase.firestore.model.ResourcePath)1 Cursor (com.google.firestore.v1.Cursor)1 Document (com.google.firestore.v1.Document)1 RunQueryResponse (com.google.firestore.v1.RunQueryResponse)1 StructuredQuery (com.google.firestore.v1.StructuredQuery)1 Value (com.google.firestore.v1.Value)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1