]> source.dussan.org Git - archiva.git/blob
d9d0da10b7f0448fae72bf4afd94eb8d7bad5ba3
[archiva.git] /
1 package org.apache.archiva.web.test;
2
3 /*
4  * Licensed to the Apache Software Foundation (ASF) under one
5  * or more contributor license agreements.  See the NOTICE file
6  * distributed with this work for additional information
7  * regarding copyright ownership.  The ASF licenses this file
8  * to you under the Apache License, Version 2.0 (the
9  * "License"); you may not use this file except in compliance
10  * with the License.  You may obtain a copy of the License at
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied.  See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  */
21
22 import org.apache.archiva.web.test.parent.AbstractArchivaTest;
23 import org.junit.Assert;
24 import org.junit.Test;
25 import org.openqa.selenium.By;
26 import org.openqa.selenium.JavascriptExecutor;
27 import org.openqa.selenium.WebElement;
28 import org.openqa.selenium.htmlunit.HtmlUnitDriver;
29 import org.openqa.selenium.support.ui.ExpectedCondition;
30 import org.openqa.selenium.support.ui.ExpectedConditions;
31 import org.openqa.selenium.support.ui.WebDriverWait;
32
33 import java.util.List;
34
35 /**
36  * Based on LoginTest of Emmanuel Venisse test.
37  *
38  * @author skygo
39  *
40  */
41
42
43 public class RepositoryAdminTest
44     extends AbstractArchivaTest
45 {
46
47     @Test
48     public void testManagedRepository()
49     {
50         login( getAdminUsername(), getAdminPassword() );
51         WebDriverWait wait = new WebDriverWait(getWebDriver(), 20);
52         WebElement el;
53         el = wait.until(ExpectedConditions.elementToBeClickable(By.id("menu-repositories-list-a")));
54         tryClick( el,  ExpectedConditions.presenceOfElementLocated( By.id( "managed-repositories-view-a" ) ),
55             "Managed Repositories not activated");
56         el = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@href='#remote-repositories-content']")));
57         tryClick(el,ExpectedConditions.visibilityOfElementLocated(By.id("remote-repositories-view-a")),
58             "Remote Repositories View not available");
59         el = wait.until(ExpectedConditions.elementToBeClickable( By.xpath("//a[@href='#remote-repository-edit']") ));
60         el = tryClick(el, ExpectedConditions.visibilityOfElementLocated(By.id("remote-repository-save-button")),
61             "Repository Save Button not available");
62         
63         setFieldValue( "id", "myrepoid" );        
64         setFieldValue( "name", "My repo name" );        
65         setFieldValue( "url", "http://www.repo.org" );
66         
67         el.click();
68         wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("remote-repositories-view-a")));
69         el = wait.until(ExpectedConditions.elementToBeClickable( By.id("menu-proxy-connectors-list-a") ));
70         el.click();
71         wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("proxy-connectors-view-tabs-a-network-proxies-grid")));
72         wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("main-content"), "Proxy Connectors"));
73         // proxy connect
74         wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("proxy-connectors-view"), "central" ));
75         assertTextNotPresent( "myrepoid" );
76         el = wait.until(ExpectedConditions.elementToBeClickable( By.id("proxy-connectors-view-tabs-a-edit") ));
77         el.click();
78         el = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("proxy-connector-btn-save")));
79         selectValue( "sourceRepoId", "internal" );
80         // Workaround
81         // TODO: Check after upgrade of htmlunit, bootstrap or jquery
82         // TODO: Check whats wrong here
83         ( (JavascriptExecutor) getWebDriver() ).executeScript( "$('#targetRepoId').show();" );
84         // End of Workaround
85         wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("targetRepoId")));
86         selectValue( "targetRepoId", "myrepoid" );
87         el.click();
88         wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("user-messages"),"ProxyConnector added"));
89         wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("proxy-connectors-view"), "central" ));
90         wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("proxy-connectors-view"), "myrepoid" ));
91         clickLinkWithXPath( "//i[contains(@class,'icon-resize-vertical')]//ancestor::a");
92         // This is needed here for HTMLUnit Tests. Currently do not know why, wait is not working for the
93         // list entries down
94         waitPage();
95         el = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("proxy-connector-edit-order-div")));
96         assertTextPresent( "internal" );
97         List<WebElement> repos = el.findElements(By.xpath("./div"));
98         Assert.assertTrue("First repo is myrepo", repos.get(0).getText().contains("myrepoid"));
99         Assert.assertTrue("Second repo is central", repos.get(1).getText().contains("central"));
100
101         // works until this point
102         /*getSelenium().mouseDown( "xpath=//div[@id='proxy-connector-edit-order-div']/div[1]" );
103         getSelenium().mouseMove( "xpath=//div[@id='proxy-connector-edit-order-div']/div[2]" );
104         getSelenium().mouseUp( "xpath=//div[@id='proxy-connector-edit-order-div']/div[last()]" );
105         Assert.assertTrue( "Second repo is myrepo", getSelenium().getText("xpath=//div[@id='proxy-connector-edit-order-div']/div[2]" ).contains( "myrepoid" ));
106         Assert.assertTrue( "First repo is central", getSelenium().getText("xpath=//div[@id='proxy-connector-edit-order-div']/div[1]" ).contains( "central" ));
107         */
108     }
109     
110 }