1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation. Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package test.fxmltests.functional;
  26 
  27 import junit.framework.Assert;
  28 import org.jemmy.env.Timeout;
  29 import org.jemmy.timing.State;
  30 import org.jemmy.timing.Waiter;
  31 import org.junit.BeforeClass;
  32 import org.junit.Test;
  33 import test.fxmltests.app.LineNumberApp;
  34 import test.javaclient.shared.TestBase;
  35 import test.javaclient.shared.Utils;
  36 
  37 public class LineNumberTest extends TestBase {
  38 
  39     private static final long WAITER_TIMEOUT = 5000;
  40 
  41     @BeforeClass
  42     public static void runUI() {
  43         Utils.launch(LineNumberApp.class, null);
  44     }
  45 
  46     /**
  47      * testing LoadListener#readImportProcessingInstruction
  48      */
  49     @Test
  50     public void testImportProcessingInstruction() {
  51         testCommon(LineNumberApp.Pages.mainPage.name(), null, false, false);
  52         new Waiter(new Timeout("", WAITER_TIMEOUT)).ensureValue(true, new State<Boolean>() {
  53             @Override
  54             public Boolean reached() {
  55                 return LineNumberApp.importProcessingInstructionMatrix.length == LineNumberApp.importProcessingInstruction.size();
  56             }
  57         });
  58         for (int i = 0; i < LineNumberApp.importProcessingInstructionMatrix.length; i++) {
  59             Assert.assertEquals(LineNumberApp.importProcessingInstructionMatrix[i], LineNumberApp.importProcessingInstruction.get(i));
  60         }
  61     }
  62 
  63     /**
  64      * testing LoadListener#readLanguageProcessingInstruction
  65      */
  66     @Test
  67     public void testLanguageProcessingInstruction() {
  68         testCommon(LineNumberApp.Pages.mainPage.name(), null, false, false);
  69         new Waiter(new Timeout("", WAITER_TIMEOUT)).ensureValue(true, new State<Boolean>() {
  70             @Override
  71             public Boolean reached() {
  72                 return LineNumberApp.languageProcessingInstructionMatrix.length == LineNumberApp.languageProcessingInstruction.size();
  73             }
  74         });
  75         for (int i = 0; i < LineNumberApp.languageProcessingInstructionMatrix.length; i++) {
  76             Assert.assertEquals(LineNumberApp.languageProcessingInstructionMatrix[i], LineNumberApp.languageProcessingInstruction.get(i));
  77         }
  78     }
  79 
  80     /**
  81      * testing LoadListener#readComment
  82      */
  83     @Test
  84     public void testComment() {
  85         testCommon(LineNumberApp.Pages.mainPage.name(), null, false, false);
  86         new Waiter(new Timeout("", WAITER_TIMEOUT)).ensureValue(true, new State<Boolean>() {
  87             @Override
  88             public Boolean reached() {
  89                 return LineNumberApp.commentMatrix.length == LineNumberApp.comment.size();
  90             }
  91         });
  92         for (int i = 0; i < LineNumberApp.commentMatrix.length; i++) {
  93             Assert.assertEquals(LineNumberApp.commentMatrix[i], LineNumberApp.comment.get(i));
  94         }
  95     }
  96 
  97     /**
  98      * testing LoadListener#beginInstanceDeclarationElement
  99      */
 100     @Test
 101     public void testBeginInstanceDeclarationElement() {
 102         testCommon(LineNumberApp.Pages.mainPage.name(), null, false, false);
 103         new Waiter(new Timeout("", WAITER_TIMEOUT)).ensureValue(true, new State<Boolean>() {
 104             @Override
 105             public Boolean reached() {
 106                 return LineNumberApp.instanceDeclarationElementMatrix.length == LineNumberApp.instanceDeclarationElement.size();
 107             }
 108         });
 109         for (int i = 0; i < LineNumberApp.instanceDeclarationElementMatrix.length; i++) {
 110             Assert.assertEquals(LineNumberApp.instanceDeclarationElementMatrix[i], LineNumberApp.instanceDeclarationElement.get(i));
 111         }
 112     }
 113 
 114     /**
 115      * testing LoadListener#beginIncludeElement
 116      */
 117     @Test
 118     public void testIncludeElement() {
 119         testCommon(LineNumberApp.Pages.mainPage.name(), null, false, false);
 120         new Waiter(new Timeout("", WAITER_TIMEOUT)).ensureValue(true, new State<Boolean>() {
 121             @Override
 122             public Boolean reached() {
 123                 return LineNumberApp.includeElementMatrix.length == LineNumberApp.includeElement.size();
 124             }
 125         });
 126         for (int i = 0; i < LineNumberApp.includeElementMatrix.length; i++) {
 127             Assert.assertEquals(LineNumberApp.includeElementMatrix[i], LineNumberApp.includeElement.get(i));
 128         }
 129     }
 130 
 131     /**
 132      * testing LoadListener#beginReferenceElement
 133      */
 134     @Test
 135     public void testReferenceElement() {
 136         testCommon(LineNumberApp.Pages.mainPage.name(), null, false, false);
 137         new Waiter(new Timeout("", WAITER_TIMEOUT)).ensureValue(true, new State<Boolean>() {
 138             @Override
 139             public Boolean reached() {
 140                 return LineNumberApp.referenceElementMatrix.length == LineNumberApp.referenceElement.size();
 141             }
 142         });
 143         for (int i = 0; i < LineNumberApp.referenceElementMatrix.length; i++) {
 144             Assert.assertEquals(LineNumberApp.referenceElementMatrix[i], LineNumberApp.referenceElement.get(i));
 145         }
 146     }
 147 
 148     /**
 149      * testing LoadListener#beginCopyElement
 150      */
 151     @Test
 152     public void testCopyElement() {
 153         testCommon(LineNumberApp.Pages.mainPage.name(), null, false, false);
 154         new Waiter(new Timeout("", WAITER_TIMEOUT)).ensureValue(true, new State<Boolean>() {
 155             @Override
 156             public Boolean reached() {
 157                 return LineNumberApp.copyElementMatrix.length == LineNumberApp.copyElement.size();
 158             }
 159         });
 160         for (int i = 0; i < LineNumberApp.copyElementMatrix.length; i++) {
 161             Assert.assertEquals(LineNumberApp.copyElementMatrix[i], LineNumberApp.copyElement.get(i));
 162         }
 163     }
 164 
 165     /**
 166      * testing LoadListener#beginRootElement
 167      */
 168     @Test
 169     public void testRootElement() {
 170         testCommon(LineNumberApp.Pages.mainPage.name(), null, false, false);
 171         new Waiter(new Timeout("", WAITER_TIMEOUT)).ensureValue(true, new State<Boolean>() {
 172             @Override
 173             public Boolean reached() {
 174                 return LineNumberApp.rootElement > 0;
 175             }
 176         });
 177         Assert.assertEquals(LineNumberApp.rootElementLine, LineNumberApp.rootElement);
 178     }
 179 
 180     /**
 181      * testing LoadListener#beginPropertyElement
 182      */
 183     @Test
 184     public void testPropertyElement() {
 185         testCommon(LineNumberApp.Pages.mainPage.name(), null, false, false);
 186         new Waiter(new Timeout("", WAITER_TIMEOUT)).ensureValue(true, new State<Boolean>() {
 187             @Override
 188             public Boolean reached() {
 189                 return LineNumberApp.propertyElementMatrix.length == LineNumberApp.propertyElement.size();
 190             }
 191         });
 192         for (int i = 0; i < LineNumberApp.propertyElementMatrix.length; i++) {
 193             Assert.assertEquals(LineNumberApp.propertyElementMatrix[i], LineNumberApp.propertyElement.get(i));
 194         }
 195     }
 196 
 197     /**
 198      * testing LoadListener#beginScriptElement
 199      */
 200     @Test
 201     public void testScriptElement() {
 202         testCommon(LineNumberApp.Pages.mainPage.name(), null, false, false);
 203         new Waiter(new Timeout("", WAITER_TIMEOUT)).ensureValue(true, new State<Boolean>() {
 204             @Override
 205             public Boolean reached() {
 206                 return LineNumberApp.propertyElementMatrix.length == LineNumberApp.propertyElement.size();
 207             }
 208         });
 209         for (int i = 0; i < LineNumberApp.propertyElementMatrix.length; i++) {
 210             Assert.assertEquals(LineNumberApp.propertyElementMatrix[i], LineNumberApp.propertyElement.get(i));
 211         }
 212     }
 213 
 214     /**
 215      * testing LoadListener#beginDefineElement
 216      */
 217     @Test
 218     public void testDefineElement() {
 219         testCommon(LineNumberApp.Pages.mainPage.name(), null, false, false);
 220         new Waiter(new Timeout("", WAITER_TIMEOUT)).ensureValue(true, new State<Boolean>() {
 221             @Override
 222             public Boolean reached() {
 223                 return LineNumberApp.defineElementMatrix.length == LineNumberApp.defineElement.size();
 224             }
 225         });
 226         for (int i = 0; i < LineNumberApp.defineElementMatrix.length; i++) {
 227             Assert.assertEquals(LineNumberApp.defineElementMatrix[i], LineNumberApp.defineElement.get(i));
 228         }
 229     }
 230 
 231     /**
 232      * testing LoadListener#readInternalAttribute
 233      */
 234     @Test
 235     public void testReadInternalProperty() {
 236         testCommon(LineNumberApp.Pages.mainPage.name(), null, false, false);
 237         new Waiter(new Timeout("", WAITER_TIMEOUT)).ensureValue(true, new State<Boolean>() {
 238             @Override
 239             public Boolean reached() {
 240                 return LineNumberApp.readInternalAttributeMatrix.length == LineNumberApp.readInternalAttribute.size();
 241             }
 242         });
 243         for (int i = 0; i < LineNumberApp.readInternalAttributeMatrix.length; i++) {
 244             Assert.assertEquals(LineNumberApp.readInternalAttributeMatrix[i], LineNumberApp.readInternalAttribute.get(i));
 245         }
 246     }
 247 
 248     /**
 249      * testing LoadListener#readPropertyAttribute
 250      */
 251     @Test
 252     public void testReadPropertyAttribute() {
 253         testCommon(LineNumberApp.Pages.mainPage.name(), null, false, false);
 254         new Waiter(new Timeout("", WAITER_TIMEOUT)).ensureValue(true, new State<Boolean>() {
 255             @Override
 256             public Boolean reached() {
 257                 return LineNumberApp.readPropertyAttributeMatrix.length == LineNumberApp.readPropertyAttribute.size();
 258             }
 259         });
 260         for (int i = 0; i < LineNumberApp.readPropertyAttributeMatrix.length; i++) {
 261             Assert.assertEquals(LineNumberApp.readPropertyAttributeMatrix[i], LineNumberApp.readPropertyAttribute.get(i));
 262         }
 263     }
 264 
 265     /**
 266      * testing LoadListener#readEventHandlerAttribute
 267      */
 268     @Test
 269     public void testReadEventHandlerAttribute() {
 270         testCommon(LineNumberApp.Pages.mainPage.name(), null, false, false);
 271         new Waiter(new Timeout("", WAITER_TIMEOUT)).ensureValue(true, new State<Boolean>() {
 272             @Override
 273             public Boolean reached() {
 274                 return LineNumberApp.readEventHandlerAttributeMatrix.length == LineNumberApp.readEventHandlerAttribute.size();
 275             }
 276         });
 277         for (int i = 0; i < LineNumberApp.readEventHandlerAttributeMatrix.length; i++) {
 278             Assert.assertEquals(LineNumberApp.readEventHandlerAttributeMatrix[i], LineNumberApp.readEventHandlerAttribute.get(i));
 279         }
 280     }
 281 
 282     /**
 283      * testing LoadListener#endElement
 284      */
 285     @Test
 286     public void testEndElement() {
 287         testCommon(LineNumberApp.Pages.mainPage.name(), null, false, false);
 288         new Waiter(new Timeout("", WAITER_TIMEOUT)).ensureValue(true, new State<Boolean>() {
 289             @Override
 290             public Boolean reached() {
 291                 return LineNumberApp.endElementMatrix.length == LineNumberApp.endElement.size();
 292             }
 293         });
 294         for (int i = 0; i < LineNumberApp.endElementMatrix.length; i++) {
 295             Assert.assertEquals(LineNumberApp.endElementMatrix[i], LineNumberApp.endElement.get(i));
 296         }
 297     }
 298 }