Mock Servers
A mock server is a standalone application that is spin next to the development system and allows other systems to send the requests to it and responds with the pre-defined set of data. In general words, this is a replacement for the real API that we want to avoid calling. The main use cases are:
...
Receives calls from test code
Replies with fake responses, initialised by test code
Triggered from unit test code
Why use Mock Servers
A mock API server is useful during development and testing when live data is either unavailable or unreliable. While designing an API, you can use mock APIs to work concurrently on the front and back-end, as well as to gather feedback from developers.
...
To test your own API while developing and before making that API live on the server of your organisation.
To get feedback and bugs quicker.
For checking the dependencies in your API before it is available to everyone.
For QA engineers to use this for testing/isolating external dependencies and integration testing.
By front end developers to use it before actual endpoints are available. This is done while designing the UI so that you don’t need to wait for the time till actual endpoints are developed. It saves a lot of time.
For engineers to develop prototype of their idea to present it to the investors for funding.
Test Servers
Test servers are used for integration tests, in which ILS test server(s) receive and send real API calls as if they are real live systems, but without modifying a production ILS ensuring that the connections between systems are working properly.
...
Receives ILS calls from integration test code
Replies with valid responses
Maintains internal database of test data, initialized by the test suite
Basic Setup
Mock servers are located on the client network. For mock servers to work, Gateway and CIRC server should be working. Mock servers are running in the Docker containers.
...
Hence below Mock servers are built:
PUL/CUL SIP2 Mock Server
SIP Server is a TCP/IP-based server that can also act as a messaging interface between SIP Server clients. Once connected the server receives SIP2 request messages from the client and using the instance parameters does the required database lookups, processing etc. and returns the appropriate response message. The parameters define how the data for each field in the response message is derived. When Request is placed to SIP2 server it will convert the request to string and while passing the response it will again convert string to the response
NYPL REST Mock Server
A mock API server imitates a real server by providing realistic responses to requests. Dynamic response can make your mock API more realistic. Responses can be static or dynamic, and simulate the data the real API would return, matching the schema with data types, objects, and arrays. The data can be randomly generated based on the type of field and requirements you determine. For getting the request and sending the response it uses RESTful API Services.
LAS Mock Server
Once a request message is placed to the request queue from SCSB-CIRC, the request message will then be consumed by mock Server. After doing some internal processing, Mock Server will respond by sending a response message to the response queue.Later,SCSB-CIRC will consume the response message.
...
There are multiple implementations of the server depending on the environment. The easiest way to set up the server is however to spin the docker image. Instruction and source files can be found here. In the most basic way, starting the server results in just two shell commands:
SIP2 Mock Server
Build Application
mvn clean install
Building Image
sudo docker build -t phase4-scsb-sip-mock-server .
Running Container
sudo docker run --name phase4-sip2scsb-sip-mock-server --restart always -v /data:/recap-vol vol -p 8012<port>:8012 <port> -e "ENV=-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath= /recap -vol/phase4-scsb-mock-nypl-server/heapdump/ -Dorg.apache.activemq.SERIALIZABLE_PACKAGES="*" -Dspring.config.location=/recap-vol/config/external-sip-application.properties " --network=scsb -d phase4-scsb-sip2sip-mock-server
NYPL Mock Server
sudo external-sip-application properties
#Database information
spring.datasource.url=jdbc:mysql://<mysqlip>:<mysqlport>/<scheme>?autoReconnect=true&serverTimezone=A merica/New_York&useSSL=false
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=XXXX
spring.datasource.password=XXXXX
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
ils.mock.sip.server.url=<ContainerName>
ils.mock.sip.server.port=<port>
Properties to Update -
UPDATE `recap`.`scsb_properties_t` SET `P_VALUE`='<ContainerName>' WHERE `P_KEY`='ils.server' AND `INSTITUTION_CODE`='CUL';
UPDATE `recap`.`scsb_properties_t` SET `P_VALUE`='<port> ' WHERE `P_KEY`='ils.server.port' AND `INSTITUTION_CODE`='CUL';
UPDATE `recap`.`scsb_properties_t` SET `P_VALUE`=XXXXX WHERE `P_KEY`='ils.server.operator.user.id' AND `INSTITUTION_CODE`='CUL';
UPDATE `recap`.`scsb_properties_t` SET `P_VALUE`=XXXXX WHERE `P_KEY`='ils.server.operator.password' AND `INSTITUTION_CODE`='CUL';
UPDATE `recap`.`scsb_properties_t` SET `P_VALUE`=XXXXXX WHERE `P_KEY`='ils.server.operator.location' AND `INSTITUTION_CODE`='CUL';
REST Mock Server
Build Application
mvn clean install -DskipTests=true
Building Image
sudo docker build -t phase4-scsb-rest-mock
...
-server .
Running Container
sudo docker run --name phase4-scsb-rest-mock-
...
server -v /data:/recap-vol -p
...
<port>:
...
<port> -e "
...
sudo docker inspect phase4-scsb-mock-nypl-server | grep IPAddress
LAS Mock Server
ENV= -Dorg.apache.activemq.SERIALIZABLE_PACKAGES="*" -Dspring.config.location=/recap-vol/config/external-rest-application.properties -Dserver.port=<port>" --network=scsb -d phase4-scsb-rest-mock-server
external-rest-application.properties
#Database information spring.datasource.url=jdbc:mysql://<mysqlip>:<mysqlport>/<scheme>?autoReconnect=true&serverTimezone= America/New_York&useSSL=false
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=XXXXX
spring.datasource.password=XXXX
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
Properties to Update
UPDATE `recap`.`scsb_properties_t` SET `P_VALUE`='http://<ContainerName>:<port>/rest' WHERE `P_KEY`='ils.rest.data.api' AND `INSTITUTION_CODE`='NYPL';
NCIP Mock Server
Build Application
./gradlew clean build
Building Image
sudo docker build -t phase4-scsb-ncip-mock-server .
Running Container -
sudo docker run --name phase4-scsb-ncip-mock-server -p <port>:<port> --network=scsb -d phase4-scsb-ncip-mock-server
Properties to Update -
UPDATE `recap`.`scsb_properties_t` SET `P_VALUE`='http://<ContainerName>:<port>/ncip' WHERE `P_KEY`='ils.server' AND `INSTITUTION_CODE`='PUL';
UPDATE `recap`.`scsb_properties_t` SET `P_VALUE`='http://<ContainerName>:<port>/ncip' WHERE `P_KEY`='ils.server' AND `INSTITUTION_CODE`='HL';
LAS Mock Server
Build Application
./gradlew clean build -x test
Building Image
sudo docker build -t phase4-scsb-las-mock-las-server .
docker images | grep none | awk '{ print $3; }' | xargs docker rmiserver .
Running Container
sudo docker run --name phase4-scsb-las-mock-las-server --restart always -v /data:/recap-vol vol -p 9103 <port>:9103 <port> -e "ENV=-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath= /recap -vol/phase4-scsb-mock-las-server/heapdump/ -Dorg.apache.activemq.SERIALIZABLE_PACKAGES="*" -Dspring.config.location=/recap-vol/config/external-las-application.properties " --network=scsb -d phase4-scsb-las-mock-server
external-las-application.properties
#Database information
spring.datasource.url=jdbc:mysql://<mysqlip>:<mysqlport>/<scheme>?autoReconnect=true&serverTimezon e=America/New_York&useSSL=false spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=XXXX
spring.datasource.password=XXXX
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
#ActiveMQ
activemq.broker.url=tcp://localhost:61613
activemq.jmx.service.url=service:jmx:rmi:///jndi/rmi://127.0.0.1:1099/jmxrmi activemq.web.console.url=http://localhost:8161
activemq.credentials=admin:admin
activemq.jolokia.api.url=/api/jolokia/read/org.apache.activemq:type=Broker,brokerName=localh ost,destinationType=Queue,destinationName= activemq.jolokia.api.queue.size.attribute=/QueueSize
Properties to Update
UPDATE `recap`.`scsb_properties_t` SET `P_VALUE`='http://<ContainerName>:<port>/lasapi/rest/lasapiSvc/lasStatus' WHERE `P_KEY`='ims.server.status.endpoint';
UPDATE `recap`.`scsb_properties_t` SET `P_VALUE`='http://<ContainerName>:<port>/lasapi/rest/lasapiSvc/itemStatus' WHERE `P_KEY`='ims.item.status.endpoint';
UPDATE `recap`.`scsb_properties_t` SET `P_VALUE`='http://<ContainerName>:<port>/lasapi/rest/lasapiSvc/retrieveItem' WHERE `P_KEY`='ims.item.retrieval.order.endpoint';
UPDATE `recap`.`scsb_properties_t` SET `P_VALUE`='http://<ContainerName>:<port>/lasapi/rest/lasapiSvc/retrieveEDD' WHERE `P_KEY`='ims.item.edd.order.endpoint';
UPDATE `recap`.`scsb_properties_t` SET `P_VALUE`='http://<ContainerName>:<port>/lasapi/rest/lasapiSvc/permanentlyRetriev eItem' WHERE `P_KEY`='ims.item.permanent.withdrawal.direct.endpoint';
UPDATE `recap`.`scsb_properties_t` SET `P_VALUE`='http://<ContainerName>:<port>/lasapi/rest/lasapiSvc/permanentlyRetriev eItemIndirect' WHERE `P_KEY`='ims.item.permanent.withdrawal.indirect.endpoint';
Example -
Request For Request Item
...