summaryrefslogtreecommitdiff
path: root/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/OasisAddressTests.java
blob: cf39a3c18b7e459198f74ad16b3d682ac4695583 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.smartdevicelink.test.rpc.datatypes;

import com.smartdevicelink.proxy.rpc.OasisAddress;
import com.smartdevicelink.test.Test;

import junit.framework.TestCase;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Iterator;

/**
 * Created by austinkirk on 6/7/17.
 */

public class OasisAddressTests extends TestCase {
    private OasisAddress msg;

    @Override
    public void setUp(){
        msg = Test.GENERAL_OASISADDRESS;
    }

    /**
     * Tests the expected values of the RPC message.
     */
    public void testRpcValues () {
        // Test Values
        String f1 = msg.getAdministrativeArea();
        String f2 = msg.getSubAdministrativeArea();
        String f3 = msg.getCountryCode();
        String f4 = msg.getCountryName();
        String f5 = msg.getLocality();
        String f6 = msg.getSubLocality();
        String f7 = msg.getPostalCode();
        String f8 = msg.getThoroughfare();
        String f9 = msg.getSubThoroughfare();


        // Valid Tests
        assertEquals(Test.MATCH, Test.GENERAL_STRING, f1);
        assertEquals(Test.MATCH, Test.GENERAL_STRING, f2);
        assertEquals(Test.MATCH, Test.GENERAL_STRING, f3);
        assertEquals(Test.MATCH, Test.GENERAL_STRING, f4);
        assertEquals(Test.MATCH, Test.GENERAL_STRING, f5);
        assertEquals(Test.MATCH, Test.GENERAL_STRING, f6);
        assertEquals(Test.MATCH, Test.GENERAL_STRING, f7);
        assertEquals(Test.MATCH, Test.GENERAL_STRING, f8);
        assertEquals(Test.MATCH, Test.GENERAL_STRING, f9);

        // Invalid/Null Tests
        OasisAddress msg = new OasisAddress();
        assertNotNull(Test.NOT_NULL, msg);

        assertNull(msg.getAdministrativeArea());
        assertNull(msg.getSubAdministrativeArea());
        assertNull(msg.getCountryCode());
        assertNull(msg.getCountryName());
        assertNull(msg.getLocality());
        assertNull(msg.getSubLocality());
        assertNull(msg.getPostalCode());
        assertNull(msg.getThoroughfare());
        assertNull(msg.getSubThoroughfare());
    }

    public void testJson(){
        JSONObject reference = new JSONObject();

        try{
            reference.put(OasisAddress.KEY_ADMINISTRATIVE_AREA, Test.GENERAL_STRING);
            reference.put(OasisAddress.KEY_SUB_ADMINISTRATIVE_AREA, Test.GENERAL_STRING);
            reference.put(OasisAddress.KEY_COUNTRY_CODE, Test.GENERAL_STRING);
            reference.put(OasisAddress.KEY_COUNTRY_NAME, Test.GENERAL_STRING);
            reference.put(OasisAddress.KEY_LOCALITY, Test.GENERAL_STRING);
            reference.put(OasisAddress.KEY_SUB_LOCALITY, Test.GENERAL_STRING);
            reference.put(OasisAddress.KEY_POSTAL_CODE, Test.GENERAL_STRING);
            reference.put(OasisAddress.KEY_THOROUGH_FARE, Test.GENERAL_STRING);
            reference.put(OasisAddress.KEY_SUB_THOROUGH_FARE, Test.GENERAL_STRING);

            JSONObject underTest = msg.serializeJSON();
            assertEquals(Test.MATCH, reference.length(), underTest.length());

            Iterator<?> iterator = reference.keys();
            while (iterator.hasNext()) {
                String key = (String) iterator.next();
                assertEquals(Test.MATCH, reference.get(key),
                        underTest.get(key));
            }

        } catch(JSONException e){
            fail(Test.JSON_FAIL);
        }
    }
}