Specifying filenames for ant junit batchtest - ant

I have a working ant-task that runs me a batch of junit-tests, in the following fashion:
<junit printsummary="yes" showoutput="yes" haltonfailure="no">
<formatter type="plain" />
<classpath>
<path refid="app.compile.classpath" />
<path id="classes" location="${app.classes.home}" />
<path id="test-classes" location="${app.build.home}/test-classes" />
</classpath>
<batchtest fork="no" todir="${app.tests.reports}">
<fileset dir="${app.tests.home}">
<include name="**/*Test*.java" />
</fileset>
</batchtest>
</junit>
Now this works fine right now, except for the names of the Test-reports that are generated. These names are overly long and follow the pattern:
TEST-com.company.package.Class.txt
Is there a way for specify a file-naming pattern for the report files for batchtest, preferrably for ant 1.6.5?
I know that for a single test, you can specify a filename by using the outfile attribute. In the junit-task reference, it's just stated that:
It then generates a test class name for each resource that ends in .java or .class.

No, it's not possible.
According to the source code
protected void execute(JUnitTest arg, int thread) throws BuildException {
validateTestName(arg.getName());
JUnitTest test = (JUnitTest) arg.clone();
test.setThread(thread);
// set the default values if not specified
//#todo should be moved to the test class instead.
if (test.getTodir() == null) {
test.setTodir(getProject().resolveFile("."));
}
if (test.getOutfile() == null) {
test.setOutfile("TEST-" + test.getName());
}
// execute the test and get the return code
TestResultHolder result = null;
if (!test.getFork()) {
result = executeInVM(test);
} else {
ExecuteWatchdog watchdog = createWatchdog();
result = executeAsForked(test, watchdog, null);
// null watchdog means no timeout, you'd better not check with null
}
actOnTestResult(result, test, "Test " + test.getName());
}
it will create the out file as "TEST-" + test.getName() if you don't specify it explicitly in the test element. It's not possible to specify it in batchtest element.

Related

phpunit not marking test as completed and successful

I'm having issues getting phpunit to positively test a method i created. im using a zend application and the ApplicationTest works fine. Here's my current command line output:
ApplicationTest\Controller\IndexController
[x] Sample not active
[x] Index action can be accessed
[x] Index action view model template rendered within layout
[x] Invalid route does not crash
PlutoTest\Stdlib\ArrayUtils
[ ] Sample not active
As you can see, there is no X inside my ArrayUtils test. I even put the method inside the ApplicationTest and you can see it executed correctly.
Here's the phpunit class:
namespace PlutoTest\Stdlib;
use Pluto\Stdlib\ArrayUtils;
use Pluto\pluto;
use PHPUnit\Framework\TestCase;
class ArrayUtilsTest extends TestCase
{
public function setUp()
{
$configOverrides = [];
$phpunitConfigFile=$this->getNormalizedPhpunitConfigFile();
$this->setApplicationConfig(ArrayUtils::merge(
include $phpunitConfigFile,
$configOverrides
));
parent::setUp();
}
private function getNormalizedPhpunitConfigFile()
{
$file = sprintf('%s/application.phpunit.php',pluto::path('zfconfig'));
return $file;
}
public function testSampleNotActive()
{
$stack = [];
$this->assertEquals(0, count($stack));
array_push($stack, 'foo');
$this->assertEquals('foo', $stack[count($stack)-1]);
$this->assertEquals(1, count($stack));
$this->assertEquals('foo', array_pop($stack));
$this->assertEquals(0, count($stack));
}
}
Here's my phpunit.xml:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
bootstrap="bootstrap.phpunit.php"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
backupGlobals="true"
backupStaticAttributes="false"
cacheTokens="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
timeoutForSmallTests="1"
timeoutForMediumTests="10"
timeoutForLargeTests="60"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestSize="true"
verbose="true">
<testsuites>
<testsuite name="Application Module Test Suite">
<directory phpVersion="7.0.0" phpVersionOperator=">=">./module/Application/test</directory>
<directory phpVersion="7.0.0" phpVersionOperator=">=">./test/pluto/src</directory>
</testsuite>
</testsuites>
<php>
<env name="APPLICATION_ENV" value="development"/>
<ini name="display_errors" value="1"/>
<ini name="display_startup_errors" value="1"/>
<ini name="error_reporting" value="32767"/>
<ini name="report_memleaks" value="1"/>
</php>
</phpunit>
And here's my composer:
"autoload-dev" : {
"psr-4" : {
"ApplicationTest\\" : "module/Application/test/",
"PlutoTest\\" : "test/pluto/src"
}
},
Try changing as the following:
"autoload-dev": {
"psr-4": {
...
"YourModuleNameTest\\": "module/YourModuleName/test/"
}
},
If done, do not forget to run dump-autoload through composer in your terminal.
What if you modify your phpunit.xml this way:
<testsuites>
<testsuite name="Application Module Test Suite">
<directory phpVersion="7.0.0" phpVersionOperator=">=">./module/Application/test</directory>
</testsuite>
<testsuite name="YourModuleName">
<directory phpVersion="7.0.0" phpVersionOperator=">=">./module/YourModuleName/test</directory>
</testsuite>
</testsuites>
Next up, run the following command:
./vendor/bin/phpunit --testsuite YourModuleName
To list all available suites, run the following command:
./vendor/bin/phpunit --list-suites
To list all available tests, run the following command:
./vendor/bin/phpunit --list-tests

