1 19 package org.netbeans.modules.xslt.model.impl; 20 21 import java.util.List ; 22 23 import org.netbeans.modules.xslt.model.Key; 24 import org.netbeans.modules.xslt.model.Output; 25 import org.netbeans.modules.xslt.model.Param; 26 import org.netbeans.modules.xslt.model.Stylesheet; 27 import org.netbeans.modules.xslt.model.StylesheetChild; 28 import org.netbeans.modules.xslt.model.Template; 29 import org.netbeans.modules.xslt.model.Variable; 30 import org.w3c.dom.Document ; 31 import org.w3c.dom.Element ; 32 import org.w3c.dom.Node ; 33 import org.w3c.dom.NodeList ; 34 35 36 40 public class StyleheetTest extends AbstractXslTestCase { 41 42 public StyleheetTest( String testName ) { 43 super(testName); 44 } 45 46 public void testGetStylesheetChildren() { 47 Stylesheet stylesheet = getStyleSheet( TEST ); 48 49 List <StylesheetChild> list = stylesheet.getStylesheetChildren(); 50 51 assert list.size() == 7 ; 52 53 assert list.get( 0 ).getComponentType() == Param.class; 54 assert list.get( 1 ).getComponentType() == Output.class; 55 assert list.get( 2 ).getComponentType() == Variable.class; 56 assert list.get( 3 ).getComponentType() == Template.class; 57 assert list.get( 4 ).getComponentType() == Template.class; 58 assert list.get( 5 ).getComponentType() == Variable.class; 59 assert list.get( 6 ).getComponentType() == Param.class; 60 } 61 62 public void testAppendStylesheetChild() { 63 Stylesheet stylesheet = getStyleSheet( TEST ); 64 65 Template template = getModel().getFactory().createTemplate(); 66 67 List <String > children = getChildrenTags( 68 stylesheet.getStylesheetChildren() ); 69 70 getModel().startTransaction(); 71 stylesheet.appendStylesheetChild( template ); 72 getModel().endTransaction(); 73 74 Document doc = getDOMDocument( getModel() ); 75 76 Element root = doc.getDocumentElement(); 77 NodeList list = root.getChildNodes(); 78 79 int count = 0; 80 assert list.getLength() > children.size(); 81 for( int i = 0 ; i< list.getLength(); i++ ) { 82 Node next = list.item( i ); 83 if ( count == children.size() && next instanceof Element ) { 84 assert next.getNodeName().endsWith( 85 template.getPeer().getNodeName() ): "Found "+ 86 next.getNodeName()+" element, but expected :"+ 87 template.getPeer().getNodeName(); 88 89 break; 90 } 91 if ( next instanceof Element && 92 !next.getNodeName().endsWith("import")) { 94 assert next.getNodeName().equals( children.get( count )): 95 "Found "+next.getNodeName()+" element, but expected : "+ 96 children.get( i ); 97 count++; 98 } 99 } 100 } 101 102 public void testRemoveStylesheetChild() { 103 Stylesheet stylesheet = getStyleSheet( TEST ); 104 105 List <StylesheetChild> children = stylesheet.getStylesheetChildren(); 106 List <String > childrenNames = getChildrenTags( children ); 107 108 getModel().startTransaction(); 109 stylesheet.removeStylesheetChild( children.get( 0 )); 110 getModel().endTransaction(); 111 112 childrenNames.remove( 0 ); 113 114 Document doc = getDOMDocument( getModel() ); 115 116 Element root = doc.getDocumentElement(); 117 NodeList list = root.getChildNodes(); 118 119 int count = 0; 120 for( int i = 0 ; i< list.getLength(); i++ ) { 121 Node next = list.item( i ); 122 if ( next instanceof Element && 123 !next.getNodeName().endsWith("import")) { 125 assert next.getNodeName().equals( childrenNames.get( count )): 126 "Found "+next.getNodeName()+" element, but expected : "+ 127 childrenNames.get( count ); 128 count++; 129 } 130 } 131 } 132 133 public void testAddStylesheetChild() { 134 Stylesheet stylesheet = getStyleSheet( TEST ); 135 136 List <StylesheetChild> children = stylesheet.getStylesheetChildren(); 137 List <String > childrenNames = getChildrenTags( children ); 138 139 Key key = getModel().getFactory().createKey(); 140 141 int position = 1; 142 getModel().startTransaction(); 143 stylesheet.addStylesheetChild( key, position ); 144 getModel().endTransaction(); 145 146 Document doc = getDOMDocument( getModel() ); 147 148 Element root = doc.getDocumentElement(); 149 NodeList list = root.getChildNodes(); 150 151 int count = 0; 152 boolean flag = true; 153 for( int i = 0 ; i< list.getLength(); i++ ) { 154 Node next = list.item( i ); 155 if ( count == position && next instanceof Element && flag ) { 156 assert next.getNodeName().endsWith( key.getPeer().getNodeName() ): 157 "Found "+ 158 next.getNodeName()+" element, but expected :"+ 159 key.getPeer().getNodeName(); 160 flag = false; 161 } 162 else if ( next instanceof Element && 163 !next.getNodeName().endsWith("import")) { 165 assert next.getNodeName().equals( childrenNames.get( count )): 166 "Found "+next.getNodeName()+" element, but expected : "+ 167 childrenNames.get( count ); 168 count++; 169 } 170 } 171 } 172 173 175 } 176 | Popular Tags |