IDEMPIERE-4289 Implement Support for JUnit5 Unit Testing (#53)

Add JUnit5 unit testing project org.idempiere.test
Add tycho sure fire test (skip by default)
This commit is contained in:
hengsin 2020-05-12 23:17:36 +08:00 committed by GitHub
parent 9d050a96b3
commit 4c03fef8a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 1952 additions and 0 deletions

View File

@ -396,6 +396,11 @@
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven.dependency.version}</version>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho.version}</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.idempiere.test</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

View File

@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=11

View File

@ -0,0 +1,3 @@
eclipse.preferences.version=1
pluginProject.extensions=false
resolve.requirebundle=false

View File

@ -0,0 +1,21 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: iDempiere Unit Testing
Bundle-SymbolicName: org.idempiere.test
Bundle-Version: 7.1.0.qualifier
Bundle-Vendor: iDempiere
Automatic-Module-Name: org.idempiere.test
Bundle-RequiredExecutionEnvironment: JavaSE-11
Import-Package: org.junit.jupiter.api;version="5.6.0",
org.junit.jupiter.api.condition;version="5.6.0",
org.junit.jupiter.api.extension;version="5.6.0",
org.junit.jupiter.api.extension.support;version="5.6.0",
org.junit.jupiter.api.function;version="5.6.0",
org.junit.jupiter.api.io;version="5.6.0",
org.junit.jupiter.api.parallel;version="5.6.0",
org.junit.jupiter.params;version="5.6.0",
org.junit.jupiter.params.aggregator;version="5.6.0",
org.junit.jupiter.params.converter;version="5.6.0",
org.junit.jupiter.params.provider;version="5.6.0",
org.junit.jupiter.params.support;version="5.6.0"
Require-Bundle: org.adempiere.base;bundle-version="7.1.0"

View File

@ -0,0 +1,4 @@
source.. = src/
output.. = target/classes/
bin.includes = META-INF/,\
.

View File

