01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.ivy.ant;
19:
20: import java.io.File;
21:
22: import junit.framework.TestCase;
23:
24: import org.apache.tools.ant.BuildException;
25: import org.apache.tools.ant.Project;
26:
27: public class IvyCleanCacheTest extends TestCase {
28: private IvyCleanCache cleanCache;
29: private File cacheDir;
30: private File repoCache2;
31: private File repoCache;
32: private File resolutionCache;
33:
34: protected void setUp() throws Exception {
35: Project p = new Project();
36: cacheDir = new File("build/cache");
37: p.setProperty("cache", cacheDir.getAbsolutePath());
38: cleanCache = new IvyCleanCache();
39: cleanCache.setProject(p);
40: IvyAntSettings settings = new IvyAntSettings();
41: settings.setProject(p);
42: settings.setUrl(IvyCleanCacheTest.class.getResource(
43: "ivysettings-cleancache.xml").toExternalForm());
44: settings.perform();
45:
46: resolutionCache = new File(cacheDir, "resolution");
47: repoCache = new File(cacheDir, "repository");
48: repoCache2 = new File(cacheDir, "repository2");
49: resolutionCache.mkdirs();
50: repoCache.mkdirs();
51: repoCache2.mkdirs();
52: }
53:
54: public void testCleanAll() throws Exception {
55: cleanCache.perform();
56: assertFalse(resolutionCache.exists());
57: assertFalse(repoCache.exists());
58: assertFalse(repoCache2.exists());
59: }
60:
61: public void testResolutionOnly() throws Exception {
62: cleanCache.setCache(IvyCleanCache.NONE);
63: cleanCache.perform();
64: assertFalse(resolutionCache.exists());
65: assertTrue(repoCache.exists());
66: assertTrue(repoCache2.exists());
67: }
68:
69: public void testRepositoryOnly() throws Exception {
70: cleanCache.setResolution(false);
71: cleanCache.perform();
72: assertTrue(resolutionCache.exists());
73: assertFalse(repoCache.exists());
74: assertFalse(repoCache2.exists());
75: }
76:
77: public void testOneRepositoryOnly() throws Exception {
78: cleanCache.setResolution(false);
79: cleanCache.setCache("mycache");
80: cleanCache.perform();
81: assertTrue(resolutionCache.exists());
82: assertFalse(repoCache.exists());
83: assertTrue(repoCache2.exists());
84: }
85:
86: public void testUnknownCache() throws Exception {
87: cleanCache.setResolution(false);
88: cleanCache.setCache("yourcache");
89: try {
90: cleanCache.perform();
91: fail("clean cache should have raised an exception with unkown cache");
92: } catch (BuildException e) {
93: assertTrue(e.getMessage().indexOf("yourcache") != -1);
94: }
95: }
96: }
|