Search in sources :

Example 1 with CreatorMethodModel

use of org.bson.codecs.pojo.entities.conventions.CreatorMethodModel in project mongo-java-driver by mongodb.

the class PojoRoundTripTest method testCases.

private static List<TestData> testCases() {
    List<TestData> data = new ArrayList<TestData>();
    data.add(new TestData("Simple model", getSimpleModel(), PojoCodecProvider.builder().register(SimpleModel.class), SIMPLE_MODEL_JSON));
    data.add(new TestData("Simple model with statics", new SimpleWithStaticModel(42, "myString"), PojoCodecProvider.builder().register(SimpleWithStaticModel.class), SIMPLE_MODEL_JSON));
    data.add(new TestData("Property selection model", new PropertySelectionModel(), getPojoCodecProviderBuilder(PropertySelectionModel.class), "{'finalStringField': 'finalStringField', 'stringField': 'stringField'}"));
    data.add(new TestData("Conventions default", getConventionModel(), getPojoCodecProviderBuilder(ConventionModel.class, SimpleModel.class), "{'_id': 'id', '_cls': 'AnnotatedConventionModel', 'myFinalField': 10, 'myIntField': 10," + "'child': {'_id': 'child', 'myFinalField': 10, 'myIntField': 10," + "'model': {'integerField': 42, 'stringField': 'myString'}}}"));
    data.add(new TestData("BsonIgnore invalid map", new BsonIgnoreInvalidMapModel("myString"), getPojoCodecProviderBuilder(BsonIgnoreInvalidMapModel.class), "{stringField: 'myString'}"));
    data.add(new TestData("Interfaced based model", new InterfaceModelImpl("a", "b"), getPojoCodecProviderBuilder(InterfaceModelImpl.class), "{'propertyA': 'a', 'propertyB': 'b'}"));
    data.add(new TestData("Interfaced based model with default method", new InterfaceWithDefaultMethodModelImpl("a", "c"), getPojoCodecProviderBuilder(InterfaceWithDefaultMethodModelImpl.class), "{'propertyA': 'a', 'propertyC': 'c'}"));
    data.add(new TestData("Interfaced based model with override default method", new InterfaceWithOverrideDefaultMethodModelImpl("a", "c-override"), getPojoCodecProviderBuilder(InterfaceWithOverrideDefaultMethodModelImpl.class), "{'propertyA': 'a', 'propertyC': 'c-override'}"));
    data.add(new TestData("Interfaced based model with bound", new InterfaceUpperBoundsModelAbstractImpl("someName", new InterfaceModelImpl("a", "b")), getPojoCodecProviderBuilder(InterfaceUpperBoundsModelAbstractImpl.class, InterfaceModelImpl.class), "{'name': 'someName', 'nestedModel': {'propertyA': 'a', 'propertyB': 'b'}}"));
    data.add(new TestData("Interface concrete and abstract model", new ConcreteAndNestedAbstractInterfaceModel("A", new ConcreteAndNestedAbstractInterfaceModel("B", new ConcreteStandAloneAbstractInterfaceModel("C"))), getPojoCodecProviderBuilder(InterfaceBasedModel.class, AbstractInterfaceModel.class, ConcreteAndNestedAbstractInterfaceModel.class, ConcreteStandAloneAbstractInterfaceModel.class), "{'_t': 'org.bson.codecs.pojo.entities.ConcreteAndNestedAbstractInterfaceModel', 'name': 'A', " + "'child': {'_t': 'org.bson.codecs.pojo.entities.ConcreteAndNestedAbstractInterfaceModel', 'name': 'B', " + "  'child': {'_t': 'org.bson.codecs.pojo.entities.ConcreteStandAloneAbstractInterfaceModel', 'name': 'C'}}}}"));
    data.add(new TestData("Concrete generic interface model", new ConcreteInterfaceGenericModel("someValue"), getPojoCodecProviderBuilder(ConcreteInterfaceGenericModel.class), "{propertyA: 'someValue'}"));
    data.add(new TestData("Primitives model", getPrimitivesModel(), getPojoCodecProviderBuilder(PrimitivesModel.class), "{ 'myBoolean': true, 'myByte': 1, 'myCharacter': '1', 'myDouble': 1.0, 'myFloat': 2.0, 'myInteger': 3, " + "'myLong': { '$numberLong': '5' }, 'myShort': 6}"));
    data.add(new TestData("Concrete collections model", getConcreteCollectionsModel(), getPojoCodecProviderBuilder(ConcreteCollectionsModel.class), "{'collection': [1, 2, 3], 'list': [4, 5, 6], 'linked': [7, 8, 9], 'map': {'A': 1.1, 'B': 2.2, 'C': 3.3}," + "'concurrent': {'D': 4.4, 'E': 5.5, 'F': 6.6}}"));
    data.add(new TestData("Handling of nulls inside collections", getConcreteCollectionsModelWithNulls(), getPojoCodecProviderBuilder(ConcreteCollectionsModel.class), "{'collection': [1, null, 3], 'list': [4, null, 6], 'linked': [null, 8, 9], 'map': {'A': 1.1, 'B': null, 'C': 3.3}}"));
    data.add(new TestData("Concrete specific return collection type model through BsonCreator", new CollectionSpecificReturnTypeCreatorModel(Arrays.asList("foo", "bar")), getPojoCodecProviderBuilder(CollectionSpecificReturnTypeCreatorModel.class), "{'properties': ['foo', 'bar']}"));
    data.add(new TestData("Concrete specific return collection type model through getter and setter", new CollectionSpecificReturnTypeModel(Arrays.asList("foo", "bar")), getPojoCodecProviderBuilder(CollectionSpecificReturnTypeModel.class), "{'properties': ['foo', 'bar']}"));
    data.add(new TestData("Concrete specific return collection type model", getConcreteCollectionsModel(), getPojoCodecProviderBuilder(ConcreteCollectionsModel.class), "{'collection': [1, 2, 3], 'list': [4, 5, 6], 'linked': [7, 8, 9], 'map': {'A': 1.1, 'B': 2.2, 'C': 3.3}," + "'concurrent': {'D': 4.4, 'E': 5.5, 'F': 6.6}}"));
    data.add(new TestData("Nested simple", getSimpleNestedPojoModel(), getPojoCodecProviderBuilder(SimpleNestedPojoModel.class, SimpleModel.class), "{'simple': " + SIMPLE_MODEL_JSON + "}"));
    data.add(new TestData("Nested collection", getCollectionNestedPojoModel(), getPojoCodecProviderBuilder(CollectionNestedPojoModel.class, SimpleModel.class), "{ 'listSimple': [" + SIMPLE_MODEL_JSON + "]," + "'listListSimple': [[" + SIMPLE_MODEL_JSON + "]]," + "'setSimple': [" + SIMPLE_MODEL_JSON + "]," + "'setSetSimple': [[" + SIMPLE_MODEL_JSON + "]]," + "'mapSimple': {'s': " + SIMPLE_MODEL_JSON + "}," + "'mapMapSimple': {'ms': {'s': " + SIMPLE_MODEL_JSON + "}}," + "'mapListSimple': {'ls': [" + SIMPLE_MODEL_JSON + "]}," + "'mapListMapSimple': {'lm': [{'s': " + SIMPLE_MODEL_JSON + "}]}," + "'mapSetSimple': {'s': [" + SIMPLE_MODEL_JSON + "]}," + "'listMapSimple': [{'s': " + SIMPLE_MODEL_JSON + "}]," + "'listMapListSimple': [{'ls': [" + SIMPLE_MODEL_JSON + "]}]," + "'listMapSetSimple': [{'s': [" + SIMPLE_MODEL_JSON + "]}]," + "}"));
    data.add(new TestData("Nested collection", getCollectionNestedPojoModelWithNulls(), getPojoCodecProviderBuilder(CollectionNestedPojoModel.class, SimpleModel.class), "{ 'listListSimple': [ null ]," + "'setSetSimple': [ null ]," + "'mapMapSimple': {'ms': null}," + "'mapListSimple': {'ls': null}," + "'mapListMapSimple': {'lm': [null]}," + "'mapSetSimple': {'s': null}," + "'listMapSimple': [null]," + "'listMapListSimple': [{'ls': null}]," + "'listMapSetSimple': [{'s': null}]," + "}"));
    data.add(new TestData("Nested generic holder", getNestedGenericHolderModel(), getPojoCodecProviderBuilder(NestedGenericHolderModel.class, GenericHolderModel.class), "{'nested': {'myGenericField': 'generic', 'myLongField': {'$numberLong': '1'}}}"));
    data.add(new TestData("Nested generic holder map", getNestedGenericHolderMapModel(), getPojoCodecProviderBuilder(NestedGenericHolderMapModel.class, GenericHolderModel.class, SimpleGenericsModel.class, SimpleModel.class), "{ 'nested': { 'myGenericField': {'s': " + SIMPLE_MODEL_JSON + "}, 'myLongField': {'$numberLong': '1'}}}"));
    data.add(new TestData("Nested reused generic", getNestedReusedGenericsModel(), getPojoCodecProviderBuilder(NestedReusedGenericsModel.class, ReusedGenericsModel.class, SimpleModel.class), "{ 'nested':{ 'field1':{ '$numberLong':'1' }, 'field2':[" + SIMPLE_MODEL_JSON + "], " + "'field3':'field3', 'field4':42, 'field5':'field5', 'field6':[" + SIMPLE_MODEL_JSON + ", " + SIMPLE_MODEL_JSON + "], 'field7':{ '$numberLong':'2' }, 'field8':'field8' } }"));
    data.add(new TestData("Nested generic holder with multiple types", getNestedGenericHolderFieldWithMultipleTypeParamsModel(), getPojoCodecProviderBuilder(NestedGenericHolderFieldWithMultipleTypeParamsModel.class, PropertyWithMultipleTypeParamsModel.class, SimpleGenericsModel.class, GenericHolderModel.class), "{'nested': {'myGenericField': {_t: 'PropertyWithMultipleTypeParamsModel', " + "'simpleGenericsModel': {_t: 'org.bson.codecs.pojo.entities.SimpleGenericsModel', 'myIntegerField': 42, " + "'myGenericField': {'$numberLong': '101'}, 'myListField': ['B', 'C'], 'myMapField': {'D': 2, 'E': 3, 'F': 4 }}}," + "'myLongField': {'$numberLong': '42'}}}"));
    data.add(new TestData("Nested generic tree", new NestedGenericTreeModel(42, getGenericTreeModel()), getPojoCodecProviderBuilder(NestedGenericTreeModel.class, GenericTreeModel.class), "{'intField': 42, 'nested': {'field1': 'top', 'field2': 1, " + "'left': {'field1': 'left', 'field2': 2, 'left': {'field1': 'left', 'field2': 3}}, " + "'right': {'field1': 'right', 'field2': 4, 'left': {'field1': 'left', 'field2': 5}}}}"));
    data.add(new TestData("Nested multiple level", new NestedMultipleLevelGenericModel(42, new MultipleLevelGenericModel<String>("string", getGenericTreeModel())), getPojoCodecProviderBuilder(NestedMultipleLevelGenericModel.class, MultipleLevelGenericModel.class, GenericTreeModel.class), "{'intField': 42, 'nested': {'stringField': 'string', 'nested': {'field1': 'top', 'field2': 1, " + "'left': {'field1': 'left', 'field2': 2, 'left': {'field1': 'left', 'field2': 3}}, " + "'right': {'field1': 'right', 'field2': 4, 'left': {'field1': 'left', 'field2': 5}}}}}"));
    data.add(new TestData("Nested Generics holder", getNestedGenericHolderSimpleGenericsModel(), getPojoCodecProviderBuilder(NestedGenericHolderSimpleGenericsModel.class, GenericHolderModel.class, SimpleGenericsModel.class, SimpleModel.class), "{'nested': {'myGenericField': {'myIntegerField': 42, 'myGenericField': 42," + "                           'myListField': [[" + SIMPLE_MODEL_JSON + "]], " + "                           'myMapField': {'A': {'A': " + SIMPLE_MODEL_JSON + "}}}," + "         'myLongField': {'$numberLong': '42' }}}"));
    data.add(new TestData("Nested property reusing type parameter", new NestedFieldReusingClassTypeParameter(new PropertyReusingClassTypeParameter<String>(getGenericTreeModelStrings())), getPojoCodecProviderBuilder(NestedFieldReusingClassTypeParameter.class, PropertyReusingClassTypeParameter.class, GenericTreeModel.class), "{'nested': {'tree': {'field1': 'top', 'field2': '1', " + "'left': {'field1': 'left', 'field2': '2', 'left': {'field1': 'left', 'field2': '3'}}, " + "'right': {'field1': 'right', 'field2': '4', 'left': {'field1': 'left', 'field2': '5'}}}}}"));
    data.add(new TestData("Abstract shape model - circle", new ShapeHolderModel(getShapeModelCircle()), getPojoCodecProviderBuilder(ShapeModelAbstract.class, ShapeModelCircle.class, ShapeModelRectangle.class, ShapeHolderModel.class), "{'shape': {'_t': 'org.bson.codecs.pojo.entities.ShapeModelCircle', 'color': 'orange', 'radius': 4.2}}"));
    data.add(new TestData("Abstract shape model - rectangle", new ShapeHolderModel(getShapeModelRectangle()), getPojoCodecProviderBuilder(ShapeModelAbstract.class, ShapeModelCircle.class, ShapeModelRectangle.class, ShapeHolderModel.class), "{'shape': {'_t': 'org.bson.codecs.pojo.entities.ShapeModelRectangle', 'color': 'green', 'width': 22.1, 'height': " + "105.0}}}"));
    data.add(new TestData("Upper bounds", new UpperBoundsConcreteModel(1L), getPojoCodecProviderBuilder(UpperBoundsConcreteModel.class), "{'myGenericField': {'$numberLong': '1'}}"));
    data.add(new TestData("Multiple bounds", getMultipleBoundsModel(), getPojoCodecProviderBuilder(MultipleBoundsModel.class), "{'level1' : 2.2, 'level2': [1, 2, 3], 'level3': {key: 'value'}}"));
    data.add(new TestData("Self referential", getNestedSelfReferentialGenericHolderModel(), getPojoCodecProviderBuilder(NestedSelfReferentialGenericHolderModel.class, NestedSelfReferentialGenericModel.class, SelfReferentialGenericModel.class), "{'nested': { 't': true, 'v': {'$numberLong': '42'}, 'z': 44.0, " + "'selfRef1': {'t': true, 'v': {'$numberLong': '33'}, 'child': {'t': {'$numberLong': '44'}, 'v': false}}, " + "'selfRef2': {'t': true, 'v': 3.14, 'child': {'t': 3.42, 'v': true}}}}"));
    data.add(new TestData("Creator constructor", new CreatorConstructorModel(asList(10, 11), "twelve", 13), getPojoCodecProviderBuilder(CreatorConstructorModel.class), "{'integersField': [10, 11], 'stringField': 'twelve', 'longField': {$numberLong: '13'}}"));
    data.add(new TestData("Creator constructor with legacy BsonProperty using name", new CreatorConstructorLegacyBsonPropertyModel(asList(10, 11), "twelve", 13), getPojoCodecProviderBuilder(CreatorConstructorLegacyBsonPropertyModel.class), "{'integersField': [10, 11], 'stringField': 'twelve', 'longField': {$numberLong: '13'}}"));
    data.add(new TestData("Creator constructor with rename", new CreatorConstructorRenameModel(asList(10, 11), "twelve", 13), getPojoCodecProviderBuilder(CreatorConstructorRenameModel.class), "{'integerList': [10, 11], 'stringField': 'twelve', 'longField': {$numberLong: '13'}}"));
    data.add(new TestData("Creator constructor with ID", new CreatorConstructorIdModel("1234-34567-890", asList(10, 11), "twelve", 13), getPojoCodecProviderBuilder(CreatorConstructorIdModel.class), "{'_id': '1234-34567-890', 'integersField': [10, 11], 'stringField': 'twelve', 'longField': {$numberLong: '13'}}"));
    data.add(new TestData("Creator no-args constructor", new CreatorNoArgsConstructorModel(40, "one", 42), getPojoCodecProviderBuilder(CreatorNoArgsConstructorModel.class), "{'integerField': 40, 'stringField': 'one', 'longField': {$numberLong: '42'}}"));
    data.add(new TestData("Creator method", new CreatorMethodModel(30, "two", 32), getPojoCodecProviderBuilder(CreatorMethodModel.class), "{'integerField': 30, 'stringField': 'two', 'longField': {$numberLong: '32'}}"));
    data.add(new TestData("Creator method", CreatorMethodModel.create(30), getPojoCodecProviderBuilder(CreatorMethodModel.class), "{'integerField': 30, 'longField': {$numberLong: '0'}}"));
    data.add(new TestData("Creator no-args method", new CreatorNoArgsMethodModel(10, "one", 11), getPojoCodecProviderBuilder(CreatorNoArgsMethodModel.class), "{'integerField': 10, 'stringField': 'one', 'longField': {$numberLong: '11'}}"));
    data.add(new TestData("Creator all final", new CreatorAllFinalFieldsModel("pId", "Ada", "Lovelace"), getPojoCodecProviderBuilder(CreatorAllFinalFieldsModel.class), "{'_id': 'pId', '_t': 'org.bson.codecs.pojo.entities.conventions.CreatorAllFinalFieldsModel', " + "'firstName': 'Ada', 'lastName': 'Lovelace'}"));
    data.add(new TestData("Creator all final with nulls", new CreatorAllFinalFieldsModel("pId", "Ada", null), getPojoCodecProviderBuilder(CreatorAllFinalFieldsModel.class), "{'_id': 'pId', '_t': 'org.bson.codecs.pojo.entities.conventions.CreatorAllFinalFieldsModel', 'firstName': 'Ada'}"));
    data.add(new TestData("Can handle custom Maps and Collections", new ContainsAlternativeMapAndCollectionModel(BsonDocument.parse("{customList: [1,2,3], customMap: {'field': 'value'}}")), getPojoCodecProviderBuilder(ContainsAlternativeMapAndCollectionModel.class), "{customList: [1,2,3], customMap: {'field': 'value'}}"));
    data.add(new TestData("Collection of discriminators abstract classes", new CollectionDiscriminatorAbstractClassesModel().setList(asList(new Subclass1Model().setName("abc").setValue(true), new Subclass2Model().setInteger(234).setValue(false))).setMap(Collections.singletonMap("key", new Subclass2Model().setInteger(123).setValue(true))), getPojoCodecProviderBuilder(CollectionDiscriminatorAbstractClassesModel.class, SuperClassModel.class, Subclass1Model.class, Subclass2Model.class), "{list: [{_t: 'org.bson.codecs.pojo.entities.conventions.Subclass1Model', value: true, name: 'abc'}," + "{_t: 'org.bson.codecs.pojo.entities.conventions.Subclass2Model', value: false, integer: 234}]," + "map: {key: {_t: 'org.bson.codecs.pojo.entities.conventions.Subclass2Model', value: true, integer: 123}}}"));
    data.add(new TestData("Collection of discriminators interfaces", new CollectionDiscriminatorInterfacesModel().setList(asList(new InterfaceModelImplA().setName("abc").setValue(true), new InterfaceModelImplB().setInteger(234).setValue(false))).setMap(Collections.<String, InterfaceModel>singletonMap("key", new InterfaceModelImplB().setInteger(123).setValue(true))), getPojoCodecProviderBuilder(CollectionDiscriminatorInterfacesModel.class, InterfaceModelImplA.class, InterfaceModelImplB.class, InterfaceModel.class), "{list: [{_t: 'org.bson.codecs.pojo.entities.conventions.InterfaceModelImplA', value: true, name: 'abc'}," + "{_t: 'org.bson.codecs.pojo.entities.conventions.InterfaceModelImplB', value: false, integer: 234}]," + "map: {key: {_t: 'org.bson.codecs.pojo.entities.conventions.InterfaceModelImplB', value: true, integer: 123}}}"));
    data.add(new TestData("Creator in super class factory method", CreatorInSuperClassModel.newInstance("a", "b"), getPojoCodecProviderBuilder(CreatorInSuperClassModelImpl.class), "{'propertyA': 'a', 'propertyB': 'b'}"));
    data.add(new TestData("Primitive field type doesn't match private property", new FieldAndPropertyTypeMismatchModel("foo"), getPojoCodecProviderBuilder(FieldAndPropertyTypeMismatchModel.class), "{'stringField': 'foo'}"));
    data.add(new TestData("Enums support", new SimpleEnumModel(SimpleEnum.BRAVO), getPojoCodecProviderBuilder(SimpleEnumModel.class), "{ 'myEnum': 'BRAVO' }"));
    data.add(new TestData("AnnotationBsonPropertyIdModel", new AnnotationBsonPropertyIdModel(99L), getPojoCodecProviderBuilder(AnnotationBsonPropertyIdModel.class), "{'id': {'$numberLong': '99' }}"));
    data.add(new TestData("Shape model - circle", new ShapeHolderCircleModel(getShapeModelCircle()), getPojoCodecProviderBuilder(ShapeModelCircle.class, ShapeHolderCircleModel.class), "{'shape': {'_t': 'org.bson.codecs.pojo.entities.ShapeModelCircle', 'color': 'orange', 'radius': 4.2}}"));
    data.add(new TestData("BsonIgnore synthentic property", new BsonIgnoreSyntheticProperty("string value"), getPojoCodecProviderBuilder(BsonIgnoreSyntheticProperty.class).conventions(Conventions.DEFAULT_CONVENTIONS), "{stringField: 'string value'}"));
    data.add(new TestData("SimpleIdModel with existing id", new SimpleIdModel(new ObjectId("123412341234123412341234"), 42, "myString"), getPojoCodecProviderBuilder(SimpleIdModel.class).conventions(Conventions.DEFAULT_CONVENTIONS), "{'_id': {'$oid': '123412341234123412341234'}, 'integerField': 42, 'stringField': 'myString'}"));
    data.add(new TestData("SimpleIdImmutableModel with existing id", new SimpleIdImmutableModel(new ObjectId("123412341234123412341234"), 42, "myString"), getPojoCodecProviderBuilder(SimpleIdImmutableModel.class).conventions(Conventions.DEFAULT_CONVENTIONS), "{'_id': {'$oid': '123412341234123412341234'}, 'integerField': 42, 'stringField': 'myString'}"));
    data.add(new TestData("NestedSimpleIdModel", new NestedSimpleIdModel(new SimpleIdModel(42, "myString")), getPojoCodecProviderBuilder(NestedSimpleIdModel.class, SimpleIdModel.class).conventions(Conventions.DEFAULT_CONVENTIONS), "{'nestedSimpleIdModel': {'integerField': 42, 'stringField': 'myString'}}"));
    data.add(new TestData("TreeWithIdModel", new TreeWithIdModel(new ObjectId("123412341234123412341234"), "top", new TreeWithIdModel("left-1", new TreeWithIdModel("left-2"), null), new TreeWithIdModel("right-1")), getPojoCodecProviderBuilder(TreeWithIdModel.class).conventions(Conventions.DEFAULT_CONVENTIONS), "{'_id': {'$oid': '123412341234123412341234'}, 'level': 'top'," + "'left': {'level': 'left-1', 'left': {'level': 'left-2'}}," + "'right': {'level': 'right-1'}}"));
    data.add(new TestData("DuplicateAnnotationAllowedModel", new DuplicateAnnotationAllowedModel("abc"), getPojoCodecProviderBuilder(DuplicateAnnotationAllowedModel.class).conventions(Conventions.DEFAULT_CONVENTIONS), "{'_id': 'abc'}"));
    data.add(new TestData("BsonIgnore duplicate property with multiple types", new BsonIgnoreDuplicatePropertyMultipleTypes("string value"), getPojoCodecProviderBuilder(BsonIgnoreDuplicatePropertyMultipleTypes.class).conventions(Conventions.DEFAULT_CONVENTIONS), "{stringField: 'string value'}"));
    data.add(new TestData("Can handle concrete generic list types", new ListGenericExtendedModel(asList(1, 2, 3)), getPojoCodecProviderBuilder(ListGenericExtendedModel.class), "{values: [1, 2, 3]}"));
    data.add(new TestData("Can handle concrete nested generic list types", new ListListGenericExtendedModel(asList(asList(1, 2, 3), asList(4, 5, 6))), getPojoCodecProviderBuilder(ListListGenericExtendedModel.class), "{values: [[1, 2, 3], [4, 5, 6]]}"));
    data.add(new TestData("Can handle concrete generic map types", new MapGenericExtendedModel(new HashMap<String, Integer>() {

        {
            put("a", 1);
            put("b", 2);
        }
    }), getPojoCodecProviderBuilder(MapGenericExtendedModel.class), "{values: {a: 1, b: 2}}"));
    data.add(new TestData("Can handle concrete nested generic map types", new MapMapGenericExtendedModel(new HashMap<String, Map<String, Integer>>() {

        {
            put("a", new HashMap<String, Integer>() {

                {
                    put("aa", 1);
                    put("ab", 2);
                }
            });
            put("b", new HashMap<String, Integer>() {

                {
                    put("ba", 1);
                    put("bb", 2);
                }
            });
        }
    }), getPojoCodecProviderBuilder(MapMapGenericExtendedModel.class), "{values: {a: {aa: 1, ab: 2}, b: {ba: 1, bb: 2}}}"));
    data.add(new TestData("Can handle concrete lists with generic map types", new ListMapGenericExtendedModel(asList(new HashMap<String, Integer>() {

        {
            put("a", 1);
            put("b", 2);
        }
    }, new HashMap<String, Integer>() {

        {
            put("c", 3);
            put("d", 4);
        }
    })), getPojoCodecProviderBuilder(ListMapGenericExtendedModel.class), "{values: [{a: 1, b: 2}, {c: 3, d: 4}]}"));
    data.add(new TestData("Can handle concrete maps with generic list types", new MapListGenericExtendedModel(new HashMap<String, List<Integer>>() {

        {
            put("a", asList(1, 2, 3));
            put("b", asList(4, 5, 6));
        }
    }), getPojoCodecProviderBuilder(MapListGenericExtendedModel.class), "{values: {a: [1, 2, 3], b: [4, 5, 6]}}"));
    data.add(new TestData("BsonRepresentation is encoded and decoded correctly", new BsonRepresentationModel(1), getPojoCodecProviderBuilder(BsonRepresentationModel.class), "{'_id': {'$oid': '111111111111111111111111'}, 'age': 1}"));
    return data;
}
Also used : CreatorConstructorModel(org.bson.codecs.pojo.entities.conventions.CreatorConstructorModel) ContainsAlternativeMapAndCollectionModel(org.bson.codecs.pojo.entities.ContainsAlternativeMapAndCollectionModel) ConcreteAndNestedAbstractInterfaceModel(org.bson.codecs.pojo.entities.ConcreteAndNestedAbstractInterfaceModel) HashMap(java.util.HashMap) ListGenericExtendedModel(org.bson.codecs.pojo.entities.ListGenericExtendedModel) MapListGenericExtendedModel(org.bson.codecs.pojo.entities.MapListGenericExtendedModel) ListListGenericExtendedModel(org.bson.codecs.pojo.entities.ListListGenericExtendedModel) ArrayList(java.util.ArrayList) ShapeHolderCircleModel(org.bson.codecs.pojo.entities.ShapeHolderCircleModel) CollectionSpecificReturnTypeModel(org.bson.codecs.pojo.entities.CollectionSpecificReturnTypeModel) BsonRepresentationModel(org.bson.codecs.pojo.entities.conventions.BsonRepresentationModel) CreatorMethodModel(org.bson.codecs.pojo.entities.conventions.CreatorMethodModel) CreatorConstructorRenameModel(org.bson.codecs.pojo.entities.conventions.CreatorConstructorRenameModel) NestedFieldReusingClassTypeParameter(org.bson.codecs.pojo.entities.NestedFieldReusingClassTypeParameter) TreeWithIdModel(org.bson.codecs.pojo.entities.TreeWithIdModel) Subclass2Model(org.bson.codecs.pojo.entities.conventions.Subclass2Model) BsonIgnoreInvalidMapModel(org.bson.codecs.pojo.entities.conventions.BsonIgnoreInvalidMapModel) Subclass1Model(org.bson.codecs.pojo.entities.conventions.Subclass1Model) SimpleEnumModel(org.bson.codecs.pojo.entities.SimpleEnumModel) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) CollectionSpecificReturnTypeCreatorModel(org.bson.codecs.pojo.entities.CollectionSpecificReturnTypeCreatorModel) CollectionDiscriminatorInterfacesModel(org.bson.codecs.pojo.entities.conventions.CollectionDiscriminatorInterfacesModel) MapMapGenericExtendedModel(org.bson.codecs.pojo.entities.MapMapGenericExtendedModel) InterfaceUpperBoundsModelAbstractImpl(org.bson.codecs.pojo.entities.InterfaceUpperBoundsModelAbstractImpl) ListMapGenericExtendedModel(org.bson.codecs.pojo.entities.ListMapGenericExtendedModel) ShapeHolderModel(org.bson.codecs.pojo.entities.ShapeHolderModel) InterfaceWithOverrideDefaultMethodModelImpl(org.bson.codecs.pojo.entities.InterfaceWithOverrideDefaultMethodModelImpl) ListMapGenericExtendedModel(org.bson.codecs.pojo.entities.ListMapGenericExtendedModel) MapGenericExtendedModel(org.bson.codecs.pojo.entities.MapGenericExtendedModel) MapMapGenericExtendedModel(org.bson.codecs.pojo.entities.MapMapGenericExtendedModel) CollectionDiscriminatorAbstractClassesModel(org.bson.codecs.pojo.entities.conventions.CollectionDiscriminatorAbstractClassesModel) NestedSimpleIdModel(org.bson.codecs.pojo.entities.NestedSimpleIdModel) BsonIgnoreSyntheticProperty(org.bson.codecs.pojo.entities.conventions.BsonIgnoreSyntheticProperty) Map(java.util.Map) HashMap(java.util.HashMap) ConcreteStandAloneAbstractInterfaceModel(org.bson.codecs.pojo.entities.ConcreteStandAloneAbstractInterfaceModel) InterfaceWithDefaultMethodModelImpl(org.bson.codecs.pojo.entities.InterfaceWithDefaultMethodModelImpl) AnnotationBsonPropertyIdModel(org.bson.codecs.pojo.entities.conventions.AnnotationBsonPropertyIdModel) DuplicateAnnotationAllowedModel(org.bson.codecs.pojo.entities.DuplicateAnnotationAllowedModel) SimpleWithStaticModel(org.bson.codecs.pojo.entities.SimpleWithStaticModel) CreatorConstructorIdModel(org.bson.codecs.pojo.entities.conventions.CreatorConstructorIdModel) SimpleIdModel(org.bson.codecs.pojo.entities.SimpleIdModel) NestedSimpleIdModel(org.bson.codecs.pojo.entities.NestedSimpleIdModel) InterfaceModelImpl(org.bson.codecs.pojo.entities.InterfaceModelImpl) FieldAndPropertyTypeMismatchModel(org.bson.codecs.pojo.entities.FieldAndPropertyTypeMismatchModel) SimpleIdImmutableModel(org.bson.codecs.pojo.entities.SimpleIdImmutableModel) BsonIgnoreDuplicatePropertyMultipleTypes(org.bson.codecs.pojo.entities.conventions.BsonIgnoreDuplicatePropertyMultipleTypes) NestedGenericTreeModel(org.bson.codecs.pojo.entities.NestedGenericTreeModel) NestedMultipleLevelGenericModel(org.bson.codecs.pojo.entities.NestedMultipleLevelGenericModel) ObjectId(org.bson.types.ObjectId) CreatorAllFinalFieldsModel(org.bson.codecs.pojo.entities.conventions.CreatorAllFinalFieldsModel) UpperBoundsConcreteModel(org.bson.codecs.pojo.entities.UpperBoundsConcreteModel) InterfaceModelImplB(org.bson.codecs.pojo.entities.conventions.InterfaceModelImplB) PropertySelectionModel(org.bson.codecs.pojo.entities.PropertySelectionModel) InterfaceModelImplA(org.bson.codecs.pojo.entities.conventions.InterfaceModelImplA) CreatorNoArgsConstructorModel(org.bson.codecs.pojo.entities.conventions.CreatorNoArgsConstructorModel) ListListGenericExtendedModel(org.bson.codecs.pojo.entities.ListListGenericExtendedModel) CreatorNoArgsMethodModel(org.bson.codecs.pojo.entities.conventions.CreatorNoArgsMethodModel) ConcreteInterfaceGenericModel(org.bson.codecs.pojo.entities.ConcreteInterfaceGenericModel) CreatorConstructorLegacyBsonPropertyModel(org.bson.codecs.pojo.entities.conventions.CreatorConstructorLegacyBsonPropertyModel) MapListGenericExtendedModel(org.bson.codecs.pojo.entities.MapListGenericExtendedModel)

