Updated more tests
This commit is contained in:
@@ -8,6 +8,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -24,12 +26,16 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.combination.AdfgvxCipherController")
|
||||
private Logger adfgvxLogger;
|
||||
//Fields
|
||||
private String url = "/adfgvx";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "AXgvdavfxgagfa afag^aaxdxfgdagda";
|
||||
private String keyword = "keyword";
|
||||
private String squareKeyword = "SquareKeyword";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -60,7 +66,7 @@ public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1"))
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.ADFGVX_CIPHER_NAME))
|
||||
@@ -78,7 +84,7 @@ public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
public void testEncodeAdfgvx() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -93,11 +99,30 @@ public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(adfgvxLogger, times(1)).info("Encoding {}", CipherInfoUtil.ADFGVX_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -111,4 +136,23 @@ public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(adfgvxLogger, times(1)).info("Decoding {}", CipherInfoUtil.ADFGVX_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,13 +21,26 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class AdfgvxCipherControllerTest{
|
||||
@InjectMocks
|
||||
private AdfgvxCipherController adfgvxCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final String KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private static final String SQUARE_KEYWORD = CipherParameterUtil.SQUARE_KEYWORD;
|
||||
private static final String INPUT_STRING = "Message to-encode";
|
||||
private static final String OUTPUT_STRING = "AXgvdavfxgagfa afag-aaxdxfgdagda";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.ADFGVX_CIPHER_NAME, CipherInfoUtil.ADFGVX_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = adfgvxCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx(){
|
||||
ObjectNode cipherParams = generateParams(KEYWORD, SQUARE_KEYWORD, INPUT_STRING);
|
||||
@@ -37,9 +51,10 @@ public class AdfgvxCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodeAdfgvx_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
adfgvxCipherController.encodeAdfgvx(blankNode);
|
||||
});
|
||||
@@ -55,22 +70,26 @@ public class AdfgvxCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_invalidParameters(){
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
adfgvxCipherController.decodeAdfgvx(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String squareKeyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.createObjectNode();
|
||||
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.SQUARE_KEYWORD, squareKeyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -24,12 +26,16 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class AdfgxCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.combination.AdfgxCipherController")
|
||||
private Logger adfgxLogger;
|
||||
//Fields
|
||||
private String url = "/adfgx";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "AAgagadfagaxxd axdx^adafafxddgdf";
|
||||
private String keyword = "keyword";
|
||||
private String squareKeyword = "SquareKeyword";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -60,7 +66,7 @@ public class AdfgxCipherControllerIntegrationTest extends CipherStreamController
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1"))
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.ADFGX_CIPHER_NAME))
|
||||
@@ -78,7 +84,7 @@ public class AdfgxCipherControllerIntegrationTest extends CipherStreamController
|
||||
public void testEncodeAdfgx() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -93,11 +99,30 @@ public class AdfgxCipherControllerIntegrationTest extends CipherStreamController
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(adfgxLogger, times(1)).info("Encoding {}", CipherInfoUtil.ADFGX_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgx() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -111,4 +136,23 @@ public class AdfgxCipherControllerIntegrationTest extends CipherStreamController
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(adfgxLogger, times(1)).info("Decoding {}", CipherInfoUtil.ADFGX_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,11 +21,25 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class AdfgxCipherControllerTest{
|
||||
@InjectMocks
|
||||
private AdfgxCipherController adfgxCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final String ADFGX_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private static final String ADFGX_SQUARE_KEYWORD = CipherParameterUtil.SQUARE_KEYWORD;
|
||||
private static final String ADFGX_INPUT_STRING = "Message to^encode";
|
||||
private static final String ADFGX_OUTPUT_STRING = "AAgagadfagaxxd axdx^adafafxddgdf";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.ADFGX_CIPHER_NAME, CipherInfoUtil.ADFGX_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = adfgxCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgx(){
|
||||
@@ -36,9 +51,10 @@ public class AdfgxCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ADFGX_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodeAdfgx_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
adfgxCipherController.encodeAdfgx(blankNode);
|
||||
});
|
||||
@@ -54,22 +70,25 @@ public class AdfgxCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ADFGX_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodeAdfgx_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
adfgxCipherController.decodeAdfgx(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String squareKeyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.createObjectNode();
|
||||
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.SQUARE_KEYWORD, squareKeyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user