Ant script javac command converted to a groovy script AntBuilder.javac

Hi im new in the jenkins/ant/groovy world and google couldnt help me to solve my problem.
My task is to get rid of ant scripts in the build process (with jenkins) and include them into the jenkins job (Execute system Groovy script).
The bold sections of my script are the reason for the failure, but i dont know how to solve this.
I hope someone can help me with that problem.
This is my "Execute system Groovy script":
antbuild = new AntBuilder()
projectHome = '...Homedirectory'
projectDomainModel = projectHome + '/CSSDomainModel'
projectPresentationBase = projectHome + '/CSSPresentationBase'
projectServices = projectHome + '/CSSServices'
projectResource = projectHome + '/src/main/resources'
Sources = projectHome + '/Presentation/JavaSource'
projectLibraries = 'lib/bin'
projectWebContent = projectHome + '/Presentation/WebContent'
projectWebInf = projectWebContent + '/WEB-INF'
deployHome = projectHome + '/target/servicekundenportal'
deployBuild = deployHome + '/build/classes'
deployWebInf = deployHome + '/WEB-INF'
foreignSources = 'src'
deployWARFile = deployHome + '/serviceportal.war'
j2eeLibraries = 'D:/Programme_x64/tomcat/8.0.21/Instanz_02/lib'
compileTarget = '1.8'
<b>compilerSourceFiles = antbuild.path{
pathelement(path:Sources)
pathelement(path:projectDomainModel + '/' + foreignSources)
pathelement(path:projectPresentationBase + '/' + foreignSources)
pathelement(path:projectServices + '/' + foreignSources)
}
compilerLibraryFiles = antbuild.path{
fileset(dir:projectDomainModel + '/' + projectLibraries) {include name:'**/*.jar'}
fileset(dir:projectPresentationBase + '/' + projectLibraries) {include name:'**/*.jar'}
fileset(dir:projectServices + '/' + projectLibraries) {include name:'**/*.jar'}
fileset(dir:j2eeLibraries) {include name:'**/*.jar'}
}</b>
antbuild.delete(dir:deployHome)
antbuild.delete(file:deployWARFile)
antbuild.mkdir(dir:deployBuild)
build() {
antbuild.javac(
destdir:deployBuild,
target:compileTarget,
debug:true,
fork:true,
executable:'D:/Programme_x64/Java/jdk1.8.0_45/bin/javac')<b>{
src(path:compilerSourceFiles)
classpath(path:compilerLibraryFiles)
}</b>
}
build()
The part of the Ant script that i am not able to convert:
<!-- Compiler Source File Definition -->
<path id="compilerSourceFiles">
<pathelement path="${Sources}" />
<pathelement path="${projectDomainModel}/${foreignSources}" />
<pathelement path="${projectPresentationBase}/${foreignSources}" />
<pathelement path="${projectServices}/${foreignSources}" />
</path>
<!-- Compiler Library Definition -->
<path id="compilerLibraryFiles">
<fileset id="librariesDomainModel" dir="${projectDomainModel}/${projectLibraries}">
<include name="**/*.jar" />
</fileset>
<fileset id="librariesPresentationBase" dir="${projectPresentationBase}/${projectLibraries}">
<include name="**/*.jar" />
</fileset>
<fileset id="librariesServices" dir="${projectServices}/${projectLibraries}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${j2eeLibraries}">
<include name="**/*.jar" />
</fileset>
</path>
<target name="executeCompiler" depends="preCompile">
<javac destdir="${deployBuild}" target="${compileTarget}"
debug="true" debuglevel="lines,vars" encoding="ISO8859-1">
<src refid="compilerSourceFiles" />
<classpath refid="compilerLibraryFiles" />
</javac>
</target>
You example has a few too many dependencies on local directory structures etc to replicate in full, but using something like the below as a pattern should get you moving in the right direction:
def ant = new AntBuilder()
def projectHome = '...Homedirectory'
ant.path(id: 'compilerSourceFiles') {
pathelement(path: "$projectHome/Presentation/JavaSource")
pathelement(path: "$projectHome/CSSDomainModel/src")
pathelement(path: "$projectHome/CSSPresentationBase/src")
pathelement(path: "$projectHome/CSSServices/src")
}
ant.path(id: "compilerSourceFiles") {
fileset(id: "librariesDomainModel", dir: "$projectHome/CSSDomainModel/lib/bin") {
include(name: "**/*.jar")
}
fileset(id: "librariesPresentationBase", dir: "....") {
include(name: "**/*.jar")
}
//...
}
ant.target(name: 'executeCompiler', depends: 'preCompile') {
javac(destDir: "...", target: "...", debug: true, debugLevel: "lines,vars", encoding: "...") {
src(refid: "compilerSourceFiles")
classpath(refid: "compilerLibraryFiles")
}
}
In other words, each ant xml snippet:
<outerelement outerattribute="outervalue">
<innerelement innerattribute="innervalue" />
</outerelement>
gets converted to:
ant.outerelement(outerattribute: "outervalue") {
innerelement(innerattribute: "innervalue")
}
when using AntBuilder.

