]> source.dussan.org Git - archiva.git/blob
7b034aa490167180c49532b702ab80fc89b7408a
[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.xpath("//table[@id='remote-repositories-table']//td[contains(text(),'central')]")),
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         tryClick(By.id("menu-proxy-connectors-list-a"),
70             ExpectedConditions.visibilityOfElementLocated(By.id("proxy-connectors-view-tabs-a-network-proxies-grid")),
71             "Network proxies not available",
72             3,10
73             );
74         wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("main-content"), "Proxy Connectors"));
75         // proxy connect
76         wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("proxy-connectors-view"), "central" ));
77         assertTextNotPresent( "myrepoid" );
78         el = wait.until(ExpectedConditions.elementToBeClickable( By.id("proxy-connectors-view-tabs-a-edit") ));
79         el.click();
80         el = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("proxy-connector-btn-save")));
81         selectValue( "sourceRepoId", "internal" );
82         // Workaround
83         // TODO: Check after upgrade of htmlunit, bootstrap or jquery
84         // TODO: Check whats wrong here
85         ( (JavascriptExecutor) getWebDriver() ).executeScript( "$('#targetRepoId').show();" );
86         // End of Workaround
87         wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("targetRepoId")));
88         selectValue( "targetRepoId", "myrepoid" );
89         el.click();
90         wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("user-messages"),"ProxyConnector added"));
91         wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("proxy-connectors-view"), "central" ));
92         wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("proxy-connectors-view"), "myrepoid" ));
93         clickLinkWithXPath( "//i[contains(@class,'icon-resize-vertical')]//ancestor::a");
94         // This is needed here for HTMLUnit Tests. Currently do not know why, wait is not working for the
95         // list entries down
96         waitPage();
97         el = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("proxy-connector-edit-order-div")));
98         assertTextPresent( "internal" );
99         List<WebElement> repos = el.findElements(By.xpath("./div"));
100         Assert.assertTrue("First repo is myrepo", repos.get(0).getText().contains("myrepoid"));
101         Assert.assertTrue("Second repo is central", repos.get(1).getText().contains("central"));
102
103         // works until this point
104         /*getSelenium().mouseDown( "xpath=//div[@id='proxy-connector-edit-order-div']/div[1]" );
105         getSelenium().mouseMove( "xpath=//div[@id='proxy-connector-edit-order-div']/div[2]" );
106         getSelenium().mouseUp( "xpath=//div[@id='proxy-connector-edit-order-div']/div[last()]" );
107         Assert.assertTrue( "Second repo is myrepo", getSelenium().getText("xpath=//div[@id='proxy-connector-edit-order-div']/div[2]" ).contains( "myrepoid" ));
108         Assert.assertTrue( "First repo is central", getSelenium().getText("xpath=//div[@id='proxy-connector-edit-order-div']/div[1]" ).contains( "central" ));
109         */
110     }
111     
112 }