i'm working with asterisk test suite and also creating custom test. but i'm trying replace some python script with java.
the problem is i don't know how to create two asterisk instances with custom dial plan for each one using "asterisk java".
Well, the good news is that with the exception of the upper most run-tests.py script, the Asterisk Test Suite is language agnostic. You'll find tests written in python, lua, and even bash. Java would be a new addition. I wouldn't recommend trying to rewrite runtests.py - you won't get a lot of bang for the buck, although I suppose you're welcome to do so.
As far as 'sandboxing' an instance of Asterisk, such that it doesn't collide with other Asterisk instances and you can run any number simultaneously, there are a number of steps you have to take to make that work properly. Luckily, if you take a look at the asterisk.py module (in lib/python/asterisk) - or astlib.lua in asttest/lib/lua - you'll have some working examples of everything that has to be done to make that happen.
At a minimum, you'll need to do the following:
As an example, lets take the confbridge python test. It spawns three instances of Asterisk. The first time it runs, it goes out and sees if /tmp/asterisk-testsuite exists. Lets say it doesn't. So we make that directory.
/tmp/asterisk-testsuite/
We then see that the test being run lives in tests/apps/confbridge - so we make our test directory, since we haven't run yet either.
/tmp/asterisk-testsuite/apps/confbridge
Now it gets interesting. We haven't run before, so when we check to see if any astn directories exist in our test directory, we determine that there aren't. So we create three of those directories.
/tmp/asterisk-testsuite/apps/confbridge
/ast1
/ast2
/ast3
Taking only ast1 as an example, we create an asterisk.conf file containing locations to our paths:
[directories](!)
astetcdir => /tmp/asterisk-testsuite/apps/confbridge/ast1/etc/asterisk
astmoddir => /tmp/asterisk-testsuite/apps/confbridge/ast1/usr/lib/asterisk/modules
astvarlibdir => /tmp/asterisk-testsuite/apps/confbridge/ast1/var/lib/asterisk
astdbdir => /tmp/asterisk-testsuite/apps/confbridge/ast1/var/lib/asterisk
astkeydir => /tmp/asterisk-testsuite/apps/confbridge/ast1/var/lib/asterisk
astdatadir => /tmp/asterisk-testsuite/apps/confbridge/ast1/var/lib/asterisk
astagidir => /tmp/asterisk-testsuite/apps/confbridge/ast1/var/lib/asterisk/agi-bin
astspooldir => /tmp/asterisk-testsuite/apps/confbridge/ast1/var/spool/asterisk
astrundir => /tmp/asterisk-testsuite/apps/confbridge/ast1/var/run/asterisk
astlogdir => /tmp/asterisk-testsuite/apps/confbridge/ast1/var/log/asterisk
[options]
verbose = 5
debug = 5
defaultlanguage = en ; Default language
documentation_language = en_US ; Set the language you want documentation
; displayed in. Value is in the same format as
; locale names.
[compat]
pbx_realtime=1.6
res_agi=1.6
app_set=1.6
We now copy our asterisk.conf into our test directory.
/tmp/asterisk-testsuite/apps/confbridge/ast1/etc/asterisk/asterisk.conf
We would then hardlink the necessary installed module shared objects to the /var/lib/asterisk/modules subdirectory, and hardlink the installed configuration files to the /etc/asterisk subdirectory. Alternatively, for /var/lib/asterisk/modules, we could have just let that use the standard installed modules and not done the hardlinking, if you so desire.
Finally, when we spawn Asterisk, we use the following syntax:
asterisk -f -g -q -m -n -C /tmp/asterisk-testsuite/apps/confbridge/ast1/etc/asterisk/asterisk.conf
Addendum to what I wrote above
There's nothing wrong with Java, but there's also a lot of re-inventing of the wheel you're going to have to do if you decide to go with a new language in the Test Suite - and not just in getting Asterisk spawned. We've written a lot of other stuff into the lua/python libraries that makes your life easier in addition to everything I've described here. Things like common test classes for CDR parsing and manipulation, voicemail manipulation, complex state machine interactions with SIPp, tests that harness multiple SIPp instances and orchestrate them in conjunction with the Test Suite - and we've been particularly focusing on the python libraries as of late. You may want to consider just going with Python - but, if you really love Java, by all means feel free to use that.