Skip to content

Commit

Permalink
#1454 Junit tests supported for openjdk 11
Browse files Browse the repository at this point in the history
  • Loading branch information
Limraj committed Dec 7, 2020
1 parent fd8ce40 commit bd70e6b
Show file tree
Hide file tree
Showing 33 changed files with 136 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ jdk:
services:
- docker
- mysql
script: ant war
script: ant war && ant junit
branches:
only:
- "/^develop.*$/"
- "/^master.*$/"
- "/^release/2.4.0.*$/"
- "/^feature/#1454.*$/"
notifications:
email: false
env:
Expand Down
25 changes: 12 additions & 13 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,18 @@
</path>
<path id="test-unit.classpath">
<pathelement location="lib/junit-4.12.jar"/>
<pathelement location="lib/mockito-all-1.10.19.jar"/>
<pathelement location="lib/powermock-api-mockito-1.6.6.jar"/>
<pathelement location="lib/powermock-core-1.6.6.jar"/>
<pathelement location="lib/powermock-module-junit4-1.6.6.jar"/>
<pathelement location="lib/powermock-reflect-1.6.6.jar"/>
<pathelement location="lib/powermock-api-support-1.6.6.jar"/>
<pathelement location="lib/powermock-module-junit4-common-1.6.6.jar"/>
<pathelement location="lib/powermock-api-mockito-common-1.6.6.jar"/>
<pathelement location="lib/javassist-3.21.0-GA.jar"/>
<pathelement location="lib/mockito-core-2.28.2.jar"/>
<pathelement location="lib/powermock-api-mockito2-2.0.7.jar"/>
<pathelement location="lib/powermock-core-2.0.7.jar"/>
<pathelement location="lib/powermock-module-junit4-2.0.7.jar"/>
<pathelement location="lib/powermock-reflect-2.0.7.jar"/>
<pathelement location="lib/powermock-api-support-2.0.7.jar"/>
<pathelement location="lib/powermock-module-junit4-common-2.0.7.jar"/>
<pathelement location="lib/javassist-3.27.0-GA.jar"/>
<pathelement location="lib/byte-buddy-1.9.10.jar"/>
<pathelement location="lib/byte-buddy-agent-1.9.10.jar"/>
<pathelement location="lib/objenesis-3.0.1.jar"/>
<pathelement location="lib/hamcrest-core-1.3.jar"/>
</path>
<path id="Web App Libraries.libraryclasspath">
<pathelement location="WebContent/WEB-INF/lib/OneWireAPI.jar"/>
Expand Down Expand Up @@ -171,9 +174,6 @@
<pathelement location="WebContent/WEB-INF/lib/xfire-aegis-1.2.6.jar"/>
<pathelement location="WebContent/WEB-INF/lib/xfire-core-1.2.6.jar"/>
<pathelement location="WebContent/WEB-INF/lib/xmlsec-1.4.3.jar"/>
<!--pathelement location="WebContent/WEB-INF/lib/junit-4.8.2.jar"/>
<pathelement location="WebContent/WEB-INF/lib/mockito-all-1.9.5.jar"/>
<pathelement location="WebContent/WEB-INF/lib/mockito-core-2.11.0.jar"/-->
<pathelement location="WebContent/WEB-INF/classes"/>
</path>
<path id="EAR Libraries.libraryclasspath"/>
Expand Down Expand Up @@ -226,7 +226,6 @@
<pathelement location="WebContent/WEB-INF/lib/bacnet4J.jar"/>
<pathelement location="WebContent/WEB-INF/lib/sqljdbc4.jar"/>
<pathelement location="WebContent/WEB-INF/lib/alpha24j.jar"/>
<!--pathelement location="lib/mockito-all-1.9.5.jar"/-->
<pathelement location="WebContent/WEB-INF/lib/joda-time-2.3.jar"/>
<pathelement location="WebContent/WEB-INF/lib/modbus4j-2.0.2.jar"/>
<path refid="Apache Tomcat v7.0 [Apache Tomcat v7.0].libraryclasspath"/>
Expand Down
Binary file added lib/byte-buddy-1.9.10.jar
Binary file not shown.
Binary file added lib/byte-buddy-agent-1.9.10.jar
Binary file not shown.
Binary file added lib/hamcrest-core-1.3.jar
Binary file not shown.
Binary file removed lib/javassist-3.21.0-GA.jar
Binary file not shown.
Binary file added lib/javassist-3.27.0-GA.jar
Binary file not shown.
Binary file removed lib/mockito-all-1.10.19.jar
Binary file not shown.
Binary file added lib/mockito-core-2.28.2.jar
Binary file not shown.
Binary file added lib/objenesis-3.0.1.jar
Binary file not shown.
Binary file removed lib/powermock-api-mockito-1.6.6.jar
Binary file not shown.
Binary file removed lib/powermock-api-mockito-common-1.6.6.jar
Binary file not shown.
Binary file added lib/powermock-api-mockito2-2.0.7.jar
Binary file not shown.
Binary file removed lib/powermock-api-support-1.6.6.jar
Binary file not shown.
Binary file added lib/powermock-api-support-2.0.7.jar
Binary file not shown.
Binary file removed lib/powermock-core-1.6.6.jar
Binary file not shown.
Binary file added lib/powermock-core-2.0.7.jar
Binary file not shown.
Binary file removed lib/powermock-module-junit4-1.6.6.jar
Binary file not shown.
Binary file added lib/powermock-module-junit4-2.0.7.jar
Binary file not shown.
Binary file removed lib/powermock-module-junit4-common-1.6.6.jar
Binary file not shown.
Binary file added lib/powermock-module-junit4-common-2.0.7.jar
Binary file not shown.
Binary file removed lib/powermock-reflect-1.6.6.jar
Binary file not shown.
Binary file added lib/powermock-reflect-2.0.7.jar
Binary file not shown.
87 changes: 87 additions & 0 deletions test/WEB-INF/classes/env.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#
# Mango - Open Source M2M - http://mango.serotoninsoftware.com
# Copyright (C) 2006-2009 Serotonin Software Technologies Inc.
# @author Matthew Lohbihler
#
# 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 3 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, see <http://www.gnu.org/licenses/>.
#
#

