Skip to content

Commit e0e25e5

Browse files
ManagerのJUnitのテスト調整。
1 parent b81e052 commit e0e25e5

5 files changed

Lines changed: 58 additions & 135 deletions

File tree

dConnectDevicePlugin/dConnectDeviceTest/app/build.gradle

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 28
4+
compileSdkVersion 29
55

66
def getVersionName = { ->
77
def version
@@ -16,8 +16,8 @@ android {
1616

1717
defaultConfig {
1818
applicationId "org.deviceconnect.android.deviceplugin.test"
19-
minSdkVersion 14
20-
targetSdkVersion 28
19+
minSdkVersion 26
20+
targetSdkVersion 29
2121
versionCode 1
2222
versionName getVersionName()
2323
}
@@ -59,6 +59,5 @@ repositories {
5959

6060
dependencies {
6161
implementation fileTree(include: '*.jar', dir: 'libs')
62-
63-
implementation 'org.deviceconnect:dconnect-device-plugin-sdk:2.5.1'
62+
implementation 'org.deviceconnect:dconnect-device-plugin-sdk:2.8.0'
6463
}

dConnectDevicePlugin/dConnectDeviceTest/app/src/main/java/org/deviceconnect/android/deviceplugin/test/UnitTestDeviceService.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,15 @@ public class UnitTestDeviceService extends DConnectMessageService {
4141
@Override
4242
public void onCreate() {
4343
super.onCreate();
44-
setUseLocalOAuth(false);
45-
4644
mFileManager = new FileManager(this);
4745

4846
// テスト用データ作成
4947
createTestData();
5048

5149
getServiceProvider().addService(new UnitTestService(SERVICE_ID,
52-
DEVICE_NAME, getPluginSpec()));
50+
DEVICE_NAME));
5351
getServiceProvider().addService(new UnitTestService(SERVICE_ID_SPECIAL_CHARACTERS,
54-
DEVICE_NAME_SPECIAL_CHARACTERS, getPluginSpec()));
52+
DEVICE_NAME_SPECIAL_CHARACTERS));
5553
}
5654

5755
@Override
@@ -70,15 +68,6 @@ public int onStartCommand(final Intent intent, final int flags, final int startI
7068
return super.onStartCommand(intent, flags, startId);
7169
}
7270

