Skip to content

Commit 13f3c1b

Browse files
author
Nickolay Savchenko
committed
Fix startup test server
1 parent 63c74ad commit 13f3c1b

File tree

6 files changed

+67
-25
lines changed

6 files changed

+67
-25
lines changed

example-client/build.gradle

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,12 @@ android {
4545
}
4646

4747
dependencies {
48-
compile fileTree(dir: 'libs', include: ['*.jar'])
49-
testCompile 'junit:junit:4.12'
50-
compile 'com.android.support:appcompat-v7:28.0.0'
51-
compile 'org.java-websocket:Java-WebSocket:1.3.6'
52-
compile 'com.android.support:recyclerview-v7:28.0.0'
53-
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
54-
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
55-
compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
56-
compile 'com.squareup.retrofit2:retrofit:2.3.0'
57-
compile project(':lib')
48+
implementation 'com.android.support:appcompat-v7:28.0.0'
49+
implementation 'org.java-websocket:Java-WebSocket:1.3.6'
50+
implementation 'com.android.support:recyclerview-v7:28.0.0'
51+
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
52+
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
53+
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
54+
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
55+
implementation project(':lib')
5856
}

lib/build.gradle

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ buildscript {
99
dependencies {
1010
classpath 'com.android.tools.build:gradle:3.2.1'
1111
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
12+
classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:2.0.0'
1213
}
1314
}
1415

@@ -19,6 +20,7 @@ repositories {
1920

2021
apply plugin: 'com.android.library'
2122
apply plugin: 'com.github.dcendents.android-maven'
23+
apply plugin: 'groovyx.android'
2224

2325
group='com.github.NaikSoftware'
2426

@@ -43,20 +45,27 @@ android {
4345
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
4446
}
4547
}
48+
49+
testOptions {
50+
unitTests.returnDefaultValues = true
51+
}
4652
}
4753

4854

4955
dependencies {
5056
implementation "io.reactivex.rxjava2:rxjava:2.1.15"
5157
// Supported transports
52-
compileOnly 'org.java-websocket:Java-WebSocket:1.3.6'
53-
compileOnly 'com.squareup.okhttp3:okhttp:3.10.0'
58+
api 'org.java-websocket:Java-WebSocket:1.3.6'
59+
api 'com.squareup.okhttp3:okhttp:3.10.0'
5460

5561
implementation 'com.android.support:support-annotations:28.0.0'
5662

63+
testImplementation "com.andrewreitz:spock-android:2.0.0"
5764
testImplementation 'org.testcontainers:testcontainers:1.8.0'
5865
testImplementation 'org.spockframework:spock-core:1.1-groovy-2.4'
59-
testImplementation 'org.spockframework:spock-spring:1.1-groovy-2.4'
66+
testImplementation 'org.java-websocket:Java-WebSocket:1.3.6'
67+
testImplementation 'com.squareup.okhttp3:okhttp:3.10.0'
68+
testImplementation 'ch.qos.logback:logback-classic:1.2.3'
6069
}
6170

