I am trying to create a test in Scala of a Java method. I have created a test to save for the method of saving a document in Elastic search:
I have tried to cast the parameter as an instance of T in my test method in Scala:
test("Save Test") {
val esr2 = new ElasticSearchRepository(jestClientFactory.getObject, index, esType.asInstanceOf[T].getClass , defaultSize)
esr2.save(esType.asInstanceOf[T],"_testId")
val results = esr.findAll()
println("Save results: " + results)
assert(results.contains("_testId") == true)
}
The object esType is an object called copy.
Here is the method that I am testing:
public JestResult save(T doc, String id) {
Index cmd = new Index.Builder(doc)
.index(index)
.type(index)
.id(id)
.build();
JestResult result = execute(cmd);
if (!result.isSucceeded()) {
logger.error("error saving {} document to elasticsearch: {}", index, result.getErrorMessage());
}
return result;
}
Even though I am converting my object of esType to T, I am getting the error of type mismatch.
When I run the test, it is saying: Type Mismatch
Found: T (in ElasticSearchRepositoryTest)
Required: T (in value esr2)
I am not sure how to make esType a T of esr2
Aucun commentaire:
Enregistrer un commentaire