Commit 12c3e860 authored by rjosula's avatar rjosula

Updated the test file with runtime input file as input to producer

application
parent 9e85d20c
......@@ -3,6 +3,8 @@ package com.voter.verification.controller;
import java.util.HashMap;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
......@@ -28,6 +30,8 @@ public class VoterVerificationController {
@Autowired
private VoterInformationGateway voterInputGateway;
Logger logger = LogManager.getLogger(VoterVerificationController.class);
/**
* Controller method recieves employee information json string which will be processed
* to verify whether the employee is eligible for voting or not.
......@@ -35,12 +39,12 @@ public class VoterVerificationController {
*/
@RequestMapping(value = "/sendVoterInfo", method = RequestMethod.POST)
public String publishVoterInfo(@RequestBody String personString) {
logger.info("Inside controller publishing the person string :: "+personString);
Map<String, Object> headers = new HashMap<>();
headers.put("content-type", "application/json");
MessageHeaders header = new MessageHeaders(headers);
Message<String> msg = MessageBuilder.createMessage(personString, header);
logger.debug("Sending the message to the Gateway");
voterInputGateway.sendToInputQ(msg);
return personString;
}
......
......@@ -6,4 +6,5 @@ spring.data.mongodb.uri=mongodb://voter:admin@localhost:27017/admin
###Adding Logging information
logging.level.root=info
voter.producer.url = http://localhost:8080/voter/verificationapp/sendVoterInfo
voterInputFilePath = voterproducer.json
{
"personId" : 4,
"personName":"RK D",
"personAge":35,
"personAddress":"DNo 7-6-69/204, Kousalya Colony, Bachupally-500090, Hyderabad",
"state":"Telangana",
"emailId":"raghunathbj13@gmail.com",
"referenceId":"DGN31147076"
}
\ No newline at end of file
package com.voter.verification;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.ResponseEntity;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.client.RestTemplate;
/**
* Voter producer application tests to test the voter information
* and to produce to a consumer.
* @author rjosula
*
*/
@SpringBootTest
class VoterProducerApiApplicationTests {
Logger logger = LogManager.getLogger(VoterProducerApiApplicationTests.class);
@Value("${voterInputFilePath}")
String voterJsonFile;
/**
* Test for producing a voter string through a producer.
* @throws IOException
*/
@Test
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" +
"}";
void voterProducer(){
logger.info("voterJsonFile "+ voterJsonFile);
String voterInput = "";
try {
File resource = new ClassPathResource(voterJsonFile).getFile();
voterInput = new String(Files.readAllBytes(resource.toPath()));
} catch(Exception ex) {
}
if(voterInput.isEmpty()) {
logger.throwing(new Exception("File Doesn't exists and test is failure."));
}
RestTemplate restCall = new RestTemplate();
String url = "http://localhost:8080/voter/verificationapp/sendVoterInfo";
......
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