6271
task sourcesJar(type: Jar) {
Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
11
package ua.naiksoftware.stomp
22

3+
import com.andrewreitz.spock.android.AndroidSpecification
4+
import groovy.util.logging.Slf4j
35
import org.testcontainers.containers.BindMode
46
import org.testcontainers.containers.GenericContainer
7+
import org.testcontainers.containers.output.OutputFrame
58
import org.testcontainers.containers.wait.strategy.Wait
69
import spock.lang.Shared
710
import spock.lang.Specification
811

9-
class Configuration extends Specification implements ApplicationContextInitializer<ConfigurableApplicationContext> {
12+
import java.util.function.Consumer
13+
14+
class Configuration extends AndroidSpecification {
1015

1116
@Shared
1217
static GenericContainer testServer = setupServer()
1318

14-
GenericContainer setupServer() {
19+
static GenericContainer setupServer() {
1520

16-
new ProcessBuilder('./gradlew bootJar')
21+
def projectRoot = new File('../')
22+
new ProcessBuilder(['./gradlew', 'test-server:bootJar'])
23+
.directory(projectRoot)
1724
.start().waitForProcessOutput(System.out as Appendable, System.err as Appendable)
1825

19-
return new GenericContainer('openjdk:8-jre-alpine')
20-
.withClasspathResourceMapping('./build/artifacts/test-server-1.0.jar', '/app.jar', BindMode.READ_ONLY)
26+
def testServerPath = new File(projectRoot.getAbsoluteFile().getParentFile().getParent(),
27+
'test-server/build/artifacts/test-server-1.0.jar').path
28+
testServer = new GenericContainer('openjdk:8-jre-alpine')
29+
.withFileSystemBind(testServerPath, '/app.jar', BindMode.READ_ONLY)
2130
.withCommand('java -jar /app.jar')
22-
.waitingFor(Wait.forHttp('/health'))
31+
.withLogConsumer({ frame -> println frame.utf8String })
32+
// .waitingFor(Wait.forHttp('/health'))
2333
.withExposedPorts(80)
34+
testServer.start()
35+
return testServer
2436
}
2537
}
Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,40 @@
11
package ua.naiksoftware.stomp
22

3+
import groovy.util.logging.Log4j
4+
import groovy.util.logging.Slf4j
5+
import io.reactivex.Flowable
6+
import io.reactivex.annotations.NonNull
7+
import io.reactivex.functions.Predicate
8+
import io.reactivex.subscribers.TestSubscriber
9+
import org.testcontainers.containers.GenericContainer
10+
import spock.lang.Shared
311
import ua.naiksoftware.stomp.Configuration
412
import ua.naiksoftware.stomp.Stomp
513

14+
import java.util.concurrent.TimeUnit
15+
616
class ConnectionTests extends Configuration {
717

8-
def "connection must be recreated when reconnect"() {
18+
def "connection must be opened"() {
919
given:
10-
def client = Stomp.over(Stomp.ConnectionProvider.OKHTTP, 'localhost/websocket')
20+
def client = Stomp.over(Stomp.ConnectionProvider.OKHTTP,
21+
'http://' + Configuration.testServer.getContainerIpAddress()
22+
+ ':' + Configuration.testServer.getMappedPort(80) + '/websocket')
1123
client.connect()
24+
def testSubscriber = new TestSubscriber<LifecycleEvent>()
1225

1326
when:
14-
client.disconnect()
27+
client.lifecycle().subscribe(testSubscriber)
1528

1629
then:
17-
client.isConnected() == false
18-
client.isConnecting() == false
30+
testSubscriber.awaitCount(1).assertValue((Predicate) { event ->
31+
if (event.exception) {
32+
event.exception.printStackTrace()
33+
}
34+
assert event.type == LifecycleEvent.Type.OPENED
35+
})
36+
37+
// cleanup:
38+
// client.disconnect()
1939
}
2040
}

test-server/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ repositories {
3030
dependencies {
3131
compile 'org.springframework.boot:spring-boot-starter-websocket'
3232
compile 'org.springframework.boot:spring-boot-starter-web'
33+
compile 'ch.qos.logback:logback-classic:1.2.3'
3334
compile 'org.codehaus.groovy:groovy-all:2.4.15'
3435
}
3536

@@ -40,6 +41,6 @@ dependencyManagement {
4041
}
4142

4243
bootJar {
43-
destinationDir = new File("./build/artifacts")
44+
destinationDir = project.file("build/artifacts")
4445
}
4546

test-server/src/main/resources/application.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
server.port=80
2+
13
spring.jackson.deserialization.accept_empty_string_as_null_object=true
24
spring.jackson.property-naming-strategy=CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES
35
spring.jackson.serialization.write_char_arrays_as_json_arrays=true

0 commit comments

Comments
 (0)