Android Open Source - Icinga-Mobile Net Controller Test

From Project

Back to project page Icinga-Mobile.


The source code is released under:

GNU General Public License

If you think the Android project Icinga-Mobile listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package mhst.dreamteam.IcingaClient.Controller;
// w w w . ja  v  a2 s.  co m
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.LargeTest;

import junit.framework.Assert;

import java.util.Map;

import mhst.dreamteam.IcingaClient.GlobalConst;

 * Test send request action:<br />
 * +Test case 1: Unknown host<br />
 * +Test case 2: Connect successful<br />
 * @author MinhNN
public class NetControllerTest extends AndroidTestCase {

    public NetControllerTest() {

    public void testNetController_UnknownHost() {
        // Unknown host to connect
        String sURL = "http://1234567890";

        // Begin test
        Map<String, Object> response = NetController.sendRequest("POST", sURL, "", null);
        // Check if any error was detected
        assertEquals("No error detected", true, response.containsKey("Error"));
        // Get error code
        int res = (Integer) response.get("Error");
        // Check if it is UNKNOWN HOST ERROR or not
        Assert.assertEquals("This should be unknown host error", GlobalConst.ERROR_UNKNOWN_HOST, res);

    public void testNetController_Success() throws UnsupportedEncodingException {
        // Server to connect
        String sURL = "";
        String sRequest = "dologin=1&username=guest&password=123@123a";

        // Begin test
        Map<String, Object> response = NetController.sendRequest("POST", sURL, sRequest, null);
        // Check if there is any response code
        assertEquals("No response code", true, response.containsKey("Code"));


Java Source Code List