@Test
public void testReplacewithImage() throws Exception {
// create source image
TextDocument sourcedoc = TextDocument.newTextDocument();
Paragraph para = sourcedoc.addParagraph("helloImage");
Image image = Image.newImage(para, ResourceUtilities.getURI("image_list_item.png"));
image.setName("this image 1");
image.setHyperlink(new URI("http://odftoolkit.org"));
Paragraph para2 = sourcedoc.addParagraph("helloImage2");
Image image2 = Image.newImage(para2, ResourceUtilities.getURI("testA.jpg"));
image2.setName("this image 2");
image2.setHyperlink(new URI("http://odftoolkit.org"));
search = null;
// 6 Simple, at the middle of original Paragraph, split original
// Paragraph, insert before the second Paragraph.
doc = (TextDocument) Document.loadDocument(ResourceUtilities.getAbsolutePath(TEXT_FILE));
search = new TextNavigation("SIMPLE", doc);
int i = 0;
TextSelection item = null;
while (search.hasNext()) {
item = (TextSelection) search.nextSelection();
Paragraph paragraph = sourcedoc.getParagraphByIndex(0, true);
TextParagraphElementBase textParaEleBase = paragraph.getOdfElement();
NodeList nodeImages = textParaEleBase.getElementsByTagName("draw:image");
Node nodeImage = nodeImages.item(0);
DrawImageElement im = (DrawImageElement) nodeImage;
Image ima = Image.getInstanceof(im);
image = item.replaceWith(ima);
Assert.assertNotNull(image);
if (image.getName().startsWith("replace")) {
Assert.assertTrue(true);
} else {