Group testNG tests without annotations - automated-tests

I'm responsible for allowing unit tests for one of ETL components.I want to acomplish this using testNG with generic java test class and number of test definitions in testng.xmlpassing various parameters to the class.Oracle and ETL guys should be able to add new tests without changing the java code, so we need to use xml suite file instead of annotations.
Question
Is there a way to group tests in testng.xml?(similarly to how it is done with annotations)
I mean something like
<group name="first_group">
<test>
<class ...>
<parameter ...>
</test>
</group>
<group name="second_group">
<test>
<class ...>
<parameter ...>
</test>
</group>
I've checked the testng.dtd as figured out that similar syntax is not allowed.But is therea workaround to allow grouping?
Thanks in advance

You can specify groups within testng.xml and then run testng using -groups
<test name="Regression1">
<groups>
<run>
<exclude name="brokenTests" />
<include name="checkinTests" />
</run>
</groups>
....

No, this is not possible at the moment.
As a rule of thumb, I don't like adding information in XML that points into Java code, because refactorings might silently break your entire build.
For example, if you rename a method or a class name, your tests might start mysteriously breaking until you remember you need to update your XML as well.
Feel free to bring this up on the testng-users mailing-list and we can see if there's interest for such a feature.
--
Cedric

Related

Workflow: Setting default value for bpm:assignee

When I start my workflow, I want the option to assign it to somebody. If nobody is chosen, I want to default to assign it to the initiator.
Is this possible to do without creating a new model that extends bpm:assignee? If not, how would that extension be accomplished?
I believe this answer from Jeff Potts is relevant: https://stackoverflow.com/a/9418066/4542428
Note: I am using Community edition 4.2
EDIT: Stefan's answer got me the vast majority of the way to the answer, but it seems that I am somehow referencing the value of the association incorrectly. Context: I've never used associations, and this is likely just my failure to understand their difference from types and aspects.
From my model:
<type name="deliveryTicketWorkflow:start">
<parent>bpm:startTask</parent>
<properties>
</properties>
<associations />
<overrides />
<mandatory-aspects>
<aspect>deliveryTicketWorkflow:pmAspect</aspect>
<aspect>deliveryTicketWorkflow:requestDetailsAspect</aspect>
</mandatory-aspects>
</type>
<aspect name="deliveryTicketWorkflow:pmAspect">
<associations>
<association name="deliveryTicketWorkflow:assignedPM">
<source>
<mandatory>false</mandatory>
<many>false</many>
</source>
<target>
<class>cm:person</class>
<mandatory>false</mandatory>
<many>true</many>
</target>
</association>
</associations>
</aspect>
Which is used by my config as:
<config condition="activiti$deliveryTicketWorkflow" evaluator="string-compare">
<forms>
<form>
<field-visibility>
...
<show id="deliveryTicketWorkflow:assignedPM" />
...
</field-visibility>
<appearance>
...
<field id="deliveryTicketWorkflow:assignedPM" label-id="Project Manager" />
...
</appearance>
</form>
</forms>
</config>
My config for deliveryTicketworkflow:start is identical. This successfully displays the person selector, without making it mandatory, exactly 100% as Stefan said it would.
In my bpmn workflow definition, I then have these snippets in an execution listener for the start event:
if(!execution.getVariable("deliveryTicketWorkflow_assignedPM")){
execution.setVariable("deliveryTicketWorkflow_assignedPM", initiator);
}
...
deliveryTicket.properties["dtdlm:projectManager"] = execution.getVariable("deliveryTicketWorkflow_assignedPM").properties.firstName + " " + execution.getVariable("deliveryTicketWorkflow_assignedPM").properties.lastName;
When the workflow is run and I select somebody as the PM, that final line (where the first and last name of the PM is grabbed) returns a value of undefined for "deliveryTicketWorkflow_assignedPM". When it is left blank, everything works swimmingly but the General Info section of the Workflow description still lists the Project Manager as (None).
You could indeed customize the people picker, as jeff describes, but it requires quite some coding effort.
Alternatively you could use a workflow executionlistener for event start, and use it to set the bpm_assignee variable to the initiator in case it was empty on the form:
Add listener to you bpmn20:
<activiti:executionListener event="start" class="com.mycomp.Executionlistener"></activiti:executionListener>
In your first usertask, define the assignee to the association property in your workflow start form.
<userTask id="firsttask" name="firsttask" activiti:assignee="${mymodel.myassoc.properties.userName}" >
Also add this association to your start task content model.
Code in com.mycomp.Executionlistener will look like this:
public void notify(DelegateExecution execution) throws Exception {
if (execution.getVariable("mymodel_myassoc") == null ){
ActivitiScriptNode userScriptNode= (ActivitiScriptNode) execution.getVariable("initiator");
execution.setVariable("mymodel_myassoc",userScriptNode);
}
}

