Skip to content
Merged
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
5 changes: 5 additions & 0 deletions commonmark-android-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.gradle
local.properties
test.properties
gradle.properties
build
95 changes: 95 additions & 0 deletions commonmark-android-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
commonmark-android-test
=======================

This module ensures that commonmark-java is supported on Android

Requirements:

* Java 7 or above
* Android SDK 15
* Running emulator or connected android device

Configuration
-----

1. Download Android SDK
2. Be sure that SDK Platform 15 and emulator for this platform (system image) are installed. It's recommended to use x86
3. Export to PATH: `path_to_android_sdk/platform-tools` and `path_to_android_sdk/tools`
4. Create 2 properties files in commonmark-android-test

/local.properties
```properties
sdk.dir=/path_to_android_sdk
```

/test.properties
```properties
# Absolute or relative (./ == /app) path to test reports.
path.report=../report

# Version number of commonmark and extensions in maven central.
version.maven=0.4.0

# Version number of commonmark and extensions in project.
version.snapshot=0.4.1-SNAPSHOT
# Version number of autolink for snapshots (since it's not contained in extension jar).
version.snapshot_autolink=0.3.0
```

If you're going to test on device with Android 15 then you can skip downloading emulator.

Usage
-----

#### Run test with MAVEN version

on Mac/Linux:
```shell
./gradlew :app:connectedMavenDebugAndroidTest
```

on Windows:
```bat
.\gradlew :app:connectedMavenDebugAndroidTest
```

#### Run test with SNAPSHOT version

Before running tests you need to run `maven install`

on Mac/Linux:
```shell
./gradlew :app:connectedSnapshotDebugAndroidTest
```

on Windows:
```bat
.\gradlew :app:connectedSnapshotDebugAndroidTest
```


#### Testing in CI

on Mac/Linux:
```shell
echo no | android create avd --force -n test -t "android-15"
emulator -avd test &
adb wait-for-device
./gradlew :app:clean :app:connectedSnapshotDebugAndroidTest
adb emu kill
```

on Windows:
```bat
echo no | android create avd --force -n test -t "android-15"
start emulator -avd test
adb wait-for-device
gradlew :app:clean :app:connectedSnapshotDebugAndroidTest & adb emu kill
```

There could be problems with command `adb wait-for-device` which could be resolved by adding additional pause before running test.

Links
-----
[Gradle Documentations](https://docs.gradle.org/current/userguide/userguide.html)
[Android Gradle Plugin Docs](http://tools.android.com/tech-docs/new-build-system)
74 changes: 74 additions & 0 deletions commonmark-android-test/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
apply plugin: 'com.android.application'

def testProperties
def testPropertiesFile = file('../test.properties')
if (testPropertiesFile.canRead()) {
testProperties = new Properties()
testPropertiesFile.withInputStream {
stream -> testProperties.load(stream)
}
}

android {
compileSdkVersion 15
buildToolsVersion "23.0.2"

defaultConfig {
applicationId "com.atlassian.commonmark.android.test"
minSdkVersion 15
targetSdkVersion 15
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

productFlavors {
maven
snapshot
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}

packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
}

testOptions {
resultsDir = testProperties['path.report']
}
}

repositories {
flatDir {
dirs '../../commonmark/target',
'../../commonmark-ext-autolink/target',
'../../commonmark-ext-gfm-strikethrough/target',
'../../commonmark-ext-gfm-tables/target',
'../../commonmark-test-util/target'
}
}

dependencies {
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'

androidTestCompile ':commonmark-test-util-' + testProperties['version.snapshot']

androidTestMavenCompile 'com.atlassian.commonmark:commonmark:' + testProperties['version.maven']
androidTestMavenCompile 'com.atlassian.commonmark:commonmark-ext-autolink:' + testProperties['version.maven']
androidTestMavenCompile 'com.atlassian.commonmark:commonmark-ext-gfm-strikethrough:' + testProperties['version.maven']
androidTestMavenCompile 'com.atlassian.commonmark:commonmark-ext-gfm-tables:' + testProperties['version.maven']

androidTestSnapshotCompile 'org.nibor.autolink:autolink:' + testProperties['version.snapshot_autolink']
androidTestSnapshotCompile ':commonmark-' + testProperties['version.snapshot']
androidTestSnapshotCompile ':commonmark-ext-autolink-' + testProperties['version.snapshot']
androidTestSnapshotCompile ':commonmark-ext-gfm-strikethrough-' + testProperties['version.snapshot']
androidTestSnapshotCompile ':commonmark-ext-gfm-tables-' + testProperties['version.snapshot']
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.atlassian.commonmark.android.test;

import org.commonmark.Extension;
import org.commonmark.ext.autolink.AutolinkExtension;
import org.commonmark.ext.gfm.strikethrough.StrikethroughExtension;
import org.commonmark.ext.gfm.tables.TablesExtension;
import org.commonmark.html.HtmlRenderer;
import org.commonmark.node.Node;
import org.commonmark.parser.Parser;
import org.commonmark.spec.SpecReader;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;

import java.util.Collections;

import static org.junit.Assert.assertNotNull;

@RunWith(AndroidJUnit4.class)
@SmallTest
public class AndroidSupportTest {

private String spec;

@Before
public void setUp() throws Exception {
spec = SpecReader.readSpec();
}

@Test
public void parseTest() throws Exception {
Parser parser = new Parser.Builder().build();

Node document = parser.parse(spec);

assertNotNull(document);
}

@Test
public void autolinkExtensionTest() throws Exception {
parseWithExtensionsTest(AutolinkExtension.create());
}

@Test
public void strikethroughExtensionTest() throws Exception {
parseWithExtensionsTest(StrikethroughExtension.create());
}

@Test
public void tablesExtensionTest() throws Exception {
parseWithExtensionsTest(TablesExtension.create());
}

@Test
public void htmlRendererTest() throws Exception {
Parser parser = new Parser.Builder().build();
HtmlRenderer renderer = new HtmlRenderer.Builder().build();

String renderedString = renderer.render(parser.parse(spec));

assertNotNull(renderedString);
}

private void parseWithExtensionsTest(Extension extension) throws Exception {
Parser parser = new Parser.Builder()
.extensions(Collections.singletonList(extension))
.build();

Node document = parser.parse(spec);

assertNotNull(document);
}
}
3 changes: 3 additions & 0 deletions commonmark-android-test/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest package="com.atlassian.commonmark.android.test">
<application />
</manifest>
18 changes: 18 additions & 0 deletions commonmark-android-test/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}

allprojects {
repositories {
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Mon Dec 28 10:00:20 PST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
Loading