Updated more tests

This commit is contained in:
Matthew Ellison
2024-04-08 16:44:38 -04:00
parent 1a93a30b42
commit ff11cd72c3
52 changed files with 1813 additions and 294 deletions

View File

@@ -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;
}
}