View Javadoc

1   /**
2    * Copyright 2008 WebPhotos
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.webphotos;
17  
18  import java.io.File;
19  import java.util.HashMap;
20  import java.util.Map;
21  import net.sf.webphotos.gui.util.WebPhotosDelegate;
22  import net.sf.webphotos.util.Util;
23  import org.junit.AfterClass;
24  import org.junit.Before;
25  import org.junit.BeforeClass;
26  import org.junit.Ignore;
27  import org.junit.Test;
28  
29  /**
30   *
31   * @author Guilherme
32   */
33  public class WebPhotosTest {
34      
35      public static final WebPhotosDelegate WEB_PHOTOS_DELEGATE = net.sf.webphotos.gui.util.uispec4j.WebPhotosDelegate.getWebPhotosDelegate();
36      //public static final WebPhotosDelegate WEB_PHOTOS_DELEGATE = net.sf.webphotos.gui.util.fest.WebPhotosDelegate.getWebPhotosDelegate();
37  
38      /**
39       *
40       * @throws Exception
41       */
42      @BeforeClass
43      public static void setUpClass() throws Exception {
44          WEB_PHOTOS_DELEGATE.setUpClass();
45      }
46  
47      /**
48       *
49       * @throws Exception
50       */
51      @AfterClass
52      public static void tearDownClass() throws Exception {
53          WEB_PHOTOS_DELEGATE.tearDownClass();
54      }
55  
56      /**
57       *
58       */
59      @Before
60      public void setUp() {
61          WEB_PHOTOS_DELEGATE.setUp();
62      }
63  
64      /**
65       * Creating a Category.
66       */
67      @Test
68      public void testAddCategory() {
69          System.out.println("Add Category");
70          WEB_PHOTOS_DELEGATE.validateMainWindowIsPresent();
71          WEB_PHOTOS_DELEGATE.fillModalWithText("buttonAddCategory", "Cat", "Geral");
72  
73          WEB_PHOTOS_DELEGATE.checkComboBoxHasText("lstCategoriasPesquisa", "Geral");
74      }
75  
76      /**
77       * Creating a Credit.
78       */
79      @Test
80      public void testAddCredits() {
81          System.out.println("Add Credits");
82          WEB_PHOTOS_DELEGATE.validateMainWindowIsPresent();
83          WEB_PHOTOS_DELEGATE.fillModalWithText("buttonAddCredits", "Cred", "Divulgacao");
84  
85          WEB_PHOTOS_DELEGATE.checkComboBoxHasText("lstCreditos", "Divulgacao");
86      }
87  
88      @Test
89      public void testCreateAlbumWithPhotos() {
90          System.out.println("Create Album With Photos");
91          WEB_PHOTOS_DELEGATE.validateMainWindowIsPresent();
92  
93          final String[] fileNames = new String[2];
94          fileNames[0] = Util.getProperty("user.dir") + File.separator + ".." + File.separator + "src" + File.separator + "main" + File.separator + "resources" + File.separator + "Originals" + File.separator + "GPL.jpg";
95          fileNames[1] = Util.getProperty("user.dir") + File.separator + ".." + File.separator + "src" + File.separator + "main" + File.separator + "resources" + File.separator + "Originals" + File.separator + "ZS-GPL.jpg";
96  
97          /**
98           * Primeira tentativa - Comportamento esperado: duas fotos na lista
99           */
100         System.out.println("Adding Photos - First try");
101         WEB_PHOTOS_DELEGATE.addPhotosToAlbumAndCheck(fileNames, "btNovo", Util.getFolder("diretorioAdicionarFotos"), "Criando novo \u00e1lbum - Selecione os arquivos");
102         checkNewAlbumButton();
103 
104         /**
105          * Segunda tentativa - com as mesmas fotos - Comportamento esperado:
106          * duas fotos ignoradas
107          */
108         System.out.println("Adding Photos - Second try");
109         WEB_PHOTOS_DELEGATE.addPhotosToAlbumAndCheck(fileNames, "buttonAddPhotos", new File(fileNames[0]).getParentFile(), "Adicionar fotos no \u00e1lbum");
110         checkNewAlbumButton();
111         
112         final Map<String, String[]> photoData = new HashMap<String, String[]>();
113         for (int i = 0; i < fileNames.length; i++) {
114             String fileName = fileNames[i];
115             photoData.put(fileName, new String[] { "Original Name: " + fileName, "Divulgacao" });
116         }
117         WEB_PHOTOS_DELEGATE.fillAlbumForm("First Test - Title", "First Test - Description", "Geral", photoData);
118         
119         WEB_PHOTOS_DELEGATE.validateMainWindowIsPresent();
120         
121         WEB_PHOTOS_DELEGATE.checkNewAlbum();
122     }
123 
124     @Ignore
125     public void testAddPhotos() {
126         System.out.println("Add Photos");
127     }
128 
129     private void checkNewAlbumButton() throws RuntimeException {
130         WEB_PHOTOS_DELEGATE.checkIsButtonEnabled("btNovo");
131         WEB_PHOTOS_DELEGATE.checkButtonHasText("btNovo", "Finalizar");
132     }
133 }