From 7cc7fd2ceaa2c2eb73b857e996ff5463c6097aa9 Mon Sep 17 00:00:00 2001 From: Jacques Le Roux Date: Mon, 12 Nov 2018 10:57:27 +0000 Subject: [PATCH] Improved: Allow unit tests to be written in Groovy (OFBIZ-10611) Since OFBIZ-9996 it is possible to write integration tests in Groovy, meaning test that depend on the dispatcher and the delegator. It would be nice if the unit tests could be written in Groovy too. The major benefit of writing tests in Groovy is that you create inputs and expected outputs more easily with objects literals. For example the following java code: Map input = new HashMap<>(); input.put("foo", 42); input.put("bar", 37); can be rewritten in Groovy like this: def input = [foo: 42, bar: 37] Thanks: Mathieu Lirzin git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1846393 13f79535-47bb-0310-9956-ffa450edef68 --- build.gradle | 7 +++++++ .../apache/ofbiz/base/util}/FileUtilTests.groovy | 16 +++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) rename framework/base/{groovyScript/test => src/test/groovy/org/apache/ofbiz/base/util}/FileUtilTests.groovy (84%) diff --git a/build.gradle b/build.gradle index bebd73e0ae..4643f6b1c0 100644 --- a/build.gradle +++ b/build.gradle @@ -34,6 +34,7 @@ buildscript { } } apply plugin: 'java' +apply plugin: 'groovy' apply plugin: 'eclipse' apply plugin: 'maven-publish' apply plugin: "at.bxm.svntools" @@ -233,6 +234,9 @@ sourceSets { srcDirs = getDirectoryInActiveComponentsIfExists('src/main/java') exclude excludedJavaSources } + groovy { + srcDirs = getDirectoryInActiveComponentsIfExists('src/main/groovy') + } resources { srcDirs = getDirectoryInActiveComponentsIfExists('src/main/java') srcDirs += getDirectoryInActiveComponentsIfExists('config') @@ -256,6 +260,9 @@ sourceSets { java { srcDirs = getDirectoryInActiveComponentsIfExists('src/test/java') } + groovy { + srcDirs = getDirectoryInActiveComponentsIfExists('src/test/groovy') + } resources { srcDirs = getDirectoryInActiveComponentsIfExists('src/test/java') } diff --git a/framework/base/groovyScript/test/FileUtilTests.groovy b/framework/base/src/test/groovy/org/apache/ofbiz/base/util/FileUtilTests.groovy similarity index 84% rename from framework/base/groovyScript/test/FileUtilTests.groovy rename to framework/base/src/test/groovy/org/apache/ofbiz/base/util/FileUtilTests.groovy index 9a7d0af4c3..ff39594f05 100644 --- a/framework/base/groovyScript/test/FileUtilTests.groovy +++ b/framework/base/src/test/groovy/org/apache/ofbiz/base/util/FileUtilTests.groovy @@ -1,4 +1,4 @@ -/******************************************************************************* +/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -15,20 +15,18 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. - *******************************************************************************/ - + */ +package org.apache.ofbiz.base.util; import org.apache.commons.io.FileUtils -import org.apache.ofbiz.base.util.FileUtil -import org.apache.ofbiz.base.util.UtilProperties -import org.apache.ofbiz.testtools.GroovyScriptTestCase - -class FileUtilTests extends GroovyScriptTestCase { +import org.junit.Test +public class FileUtilTests { /** * Test FileUtil zipFileStream and unzipFileToFolder methods, using README.adoc */ - void testZipReadme() { + @Test + void zipReadme() { String zipFilePath = UtilProperties.getPropertyValue("general", "http.upload.tmprepository", "runtime/tmp") String zipName = 'README.adoc.zip' String fileName = 'README.adoc'