# PARA INTEGRAR O ScadaBR AO POSTGRESQL v9.2 INSTALE O POSTGRESQL v9.2 NA M\u00c1QUINA SERVIDORA
# ALTERE A LINHA db.password=admin (COLOQUE A SENHA DEFINIDA POR VOC\u00ca)
# N\u00c3O REMOVA A LINHA db.url.public=jdbc:postgresql://localhost:5432/postgres

#testowy!!!!

#db.type=postgres
#db.url=jdbc:postgresql://localhost:5432/scadabr
#db.url.public=jdbc:postgresql://localhost:5432/postgres
#db.username=postgres
#db.password=admin
#db.pool.maxActive=10
#db.pool.maxIdle=10

db.type=mysql
db.datasource=true
db.datasourceName=java:comp/test_env/jdbc/scadalts
#db.url=jdbc:mysql://localhost:3306/scadalts
#db.username=root
#db.password=root
#db.pool.maxActive=10
#db.pool.maxIdle=10
#db.update.log.dir=logs
#db.upgrade.check=false

#db.type=derby
#db.url=~../../bin/scadabrDB
#db.username=
#db.password=

js.optimizationlevel=-1

api.authentication=disabled
api.username=admin
api.password=admin

abilit.disableDataSourcesOnServerStart=false

abilit.api.replace.alert.onview=true


abilit.cacheEnable=true
abilit.START_UPDATE_UNSILENCED_ALARM_LEVEL=100000
abilit.START_UPDATE_EVENT_DETECTORS=100000
abilit.START_UPDATE_PENDING_EVENTS=100000
abilit.MILLIS_SECONDS_PERIOD_UPDATE_UNSILENCED_ALARM_LEVEL=1000
abilit.MILLIS_SECONDS_PERIOD_UPDATE_EVENT_DETECTORS=1000
abilit.MILLIS_SECONDS_PERIOD_UPDATE_PENDING_EVENTS=1000
abilit.CRONE_UPDATE_CACHE_POINT_HIERARCHY=0 0/10 * * * ?

# every minute
abilit.CRONE_UPDATE_DATA_SOURCES_POINTS=0 0/1 * * * ?
abilit.USE_CACHE_DATA_SOURCES_POINTS_WHEN_THE_SYSTEM_IS_READY=true

#Permission ACL
abilit.USE_ACL=false
abilit.ACL_SERVER=http://localhost:8090

