@@ -0,0 +1,2920 @@
+/**%0A * Licensed to the Apache Software Foundation (ASF) under one%0A * or more contributor license agreements. See the NOTICE file%0A * distributed with this work for additional information%0A * regarding copyright ownership. The ASF licenses this file%0A * to you under the Apache License, Version 2.0 (the%0A * %22License%22); you may not use this file except in compliance%0A * with the License. You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing,%0A * software distributed under the License is distributed on an%0A * %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY%0A * KIND, either express or implied. See the License for the%0A * specific language governing permissions and limitations under the License.%0A */%0Apackage org.apache.shindig.gadgets;%0A%0Aimport junit.framework.TestCase;%0A%0Aimport java.io.BufferedWriter;%0Aimport java.io.File;%0Aimport java.io.FileWriter;%0Aimport java.net.URI;%0A%0Apublic class CachedContentFetcherTest extends TestCase %7B%0A  private RemoteContentFetcher fetcher%0A      = new CachedContentFetcher(new BasicRemoteContentFetcher(Integer.MAX_VALUE));%0A%0A  public void testFetch() throws Exception %7B%0A    String content = %22Hello, world!%22;%0A    File temp = File.createTempFile(this.getName(), %22.txt%22);%0A    temp.deleteOnExit();%0A    BufferedWriter out = new BufferedWriter(new FileWriter(temp));%0A    out.write(content);%0A    out.close();%0A    RemoteContentRequest request = new RemoteContentRequest(temp.toURI());%0A    RemoteContent response = fetcher.fetch(request);%0A    assertEquals(RemoteContent.SC_OK, response.getHttpStatusCode());%0A    assertEquals(content, response.getResponseAsString());%0A    temp.delete();%0A    response = fetcher.fetch(request);%0A    assertEquals(RemoteContent.SC_OK, response.getHttpStatusCode());%0A    assertEquals(content, response.getResponseAsString());%0A  %7D%0A%0A  public void testDontCache() throws Exception %7B%0A    String content = %22Hello, world!%22;%0A    File temp = File.createTempFile(this.getName(), %22.txt%22);%0A    temp.deleteOnExit();%0A    BufferedWriter out = new BufferedWriter(new FileWriter(temp));%0A    out.write(content);%0A    out.close();%0A    RemoteContentRequest request = RemoteContentRequest.getRequest(temp.toURI(), true);%0A    RemoteContent response = fetcher.fetch(request);%0A    assertEquals(RemoteContent.SC_OK, response.getHttpStatusCode());%0A    assertEquals(content, response.getResponseAsString());%0A    temp.delete();%0A    response = fetcher.fetch(request);%0A    assertEquals(RemoteContent.SC_NOT_FOUND, response.getHttpStatusCode());%0A  %7D%0A%0A%0A  public void testNotExists() throws Exception %7B%0A    RemoteContentRequest request%0A        = new RemoteContentRequest(new URI(%22file:///does/not/exist%22));%0A    RemoteContent response = fetcher.fetch(request);%0A    assertEquals(RemoteContent.SC_NOT_FOUND, response.getHttpStatusCode());%0A  %7D%0A%0A  // TODO test caching of POST requests, headers, options, etc.%0A%7D%0A

Test that nocache is honored by CachedContentFetcher