Java Code Examples for org.bson.BsonString

The following examples show how to use org.bson.BsonString. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: mongo-kafka   Source File: SinkConverterTest.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeAll
static void initializeTestData() {
  String jsonString1 = "{\"myField\":\"some text\"}";
  Schema objSchema1 = SchemaBuilder.struct().field("myField", Schema.STRING_SCHEMA);
  Struct objStruct1 = new Struct(objSchema1).put("myField", "some text");

  Map<String, Object> objMap1 = new LinkedHashMap<>();
  objMap1.put("myField", "some text");

  expectedBsonDoc = new BsonDocument("myField", new BsonString("some text"));

  combinations = new HashMap<>();
  combinations.put(jsonString1, null);
  combinations.put(objStruct1, objSchema1);
  combinations.put(objMap1, null);
}
 
Example 2
Source Project: mongo-kafka   Source File: MongoDbUpdateTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@DisplayName("when valid doc change cdc event then correct UpdateOneModel")
void testValidSinkDocumentForUpdate() {
  BsonDocument keyDoc = BsonDocument.parse("{id: '1234'}");
  BsonDocument valueDoc =
      new BsonDocument("op", new BsonString("u"))
          .append("patch", new BsonString(UPDATE_DOC.toJson()));

  WriteModel<BsonDocument> result = UPDATE.perform(new SinkDocument(keyDoc, valueDoc));
  assertTrue(result instanceof UpdateOneModel, "result expected to be of type UpdateOneModel");

  UpdateOneModel<BsonDocument> writeModel = (UpdateOneModel<BsonDocument>) result;
  assertEquals(UPDATE_DOC, writeModel.getUpdate(), "update doc not matching what is expected");
  assertTrue(
      writeModel.getFilter() instanceof BsonDocument,
      "filter expected to be of type BsonDocument");
  assertEquals(FILTER_DOC, writeModel.getFilter());
}
 
Example 3
Source Project: mongo-kafka   Source File: MongoDbUpdateTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@DisplayName(
    "when valid doc change cdc event containing internal oplog fields then correct UpdateOneModel")
public void testValidSinkDocumentWithInternalOploagFieldForUpdate() {
  BsonDocument keyDoc = BsonDocument.parse("{id: '1234'}");
  BsonDocument valueDoc =
      new BsonDocument("op", new BsonString("u"))
          .append("patch", new BsonString(UPDATE_DOC_WITH_OPLOG_INTERNALS.toJson()));

  WriteModel<BsonDocument> result = UPDATE.perform(new SinkDocument(keyDoc, valueDoc));
  assertTrue(
      result instanceof UpdateOneModel, () -> "result expected to be of type UpdateOneModel");

  UpdateOneModel<BsonDocument> writeModel = (UpdateOneModel<BsonDocument>) result;
  assertEquals(
      UPDATE_DOC, writeModel.getUpdate(), () -> "update doc not matching what is expected");
  assertTrue(
      writeModel.getFilter() instanceof BsonDocument,
      () -> "filter expected to be of type BsonDocument");
  assertEquals(FILTER_DOC, writeModel.getFilter());
}
 
Example 4
Source Project: mongo-kafka   Source File: MongoDbInsertTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@DisplayName("when valid cdc event then correct ReplaceOneModel")
void testValidSinkDocument() {
  BsonDocument keyDoc = new BsonDocument("id", new BsonString("1234"));
  BsonDocument valueDoc =
      new BsonDocument("op", new BsonString("c"))
          .append("after", new BsonString(REPLACEMENT_DOC.toJson()));

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

  assertTrue(result instanceof ReplaceOneModel, "result expected to be of type ReplaceOneModel");

  ReplaceOneModel<BsonDocument> writeModel = (ReplaceOneModel<BsonDocument>) result;

  assertEquals(
      REPLACEMENT_DOC,
      writeModel.getReplacement(),
      "replacement doc not matching what is expected");
  assertTrue(
      writeModel.getFilter() instanceof BsonDocument,
      "filter expected to be of type BsonDocument");
  assertEquals(FILTER_DOC, writeModel.getFilter());
  assertTrue(
      writeModel.getReplaceOptions().isUpsert(),
      "replacement expected to be done in upsert mode");
}
 
