![JAR search and dependency download from the Maven repository](/logo.png)
io.codearte.accurest.stubrunner.RunningStubs.groovy Maven / Gradle / Ivy
package io.codearte.accurest.stubrunner
import groovy.transform.CompileStatic
import groovy.transform.EqualsAndHashCode
/**
* Structure representing executed stubs. Contains the configuration of each stub
* together with the port on which its executed.
*/
@EqualsAndHashCode
@CompileStatic
class RunningStubs {
final Map namesAndPorts = [:]
RunningStubs(Map map) {
this.namesAndPorts.putAll(map)
}
RunningStubs(Collection runningStubs) {
runningStubs.each {
this.namesAndPorts.putAll(it.namesAndPorts)
}
}
Integer getPort(String artifactId) {
return getEntry(artifactId)?.value
}
Map.Entry getEntry(String artifactId) {
return namesAndPorts.entrySet().find {
it.key.matchesIvyNotation(artifactId)
}
}
Integer getPort(String groupId, String artifactId) {
return namesAndPorts.entrySet().find {
it.key.matchesIvyNotation("$groupId:$artifactId")
}?.value
}
boolean isPresent(String artifactId) {
return getEntry(artifactId)
}
boolean isPresent(String groupId, String artifactId) {
return namesAndPorts.entrySet().find {
it.key.matchesIvyNotation("$groupId:$artifactId")
}
}
Set getAllServices() {
return namesAndPorts.keySet()
}
Set getAllServicesNames() {
return namesAndPorts.keySet().collect { it.artifactId } as Set
}
Map toIvyToPortMapping() {
return namesAndPorts.collectEntries { [(it.key.toColonSeparatedDependencyNotation()) : it.value] } as Map
}
@Override
String toString() {
return namesAndPorts.collect {
"Stub [${it.key.toColonSeparatedDependencyNotation()}] is running on port [${it.value}]"
}.join("\n")
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy