Skip to content

Commit

Permalink
MQTT Helper Classes + Fixed GPS permission
Browse files Browse the repository at this point in the history
  • Loading branch information
irinil committed Jun 25, 2020
1 parent 1f54ceb commit b717011
Show file tree
Hide file tree
Showing 10 changed files with 1,137 additions and 38 deletions.
17 changes: 13 additions & 4 deletions build.gradle
Expand Up @@ -2,7 +2,6 @@ buildscript {
repositories {
jcenter()
google()

}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
Expand All @@ -18,7 +17,6 @@ allprojects {
google()

maven { url "https://jitpack.io" }

}
}
dependencies {
Expand All @@ -38,9 +36,11 @@ dependencies {
implementation 'org.greenrobot:greendao:3.3.0'
implementation 'org.greenrobot:greendao-generator:3.3.0'
//hive-Mq
implementation 'com.github.hivemq.hivemq-community-edition:hivemq-community-edition:2020.1'
implementation group: 'com.hivemq', name: 'hivemq-mqtt-client', version: '1.2.0'
//android X migration
//moquette
implementation 'io.moquette:moquette-broker:0.12.1'

//androidX legacy support
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.preference:preference:1.1.1'

Expand All @@ -54,6 +54,8 @@ dependencies {
implementation files('libs/snmp4j-agent-2.3.3.jar')
implementation files('libs/VirusTotalAPI.jar')

//switchButton
implementation 'com.github.zcweng:switch-button:0.0.3@aar'

// Required -- JUnit 4 framework
testImplementation 'junit:junit:4.12'
Expand Down Expand Up @@ -82,6 +84,10 @@ greendao{
//generateTests true
// targetGenDir "src/db/"
}
//this is for the conflict of common apache libraries between moquette and VirusTotalApi
configurations {
all*.exclude group: 'commons-codec', module: 'commons-codec'
}

android {
compileSdkVersion 28
Expand All @@ -93,7 +99,9 @@ android {
targetSdkVersion 28
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
useLibrary 'org.apache.http.legacy'
// signingConfig signingConfigs.config

}
testOptions {
unitTests {
Expand All @@ -112,6 +120,7 @@ android {
release.setRoot('build-types/release')
}


packagingOptions {
pickFirst "META-INF/DEPENDENCIES"
pickFirst "META-INF/INDEX.LIST"
Expand Down
@@ -0,0 +1,261 @@
package de.tudarmstadt.informatik.hostage.ui.activity;


import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;

import androidx.test.espresso.DataInteraction;
import androidx.test.espresso.ViewInteraction;
import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import de.tudarmstadt.informatik.hostage.R;

import static androidx.test.espresso.Espresso.onData;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withClassName;
import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.anything;
import static org.hamcrest.Matchers.is;

@LargeTest
@RunWith(AndroidJUnit4.class)
public class BasicUtilitiesTest {

@Rule
public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class);

@Test
public void basicUtilitiesTest() {
// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}

ViewInteraction button = onView(
allOf(withId(android.R.id.button1), withText("Agree"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
0),
2),
isDisplayed()));
button.perform(click());

ViewInteraction switch_ = onView(
allOf(withId(R.id.home_switch_connection),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
1),
1),
isDisplayed()));
switch_.perform(click());

ViewInteraction imageView = onView(
allOf(withId(R.id.home_button_connection_info),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
0),
1),
isDisplayed()));
imageView.perform(click());

ViewInteraction button2 = onView(
allOf(withId(android.R.id.button1), withText("Show records"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
0),
2),
isDisplayed()));
button2.perform(click());

ViewInteraction linearLayout = onView(
allOf(withContentDescription("Records, Open navigation drawer"),
childAtPosition(
allOf(withClassName(is("com.android.internal.widget.ActionBarView")),
childAtPosition(
withClassName(is("com.android.internal.widget.ActionBarContainer")),
0)),
0),
isDisplayed()));
linearLayout.perform(click());

DataInteraction linearLayout2 = onData(anything())
.inAdapterView(allOf(withId(R.id.left_drawer),
childAtPosition(
withId(R.id.drawer_layout),
1)))
.atPosition(4);
linearLayout2.perform(click());

// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try {
Thread.sleep(7000);
} catch (InterruptedException e) {
e.printStackTrace();
}

ViewInteraction imageView2 = onView(
allOf(withId(R.id.services_button_connection_info),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
0),
1),
isDisplayed()));
imageView2.perform(click());

ViewInteraction button3 = onView(
allOf(withId(android.R.id.button1), withText("Show records"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
0),
2),
isDisplayed()));
button3.perform(click());

ViewInteraction linearLayout3 = onView(
allOf(withContentDescription("Records, Open navigation drawer"),
childAtPosition(
allOf(withClassName(is("com.android.internal.widget.ActionBarView")),
childAtPosition(
withClassName(is("com.android.internal.widget.ActionBarContainer")),
0)),
0),
isDisplayed()));
linearLayout3.perform(click());

DataInteraction linearLayout4 = onData(anything())
.inAdapterView(allOf(withId(R.id.left_drawer),
childAtPosition(
withId(R.id.drawer_layout),
1)))
.atPosition(6);
linearLayout4.perform(click());

DataInteraction linearLayout5 = onData(anything())
.inAdapterView(allOf(withId(android.R.id.list),
childAtPosition(
withId(android.R.id.list_container),
0)))
.atPosition(1);
linearLayout5.perform(click());

DataInteraction linearLayout6 = onData(anything())
.inAdapterView(allOf(withId(android.R.id.list),
childAtPosition(
withId(android.R.id.list_container),
0)))
.atPosition(1);
linearLayout6.perform(click());

ViewInteraction relativeLayout = onView(
allOf(childAtPosition(
childAtPosition(
withId(android.R.id.list),
1),
1),
isDisplayed()));
relativeLayout.check(matches(isDisplayed()));

ViewInteraction linearLayout7 = onView(
allOf(withContentDescription("Settings, Open navigation drawer"),
childAtPosition(
allOf(withClassName(is("com.android.internal.widget.ActionBarView")),
childAtPosition(
withClassName(is("com.android.internal.widget.ActionBarContainer")),
0)),
0),
isDisplayed()));
linearLayout7.perform(click());

DataInteraction linearLayout8 = onData(anything())
.inAdapterView(allOf(withId(R.id.left_drawer),
childAtPosition(
withId(R.id.drawer_layout),
1)))
.atPosition(6);
linearLayout8.perform(click());

ViewInteraction linearLayout9 = onView(
allOf(withContentDescription("Settings, Open navigation drawer"),
childAtPosition(
allOf(withClassName(is("com.android.internal.widget.ActionBarView")),
childAtPosition(
withClassName(is("com.android.internal.widget.ActionBarContainer")),
0)),
0),
isDisplayed()));
linearLayout9.perform(click());

DataInteraction linearLayout10 = onData(anything())
.inAdapterView(allOf(withId(R.id.left_drawer),
childAtPosition(
withId(R.id.drawer_layout),
1)))
.atPosition(1);
linearLayout10.perform(click());

// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try {
Thread.sleep(7000);
} catch (InterruptedException e) {
e.printStackTrace();
}

ViewInteraction relativeLayout2 = onView(
allOf(childAtPosition(
childAtPosition(
withId(R.id.threatmapfragment),
0),
0),
isDisplayed()));
relativeLayout2.check(matches(isDisplayed()));
}

private static Matcher<View> childAtPosition(
final Matcher<View> parentMatcher, final int position) {

return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}

@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent)
&& view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}
}

0 comments on commit b717011

Please sign in to comment.