Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

WIP Improve testing and refactoring code #498

Open
wants to merge 7 commits into
base: develop
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
13 changes: 11 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ android {
defaultConfig {
multiDexEnabled true
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

sonarqube {
Expand All @@ -66,8 +71,12 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.9.0'
androidTestImplementation 'org.mockito:mockito-android:2.7.22'
testImplementation 'org.mockito:mockito-core:2.7.1'
testImplementation "org.powermock:powermock-module-junit4:1.7.4"
testImplementation "org.powermock:powermock-api-mockito:1.7.4"
testImplementation 'org.robolectric:robolectric:3.3.1'
testImplementation "org.robolectric:multidex:3.4.2"

implementation 'com.android.support:multidex:1.0.2'
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0'
implementation 'com.android.support:appcompat-v7:27.1.1'
Expand Down

This file was deleted.

6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
>
</service>
<service
android:name=".services.MQTTService"
android:name=".services.MDMService"
android:enabled="true"
android:label="M2M communications"
>
Expand All @@ -168,7 +168,7 @@

<!-- This receiver is for restart MQTT on reboot device -->
<receiver
android:name=".receivers.MQTTRestarterBroadcastReceiver"
android:name=".receivers.RestarterBroadcastReceiver"
android:enabled="true"
android:exported="true"
android:label="RestartServiceWhenStopped">
Expand Down Expand Up @@ -203,7 +203,7 @@

<!-- This receiver is for information about Wifi or Bluetooth -->
<receiver
android:name=".receivers.MQTTConnectivityReceiver"
android:name=".receivers.ConnectivityReceiver"
android:exported="false">
<intent-filter android:priority="100">
<action android:name="android.net.wifi.STATE_CHANGE" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@
import android.content.ServiceConnection;
import android.os.IBinder;

import org.flyve.mdm.agent.services.MQTTService;
import org.flyve.mdm.agent.services.MDMService;
import org.flyve.mdm.agent.utils.FlyveLog;

public class AppsReceiver extends BroadcastReceiver {

private MQTTService mqttService;
private MDMService MDMService;

ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
mqttService = null;
MDMService = null;
}

@Override
public void onServiceConnected(ComponentName name, IBinder service) {
MQTTService.LocalBinder mLocalBinder = (MQTTService.LocalBinder)service;
mqttService = mLocalBinder.getServerInstance();
mqttService.sendInventory();
MDMService.LocalBinder mLocalBinder = (MDMService.LocalBinder)service;
MDMService = mLocalBinder.getServerInstance();
MDMService.sendInventory();
}
};

Expand All @@ -60,7 +60,7 @@ public void onServiceConnected(ComponentName name, IBinder service) {
@Override
public void onReceive(Context context, Intent intent) {
try {
Intent mIntent = new Intent(context, MQTTService.class);
Intent mIntent = new Intent(context, MDMService.class);
context.bindService(mIntent, mConnection, Context.BIND_AUTO_CREATE);
} catch (Exception ex) {
FlyveLog.e(ex.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
* Receive broadcast from android.net.wifi.STATE_CHANGE and android.bluetooth.adapter.action.STATE_CHANGED
* on AndroidManifest.xml
*/
public class MQTTConnectivityReceiver extends BroadcastReceiver {
public class ConnectivityReceiver extends BroadcastReceiver {

/**
* It is called when it receives information about the state of the connectivity of the WIFI, Bluetooth and GPS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
import android.content.Context;
import android.content.Intent;

import org.flyve.mdm.agent.services.MQTTService;
import org.flyve.mdm.agent.services.MDMService;
import org.flyve.mdm.agent.utils.FlyveLog;

/**
* Broadcast for BOOT
*/
public class MQTTRestarterBroadcastReceiver extends BroadcastReceiver {
public class RestarterBroadcastReceiver extends BroadcastReceiver {

/**
* Re-starts the service if it stops
Expand All @@ -42,7 +42,7 @@ public class MQTTRestarterBroadcastReceiver extends BroadcastReceiver {
*/
@Override
public void onReceive(Context context, Intent intent) {
FlyveLog.d(MQTTRestarterBroadcastReceiver.class.getSimpleName(), "Service Stops!");
context.startService(new Intent(context, MQTTService.class));
FlyveLog.d(RestarterBroadcastReceiver.class.getSimpleName(), "Service Stops!");
context.startService(new Intent(context, MDMService.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
/**
* This is the service get and send message from MQTT
*/
public class MQTTService extends Service implements MqttCallback {
public class MDMService extends Service implements MqttCallback {

public static final String ACTION_START = "org.flyve.mdm.agent.ACTION_START";
public static final String ACTION_INVENTORY = "org.flyve.mdm.agent.ACTION_INVENTORY";
Expand All @@ -117,8 +117,8 @@ public class MQTTService extends Service implements MqttCallback {
IBinder mBinder = new LocalBinder();

public static Intent start(Context context) {
MQTTService mMQTTService = new MQTTService();
Intent mServiceIntent = new Intent(context.getApplicationContext(), mMQTTService.getClass());
MDMService mMDMService = new MDMService();
Intent mServiceIntent = new Intent(context.getApplicationContext(), mMDMService.getClass());

// Start the service
context.startService(mServiceIntent);
Expand All @@ -129,13 +129,13 @@ public static Intent start(Context context) {
/**
* Constructor
*/
public MQTTService() {
public MDMService() {
FlyveLog.d("MQTT Service Constructor");
}

public class LocalBinder extends Binder {
public MQTTService getServerInstance() {
return MQTTService.this;
public MDMService getServerInstance() {
return MDMService.this;
}
}

Expand Down Expand Up @@ -202,7 +202,7 @@ public void onDestroy() {
super.onDestroy();
Helpers.deleteMQTTCache(getApplicationContext());
try {
getApplicationContext().startService(new Intent(getApplicationContext(), MQTTService.class));
getApplicationContext().startService(new Intent(getApplicationContext(), MDMService.class));
} catch (Exception ex) {
FlyveLog.e(ex.getMessage());
}
Expand Down Expand Up @@ -376,7 +376,7 @@ public void run() {
executeConnection = true;
}

if(!MQTTService.this.connected) {
if(!MDMService.this.connected) {
if(executeConnection) {
reconnectionCounter++;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void useTLS(String taskId, Boolean enable) {
((Service) context).stopSelf();

// restart MQTT connection with this new parameters
MQTTService.start(MDMAgent.getInstance());
MDMService.start(MDMAgent.getInstance());

// return the status of the task
sendTaskStatus(taskId, FEEDBACK_DONE);
Expand All @@ -201,7 +201,7 @@ public void useTLS(String taskId, Boolean enable) {
((Service) context).stopSelf();

// restart MQTT connection with this new parameters
MQTTService.start(MDMAgent.getInstance());
MDMService.start(MDMAgent.getInstance());

// return the status of the task
sendTaskStatus(taskId, FEEDBACK_DONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private void statusMQTT(Boolean bval) {
}

/**
* broadcastServiceStatus instance that receive service status from MQTTService
* broadcastServiceStatus instance that receive service status from MDMService
*/
private BroadcastReceiver broadcastServiceStatus = new BroadcastReceiver() {
@Override
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/flyve/mdm/agent/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import org.flyve.mdm.agent.adapter.DrawerAdapter;
import org.flyve.mdm.agent.data.localstorage.AppData;
import org.flyve.mdm.agent.services.DeviceLockedController;
import org.flyve.mdm.agent.services.MQTTService;
import org.flyve.mdm.agent.services.MDMService;
import org.flyve.mdm.agent.services.PoliciesDeviceManager;
import org.flyve.mdm.agent.utils.FlyveLog;

Expand Down Expand Up @@ -151,7 +151,7 @@ public void globalStartMQTT() {
// ------------------
// MQTT SERVICE
// ------------------
mServiceIntent = MQTTService.start( this.getApplicationContext() );
mServiceIntent = MDMService.start( this.getApplicationContext() );
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.flyve.inventory.agent;
package org.flyve.mdm.agent;

import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
package org.flyve.mdm.agent.core.enrollment;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
package org.flyve.mdm.agent.core.deeplink;

/*
* Copyright © 2018 Teclib. All rights reserved.
Expand All @@ -27,38 +18,46 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ------------------------------------------------------------------------------
* @author rafaelhernandez
* @date 7/1/18
* @author Rafael Hernandez
* @date 9/7/18
* @copyright Copyright © 2018 Teclib. All rights reserved.
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/flyve-mdm/flyve-mdm-android
* @link https://flyve-mdm.com
* ------------------------------------------------------------------------------
*/
@RunWith(AndroidJUnit4.class)
public class EnrollmentHelperTest {

private Context context;
private EnrollmentHelper enroll;
import org.flyve.mdm.agent.BuildConfig;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import static org.mockito.Mockito.mock;

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 23)
public class DeepLinkModelRoboTest {

private Deeplink.Presenter presenter;
private DeeplinkModel model;

@Before
public void setUp() throws Exception {
context = InstrumentationRegistry.getTargetContext();
enroll = new EnrollmentHelper(context);
public void setUp() {
presenter = mock(Deeplink.Presenter.class);
model = new DeeplinkModel(presenter);
}

@Test
public void createX509certificateSuccess() throws Exception {
enroll.createX509cert(new EnrollmentHelper.EnrollCallBack() {
@Override
public void onSuccess(String data) {
Assert.assertTrue(true);
}
public void saveMQTTConfig() {
String url = "http://flyve.org";
String userToken = "41PtTmelVCT3jUb834fapiUnaq11111Z4oIFahv29";
String invitationToken = "d587e80887e3157f876b00b3eb84a20c11111f44e251bedd012a86355dd12c51";

@Override
public void onError(String error) {
Assert.assertTrue(false);
}
});
model.saveMQTTConfig(RuntimeEnvironment.application, url, userToken, invitationToken);
Assert.assertTrue(true);
}
}
}
Loading