/**
 * Copyright 2008 Matthew Hillsdon
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.hillsdon.reviki.webtests;

import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlPage;


public class TestInterWikiLinks extends WebTestSupport {

  /**
   * Add an interwiki link mapping, create a link, make sure it points where we expect.
   */
  public void test() throws Exception {
    editWikiPage("ConfigInterWikiLinks", "foo http://www.example.com/Wiki?%s", "", "Link mapping.", null);
    HtmlPage page = editWikiPage(uniqueWikiPageName("InterWikiLinkTest"), "foo:1234", "", "Add inter-wiki link.", true);
    HtmlAnchor link = page.getAnchorByHref("http://www.example.com/Wiki?1234");
    assertEquals("foo:1234", link.asText());
  }

}

@@ -633,16 +633,45 @@
 tests;%0A%0A
+import java.io.IOException;%0A%0A
 import c
@@ -716,16 +716,16 @@
 Anchor;%0A
-
 import c
@@ -946,16 +946,20 @@
 oid test
+Link
 () throw
@@ -1189,16 +1189,17 @@
 iki link
+s
 .%22, true
@@ -1330,11 +1330,1163 @@
 ));%0A  %7D%0A
+  %0A  /**%0A   * Add many interiki links to a page and test the render time.%0A   */%0A  public void testRenderTiming() throws Exception %7B%0A    editWikiPage(%22ConfigInterWikiLinksTiming%22, %22foo http://www.example.com/Wiki?%25s%22, %22%22, %22Link mapping.%22, null);%0A    String content = %22%22;%0A    for (int i=0; i%3C100; i++) %7B%0A      content += %22foo:%22 + i + %22 %22;%0A    %7D%0A    String pageName = uniqueWikiPageName(%22ConfigInterWikiLinkTest%22);%0A    editWikiPage(pageName, content, %22%22, %22Add inter-wiki links.%22, true);%0A%0A    assertTrue(wikiPageFetchTime(pageName, 3) %3C 1000);%0A  %7D%0A%0A  /**%0A   * Fetch a wiki page several times and return the shortest elapsed time.%0A   */%0A  public long wikiPageFetchTime(String pageName, int iterations) throws IOException %7B%0A    long minElapsedTime = -1;%0A%0A    for (int i=0; i%3Citerations; i++) %7B%0A      long startTime = System.currentTimeMillis();%0A      getWikiPage(pageName);%0A      long endTime = System.currentTimeMillis();%0A%0A      long elapsedTime = endTime - startTime;%0A      if (minElapsedTime == -1 %7C%7C elapsedTime %3C minElapsedTime) %7B%0A        minElapsedTime = elapsedTime;%0A      %7D%0A    %7D%0A    System.out.println(minElapsedTime);%0A    return minElapsedTime;%0A  %7D
 %0A%7D%0A

Add a timing test for rendering a page containing interwiki links.