@ -0,0 +1,568 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.pde.ui.JunitLaunchConfig">
<booleanAttribute key="append.args" value="true"/>
<stringAttribute key="application" value="org.eclipse.pde.junit.runtime.coretestapplication"/>
<booleanAttribute key="askclear" value="false"/>
<booleanAttribute key="automaticAdd" value="true"/>
<booleanAttribute key="automaticValidate" value="true"/>
<stringAttribute key="bootstrap" value=""/>
<stringAttribute key="checked" value="[NONE]"/>
<booleanAttribute key="clearConfig" value="true"/>
<booleanAttribute key="clearws" value="true"/>
<booleanAttribute key="clearwslog" value="false"/>
<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/pde-junit"/>
<booleanAttribute key="default" value="false"/>
<setAttribute key="deselected_workspace_bundles">
<setEntry value="org.adempiere.replication"/>
<setEntry value="org.adempiere.replication.server"/>
<setEntry value="org.adempiere.server"/>
<setEntry value="org.adempiere.ui.zk"/>
<setEntry value="org.idempiere.felix.webconsole"/>
<setEntry value="org.idempiere.javadoc"/>
<setEntry value="org.idempiere.webservices"/>
<setEntry value="org.idempiere.zk.extra"/>
</setAttribute>
<booleanAttribute key="includeOptional" value="true"/>
<stringAttribute key="location" value="${workspace_loc}/../junit-workspace"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/org.idempiere.test"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=org.idempiere.test"/>
<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.junit5"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.idempiere.test"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea"/>
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc}"/>
<stringAttribute key="pde.version" value="3.3"/>
<stringAttribute key="product" value="org.adempiere.server.server_product"/>
<booleanAttribute key="run_in_ui_thread" value="true"/>
<setAttribute key="selected_target_bundles">
<setEntry value="bcmail@default:default"/>
<setEntry value="bcpkix@default:default"/>
<setEntry value="bcprov@default:default"/>
<setEntry value="bctsp@default:default"/>
<setEntry value="ca.odell.glazedlists@default:default"/>
<setEntry value="ch.qos.logback.classic@default:default"/>
<setEntry value="ch.qos.logback.core@default:default"/>
<setEntry value="com.cronutils@default:default"/>
<setEntry value="com.diffplug.osgi.extension.sun.misc@default:false"/>
<setEntry value="com.fasterxml.jackson.core.jackson-annotations@default:default"/>
<setEntry value="com.fasterxml.jackson.core.jackson-core@default:default"/>
<setEntry value="com.fasterxml.jackson.core.jackson-databind@default:default"/>
<setEntry value="com.fasterxml.jackson.dataformat.jackson-dataformat-xml@default:default"/>
<setEntry value="com.fasterxml.jackson.datatype.jackson-datatype-guava@default:default"/>
<setEntry value="com.fasterxml.jackson.datatype.jackson-datatype-joda@default:default"/>
<setEntry value="com.fasterxml.jackson.datatype.jackson-datatype-json-org@default:default"/>
<setEntry value="com.fasterxml.jackson.jaxrs.jackson-jaxrs-base@default:default"/>
<setEntry value="com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider@default:default"/>
<setEntry value="com.fasterxml.jackson.jaxrs.jackson-jaxrs-xml-provider@default:default"/>
<setEntry value="com.fasterxml.jackson.module.jackson-module-jaxb-annotations@default:default"/>
<setEntry value="com.fasterxml.jackson.module.jackson-module-jsonSchema@default:default"/>
<setEntry value="com.fasterxml.woodstox.woodstox-core@default:default"/>
<setEntry value="com.github.relaxng.Datatype@default:default"/>
<setEntry value="com.google.flogger.systembackend@default:default"/>
<setEntry value="com.google.flogger.testing@default:default"/>
<setEntry value="com.google.flogger@default:default"/>
<setEntry value="com.google.gson@default:default"/>
<setEntry value="com.google.guava@default:default"/>
<setEntry value="com.google.zxing.core@default:default"/>
<setEntry value="com.graphql.java.dataloader@default:default"/>
<setEntry value="com.ibm.icu*63.1.0@default:default"/>
<setEntry value="com.ibm.icu*64.2.0.v20190507-1337@default:default"/>
<setEntry value="com.itextpdf@default:default"/>
<setEntry value="com.jaspersoft.studio.bundles.barbecue@default:default"/>
<setEntry value="com.jaspersoft.studio.bundles.itext@default:default"/>
<setEntry value="com.jcraft.jsch@default:default"/>
<setEntry value="com.konghq.unirest-java@default:default"/>
<setEntry value="com.sun.activation.jakarta.activation@default:default"/>
<setEntry value="com.sun.el@default:default"/>
<setEntry value="com.sun.grid.drmaa@default:default"/>
<setEntry value="com.sun.istack.commons-runtime@default:default"/>
<setEntry value="com.sun.jna.platform@default:default"/>
<setEntry value="com.sun.jna@default:default"/>
<setEntry value="com.sun.mail.gimap@default:default"/>
<setEntry value="com.sun.mail.imap@default:default"/>
<setEntry value="com.sun.mail.jakarta.mail@default:default"/>
<setEntry value="com.sun.mail.smtp@default:default"/>
<setEntry value="com.sun.org.apache.xml.internal.resolver@default:default"/>
<setEntry value="com.sun.xml.bind.external.rngom@default:default"/>
<setEntry value="com.sun.xml.bind.jaxb-impl@default:default"/>
<setEntry value="com.sun.xml.bind.jaxb-jxc@default:default"/>
<setEntry value="com.sun.xml.bind.jaxb-osgi@default:default"/>
<setEntry value="com.sun.xml.bind.jaxb-xjc@default:default"/>
<setEntry value="com.sun.xml.fastinfoset.FastInfoset@default:default"/>
<setEntry value="com.sun.xml.messaging.saaj.impl@default:default"/>
<setEntry value="com.sun.xml.stream.buffer.streambuffer@default:default"/>
<setEntry value="com.sun.xml.ws.jaxws-rt@default:default"/>
<setEntry value="com.sun.xml.ws.policy@default:default"/>
<setEntry value="groovy-ant@default:false"/>
<setEntry value="groovy-cli-commons@default:false"/>
<setEntry value="groovy-cli-picocli@default:false"/>
<setEntry value="groovy-console@default:false"/>
<setEntry value="groovy-datetime@default:false"/>
<setEntry value="groovy-docgenerator@default:false"/>
<setEntry value="groovy-groovydoc@default:false"/>
<setEntry value="groovy-groovysh@default:false"/>
<setEntry value="groovy-jmx@default:false"/>
<setEntry value="groovy-json@default:false"/>
<setEntry value="groovy-jsr223@default:false"/>
<setEntry value="groovy-macro@default:false"/>
<setEntry value="groovy-nio@default:false"/>
<setEntry value="groovy-servlet@default:false"/>
<setEntry value="groovy-sql@default:false"/>
<setEntry value="groovy-swing@default:false"/>
<setEntry value="groovy-xml@default:false"/>
<setEntry value="groovy@default:default"/>
<setEntry value="io.github.classgraph@default:default"/>
<setEntry value="jakarta.jws-api@default:default"/>
<setEntry value="jakarta.mail.api@default:default"/>
<setEntry value="jakarta.persistence-api@default:default"/>
<setEntry value="jakarta.ws.rs-api@default:default"/>
<setEntry value="jakarta.xml.bind-api@default:default"/>
<setEntry value="jakarta.xml.soap-api@default:default"/>
<setEntry value="jakarta.xml.ws-api@default:default"/>
<setEntry value="java_cup-runtime@default:default"/>
<setEntry value="java_cup@default:default"/>
<setEntry value="javaewah@default:default"/>
<setEntry value="javax.annotation-api@default:default"/>
<setEntry value="javax.annotation@default:default"/>
<setEntry value="javax.el@default:default"/>
<setEntry value="javax.enterprise.cdi-api@default:default"/>
<setEntry value="javax.inject@default:default"/>
<setEntry value="javax.interceptor-api@default:default"/>
<setEntry value="javax.jms@default:default"/>
<setEntry value="javax.measure.unit-api@default:default"/>
<setEntry value="javax.servlet.jsp@default:default"/>
<setEntry value="javax.servlet@default:default"/>
<setEntry value="javax.transaction-api@default:default"/>
<setEntry value="javax.validation.api@default:default"/>
<setEntry value="javax.validation@default:default"/>
<setEntry value="javax.websocket-api@default:default"/>
<setEntry value="javax.ws.rs@default:default"/>
<setEntry value="joda-time@default:default"/>
<setEntry value="json@default:default"/>
<setEntry value="net.bytebuddy.byte-buddy-agent@default:default"/>
<setEntry value="net.bytebuddy.byte-buddy@default:default"/>
<setEntry value="net.i2p.crypto.eddsa@default:default"/>
<setEntry value="net.sf.jasperreports.engine@default:default"/>
<setEntry value="net.sf.supercsv.super-csv@default:default"/>
<setEntry value="org.antlr.runtime@default:default"/>
<setEntry value="org.aopalliance@default:default"/>
<setEntry value="org.apache.activemq.activemq-core@default:default"/>
<setEntry value="org.apache.activemq.kahadb@default:default"/>
<setEntry value="org.apache.ant@default:default"/>
<setEntry value="org.apache.aries.spifly.dynamic.bundle@default:default"/>
<setEntry value="org.apache.aries.util@default:default"/>
<setEntry value="org.apache.batik.constants@default:default"/>
<setEntry value="org.apache.batik.css@default:default"/>
<setEntry value="org.apache.batik.i18n@default:default"/>
<setEntry value="org.apache.batik.util@default:default"/>
<setEntry value="org.apache.commons.beanutils@default:default"/>
<setEntry value="org.apache.commons.codec@default:default"/>
<setEntry value="org.apache.commons.collections@default:default"/>
<setEntry value="org.apache.commons.commons-collections4@default:default"/>
<setEntry value="org.apache.commons.commons-configuration2@default:default"/>
<setEntry value="org.apache.commons.compress@default:default"/>
<setEntry value="org.apache.commons.csv@default:default"/>
<setEntry value="org.apache.commons.digester@default:default"/>
<setEntry value="org.apache.commons.discovery@default:default"/>
<setEntry value="org.apache.commons.fileupload@default:default"/>
<setEntry value="org.apache.commons.io@default:default"/>
<setEntry value="org.apache.commons.jxpath@default:default"/>
<setEntry value="org.apache.commons.lang3.source@default:default"/>
<setEntry value="org.apache.commons.lang3@default:default"/>
<setEntry value="org.apache.commons.lang@default:default"/>
<setEntry value="org.apache.commons.logging@default:default"/>
<setEntry value="org.apache.commons.math3@default:default"/>
<setEntry value="org.apache.commons.net@default:default"/>
<setEntry value="org.apache.cxf.cxf-core@default:default"/>
<setEntry value="org.apache.cxf.cxf-rt-bindings-soap@default:default"/>
<setEntry value="org.apache.cxf.cxf-rt-bindings-xml@default:default"/>
<setEntry value="org.apache.cxf.cxf-rt-databinding-jaxb@default:default"/>
<setEntry value="org.apache.cxf.cxf-rt-databinding-xmlbeans@default:default"/>
<setEntry value="org.apache.cxf.cxf-rt-frontend-jaxrs@default:default"/>
<setEntry value="org.apache.cxf.cxf-rt-frontend-jaxws@default:default"/>
<setEntry value="org.apache.cxf.cxf-rt-frontend-simple@default:default"/>
<setEntry value="org.apache.cxf.cxf-rt-management@default:default"/>
<setEntry value="org.apache.cxf.cxf-rt-rs-extension-providers@default:default"/>
<setEntry value="org.apache.cxf.cxf-rt-rs-http-sci@default:default"/>
<setEntry value="org.apache.cxf.cxf-rt-rs-service-description@default:default"/>
<setEntry value="org.apache.cxf.cxf-rt-security@default:default"/>
<setEntry value="org.apache.cxf.cxf-rt-transports-http-jetty@default:default"/>
<setEntry value="org.apache.cxf.cxf-rt-transports-http@default:default"/>
<setEntry value="org.apache.cxf.cxf-rt-ws-addr@default:default"/>
<setEntry value="org.apache.cxf.cxf-rt-ws-policy@default:default"/>
<setEntry value="org.apache.cxf.cxf-rt-wsdl@default:default"/>
<setEntry value="org.apache.cxf.rt-ws-transfer@default:default"/>
<setEntry value="org.apache.felix.gogo.command@default:default"/>
<setEntry value="org.apache.felix.gogo.runtime@default:default"/>
<setEntry value="org.apache.felix.gogo.shell@default:default"/>
<setEntry value="org.apache.felix.inventory@default:default"/>
<setEntry value="org.apache.felix.scr@1:true"/>
<setEntry value="org.apache.felix.webconsole.plugins.ds@default:default"/>
<setEntry value="org.apache.felix.webconsole.plugins.memoryusage@default:default"/>
<setEntry value="org.apache.felix.webconsole@default:default"/>
<setEntry value="org.apache.geronimo.specs.geronimo-j2ee-management_1.1_spec@default:default"/>
<setEntry value="org.apache.httpcomponents.httpasyncclient@default:default"/>
<setEntry value="org.apache.httpcomponents.httpclient@default:default"/>
<setEntry value="org.apache.httpcomponents.httpcore-nio@default:default"/>
<setEntry value="org.apache.httpcomponents.httpcore@default:default"/>
<setEntry value="org.apache.httpcomponents.httpmime@default:default"/>
<setEntry value="org.apache.jasper.glassfish@default:default"/>
<setEntry value="org.apache.jclouds.api.cloudwatch@default:default"/>
<setEntry value="org.apache.jclouds.api.ec2@default:default"/>
<setEntry value="org.apache.jclouds.api.openstack-cinder@default:default"/>
<setEntry value="org.apache.jclouds.api.openstack-keystone@default:default"/>
<setEntry value="org.apache.jclouds.api.openstack-nova@default:default"/>
<setEntry value="org.apache.jclouds.api.sts@default:default"/>
<setEntry value="org.apache.jclouds.common.openstack-common@default:default"/>
<setEntry value="org.apache.jclouds.driver.jclouds-slf4j@default:default"/>
<setEntry value="org.apache.jclouds.jclouds-blobstore@default:default"/>
<setEntry value="org.apache.jclouds.jclouds-compute@default:default"/>
<setEntry value="org.apache.jclouds.jclouds-core@default:default"/>
<setEntry value="org.apache.jclouds.jclouds-scriptbuilder@default:default"/>
<setEntry value="org.apache.jclouds.labs.docker@default:default"/>
<setEntry value="org.apache.jclouds.labs.openstack-neutron@default:default"/>
<setEntry value="org.apache.lucene.analyzers-common@default:default"/>
<setEntry value="org.apache.lucene.analyzers-smartcn@default:default"/>
<setEntry value="org.apache.lucene.core@default:default"/>
<setEntry value="org.apache.maven.resolver.api@default:default"/>
<setEntry value="org.apache.maven.resolver.connector.basic@default:default"/>
<setEntry value="org.apache.maven.resolver.impl@default:default"/>
<setEntry value="org.apache.maven.resolver.spi@default:default"/>
<setEntry value="org.apache.maven.resolver.transport.file@default:default"/>
<setEntry value="org.apache.maven.resolver.transport.http@default:default"/>
<setEntry value="org.apache.maven.resolver.util@default:default"/>
<setEntry value="org.apache.neethi@default:default"/>
<setEntry value="org.apache.onami.configuration@default:default"/>
<setEntry value="org.apache.pdfbox.fontbox@default:default"/>
<setEntry value="org.apache.pdfbox.preflight@default:default"/>
<setEntry value="org.apache.pdfbox.xmpbox@default:default"/>
<setEntry value="org.apache.pdfbox@default:default"/>
<setEntry value="org.apache.poi.poi-ooxml-schemas@default:default"/>
<setEntry value="org.apache.poi.poi-ooxml@default:default"/>
<setEntry value="org.apache.poi.poi@default:default"/>
<setEntry value="org.apache.servicemix.bundles.cglib@default:default"/>
<setEntry value="org.apache.servicemix.bundles.jaxen@default:default"/>
<setEntry value="org.apache.servicemix.bundles.rhino@default:default"/>
<setEntry value="org.apache.servicemix.bundles.spring-aop@default:default"/>
<setEntry value="org.apache.servicemix.bundles.spring-beans@default:default"/>
<setEntry value="org.apache.servicemix.bundles.spring-context-support@default:default"/>
<setEntry value="org.apache.servicemix.bundles.spring-context@default:default"/>
<setEntry value="org.apache.servicemix.bundles.spring-core@default:default"/>
<setEntry value="org.apache.servicemix.bundles.spring-expression@default:default"/>
<setEntry value="org.apache.servicemix.bundles.spring-web@default:default"/>
<setEntry value="org.apache.servicemix.bundles.wsdl4j@default:default"/>
<setEntry value="org.apache.servicemix.bundles.xerces@default:default"/>
<setEntry value="org.apache.sshd.core@default:default"/>
<setEntry value="org.apache.sshd.osgi@default:default"/>
<setEntry value="org.apache.sshd.putty@default:default"/>
<setEntry value="org.apache.sshd.sftp@default:default"/>
<setEntry value="org.apache.taglibs.standard-impl@default:default"/>
<setEntry value="org.apache.taglibs.standard-jstlel@default:default"/>
<setEntry value="org.apache.taglibs.taglibs-standard-spec@default:default"/>
<setEntry value="org.apache.velocity@default:default"/>
<setEntry value="org.apache.ws.commons.util@default:default"/>
<setEntry value="org.apache.ws.xmlschema.core@default:default"/>
<setEntry value="org.apache.xalan@default:default"/>
<setEntry value="org.apache.xml.resolver@default:default"/>
<setEntry value="org.apache.xml.serializer@default:default"/>
<setEntry value="org.apache.xmlbeans@default:default"/>
<setEntry value="org.apache.xmlgraphics.batik-anim@default:default"/>
<setEntry value="org.apache.xmlgraphics.batik-awt-util@default:default"/>
<setEntry value="org.apache.xmlgraphics.batik-bridge@default:default"/>
<setEntry value="org.apache.xmlgraphics.batik-codec@default:default"/>
<setEntry value="org.apache.xmlgraphics.batik-constants@default:default"/>
<setEntry value="org.apache.xmlgraphics.batik-css@default:default"/>
<setEntry value="org.apache.xmlgraphics.batik-dom@default:default"/>
<setEntry value="org.apache.xmlgraphics.batik-ext@default:default"/>
<setEntry value="org.apache.xmlgraphics.batik-extension@default:default"/>
<setEntry value="org.apache.xmlgraphics.batik-gvt@default:default"/>
<setEntry value="org.apache.xmlgraphics.batik-i18n@default:default"/>
<setEntry value="org.apache.xmlgraphics.batik-parser@default:default"/>
<setEntry value="org.apache.xmlgraphics.batik-script@default:default"/>
<setEntry value="org.apache.xmlgraphics.batik-svg-dom@default:default"/>
<setEntry value="org.apache.xmlgraphics.batik-svggen@default:default"/>
<setEntry value="org.apache.xmlgraphics.batik-util@default:default"/>
<setEntry value="org.apache.xmlgraphics.batik-xml@default:default"/>
<setEntry value="org.apache.xmlgraphics@default:default"/>
<setEntry value="org.apiguardian@default:default"/>
<setEntry value="org.assertj@default:default"/>
<setEntry value="org.atmosphere.runtime@default:default"/>
<setEntry value="org.cryptacular@default:default"/>
<setEntry value="org.dom4j@default:default"/>
<setEntry value="org.eclipse.ant.core@default:default"/>
<setEntry value="org.eclipse.core.commands@default:default"/>
<setEntry value="org.eclipse.core.contenttype@default:default"/>
<setEntry value="org.eclipse.core.databinding.beans@default:default"/>
<setEntry value="org.eclipse.core.databinding.observable@default:default"/>
<setEntry value="org.eclipse.core.databinding.property@default:default"/>
<setEntry value="org.eclipse.core.databinding@default:default"/>
<setEntry value="org.eclipse.core.expressions@default:default"/>
<setEntry value="org.eclipse.core.externaltools@default:default"/>
<setEntry value="org.eclipse.core.filebuffers@default:default"/>
<setEntry value="org.eclipse.core.filesystem@default:default"/>
<setEntry value="org.eclipse.core.jobs@default:default"/>
<setEntry value="org.eclipse.core.net@default:default"/>
<setEntry value="org.eclipse.core.resources@default:default"/>
<setEntry value="org.eclipse.core.runtime@default:true"/>
<setEntry value="org.eclipse.core.variables@default:default"/>
<setEntry value="org.eclipse.debug.core@default:default"/>
<setEntry value="org.eclipse.ecf.filetransfer@default:default"/>
<setEntry value="org.eclipse.ecf.identity@default:default"/>
<setEntry value="org.eclipse.ecf.provider.filetransfer.httpclient45@default:default"/>
<setEntry value="org.eclipse.ecf.provider.filetransfer.ssl@default:false"/>
<setEntry value="org.eclipse.ecf.provider.filetransfer@default:default"/>
<setEntry value="org.eclipse.ecf.ssl@default:false"/>
<setEntry value="org.eclipse.ecf@default:default"/>
<setEntry value="org.eclipse.equinox.app@default:default"/>
<setEntry value="org.eclipse.equinox.bidi@default:default"/>
<setEntry value="org.eclipse.equinox.cm@default:default"/>
<setEntry value="org.eclipse.equinox.common@2:true"/>
<setEntry value="org.eclipse.equinox.concurrent@default:default"/>
<setEntry value="org.eclipse.equinox.console@default:default"/>
<setEntry value="org.eclipse.equinox.coordinator@default:default"/>
<setEntry value="org.eclipse.equinox.device@default:default"/>
<setEntry value="org.eclipse.equinox.ds@1:true"/>
<setEntry value="org.eclipse.equinox.event@default:default"/>
<setEntry value="org.eclipse.equinox.frameworkadmin.equinox@default:default"/>
<setEntry value="org.eclipse.equinox.frameworkadmin@default:default"/>
<setEntry value="org.eclipse.equinox.http.jetty@default:default"/>
<setEntry value="org.eclipse.equinox.http.registry@default:default"/>
<setEntry value="org.eclipse.equinox.http.servlet@default:default"/>
<setEntry value="org.eclipse.equinox.http.servletbridge@default:default"/>
<setEntry value="org.eclipse.equinox.jsp.jasper.registry@default:default"/>
<setEntry value="org.eclipse.equinox.jsp.jasper@default:default"/>
<setEntry value="org.eclipse.equinox.metatype@default:default"/>
<setEntry value="org.eclipse.equinox.p2.artifact.repository@default:default"/>
<setEntry value="org.eclipse.equinox.p2.console@default:default"/>
<setEntry value="org.eclipse.equinox.p2.core@default:default"/>
<setEntry value="org.eclipse.equinox.p2.director.app@default:default"/>
<setEntry value="org.eclipse.equinox.p2.director@default:default"/>
<setEntry value="org.eclipse.equinox.p2.directorywatcher@default:default"/>
<setEntry value="org.eclipse.equinox.p2.engine@default:default"/>
<setEntry value="org.eclipse.equinox.p2.extensionlocation@default:default"/>
<setEntry value="org.eclipse.equinox.p2.garbagecollector@default:default"/>
<setEntry value="org.eclipse.equinox.p2.jarprocessor@default:default"/>
<setEntry value="org.eclipse.equinox.p2.metadata.repository@default:default"/>
<setEntry value="org.eclipse.equinox.p2.metadata@default:default"/>
<setEntry value="org.eclipse.equinox.p2.operations@default:default"/>
<setEntry value="org.eclipse.equinox.p2.publisher.eclipse@default:default"/>
<setEntry value="org.eclipse.equinox.p2.publisher@default:default"/>
<setEntry value="org.eclipse.equinox.p2.reconciler.dropins@default:default"/>
<setEntry value="org.eclipse.equinox.p2.repository.tools@default:default"/>
<setEntry value="org.eclipse.equinox.p2.repository@default:default"/>
<setEntry value="org.eclipse.equinox.p2.touchpoint.eclipse@default:default"/>
<setEntry value="org.eclipse.equinox.p2.touchpoint.natives@default:default"/>
<setEntry value="org.eclipse.equinox.p2.transport.ecf@default:default"/>
<setEntry value="org.eclipse.equinox.p2.updatechecker@default:default"/>
<setEntry value="org.eclipse.equinox.p2.updatesite@default:default"/>
<setEntry value="org.eclipse.equinox.preferences@default:default"/>
<setEntry value="org.eclipse.equinox.registry@default:default"/>
<setEntry value="org.eclipse.equinox.security@default:default"/>
<setEntry value="org.eclipse.equinox.servletbridge@default:default"/>
<setEntry value="org.eclipse.equinox.simpleconfigurator.manipulator@default:default"/>
<setEntry value="org.eclipse.equinox.simpleconfigurator@1:true"/>
<setEntry value="org.eclipse.equinox.useradmin@default:default"/>
<setEntry value="org.eclipse.help.base@default:default"/>
<setEntry value="org.eclipse.help.webapp@default:default"/>
<setEntry value="org.eclipse.help@default:default"/>
<setEntry value="org.eclipse.jdt.annotation*1.1.400.v20180921-1416@default:default"/>
<setEntry value="org.eclipse.jdt.annotation*2.2.400.v20191120-1313@default:default"/>
<setEntry value="org.eclipse.jdt.apt.core@default:default"/>
<setEntry value="org.eclipse.jdt.apt.pluggable.core@default:default"/>
<setEntry value="org.eclipse.jdt.compiler.apt@default:false"/>
<setEntry value="org.eclipse.jdt.compiler.tool@default:false"/>
<setEntry value="org.eclipse.jdt.core.formatterapp@default:default"/>
<setEntry value="org.eclipse.jdt.core@default:default"/>
<setEntry value="org.eclipse.jdt.debug@default:default"/>
<setEntry value="org.eclipse.jdt.doc.user@default:default"/>
<setEntry value="org.eclipse.jdt.junit.runtime@default:default"/>
<setEntry value="org.eclipse.jdt.junit4.runtime@default:default"/>
<setEntry value="org.eclipse.jdt.junit5.runtime@default:default"/>
<setEntry value="org.eclipse.jetty.alpn.api@default:default"/>
<setEntry value="org.eclipse.jetty.alpn.client@default:default"/>
<setEntry value="org.eclipse.jetty.alpn.server@default:default"/>
<setEntry value="org.eclipse.jetty.annotations@default:default"/>
<setEntry value="org.eclipse.jetty.apache-jsp@default:default"/>
<setEntry value="org.eclipse.jetty.client@default:default"/>
<setEntry value="org.eclipse.jetty.continuation*9.4.27.v20200227@default:default"/>
<setEntry value="org.eclipse.jetty.continuation*9.4.28.v20200408@default:default"/>
<setEntry value="org.eclipse.jetty.deploy@default:default"/>
<setEntry value="org.eclipse.jetty.http*9.4.27.v20200227@default:default"/>
<setEntry value="org.eclipse.jetty.http*9.4.28.v20200408@default:default"/>
<setEntry value="org.eclipse.jetty.http2.client.http@default:default"/>
<setEntry value="org.eclipse.jetty.http2.client@default:default"/>
<setEntry value="org.eclipse.jetty.http2.common@default:default"/>
<setEntry value="org.eclipse.jetty.http2.hpack@default:default"/>
<setEntry value="org.eclipse.jetty.http2.server@default:default"/>
<setEntry value="org.eclipse.jetty.io*9.4.27.v20200227@default:default"/>
<setEntry value="org.eclipse.jetty.io*9.4.28.v20200408@default:default"/>
<setEntry value="org.eclipse.jetty.jaas@default:default"/>
<setEntry value="org.eclipse.jetty.jmx@default:default"/>
<setEntry value="org.eclipse.jetty.jndi@default:default"/>
<setEntry value="org.eclipse.jetty.osgi-servlet-api@default:default"/>
<setEntry value="org.eclipse.jetty.osgi.alpn.fragment@default:false"/>
<setEntry value="org.eclipse.jetty.osgi.boot.jsp@default:false"/>
<setEntry value="org.eclipse.jetty.osgi.boot.warurl@default:default"/>
<setEntry value="org.eclipse.jetty.osgi.boot@default:default"/>
<setEntry value="org.eclipse.jetty.osgi.httpservice@default:default"/>
<setEntry value="org.eclipse.jetty.plus@default:default"/>
<setEntry value="org.eclipse.jetty.proxy@default:default"/>
<setEntry value="org.eclipse.jetty.rewrite@default:default"/>
<setEntry value="org.eclipse.jetty.security*9.4.27.v20200227@default:default"/>
<setEntry value="org.eclipse.jetty.security*9.4.28.v20200408@default:default"/>
<setEntry value="org.eclipse.jetty.server*9.4.27.v20200227@default:default"/>
<setEntry value="org.eclipse.jetty.server*9.4.28.v20200408@default:default"/>
<setEntry value="org.eclipse.jetty.servlet*9.4.27.v20200227@default:default"/>
<setEntry value="org.eclipse.jetty.servlet*9.4.28.v20200408@default:default"/>
<setEntry value="org.eclipse.jetty.servlets@default:default"/>
<setEntry value="org.eclipse.jetty.util*9.4.27.v20200227@default:default"/>
<setEntry value="org.eclipse.jetty.util*9.4.28.v20200408@default:default"/>
<setEntry value="org.eclipse.jetty.util.ajax@default:default"/>
<setEntry value="org.eclipse.jetty.webapp@default:default"/>
<setEntry value="org.eclipse.jetty.websocket.api@default:default"/>
<setEntry value="org.eclipse.jetty.websocket.client@default:default"/>
<setEntry value="org.eclipse.jetty.websocket.common@default:default"/>
<setEntry value="org.eclipse.jetty.websocket.javax.websocket.server@default:default"/>
<setEntry value="org.eclipse.jetty.websocket.javax.websocket@default:default"/>
<setEntry value="org.eclipse.jetty.websocket.server@default:default"/>
<setEntry value="org.eclipse.jetty.websocket.servlet@default:default"/>
<setEntry value="org.eclipse.jetty.xml@default:default"/>
<setEntry value="org.eclipse.jsch.core@default:default"/>
<setEntry value="org.eclipse.ltk.core.refactoring@default:default"/>
<setEntry value="org.eclipse.orbit.mongodb@default:default"/>
<setEntry value="org.eclipse.osgi.compatibility.state@default:false"/>
<setEntry value="org.eclipse.osgi.services@default:default"/>
<setEntry value="org.eclipse.osgi.util@default:default"/>
<setEntry value="org.eclipse.osgi@-1:true"/>
<setEntry value="org.eclipse.text@default:default"/>
<setEntry value="org.eclipse.update.configurator@default:default"/>
<setEntry value="org.eclipse.urischeme@default:default"/>
<setEntry value="org.ejml.core@default:default"/>
<setEntry value="org.ejml.dense64@default:default"/>
<setEntry value="org.ejml.denseC64@default:default"/>
<setEntry value="org.ejml.ejml-all@default:default"/>
<setEntry value="org.ejml.equation@default:default"/>
<setEntry value="org.ejml.experimental@default:default"/>
<setEntry value="org.ejml.simple@default:default"/>
<setEntry value="org.freemarker@default:default"/>
<setEntry value="org.ggf.drmaa@default:default"/>
<setEntry value="org.glassfish.external.management-api@default:default"/>
<setEntry value="org.glassfish.gmbal.gmbal@default:default"/>
<setEntry value="org.glassfish.hk2.api@default:default"/>
<setEntry value="org.glassfish.hk2.locator@default:default"/>
<setEntry value="org.glassfish.hk2.osgi-resource-locator@default:default"/>
<setEntry value="org.glassfish.hk2.utils@default:default"/>
<setEntry value="org.glassfish.jaxb.txw2@default:default"/>
<setEntry value="org.glassfish.jersey.apache.connector@default:default"/>
<setEntry value="org.glassfish.jersey.bundles.repackaged.jersey-guava@default:default"/>
<setEntry value="org.glassfish.jersey.containers.servlet.core@default:default"/>
<setEntry value="org.glassfish.jersey.containers.servlet@default:default"/>
<setEntry value="org.glassfish.jersey.core.jersey-client@default:default"/>
<setEntry value="org.glassfish.jersey.core.jersey-common@default:default"/>
<setEntry value="org.glassfish.jersey.core.jersey-server@default:default"/>
<setEntry value="org.glassfish.jersey.ext.entityfiltering@default:default"/>
<setEntry value="org.glassfish.jersey.media.jersey-media-json-jackson@default:default"/>
<setEntry value="org.glassfish.pfl.pfl-asm@default:default"/>
<setEntry value="org.glassfish.pfl.pfl-basic@default:default"/>
<setEntry value="org.glassfish.pfl.pfl-dynamic@default:default"/>
<setEntry value="org.glassfish.pfl.pfl-tf@default:default"/>
<setEntry value="org.hamcrest.core@default:default"/>
<setEntry value="org.hamcrest.library@default:default"/>
<setEntry value="org.hsqldb@default:default"/>
<setEntry value="org.jacoco.agent@default:default"/>
<setEntry value="org.jacoco.core@default:default"/>
<setEntry value="org.jacoco.report@default:default"/>
<setEntry value="org.jaxen@default:default"/>
<setEntry value="org.jcodings@default:default"/>
<setEntry value="org.jdom2@default:default"/>
<setEntry value="org.jfree.chart@default:default"/>
<setEntry value="org.jfree.jcommon@default:default"/>
<setEntry value="org.joni@default:default"/>
<setEntry value="org.jsoup@default:default"/>
<setEntry value="org.junit.jupiter.api@default:default"/>
<setEntry value="org.junit.jupiter.engine@default:default"/>
<setEntry value="org.junit.jupiter.migrationsupport@default:default"/>
<setEntry value="org.junit.jupiter.params@default:default"/>
<setEntry value="org.junit.platform.commons@default:default"/>
<setEntry value="org.junit.platform.engine@default:default"/>
<setEntry value="org.junit.platform.launcher@default:default"/>
<setEntry value="org.junit.platform.runner@default:default"/>
<setEntry value="org.junit.platform.suite.api@default:default"/>
<setEntry value="org.junit.vintage.engine@default:default"/>
<setEntry value="org.junit@default:default"/>
<setEntry value="org.jvnet.mimepull@default:default"/>
<setEntry value="org.jvnet.staxex.stax-ex@default:default"/>
<setEntry value="org.kohsuke.args4j@default:default"/>
<setEntry value="org.krysalis.barcode4j@default:default"/>
<setEntry value="org.mockito@default:default"/>
<setEntry value="org.mortbay.jasper.apache-el@default:default"/>
<setEntry value="org.mortbay.jasper.apache-jsp@default:default"/>
<setEntry value="org.mozilla.javascript@default:default"/>
<setEntry value="org.objectweb.asm*7.0.0@default:default"/>
<setEntry value="org.objectweb.asm*7.2.0.v20191010-1910@default:default"/>
<setEntry value="org.objectweb.asm.analysis@default:default"/>
<setEntry value="org.objectweb.asm.commons*7.0.0@default:default"/>
<setEntry value="org.objectweb.asm.commons*7.2.0.v20191010-1910@default:default"/>
<setEntry value="org.objectweb.asm.tree*7.0.0@default:default"/>
<setEntry value="org.objectweb.asm.tree*7.2.0.v20191010-1910@default:default"/>
<setEntry value="org.objectweb.asm.tree.analysis@default:default"/>
<setEntry value="org.objectweb.asm.util*7.0.0@default:default"/>
<setEntry value="org.objectweb.asm.util*7.2.0.v20191010-1910@default:default"/>
<setEntry value="org.objenesis@default:default"/>
<setEntry value="org.opentest4j@default:default"/>
<setEntry value="org.passay@default:default"/>
<setEntry value="org.reactivestreams@default:default"/>
<setEntry value="org.sat4j.core@default:default"/>
<setEntry value="org.sat4j.pb@default:default"/>
<setEntry value="org.springframework.spring-jcl@default:default"/>
<setEntry value="org.tukaani.xz@default:default"/>
<setEntry value="org.w3c.css.sac@default:default"/>
<setEntry value="org.w3c.dom.events@default:default"/>
<setEntry value="org.w3c.dom.smil@default:default"/>
<setEntry value="org.w3c.dom.svg.patch@default:false"/>
<setEntry value="org.w3c.dom.svg@default:default"/>
<setEntry value="org.zkoss.zsoup@default:default"/>
<setEntry value="slf4j.api@default:default"/>
<setEntry value="slf4j.jcl@default:false"/>
<setEntry value="slf4j.jdk14@default:false"/>
<setEntry value="stax2-api@default:default"/>
<setEntry value="zjavassist@default:default"/>
</setAttribute>
<setAttribute key="selected_workspace_bundles">
<setEntry value="org.adempiere.base.callout@default:default"/>
<setEntry value="org.adempiere.base.process@default:default"/>
<setEntry value="org.adempiere.base@default:default"/>
<setEntry value="org.adempiere.eclipse.equinox.http.servlet@default:default"/>
<setEntry value="org.adempiere.install@default:default"/>
<setEntry value="org.adempiere.payment.processor@default:default"/>
<setEntry value="org.adempiere.pipo.handlers@default:default"/>
<setEntry value="org.adempiere.pipo@default:default"/>
<setEntry value="org.adempiere.plugin.utils@default:default"/>
<setEntry value="org.adempiere.report.jasper.library@default:false"/>
<setEntry value="org.adempiere.report.jasper@default:default"/>
<setEntry value="org.adempiere.ui@default:default"/>
<setEntry value="org.apache.ecs@default:default"/>
<setEntry value="org.compiere.db.oracle.provider@default:default"/>
<setEntry value="org.compiere.db.postgresql.provider@default:default"/>
<setEntry value="org.idempiere.hazelcast.service@default:default"/>
<setEntry value="org.idempiere.test@default:default"/>
</setAttribute>
<booleanAttribute key="show_selected_only" value="false"/>
<stringAttribute key="templateConfig" value="${target_home}/configuration/config.ini"/>
<booleanAttribute key="tracing" value="false"/>
<booleanAttribute key="useCustomFeatures" value="false"/>
<booleanAttribute key="useDefaultConfig" value="true"/>
<booleanAttribute key="useDefaultConfigArea" value="false"/>
<booleanAttribute key="useProduct" value="false"/>
</launchConfiguration>

