Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Paho to use AndroidX ServiceTestRule for unit tests #502

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,11 @@ hs_err_pid*


org.eclipse.paho.android.sample/libs/

# Ignore all IDE-related artifacts
.project
*/.project
*/.classpath
tags
.settings/*
*/.settings/*
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

buildscript {
repositories {
jcenter()
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:8.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down Expand Up @@ -57,7 +57,7 @@ println "SDK dir: $sdkDir"
allprojects {

repositories {
jcenter()
google()
maven {
url "file://$sdkDir/extras/android/m2repository/"
}
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# org.gradle.parallel=true
android.useAndroidX=true
39 changes: 0 additions & 39 deletions org.eclipse.paho.android.service/.project

This file was deleted.

62 changes: 32 additions & 30 deletions org.eclipse.paho.android.service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ apply plugin: 'com.android.library'
apply plugin: 'maven-publish'

android {
namespace "org.eclipse.paho"
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
minSdkVersion 9
minSdkVersion 19
targetSdkVersion 24

testApplicationId "org.eclipse.paho.android.service.test"
Expand All @@ -18,10 +18,6 @@ android {
}
}

dexOptions {
preDexLibraries = false
}

lintOptions {
abortOnError false
}
Expand All @@ -32,40 +28,42 @@ repositories {
}

configurations {
//androidTestCompile.exclude module: 'org.eclipse.paho.client.mqttv3'
androidTestCompile.exclude module: 'org.eclipse.paho.client.mqttv3'
}

dependencies {
compile "org.eclipse.paho:org.eclipse.paho.client.mqttv3:${rootProject.ext.clientVersion}"
compile "com.android.support:support-v4:${rootProject.ext.supportLibVersion}"
compile fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.eclipse.paho:org.eclipse.paho.client.mqttv3:${rootProject.ext.clientVersion}"
implementation "com.android.support:support-v4:${rootProject.ext.supportLibVersion}"
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.test.ext:junit:1.2.0-alpha03'
implementation 'androidx.test:rules:1.5.0'
}

android.libraryVariants.all { variant ->
task("generate${variant.name}Javadoc", type: Javadoc) {
title = "$name $version API"
description "Generates Javadoc for $variant.name."
source = variant.javaCompile.source
ext.androidJar =
"${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
options.links("http://docs.oracle.com/javase/7/docs/api/");
options.links("http://d.android.com/reference/");
exclude '**/BuildConfig.java'
exclude '**/R.java'
}
}
//android.libraryVariants.all { variant ->
// task("generate${variant.name}Javadoc", type: Javadoc) {
// title = "$name $version API"
// description "Generates Javadoc for $variant.name."
// source = variant.javaCompile.source
// ext.androidJar =
// "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
// classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
// options.links("http://docs.oracle.com/javase/7/docs/api/");
// options.links("http://d.android.com/reference/");
// exclude '**/BuildConfig.java'
// exclude '**/R.java'
// }
//}

// Generate Sources Jar
task("generateSourcesJar", type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
archiveClassifier = 'sources'
}