Example 5
Source Project: game-server   Source File: MongoUtil.java    License: MIT License 6 votes vote down vote up
public static BsonValue getBsonValue(Object obj) {
    if (obj instanceof Integer) {
        return new BsonInt32((Integer) obj);
    }

    if (obj instanceof String) {
        return new BsonString((String) obj);
    }

    if (obj instanceof Long) {
        return new BsonInt64((Long) obj);
    }

    if (obj instanceof Date) {
        return new BsonDateTime(((Date) obj).getTime());
    }
    if (obj instanceof Double || obj instanceof Float) {
        return new BsonDouble((Double) obj);
    }
    return new BsonNull();

}
 
Example 6
Source Project: game-server   Source File: MongoUtil.java    License: MIT License 6 votes vote down vote up
public static BsonValue getBsonValue(Object obj) {
    if (obj instanceof Integer) {
        return new BsonInt32((Integer) obj);
    }

    if (obj instanceof String) {
        return new BsonString((String) obj);
    }

    if (obj instanceof Long) {
        return new BsonInt64((Long) obj);
    }

    if (obj instanceof Date) {
        return new BsonDateTime(((Date) obj).getTime());
    }
    if (obj instanceof Double || obj instanceof Float) {
        return new BsonDouble((Double) obj);
    }
    return new BsonNull();

}
 
Example 7
Source Project: kafka-connect-mongodb   Source File: RdbmsDeleteTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@DisplayName("when valid cdc event with single field PK then correct DeleteOneModel")
public void testValidSinkDocumentSingleFieldPK() {

    BsonDocument filterDoc =
            new BsonDocument(DBCollection.ID_FIELD_NAME,
                    new BsonDocument("id",new BsonInt32(1004)));

    BsonDocument keyDoc = new BsonDocument("id",new BsonInt32(1004));
    BsonDocument valueDoc = new BsonDocument("op",new BsonString("d"));

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

    assertTrue(result instanceof DeleteOneModel,
            () -> "result expected to be of type DeleteOneModel");

    DeleteOneModel<BsonDocument> writeModel =
            (DeleteOneModel<BsonDocument>) result;

    assertTrue(writeModel.getFilter() instanceof BsonDocument,
            () -> "filter expected to be of type BsonDocument");

    assertEquals(filterDoc,writeModel.getFilter());

}
 
Example 8
Source Project: kafka-connect-mongodb   Source File: MongoDbUpdateTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@DisplayName("when valid doc change cdc event then correct UpdateOneModel")
public void testValidSinkDocumentForUpdate() {
    BsonDocument keyDoc = new BsonDocument("id",new BsonString("1004"));

    BsonDocument valueDoc = new BsonDocument("op",new BsonString("u"))
            .append("patch",new BsonString(UPDATE_DOC.toJson()));

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

    assertTrue(result instanceof UpdateOneModel,
            () -> "result expected to be of type UpdateOneModel");

    UpdateOneModel<BsonDocument> writeModel =
            (UpdateOneModel<BsonDocument>) result;

    assertEquals(UPDATE_DOC,writeModel.getUpdate(),
            ()-> "update doc not matching what is expected");

    assertTrue(writeModel.getFilter() instanceof BsonDocument,
            () -> "filter expected to be of type BsonDocument");

    assertEquals(FILTER_DOC,writeModel.getFilter());

}
 
Example 9
Source Project: ditto   Source File: BulkWriteResultAckFlowTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void allSuccess() {
    final List<AbstractWriteModel> writeModels = generate5WriteModels();
    final BulkWriteResult result = BulkWriteResult.acknowledged(0, 3, 1, 1,
            List.of(new BulkWriteUpsert(0, new BsonString("upsert 0")),
                    new BulkWriteUpsert(4, new BsonString("upsert 4")))
    );

    // WHEN
    final WriteResultAndErrors resultAndErrors = WriteResultAndErrors.success(writeModels, result);
    final String message = runBulkWriteResultAckFlowAndGetFirstLogEntry(resultAndErrors);

    // THEN
    actorSystem.log().info(message);
    assertThat(message).contains("Acknowledged: Success");
}
 
