1 package org.apache.archiva.web.test;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
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;
33 import java.util.List;
36 * Based on LoginTest of Emmanuel Venisse test.
43 public class RepositoryAdminTest
44 extends AbstractArchivaTest
48 public void testManagedRepository()
50 login( getAdminUsername(), getAdminPassword() );
51 WebDriverWait wait = new WebDriverWait(getWebDriver(), 20);
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");
63 setFieldValue( "id", "myrepoid" );
64 setFieldValue( "name", "My repo name" );
65 setFieldValue( "url", "http://www.repo.org" );
68 wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("remote-repositories-view-a")));
69 el = wait.until(ExpectedConditions.elementToBeClickable( By.id("menu-proxy-connectors-list-a") ));
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"));
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") ));
78 el = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("proxy-connector-btn-save")));
79 selectValue( "sourceRepoId", "internal" );
81 // TODO: Check after upgrade of htmlunit, bootstrap or jquery
82 // TODO: Check whats wrong here
83 ( (JavascriptExecutor) getWebDriver() ).executeScript( "$('#targetRepoId').show();" );
85 wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("targetRepoId")));
86 selectValue( "targetRepoId", "myrepoid" );
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
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"));
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" ));