Aggregations

ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CollectionSpecificReturnTypeCreatorModel (org.bson.codecs.pojo.entities.CollectionSpecificReturnTypeCreatorModel)1 CollectionSpecificReturnTypeModel (org.bson.codecs.pojo.entities.CollectionSpecificReturnTypeModel)1 ConcreteAndNestedAbstractInterfaceModel (org.bson.codecs.pojo.entities.ConcreteAndNestedAbstractInterfaceModel)1 ConcreteInterfaceGenericModel (org.bson.codecs.pojo.entities.ConcreteInterfaceGenericModel)1 ConcreteStandAloneAbstractInterfaceModel (org.bson.codecs.pojo.entities.ConcreteStandAloneAbstractInterfaceModel)1 ContainsAlternativeMapAndCollectionModel (org.bson.codecs.pojo.entities.ContainsAlternativeMapAndCollectionModel)1 DuplicateAnnotationAllowedModel (org.bson.codecs.pojo.entities.DuplicateAnnotationAllowedModel)1 FieldAndPropertyTypeMismatchModel (org.bson.codecs.pojo.entities.FieldAndPropertyTypeMismatchModel)1 InterfaceModelImpl (org.bson.codecs.pojo.entities.InterfaceModelImpl)1 InterfaceUpperBoundsModelAbstractImpl (org.bson.codecs.pojo.entities.InterfaceUpperBoundsModelAbstractImpl)1 InterfaceWithDefaultMethodModelImpl (org.bson.codecs.pojo.entities.InterfaceWithDefaultMethodModelImpl)1 InterfaceWithOverrideDefaultMethodModelImpl (org.bson.codecs.pojo.entities.InterfaceWithOverrideDefaultMethodModelImpl)1 ListGenericExtendedModel (org.bson.codecs.pojo.entities.ListGenericExtendedModel)1 ListListGenericExtendedModel (org.bson.codecs.pojo.entities.ListListGenericExtendedModel)1 ListMapGenericExtendedModel (org.bson.codecs.pojo.entities.ListMapGenericExtendedModel)1