Skip to content

Commit

Permalink
Release 1.7 (#29)
Browse files Browse the repository at this point in the history
- Create mechanism for request recording
- Refactoring.
- Increase performance
- Documentation
- Improve builders for java code configuration
- Improve data structures
- Add gradle wrapper
- Add ktlint
- Add variables for log request/response
- Add request counter
- Add delay for response
- Remove kotlinx package
  • Loading branch information
laviua authored Aug 31, 2017
1 parent 68ff600 commit cdf20df
Show file tree
Hide file tree
Showing 42 changed files with 239 additions and 137 deletions.
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ script:
branches:
only:
- master
- develop
- develop
cache:
directories:
- '$HOME/.m2/repository'
- '$HOME/.gradle'
- '.gradle'
14 changes: 2 additions & 12 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
# Change Log
All notable changes to this project will be documented in this file.

## [1.6.3] - 2017-08-28
## [1.7.0] - 2017-08-31
### Changes
- Create mechanism for request recording
- Refactoring.
- Increase performance

## [1.6.2] - 2017-08-06
### Changes
- Refactoring.
- Increase performance
- Documentation
- Improve builders for java code configuration
- Improve data structures
- Remove unused functionality
- Add gradle wrapper
- Add ktlint

## [1.6.1] - 2017-07-11
### Changes
- Add variables for log request/response
- Add request counter
- Add delay for response
- Add documentation and unit tests
- Remove kotlinx package
- Refactoring

## [1.6] - 2017-04-02
### Changes
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.6.3
version=1.7
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip
7 changes: 7 additions & 0 deletions komock-core/mock_example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ springConfig:
enabled: true
keyStoreLocation: mock_keystore.jks
keyStorePassword: mockpassword
routes:
-
httpMethod: GET
url: /testNoContent
contentType: text/plain
responseBody: This content will be ignored
code: 204

httpServers:
-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import java.util.regex.Pattern
* Replace input line by parameters map
* Created by Oleksandr Loushkin on 10.07.2017.
*/

object VariableResolver {

private val parameterRegexp = Pattern.compile("\\$\\{(.+?)}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package ua.com.lavi.komock.engine.handler.after
import ua.com.lavi.komock.engine.model.Request
import ua.com.lavi.komock.engine.model.Response

/**
* Created by Oleksandr Loushkin
*/

class EmptyAfterResponseHandlerImpl : AfterResponseHandler {
override fun handle(request: Request, response: Response) {
// nothing to do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ua.com.lavi.komock.engine.model.config.http.RouteProperties
/**
* Created by Oleksandr Loushkin on 10.07.17.
*/

class LogAfterResponseHandlerImpl(private val routeProperties: RouteProperties) : AfterResponseHandler {

private val log = LoggerFactory.getLogger(this.javaClass)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package ua.com.lavi.komock.engine.handler.before
import ua.com.lavi.komock.engine.model.Request
import ua.com.lavi.komock.engine.model.Response

/**
* Created by Oleksandr Loushkin
*/

class EmptyBeforeResponseHandlerImpl : BeforeResponseHandler {

override fun handle(request: Request, response: Response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.util.concurrent.atomic.AtomicInteger
/**
* Created by Oleksandr Loushkin on 10.07.17.
*/

class LogBeforeResponseHandlerImpl(private val routeProperties: RouteProperties) : BeforeResponseHandler {

private val log = LoggerFactory.getLogger(this.javaClass)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ua.com.lavi.komock.engine.model.Response
/**
* Created by Oleksandr Loushkin on 30.03.17.
*/

interface CallbackHandler {
fun handle(request: Request, response: Response)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import kotlin.concurrent.thread
/**
* Created by Oleksandr Loushkin on 10.07.17.
*/

class CallbackHandlerImpl(private val callbackProperties: CallbackProperties) : CallbackHandler {

private val log = LoggerFactory.getLogger(this.javaClass)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package ua.com.lavi.komock.engine.handler.callback
import ua.com.lavi.komock.engine.model.Request
import ua.com.lavi.komock.engine.model.Response

/**
* Created by Oleksandr Loushkin
*/

class EmptyCallbackHandlerImpl : CallbackHandler {

override fun handle(request: Request, response: Response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package ua.com.lavi.komock.engine.handler.response
import ua.com.lavi.komock.engine.model.Request
import ua.com.lavi.komock.engine.model.Response

/**
* Created by Oleksandr Loushkin
*/

class EmptyResponseHandler : ResponseHandler {

override fun handle(request: Request, response: Response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ua.com.lavi.komock.engine.model.config.http.RouteProperties
/**
* Created by Oleksandr Loushkin on 10.07.17.
*/

open class RoutedResponseHandlerImpl(private val routeProperties: RouteProperties) : ResponseHandler {

override fun handle(request: Request, response: Response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ data class SpringConfigResponse(val name: String,
val profiles: List<String> = ArrayList(),
val label: String?,
val version: String?,
val propertySources: List<PropertySource> = ArrayList())
val propertySources: List<PropertySource> = ArrayList()) {

constructor(name: String, profiles: List<String>, propertySources: List<PropertySource>) : this(name, profiles, null, null, propertySources)
}

data class PropertySource(val name: String,
val source: Any)
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ open class ConsulAgentProperties {
var enabled: Boolean = false
var consulHost = "localhost"
var consulPort = 8500
var daemon: Boolean = false
var services: List<ConsulServiceAgentProperties> = ArrayList()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ua.com.lavi.komock.engine.model.config.http
/**
* Created by Oleksandr Loushkin on 30.03.17.
*/

open class CallbackProperties {
var enabled: Boolean = false
var httpMethod: String = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import java.net.URI
/**
* Created by Oleksandr Loushkin on 30.03.17.
*/

open class CallbackRequest(private val methodName: String,
private val uri: String) : HttpEntityEnclosingRequestBase() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ua.com.lavi.komock.engine.model.config.http
/**
* Created by Oleksandr Loushkin on 20.08.17.
*/

open class CaptureProperties {
var enabled: Boolean = false
var bufferSize: Long = 10000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ua.com.lavi.komock.engine.model.Response
/**
* Created by Oleksandr Loushkin on 20.08.17.
*/

data class CapturedData(private val request: Request, private val response: Response) {

val requestBody: String = request.getRequestBody()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ open class HttpServerProperties {
return this
}

fun withRoutes(routes: List<RouteProperties>): HttpServerProperties {
this.routes = routes
return this
}

fun hasRoutes(): Boolean {
if (routes.isEmpty()) {
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ open class SpringConfigProperties {
var sourceFolder: String = "/"
var httpServer: HttpServerProperties = HttpServerProperties()

fun doRefresh(): Boolean {
return refreshPeriod > 0
}

fun fileList() : List<Path> {
return Files.walk(Paths.get(sourceFolder))
.filter { it.toFile().isFile }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ abstract class AbstractMockServer(val serverProps: HttpServerProperties) : MockS
serverConnector.host = serverProps.host
serverConnector.port = serverProps.port
jettyServer.connectors = arrayOf(serverConnector)

//register only enabled routes
serverProps.routes.filter { it.enabled }.forEach { addRoute(it) }
}

override fun start() {
Expand Down Expand Up @@ -91,26 +94,16 @@ abstract class AbstractMockServer(val serverProps: HttpServerProperties) : MockS
}
}

/**
* Add virtual hosts to the running server
*/
override fun addVirtualHosts(virtualHosts: List<String>) {
getContextHandler().addVirtualHosts(virtualHosts.toTypedArray())
log.info("Added virtual hosts: $virtualHosts")
}

/**
* Remove virtual host from the running server
*/
override fun deleteVirtualHosts(virtualHosts: List<String>) {
getContextHandler().removeVirtualHosts(virtualHosts.toTypedArray())
log.info("Removed virtual hosts: $virtualHosts")
}


/**
* Add route by route properties configuration. It will create before, after, callback handlers
*/
override fun addRoute(routeProperties: RouteProperties) {

val beforeRouteHandler = if (routeProperties.logRequest) {
Expand All @@ -133,9 +126,6 @@ abstract class AbstractMockServer(val serverProps: HttpServerProperties) : MockS
addRoute(url, httpMethod, responseHandler, beforeRouteHandler, afterRouteHandler, callbackHandler)
}

/**
* Add route with empty before, after and callback handlers.
*/
override fun addRoute(url: String,
httpMethod: HttpMethod,
responseHandler: ResponseHandler) {
Expand All @@ -148,6 +138,19 @@ abstract class AbstractMockServer(val serverProps: HttpServerProperties) : MockS
EmptyCallbackHandlerImpl())
}

override fun addRoute(url: String,
httpMethod: HttpMethod,
responseHandler: ResponseHandler,
callbackHandler: CallbackHandler) {

addRoute(url,
httpMethod,
responseHandler,
EmptyBeforeResponseHandlerImpl(),
EmptyAfterResponseHandlerImpl(),
callbackHandler)
}

override fun addRoute(url: String,
httpMethod: HttpMethod,
responseHandler: ResponseHandler,
Expand Down
Loading

0 comments on commit cdf20df

Please sign in to comment.