View File

@ -0,0 +1,50 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.idempiere</groupId>
<artifactId>org.idempiere.parent</artifactId>
<version>7.1.0-SNAPSHOT</version>
<relativePath>../org.idempiere.parent/pom.xml</relativePath>
</parent>
<artifactId>org.idempiere.test</artifactId>
<packaging>eclipse-test-plugin</packaging>
<properties>
<idempiere.home>..</idempiere.home>
<skipTests>true</skipTests>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<configuration>
<argLine>
-DIDEMPIERE_HOME=${idempiere.home}
</argLine>
<testRuntime>p2Installed</testRuntime>
<skipTests>${skipTests}</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho.version}</version>
<configuration>
<dependency-resolution>
<extraRequirements>
<!-- product IU under test -->
<requirement>
<type>p2-installable-unit</type>
<id>org.adempiere.server.product</id>
<versionRange>0.0.0</versionRange>
</requirement>
</extraRequirements>
</dependency-resolution>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,191 @@
/***********************************************************************
* This file is part of iDempiere ERP Open Source *
* http://www.idempiere.org *
* *
* Copyright (C) Contributors *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
* Contributors: *
* - hengsin *
**********************************************************************/
package org.idempiere.test;
import static org.junit.jupiter.api.Assertions.fail;
import java.sql.SQLException;
import java.sql.Timestamp;
import org.compiere.Adempiere;
import org.compiere.model.MAcctSchema;
import org.compiere.model.MClientInfo;
import org.compiere.model.MRole;
import org.compiere.util.Env;
import org.compiere.util.Language;
import org.compiere.util.Trx;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
/**
* @author hengsin
*
*/
public abstract class AbstractTestCase {
private Trx trx;
private LoginDetails loginDetails;
protected final int GARDEN_WORLD_CLIENT = 11;
protected final int GARDEN_WORLD_HQ_ORG = 11;
protected final int GARDEN_WORLD_ADMIN_USER = 101;
protected final int GARDEN_WORLD_ADMIN_ROLE = 102;
protected final int GARDEN_WORLD_HQ_WAREHOUSE = 103;
@BeforeAll
static void setup() {
Adempiere.startup(false);
}
@BeforeEach
protected void init() {
String trxName = Trx.createTrxName(getClass().getName()+"_");
trx = Trx.get(trxName, true);
trx.start();
initContext();
}
protected LoginDetails newLoginDetails() {
return new LoginDetails(GARDEN_WORLD_CLIENT, GARDEN_WORLD_HQ_ORG, GARDEN_WORLD_ADMIN_USER, GARDEN_WORLD_ADMIN_ROLE, GARDEN_WORLD_HQ_WAREHOUSE,
new Timestamp(System.currentTimeMillis()), Language.getLanguage("en_US"));
}
protected void initContext() {
loginDetails = newLoginDetails();
Env.setContext(Env.getCtx(), Env.AD_CLIENT_ID, loginDetails.getClientId());
Env.setContext(Env.getCtx(), Env.AD_ORG_ID, loginDetails.getOrganizationId());
Env.setContext(Env.getCtx(), Env.AD_USER_ID, loginDetails.getUserId());
Env.setContext(Env.getCtx(), Env.AD_ROLE_ID, loginDetails.getRoleId());
Env.setContext(Env.getCtx(), Env.M_WAREHOUSE_ID, loginDetails.getWarehouseId());
Env.setContext(Env.getCtx(), "#LanguageName", loginDetails.getLoginLanguage().getName());
Env.setContext(Env.getCtx(), "#Date", loginDetails.getLoginDate());
Env.verifyLanguage(Env.getCtx(), getLanguage());
Env.setContext(Env.getCtx(), Env.LANGUAGE, getLanguage().getAD_Language());
Env.setContext(Env.getCtx(), Env.LOCALE, getLanguage().getLocale().toString());
if (loginDetails.getRoleId() > 0) {
if (MRole.getDefault(Env.getCtx(), false).isShowAcct())
Env.setContext(Env.getCtx(), "#ShowAcct", "Y");
else
Env.setContext(Env.getCtx(), "#ShowAcct", "N");
}
/** Define AcctSchema , Currency, HasAlias **/
if (loginDetails.getClientId() > 0) {
if (MClientInfo.get(Env.getCtx(), loginDetails.getClientId()).getC_AcctSchema1_ID() > 0) {
MAcctSchema primary = MAcctSchema.get(Env.getCtx(), MClientInfo.get(Env.getCtx(), loginDetails.getClientId()).getC_AcctSchema1_ID());
Env.setContext(Env.getCtx(), "$C_AcctSchema_ID", primary.getC_AcctSchema_ID());
Env.setContext(Env.getCtx(), "$C_Currency_ID", primary.getC_Currency_ID());
Env.setContext(Env.getCtx(), "$HasAlias", primary.isHasAlias());
}
MAcctSchema[] ass = MAcctSchema.getClientAcctSchema(Env.getCtx(), loginDetails.getClientId());
if(ass != null && ass.length > 1) {
for(MAcctSchema as : ass) {
if (as.getAD_OrgOnly_ID() != 0) {
if (as.isSkipOrg(loginDetails.getOrganizationId())) {
continue;
} else {
Env.setContext(Env.getCtx(), "$C_AcctSchema_ID", as.getC_AcctSchema_ID());
Env.setContext(Env.getCtx(), "$C_Currency_ID", as.getC_Currency_ID());
Env.setContext(Env.getCtx(), "$HasAlias", as.isHasAlias());
break;
}
}
}
}
}
}
@AfterEach
protected void tearDown() {
if (trx != null && trx.isActive()) {
trx.rollback();
trx.close();
}
}
protected Trx getTrx() {
return trx;
}
protected void commit() {
if (trx != null && trx.isActive()) {
try {
trx.commit(true);
} catch (SQLException e) {
fail(e.getMessage(), e);
}
}
}
protected void rollback() {
if (trx != null && trx.isActive()) {
trx.rollback();
}
}
protected int getAD_Client_ID() {
return loginDetails.getClientId();
}
protected int getAD_Org_ID() {
return loginDetails.getOrganizationId();
}
protected int getAD_User_ID() {
return loginDetails.getUserId();
}
protected int getAD_Role_ID() {
return loginDetails.getRoleId();
}
protected int getM_Warehouse_ID() {
return loginDetails.getWarehouseId();
}
protected Language getLanguage() {
return loginDetails.getLoginLanguage();
}
protected Timestamp getLoginDate() {
return loginDetails.getLoginDate();
}
protected String getTrxName() {
return trx.getTrxName();
}
@AfterAll
static void shutdown() {
Adempiere.stop();
}
}

