summaryrefslogtreecommitdiff
path: root/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/CloudAppPropertiesTests.java
blob: 5340efdd2be4b499651abd307f98d1e46793733c (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
96
package com.smartdevicelink.test.rpc.datatypes;

import java.util.Iterator;

import junit.framework.TestCase;

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

import com.smartdevicelink.proxy.rpc.CloudAppProperties;
import com.smartdevicelink.proxy.rpc.enums.HybridAppPreference;
import com.smartdevicelink.test.JsonUtils;
import com.smartdevicelink.test.Test;

/**
 * This is a unit test class for the SmartDeviceLink library project class :
 * {@link com.smartdevicelink.proxy.rpc.CloudAppProperties}
 */
public class CloudAppPropertiesTests extends TestCase{

	private CloudAppProperties msg;

	@Override
	public void setUp(){
		msg = new CloudAppProperties();

		msg.setAppName(Test.GENERAL_STRING);
		msg.setAppID(Test.GENERAL_STRING);
		msg.setEnabled(Test.GENERAL_BOOLEAN);
		msg.setAuthToken(Test.GENERAL_STRING);
		msg.setCloudTransportType(Test.GENERAL_STRING);
		msg.setHybridAppPreference(Test.GENERAL_HYBRID_APP_PREFERENCE);
		msg.setEndpoint(Test.GENERAL_STRING);
	}

	/**
	 * Tests the expected values of the RPC message.
	 */
	public void testRpcValues () {
		// Test Values
		String appName = msg.getAppName();
		String appID = msg.getAppID();
		boolean enabled = msg.isEnabled();
		String authToken = msg.getAuthToken();
		String cloudTransportType = msg.getCloudTransportType();
		HybridAppPreference hybridAppPreference = msg.getHybridAppPreference();
		String endpoint = msg.getEndpoint();

		// Valid Tests
		assertEquals(Test.MATCH, Test.GENERAL_STRING, appName);
		assertEquals(Test.MATCH, Test.GENERAL_STRING, appID);
		assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, enabled);
		assertEquals(Test.MATCH, Test.GENERAL_STRING, authToken);
		assertEquals(Test.MATCH, Test.GENERAL_STRING, cloudTransportType);
		assertEquals(Test.MATCH, Test.GENERAL_HYBRID_APP_PREFERENCE, hybridAppPreference);
		assertEquals(Test.MATCH, Test.GENERAL_STRING, endpoint);

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

		assertNull(Test.NULL, msg.getAppName());
		assertNull(Test.NULL, msg.getAppID());
		assertNull(Test.NULL, msg.isEnabled());
		assertNull(Test.NULL, msg.getAuthToken());
		assertNull(Test.NULL, msg.getCloudTransportType());
		assertNull(Test.NULL, msg.getHybridAppPreference());
		assertNull(Test.NULL, msg.getEndpoint());
	}

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

		try{
			reference.put(CloudAppProperties.KEY_APP_NAME, Test.GENERAL_STRING);
			reference.put(CloudAppProperties.KEY_APP_ID, Test.GENERAL_STRING);
			reference.put(CloudAppProperties.KEY_ENABLED, Test.GENERAL_BOOLEAN);
			reference.put(CloudAppProperties.KEY_AUTH_TOKEN, Test.GENERAL_STRING);
			reference.put(CloudAppProperties.KEY_CLOUD_TRANSPORT_TYPE, Test.GENERAL_STRING);
			reference.put(CloudAppProperties.KEY_HYBRID_APP_PREFERENCE, Test.GENERAL_HYBRID_APP_PREFERENCE);
			reference.put(CloudAppProperties.KEY_ENDPOINT, 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, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key));
			}
		} catch(JSONException e){
			fail(Test.JSON_FAIL);
		}
	}
}