#Events
abilit.DO_NOT_CREATE_EVENTS_FOR_EMAIL_ERROR=true

#Reactivation HttpRetriver
abilit.HTTP_RETRIVER_SLEEP_CHECK_TO_REACTIVATION_WHEN_START=false
abilit.HTTP_RETRIVER_DO_NOT_ALLOW_ENABLE_REACTIVATION=false

#security.hashAlgorithm=NONE
#grove.url=http://mango.serotoninsoftware.com/servlet
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import br.org.scadabr.rt.scripting.context.ScriptContextObject;
import com.serotonin.mango.Common;
import com.serotonin.mango.rt.RuntimeManager;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import utils.ScriptTestUtils;
import com.serotonin.mango.rt.dataImage.DataPointRT;
import com.serotonin.mango.rt.dataImage.IDataPoint;
Expand Down Expand Up @@ -34,6 +35,9 @@
@PrepareForTest({DAO.class, PointValueCache.class, Permissions.class,
ContextualizedScriptRT.class, ScriptContextObject.class,
ScriptExecutor.class, Common.class})
// resources/org/powermock/extensions/configuration.properties is not working
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "org.w3c.*", "com.sun.org.apache.xalan.*",
"javax.activation.*", "javax.management.*"})
public class ScriptExecutorTest {

@Before
Expand Down
4 changes: 4 additions & 0 deletions test/com/serotonin/mango/rt/scripting/ScriptTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
Expand All @@ -39,6 +40,9 @@
@PrepareForTest({DAO.class, PointValueCache.class, Permissions.class,
ContextualizedScriptRT.class, ScriptContextObject.class,
Common.class})
// resources/org/powermock/extensions/configuration.properties is not working
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "org.w3c.*", "com.sun.org.apache.xalan.*",
"javax.activation.*", "javax.management.*"})
public class ScriptTest {

@Parameterized.Parameters(name = "{index}: value: {0}, point context: {2}, script: {3}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.serotonin.db.IntValuePair;
import com.serotonin.mango.Common;
import com.serotonin.mango.rt.RuntimeManager;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import utils.ScriptTestUtils;
import com.serotonin.mango.rt.dataImage.PointValueCache;
import com.serotonin.mango.vo.permission.Permissions;
Expand Down Expand Up @@ -35,6 +36,9 @@
@PrepareForTest({DAO.class, PointValueCache.class, Permissions.class,
ContextualizedScriptRT.class, ScriptContextObject.class,
Common.class})
// resources/org/powermock/extensions/configuration.properties is not working
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "org.w3c.*", "com.sun.org.apache.xalan.*",
"javax.activation.*", "javax.management.*"})
public class ScriptWithObjectContextEnableDisableDataPointTest {

private static String pointToChangeXid = "DP_093765";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.serotonin.db.IntValuePair;
import com.serotonin.mango.Common;
import com.serotonin.mango.rt.RuntimeManager;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import utils.ScriptTestUtils;
import com.serotonin.mango.rt.dataImage.PointValueCache;
import com.serotonin.mango.vo.permission.Permissions;
Expand All @@ -32,6 +33,9 @@
@PrepareForTest({DAO.class, PointValueCache.class, Permissions.class,
ContextualizedScriptRT.class, ScriptContextObject.class,
Common.class})
// resources/org/powermock/extensions/configuration.properties is not working
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "org.w3c.*", "com.sun.org.apache.xalan.*",
"javax.activation.*", "javax.management.*"})
public class ScriptWithObjectContextEnableDisableDataSourceTest {

private static String sourceToChangeXid = "DP_093765";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.serotonin.db.IntValuePair;
import com.serotonin.mango.Common;
import com.serotonin.mango.rt.RuntimeManager;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import utils.IntValuePairPrinted;
import utils.ScriptTestUtils;
import com.serotonin.mango.rt.dataImage.DataPointRT;
Expand Down Expand Up @@ -36,6 +37,9 @@
@PrepareForTest({DAO.class, PointValueCache.class, Permissions.class,
ContextualizedScriptRT.class, ScriptContextObject.class,
Common.class})
// resources/org/powermock/extensions/configuration.properties is not working
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "org.w3c.*", "com.sun.org.apache.xalan.*",
"javax.activation.*", "javax.management.*"})
public class ScriptWithObjectContextWriteDataPointTest {

private static String pointToChangeXid = "DP_093765";
Expand Down
11 changes: 5 additions & 6 deletions test/com/serotonin/mango/view/component/ButtonComponentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@
import com.serotonin.mango.rt.dataImage.DataPointRT;
import com.serotonin.mango.rt.dataImage.PointValueCache;
import com.serotonin.mango.rt.dataImage.PointValueTime;
import com.serotonin.mango.rt.dataImage.types.AlphanumericValue;
import com.serotonin.mango.rt.dataImage.types.BinaryValue;
import com.serotonin.mango.rt.dataImage.types.MultistateValue;
import com.serotonin.mango.rt.dataImage.types.NumericValue;

import com.serotonin.mango.rt.dataSource.meta.ScriptExecutor;
import com.serotonin.mango.view.text.MultistateRenderer;
import com.serotonin.mango.view.text.TextRenderer;
import com.serotonin.mango.vo.DataPointVO;
import com.serotonin.mango.vo.User;
import com.serotonin.mango.vo.permission.Permissions;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.scada_lts.dao.DAO;
Expand All @@ -32,14 +30,15 @@
import java.util.Map;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.powermock.api.mockito.PowerMockito.mockStatic;


@RunWith(PowerMockRunner.class)
@PrepareForTest({DAO.class, PointValueCache.class, Permissions.class,
ContextualizedScriptRT.class, ScriptContextObject.class,
ScriptExecutor.class, Common.class})
// resources/org/powermock/extensions/configuration.properties is not working
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "org.w3c.*", "com.sun.org.apache.xalan.*",
"javax.activation.*", "javax.management.*"})
public class ButtonComponentTest {

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
import com.serotonin.mango.vo.permission.Permissions;
import com.serotonin.util.PropertiesUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.scada_lts.dao.DAO;
Expand All @@ -37,6 +37,9 @@
@PrepareForTest({DAO.class, PointValueCache.class, Permissions.class,
ContextualizedScriptRT.class, ScriptContextObject.class,
ScriptExecutor.class, Common.class, ScriptComponent.class})
// resources/org/powermock/extensions/configuration.properties is not working
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "org.w3c.*", "com.sun.org.apache.xalan.*",
"javax.activation.*", "javax.management.*"})
public class ScriptComponentTest {

@BeforeClass
Expand Down
2 changes: 1 addition & 1 deletion test/env.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

db.type=mysql
db.datasource=true
db.datasourceName=java:comp/env/jdbc/scadalts
db.datasourceName=java:comp/test_env/jdbc/scadalts
#db.url=jdbc:mysql://localhost:3306/scadalts
#db.username=root
#db.password=root
Expand Down
9 changes: 5 additions & 4 deletions test/utils/ScriptTestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import javax.servlet.ServletContext;
import java.util.Collections;
import java.util.List;
import java.util.ResourceBundle;

import static org.mockito.ArgumentMatchers.contains;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.when;
Expand Down Expand Up @@ -69,7 +69,8 @@ public static void configMock(RuntimeManager runtimeManager, ScriptContextObject
Common.ctx = contextWrapper;
when(contextWrapper.getRuntimeManager()).thenReturn(runtimeManager);
when(contextWrapper.getServletContext()).thenReturn(servletContext);
when(servletContext.getRealPath(anyString())).thenReturn("test/scriptFunctions.js");
when(servletContext.getRealPath(contains("scriptFunctions"))).thenReturn("test/scriptFunctions.js");
when(servletContext.getRealPath(eq(""))).thenReturn("test/");

PointValueDao pointValueDao = mock(PointValueDao.class);
whenNew(PointValueDao.class)
Expand Down Expand Up @@ -97,7 +98,7 @@ public static void configMock(RuntimeManager runtimeManager, ScriptContextObject
mockStatic(Common.class);
when(Common.getUser()).thenReturn(user);

PropertiesUtils propertiesUtils = new PropertiesUtils("env");
PropertiesUtils propertiesUtils = new PropertiesUtils("WEB-INF/classes/env");
when(Common.getEnvironmentProfile()).thenReturn(propertiesUtils);

mockStatic(Permissions.class);
Expand Down

0 comments on commit bd70e6b

Please sign in to comment.