BlueZ: get device name by it's mac address

Background: I'm working on OOB Pairing (via USB) between iOS device and embedded Linux board. Currently, on Linux side, I'm receiving bluetooth linkkey (needed for future connections) and mac address.
ps: if you are familiar with the subject - please, look at this question as well.
My current implementation, uses mac address as device's name (for details - see link to the question above), which is being resolved after second bluetoothd service restart.
Question: is there a way to get bluetooth name of the device having it's mac only with a help of BlueZ? I will use this in the C code with an access to BlueZ's DBus interface.
AFAIK, there is no straight forward DBus API or method to find the name from MAC address. But this can done using the method "GetManagedObjects" in "org.freedesktop.DBus.Properties" interface of the device.
Below is the pseudo code which will should work if proper error handling and variables are added. DBus XML is added at the top of the source just for reference.
#if 0
dbus-send --system --dest=org.bluez --type=method_call --print-reply /org/bluez/hci0/dev_44_D8_84_02_A3_17 org.freedesktop.DBus.Introspectable.Introspect
method return sender=:1.1 -> dest=:1.7 reply_serial=2
string "<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg name="xml" type="s" direction="out"/>
</method>
</interface>
<interface name="org.bluez.Device1">
<method name="Disconnect"></method>
<method name="Connect"></method>
<method name="ConnectProfile">
<arg name="UUID" type="s" direction="in"/>
</method>
<method name="DisconnectProfile">
<arg name="UUID" type="s" direction="in"/>
</method>
<method name="Pair"></method>
<method name="CancelPairing"></method>
<property name="Address" type="s" access="read"></property>
<property name="Name" type="s" access="read"></property>
<property name="Alias" type="s" access="readwrite"></property>
<property name="Class" type="u" access="read"></property>
<property name="Appearance" type="q" access="read"></property>
<property name="Icon" type="s" access="read"></property>
<property name="Paired" type="b" access="read"></property>
<property name="Trusted" type="b" access="readwrite"></property>
<property name="Blocked" type="b" access="readwrite"></property>
<property name="LegacyPairing" type="b" access="read"></property>
<property name="RSSI" type="n" access="read"></property>
<property name="Connected" type="b" access="read"></property>
<property name="UUIDs" type="as" access="read"></property>
<property name="Modalias" type="s" access="read"></property>
<property name="Adapter" type="o" access="read"></property>
</interface>
<interface name="org.freedesktop.DBus.Properties">
<method name="Get">
<arg name="interface" type="s" direction="in"/>
<arg name="name" type="s" direction="in"/>
<arg name="value" type="v" direction="out"/>
</method>
<method name="Set">
<arg name="interface" type="s" direction="in"/>
<arg name="name" type="s" direction="in"/>
<arg name="value" type="v" direction="in"/>
</method>
<method name="GetAll">
<arg name="interface" type="s" direction="in"/>
<arg name="properties" type="a{sv}" direction="out"/>
</method>
<signal name="PropertiesChanged">
<arg name="interface" type="s"/>
<arg name="changed_properties" type="a{sv}"/>
<arg name="invalidated_properties" type="as"/>
</signal>
</interface>
<node name="player0"/></node>"
#endif
#define BT_BLUEZ_NAME "org.bluez"
#define BT_MANAGER_PATH "/"
#define BT_ADAPTER_INTERFACE "org.bluez.Adapter1"
#define BT_DEVICE_IFACE "org.bluez.Device1"
#define BT_MANAGER_INTERFACE "org.freedesktop.DBus.ObjectManager"
#define BT_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
int main(void)
{
char *known_address = "2C:F0:A2:26:D7:F5"; /*This is your address to search */
conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE, NULL, BT_BLUEZ_NAME, BT_MANAGER_PATH, BT_MANAGER_INTERFACE, NULL, &err);
result = g_dbus_proxy_call_sync(proxy, "GetManagedObjects", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
char *device_path = NULL;
char device_address[18] = { 0 };
/* Parse the signature: oa{sa{sv}}} */
while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &device_path, NULL)) {
{
char address[BT_ADDRESS_STRING_SIZE] = { 0 };
char *dev_addr;
dev_addr = strstr(device_path, "dev_");
if (dev_addr != NULL) {
char *pos = NULL;
dev_addr += 4;
g_strlcpy(address, dev_addr, sizeof(address));
while ((pos = strchr(address, '_')) != NULL) {
*pos = ':';
}
g_strlcpy(device_address, address, BT_ADDRESS_STRING_SIZE);
}
}
if (g_strcmp0(known_address, device_address) == 0) {
/* Find the name of the device */
device_property_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE, NULL, BT_BLUEZ_NAME, &device_path, BT_PROPERTIES_INTERFACE, NULL, NULL);
result = g_dbus_proxy_call_sync(proxy, "Get", g_variant_new("(ss)", BT_DEVICE_IFACE, "Alias"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
const char *local = NULL;
g_variant_get(result, "(v)", &temp);
local = g_variant_get_string(temp, NULL);
printf("Your desired name : %s\n", local);
}
}
}