View File

@ -0,0 +1,114 @@
/***********************************************************************
* This file is part of iDempiere ERP Open Source *
* http://www.idempiere.org *
* *
* Copyright (C) Contributors *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
* Contributors: *
* - hengsin *
**********************************************************************/
package org.idempiere.test;
import java.sql.Timestamp;
import org.compiere.util.Language;
/**
*
* @author hengsin
*
*/
public class LoginDetails {
private int clientId;
private int organizationId;
private int userId;
private int roleId;
private int warehouseId;
private Timestamp loginDate;
private Language loginLanguage;
public LoginDetails(int clientId, int organizationId, int userId, int roleId, int warehouseId, Timestamp loginDate,
Language loginLanguage) {
super();
this.clientId = clientId;
this.organizationId = organizationId;
this.userId = userId;
this.roleId = roleId;
this.warehouseId = warehouseId;
this.loginDate = loginDate;
this.loginLanguage = loginLanguage;
}
public int getClientId() {
return clientId;
}
public void setClientId(int clientId) {
this.clientId = clientId;
}
public int getOrganizationId() {
return organizationId;
}
public void setOrganizationId(int organizationId) {
this.organizationId = organizationId;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public int getRoleId() {
return roleId;
}
public void setRoleId(int roleId) {
this.roleId = roleId;
}
public int getWarehouseId() {
return warehouseId;
}
public void setWarehouseId(int warehouseId) {
this.warehouseId = warehouseId;
}
public Timestamp getLoginDate() {
return loginDate;
}
public void setLoginDate(Timestamp loginDate) {
this.loginDate = loginDate;
}
public Language getLoginLanguage() {
return loginLanguage;
}
public void setLoginLanguage(Language loginLanguage) {
this.loginLanguage = loginLanguage;
}
}

View File

@ -0,0 +1,207 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 2008 SC ARHIPAC SERVICE SRL. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.idempiere.test.base;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import org.adempiere.exceptions.DBException;
import org.compiere.model.MTable;
import org.compiere.util.DB;
import org.compiere.util.KeyNamePair;
import org.compiere.util.TimeUtil;
import org.compiere.util.ValueNamePair;
import org.idempiere.test.AbstractTestCase;
import org.junit.jupiter.api.Test;
/**
* Test {@link org.compiere.util.DB} class
* @author Teo Sarca, www.arhipac.ro
* @author hengsin
*/
public class DBTest extends AbstractTestCase
{
@Test
public void test_getSQLValueEx() throws Exception
{
int result = DB.getSQLValueEx(null, "SELECT 10 FROM DUAL");
assertEquals(10, result);
//
result = DB.getSQLValue(null, "SELECT 10 FROM AD_SYSTEM WHERE 1=2");
assertEquals(-1, result, "No value should be returned");
//
assertThrows(DBException.class, () -> {
DB.getSQLValueEx(null, "SELECT 10 FROM INEXISTENT_TABLE");
});
}
@Test
public void test_getSQLValue() throws Exception
{
int result = DB.getSQLValue(null, "SELECT 10 FROM DUAL");
assertEquals(10, result);
//
result = DB.getSQLValue(null, "SELECT 10 FROM AD_SYSTEM WHERE 1=2");
assertEquals(-1, result, "No value should be returned");
//
result = DB.getSQLValue(null, "SELECT 10 FROM INEXISTENT_TABLE");
assertEquals(-1, result, "Error should be signaled");
}
@Test
public void test_getSQLValueBDEx() throws Exception
{
BigDecimal result = DB.getSQLValueBDEx(null, "SELECT 10 FROM DUAL");
assertEquals(BigDecimal.TEN, result);
//
result = DB.getSQLValueBD(null, "SELECT 10 FROM AD_SYSTEM WHERE 1=2");
assertNull(result, "No value should be returned");
//
assertThrows(DBException.class, () -> {
DB.getSQLValueBDEx(null, "SELECT 10 FROM INEXISTENT_TABLE");
});
}
@Test
public void test_getSQLValueBD() throws Exception
{
BigDecimal result = DB.getSQLValueBD(null, "SELECT 10 FROM DUAL");
assertEquals(BigDecimal.TEN, result);
//
result = DB.getSQLValueBD(null, "SELECT 10 FROM AD_SYSTEM WHERE 1=2");
assertNull(result, "No value should be returned");
//
result = DB.getSQLValueBD(null, "SELECT 10 FROM INEXISTENT_TABLE");
assertNull(result, "Error should be signaled");
}
@Test
public void test_getSQLValueStringEx() throws Exception
{
String result = DB.getSQLValueStringEx(null, "SELECT 'string' FROM DUAL");
assertEquals("string", result);
//
result = DB.getSQLValueStringEx(null, "SELECT 10 FROM AD_SYSTEM WHERE 1=2");
assertNull(result, "No value should be returned");
//
assertThrows(DBException.class, () -> {
DB.getSQLValueStringEx(null, "SELECT 'string' FROM INEXISTENT_TABLE");
});
}
@Test
public void test_getSQLValueString() throws Exception
{
String result = DB.getSQLValueString(null, "SELECT 'string' FROM DUAL");
assertEquals("string", result);
//
result = DB.getSQLValueString(null, "SELECT 'string' FROM AD_SYSTEM WHERE 1=2");
assertNull(result, "No value should be returned");
//
result = DB.getSQLValueString(null, "SELECT 'string' FROM INEXISTENT_TABLE");
assertNull(result, "Error should be signaled");
}
@Test
public void test_getSQLValueTSEx() throws Exception
{
final Timestamp target = TimeUtil.getDay(2008, 01, 01);
//
Timestamp result = DB.getSQLValueTSEx(null, "SELECT TO_DATE('2008-01-01','YYYY-MM-DD') FROM AD_SYSTEM");
assertEquals(target, result);
//
result = DB.getSQLValueTSEx(null, "SELECT TO_DATE('2008-01-01','YYYY-MM-DD') FROM AD_SYSTEM WHERE 1=2");
assertNull(result, "No value should be returned");
//
assertThrows(DBException.class, () -> {
DB.getSQLValueTSEx(null, "SELECT TO_DATE('2008-01-01','YYYY-MM-DD') FROM INEXISTENT_TABLE");
});
}
@Test
public void test_getSQLValueTS() throws Exception
{
final Timestamp target = TimeUtil.getDay(2008, 01, 01);
//
Timestamp result = DB.getSQLValueTS(null, "SELECT TO_DATE('2008-01-01','YYYY-MM-DD') FROM DUAL");
assertEquals(target, result);
//
result = DB.getSQLValueTS(null, "SELECT TO_DATE('2008-01-01','YYYY-MM-DD') FROM AD_SYSTEM WHERE 1=2");
assertNull(result, "No value should be returned");
//
result = DB.getSQLValueTS(null, "SELECT TO_DATE('2008-01-01','YYYY-MM-DD') FROM INEXISTENT_TABLE");
assertNull(result, "Error should be signaled");
}
@Test
public void test_getValueNamePairs() throws Exception
{
ArrayList<Object> params = new ArrayList<Object>();
params.add(MTable.ACCESSLEVEL_AD_Reference_ID);
final String sql = "SELECT Value, Name FROM AD_Ref_List WHERE AD_Reference_ID=? ORDER BY Value";
// Get (with optional item)
ValueNamePair[] arr = DB.getValueNamePairs(sql, true, params);
assertEquals(6+1, arr.length, "Invalid size");
assertSame(ValueNamePair.EMPTY, arr[0], "First value should be EMPTY");
assertEquals(arr[1].getValue(), "1");
assertEquals(arr[2].getValue(), "2");
assertEquals(arr[3].getValue(), "3");
assertEquals(arr[4].getValue(), "4");
assertEquals(arr[5].getValue(), "6");
assertEquals(arr[6].getValue(), "7");
// Get (NO optional item)
arr = DB.getValueNamePairs(sql, false, params);
assertEquals(6, arr.length, "Invalid size");
assertEquals(arr[0].getValue(), "1");
assertEquals(arr[1].getValue(), "2");
assertEquals(arr[2].getValue(), "3");
assertEquals(arr[3].getValue(), "4");
assertEquals(arr[4].getValue(), "6");
assertEquals(arr[5].getValue(), "7");
}
@Test
public void test_getKeyNamePairs() throws Exception
{
ArrayList<Object> params = new ArrayList<Object>();
params.add(MTable.ACCESSLEVEL_AD_Reference_ID);
final String sql = "SELECT AD_Ref_List_ID, Value FROM AD_Ref_List WHERE AD_Reference_ID=? ORDER BY Value";
// Get (with optional item)
KeyNamePair[] arr = DB.getKeyNamePairs(sql, true, params);
assertEquals(6+1, arr.length, "Invalid size");
assertSame(KeyNamePair.EMPTY, arr[0], "First value should be EMPTY");
assertEquals(arr[1].getName(), "1");
assertEquals(arr[2].getName(), "2");
assertEquals(arr[3].getName(), "3");
assertEquals(arr[4].getName(), "4");
assertEquals(arr[5].getName(), "6");
assertEquals(arr[6].getName(), "7");
// Get (NO optional item)
arr = DB.getKeyNamePairs(sql, false, params);
assertEquals(6, arr.length, "Invalid size");
assertEquals(arr[0].getName(), "1");
assertEquals(arr[1].getName(), "2");
assertEquals(arr[2].getName(), "3");
assertEquals(arr[3].getName(), "4");
assertEquals(arr[4].getName(), "6");
assertEquals(arr[5].getName(), "7");
}
}

View File

@ -0,0 +1,84 @@
/**********************************************************************
* This file is part of iDempiere ERP Open Source *
* http://www.idempiere.org *
* *
* Copyright (C) Contributors *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
* Contributors: *
* - Carlos Ruiz - globalqss *
* - hengsin *
**********************************************************************/
package org.idempiere.test.base;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Arrays;
import java.util.Collection;
import org.compiere.util.EMail;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
/*
* Unit test sample from http://examples.javacodegeeks.com/core-java/util/regex/matcher/validate-email-address-with-java-regular-expression-example/
*/
public class EmailFormatValidatorTest {
public EmailFormatValidatorTest() {
}
public static Collection<Object[]> data() {
Object[][] data = new Object[][] {
{ "javacodegeeks@gmail.com.2j",true },
{ "java@java@oracle.com", false }, // you cannot have @ twice in the address
{ "java!!!@example.com", true },
{ "mysite@.com", false }, // tld cannot start with a dot
{ "javacodegees.com", false }, // must contain a @ character and a tld
{ ".javacodegees.com@at.com", false },
{ "javacodegees..javacom@at.com", false },
{ "javacodegeeks@gmail.com",true },
{ "nikos+mylist@gmail.com", true },
{ "abc.efg-900@gmail-list.com", true },
{ "abc123@example.com.gr", true },
{ "username+detail@example.com", true },
{ "user@example.museum", true },
{ "myemail+sketchysite@gmail.com", true },
{ "micky.o'finnagan@wherever.com", true },
{ "exampleemail@testing.info", true },
{ "marcelo.calbucci%mandic@fapesp.com.br", true },
{ "customer/department=shipping@example.com", true },
{ "$A12345@example.com", true },
{ "!def!xyz%abc@example.com", true },
{ "_somename@example.com", true },
{ "nuñez@globalqss.com", true },
{ "name@tld", true },
{ "john@server.department.company.com", true }
};
return Arrays.asList(data);
}
@ParameterizedTest
@MethodSource("data")
public void test(String arg, Boolean expectedValidation) {
Boolean res = EMail.validate(arg);
assertEquals(expectedValidation, res, "Result");
}
}

View File

@ -0,0 +1,322 @@
/***********************************************************************
* This file is part of iDempiere ERP Open Source *
* http://www.idempiere.org *
* *
* Copyright (C) Contributors *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
* Contributors: *
* - teo sarca *
* - hengsin *
**********************************************************************/
package org.idempiere.test.base;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Properties;
import org.adempiere.exceptions.DBException;
import org.compiere.model.MClient;
import org.compiere.model.MTest;
import org.compiere.model.POInfo;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Trx;
import org.idempiere.test.AbstractTestCase;
import org.junit.jupiter.api.Test;
/**
* Tests for {@link org.compiere.model.PO} class.
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
* @author hengsin
*/
public class POTest extends AbstractTestCase
{
public static class MyTestPO extends MTest
{
private static final long serialVersionUID = -6861171283806782985L;
protected boolean failOnSave = false;
private MyTestPO m_parent = null;
private MyTestPO m_dependentRecord = null;
public static String getName(int Test_ID, String trxName)
{
String sql = "SELECT "+COLUMNNAME_Name+" FROM "+Table_Name
+" WHERE "+COLUMNNAME_Test_ID+"=?";
return DB.getSQLValueStringEx(trxName, sql, Test_ID);
}
public static boolean exists(int Test_ID, String trxName)
{
final String sql = "SELECT "+COLUMNNAME_Test_ID+" FROM "+Table_Name
+" WHERE "+COLUMNNAME_Test_ID+"=?";
int id = DB.getSQLValueEx(trxName, sql, Test_ID);
return id > 0 && id == Test_ID;
}
public MyTestPO(Properties ctx, boolean failOnSave, String trxName)
{
super(ctx, "Test_"+System.currentTimeMillis(), 10);
this.set_TrxName(trxName);
this.setDescription(""+getClass());
this.failOnSave = failOnSave;
}
public MyTestPO(Properties ctx, int id, String trxName)
{
super(ctx, id, trxName);
}
@Override
protected boolean afterSave(boolean newRecord, boolean success)
{
if (m_parent == null)
{
m_dependentRecord = new MyTestPO(getCtx(), false, get_TrxName());
m_dependentRecord.m_parent = this;
m_dependentRecord.setName("D_"+this.getName());
m_dependentRecord.saveEx();
}
if (this.failOnSave)
throw new RuntimeException("Never save this object [trxName="+get_TrxName()+", success="+success+"]");
return true;
}
public int getDependent_ID()
{
return (m_dependentRecord != null ? m_dependentRecord.get_ID() : -1);
}
};
/**
* Tests the following methods:
* <ul>
* <li>{@link org.compiere.model.PO#is_Changed()}
* <li>{@link org.compiere.model.PO#is_ValueChanged(String)}
* </ul>
* Applies to following bugs:
* <ul>
* <li>[ 1704828 ] PO.is_Changed() and PO.is_ValueChanged are not consistent
* </ul>
*/
@Test
public void test_Changed()
{
String[] testStrings = new String[] {
"a",
"test",
};
// Create the test PO and save
MTest testPO = new MTest(Env.getCtx(), getClass().getName(), 1);
testPO.set_TrxName(getTrxName());
for (String str : testStrings)
{
testPO.setHelp(str);
testPO.saveEx();
String originalString = testPO.getHelp();
String info = "testString=[" + str + "]" + ", originalString=[" + originalString + "]";
// Initial asserts (nothing changed)
assertFalse(testPO.is_ValueChanged(MTest.COLUMNNAME_Help), info);
assertFalse(testPO.is_Changed(), info);
// Set the same name
testPO.setHelp(originalString);
assertFalse(testPO.is_ValueChanged(MTest.COLUMNNAME_Help), info);
assertFalse(testPO.is_Changed(), info);
// Set a new name
testPO.setHelp(originalString+"-changed");
assertTrue(testPO.is_ValueChanged(MTest.COLUMNNAME_Help), info);
assertTrue(testPO.is_Changed(), info);
// Set the original name back
testPO.setHelp(originalString);
assertFalse(testPO.is_ValueChanged(MTest.COLUMNNAME_Help), info);
assertFalse(testPO.is_Changed(), info);
}
// Finally, delete the testPO
testPO.delete(true, getTrxName());
}
/**
* <li>BF [ 1990856 ] PO.set_Value* : truncate string more than needed
*/
@Test
public void testTruncatedStrings() {
//
// Creating a huge string for testing:
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= 1000; i++) {
sb.append("0123456789");
}
String bigString = sb.toString();
//
// Create the test PO:
MTest testPO = new MTest(Env.getCtx(), getClass().getName(), 1);
testPO.set_TrxName(getTrxName());
//
// Getting Max Length:
POInfo info = POInfo.getPOInfo(Env.getCtx(), MTest.Table_ID);
int maxLength = info.getFieldLength(info.getColumnIndex(MTest.COLUMNNAME_Name));
//
// Test with a string that has less then maxLength
{
testPO.set_ValueOfColumn(MTest.COLUMNNAME_Name, bigString.substring(0, maxLength - 1));
String resultString = (String) testPO.get_Value(MTest.COLUMNNAME_Name);
assertEquals(maxLength - 1, resultString.length(), "String was not truncated correctly (1)");
//
testPO.setName(bigString.substring(0, maxLength - 1));
assertEquals(maxLength - 1, testPO.getName().length(), "String was not truncated correctly (2)");
}
//
// Test with a string that has maxLength
{
testPO.set_ValueOfColumn(MTest.COLUMNNAME_Name, bigString.substring(0, maxLength));
String resultString = (String) testPO.get_Value(MTest.COLUMNNAME_Name);
assertEquals(maxLength, resultString.length(), "String was not truncated correctly (3)");
//
testPO.setName(bigString.substring(0, maxLength));
assertEquals(maxLength, testPO.getName().length(), "String was not truncated correctly (4)");
}
//
// Test with a string that has more than maxLength
{
testPO.set_ValueOfColumn(MTest.COLUMNNAME_Name, bigString);
String resultString = (String) testPO.get_Value(MTest.COLUMNNAME_Name);
assertEquals(maxLength, resultString.length(), "String was not truncated correctly (5)");
//
testPO.setName(bigString);
assertEquals(maxLength, testPO.getName().length(), "String was not truncated correctly (6)");
}
}
/**
* Object should NOT be saved if afterSave fails EVEN if is outside transaction (trxName=null)
*/
@Test
public void testAfterSaveError()
{
//
// Test for new objects
{
MyTestPO test = new MyTestPO(Env.getCtx(), true, null);
assertFalse(test.save(), "Object should not be saved -- "+test);
assertFalse(test.get_ID() <= 0, "Object should not be saved -- "+test);
assertFalse(MyTestPO.exists(test.get_ID(), null), "Object should not be saved(2) -- "+test);
}
//
// Test for old objects
{
MyTestPO test = new MyTestPO(Env.getCtx(), false, null);
assertTrue(test.save(), "Object *should* be saved -- "+test);
//
MyTestPO test2 = new MyTestPO(Env.getCtx(), test.get_ID(), null);
assertEquals(test2.get_ID(), test.get_ID(), "Object not found");
test2.failOnSave = true;
test2.setName(test2.getName()+"_2");
assertFalse(test2.save(), "Object should not be saved -- "+test2);
//
String name = MyTestPO.getName(test2.get_ID(), null);
assertEquals(test.getName(), name, "Object should not be modified(2) -- id="+test2);
}
}
/**
* If one object fails on after save we should not revert all transaction.
* BF [ 2849122 ] PO.AfterSave is not rollback on error
* https://sourceforge.net/tracker/index.php?func=detail&aid=2849122&group_id=176962&atid=879332#
*/
@Test
public void testAfterSaveError_BF2849122()
{
assertNotNull(getTrxName(), "TrxName should not be null");
MyTestPO t1 = new MyTestPO(Env.getCtx(), false, getTrxName());
t1.saveEx();
assertTrue(MyTestPO.exists(t1.get_ID(), getTrxName()), "Object not found(1) - t1="+t1);
assertTrue(MyTestPO.exists(t1.getDependent_ID(), getTrxName()), "Object not found(1) - t1(dep)="+t1);
//
final MyTestPO t2 = new MyTestPO(Env.getCtx(), true, getTrxName());
try
{
t2.saveEx();
}
catch (Exception e){}
assertTrue(MyTestPO.exists(t1.get_ID(), getTrxName()), "Object not found(2) - t1="+t1);
assertTrue(MyTestPO.exists(t1.getDependent_ID(), getTrxName()), "Object not found(2) - t1(dep)="+t1);
assertFalse(MyTestPO.exists(t2.get_ID(), getTrxName()), "Object found(2) - t2="+t2);
assertFalse(MyTestPO.exists(t2.getDependent_ID(), getTrxName()), "Object found(2) - t2(dep)="+t2);
//
final MyTestPO t3 = new MyTestPO(Env.getCtx(), false, getTrxName());
t3.saveEx();
assertTrue(MyTestPO.exists(t1.get_ID(), getTrxName()), "Object not found(3) - t1="+t1);
assertTrue(MyTestPO.exists(t1.getDependent_ID(), getTrxName()), "Object not found(3) - t1(dep)="+t1);
assertFalse(MyTestPO.exists(t2.get_ID(), getTrxName()), "Object found(3) - t2="+t2);
assertFalse(MyTestPO.exists(t2.getDependent_ID(), getTrxName()), "Object found(3) - t2(dep)="+t2);
assertTrue(MyTestPO.exists(t3.get_ID(), getTrxName()), "Object not found(3) - t3="+t3);
assertTrue(MyTestPO.exists(t3.getDependent_ID(), getTrxName()), "Object not found(3) - t3(dep)="+t3);
}
@Test
public void testForUpdate()
{
MClient client = new MClient(Env.getCtx(), Env.getAD_Client_ID(Env.getCtx()), getTrxName());
assertDoesNotThrow(() -> {
boolean ok = DB.getDatabase().forUpdate(client, 5);
assertTrue(ok);
});
Trx trx2 = Trx.get(Trx.createTrxName(), true);
try {
trx2.start();
MClient client2 = new MClient(Env.getCtx(), Env.getAD_Client_ID(Env.getCtx()), trx2.getTrxName());
assertThrows(DBException.class, () -> {
DB.getDatabase().forUpdate(client2, 5);
});
} finally {
trx2.close();
}
String description = client.getDescription();
client.setDescription(client.getName()+".Description");
assertDoesNotThrow(() -> {
client.saveEx();
});
rollback();
client.load(getTrxName());
assertEquals(description, client.getDescription());
Trx trx3 = Trx.get(Trx.createTrxName(), true);
try {
trx3.start();
MClient client3 = new MClient(Env.getCtx(), Env.getAD_Client_ID(Env.getCtx()), trx3.getTrxName());
assertDoesNotThrow(() -> {
boolean ok = DB.getDatabase().forUpdate(client3, 5);
assertTrue(ok);
});
} finally {
trx3.close();
}
}
}