Example 10
@Test
public void selectEntityWhenNamespacesDisabled() {
    final MongoEventSourceSettings settings = MongoEventSourceSettings.of(PERSISTENCE_ID_PREFIX,
            false, METADATA_COLLECTION_NAME, JOURNAL_COLLECTION_NAME, SNAPSHOT_COLLECTION_NAME);
    final MongoPersistenceOperationsSelectionProvider underTest =
            MongoPersistenceOperationsSelectionProvider.of(settings);

    final Collection<MongoPersistenceOperationsSelection> selections =
            underTest.selectEntity(DefaultEntityId.of(ENTITY_NAME));

    final String pid = PERSISTENCE_ID_PREFIX + ENTITY_NAME;
    final Document pidFilter = new Document().append(KEY_PID, new BsonString(pid));
    final MongoPersistenceOperationsSelection expectedMetadataSelection =
            MongoPersistenceOperationsSelection.of(METADATA_COLLECTION_NAME, pidFilter);
    final MongoPersistenceOperationsSelection expectedJournalSelection =
            MongoPersistenceOperationsSelection.of(JOURNAL_COLLECTION_NAME, pidFilter);
    final MongoPersistenceOperationsSelection expectedSnapshotSelection =
            MongoPersistenceOperationsSelection.of(SNAPSHOT_COLLECTION_NAME, pidFilter);
    assertThat(selections)
            .containsExactlyInAnyOrder(expectedMetadataSelection, expectedJournalSelection,
                    expectedSnapshotSelection);
}
 
Example 11
NamespaceSynchronizationConfig(
    final MongoCollection<NamespaceSynchronizationConfig> namespacesColl,
    final MongoCollection<CoreDocumentSynchronizationConfig> docsColl,
    final MongoNamespace namespace
) {
  this.namespacesColl = namespacesColl;
  this.docsColl = docsColl;
  this.namespace = namespace;
  this.syncedDocuments = new ConcurrentHashMap<>();
  this.nsLock = new ReentrantReadWriteLock();

  // Fill from db
  final BsonDocument docsFilter = new BsonDocument();
  docsFilter.put(
      CoreDocumentSynchronizationConfig.ConfigCodec.Fields.NAMESPACE_FIELD,
      new BsonString(namespace.toString()));
  docsColl.find(docsFilter, CoreDocumentSynchronizationConfig.class)
      .forEach(new Block<CoreDocumentSynchronizationConfig>() {
        @Override
        public void apply(@Nonnull final CoreDocumentSynchronizationConfig docConfig) {
          syncedDocuments.put(docConfig.getDocumentId(), new CoreDocumentSynchronizationConfig(
              docsColl,
              docConfig));
        }
      });
}
 
Example 12
Source Project: stitch-android-sdk   Source File: UpdateDescription.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Converts this update description to its document representation as it would appear in a
 * MongoDB Change Event.
 *
 * @return the update description document as it would appear in a change event
 */
public BsonDocument toBsonDocument() {
  final BsonDocument updateDescDoc = new BsonDocument();
  updateDescDoc.put(
      Fields.UPDATED_FIELDS_FIELD,
      this.getUpdatedFields());

  final BsonArray removedFields = new BsonArray();
  for (final String field : this.getRemovedFields()) {
    removedFields.add(new BsonString(field));
  }
  updateDescDoc.put(
      Fields.REMOVED_FIELDS_FIELD,
      removedFields);

  return updateDescDoc;
}
 
Example 13
Source Project: mongo-kafka   Source File: KafkaMetaAdder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void process(final SinkDocument doc, final SinkRecord orig) {
  doc.getValueDoc()
      .ifPresent(
          vd -> {
            vd.put(
                KAFKA_META_DATA,
                new BsonString(
                    format("%s-%s-%s", orig.topic(), orig.kafkaPartition(), orig.kafkaOffset())));
            if (orig.timestampType() != null && orig.timestamp() != null) {
              vd.put(orig.timestampType().name(), new BsonInt64(orig.timestamp()));
            }
          });
}
 
Example 14
Source Project: mongo-kafka   Source File: UuidStrategy.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public BsonValue generateId(final SinkDocument doc, final SinkRecord orig) {
  UUID uuid = UUID.randomUUID();
  if (outputFormat.equals(UuidBsonFormat.STRING)) {
    return new BsonString(uuid.toString());
  }

  return new BsonBinary(uuid, UuidRepresentation.STANDARD);
}
 