Microsoft XmlLite fails to detect end-of-element

I'm using Microsoft's XmlLite DLL to parse a simple XML file, using the code in the example XmlLiteReader. The essential part of the code (C++) is
while(S_OK == (hr = pReader->Read(&nodeType)))
{
switch(nodeType)
{
case XmlNodeType_Element:
// Get name...
WriteAttributes(pReader, es, attributes);
break;
case XmlNodeType_EndElement:
// Process end-of-element...
break;
}
and
HRESULT WriteAttributes(IXmlReader* pReader, CString& es, StringStringMap& attributes)
{
while(TRUE)
{
// Get and store an attribute...
HRESULT hrMove = pReader->MoveToNextAttribute();
}
// ...
}
So, here's my question. With XML input such as
<?xml version="1.0" encoding="utf-8"?>
<settings version="1.2">
<runID name="test" mode="N" take_data="Y">
<cell id="01">
<channel id="A" sample="something"/>
<channel id="B" sample="something else"/>
</cell>
<cell id="03">
<channel id="A" sample="other something"/>
<channel id="B" sample="other something else"/>
</cell>
</runID>
</settings>
Everything works as expected, except that the /> at the end of each channel line, which indicates the end of the element channel, isn't recognized as the end of an element. The successive node types following channel are whitespace (\n), then element (the second channel).
How can I determine from XmlLite that element `channel' has ended? Or am I misunderstanding the XML syntax?
You can test if an element ends with /> by using the function IsElementEmpty.

Get an entry of a Manifest file with ant

I am trying to develope an Ant macrodef which gets the values separated by commas of the Require-Bundle property in a Manifest file passed as parameter. What I want to obtain is something like this:
Require-Bundle=org.eclipse.ui,org.eclipse.ui.ide,org.eclipse.ui.views...
The problem I am facing in my code is that it doesn't take into account if the property has multiple values in multiple lines, here is my code:
<macrodef name="getDependencies">
<attribute name="file" />
<attribute name="prefix" default="ant-mf." />
<sequential>
<loadproperties>
<file file="#{file}" />
<filterchain>
<linecontains>
<contains value="Require-Bundle" />
</linecontains>
<prefixlines prefix="#{prefix}" />
</filterchain>
</loadproperties>
</sequential>
</macrodef>
But this is what I get:
[echoproperties] ant-mf.Require-Bundle=org.eclipse.ui,
Any help will be appreciated.
Most likely, your Manifest file looks like this:
Require-Bundle: org.eclipse.ui,
org.eclipse.ui.ide,
org.eclipse.ui.views,
...
Unfortunately, Java Manifest files aren't quite Java Properties files. Manifest files can have attributes that span multiple lines whereas Property files can't have multi-line values. The <loadproperties> task can't handle multi-line attributes.
Instead, you'll need an Ant task that knows about Manifest files. In another question, Richard Steele provides Ant script that loads a Manifest file from a Jar file. You can adapt the example to get just the Require-Bundle attribute.
Thanks to Chad Nouis I have changed the macrodef approach to scriptdef. I have debugged and adapted the Richard Steele script to fit my needs:
<!--
Loads entries from a manifest file.
#manifest A manifest file to read
#entry The name of the manifest entry to load (optional)
#prefix A prefix to prepend (optional)
-->
<scriptdef name="getDependencies" language="javascript" description="Gets all entries or a specified one of a manifest file">
<attribute name="manifest" />
<attribute name="entry" />
<attribute name="prefix" />
<![CDATA[
var filename = attributes.get("manifest");
var entry = attributes.get("entry");
if (entry == null) {
entry = "";
}
var prefix = attributes.get("prefix");
if (prefix == null) {
prefix = "";
}
var manifest;
if (filename != null) {
manifest = new java.util.jar.Manifest(new java.io.FileInputStream(new java.io.File(filename)));
} else {
self.fail("File is required");
}
if (manifest == null) {
self.log("Problem loading the Manifest");
} else {
var attributes = manifest.getMainAttributes();
if (attributes != null) {
if (entry != "") {
project.setProperty(prefix + entry, attributes.getValue(entry));
} else {
var it = attributes.keySet().iterator();
while (it.hasNext()) {
var key = it.next();
project.setProperty(prefix + key, attributes.getValue(key));
}
}
}
}
]]>
</scriptdef>

Resources