Skip to content

Commit

Permalink
Merge branch 'release/v1.2.3' into public-main
Browse files Browse the repository at this point in the history
  • Loading branch information
KUGDev committed Nov 29, 2022
2 parents 151cc98 + 114c15d commit 6d3aa1b
Show file tree
Hide file tree
Showing 38 changed files with 586 additions and 455 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
.idea/modules
.idea/.gitignore
build
gradle
.gradle
.gradle.properties
bin
.vscode
gradle/wrapper/gradle-wrapper.jar
gradle.properties.for-release
23 changes: 23 additions & 0 deletions .run/Run integration tests.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run integration tests" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="intTest" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<method v="2" />
</configuration>
</component>
23 changes: 23 additions & 0 deletions .run/Run unit tests.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run unit tests" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="-x signArchives" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="test" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<method v="2" />
</configuration>
</component>
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,24 @@ if (response.isSuccessful){
val members = response.body();
}
```
Please note that in order to create API stub, you have to specify that the response should be converted by gson. And that's how you can easily use r2z.
Please note that in order to create API stub, you have to specify that the response should be converted by gson. And that's how you can easily use r2z.

## How to run tests

### Unit tests
To run unit tests:
```
./gradlew test -x signArchives
```
### Integration tests
**NOTE:** integration tests use a specific environment. To test their correctness, you need either create the compliant one, or change the tests

Before running integration tests, you need three variables to be set up:
- ``ZOSMF_TEST_URL`` - URL of the real mainframe with z/OSMF API to run the tests
- ``ZOSMF_TEST_USERNAME`` - username with appropriate permissions to run the tests
- ``ZOSMF_TEST_PASSWORD`` - user password to run the tests

To run integration tests:
```
./gradlew intTest
```
46 changes: 41 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ repositories {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib"
implementation "org.jetbrains.kotlin:kotlin-reflect:1.4.21"
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
testImplementation 'com.squareup.okhttp:mockwebserver:1.2.1'
implementation "org.jetbrains.kotlin:kotlin-reflect:1.6.21"
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testImplementation 'com.squareup.okhttp3:mockwebserver:4.10.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
implementation 'com.squareup.retrofit2:retrofit:2.9.0',
'com.squareup.retrofit2:converter-gson:2.9.0',
'com.squareup.retrofit2:converter-scalars:2.9.0',
'com.google.code.gson:gson:2.9.0',
'com.google.code.gson:gson:2.10',
'com.starxg:java-keytar:1.0.0',
'org.yaml:snakeyaml:1.29',
'org.junit.jupiter:junit-jupiter-api:5.8.2'
Expand All @@ -59,6 +59,43 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
from javadoc.destinationDir
}

/**
* Adds intTest source sets
*/
sourceSets {
intTest {
java {
compileClasspath += main.output
runtimeClasspath += main.output
srcDir 'src/intTest/kotlin'
}
resources {
srcDir 'src/intTest/resources'
}
}
}

/**
* Configures the integration tests to inherit the testImplementation and testRuntimeOnly in dependencies
*/
configurations {
intTestImplementation.extendsFrom testImplementation
intTestRuntimeOnly.extendsFrom testRuntimeOnly
}

task intTest(type:Test) {
description = "Run integration tests"
group = "verification"
testClassesDirs = sourceSets.intTest.output.classesDirs
classpath = sourceSets.intTest.runtimeClasspath
useJUnitPlatform() {
excludeTags "FirstTime"
}
testLogging {
events("passed", "skipped", "failed")
}
}

artifacts {
archives jar
archives sourceJar
Expand Down Expand Up @@ -151,7 +188,6 @@ def customizePom(pom) {
}
}


model {
tasks.generatePomFileForMavenJavaPublication {
destination = file("$buildDir/generated-pom.xml")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ signing.keyId=FADC1195
signing.password=key_pass
signing.secretKeyRingFile=path/to/secret/key

projectVersion=1.2.2
projectVersion=1.2.3
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
12 changes: 12 additions & 0 deletions src/intTest/intTest.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/kotlin" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="true" />
<orderEntry type="library" scope="TEST" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib:1.6.21" level="project" />
</component>
</module>
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright © 2020 IBA Group, a.s. All rights reserved. Use of this source code is governed by Eclipse Public License – v 2.0 that can be found at: https://www.eclipse.org/legal/epl-2.0/

package eu.ibagroup.r2z
package common

import eu.ibagroup.r2z.BytesConverterFactory
import okhttp3.Credentials
import okhttp3.OkHttpClient
import retrofit2.Retrofit
Expand Down Expand Up @@ -38,7 +39,7 @@ open class BaseTest {
return try {


val trustAllCerts: Array<TrustManager> = arrayOf<TrustManager>(
val trustAllCerts: Array<TrustManager> = arrayOf(
object : X509TrustManager {
@Throws(CertificateException::class)
override fun checkClientTrusted(
Expand All @@ -62,7 +63,7 @@ open class BaseTest {
val sslContext: SSLContext = SSLContext.getInstance("TLSv1.2")
sslContext.init(null, trustAllCerts, SecureRandom())

val sslSocketFactory: SSLSocketFactory = sslContext.getSocketFactory()
val sslSocketFactory: SSLSocketFactory = sslContext.socketFactory
val builder = OkHttpClient.Builder()
builder.sslSocketFactory(sslSocketFactory, trustAllCerts[0] as X509TrustManager)
builder.hostnameVerifier(object : HostnameVerifier {
Expand All @@ -75,4 +76,4 @@ open class BaseTest {
throw RuntimeException(e)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright © 2020 IBA Group, a.s. All rights reserved. Use of this source code is governed by Eclipse Public License – v 2.0 that can be found at: https://www.eclipse.org/legal/epl-2.0/

package eu.ibagroup.r2z
package common

import eu.ibagroup.r2z.CancelJobPurgeOutRequest
import eu.ibagroup.r2z.JESApi
import eu.ibagroup.r2z.ProcessMethod
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import retrofit2.Call
Expand Down Expand Up @@ -43,7 +46,7 @@ class CancelJobAndPurgeOutputTest : BaseTest() {
println(jobStatus.status)
Assertions.assertEquals(SUCCESSFUL_REQUEST_RESULT, jobStatus.status)
Assertions.assertNotNull(jobStatus.owner)
Assertions.assertEquals(jobStatus.owner?.toLowerCase(), "hlh")
Assertions.assertEquals(jobStatus.owner?.lowercase(), "hlh")
} else
{
println(response.errorBody())
Expand Down
58 changes: 58 additions & 0 deletions src/intTest/kotlin/common/CancelJobTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright © 2020 IBA Group, a.s. All rights reserved. Use of this source code is governed by Eclipse Public License – v 2.0 that can be found at: https://www.eclipse.org/legal/epl-2.0/

package common

import eu.ibagroup.r2z.CancelJobRequest
import eu.ibagroup.r2z.CancelJobRequestBody
import eu.ibagroup.r2z.JESApi
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import retrofit2.Call
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

class CancelJobTest : BaseTest() {
val JOB_ID = "JOB06200"
val JOB_NAME = "NOTHINGJ"

val JOB_CORRELATOR = "J0001561S0W1....D940967F.......:"

// 0 - request was successful
val SUCCESSFUL_REQUEST_RESULT = "0"

@Test
fun cancelJobTest() {
val retrofit = Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(getUnsafeOkHttpClient())
.build()

val request = retrofit.create(JESApi::class.java)
val call: Call<CancelJobRequest> = request
.cancelJobRequest(
BASIC_AUTH_TOKEN,
JOB_NAME,
JOB_ID,
CancelJobRequestBody()
)
enqueueCancelJobCallAndCheckResult(call)
}

fun enqueueCancelJobCallAndCheckResult(call: Call<CancelJobRequest>) {
val response = call.execute()

if (response.isSuccessful)
{
val jobStatus: CancelJobRequest = response.body() as CancelJobRequest
println(jobStatus.status)
Assertions.assertEquals(SUCCESSFUL_REQUEST_RESULT, jobStatus.status)
Assertions.assertNotNull(jobStatus.owner)
Assertions.assertEquals(jobStatus.owner?.lowercase(), "hlh")
} else
{
println(response.errorBody())
Assertions.assertTrue(false)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright © 2020 IBA Group, a.s. All rights reserved. Use of this source code is governed by Eclipse Public License – v 2.0 that can be found at: https://www.eclipse.org/legal/epl-2.0/

package eu.ibagroup.r2z
package common

import eu.ibagroup.r2z.*
import org.junit.jupiter.api.Test


Expand Down
80 changes: 80 additions & 0 deletions src/intTest/kotlin/common/HoldJobFor10sThenReleaseTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright © 2020 IBA Group, a.s. All rights reserved. Use of this source code is governed by Eclipse Public License – v 2.0 that can be found at: https://www.eclipse.org/legal/epl-2.0/
package common

import eu.ibagroup.r2z.*
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import retrofit2.Call
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.*

class HoldJobFor10sThenReleaseTest : BaseTest() {
val JOB_ID = "JOB06152"
val JOB_NAME = "NOTHINGJ"

val JOB_CORRELATOR = "J0001561S0W1....D940967F.......:"

// 0 - request was successful
val SUCCESSFUL_REQUEST_RESULT = 0

@Test
fun holdFor10sThenReleaseJobTest() {
val retrofit = Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(getUnsafeOkHttpClient())
.build()

val request = retrofit.create(JESApi::class.java)
val firstCall: Call<HoldJobRequest> = request
.holdJobRequest(
BASIC_AUTH_TOKEN,
JOB_NAME,
JOB_ID,
HoldJobRequestBody()
)

enqueueHoldCallAndCheckResult(firstCall)

Thread.sleep(10000)

val secondCall: Call<ReleaseJobRequest> = request
.releaseJobRequest(
BASIC_AUTH_TOKEN,
JOB_NAME,
JOB_ID,
ReleaseJobRequestBody()
)

enqueueReleaseCallAndCheckResult(secondCall)
}

fun enqueueHoldCallAndCheckResult(call: Call<HoldJobRequest>) {
val response = call.execute()
if (response.isSuccessful) {
val jobStatus: HoldJobRequest = response.body() as HoldJobRequest
println(jobStatus.status)
Assertions.assertEquals(SUCCESSFUL_REQUEST_RESULT, jobStatus.status)
Assertions.assertNotNull(jobStatus.owner)
Assertions.assertEquals(jobStatus.owner?.lowercase(Locale.getDefault()), "hlh")
} else {
println(response.errorBody())
Assertions.assertTrue(false)
}
}

fun enqueueReleaseCallAndCheckResult(call: Call<ReleaseJobRequest>) {
val response = call.execute()
if (response.isSuccessful) {
val jobStatus: ReleaseJobRequest = response.body() as ReleaseJobRequest
println(jobStatus.status)
Assertions.assertEquals(SUCCESSFUL_REQUEST_RESULT, jobStatus.status)
Assertions.assertNotNull(jobStatus.owner)
Assertions.assertEquals(jobStatus.owner?.lowercase(Locale.getDefault()), "hlh")
} else {
println(response.errorBody())
Assertions.assertTrue(false)
}
}
}
Loading

0 comments on commit 6d3aa1b

Please sign in to comment.