FieldSelection extends Selection { public Field replaceWithSimpleField(Field.FieldType fieldType) { int leftLength = textSelection.getText().length(); int index = textSelection.getIndex(); prepareSpanContainer(leftLength, index); Field field = null; switch (fieldType) { case DATE_FIELD: field = Fields.createDateField(spanContainer); break; case FIXED_DATE_FIELD: field = Fields.createFixedDateField(spanContainer); break; case TIME_FIELD: field = Fields.createTimeField(spanContainer); break; case FIXED_TIME_FIELD: field = Fields.createFixedTimeField(spanContainer); break; case PREVIOUS_PAGE_NUMBER_FIELD: field = Fields.createPreviousPageNumberField(spanContainer); break; case CURRENT_PAGE_NUMBER_FIELD: field = Fields.createCurrentPageNumberField(spanContainer); break; case NEXT_PAGE_NUMBER_FIELD: field = Fields.createNextPageNumberField(spanContainer); break; case PAGE_COUNT_FIELD: field = Fields.createPageCountField(spanContainer); break; case TITLE_FIELD: field = Fields.createTitleField(spanContainer); break; case SUBJECT_FIELD: field = Fields.createSubjectField(spanContainer); break; case AUTHOR_NAME_FIELD: field = Fields.createAuthorNameField(spanContainer); break; case AUTHOR_INITIALS_FIELD: field = Fields.createAuthorInitialsField(spanContainer); break; case CHAPTER_FIELD: field = Fields.createChapterField(spanContainer); break; case REFERENCE_FIELD: case SIMPLE_VARIABLE_FIELD: case USER_VARIABLE_FIELD: case CONDITION_FIELD: case HIDDEN_TEXT_FIELD: throw new IllegalArgumentException("this is not a vaild simple field type."); } textSelection.mMatchedText = field.getOdfElement().getTextContent(); int textLength = textSelection.mMatchedText.length(); int offset = textLength - leftLength; SelectionManager.refresh(textSelection.getContainerElement(), offset, index + textLength); return field; } FieldSelection(TextSelection selection); Field replaceWithSimpleField(Field.FieldType fieldType); void replaceWithReferenceField(ReferenceField field, ReferenceField.DisplayType type); void replaceWithVariableField(VariableField field); ConditionField replaceWithConditionField(String condition, String trueText, String falseText); ConditionField replaceWithHiddenTextField(String condition, String text); void applyStyle(OdfStyleBase style); @Override void cut(); void replaceWith(String newText); @Override void pasteAtEndOf(Selection positionItem); @Override void pasteAtFrontOf(Selection positionItem);  }
@Test public void testReplaceWithSimpleField() { try { search = new TextNavigation("ReplaceDateTarget", doc); OdfContentDom contentDom = doc.getContentDom(); NodeList nodeList = contentDom.getElementsByTagName(TextDateElement.ELEMENT_NAME.getQName()); int i = nodeList.getLength(); OdfStylesDom styleDom = doc.getStylesDom(); nodeList = styleDom.getElementsByTagName(TextDateElement.ELEMENT_NAME.getQName()); i += nodeList.getLength(); while (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); FieldSelection fieldSelection = new FieldSelection(item); fieldSelection.replaceWithSimpleField(Field.FieldType.FIXED_DATE_FIELD); i++; } nodeList = contentDom.getElementsByTagName(TextDateElement.ELEMENT_NAME.getQName()); int j = nodeList.getLength(); nodeList = styleDom.getElementsByTagName(TextDateElement.ELEMENT_NAME.getQName()); j += nodeList.getLength(); Assert.assertEquals(j, i); doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_REPLACE)); } catch (Exception e) { Logger.getLogger(FieldSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e); Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'"); } }
@Test public void testReplaceWithSimpleField2() { try { search = new TextNavigation("ReplaceDateTarget", doc); OdfContentDom contentDom = doc.getContentDom(); NodeList nodeList = contentDom.getElementsByTagName(TextDateElement.ELEMENT_NAME.getQName()); int i = nodeList.getLength(); OdfStylesDom styleDom = doc.getStylesDom(); nodeList = styleDom.getElementsByTagName(TextDateElement.ELEMENT_NAME.getQName()); i += nodeList.getLength(); while (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); FieldSelection fieldSelection = new FieldSelection(item); fieldSelection.replaceWithSimpleField(Field.FieldType.DATE_FIELD); i++; } nodeList = contentDom.getElementsByTagName(TextDateElement.ELEMENT_NAME.getQName()); int j = nodeList.getLength(); nodeList = styleDom.getElementsByTagName(TextDateElement.ELEMENT_NAME.getQName()); j += nodeList.getLength(); Assert.assertEquals(j, i); doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_REPLACE)); } catch (Exception e) { Logger.getLogger(FieldSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e); Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'"); } }
@Test public void testReplaceWithSimpleField_time_field() { try { search = new TextNavigation("ReplaceDateTarget", doc); OdfContentDom contentDom = doc.getContentDom(); NodeList nodeList = contentDom.getElementsByTagName(TextTimeElement.ELEMENT_NAME.getQName()); int i = nodeList.getLength(); for(int k =0;k<nodeList.getLength();k++){ Node nv = nodeList.item(k); if(nv.getFirstChild().getNodeValue().matches("^([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$")){ NamedNodeMap nameMap = nv.getAttributes(); Node nfix = nameMap.getNamedItem("text:fixed"); nfix.setNodeValue("false"); } } OdfStylesDom styleDom = doc.getStylesDom(); nodeList = styleDom.getElementsByTagName(TextTimeElement.ELEMENT_NAME.getQName()); i += nodeList.getLength(); while (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); FieldSelection fieldSelection = new FieldSelection(item); fieldSelection.replaceWithSimpleField(Field.FieldType.TIME_FIELD); i++; } nodeList = contentDom.getElementsByTagName(TextTimeElement.ELEMENT_NAME.getQName()); int j = nodeList.getLength(); nodeList = styleDom.getElementsByTagName(TextTimeElement.ELEMENT_NAME.getQName()); j += nodeList.getLength(); Assert.assertEquals(j, i); doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_REPLACE)); TextDocument doc1 = (TextDocument) Document.loadDocument(ResourceUtilities.getAbsolutePath(SAVE_FILE_REPLACE)); OdfContentDom contentDom1 = doc1.getContentDom(); nodeList = contentDom1.getElementsByTagName(TextTimeElement.ELEMENT_NAME.getQName()); for(int k =0;k<nodeList.getLength();k++){ Node nv = nodeList.item(k); if(nv.getFirstChild().getNodeValue().matches("^([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$")){ NamedNodeMap nameMap = nv.getAttributes(); Node nfix = nameMap.getNamedItem("text:fixed"); System.out.println("&&& " + nfix.getNodeValue()); Assert.assertEquals("false", nfix.getNodeValue()); } } } catch (Exception e) { Logger.getLogger(FieldSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e); Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'"); } }
@Test public void testReplaceWithSimpleField_fixed_time_field() { try { search = new TextNavigation("ReplaceDateTarget", doc); OdfContentDom contentDom = doc.getContentDom(); NodeList nodeList = contentDom.getElementsByTagName(TextTimeElement.ELEMENT_NAME.getQName()); int i = nodeList.getLength(); OdfStylesDom styleDom = doc.getStylesDom(); nodeList = styleDom.getElementsByTagName(TextTimeElement.ELEMENT_NAME.getQName()); i += nodeList.getLength(); while (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); FieldSelection fieldSelection = new FieldSelection(item); fieldSelection.replaceWithSimpleField(Field.FieldType.FIXED_TIME_FIELD); i++; } nodeList = contentDom.getElementsByTagName(TextTimeElement.ELEMENT_NAME.getQName()); int j = nodeList.getLength(); nodeList = styleDom.getElementsByTagName(TextTimeElement.ELEMENT_NAME.getQName()); j += nodeList.getLength(); Assert.assertEquals(j, i); doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_REPLACE)); } catch (Exception e) { Logger.getLogger(FieldSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e); Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'"); } }
@Test public void testReplaceWithSimpleField_previous_page_number_field() { try { search = new TextNavigation("ReplaceDateTarget", doc); OdfContentDom contentDom = doc.getContentDom(); NodeList nodeList1 = contentDom.getElementsByTagName(TextPageNumberElement.ELEMENT_NAME.getQName()); for(int k =0;k<nodeList1.getLength();k++){ Node nv = nodeList1.item(k); NamedNodeMap nameMap = nv.getAttributes(); Node nfix = nameMap.getNamedItem("text:select-page"); nfix.setNodeValue("previous"); } NodeList nodeList = contentDom.getElementsByTagName(TextPageNumberElement.ELEMENT_NAME.getQName()); int i = nodeList.getLength(); OdfStylesDom styleDom = doc.getStylesDom(); nodeList = styleDom.getElementsByTagName(TextPageNumberElement.ELEMENT_NAME.getQName()); i += nodeList.getLength(); while (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); FieldSelection fieldSelection = new FieldSelection(item); fieldSelection.replaceWithSimpleField(Field.FieldType.PREVIOUS_PAGE_NUMBER_FIELD); i++; } nodeList = contentDom.getElementsByTagName(TextPageNumberElement.ELEMENT_NAME.getQName()); int j = nodeList.getLength(); nodeList = styleDom.getElementsByTagName(TextPageNumberElement.ELEMENT_NAME.getQName()); j += nodeList.getLength(); Assert.assertEquals(j, i); doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_REPLACE)); TextDocument doc1 = (TextDocument) Document.loadDocument(ResourceUtilities.getAbsolutePath(SAVE_FILE_REPLACE)); OdfContentDom contentDom1 = doc1.getContentDom(); nodeList = contentDom1.getElementsByTagName(TextPageNumberElement.ELEMENT_NAME.getQName()); for(int k =0;k<nodeList.getLength();k++){ Node nv = nodeList.item(k); NamedNodeMap nameMap = nv.getAttributes(); Node nfix = nameMap.getNamedItem("text:select-page"); Assert.assertEquals("previous", nfix.getNodeValue()); } } catch (Exception e) { Logger.getLogger(FieldSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e); Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'"); } }
@Test public void testReplaceWithSimpleField_current_page_number_field() { try { search = new TextNavigation("ReplaceDateTarget", doc); OdfContentDom contentDom = doc.getContentDom(); NodeList nodeList1 = contentDom.getElementsByTagName(TextPageNumberElement.ELEMENT_NAME.getQName()); for(int k =0;k<nodeList1.getLength();k++){ Node nv = nodeList1.item(k); NamedNodeMap nameMap = nv.getAttributes(); Node nfix = nameMap.getNamedItem("text:select-page"); nfix.setNodeValue("current"); } NodeList nodeList = contentDom.getElementsByTagName(TextPageNumberElement.ELEMENT_NAME.getQName()); int i = nodeList.getLength(); OdfStylesDom styleDom = doc.getStylesDom(); nodeList = styleDom.getElementsByTagName(TextPageNumberElement.ELEMENT_NAME.getQName()); i += nodeList.getLength(); while (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); FieldSelection fieldSelection = new FieldSelection(item); fieldSelection.replaceWithSimpleField(Field.FieldType.CURRENT_PAGE_NUMBER_FIELD); i++; } nodeList = contentDom.getElementsByTagName(TextPageNumberElement.ELEMENT_NAME.getQName()); int j = nodeList.getLength(); nodeList = styleDom.getElementsByTagName(TextPageNumberElement.ELEMENT_NAME.getQName()); j += nodeList.getLength(); Assert.assertEquals(j, i); doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_REPLACE)); TextDocument doc1 = (TextDocument) Document.loadDocument(ResourceUtilities.getAbsolutePath(SAVE_FILE_REPLACE)); OdfContentDom contentDom1 = doc1.getContentDom(); nodeList = contentDom1.getElementsByTagName(TextPageNumberElement.ELEMENT_NAME.getQName()); for(int k =0;k<nodeList.getLength();k++){ Node nv = nodeList.item(k); NamedNodeMap nameMap = nv.getAttributes(); Node nfix = nameMap.getNamedItem("text:select-page"); System.out.println(nfix.getNodeValue()); Assert.assertEquals("current", nfix.getNodeValue()); } } catch (Exception e) { Logger.getLogger(FieldSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e); Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'"); } }
@Test public void testReplaceWithSimpleField_next_page_number_field() { try { search = new TextNavigation("ReplaceDateTarget", doc); OdfContentDom contentDom = doc.getContentDom(); NodeList nodeList1 = contentDom.getElementsByTagName(TextPageNumberElement.ELEMENT_NAME.getQName()); for(int k =0;k<nodeList1.getLength();k++){ Node nv = nodeList1.item(k); NamedNodeMap nameMap = nv.getAttributes(); Node nfix = nameMap.getNamedItem("text:select-page"); nfix.setNodeValue("next"); } NodeList nodeList = contentDom.getElementsByTagName(TextPageNumberElement.ELEMENT_NAME.getQName()); int i = nodeList.getLength(); OdfStylesDom styleDom = doc.getStylesDom(); nodeList = styleDom.getElementsByTagName(TextPageNumberElement.ELEMENT_NAME.getQName()); i += nodeList.getLength(); while (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); FieldSelection fieldSelection = new FieldSelection(item); fieldSelection.replaceWithSimpleField(Field.FieldType.NEXT_PAGE_NUMBER_FIELD); i++; } nodeList = contentDom.getElementsByTagName(TextPageNumberElement.ELEMENT_NAME.getQName()); int j = nodeList.getLength(); nodeList = styleDom.getElementsByTagName(TextPageNumberElement.ELEMENT_NAME.getQName()); j += nodeList.getLength(); Assert.assertEquals(j, i); doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_REPLACE)); TextDocument doc1 = (TextDocument) Document.loadDocument(ResourceUtilities.getAbsolutePath(SAVE_FILE_REPLACE)); OdfContentDom contentDom1 = doc1.getContentDom(); nodeList = contentDom1.getElementsByTagName(TextPageNumberElement.ELEMENT_NAME.getQName()); for(int k =0;k<nodeList.getLength();k++){ Node nv = nodeList.item(k); NamedNodeMap nameMap = nv.getAttributes(); Node nfix = nameMap.getNamedItem("text:select-page"); System.out.println(nfix.getNodeValue()); Assert.assertEquals("next", nfix.getNodeValue()); } } catch (Exception e) { Logger.getLogger(FieldSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e); Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'"); } }
@Test public void testReplaceWithSimpleField_page_count_field() { try { search = new TextNavigation("ReplaceDateTarget", doc); OdfContentDom contentDom = doc.getContentDom(); NodeList nodeList = contentDom.getElementsByTagName(TextPageCountElement.ELEMENT_NAME.getQName()); int i = nodeList.getLength(); OdfStylesDom styleDom = doc.getStylesDom(); nodeList = styleDom.getElementsByTagName(TextPageCountElement.ELEMENT_NAME.getQName()); i += nodeList.getLength(); while (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); FieldSelection fieldSelection = new FieldSelection(item); fieldSelection.replaceWithSimpleField(Field.FieldType.PAGE_COUNT_FIELD); i++; } nodeList = contentDom.getElementsByTagName(TextPageCountElement.ELEMENT_NAME.getQName()); int j = nodeList.getLength(); nodeList = styleDom.getElementsByTagName(TextPageCountElement.ELEMENT_NAME.getQName()); j += nodeList.getLength(); Assert.assertEquals(j, i); doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_REPLACE)); } catch (Exception e) { Logger.getLogger(FieldSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e); Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'"); } }
@Test public void testReplaceWithSimpleField_title_field() { try { search = new TextNavigation("ReplaceDateTarget", doc); OdfContentDom contentDom = doc.getContentDom(); NodeList nodeList = contentDom.getElementsByTagName(TextTitleElement.ELEMENT_NAME.getQName()); int i = nodeList.getLength(); OdfStylesDom styleDom = doc.getStylesDom(); nodeList = styleDom.getElementsByTagName(TextTitleElement.ELEMENT_NAME.getQName()); i += nodeList.getLength(); while (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); FieldSelection fieldSelection = new FieldSelection(item); fieldSelection.replaceWithSimpleField(Field.FieldType.TITLE_FIELD); i++; } nodeList = contentDom.getElementsByTagName(TextTitleElement.ELEMENT_NAME.getQName()); int j = nodeList.getLength(); nodeList = styleDom.getElementsByTagName(TextTitleElement.ELEMENT_NAME.getQName()); j += nodeList.getLength(); Assert.assertEquals(j, i); doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_REPLACE)); } catch (Exception e) { Logger.getLogger(FieldSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e); Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'"); } }
@Test public void testReplaceWithSimpleField_subject_field() { try { search = new TextNavigation("ReplaceDateTarget", doc); OdfContentDom contentDom = doc.getContentDom(); NodeList nodeList = contentDom.getElementsByTagName(TextSubjectElement.ELEMENT_NAME.getQName()); int i = nodeList.getLength(); OdfStylesDom styleDom = doc.getStylesDom(); nodeList = styleDom.getElementsByTagName(TextSubjectElement.ELEMENT_NAME.getQName()); i += nodeList.getLength(); while (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); FieldSelection fieldSelection = new FieldSelection(item); fieldSelection.replaceWithSimpleField(Field.FieldType.SUBJECT_FIELD); i++; } nodeList = contentDom.getElementsByTagName(TextSubjectElement.ELEMENT_NAME.getQName()); int j = nodeList.getLength(); nodeList = styleDom.getElementsByTagName(TextSubjectElement.ELEMENT_NAME.getQName()); j += nodeList.getLength(); Assert.assertEquals(j, i); doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_REPLACE)); } catch (Exception e) { Logger.getLogger(FieldSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e); Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'"); } }
@Test public void testReplaceWithSimpleField_author_name_field() { try { search = new TextNavigation("ReplaceDateTarget", doc); OdfContentDom contentDom = doc.getContentDom(); NodeList nodeList = contentDom.getElementsByTagName(TextAuthorNameElement.ELEMENT_NAME.getQName()); int i = nodeList.getLength(); OdfStylesDom styleDom = doc.getStylesDom(); nodeList = styleDom.getElementsByTagName(TextAuthorNameElement.ELEMENT_NAME.getQName()); i += nodeList.getLength(); while (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); FieldSelection fieldSelection = new FieldSelection(item); fieldSelection.replaceWithSimpleField(Field.FieldType.AUTHOR_NAME_FIELD); i++; } nodeList = contentDom.getElementsByTagName(TextAuthorNameElement.ELEMENT_NAME.getQName()); int j = nodeList.getLength(); nodeList = styleDom.getElementsByTagName(TextAuthorNameElement.ELEMENT_NAME.getQName()); j += nodeList.getLength(); Assert.assertEquals(j, i); doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_REPLACE)); } catch (Exception e) { Logger.getLogger(FieldSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e); Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'"); } }
@Test public void testReplaceWithSimpleField_author_initials_field() { try { search = new TextNavigation("ReplaceDateTarget", doc); OdfContentDom contentDom = doc.getContentDom(); NodeList nodeList = contentDom.getElementsByTagName(TextAuthorInitialsElement.ELEMENT_NAME.getQName()); int i = nodeList.getLength(); OdfStylesDom styleDom = doc.getStylesDom(); nodeList = styleDom.getElementsByTagName(TextAuthorInitialsElement.ELEMENT_NAME.getQName()); i += nodeList.getLength(); while (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); FieldSelection fieldSelection = new FieldSelection(item); fieldSelection.replaceWithSimpleField(Field.FieldType.AUTHOR_INITIALS_FIELD); i++; } nodeList = contentDom.getElementsByTagName(TextAuthorInitialsElement.ELEMENT_NAME.getQName()); int j = nodeList.getLength(); nodeList = styleDom.getElementsByTagName(TextAuthorInitialsElement.ELEMENT_NAME.getQName()); j += nodeList.getLength(); Assert.assertEquals(j, i); doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_REPLACE)); } catch (Exception e) { Logger.getLogger(FieldSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e); Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'"); } }
@Test public void testReplaceWithSimpleField_chapter_field() { try { search = new TextNavigation("ReplaceDateTarget", doc); OdfContentDom contentDom = doc.getContentDom(); NodeList nodeList = contentDom.getElementsByTagName(TextChapterElement.ELEMENT_NAME.getQName()); int i = nodeList.getLength(); OdfStylesDom styleDom = doc.getStylesDom(); nodeList = styleDom.getElementsByTagName(TextChapterElement.ELEMENT_NAME.getQName()); i += nodeList.getLength(); while (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); FieldSelection fieldSelection = new FieldSelection(item); fieldSelection.replaceWithSimpleField(Field.FieldType.CHAPTER_FIELD); i++; } nodeList = contentDom.getElementsByTagName(TextChapterElement.ELEMENT_NAME.getQName()); int j = nodeList.getLength(); nodeList = styleDom.getElementsByTagName(TextChapterElement.ELEMENT_NAME.getQName()); j += nodeList.getLength(); Assert.assertEquals(j, i); doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_REPLACE)); } catch (Exception e) { Logger.getLogger(FieldSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e); Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'"); } }
@Test public void testReplaceWithSimpleField_reference_field() { try { search = new TextNavigation("ReplaceDateTarget", doc); while (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); FieldSelection fieldSelection = new FieldSelection(item); fieldSelection.replaceWithSimpleField(Field.FieldType.REFERENCE_FIELD); } } catch (Exception e) { Assert.assertTrue(e instanceof IllegalArgumentException); Assert.assertEquals("this is not a vaild simple field type.", e.getMessage()); } }
@Test public void testReplaceWithSimpleField_simple_variable_field() { try { search = new TextNavigation("ReplaceDateTarget", doc); while (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); FieldSelection fieldSelection = new FieldSelection(item); fieldSelection.replaceWithSimpleField(Field.FieldType.SIMPLE_VARIABLE_FIELD); } } catch (Exception e) { Assert.assertTrue(e instanceof IllegalArgumentException); Assert.assertEquals("this is not a vaild simple field type.", e.getMessage()); } }
@Test public void testReplaceWithSimpleField_user_variable_field() { try { search = new TextNavigation("ReplaceDateTarget", doc); while (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); FieldSelection fieldSelection = new FieldSelection(item); fieldSelection.replaceWithSimpleField(Field.FieldType.USER_VARIABLE_FIELD); } } catch (Exception e) { Assert.assertTrue(e instanceof IllegalArgumentException); Assert.assertEquals("this is not a vaild simple field type.", e.getMessage()); } }
@Test public void testReplaceWithSimpleField_condition_field() { try { search = new TextNavigation("ReplaceDateTarget", doc); while (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); FieldSelection fieldSelection = new FieldSelection(item); fieldSelection.replaceWithSimpleField(Field.FieldType.CONDITION_FIELD); } } catch (Exception e) { Assert.assertTrue(e instanceof IllegalArgumentException); Assert.assertEquals("this is not a vaild simple field type.", e.getMessage()); } }
@Test public void testReplaceWithSimpleField_hidden_text_field() { try { search = new TextNavigation("ReplaceDateTarget", doc); while (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); FieldSelection fieldSelection = new FieldSelection(item); fieldSelection.replaceWithSimpleField(Field.FieldType.HIDDEN_TEXT_FIELD); } } catch (Exception e) { Assert.assertTrue(e instanceof IllegalArgumentException); Assert.assertEquals("this is not a vaild simple field type.", e.getMessage()); } }