Skip to content

Commit 7f86a05

Browse files
DATAMONGO-479 - Assert MongoDB Java driver generation 3 compatibility.
Use getCode() instead of toString for converting o.b.t.Code objects. This works fine for MongoDB Java driver versions 2 and 3.
1 parent e132f8c commit 7f86a05

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MongoConverters.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public CallableMongoScript convert(DBObject source) {
202202
String id = source.get("_id").toString();
203203
Object rawValue = source.get("value");
204204

205-
return new CallableMongoScript(id, rawValue.toString());
205+
return new CallableMongoScript(id, ((Code) rawValue).getCode());
206206
}
207207
}
208208

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/CallableMongoScriptConvertsUnitTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.junit.runners.Suite;
2828
import org.junit.runners.Suite.SuiteClasses;
2929
import org.springframework.data.mongodb.core.convert.CallableMongoScriptConvertsUnitTests.CallableMongoScriptToDboConverterUnitTests;
30+
import org.springframework.data.mongodb.core.convert.CallableMongoScriptConvertsUnitTests.DboToCallableMongoScriptConverterUnitTests;
3031
import org.springframework.data.mongodb.core.convert.MongoConverters.CallableMongoScriptToDBObjectConverter;
3132
import org.springframework.data.mongodb.core.convert.MongoConverters.DBObjectToCallableMongoScriptCoverter;
3233
import org.springframework.data.mongodb.core.script.CallableMongoScript;
@@ -39,7 +40,7 @@
3940
* @author Christoph Strobl
4041
*/
4142
@RunWith(Suite.class)
42-
@SuiteClasses({ CallableMongoScriptToDboConverterUnitTests.class })
43+
@SuiteClasses({ CallableMongoScriptToDboConverterUnitTests.class, DboToCallableMongoScriptConverterUnitTests.class })
4344
public class CallableMongoScriptConvertsUnitTests {
4445

4546
static final String FUNCTION_NAME = "echo";
@@ -86,7 +87,7 @@ public void convertShouldConvertScriptCodeCorreclty() {
8687

8788
Object code = dbo.get("value");
8889
assertThat(code, instanceOf(Code.class));
89-
assertThat(code.toString(), equalTo(JS_FUNCTION));
90+
assertThat(code, equalTo((Object) new Code(JS_FUNCTION)));
9091
}
9192
}
9293

@@ -125,7 +126,7 @@ public void convertShouldConvertScriptValueCorreclty() {
125126
CallableMongoScript script = converter.convert(FUNCTION);
126127

127128
assertThat(script.getCode(), notNullValue());
128-
assertThat(script.getCode().toString(), equalTo(JS_FUNCTION));
129+
assertThat(script.getCode(), equalTo(JS_FUNCTION));
129130
}
130131
}
131132

0 commit comments

Comments
 (0)