// Copy the Paho Java client into the libs directory to bundle it with the AAR
task("copyLibs", type: Copy) {
println "Copying MQTT Jar into libs directory"
from configurations.compile
from configurations.implementation
into 'libs'
include 'org.eclipse.paho*'
}
Expand All @@ -86,7 +84,7 @@ task("generateLibraryJar", type: Jar) {
// Generate Javadoc
task("generateJavaDocJar", type: Jar, dependsOn: (rootProject.ext.serviceVersion.endsWith('-SNAPSHOT') ? 'generatedebugJavadoc' : 'generatereleaseJavadoc')){
from("$buildDir/docs/javadoc")
classifier = 'javadoc'
archiveClassifier = 'javadoc'
}

publishing {
Expand Down Expand Up @@ -117,13 +115,17 @@ publishing {
}
}


/*
task debug << {
configurations.compile.each { println it}
configurations.implementation.each { println it}
}
*/

// Required to bundle Java library Jar in AAR
clean.doLast{
copyLibs.execute()
dependencies {
copyLibs
}
}
assemble.doLast {
renameReleaseAAR.execute()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.eclipse.paho.android.service.test">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<!-- Permissions the Application Requires -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttMessage;

import android.test.AndroidTestCase;
import androidx.test.rule.ServiceTestRule;
import androidx.test.platform.app.InstrumentationRegistry;

import org.eclipse.paho.android.service.MqttAndroidClient;

import android.util.Log;

import android.content.Context;
import static org.junit.Assert.*;

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class AndroidServiceTest extends AndroidTestCase {
public class AndroidServiceTest extends ServiceTestRule {

private static final String TAG = "AndroidServiceTest";

Expand All @@ -29,11 +33,15 @@ public class AndroidServiceTest extends AndroidTestCase {
private String mqttSSLServerURI;
private int waitForCompletionTime;
private String keyStorePwd;

private Context mContext;

@Override
public void setUp() throws Exception {
super.setUp();
TestProperties properties = new TestProperties(this.getContext());
public void beforeService() {
super.beforeService();

mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
TestProperties properties = new TestProperties(mContext);
mqttServerURI = properties.getServerURI();
mqttSSLServerURI = properties.getServerSSLURI();
waitForCompletionTime = properties.getWaitForCompletionTime();
Expand All @@ -42,8 +50,6 @@ public void setUp() throws Exception {
Log.d(TAG, properties.getServerSSLURI());
}



/**
* Tests that a client can be constructed and that it can connect to and
* disconnect from the service
Expand Down Expand Up @@ -170,7 +176,6 @@ public void testRemoteConnect() throws Exception {
mqttClient.close();
}
}

}

/**
Expand Down Expand Up @@ -237,7 +242,6 @@ public void testLargeMessage() {

}
}

}

/**
Expand Down Expand Up @@ -341,7 +345,6 @@ public void testMultipleClients() {

}
}

}

/**
Expand Down Expand Up @@ -537,7 +540,6 @@ public void testQoSPreserved() {

}
}

}

/**
Expand Down Expand Up @@ -674,7 +676,6 @@ public void testCleanStart() {

}
}

}
// /** Oringally commented out from the fv test version
// * Tests that invalid clientIds cannot connect.
Expand Down Expand Up @@ -780,7 +781,6 @@ public void testPubSub(){

}
}

}

public void testHAConnect() throws Exception{
Expand Down Expand Up @@ -902,7 +902,6 @@ public void testRetainedMessage(){
fail("Failed to instantiate:" + methodName + " exception="
+ exception);
}

}

/**
Expand All @@ -920,7 +919,7 @@ public void testSSLConnect() throws Exception {
"testSSLConnect");

MqttConnectOptions options = new MqttConnectOptions();
options.setSocketFactory(mqttClient.getSSLSocketFactory(this.getContext().getAssets().open("test.bks"), keyStorePwd));
options.setSocketFactory(mqttClient.getSSLSocketFactory(mContext.getAssets().open("test.bks"), keyStorePwd));

IMqttToken connectToken = null;
IMqttToken disconnectToken = null;
Expand All @@ -945,10 +944,8 @@ public void testSSLConnect() throws Exception {
mqttClient.close();
}
}

}



/**
* An SSL connection with server cert authentication, simple pub/sub of an message
*
Expand All @@ -969,7 +966,7 @@ public void testSSLPubSub() throws Exception {
"testSSLPubSub");

MqttConnectOptions options = new MqttConnectOptions();
options.setSocketFactory(mqttClient.getSSLSocketFactory(this.getContext().getAssets().open("test.bks"),
options.setSocketFactory(mqttClient.getSSLSocketFactory(mContext.getAssets().open("test.bks"),
keyStorePwd));

MqttV3Receiver mqttV3Receiver = new MqttV3Receiver(mqttClient, null);
Expand Down Expand Up @@ -1009,8 +1006,5 @@ public void testSSLPubSub() throws Exception {
mqttClient.close();
}
}

}


}
}
Loading