Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoDataImport - Error while trying to convert Object: {id=55f3ed00b1375a48e618300a, data=A} to: class com.jupiter.tools.spring.test.mongo.Bar #70

Open
bachhavdipak opened this issue Sep 13, 2021 · 0 comments

Comments

@bachhavdipak
Copy link

bachhavdipak commented Sep 13, 2021

I am trying to implement JUnit5 integration test using below code but facing below issue

Error:

Error while parsing the document record in the collection.
com.antkorwin.commonutils.exceptions.InternalException: Error while parsing the document record in the collection.
	at com.jupiter.tools.spring.test.mongo.internal.importdata.MongoDataImport.lambda$importDocumentCollection$1(MongoDataImport.java:54)
	at java.util.ArrayList.forEach(ArrayList.java:1257)
	at com.jupiter.tools.spring.test.mongo.internal.importdata.MongoDataImport.importDocumentCollection(MongoDataImport.java:48)
	at com.jupiter.tools.spring.test.mongo.internal.importdata.MongoDataImport.lambda$importFrom$0(MongoDataImport.java:39)
	at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
	at com.jupiter.tools.spring.test.mongo.internal.importdata.MongoDataImport.importFrom(MongoDataImport.java:39)
	at com.jupiter.tools.spring.test.mongo.internal.MongoDbTest.importFrom(MongoDbTest.java:59)
	at com.jupiter.tools.spring.test.mongo.junit5.MongoDbExtension.beforeEach(MongoDbExtension.java:66)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeEachCallbacks$1(TestMethodTestDescriptor.java:159)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeMethodsOrCallbacksUntilExceptionOccurs$5(TestMethodTestDescriptor.java:195)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeMethodsOrCallbacksUntilExceptionOccurs(TestMethodTestDescriptor.java:195)
	
Caused by: java.lang.IllegalArgumentException: Unrecognized field "id" (class com.jupiter.tools.spring.test.mongo.Bar), not marked as ignorable (0 known properties: ])
 at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: com.jupiter.tools.spring.test.mongo.Bar["id"])
	at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:4202)
	at com.fasterxml.jackson.databind.ObjectMapper.convertValue(ObjectMapper.java:4133)
	at com.jupiter.tools.spring.test.mongo.internal.importdata.MongoDataImport.lambda$importDocumentCollection$1(MongoDataImport.java:50)
	... 79 more
Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "id" (class com.jupiter.tools.spring.test.mongo.Bar), not marked as ignorable (0 known properties: ])
 at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: com.jupiter.tools.spring.test.mongo.Bar["id"])
	at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:61)
	at com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:855)
	at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1206)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1592)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1570)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:299)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:156)
	at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:4197)
	... 81 more

build.gradle

 plugins {
    id 'java'
}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
    jcenter()
}

dependencies {

    testCompile group: 'junit', name: 'junit', version: '4.12'
    testImplementation 'org.springframework.boot:spring-boot-starter-test:2.5.4'
    testImplementation 'org.springframework.boot:spring-boot-starter-data-mongodb:2.5.4'
    testImplementation 'com.jupiter-tools:spring-test-mongo:0.15'
    testImplementation 'org.projectlombok:lombok:1.18.20'

}
test {
    useJUnitPlatform()
}

JUnit5ExampleTest.Class

package com.jupiter.tools.spring.test.mongo;

import com.jupiter.tools.spring.test.mongo.annotation.MongoDataSet;
import com.jupiter.tools.spring.test.mongo.junit5.meta.annotation.MongoDbIntegrationTest;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;

@MongoDbIntegrationTest

class JUnit5ExampleTest {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Test
    @MongoDataSet(value = "/dataset/bar_dataset.json")
    void testPopulatingByMongoDataSet() throws Exception {

        Bar simpleDoc = mongoTemplate.findById("55f3ed00b1375a48e618300b", Bar.class);

        Assertions.assertThat(simpleDoc)
                .isNotNull();
    }
}

Bar.Class

package com.jupiter.tools.spring.test.mongo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;


@Document
@AllArgsConstructor
@NoArgsConstructor
@Data
public class Bar {

    @Id
    private String id;

    private String data;
}

bar_dataset.json

{
  "com.jupiter.tools.spring.test.mongo.Bar": [
    {
      "id": "55f3ed00b1375a48e618300a",
      "data": "A"
    },
    {
      "id": "55f3ed00b1375a48e618300b",
      "data": "BB"
    }
  ]
}
@bachhavdipak bachhavdipak changed the title Getting parsing exception with Junit 5:: Caused by: java.lang.IllegalArgumentException: Unrecognized field "id" (class com.jupiter.tools.spring.test.mongo.Bar) MongoDataImport - Error while trying to convert Object: {id=55f3ed00b1375a48e618300a, data=A} to: class com.jupiter.tools.spring.test.mongo.Bar Sep 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant