From 6ec01c2269e4e28c41c13dd09ff1a6dfeec6f7fb Mon Sep 17 00:00:00 2001 From: Shireesh Anjal Date: Tue, 1 Mar 2011 20:20:59 +0530 Subject: Introducing JUnit test cases --- com.gluster.storage.management.core/.classpath | 2 + .../management/core/utils/TestFileUtil.java | 84 ++++++++++++++++++++++ .../junit/core.junit.launch | 15 ++++ .../junit/test/test.txt | 1 + com.gluster.storage.management.server/.classpath | 1 - 5 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/TestFileUtil.java create mode 100644 com.gluster.storage.management.core/junit/core.junit.launch create mode 100644 com.gluster.storage.management.core/junit/test/test.txt diff --git a/com.gluster.storage.management.core/.classpath b/com.gluster.storage.management.core/.classpath index 4c62a804..b41cbcdb 100644 --- a/com.gluster.storage.management.core/.classpath +++ b/com.gluster.storage.management.core/.classpath @@ -2,6 +2,8 @@ + + diff --git a/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/TestFileUtil.java b/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/TestFileUtil.java new file mode 100644 index 00000000..8902ae8f --- /dev/null +++ b/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/TestFileUtil.java @@ -0,0 +1,84 @@ +/** + * TestFileUtil.java + * + * Copyright (c) 2011 Gluster, Inc. + * This file is part of Gluster Management Console. + * + * Gluster Management Console is free software; you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Gluster Management Console is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License + * for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * . + */ +package com.gluster.storage.management.core.utils; + +import static org.junit.Assert.assertTrue; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStreamWriter; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class TestFileUtil { + private String testFileName; + private String fileContent; + private FileUtil fileUtil; + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + testFileName = "testFileUtil.txt"; + fileContent = "Testing FileUtil class."; + fileUtil = new FileUtil(); + + BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(testFileName)); + OutputStreamWriter writer = new OutputStreamWriter(outStream); + writer.write(fileContent); + writer.close(); + outStream.close(); + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + File testFile = new File(testFileName); + testFile.delete(); + } + + /** + * Test method for {@link com.gluster.storage.management.core.utils.FileUtil#readFileAsString(java.io.File)}. + */ + @Test + public final void testReadFileAsString() { + String readContent = fileUtil.readFileAsString(new File(testFileName)); + assertTrue("File contents expected [" + fileContent + "], actual [" + readContent + "]", + readContent.equals(fileContent)); + } + + /** + * Test method for {@link com.gluster.storage.management.core.utils.FileUtil#loadResource(java.lang.String)}. + */ + @Test + public final void testLoadResource() { + InputStream inputStream = fileUtil.loadResource("test/test.txt"); + Assert.assertNotNull(inputStream); + } +} diff --git a/com.gluster.storage.management.core/junit/core.junit.launch b/com.gluster.storage.management.core/junit/core.junit.launch new file mode 100644 index 00000000..0bf6dc30 --- /dev/null +++ b/com.gluster.storage.management.core/junit/core.junit.launch @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/com.gluster.storage.management.core/junit/test/test.txt b/com.gluster.storage.management.core/junit/test/test.txt new file mode 100644 index 00000000..267ce144 --- /dev/null +++ b/com.gluster.storage.management.core/junit/test/test.txt @@ -0,0 +1 @@ +Test Resource \ No newline at end of file diff --git a/com.gluster.storage.management.server/.classpath b/com.gluster.storage.management.server/.classpath index a88ad336..59631d14 100644 --- a/com.gluster.storage.management.server/.classpath +++ b/com.gluster.storage.management.server/.classpath @@ -10,6 +10,5 @@ - -- cgit