73-
@Override
74-
public void onRequest(final Intent request, final Intent response) {
75-
boolean timeout = request.hasExtra("_timeout");
76-
if (timeout) {
77-
return;
78-
}
79-
super.onRequest(request, response);
80-
}
81-
8271
@Override
8372
protected SystemProfile getSystemProfile() {
8473
return new TestSystemProfile();

dConnectDevicePlugin/dConnectDeviceTest/app/src/main/java/org/deviceconnect/android/deviceplugin/test/service/UnitTestService.java

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,7 @@
1717
import org.deviceconnect.android.deviceplugin.test.profile.unique.TestJSONConversionProfile;
1818
import org.deviceconnect.android.deviceplugin.test.profile.unique.TestUniqueProfile;
1919
import org.deviceconnect.android.message.MessageUtils;
20-
import org.deviceconnect.android.profile.AuthorizationProfile;
2120
import org.deviceconnect.android.profile.DConnectProfile;
22-
import org.deviceconnect.android.profile.ServiceDiscoveryProfile;
23-
import org.deviceconnect.android.profile.ServiceInformationProfile;
24-
import org.deviceconnect.android.profile.SystemProfile;
25-
import org.deviceconnect.android.profile.api.DConnectApi;
26-
import org.deviceconnect.android.profile.spec.DConnectApiSpec;
27-
import org.deviceconnect.android.profile.spec.DConnectPluginSpec;
28-
import org.deviceconnect.android.profile.spec.DConnectProfileSpec;
2921
import org.deviceconnect.android.service.DConnectService;
3022
import org.deviceconnect.message.DConnectMessage;
3123

@@ -45,68 +37,11 @@ public class UnitTestService extends DConnectService {
4537

4638
private Map<String, EventSender> mEventSenders = new HashMap<String, EventSender>();
4739

48-
public UnitTestService(final String id, final String name, final DConnectPluginSpec pluginSpec) {
40+
public UnitTestService(final String id, final String name) {
4941
super(id);
5042
setName(name);
5143
setOnline(true);
5244

53-
Map<String, DConnectProfileSpec> profileSpecs = pluginSpec.getProfileSpecs();
54-
for (Map.Entry<String, DConnectProfileSpec> entry : profileSpecs.entrySet()) {
55-
final String profileName = entry.getKey();
56-
if (AuthorizationProfile.PROFILE_NAME.equalsIgnoreCase(profileName)
57-
|| ServiceDiscoveryProfile.PROFILE_NAME.equalsIgnoreCase(profileName)
58-
|| ServiceInformationProfile.PROFILE_NAME.equalsIgnoreCase(profileName)
59-
|| SystemProfile.PROFILE_NAME.equalsIgnoreCase(profileName)) {
60-
continue;
61-
}
62-
63-
final DConnectProfileSpec profileSpec = entry.getValue();
64-
final DConnectProfile profile = new DConnectProfile() {
65-
@Override
66-
public String getProfileName() {
67-
return profileName;
68-
}
69-
};
70-
for (final DConnectApiSpec apiSpec : profileSpec.getApiSpecList()) {
71-
DConnectApi api = new DConnectApi() {
72-
@Override
73-
public Method getMethod() {
74-
return apiSpec.getMethod();
75-
}
76-
77-
@Override
78-
public String getInterface() {
79-
return apiSpec.getInterfaceName();
80-
}
81-
82-
@Override
83-
public String getAttribute() {
84-
return apiSpec.getAttributeName();
85-
}
86-
87-
@Override
88-
public boolean onRequest(final Intent request, final Intent response) {
89-
DConnectProfile.setResult(response, DConnectMessage.RESULT_OK);
90-
if (apiSpec.getType() == Type.EVENT) {
91-
switch (apiSpec.getMethod()) {
92-
case PUT:
93-
startEventBroadcast(request);
94-
break;
95-
case DELETE:
96-
stopEventSender(request);
97-
break;
98-
default:
99-
break;
100-
}
101-
}
102-
return true;
103-
}
104-
};
105-
profile.addApi(api);
106-
}
107-
addProfile(profile);
108-
}
109-
11045
addProfile(new TestSystemProfile());
11146
addProfile(new TestUniqueProfile());
11247
addProfile(new TestJSONConversionProfile());

dConnectManager/dConnectManager/dconnect-manager-app/src/androidTest/java/org/deviceconnect/android/manager/test/JSONConversionTest.java

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import android.os.Bundle;
1010
import android.support.test.runner.AndroidJUnit4;
1111

12-
import junit.framework.Assert;
13-
1412
import org.deviceconnect.android.profile.restful.test.RESTfulDConnectTestCase;
1513
import org.deviceconnect.message.DConnectMessage;
1614
import org.deviceconnect.message.DConnectResponseMessage;
@@ -20,8 +18,11 @@
2018
import org.junit.Test;
2119
import org.junit.runner.RunWith;
2220

21+
import static junit.framework.TestCase.assertFalse;
2322
import static org.hamcrest.CoreMatchers.notNullValue;
2423
import static org.hamcrest.core.Is.is;
24+
import static org.junit.Assert.assertEquals;
25+
import static org.junit.Assert.assertNotNull;
2526
import static org.junit.Assert.assertThat;
2627

2728

@@ -54,53 +55,52 @@ public void testConversion() throws JSONException {
5455

5556
DConnectResponseMessage response = mDConnectSDK.get(builder.toString());
5657
assertThat(response, is(notNullValue()));
57-
5858
DConnectMessage root = response.getMessage("extra");
59-
Assert.assertNotNull("root is null.", root);
60-
Assert.assertFalse(root.containsKey(IntentDConnectMessage.EXTRA_REQUEST_CODE));
61-
Assert.assertEquals("http://localhost:8080", root.getString("uri"));
62-
Assert.assertEquals(0, root.getInt("byte"));
63-
Assert.assertEquals('0', root.getInt("char"));
64-
Assert.assertEquals(0, root.getInt("int"));
65-
Assert.assertEquals(0L, root.getLong("long"));
66-
Assert.assertEquals(0.0, root.getDouble("float"), TEST_FLOATING_VALUE);
67-
Assert.assertEquals(0.0, root.getDouble("double"), TEST_FLOATING_VALUE);
68-
Assert.assertEquals(false, root.getBoolean("boolean"));
69-
Assert.assertEquals(0, root.getInt(Byte.class.getName()));
70-
Assert.assertEquals('0', root.getInt(Character.class.getName()));
71-
Assert.assertEquals(0, root.getInt(Integer.class.getName()));
72-
Assert.assertEquals(0L, root.getLong(Long.class.getName()));
73-
Assert.assertEquals(0.0, root.getDouble(Float.class.getName()), TEST_FLOATING_VALUE);
74-
Assert.assertEquals(0.0, root.getDouble(Double.class.getName()), TEST_FLOATING_VALUE);
75-
Assert.assertEquals(false, root.getBoolean(Boolean.class.getName()));
76-
Assert.assertEquals(String.class.getName(), root.getString(String.class.getName()));
77-
Assert.assertEquals(1, root.getList(int[].class.getName()).size());
78-
Assert.assertEquals(0, root.getList(int[].class.getName()).get(0));
79-
Assert.assertEquals(1, root.getList(long[].class.getName()).size());
80-
Assert.assertEquals(0, root.getList(long[].class.getName()).get(0));
81-
Assert.assertEquals(1, root.getList(float[].class.getName()).size());
82-
Assert.assertEquals(0.0f, ((Integer)root.getList(float[].class.getName()).get(0)).floatValue(), TEST_FLOATING_VALUE);
83-
Assert.assertEquals(1, root.getList(double[].class.getName()).size());
84-
Assert.assertEquals(0.0d, ((Integer)root.getList(double[].class.getName()).get(0)).doubleValue(), TEST_FLOATING_VALUE);
85-
Assert.assertEquals(1, root.getList(boolean[].class.getName()).size());
86-
Assert.assertEquals(false, root.getList(boolean[].class.getName()).get(0));
87-
Assert.assertEquals(1, root.getList(Integer[].class.getName()).size());
88-
Assert.assertEquals(0, root.getList(Integer[].class.getName()).get(0));
89-
Assert.assertEquals(1, root.getList(Long[].class.getName()).size());
90-
Assert.assertEquals(0, root.getList(Long[].class.getName()).get(0));
91-
Assert.assertEquals(1, root.getList(Float[].class.getName()).size());
92-
Assert.assertEquals(0.0f, ((Integer) root.getList(Float[].class.getName()).get(0)).floatValue(), TEST_FLOATING_VALUE);
93-
Assert.assertEquals(1, root.getList(Double[].class.getName()).size());
94-
Assert.assertEquals(0.0d, ((Integer)root.getList(Double[].class.getName()).get(0)).doubleValue(), TEST_FLOATING_VALUE);
95-
Assert.assertEquals(1, root.getList(Boolean[].class.getName()).size());
96-
Assert.assertEquals(false, root.getList(Boolean[].class.getName()).get(0));
97-
Assert.assertEquals(1, root.getList(String[].class.getName()).size());
98-
Assert.assertEquals("String", root.getList(String[].class.getName()).get(0));
99-
Assert.assertNotNull(root.getMessage(Bundle.class.getName()));
100-
Assert.assertEquals(1, root.getList(Bundle[].class.getName()).size());
101-
Assert.assertNotNull(root.getList(Bundle[].class.getName()).get(0));
102-
Assert.assertEquals(1, root.getList("ArrayList<Integer>").size());
103-
Assert.assertEquals(0, root.getList("ArrayList<Integer>").get(0));
59+
assertNotNull("root is null.", root);
60+
assertFalse(root.containsKey(IntentDConnectMessage.EXTRA_REQUEST_CODE));
61+
assertEquals("http://localhost:8080", root.getString("uri"));
62+
assertEquals(0, root.getInt("byte"));
63+
assertEquals('0', root.getInt("char"));
64+
assertEquals(0, root.getInt("int"));
65+
assertEquals(0L, root.getLong("long"));
66+
assertEquals(0.0, root.getDouble("float"), TEST_FLOATING_VALUE);
67+
assertEquals(0.0, root.getDouble("double"), TEST_FLOATING_VALUE);
68+
assertEquals(false, root.getBoolean("boolean"));
69+
assertEquals(0, root.getInt(Byte.class.getName()));
70+
assertEquals('0', root.getInt(Character.class.getName()));
71+
assertEquals(0, root.getInt(Integer.class.getName()));
72+
assertEquals(0L, root.getLong(Long.class.getName()));
73+
assertEquals(0.0, root.getDouble(Float.class.getName()), TEST_FLOATING_VALUE);
74+
assertEquals(0.0, root.getDouble(Double.class.getName()), TEST_FLOATING_VALUE);
75+
assertEquals(false, root.getBoolean(Boolean.class.getName()));
76+
assertEquals(String.class.getName(), root.getString(String.class.getName()));
77+
assertEquals(1, root.getList(int[].class.getName()).size());
78+
assertEquals(0, root.getList(int[].class.getName()).get(0));
79+
assertEquals(1, root.getList(long[].class.getName()).size());
80+
assertEquals(0, root.getList(long[].class.getName()).get(0));
81+
assertEquals(1, root.getList(float[].class.getName()).size());
82+
assertEquals(0.0f, ((Integer)root.getList(float[].class.getName()).get(0)).floatValue(), TEST_FLOATING_VALUE);
83+
assertEquals(1, root.getList(double[].class.getName()).size());
84+
assertEquals(0.0d, ((Integer)root.getList(double[].class.getName()).get(0)).doubleValue(), TEST_FLOATING_VALUE);
85+
assertEquals(1, root.getList(boolean[].class.getName()).size());
86+
assertEquals(false, root.getList(boolean[].class.getName()).get(0));
87+
assertEquals(1, root.getList(Integer[].class.getName()).size());
88+
assertEquals(0, root.getList(Integer[].class.getName()).get(0));
89+
assertEquals(1, root.getList(Long[].class.getName()).size());
90+
assertEquals(0, root.getList(Long[].class.getName()).get(0));
91+
assertEquals(1, root.getList(Float[].class.getName()).size());
92+
assertEquals(0.0f, ((Integer) root.getList(Float[].class.getName()).get(0)).floatValue(), TEST_FLOATING_VALUE);
93+
assertEquals(1, root.getList(Double[].class.getName()).size());
94+
assertEquals(0.0d, ((Integer)root.getList(Double[].class.getName()).get(0)).doubleValue(), TEST_FLOATING_VALUE);
95+
assertEquals(1, root.getList(Boolean[].class.getName()).size());
96+
assertEquals(false, root.getList(Boolean[].class.getName()).get(0));
97+
assertEquals(1, root.getList(String[].class.getName()).size());
98+
assertEquals("String", root.getList(String[].class.getName()).get(0));
99+
assertNotNull(root.getMessage(Bundle.class.getName()));
100+
assertEquals(1, root.getList(Bundle[].class.getName()).size());
101+
assertNotNull(root.getList(Bundle[].class.getName()).get(0));
102+
assertEquals(1, root.getList("ArrayList<Integer>").size());
103+
assertEquals(0, root.getList("ArrayList<Integer>").get(0));
104104
}
105105

106106
}

dConnectManager/dConnectManager/dconnect-manager-app/src/androidTest/java/org/deviceconnect/android/profile/restful/test/NormalEventProfileTestCase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class NormalEventProfileTestCase extends RESTfulDConnectTestCase {
4747
*/
4848
@Test
4949
public void testEvent() throws Exception {
50-
String uri = "http://localhost:4035/gotapi/deviceOrientation/onDeviceOrientation";
50+
String uri = "http://localhost:4035/gotapi/unique/event";
5151
uri += "?serviceId=" + URLEncoder.encode(getServiceId(), "UTF-8");
5252
uri += "&accessToken=" + URLEncoder.encode(getAccessToken(), "UTF-8");
5353

@@ -100,8 +100,8 @@ public void onResponse(DConnectResponseMessage response) {
100100
DConnectEventMessage e = event.get();
101101
assertThat(e, is(notNullValue()));
102102
assertThat(e.getString("serviceId"), is(getServiceId()));
103-
assertThat(e.getString("profile"), is(equalToIgnoringCase("deviceOrientation")));
104-
assertThat(e.getString("attribute"), is(equalToIgnoringCase("onDeviceOrientation")));
103+
assertThat(e.getString("profile"), is(equalToIgnoringCase("unique")));
104+
assertThat(e.getString("attribute"), is(equalToIgnoringCase("event")));
105105
} finally {
106106
mDConnectSDK.removeEventListener(uri);
107107
mDConnectSDK.disconnectWebSocket();

0 commit comments

Comments
 (0)