Example 15
Source Project: mongo-kafka   Source File: SinkDocumentTest.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeAll
static void initBsonDocs() {

  flatStructKey = new BsonDocument();
  flatStructKey.put("_id", new BsonObjectId(ObjectId.get()));
  flatStructKey.put("myBoolean", new BsonBoolean(true));
  flatStructKey.put("myInt", new BsonInt32(42));
  flatStructKey.put("myBytes", new BsonBinary(new byte[] {65, 66, 67}));
  BsonArray ba1 = new BsonArray();
  ba1.addAll(asList(new BsonInt32(1), new BsonInt32(2), new BsonInt32(3)));
  flatStructKey.put("myArray", ba1);

  flatStructValue = new BsonDocument();
  flatStructValue.put("myLong", new BsonInt64(42L));
  flatStructValue.put("myDouble", new BsonDouble(23.23d));
  flatStructValue.put("myString", new BsonString("BSON"));
  flatStructValue.put("myBytes", new BsonBinary(new byte[] {120, 121, 122}));
  BsonArray ba2 = new BsonArray();
  ba2.addAll(asList(new BsonInt32(9), new BsonInt32(8), new BsonInt32(7)));
  flatStructValue.put("myArray", ba2);

  nestedStructKey = new BsonDocument();
  nestedStructKey.put("_id", new BsonDocument("myString", new BsonString("doc")));
  nestedStructKey.put(
      "mySubDoc", new BsonDocument("mySubSubDoc", new BsonDocument("myInt", new BsonInt32(23))));

  nestedStructValue = new BsonDocument();
  nestedStructValue.put("mySubDocA", new BsonDocument("myBoolean", new BsonBoolean(false)));
  nestedStructValue.put(
      "mySubDocB",
      new BsonDocument(
          "mySubSubDocC", new BsonDocument("myString", new BsonString("some text..."))));
}
 
Example 16
Source Project: mongo-kafka   Source File: RdbmsUpdateTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("when 'after' field missing in value doc then DataException")
void testMissingAfterFieldInValueDocument() {
  assertThrows(
      DataException.class,
      () ->
          RDBMS_UPDATE.perform(
              new SinkDocument(
                  BsonDocument.parse("{id: 1234}"),
                  new BsonDocument("op", new BsonString("u")))));
}
 
Example 17
Source Project: mongo-kafka   Source File: RdbmsUpdateTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("when 'after' field empty in value doc then DataException")
void testEmptyAfterFieldInValueDocument() {
  assertThrows(
      DataException.class,
      () ->
          RDBMS_UPDATE.perform(
              new SinkDocument(
                  BsonDocument.parse("{id: 1234}"),
                  new BsonDocument("op", new BsonString("u"))
                      .append("after", new BsonDocument()))));
}
 
Example 18
Source Project: mongo-kafka   Source File: RdbmsUpdateTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("when 'after' field null in value doc then DataException")
void testNullAfterFieldInValueDocument() {
  assertThrows(
      DataException.class,
      () ->
          RDBMS_UPDATE.perform(
              new SinkDocument(
                  BsonDocument.parse("{id: 1234}"),
                  new BsonDocument("op", new BsonString("u")).append("after", new BsonNull()))));
}
 
Example 19
Source Project: mongo-kafka   Source File: RdbmsUpdateTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("when 'after' field no document in value doc then DataException")
void testNoDocumentAfterFieldInValueDocument() {
  assertThrows(
      DataException.class,
      () ->
          RDBMS_UPDATE.perform(
              new SinkDocument(
                  BsonDocument.parse("{id: 1234}"),
                  new BsonDocument("op", new BsonString("u"))
                      .append("after", new BsonString("wrong type")))));
}
 
