Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Commander Lvl 2
Message 1 of 1

[TDD + Docker + MongoDB] I can not understand jongo error

I'm doing exercise with test driven development with using jongo but when i run my test i get an exception that i can not understand:

 

org.jongo.marshall.MarshallingException: Unable to unmarshall result to interface wabri.SchoolController.Student from content { "_id" : { "$oid" : "5a140eec5838d96eedec0f46"} , "id" : "1" , "name" : "first"}
    at org.jongo.marshall.jackson.JacksonEngine.unmarshall(JacksonEngine.java:50)......

 

I copied only the first two raw.

Below i post the class test of my sut and the abstract class that extend:

import java.net.UnknownHostException;

import org.junit.ClassRule;
import org.testcontainers.containers.GenericContainer;

import com.mongodb.MongoClient;

import wabri.SchoolController.common.AbstractMongoDatabaseWrapperTest;

public class MongoDatabaseWrapperWithTestContainersIT extends AbstractMongoDatabaseWrapperTest {

	@SuppressWarnings("rawtypes")
	@ClassRule
	public static GenericContainer mongo = new GenericContainer("mongo:latest").withExposedPorts(27017);

	@Override
	public MongoClient createMongoClient() throws UnknownHostException {
		MongoClient mongoClient = new MongoClient(mongo.getContainerIpAddress(), mongo.getMappedPort(27017));
		return mongoClient;
	}

}

 

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.net.UnknownHostException;

import org.junit.Before;
import org.junit.Test;

import com.mongodb.MongoClient;

import wabri.SchoolController.Student;
import wabri.SchoolController.helper.MongoTestHelper;
import wabri.SchoolController.mongo.MongoDatabaseWrapper;

public abstract class AbstractMongoDatabaseWrapperTest {
	
	private MongoDatabaseWrapper mongoDatabase;

	public abstract MongoClient createMongoClient() throws UnknownHostException;

	private MongoTestHelper mongoTestHelper;

	@Before
	public void initDB() throws UnknownHostException {
		MongoClient mongoClient = createMongoClient();
		mongoTestHelper = new MongoTestHelper(mongoClient);
		mongoDatabase = new MongoDatabaseWrapper(mongoClient);
	}

	@Test
	public void testGetAllStudentsEmpty() {
		assertTrue(mongoDatabase.getAllStudentsList().isEmpty());
	}

	@Test
	public void testGetAllStudentsNotEmpty() {
		mongoTestHelper.addStudent("1", "first");
		mongoTestHelper.addStudent("2", "second");
		assertEquals(2, mongoDatabase.getAllStudentsList().size());
	}

	@Test
	public void testFindStudentByIdNotFound() {
		mongoTestHelper.addStudent("1", "first");
		assertNull(mongoDatabase.findStudentById("2"));
	}

	@Test
	public void testFindStudentByIdFound() {
		mongoTestHelper.addStudent("1", "first");
		mongoTestHelper.addStudent("2", "second");
		Student findStudentById = mongoDatabase.findStudentById("2");
		assertNotNull(findStudentById);
		assertEquals("2", findStudentById.getId());
		assertEquals("second", findStudentById.getName());
	}

}

if it's not enough the classes above this is the repo.

 

thanks for help.