Updated more tests
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user