Example 20
Source Project: mongo-kafka   Source File: MongoDbUpdateTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("when valid doc replace cdc event then correct ReplaceOneModel")
void testValidSinkDocumentForReplacement() {

  BsonDocument keyDoc = BsonDocument.parse("{id: 1234}");
  BsonDocument valueDoc =
      new BsonDocument("op", new BsonString("u"))
          .append("patch", new BsonString(REPLACEMENT_DOC.toJson()));

  WriteModel<BsonDocument> result = UPDATE.perform(new SinkDocument(keyDoc, valueDoc));
  assertTrue(result instanceof ReplaceOneModel, "result expected to be of type ReplaceOneModel");

  ReplaceOneModel<BsonDocument> writeModel = (ReplaceOneModel<BsonDocument>) result;

  assertEquals(
      REPLACEMENT_DOC,
      writeModel.getReplacement(),
      "replacement doc not matching what is expected");
  assertTrue(
      writeModel.getFilter() instanceof BsonDocument,
      "filter expected to be of type BsonDocument");

  assertEquals(FILTER_DOC, writeModel.getFilter());
  assertTrue(
      writeModel.getReplaceOptions().isUpsert(),
      "replacement expected to be done in upsert mode");
}
 
Example 21
Source Project: mongo-kafka   Source File: MongoDbHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("when value doc contains unknown operation type then DataException")
void testUnkownCdcOperationType() {
  SinkDocument cdcEvent =
      new SinkDocument(
          new BsonDocument("id", new BsonInt32(1234)),
          new BsonDocument("op", new BsonString("x")));
  assertThrows(DataException.class, () -> HANDLER_DEFAULT_MAPPING.handle(cdcEvent));
}
 
Example 22
Source Project: mongo-kafka   Source File: MongoDbHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("when value doc contains unmapped operation type then DataException")
void testUnmappedCdcOperationType() {
  SinkDocument cdcEvent =
      new SinkDocument(
          new BsonDocument("_id", new BsonInt32(1234)),
          new BsonDocument("op", new BsonString("c"))
              .append("after", new BsonString("{_id:1234,foo:\"blah\"}")));

  assertThrows(DataException.class, () -> HANDLER_EMPTY_MAPPING.handle(cdcEvent));
}
 
Example 23
Source Project: mongo-kafka   Source File: MongoDbHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
@TestFactory
@DisplayName("when valid cdc operation type then correct MongoDB CdcOperation")
Stream<DynamicTest> testValidCdcOpertionTypes() {

  return Stream.of(
      dynamicTest(
          "test operation " + OperationType.CREATE,
          () ->
              assertTrue(
                  HANDLER_DEFAULT_MAPPING.getCdcOperation(
                          new BsonDocument("op", new BsonString("c")))
                      instanceof MongoDbInsert)),
      dynamicTest(
          "test operation " + OperationType.READ,
          () ->
              assertTrue(
                  HANDLER_DEFAULT_MAPPING.getCdcOperation(
                          new BsonDocument("op", new BsonString("r")))
                      instanceof MongoDbInsert)),
      dynamicTest(
          "test operation " + OperationType.UPDATE,
          () ->
              assertTrue(
                  HANDLER_DEFAULT_MAPPING.getCdcOperation(
                          new BsonDocument("op", new BsonString("u")))
                      instanceof MongoDbUpdate)),
      dynamicTest(
          "test operation " + OperationType.DELETE,
          () ->
              assertTrue(
                  HANDLER_DEFAULT_MAPPING.getCdcOperation(
                          new BsonDocument("op", new BsonString("d")))
                      instanceof MongoDbDelete)));
}
 
Example 24
Source Project: mongo-kafka   Source File: MongoDbDeleteTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("when key doc 'id' field contains invalid JSON then DataException")
void testInvalidJsonIdFieldInKeyDocument() {
  BsonDocument keyDoc = new BsonDocument("id", new BsonString("{,NOT:JSON,}"));
  assertThrows(
      DataException.class, () -> DELETE.perform(new SinkDocument(keyDoc, new BsonDocument())));
}
 
Example 25
Source Project: kafka-connect-mongodb   Source File: KafkaMetaAdder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void process(SinkDocument doc, SinkRecord orig) {

    doc.getValueDoc().ifPresent(vd -> {
        vd.put(KAFKA_META_DATA, new BsonString(orig.topic()
                + "-" + orig.kafkaPartition() + "-" + orig.kafkaOffset()));
        vd.put(orig.timestampType().name(), new BsonInt64(orig.timestamp()));
    });

    getNext().ifPresent(pp -> pp.process(doc, orig));
}
 
