// Path: src/main/java/at/grahsl/kafka/connect/mongodb/converter/SinkDocument.java
// public class SinkDocument {
// 
//     private final Optional<BsonDocument> keyDoc;
//     private final Optional<BsonDocument> valueDoc;
// 
//     public SinkDocument(BsonDocument keyDoc, BsonDocument valueDoc) {
//         this.keyDoc = Optional.ofNullable(keyDoc);
//         this.valueDoc = Optional.ofNullable(valueDoc);
//     }
// 
//     public Optional<BsonDocument> getKeyDoc() {
//         return keyDoc;
//     }
// 
//     public Optional<BsonDocument> getValueDoc() {
//         return valueDoc;
//     }
// 
//     public SinkDocument clone() {
//         BsonDocument kd = keyDoc.isPresent() ? keyDoc.get().clone() : null;
//         BsonDocument vd = valueDoc.isPresent() ? valueDoc.get().clone() : null;
//         return new SinkDocument(kd,vd);
//     }
// 
// }


import at.grahsl.kafka.connect.mongodb.converter.SinkDocument;
import com.mongodb.DBCollection;
import com.mongodb.client.model.ReplaceOneModel;
import com.mongodb.client.model.WriteModel;
import org.apache.kafka.connect.errors.DataException;
import org.bson.*;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import static org.junit.jupiter.api.Assertions.*;
                        .append("active", new BsonBoolean(false)));

        verifyResultsNoPK(valueDocCreate);

        BsonDocument valueDocRead = new BsonDocument("op",new BsonString("r"))
                .append("after",new BsonDocument("text", new BsonString("lalala"))
                        .append("number", new BsonInt32(1234))
                        .append("active", new BsonBoolean(false)));

        verifyResultsNoPK(valueDocRead);

    }

    private void verifyResultsNoPK(BsonDocument valueDoc) {

        //NOTE: for both filterDoc and replacementDoc _id is a generated ObjectId
        //which cannot be set from outside for testing thus it is set
        //by taking it from the resulting writeModel in order to do an equals comparison
        //for all contained fields

        BsonDocument filterDoc = new BsonDocument();

        BsonDocument replacementDoc =
                new BsonDocument("text", new BsonString("lalala"))
                        .append("number", new BsonInt32(1234))
                        .append("active", new BsonBoolean(false));

        BsonDocument keyDoc = new BsonDocument();

        WriteModel<BsonDocument> result =
// Path: src/main/java/at/grahsl/kafka/connect/mongodb/converter/SinkDocument.java
// public class SinkDocument {
// 
//     private final Optional<BsonDocument> keyDoc;
//     private final Optional<BsonDocument> valueDoc;
// 
//     public SinkDocument(BsonDocument keyDoc, BsonDocument valueDoc) {
//         this.keyDoc = Optional.ofNullable(keyDoc);
//         this.valueDoc = Optional.ofNullable(valueDoc);
//     }
// 
//     public Optional<BsonDocument> getKeyDoc() {
//         return keyDoc;
//     }
// 
//     public Optional<BsonDocument> getValueDoc() {
//         return valueDoc;
//     }
// 
//     public SinkDocument clone() {
//         BsonDocument kd = keyDoc.isPresent() ? keyDoc.get().clone() : null;
//         BsonDocument vd = valueDoc.isPresent() ? valueDoc.get().clone() : null;
//         return new SinkDocument(kd,vd);
//     }
// 
// }


// Path: src/test/java/at/grahsl/kafka/connect/mongodb/cdc/debezium/rdbms/RdbmsInsertTest.java
import at.grahsl.kafka.connect.mongodb.converter.SinkDocument;
import com.mongodb.DBCollection;
import com.mongodb.client.model.ReplaceOneModel;
import com.mongodb.client.model.WriteModel;
import org.apache.kafka.connect.errors.DataException;
import org.bson.*;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import static org.junit.jupiter.api.Assertions.*;

                        .append("active", new BsonBoolean(false)));

        verifyResultsNoPK(valueDocCreate);

        BsonDocument valueDocRead = new BsonDocument("op",new BsonString("r"))
                .append("after",new BsonDocument("text", new BsonString("lalala"))
                        .append("number", new BsonInt32(1234))
                        .append("active", new BsonBoolean(false)));

        verifyResultsNoPK(valueDocRead);

    }

    private void verifyResultsNoPK(BsonDocument valueDoc) {

        //NOTE: for both filterDoc and replacementDoc _id is a generated ObjectId
        //which cannot be set from outside for testing thus it is set
        //by taking it from the resulting writeModel in order to do an equals comparison
        //for all contained fields

        BsonDocument filterDoc = new BsonDocument();

        BsonDocument replacementDoc =
                new BsonDocument("text", new BsonString("lalala"))
                        .append("number", new BsonInt32(1234))
                        .append("active", new BsonBoolean(false));

        BsonDocument keyDoc = new BsonDocument();

        WriteModel<BsonDocument> result =
                RDBMS_INSERT.perform(new SinkDocument(keyDoc,valueDoc));