View File

@ -0,0 +1,326 @@
/***********************************************************************
* This file is part of iDempiere ERP Open Source *
* http://www.idempiere.org *
* *
* Copyright (C) Contributors *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
* Contributors: *
* - hengsin *
**********************************************************************/
package org.idempiere.test.base;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.adempiere.exceptions.DBException;
import org.compiere.model.MTable;
import org.compiere.model.POResultSet;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Element;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
import org.idempiere.test.AbstractTestCase;
import org.junit.jupiter.api.Test;
/**
* @author hengsin
*
*/
public class QueryTest extends AbstractTestCase {
/**
*
*/
public QueryTest() {
}
@Test
public void testNoTable() {
assertThrows(IllegalArgumentException.class, () -> {
new Query(Env.getCtx(), "NO_TABLE_DEFINED", null, getTrxName());
});
}
@Test
public void testList() throws Exception
{
List<MTable> list = new Query(Env.getCtx(), "AD_Table", "TableName IN (?,?)", getTrxName())
.setParameters(new Object[]{"C_Invoice", "M_InOut"})
.setOrderBy("TableName")
.list();
assertEquals(2, list.size(), "Invalid list size");
assertEquals(list.get(0).getTableName(), "C_Invoice", "Invalid object 1");
assertEquals(list.get(1).getTableName(), "M_InOut", "Invalid object 2");
}
@Test
public void testScroll() throws Exception
{
POResultSet<MTable> rs = new Query(Env.getCtx(), "AD_Table", "TableName IN (?,?)", getTrxName())
.setParameters(new Object[]{"C_Invoice", "M_InOut"})
.setOrderBy("TableName")
.scroll();
try
{
int i = 0;
while (rs.hasNext())
{
MTable t = rs.next();
if (i == 0)
{
assertEquals("C_Invoice", t.getTableName(), "Invalid object "+i);
}
else if (i == 1)
{
assertEquals("M_InOut", t.getTableName(), "Invalid object "+i);
}
else
{
fail("More objects retrived than expected");
}
i++;
}
}
finally
{
DB.close(rs);
}
}
@Test
public void testIterate() throws Exception
{
Iterator<MTable> it = new Query(Env.getCtx(), "AD_Table", "TableName IN (?,?)", getTrxName())
.setParameters(new Object[]{"C_Invoice", "M_InOut"})
.setOrderBy("TableName")
.iterate();
int i = 0;
while(it.hasNext())
{
MTable t = it.next();
if (i == 0)
{
assertEquals("C_Invoice", t.getTableName(), "Invalid object "+i);
}
else if (i == 1)
{
assertEquals("M_InOut", t.getTableName(), "Invalid object "+i);
}
else
{
fail("More objects retrived than expected");
}
i++;
}
}
@Test
public void testCount() throws Exception
{
int count = new Query(Env.getCtx(), "AD_Table", "TableName IN (?,?)", getTrxName())
.setParameters(new Object[]{"C_Invoice", "M_InOut"})
.setOrderBy("TableName")
.count();
assertEquals(2, count, "Invalid count");
}
@Test
public void testCount_BadSQL() throws Exception
{
assertThrows(DBException.class, () -> {
new Query(Env.getCtx(), "AD_Table", "TableName IN (?,?) AND BAD_SQL", getTrxName())
.setParameters(new Object[]{"C_Invoice", "M_InOut"})
.setOrderBy("TableName")
.count();
});
}
@Test
public void testCount_NoValues() throws Exception
{
int count = new Query(Env.getCtx(), "AD_Table", "1=2", getTrxName()).count();
assertEquals(0, count, "Counter should be ZERO");
}
@Test
public void testFirst() throws Exception
{
MTable t = new Query(Env.getCtx(), "AD_Table", "TableName IN (?,?)", getTrxName())
.setParameters(new Object[]{"C_Invoice", "M_InOut"})
.setOrderBy("TableName")
.first();
assertEquals("C_Invoice", t.getTableName(), "Invalid object");
}
@Test
public void testFirstId() throws Exception
{
int id = new Query(Env.getCtx(), "AD_Table", "TableName IN (?,?)", getTrxName())
.setParameters(new Object[]{"C_Invoice", "M_InOut"})
.setOrderBy("TableName")
.firstId();
int expectedId = 318; // C_Invoice
assertEquals(expectedId, id, "Invalid ID");
}
@Test
public void testFirstOnly() throws Exception
{
MTable t = new Query(Env.getCtx(), "AD_Table", "AD_Table_ID=?", getTrxName())
.setParameters(new Object[]{318})
.firstOnly();
assertEquals(318, t.get_ID(), "Invalid table ID");
//
assertThrows(DBException.class, () -> {
new Query(Env.getCtx(), "AD_Table", "TableName IN (?,?)", getTrxName())
.setParameters(new Object[]{"C_Invoice", "M_InOut"})
.setOrderBy("TableName")
.firstOnly();
});
}
@Test
public void testFirstIdOnly() throws Exception
{
int expectedId = 318; // C_Invoice
int id = new Query(Env.getCtx(), "AD_Table", "AD_Table_ID=?", getTrxName())
.setParameters(new Object[]{expectedId})
.firstIdOnly();
assertEquals(expectedId, id, "Invalid table ID");
//
assertThrows(DBException.class, () -> {
new Query(Env.getCtx(), "AD_Table", "TableName IN (?,?)", getTrxName())
.setParameters(new Object[]{"C_Invoice", "M_InOut"})
.setOrderBy("TableName")
.firstIdOnly();
});
}
@Test
public void testSetClient_ID() throws Exception
{
int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
String sql = "SELECT COUNT(*) FROM C_Invoice WHERE IsActive='Y' AND AD_Client_ID="+AD_Client_ID;
int targetCount = DB.getSQLValue(null, sql);
//
int count = new Query(Env.getCtx(), "C_Invoice", "1=1", getTrxName())
.setOnlyActiveRecords(true)
.setClient_ID()
.count();
assertEquals(targetCount, count, "Invoice # not match");
}
@Test
public void testGet_IDs() throws Exception
{
final String whereClause = "AD_Element_ID IN (101, 102)";
int[] ids = new Query(Env.getCtx(), "AD_Element", whereClause, getTrxName())
.setOrderBy("AD_Element_ID")
.getIDs();
assertNotNull(ids);
assertEquals(2, ids.length);
assertEquals(101, ids[0]);
assertEquals(102, ids[1]);
}
@Test
public void testAggregate() throws Exception
{
final int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
final String sqlFrom = "FROM C_InvoiceLine WHERE IsActive='Y' AND AD_Client_ID="+AD_Client_ID;
final Query query = new Query(Env.getCtx(), "C_InvoiceLine", null, getTrxName())
.setOnlyActiveRecords(true)
.setClient_ID();
//
// Test COUNT:
assertEquals(DB.getSQLValueBDEx(getTrxName(), "SELECT COUNT(*) "+sqlFrom),
query.aggregate(null, Query.AGGREGATE_COUNT), "COUNT not match");
//
// Test SUM:
assertEquals(DB.getSQLValueBDEx(getTrxName(), "SELECT SUM(LineNetAmt+TaxAmt) "+sqlFrom),
query.aggregate("LineNetAmt+TaxAmt", Query.AGGREGATE_SUM), "SUM not match");
//
// Test MIN:
assertEquals(DB.getSQLValueBDEx(getTrxName(), "SELECT MIN(LineNetAmt) "+sqlFrom),
query.aggregate("LineNetAmt", Query.AGGREGATE_MIN), "MIN not match");
//
// Test MAX:
assertEquals(DB.getSQLValueBDEx(getTrxName(), "SELECT MAX(LineNetAmt) "+sqlFrom),
query.aggregate("LineNetAmt", Query.AGGREGATE_MAX), "MAX not match");
//
// Test aggregate (String) - FR [ 2726447 ]
assertEquals(DB.getSQLValueStringEx(getTrxName(), "SELECT MAX(Description) "+sqlFrom),
(String)query.aggregate("Description", Query.AGGREGATE_MAX, String.class), "MAX not match (String)");
//
// Test aggregate (Timestamp) - FR [ 2726447 ]
assertEquals(DB.getSQLValueTSEx(getTrxName(), "SELECT MAX(Updated) "+sqlFrom),
(Timestamp)query.aggregate("Updated", Query.AGGREGATE_MAX, Timestamp.class), "MAX not match (Timestamp)");
//
// Test Exception : No Aggregate Function defined
assertThrows(DBException.class, () -> {
query.aggregate("*", null);
},
"No Aggregate Function defined"
);
//
// Test Exception : No Expression defined
assertThrows(DBException.class, () -> {
query.aggregate(null, Query.AGGREGATE_SUM);
}, "No Expression defined");
}
@Test
public void testOnlySelection() throws Exception
{
// Get one AD_PInstance_ID
int AD_PInstance_ID = DB.getSQLValueEx(null, "SELECT MAX(AD_PInstance_ID) FROM AD_PInstance");
assertTrue(AD_PInstance_ID > 0);
// Create selection list
List<KeyNamePair> elements = new ArrayList<KeyNamePair> ();
elements.add(new KeyNamePair(102, null)); // AD_Element_ID=102 => AD_Client_ID
elements.add(new KeyNamePair(104, null)); // AD_Element_ID=104 => AD_Column_ID
DB.executeUpdateEx("DELETE FROM T_Selection WHERE AD_PInstance_ID="+AD_PInstance_ID, getTrxName());
DB.createT_SelectionNew (AD_PInstance_ID, elements, getTrxName());
String whereClause = "1=1"; // some dummy where clause
int[] ids = new Query(Env.getCtx(), X_AD_Element.Table_Name, whereClause, getTrxName())
.setOnlySelection(AD_PInstance_ID)
.setOrderBy(X_AD_Element.COLUMNNAME_AD_Element_ID)
.getIDs();
assertEquals(elements.size(), ids.length, "Resulting number of elements differ");
for (int i = 0; i < elements.size(); i++)
{
int expected = elements.get(i).getKey();
assertEquals(expected, ids[i], "Element "+i+" not equals");
}
}
}

View File

@ -53,6 +53,7 @@
<module>org.idempiere.webservices.client-feature</module>
<module>org.idempiere.p2</module>
<module>org.idempiere.javadoc</module>
<module>org.idempiere.test</module>
<module>${idempiere.target}</module>
</modules>