TestNG groups depending on the same group. Which one should get executed first?

I have two test groups which are dependent on another group.
<dependencies>
<group name="search" depends-on="login" />
<group name="addnew" depends-on="login" />
</dependencies>
Which one out of the two groups (search, addnew) should ideally get executed first? For me, the group addnew is getting executed first all the time, which I don't want to happen. I want search to get executed and then addnew to get executed, once login is done. Also, I have set "preserve-order" for the test as true. Any suggestions?
If you want search to get executed first, then add new is also dependent on search group in that case. You can specify a list of groups in the depends-on list. Try with depends-on="login search" or you can let search depend on login and make add new depend on search to guarantee execution order.
Quote from documentation: "By default, TestNG will run your tests in the order they are found in the XML file. If you want the classes and methods listed in this file to be run in an unpredictible order, set the preserve-order attribute to false:"
<test name="Regression1" preserve-order="false">
<class name="test.Test1">
<methods>
<include name="m1" />
<include name="m2" />
</methods>
</class>
<class name="test.Test2" />

Alfresco FormService Fundamental WRONG

Alfresco Forms Service does not work properly.
Looks like a fundamental Form functionality does not pass form configs (control-param name="nameHere") to webscripts.
I reproduce it step-by-step.
Create the Freemarker template and register it according to the documentation under /share project. The component renders and shows successfully. Everything works well.
Create a form according to the documentation on wiki Forms page.
Register it in <TOMCAT_INST/shared/classes/alfresco/web-
extension/myclok-form-config.xml> directory and pass it for load in such manner:
<bean id="sampleShareConfig" class="org.springframework.extensions.config.ConfigBootstrap" init-method="register">
<property name="configService" ref="web.config" />
<property name="configs">
<list>
<value>classpath:alfresco/web-extension/myclok-form-config.xml</value>
</list>
</property>
</bean>
<!-- ... share/WEB-INF/classes/org/springframework/extensions/surf/bootstrap/forms-bootstrap-context.xml -->
Form inst:
<config>
<forms>
<form id="myclok">
<view-form template="/org/alfresco/components/myclok/myclok.get.html.ftl" />
<edit-form template="/org/alfresco/components/myclok/myclok.get.html.ftl" />
<create-form template="/org/alfresco/components/myclok/myclok.get.html.ftl" />
<field-visibility>
<show id="currentPath" />
</field-visibility>
<appearance>
<field id="currentPath">
<control name="currentPath" template="/org/alfresco/components/myclok/myclok.get.html.ftl">
<control-param name="currentPath">sampleData1</control-param>
</control>
</field>
<control name="currentPath" template="/org/alfresco/components/myclok/myclok.get.html.ftl">
<control-param name="currentPath">sampleData2</control-param>
</control>
</appearance>
</form>
</forms>
</config>
In official documentation is written:
If the form element exists within a config element without an
evaluator and condition the form is always found, this is useful if
you want a certain field to appear on EVERY form in your application.
So, I specified it in myclok-form-config.xml file, but this approach does not give any result. Thus when the component with such reference to param is loaded by the following URL <http://localhost:8080/share/page/site/wcmqs/myclok> the Alfresco fails with the Exception:
Exception: freemarker.core.InvalidReferenceException - Expression field is undefined on line 6, column 6 in org/alfresco/components/myclok/myclok.get.html.ftl.
freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:125)
freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:135)
freemarker.core.Dot._getAsTemplateModel(Dot.java:78)
In other words it's impossible to receive the value of the parameter of currentPath that is defined in FormConfigs.
So, the minimal functionality of FormsService / ConfigService does not work.
<#if field.control.params.currentPath??>
<#assign path=field.control.params.currentPath>
<#else>
<#assign path="someOtherDataValue">
</#if>
Does anyone know how to resolve it Or can demonstrate a working sample?
PS: All above described configurations of the form of FormService and the webscript component are attached.
The .AMP file for quick installation is required just to invoke the following command:
java -jar alfresco-mmt.jar install myclokStubFormComponent.amp ../tomcat/webapps/share.war
AMP file.
Config file.
I think you have mis-understood the difference betweent a form template and a field template. You are specifying the same file /org/alfresco/components/myclok/myclok.get.html.ftl to control the layout of the form as well as to render your fields.
When you use a field template to render the form you are getting an error that says the field object has not been populated. This is quite correct as the framework has not yet started to render the individual fields. You are rendering the form.
I'd suggest you try some more basic examples such as those that come with the Forms Development Kit (FDK) before you start implementing your own more complex forms, and especially before you begin to claim that the framework does not work as documented.

Add computed metadata to catalog for dexterity object (plone 4)

