01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.tools.util;
19:
20: import java.io.File;
21: import java.io.IOException;
22:
23: import org.junit.Assert;
24: import org.junit.Test;
25:
26: public class FileWriterUtilTest extends Assert {
27:
28: private void cleanDir(File dir) {
29: try {
30: for (File fl : dir.listFiles()) {
31: if (fl.isDirectory()) {
32: cleanDir(fl);
33: } else {
34: fl.delete();
35: }
36: }
37: } catch (Exception ex) {
38: //ignore
39: }
40: dir.delete();
41: }
42:
43: @Test
44: public void testGetFile() throws Exception {
45: FileWriterUtil fileWriter = null;
46: String tmpDir = System.getProperty("java.io.tmpdir");
47: File targetDir = new File(tmpDir + File.separator + "target");
48: try {
49: targetDir.mkdirs();
50: fileWriter = new FileWriterUtil(targetDir.getAbsolutePath());
51: fileWriter.getWriter("com.iona.test", "A.java");
52: String packPath = "/com/iona/test/A.java".replace('/',
53: File.separatorChar);
54: String path = targetDir.getAbsolutePath() + packPath;
55: assertNotNull(new File(path).getName());
56: } catch (IOException e) {
57: // TODO Auto-generated catch block
58: e.printStackTrace();
59: } finally {
60: cleanDir(targetDir);
61: }
62:
63: }
64:
65: @Test
66: public void testGetWriter() throws Exception {
67: FileWriterUtil fileWriter = null;
68: String tmpDir = System.getProperty("java.io.tmpdir");
69: File targetDir = new File(tmpDir + File.separator + "target");
70:
71: try {
72: targetDir.mkdirs();
73: fileWriter = new FileWriterUtil(targetDir.getAbsolutePath());
74: assertNotNull(fileWriter.getWriter("com.iona.test.SAMPLE",
75: "A.java"));
76: } catch (IOException e) {
77: // TODO Auto-generated catch block
78: e.printStackTrace();
79: } finally {
80: cleanDir(targetDir);
81: }
82: }
83:
84: }
|