Commit 9e85d20c authored by rjosula's avatar rjosula

Added Junit Tests for producer components

parent 16ee4e93
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.voter.verification</groupId>
<artifactId>VoterProducerApi</artifactId>
......@@ -27,7 +28,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-mongodb</artifactId>
......@@ -45,6 +46,10 @@
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
......
......@@ -4,8 +4,6 @@ import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
......@@ -35,8 +33,8 @@ public class VoterVerificationController {
* to verify whether the employee is eligible for voting or not.
* @return
*/
@RequestMapping(value = "/sendVoterInfo", method = RequestMethod.POST, produces = {"application/xml"})
public ResponseEntity<?> publishVoterInfo(@RequestBody String personString) {
@RequestMapping(value = "/sendVoterInfo", method = RequestMethod.POST)
public String publishVoterInfo(@RequestBody String personString) {
Map<String, Object> headers = new HashMap<>();
headers.put("content-type", "application/json");
......@@ -44,8 +42,6 @@ public class VoterVerificationController {
MessageHeaders header = new MessageHeaders(headers);
Message<String> msg = MessageBuilder.createMessage(personString, header);
voterInputGateway.sendToInputQ(msg);
return new ResponseEntity<String>("Published successfully", HttpStatus.ACCEPTED);
return personString;
}
}
......@@ -4,4 +4,6 @@ spring.activemq.user=admin
spring.activemq.password=admin
spring.data.mongodb.uri=mongodb://voter:admin@localhost:27017/admin
###Adding Logging information
logging.level.root=info
package com.voter.verification;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
@SpringBootTest
class VoterProducerApiApplicationTests {
Logger logger = LogManager.getLogger(VoterProducerApiApplicationTests.class);
@Test
void contextLoads() {
void voterProducer() {
String voterInput = "{\n" +
" \"personId\" : 4,\n" +
" \"personName\":\"RK D\",\n" +
" \"personAge\":35,\n" +
" \"personAddress\":\"DNo 7-6-69/204, Kousalya Colony, Bachupally-500090, Hyderabad\",\n" +
" \"state\":\"Telangana\",\n" +
" \"emailId\":\"raghunathbj13@gmail.com\",\n" +
" \"referenceId\":\"DGN31147076\"\n" +
"}";
RestTemplate restCall = new RestTemplate();
String url = "http://localhost:8080/voter/verificationapp/sendVoterInfo";
String response = restCall.postForObject(url, voterInput, String.class);
if(response != null) {
logger.info("Response achieved is:: " + response);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment