Update cipher descriptions
This commit is contained in:
@@ -13,6 +13,7 @@ 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;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -27,15 +28,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class AffineCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private AffineCipherController affineCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AffineCipherController")
|
||||
private Logger affineLogger;
|
||||
//Fields
|
||||
private String url = "/affine";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Pbtthlb yz^burzwb";
|
||||
private int key1 = 5;
|
||||
private int key2 = 7;
|
||||
private static final String url = "/affine";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "Pbtthlb yz^burzwb";
|
||||
private static final int key1 = 5;
|
||||
private static final int key2 = 7;
|
||||
private static final String affineName = "affineCipherName";
|
||||
private static final String affineDescription = "affineCipherDescription";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@@ -58,26 +63,29 @@ public class AffineCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
encodedNode.put(CipherParameterUtil.AFFINE_KEY_2, key2);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
|
||||
ReflectionTestUtils.setField(affineCipherController, "affineName", affineName);
|
||||
ReflectionTestUtils.setField(affineCipherController, "affineDescription", affineDescription);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.AFFINE_CIPHER_NAME, CipherInfoUtil.AFFINE_CIPHER_DESCRIPTION);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(affineName, affineDescription);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.AFFINE_CIPHER_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.AFFINE_CIPHER_NAME));
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(affineDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(affineName));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(affineLogger, times(1)).info("Getting info for {}", CipherInfoUtil.AFFINE_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AFFINE_CIPHER_NAME);
|
||||
verify(affineLogger, times(1)).info("Getting info for {}", affineName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
@@ -96,8 +104,8 @@ public class AffineCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(affineLogger, times(1)).info("Encoding {}", CipherInfoUtil.AFFINE_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AFFINE_CIPHER_NAME);
|
||||
verify(affineLogger, times(1)).info("Encoding {}", affineName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
@@ -116,8 +124,8 @@ public class AffineCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(affineLogger, times(1)).info("Encoding {}", CipherInfoUtil.AFFINE_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AFFINE_CIPHER_NAME);
|
||||
verify(affineLogger, times(1)).info("Encoding {}", affineName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
@@ -136,8 +144,8 @@ public class AffineCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(affineLogger, times(1)).info("Decoding {}", CipherInfoUtil.AFFINE_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AFFINE_CIPHER_NAME);
|
||||
verify(affineLogger, times(1)).info("Decoding {}", affineName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
@@ -156,8 +164,8 @@ public class AffineCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(affineLogger, times(1)).info("Decoding {}", CipherInfoUtil.AFFINE_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AFFINE_CIPHER_NAME);
|
||||
verify(affineLogger, times(1)).info("Decoding {}", affineName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -28,11 +30,19 @@ public class AffineCipherControllerTest{
|
||||
private static final int AFFINE_KEY_1 = 5;
|
||||
private static final int AFFINE_KEY_2 = 7;
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String affineName = "affineCipherName";
|
||||
private static final String affineDescription = "affineCipherDescription";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(affineCipherController, "affineName", affineName);
|
||||
ReflectionTestUtils.setField(affineCipherController, "affineDescription", affineDescription);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.AFFINE_CIPHER_NAME, CipherInfoUtil.AFFINE_CIPHER_DESCRIPTION);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(affineName, affineDescription);
|
||||
|
||||
|
||||
ObjectNode returnedJson = affineCipherController.getCipherInfo();
|
||||
|
||||
@@ -13,6 +13,7 @@ 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;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -27,14 +28,18 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class AtbashCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private AtbashCipherController atbashController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AtbashCipherController")
|
||||
protected Logger atbashLogger;
|
||||
//Fields
|
||||
private String url = "/atbash";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Nvhhztv gl^vmxlwv";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/atbash";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "Nvhhztv gl^vmxlwv";
|
||||
private static final String atbashName = "atbashName";
|
||||
private static final String atbashDescription = "atbashDescription";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -52,26 +57,29 @@ public class AtbashCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
|
||||
ReflectionTestUtils.setField(atbashController, "atbashName", atbashName);
|
||||
ReflectionTestUtils.setField(atbashController, "atbashDescription", atbashDescription);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.ATBASH_CIPHER_NAME, CipherInfoUtil.ATBASH_CIPHER_DESCRIPTION);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(atbashName, atbashDescription);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.ATBASH_CIPHER_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.ATBASH_CIPHER_NAME));
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(atbashDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(atbashName));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(atbashLogger, times(1)).info("Getting info for {}", CipherInfoUtil.ATBASH_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ATBASH_CIPHER_NAME);
|
||||
verify(atbashLogger, times(1)).info("Getting info for {}", atbashName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
@@ -90,8 +98,8 @@ public class AtbashCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(atbashLogger, times(1)).info("Encoding {}", CipherInfoUtil.ATBASH_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ATBASH_CIPHER_NAME);
|
||||
verify(atbashLogger, times(1)).info("Encoding {}", atbashName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
@@ -110,8 +118,8 @@ public class AtbashCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(atbashLogger, times(1)).info("Encoding {}", CipherInfoUtil.ATBASH_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ATBASH_CIPHER_NAME);
|
||||
verify(atbashLogger, times(1)).info("Encoding {}", atbashName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
@@ -130,8 +138,8 @@ public class AtbashCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(atbashLogger, times(1)).info("Decoding {}", CipherInfoUtil.ATBASH_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ATBASH_CIPHER_NAME);
|
||||
verify(atbashLogger, times(1)).info("Decoding {}", atbashName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
@@ -150,8 +158,8 @@ public class AtbashCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(atbashLogger, times(1)).info("Decoding {}", CipherInfoUtil.ATBASH_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ATBASH_CIPHER_NAME);
|
||||
verify(atbashLogger, times(1)).info("Decoding {}", atbashName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -22,11 +24,19 @@ public class AtbashCipherControllerTest{
|
||||
private AtbashCipherController atbashCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String ATBASH_INPUT_STRING = "Message to^encode";
|
||||
private static final String ATBASH_OUTPUT_STRING = "Nvhhztv gl^vmxlwv";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String atbashName = "atbashName";
|
||||
private static final String atbashDescription = "atbashDescription";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(atbashCipherController, "atbashName", atbashName);
|
||||
ReflectionTestUtils.setField(atbashCipherController, "atbashDescription", atbashDescription);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAtbash(){
|
||||
ObjectNode cipherParams = generateParams(ATBASH_INPUT_STRING);
|
||||
|
||||
@@ -13,6 +13,7 @@ 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;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -27,15 +28,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class AutokeyCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private AutokeyCipherController autokeyCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AutokeyCipherController")
|
||||
protected Logger autokeyLogger;
|
||||
//Fields
|
||||
private String url = "/autokey";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Wiqooxh fs^wfcuhx";
|
||||
private String keyword = "keyword";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/autokey";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "Wiqooxh fs^wfcuhx";
|
||||
private static final String keyword = "keyword";
|
||||
private static final String autokeyName = "autokeyName";
|
||||
private static final String autokeyDescription = "autokeyDescription";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -55,26 +60,29 @@ public class AutokeyCipherControllerIntegrationTest extends CipherStreamControll
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
|
||||
ReflectionTestUtils.setField(autokeyCipherController, "autokeyName", autokeyName);
|
||||
ReflectionTestUtils.setField(autokeyCipherController, "autokeyDescription", autokeyDescription);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.AUTOKEY_CIPHER_NAME, CipherInfoUtil.AUTOKEY_CIPHER_DESCRIPTION);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(autokeyName, autokeyDescription);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.AUTOKEY_CIPHER_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.AUTOKEY_CIPHER_NAME));
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(autokeyDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(autokeyName));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(autokeyLogger, times(1)).info("Getting info for {}", CipherInfoUtil.AUTOKEY_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AUTOKEY_CIPHER_NAME);
|
||||
verify(autokeyLogger, times(1)).info("Getting info for {}", autokeyName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
@@ -93,8 +101,8 @@ public class AutokeyCipherControllerIntegrationTest extends CipherStreamControll
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(autokeyLogger, times(1)).info("Encoding {}", CipherInfoUtil.AUTOKEY_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AUTOKEY_CIPHER_NAME);
|
||||
verify(autokeyLogger, times(1)).info("Encoding {}", autokeyName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
@@ -113,8 +121,8 @@ public class AutokeyCipherControllerIntegrationTest extends CipherStreamControll
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(autokeyLogger, times(1)).info("Encoding {}", CipherInfoUtil.AUTOKEY_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AUTOKEY_CIPHER_NAME);
|
||||
verify(autokeyLogger, times(1)).info("Encoding {}", autokeyName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
@@ -133,8 +141,8 @@ public class AutokeyCipherControllerIntegrationTest extends CipherStreamControll
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(autokeyLogger, times(1)).info("Decoding {}", CipherInfoUtil.AUTOKEY_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AUTOKEY_CIPHER_NAME);
|
||||
verify(autokeyLogger, times(1)).info("Decoding {}", autokeyName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
@@ -153,8 +161,8 @@ public class AutokeyCipherControllerIntegrationTest extends CipherStreamControll
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(autokeyLogger, times(1)).info("Decoding {}", CipherInfoUtil.AUTOKEY_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AUTOKEY_CIPHER_NAME);
|
||||
verify(autokeyLogger, times(1)).info("Decoding {}", autokeyName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -23,15 +25,23 @@ public class AutokeyCipherControllerTest{
|
||||
private AutokeyCipherController autokeyCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String AUTOKEY_INPUT_STRING = "Message to^encode";
|
||||
private static final String AUTOKEY_OUTPUT_STRING = "Wiqooxh fs^wfcuhx";
|
||||
private static final String AUTOKEY_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String autokeyName = "autokeyName";
|
||||
private static final String autokeyDescription = "autokeyDescription";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(autokeyCipherController, "autokeyName", autokeyName);
|
||||
ReflectionTestUtils.setField(autokeyCipherController, "autokeyDescription", autokeyDescription);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.AUTOKEY_CIPHER_NAME, CipherInfoUtil.AUTOKEY_CIPHER_DESCRIPTION);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(autokeyName, autokeyDescription);
|
||||
|
||||
|
||||
ObjectNode returnedJson = autokeyCipherController.getCipherInfo();
|
||||
|
||||
@@ -13,6 +13,7 @@ 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;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -27,14 +28,18 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class BaconianCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private BaconianCipherController baconianCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BaconianCipherController")
|
||||
protected Logger baconianLogger;
|
||||
//Fields
|
||||
private String url = "/baconian";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
private static final String url = "/baconian";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String baconianName = "baconianName";
|
||||
private static final String baconianDescription = "baconianDescription";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -52,26 +57,29 @@ public class BaconianCipherControllerIntegrationTest extends CipherStreamControl
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString.replaceAll("[^a-zA-Z]", ""));
|
||||
|
||||
ReflectionTestUtils.setField(baconianCipherController, "baconianName", baconianName);
|
||||
ReflectionTestUtils.setField(baconianCipherController, "baconianDescription", baconianDescription);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.BACONIAN_CIPHER_NAME, CipherInfoUtil.BACONIAN_CIPHER_DESCRIPTION);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(baconianName, baconianDescription);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.BACONIAN_CIPHER_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.BACONIAN_CIPHER_NAME));
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(baconianDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(baconianName));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(baconianLogger, times(1)).info("Getting info for {}", CipherInfoUtil.BACONIAN_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BACONIAN_CIPHER_NAME);
|
||||
verify(baconianLogger, times(1)).info("Getting info for {}", baconianName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
@@ -90,8 +98,8 @@ public class BaconianCipherControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(baconianLogger, times(1)).info("Encoding {}", CipherInfoUtil.BACONIAN_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BACONIAN_CIPHER_NAME);
|
||||
verify(baconianLogger, times(1)).info("Encoding {}", baconianName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
@@ -110,8 +118,8 @@ public class BaconianCipherControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(baconianLogger, times(1)).info("Encoding {}", CipherInfoUtil.BACONIAN_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BACONIAN_CIPHER_NAME);
|
||||
verify(baconianLogger, times(1)).info("Encoding {}", baconianName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
@@ -130,8 +138,8 @@ public class BaconianCipherControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(baconianLogger, times(1)).info("Decoding {}", CipherInfoUtil.BACONIAN_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BACONIAN_CIPHER_NAME);
|
||||
verify(baconianLogger, times(1)).info("Decoding {}", baconianName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
@@ -150,8 +158,8 @@ public class BaconianCipherControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(baconianLogger, times(1)).info("Decoding {}", CipherInfoUtil.BACONIAN_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BACONIAN_CIPHER_NAME);
|
||||
verify(baconianLogger, times(1)).info("Decoding {}", baconianName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -27,11 +29,20 @@ public class BaconianCipherControllerTest{
|
||||
private static final String BACONIAN_OUTPUT_STRING = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
private static final String BACONIAN_DECODED_STRING = "Messagetoencode";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String baconianName = "baconianName";
|
||||
private static final String baconianDescription = "baconianDescription";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(baconianCipherController, "baconianName", baconianName);
|
||||
ReflectionTestUtils.setField(baconianCipherController, "baconianDescription", baconianDescription);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.BACONIAN_CIPHER_NAME, CipherInfoUtil.BACONIAN_CIPHER_DESCRIPTION);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(baconianName, baconianDescription);
|
||||
|
||||
|
||||
ObjectNode returnedJson = baconianCipherController.getCipherInfo();
|
||||
|
||||
@@ -13,6 +13,7 @@ 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;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -27,15 +28,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class BaseXCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private BaseXCipherController baseXCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BaseXCipherController")
|
||||
protected Logger baseXLogger;
|
||||
//Fields
|
||||
private String url = "/basex";
|
||||
private String decodedString = "A+B@C d\te\nf";
|
||||
private String encodedString = "1000001 101011 1000010 1000000 1000011 100000 1100100 1001 1100101 1010 1100110";
|
||||
private int base = 2;
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/basex";
|
||||
private static final String decodedString = "A+B@C d\te\nf";
|
||||
private static final String encodedString = "1000001 101011 1000010 1000000 1000011 100000 1100100 1001 1100101 1010 1100110";
|
||||
private static final int base = 2;
|
||||
private static final String baseXName = "baseXName";
|
||||
private static final String baseXDescription = "baseXDescription";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -55,26 +60,29 @@ public class BaseXCipherControllerIntegrationTest extends CipherStreamController
|
||||
encodedNode.put(CipherParameterUtil.BASE_X_BASE, base);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
|
||||
ReflectionTestUtils.setField(baseXCipherController, "baseXName", baseXName);
|
||||
ReflectionTestUtils.setField(baseXCipherController, "baseXDescription", baseXDescription);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.BASE_X_CIPHER_NAME, CipherInfoUtil.BASE_X_CIPHER_DESCRIPTION);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(baseXName, baseXDescription);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.BASE_X_CIPHER_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.BASE_X_CIPHER_NAME));
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(baseXDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(baseXName));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(baseXLogger, times(1)).info("Getting info for {}", CipherInfoUtil.BASE_X_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BASE_X_CIPHER_NAME);
|
||||
verify(baseXLogger, times(1)).info("Getting info for {}", baseXName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
@@ -93,8 +101,8 @@ public class BaseXCipherControllerIntegrationTest extends CipherStreamController
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(baseXLogger, times(1)).info("Encoding {}", CipherInfoUtil.BASE_X_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BASE_X_CIPHER_NAME);
|
||||
verify(baseXLogger, times(1)).info("Encoding {}", baseXName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
@@ -113,8 +121,8 @@ public class BaseXCipherControllerIntegrationTest extends CipherStreamController
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(baseXLogger, times(1)).info("Encoding {}", CipherInfoUtil.BASE_X_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BASE_X_CIPHER_NAME);
|
||||
verify(baseXLogger, times(1)).info("Encoding {}", baseXName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
@@ -133,8 +141,8 @@ public class BaseXCipherControllerIntegrationTest extends CipherStreamController
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(baseXLogger, times(1)).info("Decoding {}", CipherInfoUtil.BASE_X_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BASE_X_CIPHER_NAME);
|
||||
verify(baseXLogger, times(1)).info("Decoding {}", baseXName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
@@ -153,8 +161,8 @@ public class BaseXCipherControllerIntegrationTest extends CipherStreamController
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(baseXLogger, times(1)).info("Decoding {}", CipherInfoUtil.BASE_X_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BASE_X_CIPHER_NAME);
|
||||
verify(baseXLogger, times(1)).info("Decoding {}", baseXName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -23,15 +25,23 @@ public class BaseXCipherControllerTest{
|
||||
private BaseXCipherController baseXCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final int BASE_X_BASE = 2;
|
||||
private static final String BASE_X_INPUT_STRING = "A+B@C d\te\nf";
|
||||
private static final String BASE_X_OUTPUT_STRING = "1000001 101011 1000010 1000000 1000011 100000 1100100 1001 1100101 1010 1100110";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String baseXName = "baseXName";
|
||||
private static final String baseXDescription = "baseXDescription";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(baseXCipherController, "baseXName", baseXName);
|
||||
ReflectionTestUtils.setField(baseXCipherController, "baseXDescription", baseXDescription);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.BASE_X_CIPHER_NAME, CipherInfoUtil.BASE_X_CIPHER_DESCRIPTION);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(baseXName, baseXDescription);
|
||||
|
||||
|
||||
ObjectNode returnedJson = baseXCipherController.getCipherInfo();
|
||||
|
||||
@@ -13,6 +13,7 @@ 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;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -27,15 +28,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class BeaufortCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private BeaufortCipherController beaufortCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BeaufortCipherController")
|
||||
protected Logger beaufortLogger;
|
||||
//Fields
|
||||
private String url = "/beaufort";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Yageolz rq^ujmdag";
|
||||
private String keyword = "Ke*y word";
|
||||
private static final String url = "/beaufort";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "Yageolz rq^ujmdag";
|
||||
private static final String keyword = "Ke*y word";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String beaufortName = "beaufortName";
|
||||
private static final String beaufortDescription = "beaufortDescription";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -55,26 +60,29 @@ public class BeaufortCipherControllerIntegrationTest extends CipherStreamControl
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
|
||||
ReflectionTestUtils.setField(beaufortCipherController, "beaufortName", beaufortName);
|
||||
ReflectionTestUtils.setField(beaufortCipherController, "beaufortDescription", beaufortDescription);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.BEAUFORT_CIPHER_NAME, CipherInfoUtil.BEAUFORT_CIPHER_DESCRIPTION);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(beaufortName, beaufortDescription);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.BEAUFORT_CIPHER_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.BEAUFORT_CIPHER_NAME));
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(beaufortDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(beaufortName));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(beaufortLogger, times(1)).info("Getting info for {}", CipherInfoUtil.BEAUFORT_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BEAUFORT_CIPHER_NAME);
|
||||
verify(beaufortLogger, times(1)).info("Getting info for {}", beaufortName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
@@ -93,8 +101,8 @@ public class BeaufortCipherControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(beaufortLogger, times(1)).info("Encoding {}", CipherInfoUtil.BEAUFORT_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BEAUFORT_CIPHER_NAME);
|
||||
verify(beaufortLogger, times(1)).info("Encoding {}", beaufortName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
@@ -113,8 +121,8 @@ public class BeaufortCipherControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(beaufortLogger, times(1)).info("Encoding {}", CipherInfoUtil.BEAUFORT_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BEAUFORT_CIPHER_NAME);
|
||||
verify(beaufortLogger, times(1)).info("Encoding {}", beaufortName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
@@ -133,8 +141,8 @@ public class BeaufortCipherControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(beaufortLogger, times(1)).info("Decoding {}", CipherInfoUtil.BEAUFORT_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BEAUFORT_CIPHER_NAME);
|
||||
verify(beaufortLogger, times(1)).info("Decoding {}", beaufortName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
@@ -153,8 +161,8 @@ public class BeaufortCipherControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(beaufortLogger, times(1)).info("Decoding {}", CipherInfoUtil.BEAUFORT_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BEAUFORT_CIPHER_NAME);
|
||||
verify(beaufortLogger, times(1)).info("Decoding {}", beaufortName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -27,11 +29,19 @@ public class BeaufortCipherControllerTest{
|
||||
private static final String BEAUFORT_INPUT_STRING = "Message to^encode";
|
||||
private static final String BEAUFORT_OUTPUT_STRING = "Yageolz rq^ujmdag";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String beaufortName = "beaufortName";
|
||||
private static final String beaufortDescription = "beaufortDescription";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(beaufortCipherController, "beaufortName", beaufortName);
|
||||
ReflectionTestUtils.setField(beaufortCipherController, "beaufortDescription", beaufortDescription);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.BEAUFORT_CIPHER_NAME, CipherInfoUtil.BEAUFORT_CIPHER_DESCRIPTION);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(beaufortName, beaufortDescription);
|
||||
|
||||
|
||||
ObjectNode returnedJson = beaufortCipherController.getCipherInfo();
|
||||
|
||||
@@ -13,6 +13,7 @@ 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;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -27,15 +28,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class CaesarCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private CaesarCipherController caesarCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.CaesarCipherController")
|
||||
protected Logger caesarLogger;
|
||||
//Fields
|
||||
private String url = "/caesar";
|
||||
private String decodedString = "The quick brown fox jumps over - the lazy dog";
|
||||
private String encodedString = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
private int shiftAmount = 23;
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/caesar";
|
||||
private static final String decodedString = "The quick brown fox jumps over - the lazy dog";
|
||||
private static final String encodedString = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
private static final int shiftAmount = 23;
|
||||
private static final String caesarName = "caesarName";
|
||||
private static final String caesarDescription = "caesarDescription";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -55,26 +60,29 @@ public class CaesarCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
encodedNode.put(CipherParameterUtil.CAESAR_SHIFT_AMOUNT, shiftAmount);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
|
||||
ReflectionTestUtils.setField(caesarCipherController, "caesarName", caesarName);
|
||||
ReflectionTestUtils.setField(caesarCipherController, "caesarDescription", caesarDescription);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.CAESAR_CIPHER_NAME, CipherInfoUtil.CAESAR_CIPHER_DESCRIPTION);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(caesarName, caesarDescription);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.CAESAR_CIPHER_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.CAESAR_CIPHER_NAME));
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(caesarDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(caesarName));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(caesarLogger, times(1)).info("Getting info for {}", CipherInfoUtil.CAESAR_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.CAESAR_CIPHER_NAME);
|
||||
verify(caesarLogger, times(1)).info("Getting info for {}", caesarName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
@@ -93,8 +101,8 @@ public class CaesarCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(caesarLogger, times(1)).info("Encoding {}", CipherInfoUtil.CAESAR_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.CAESAR_CIPHER_NAME);
|
||||
verify(caesarLogger, times(1)).info("Encoding {}", caesarName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
@@ -113,8 +121,8 @@ public class CaesarCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(caesarLogger, times(1)).info("Encoding {}", CipherInfoUtil.CAESAR_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.CAESAR_CIPHER_NAME);
|
||||
verify(caesarLogger, times(1)).info("Encoding {}", caesarName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
@@ -133,8 +141,8 @@ public class CaesarCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(caesarLogger, times(1)).info("Decoding {}", CipherInfoUtil.CAESAR_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.CAESAR_CIPHER_NAME);
|
||||
verify(caesarLogger, times(1)).info("Decoding {}", caesarName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
@@ -153,8 +161,8 @@ public class CaesarCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(caesarLogger, times(1)).info("Decoding {}", CipherInfoUtil.CAESAR_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.CAESAR_CIPHER_NAME);
|
||||
verify(caesarLogger, times(1)).info("Decoding {}", caesarName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -27,11 +29,19 @@ public class CaesarCipherControllerTest{
|
||||
private static final String CAESAR_OUTPUT_STRING = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
private static final int CAESAR_SHIFT_AMOUNT = 23;
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String caesarName = "caesarName";
|
||||
private static final String caesarDescription = "caesarDescription";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(caesarCipherController, "caesarName", caesarName);
|
||||
ReflectionTestUtils.setField(caesarCipherController, "caesarDescription", caesarDescription);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.CAESAR_CIPHER_NAME, CipherInfoUtil.CAESAR_CIPHER_DESCRIPTION);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(caesarName, caesarDescription);
|
||||
|
||||
|
||||
ObjectNode returnedJson = caesarCipherController.getCipherInfo();
|
||||
|
||||
@@ -13,6 +13,7 @@ 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;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -27,15 +28,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class OneTimePadCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private OneTimePadCipherController oneTimePadCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.OneTimePadCipherController")
|
||||
protected Logger oneTimePadLogger;
|
||||
//Fields
|
||||
private String url = "/oneTimePad";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Wiqooxh mv^egkgws";
|
||||
private String keyword = "keywordThatIsTotallyRandom";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/oneTimePad";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "Wiqooxh mv^egkgws";
|
||||
private static final String keyword = "keywordThatIsTotallyRandom";
|
||||
private static final String oneTimePadName = "oneTimePadName";
|
||||
private static final String oneTimePadDescription = "oneTimePadDescription";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -55,26 +60,29 @@ public class OneTimePadCipherControllerIntegrationTest extends CipherStreamContr
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
|
||||
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadName", oneTimePadName);
|
||||
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadDescription", oneTimePadDescription);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME, CipherInfoUtil.ONE_TIME_PAD_CIPHER_DESCRIPTION);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(oneTimePadName, oneTimePadDescription);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.ONE_TIME_PAD_CIPHER_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME));
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(oneTimePadDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(oneTimePadName));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(oneTimePadLogger, times(1)).info("Getting info for {}", CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME);
|
||||
verify(oneTimePadLogger, times(1)).info("Getting info for {}", oneTimePadName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
@@ -93,8 +101,8 @@ public class OneTimePadCipherControllerIntegrationTest extends CipherStreamContr
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(oneTimePadLogger, times(1)).info("Encoding {}", CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME);
|
||||
verify(oneTimePadLogger, times(1)).info("Encoding {}", oneTimePadName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
@@ -113,8 +121,8 @@ public class OneTimePadCipherControllerIntegrationTest extends CipherStreamContr
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(oneTimePadLogger, times(1)).info("Encoding {}", CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME);
|
||||
verify(oneTimePadLogger, times(1)).info("Encoding {}", oneTimePadName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
@@ -133,8 +141,8 @@ public class OneTimePadCipherControllerIntegrationTest extends CipherStreamContr
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(oneTimePadLogger, times(1)).info("Decoding {}", CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME);
|
||||
verify(oneTimePadLogger, times(1)).info("Decoding {}", oneTimePadName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
@@ -153,8 +161,8 @@ public class OneTimePadCipherControllerIntegrationTest extends CipherStreamContr
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(oneTimePadLogger, times(1)).info("Decoding {}", CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME);
|
||||
verify(oneTimePadLogger, times(1)).info("Decoding {}", oneTimePadName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -23,15 +25,23 @@ public class OneTimePadCipherControllerTest{
|
||||
private OneTimePadCipherController oneTimePadCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String ONE_TIME_PAD_KEYWORD = "keywordThatIsTotallyRandom";
|
||||
private static final String ONE_TIME_PAD_INPUT_STRING = "Message to^encode";
|
||||
private static final String ONE_TIME_PAD_OUTPUT_STRING = "Wiqooxh mv^egkgws";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String oneTimePadName = "oneTimePadName";
|
||||
private static final String oneTimePadDescription = "oneTimePadDescription";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadName", oneTimePadName);
|
||||
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadDescription", oneTimePadDescription);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME, CipherInfoUtil.ONE_TIME_PAD_CIPHER_DESCRIPTION);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(oneTimePadName, oneTimePadDescription);
|
||||
|
||||
|
||||
ObjectNode returnedJson = oneTimePadCipherController.getCipherInfo();
|
||||
|
||||
@@ -14,6 +14,7 @@ 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;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -28,15 +29,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class PortaCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private PortaCipherController portaCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.PortaCipherController")
|
||||
protected Logger portaLogger;
|
||||
//Fields
|
||||
private String url = "/porta";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Rtghuos bm^qcwgrw";
|
||||
private String keyword = "keyword";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/porta";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "Rtghuos bm^qcwgrw";
|
||||
private static final String keyword = "keyword";
|
||||
private static final String portaName = "portaName";
|
||||
private static final String portaDescription = "portaDescription";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -56,26 +61,29 @@ public class PortaCipherControllerIntegrationTest extends CipherStreamController
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
|
||||
ReflectionTestUtils.setField(portaCipherController, "portaName", portaName);
|
||||
ReflectionTestUtils.setField(portaCipherController, "portaDescription", portaDescription);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.PORTA_CIPHER_NAME, CipherInfoUtil.PORTA_CIPHER_DESCRIPTION);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(portaName, portaDescription);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.PORTA_CIPHER_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.PORTA_CIPHER_NAME));
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(portaDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(portaName));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(portaLogger, times(1)).info("Getting info for {}", CipherInfoUtil.PORTA_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PORTA_CIPHER_NAME);
|
||||
verify(portaLogger, times(1)).info("Getting info for {}", portaName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
@@ -98,8 +106,8 @@ public class PortaCipherControllerIntegrationTest extends CipherStreamController
|
||||
verify(mdc, times(1)).put("url", url + "/encode");
|
||||
verify(mdc, times(1)).clear();
|
||||
//Controller
|
||||
verify(portaLogger, times(1)).info("Encoding {}", CipherInfoUtil.PORTA_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PORTA_CIPHER_NAME);
|
||||
verify(portaLogger, times(1)).info("Encoding {}", portaName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
@@ -118,8 +126,8 @@ public class PortaCipherControllerIntegrationTest extends CipherStreamController
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(portaLogger, times(1)).info("Encoding {}", CipherInfoUtil.PORTA_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PORTA_CIPHER_NAME);
|
||||
verify(portaLogger, times(1)).info("Encoding {}", portaName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
@@ -142,8 +150,8 @@ public class PortaCipherControllerIntegrationTest extends CipherStreamController
|
||||
verify(mdc, times(1)).put("url", url + "/decode");
|
||||
verify(mdc, times(1)).clear();
|
||||
//Controller
|
||||
verify(portaLogger, times(1)).info("Decoding {}", CipherInfoUtil.PORTA_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PORTA_CIPHER_NAME);
|
||||
verify(portaLogger, times(1)).info("Decoding {}", portaName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
@@ -162,8 +170,8 @@ public class PortaCipherControllerIntegrationTest extends CipherStreamController
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(portaLogger, times(1)).info("Decoding {}", CipherInfoUtil.PORTA_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PORTA_CIPHER_NAME);
|
||||
verify(portaLogger, times(1)).info("Decoding {}", portaName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -23,15 +25,23 @@ public class PortaCipherControllerTest{
|
||||
private PortaCipherController portaCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String PORTA_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private static final String PORTA_INPUT_STRING = "Message to^encode";
|
||||
private static final String PORTA_OUTPUT_STRING = "Rtghuos bm^qcwgrw";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String portaName = "portaName";
|
||||
private static final String portaDescription = "portaDescription";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(portaCipherController, "portaName", portaName);
|
||||
ReflectionTestUtils.setField(portaCipherController, "portaDescription", portaDescription);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.PORTA_CIPHER_NAME, CipherInfoUtil.PORTA_CIPHER_DESCRIPTION);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(portaName, portaDescription);
|
||||
|
||||
|
||||
ObjectNode returnedJson = portaCipherController.getCipherInfo();
|
||||
|
||||
@@ -13,6 +13,7 @@ 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;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -27,15 +28,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class SubstitutionCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private SubstitutionCipherController substitutionCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.SubstitutionCipherController")
|
||||
protected Logger substitutionLogger;
|
||||
//Fields
|
||||
private String url = "/substitution";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Oguucig vq^gpeqfg";
|
||||
private String keyword = "cdefghijklmnopqrstuvwxyzab";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/substitution";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "Oguucig vq^gpeqfg";
|
||||
private static final String keyword = "cdefghijklmnopqrstuvwxyzab";
|
||||
private static final String substitutionName = "substitutionName";
|
||||
private static final String substitutionDescription = "substitutionDescription";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -55,26 +60,29 @@ public class SubstitutionCipherControllerIntegrationTest extends CipherStreamCon
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
|
||||
ReflectionTestUtils.setField(substitutionCipherController, "substitutionName", substitutionName);
|
||||
ReflectionTestUtils.setField(substitutionCipherController, "substitutionDescription", substitutionDescription);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.SUBSTITUTION_CIPHER_NAME, CipherInfoUtil.SUBSTITUTION_CIPHER_DESCRIPTION);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(substitutionName, substitutionDescription);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.SUBSTITUTION_CIPHER_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.SUBSTITUTION_CIPHER_NAME));
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(substitutionDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(substitutionName));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(substitutionLogger, times(1)).info("Getting info for {}", CipherInfoUtil.SUBSTITUTION_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.SUBSTITUTION_CIPHER_NAME);
|
||||
verify(substitutionLogger, times(1)).info("Getting info for {}", substitutionName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
@@ -93,8 +101,8 @@ public class SubstitutionCipherControllerIntegrationTest extends CipherStreamCon
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(substitutionLogger, times(1)).info("Encoding {}", CipherInfoUtil.SUBSTITUTION_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.SUBSTITUTION_CIPHER_NAME);
|
||||
verify(substitutionLogger, times(1)).info("Encoding {}", substitutionName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
@@ -113,8 +121,8 @@ public class SubstitutionCipherControllerIntegrationTest extends CipherStreamCon
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(substitutionLogger, times(1)).info("Encoding {}", CipherInfoUtil.SUBSTITUTION_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.SUBSTITUTION_CIPHER_NAME);
|
||||
verify(substitutionLogger, times(1)).info("Encoding {}", substitutionName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
@@ -133,8 +141,8 @@ public class SubstitutionCipherControllerIntegrationTest extends CipherStreamCon
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(substitutionLogger, times(1)).info("Decoding {}", CipherInfoUtil.SUBSTITUTION_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.SUBSTITUTION_CIPHER_NAME);
|
||||
verify(substitutionLogger, times(1)).info("Decoding {}", substitutionName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
@@ -153,8 +161,8 @@ public class SubstitutionCipherControllerIntegrationTest extends CipherStreamCon
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(substitutionLogger, times(1)).info("Decoding {}", CipherInfoUtil.SUBSTITUTION_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.SUBSTITUTION_CIPHER_NAME);
|
||||
verify(substitutionLogger, times(1)).info("Decoding {}", substitutionName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -23,15 +25,23 @@ public class SubstitutionCipherControllerTest{
|
||||
private SubstitutionCipherController substitutionCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String SUBSTITUTION_KEYWORD = "cdefghijklmnopqrstuvwxyzab9876543210";
|
||||
private static final String SUBSTITUTION_INPUT_STRING = "Message to&encode 123";
|
||||
private static final String SUBSTITUTION_OUTPUT_STRING = "Oguucig vq&gpeqfg 876";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String substitutionName = "substitutionName";
|
||||
private static final String substitutionDescription = "substitutionDescription";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(substitutionCipherController, "substitutionName", substitutionName);
|
||||
ReflectionTestUtils.setField(substitutionCipherController, "substitutionDescription", substitutionDescription);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.SUBSTITUTION_CIPHER_NAME, CipherInfoUtil.SUBSTITUTION_CIPHER_DESCRIPTION);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(substitutionName, substitutionDescription);
|
||||
|
||||
|
||||
ObjectNode returnedJson = substitutionCipherController.getCipherInfo();
|
||||
|
||||
@@ -13,6 +13,7 @@ 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;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -27,15 +28,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class VigenereCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private VigenereCipherController vigenereCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.VigenereCipherController")
|
||||
protected Logger vigenereLogger;
|
||||
//Fields
|
||||
private String url = "/vigenere";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Wiqooxh ds^cjqfgo";
|
||||
private String keyword = "keyword";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/vigenere";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "Wiqooxh ds^cjqfgo";
|
||||
private static final String keyword = "keyword";
|
||||
private static final String vigenereName = "vigenereName";
|
||||
private static final String vigenereDescription = "vigenereDescription";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -55,26 +60,29 @@ public class VigenereCipherControllerIntegrationTest extends CipherStreamControl
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
|
||||
ReflectionTestUtils.setField(vigenereCipherController, "vigenereName", vigenereName);
|
||||
ReflectionTestUtils.setField(vigenereCipherController, "vigenereDescription", vigenereDescription);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.VIGENERE_CIPHER_NAME, CipherInfoUtil.VIGENERE_CIPHER_DESCRIPTION);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(vigenereName, vigenereDescription);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.VIGENERE_CIPHER_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.VIGENERE_CIPHER_NAME));
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(vigenereDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(vigenereName));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(vigenereLogger, times(1)).info("Getting info for {}", CipherInfoUtil.VIGENERE_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.VIGENERE_CIPHER_NAME);
|
||||
verify(vigenereLogger, times(1)).info("Getting info for {}", vigenereName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
@@ -93,8 +101,8 @@ public class VigenereCipherControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(vigenereLogger, times(1)).info("Encoding {}", CipherInfoUtil.VIGENERE_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.VIGENERE_CIPHER_NAME);
|
||||
verify(vigenereLogger, times(1)).info("Encoding {}", vigenereName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
@@ -113,8 +121,8 @@ public class VigenereCipherControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(vigenereLogger, times(1)).info("Encoding {}", CipherInfoUtil.VIGENERE_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.VIGENERE_CIPHER_NAME);
|
||||
verify(vigenereLogger, times(1)).info("Encoding {}", vigenereName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
@@ -133,8 +141,8 @@ public class VigenereCipherControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(vigenereLogger, times(1)).info("Decoding {}", CipherInfoUtil.VIGENERE_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.VIGENERE_CIPHER_NAME);
|
||||
verify(vigenereLogger, times(1)).info("Decoding {}", vigenereName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
@@ -153,8 +161,8 @@ public class VigenereCipherControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(vigenereLogger, times(1)).info("Decoding {}", CipherInfoUtil.VIGENERE_CIPHER_NAME);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.VIGENERE_CIPHER_NAME);
|
||||
verify(vigenereLogger, times(1)).info("Decoding {}", vigenereName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -23,15 +25,23 @@ public class VigenereCipherControllerTest{
|
||||
private VigenereCipherController vigenereCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String VIGENERE_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private static final String VIGENERE_INPUT_STRING = "Message to^encode";
|
||||
private static final String VIGENERE_OUTPUT_STRING = "Wiqooxh ds^cjqfgo";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String vigenereName = "vigenereName";
|
||||
private static final String vigenereDescription = "vigenereDescription";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(vigenereCipherController, "vigenereName", vigenereName);
|
||||
ReflectionTestUtils.setField(vigenereCipherController, "vigenereDescription", vigenereDescription);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.VIGENERE_CIPHER_NAME, CipherInfoUtil.VIGENERE_CIPHER_DESCRIPTION);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(vigenereName, vigenereDescription);
|
||||
|
||||
|
||||
ObjectNode returnedJson = vigenereCipherController.getCipherInfo();
|
||||
|
||||
Reference in New Issue
Block a user