Example 26
Source Project: kafka-connect-mongodb   Source File: RdbmsHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("when value doc contains unknown operation type then DataException")
public void testUnkownCdcOperationType() {
    SinkDocument cdcEvent = new SinkDocument(
            new BsonDocument("id",new BsonInt32(1234)),
                    new BsonDocument("op",new BsonString("x"))
    );
    assertThrows(DataException.class, () ->
            RDBMS_HANDLER_DEFAULT_MAPPING.handle(cdcEvent)
    );
}
 
Example 27
Source Project: kafka-connect-mongodb   Source File: RdbmsHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("when value doc contains unmapped operation type then DataException")
public void testUnmappedCdcOperationType() {
    SinkDocument cdcEvent = new SinkDocument(
            new BsonDocument("id",new BsonInt32(1004)),
            new BsonDocument("op",new BsonString("c"))
                    .append("after",new BsonDocument("id",new BsonInt32(1004))
                            .append("foo",new BsonString("blah")))
    );
    assertThrows(DataException.class, () ->
            RDBMS_HANDLER_EMPTY_MAPPING.handle(cdcEvent)
    );
}
 
Example 28
Source Project: kafka-connect-mongodb   Source File: RdbmsHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
@TestFactory
@DisplayName("when valid cdc operation type then correct RDBMS CdcOperation")
public Stream<DynamicTest> testValidCdcOpertionTypes() {

    return Stream.of(
            dynamicTest("test operation " + OperationType.CREATE, () ->
                    assertTrue(RDBMS_HANDLER_DEFAULT_MAPPING.getCdcOperation(
                            new BsonDocument("op", new BsonString("c")))
                            instanceof RdbmsInsert)
            ),
            dynamicTest("test operation " + OperationType.READ, () ->
                    assertTrue(RDBMS_HANDLER_DEFAULT_MAPPING.getCdcOperation(
                            new BsonDocument("op", new BsonString("r")))
                            instanceof RdbmsInsert)
            ),
            dynamicTest("test operation " + OperationType.UPDATE, () ->
                    assertTrue(RDBMS_HANDLER_DEFAULT_MAPPING.getCdcOperation(
                            new BsonDocument("op", new BsonString("u")))
                            instanceof RdbmsUpdate)
            ),
            dynamicTest("test operation " + OperationType.DELETE, () ->
                    assertTrue(RDBMS_HANDLER_DEFAULT_MAPPING.getCdcOperation(
                            new BsonDocument("op", new BsonString("d")))
                            instanceof RdbmsDelete)
            )
    );

}
 
Example 29
Source Project: kafka-connect-mongodb   Source File: RdbmsHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
@TestFactory
@DisplayName("when valid cdc operation type mapped to NO OP then CdcOperation of type RdbmsNoOp")
public Stream<DynamicTest> testValidCdcOpertionWithNoOpMappings() {

    return Stream.of(OperationType.values()).map(ot ->
            dynamicTest("test operation " + ot, () ->
                    assertTrue(RDBMS_HANDLER_NOOP_MAPPING.getCdcOperation(
                            new BsonDocument("op", new BsonString("c")))
                            instanceof RdbmsNoOp)
            )
    );

}
 
Example 30
Source Project: kafka-connect-mongodb   Source File: RdbmsDeleteTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("when valid cdc event with compound PK then correct DeleteOneModel")
public void testValidSinkDocumentCompoundPK() {

    BsonDocument filterDoc =
            new BsonDocument(DBCollection.ID_FIELD_NAME,
                    new BsonDocument("idA",new BsonInt32(123))
                            .append("idB",new BsonString("ABC")));

    BsonDocument keyDoc = new BsonDocument("idA",new BsonInt32(123))
                                .append("idB",new BsonString("ABC"));
    BsonDocument valueDoc = new BsonDocument("op",new BsonString("d"));

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

    assertTrue(result instanceof DeleteOneModel,
            () -> "result expected to be of type DeleteOneModel");

    DeleteOneModel<BsonDocument> writeModel =
            (DeleteOneModel<BsonDocument>) result;

    assertTrue(writeModel.getFilter() instanceof BsonDocument,
            () -> "filter expected to be of type BsonDocument");

    assertEquals(filterDoc,writeModel.getFilter());

}