I want to create a catalog metadata with a computed string. So following Aspeli's book and the developer manual I proceeded to create an indexer:
# indexer.py
#grok.adapter(Entry, name='bind_representation')
#indexer(Entry)
def bindIndexer(context):
print str(IBindRepresentable(context))
return str(IBindRepresentable(context))
and register the index with genericSetup:
<!-- profiles/default/catalog.xml -->
<?xml version="1.0"?>
<object name="portal_catalog" meta_type="Plone Catalog Tool">
<index name="bind_representation" meta_type="ZCTextIndex">
<!-- I tried with meta_type="FieldIndex" too -->
<indexed_attr value="bind_representation"/>
<!-- copied from other text metadata -->
<extra name="index_type" value="Okapi BM25 Rank"/>
<extra name="lexicon_id" value="plaintext_lexicon"/>
</index>
</object>
The problems are: (1) only the index is registered, not the metadata, and (2) After reindex all the zodb, bind_representation still doesn't find any entry to index, even when they are.
The examples cited only deal with pre-existent indexes, so I'm not sure about the content of catalog.xml. bindIndexer seems not to be called at all, since its print statement is never executed. I copied bindIndexer to entry.py too, to get sure it wasn't being ignored, but still nothing.
What am I missing?
Thanks.
1- In order to add a new metadata, you have to use this syntax:
<?xml version="1.0"?>
<object name="portal_catalog" meta_type="Plone Catalog Tool">
...
<column value="bind_representation"/>
</object>
2a- you are adapting your content class, you should adapt your content interface (IEntry most likely).
2b- you are using a ZCTextIndex: that index won't show you all entries anyway (even following the previous point) because it's based on a lexicon. You should probably use this instead (unless you have specific bounds):
<index name="bind_representation" meta_type="FieldIndex">
<indexed_attr value="bind_representation"/>
</index>
More info:
http://bluebream.zope.org/doc/1.0/manual/componentarchitecture.html#adapters
http://maurits.vanrees.org/weblog/archive/2009/12/catalog

Conditionally including Flex libraries (SWCs) in mxmlc/compc ant tasks

I have been struggling trying to figure out how to conditionally include Flex libraries in an ant build based on a property that is set on the command line. I have tried a number of approaches with the <condition/> task, but so far have not gotten it to work. Here is where I am currently.
I have an init target that includes condition tasks like this:
<condition property="automation.libs" value="automation.qtp">
<equals arg1="${automation}" arg2="qtp" casesensitive="false" trim="true"/>
</condition>
The purpose of this task is to set a property that determines the name of the patternset to be used when declaring the implicit fileset on a mxmlc or compc task. The pattern set referenced above is defined as:
<patternset id="automation.qtp">
<include name="automation*.swc"/>
<include name="qtp.swc"/>
</patternset>
The named patternset is then referenced by the mxmlc or compc task like this:
<compc>
<compiler.include-libraries dir="${FLEX_HOME}/frameworks/libs" append="true">
<patternset refid="${automation.libs}"/>
</compiler.include-libraries>
</compc>
This doesn't appear to work. At least the SWC size does not indicate that the additional automation libraries have been compiled in. I want to be able to specify a command line property that determine which patternset to use for various types of builds.
Does anyone have any ideas about how to accomplish this? Thanks!
If you can't get <patternset> to work correctly, you might want to take a look at the <if> <then> and <else> tasks provided by ant-contrib. We ended up doing something like this:
<target name = "build">
<if>
<equals arg1="automation.qtp" arg2="true"/>
<then>
<!--
- Build with QTP support.
-->
</then>
<else>
<!--
- Build without QTP support.
-->
</else>
</if>
</target>
There is some duplication of build logic between the if and else branch, but you can factor some of that out if you wrap <mxmlc> with a macrodef.
The mxmlc task supports loading configuration files <load-config filename="path/to/flex-config.xml" />. So, generate the config xml on the fly, by combining the echoxml task and if-then-else.
<echoxml file="path/to/flex-config.xml">
<flex-config>
<compiler>
<library-path append="true">
<path-element>${lib.qtp}</path-element>
</library-path>
</compiler>
</flex-config>
</echoxml>
If your needs are more complicated, you could even generate several xml configs and <load-config ... /> them all.
Personally, I find any logic very terse and ugly to write using Ant's conditions or if-then-else, XML is not a pretty language to use for programming. Luckily, it's possible to use more flexible approach - write a script to produce the config xml, before calling mxmlc. E.g. use the script task with your favorite scripting language
<script language="javascript">
<![CDATA[
// Create your XML dynamically here.
// Write that XML to an external file.
// Later, feed that file to mxmlc using `<load-config ... />`.
]]>
</script>

Resources