Testing from JUnit if a SIP Soft Phone is ringing, answered a call, disconnected - sip

I want to initiate calls to two numbers using a 3rd party API. I need to make sure that the devices ring when they get the calls, media starts to transmit when the call is answered, and the call is terminated when hungup.
Ideally I would like to do this from JUnit tests so that I can automate this whole process. But any other tool will also be fine.
So this is what I want to do programatically,
1) Configure two SIP soft phones to answer on 2 different numbers using some credentials provided by the test.
2) Make a call using the API
3) Assert that two phones are in ringing state
4) Answer the call
5) Assert that RTP media is being transmitted among them
6) Hang up
7) Assert that the call is now successfully disconnected
I am quite new to telephony, so would appreciate any pointers on any tool or SDK that will help me accomplish this.

Please check out SipUnit https://code.google.com/p/commtesting/wiki/SipUnit.
It can do all above except check out the media is flowing yet.

Check out the KitCAT framework. It's based on JUnit and can support all of your requirements. It supports multiple user agents, which can all be coordinated within a test case. It also provides coordination with other protocols (e.g., RTP, HTTP).
Sample code:
SIPAgent callee1 = createAgent("callee1"); // sip:callee1#host
SIPAgent callee2 = createAgent("callee2"); // sip:callee2#host
// invoke your API here
invoke3rdPartyAPI(callee1.getSipURI(), callee2.getSipURI());
pause(2000);
assertThat(callee1, is(invited()));
assertThat(callee2, is(invited()));
callee1.answer();
callee2.answer();
pause(500);
assertThat(callee1, is(connectedTo(callee2))); // check for SDP match
callee1.playAudio(audioFileName);
pause(500);
assertThat(callee2, has(incomingMedia());
callee1.disconnect();
pause(500);
assertThat(callee2, is(disconnected()));
Check out the complete API here.

Related

Unit test for Request Timeout

I have a need to write an integration between three applications. Two of these applications I don’t have access to the code for because they are third party applications. I’ll refer to these apps as third party app #1 and third party app #2. If an error occurs in the integration between these three apps, I want third party application #1 to receive an appropriate status code.
However, I’m currently seeing the following behavior:
My application is a spring boot app with an endpoint that, when called, synchronously makes a PATCH request using a rest template to a third party application #2’s rest API. However, I am occasionally seeing an issue where the request to the third party application takes an unacceptable amount of time to fail (up to 8 hours). When this occurs, the logs for application #1 show it received “No Response”. I intend to write a fix for this problem by adding a timeout to the request from my application to third party application #2 (as described here https://howtodoinjava.com/spring-boot2/resttemplate/resttemplate-timeout-example/). Doing this should at least guarantee a status code is returned to third party application #1.
To summarize, I want to write a test simulate the request to the third party application #2 failing after 5 seconds. When the request fails, I want to return a specific status code to the original application which called the endpoint. I’m going to try to write a fix for this issue by implementing a timeout for the request represented by arrow #2. However, Im unsure how to adequately write a test that simulates this issue and verifies that we are seeing the correct behaviour. My goal is to write a test that checks that my application returns an error with a response code to third party application #1 on encountering the scenario where the request to third party application #2 lasts longer than a given time period (maybe 5 seconds). That said, I have seen people suggest things like this to ensure a test request takes a specified amount of time.
this.mockMvc.perform(put(expectedUrl))
.andDo((result) -> {
Thread.sleep(6000);
}).andReturn();
However my fix for this issue will be to set several properties on the request factory being used by the rest template itself (as described in the provided link) and I don’t feel like doing the above is an adequate test of this behavior as we never actually verify that (though I could be wrong). In short how can I write a test that checks that a request times out after a set period of time? Thanks in advance for any guidance or assistance.

Read from a serial port in Swift 4 using ORSSerialPort

I've been wanting to make an app that sends instructions over serial to my LED controller. For this to work, I need to read what the controller sends back after sending it a command. I found the following function in ORSSerialPort:
func serialPort(_ serialPort: ORSSerialPort, didReceive data: Data) {
// Do things
}
However, is there something like ORSSerialPort.read()?
I don't think ORSSerialPort.read() is a good idea. I know some other serial libraries are written that way, but the only way for that to work is for read() to block (possibly with a timeout) until a byte comes in on the port. Blocking I/O makes it a lot harder to write a good, responsive app, and I want to guide developers using ORSSerialPort away from that approach.
Instead, you should indeed implement serialPort(_:, didReceive:) in your ORSSerialPort delegate. When data is received by the serial port, that method will be called with the received data and you can do whatever you'd like with it.
That said, if your device communicates using a command/response type protocol (ie. every time you send a command, the device sends some response), you ought to look at ORSSerialPort's request/response API. It allows you to explicitly define the format of expected responses to commands, and ORSSerialPort itself will handle asynchronously waiting for, parsing, and validating responses. See the documentation for more info about this part of ORSSerialPort. The library also includes a sample project, RequestResponseDemo, that demonstrates using this API. Both Swift and Objective-C versions are included.
The ORSSerialPort library is popular and generally good. However, I'd found that it didn't work well with TTY serial devices. This was primarily because of its use of IOKit to discover serial ports -- it would only discover physical devices.
This is likely OK in your case but where you want to test your code but don't want to connect to a physical device, it falls over. Good code always needs a testing framwork. So, check out https://github.com/kpishere/POSIXSerialPort for a very simple serial interface API it is just what you need to write and respond to incoming data and also works with physical or virtual devices (as Unix was originally envisoned!).
To your question though, you don't want to call read() directly. You get into understanding whether or not, "is it a blocking read?" Then you get into dealing with threads. Both of the suggested APIs insulate you from that and allow you to think in terms of an event driven model -- this makes for much simpler code.

Showing timer with WebSockets

I have an application (Laravel + MongoDB running on Nginx) where I pull some data from the database and render it on the screen. The application focusses on multiple real life objects. Once an object is turned on (is_on equals to true in the database), the timer on the screen needs to start ticking. Once the object is turned off (is_on equals to false in the database) the clock stops ticking and resets to 0. The format of the clock is HH:MM:SS. So it shows how long the real life object is turned on.
My problem is that I don't really now how to save/implement such timer. When the user request the page, I pull the necessary data from the database. If I also save the timer in the database, you have to make a query every second which is very bad practice.
I remembered something about WebSockets and tried to look into them. I actually managed to build a basic Hello World chat application, but don't really know how to implement this in my project. There is no place for it in the database (because of the queries), so I don't really know where to save that timer on the server. I'm also doubting if WebSockets are the way to go.
So are WebSockets the way to go and if it is, can you guys point me in the right direction on how to implement this? If not, can you advise me what I should do?
Thanks in advance!
From your question:
I understand that the objects you print in the screen are modified by
users in the application, and your aim is to live forward those
modifications to other active client instances of your application.
In that case, as you mention, I would point you to websockets. They are a great way to feed information directly to the client, so the client receives the update signals and modify the interface, with no need of user action.
In order to implement the logic to notify the client, I recommend using a push approach, but this is really depending on what kind of clients you'd like to notify, since the push world is still a bit tricky.
Further readings for this websocket based push implementation:
Question about Push Flags:
Difference between push and urgent flags in TCP
If your client runs in browser or mobile this question is nice to read:
How to send push notification to web browser?
Also html5 websockets:
http://www.websocket.org/aboutwebsocket.html
As a sidenote:
A nice architecture for client-server live communication is based on node.js together with socket.io library offering good performance and not really complex implementation if you know what you do.

"Do Not Disturb" feature in iOS 6 How to implement?

I want to implement the feature "DO Not Disturb" in iOS 6.
First question : Is there any framework or api apple exposed to control them through the code?
After lot of googling i found an application on the app store "Call Bliss" that provides this functionality and complete control over the calls, sms and mms.
Can anybody explain how this application works?
or
any other work around to learn and implement this feature in iOS?
Thanks in advance...
From reading the description of Call Bliss, it actually sounds quite simple in how it works.
1) Do Not Disturb must be enabled at all times. Not scheduled, not off, but on at all times.
2) It requires you to set the contacts group for exceptions to Do Not Disturb to "Bliss Exceptions". This implies that the application requires access to your address book.
From there, it's probably wise to assume that it manages the contacts in the "Bliss Exceptions" contact group based on whatever parameters you set in the application. It adds and removes people in that group based said parameters.
So to answer your question, no, there is no framework to do this. The way they're doing it is likely the only way to do it currently with no public API for managing do not disturb status.
There is no public API to even access do-not-disturb functionality.
I think this is what the app does:
The app creates and manages its own contact list (called Bliss exceptions)
the user have to select it in the do-not-disturb preferences.
The App can run in the background because it uses location tracking (probably significant only to save battery life), so when the user changes locations it can update the exception list.
When a call is received do-not-disturb system functionality checks the Bliss exceptions list and silences all calls from contacts on the list.
Please note that reviewers complain about the lack of time based call blocking. It is impossible because the app can only execute code when the location is changed.
In my Knowledge there is no way to implement it via code. There is no public api provided for restricting the calls.
But there is an API for detecting the calls : CTCallCenter and a FrameWork called CoreTelephonyFramework

Does the Rx Framework have any use in a web application?

I have been looking at the Rx Framework aslo refered to as LINQ to events. This is definately a great thing but I have been wondering if anyone sees this as having any uses in web applications rather than just normal windows based apps?
You can use Rx in various call back scenarios, not just when you work 'normal windows apps'. Especially, when you work with Async operations - for ex, you might need to make a call to the server or cloud from your silverlight or desktop client and to receive the data back. Or in cases you'll get a call back from the server (in cases like Polling Duplex).
Also, another scenario for web apps - to invalidate your cache when you receive a data changed event from the model. Just some 'imaginary' code here if you've a cache and model designed accordingly...
var cacheListeners=from sender in myModel.GetDataChangedEvents()
select sender;
//Subscribe
cacheListeners.Subscribe(data=>Cache.Invalidate(data.Key));
Have a look at this http://amazedsaint.blogspot.com/2009/11/systemreactive-or-net-reactive.html
It appears that the original spark for the Rx was around web based programming - in particular to simplify the challenges of AJAX style applications.
Here's a web based example
http://blogs.msdn.com/somasegar/archive/2009/11/18/reactive-extensions-for-net-rx.aspx
See the project http://reactivetrader.com/ to see Rx in use in a web application.