diff options
| author | Shireesh Anjal <shireesh@gluster.com> | 2011-03-01 20:20:59 +0530 |
|---|---|---|
| committer | Shireesh Anjal <shireesh@gluster.com> | 2011-03-01 20:20:59 +0530 |
| commit | 6ec01c2269e4e28c41c13dd09ff1a6dfeec6f7fb (patch) | |
| tree | 15ec648f67ffcea0385ad94bb38222679c5d6690 | |
| parent | 66fa140102e7206758c6b46068c65eda58a2c904 (diff) | |
Introducing JUnit test cases
5 files changed, 102 insertions, 1 deletions
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 @@ <classpath> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="src" path="src"/> + <classpathentry kind="src" path="junit"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> <classpathentry kind="output" path="bin"/> </classpath> 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. <http://www.gluster.com> + * 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 + * <http://www.gnu.org/licenses/>. + */ +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 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<launchConfiguration type="org.eclipse.jdt.junit.launchconfig"> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> +<listEntry value="/com.gluster.storage.management.core"/> +</listAttribute> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> +<listEntry value="4"/> +</listAttribute> +<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=com.gluster.storage.management.core"/> +<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> +<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> +<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/> +<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/> +<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="com.gluster.storage.management.core"/> +</launchConfiguration> 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 @@ <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/> <classpathentry combineaccessrules="false" kind="src" path="/com.gluster.storage.management.core"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> - <classpathentry kind="lib" path="WebContent/WEB-INF/classes"/> <classpathentry kind="output" path="WebContent/WEB-INF/classes"/> </classpath> |
