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,12 +21,25 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class RailFenceControllerTest{
|
||||
@InjectMocks
|
||||
private RailFenceController railFenceController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final String RAIL_FENCE_INPUT_STRING = "Message to^encode";
|
||||
private static final String RAIL_FENCE_OUTPUT_STRING = "Moetese ne^sgcdao";
|
||||
private static final int RAIL_FENCE_RAILS = 5;
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.RAIL_FENCE_CIPHER_NAME, CipherInfoUtil.RAIL_FENCE_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = railFenceController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeRailFence(){
|
||||
ObjectNode cipherParams = generateParams(RAIL_FENCE_RAILS, RAIL_FENCE_INPUT_STRING);
|
||||
@@ -36,9 +50,10 @@ public class RailFenceControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(RAIL_FENCE_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify inavlid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodeRailFence_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
railFenceController.encodeRailFence(blankNode);
|
||||
});
|
||||
@@ -54,21 +69,24 @@ public class RailFenceControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(RAIL_FENCE_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify inavlid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodeRailFence_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
railFenceController.encodeRailFence(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(int rails, 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.RAIL_FENCE_RAILS, rails);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user