diff --git a/README.md b/README.md
index 927a16e..f58378f 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,3 @@
# Cipher Stream API
+
+[](https://sonarqube.mattrixwv.com/dashboard?id=CipherStreamAPI)
diff --git a/TODO.txt b/TODO.txt
deleted file mode 100644
index 0da5b74..0000000
--- a/TODO.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-Fix logger testing
-Update to no-op logger for tests
diff --git a/pom.xml b/pom.xml
index b01a4ed..24f54b7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -168,6 +168,11 @@
+
+ org.apache.maven.plugins
+ maven-failsafe-plugin
+
+
org.owasp
@@ -270,6 +275,7 @@
**/*IntegrationTest.java
+ @{argLine} -Xshare:off -javaagent:${org.mockito:mockito-core:jar}
@@ -334,7 +340,7 @@
html
nvd
- 7
+
ossindex
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 60f2a59..a1fc7f2 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1,5 +1,5 @@
#Server options
-server.error.include-stacktrace=always
+spring.web.error.include-stacktrace=always
server.port=8001
server.shutdown=graceful
spring.lifecycle.timeoutPerShutdownPhase=10s
diff --git a/src/test/java/com/mattrixwv/cipherstream/config/FullFilterIntegrationTest.java b/src/test/java/com/mattrixwv/cipherstream/config/FullFilterIntegrationTest.java
index 710fc8d..7ffa5a7 100644
--- a/src/test/java/com/mattrixwv/cipherstream/config/FullFilterIntegrationTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/config/FullFilterIntegrationTest.java
@@ -1,6 +1,8 @@
package com.mattrixwv.cipherstream.config;
+import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@@ -11,6 +13,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
+import org.springframework.test.context.bean.override.mockito.MockitoSpyBean;
import org.springframework.test.web.servlet.MockMvc;
import com.mattrixwv.cipherstream.controller.monosubstitution.CaesarCipherController;
@@ -22,14 +25,10 @@ public class FullFilterIntegrationTest{
//HTTP
@Autowired
private MockMvc mockMvc;
- //Logging
- //TODO: Fix logger testing
- //@Mock(name = "com.mattrixwv.cipherstream.config.FullFilter")
- //private Logger logger;
- //@Mock
- //private MDCAdapter mdc;
+ @MockitoSpyBean
+ private FullFilter fullFilter;
//Fields
- private static final String url = "/caesar";
+ private static final String URL = "/caesar";
private UUID requestId = UUID.randomUUID();
private String ipAddresses = "192.168.1.1,192.168.1.2,192.168.1.3";
@Value("${cipher.mono.caesar.name}")
@@ -38,7 +37,7 @@ public class FullFilterIntegrationTest{
@Test
public void testDoFilterInternal() throws Exception{
- mockMvc.perform(get(url)
+ mockMvc.perform(get(URL)
.header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddresses)
.param("param1", "value1")
@@ -47,42 +46,22 @@ public class FullFilterIntegrationTest{
.param("_", "value3"))
.andExpect(status().isOk());
- //TODO: Fix logger testing
- /*
- verify(logger, times(1)).info(eq("Request parameters: {}"), any(StringJoiner.class));
- verifyNoMoreInteractions(logger);
- verify(mdc, times(1)).put("requestId", requestId.toString());
- verify(mdc, times(1)).put("ip", "192.168.1.1");
- verify(mdc, times(1)).put("url", url);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
- verify(mdc, times(1)).clear();
- verifyNoMoreInteractions(mdc);
- */
+ verify(fullFilter, times(1)).doFilterInternal(any(), any(), any());
}
@Test
public void testDoFilterInternal_noParameters() throws Exception{
- mockMvc.perform(get(url)
+ mockMvc.perform(get(URL)
.header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddresses))
.andExpect(status().isOk());
- //TODO: Fix logger testing
- /*
- verify(logger, never()).info(anyString(), any(Object.class));
- verifyNoMoreInteractions(logger);
- verify(mdc, times(1)).put("requestId", requestId.toString());
- verify(mdc, times(1)).put("ip", "192.168.1.1");
- verify(mdc, times(1)).put("url", url);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
- verify(mdc, times(1)).clear();
- verifyNoMoreInteractions(mdc);
- */
+ verify(fullFilter, times(1)).doFilterInternal(any(), any(), any());
}
@Test
public void testDoFilterInternal_options() throws Exception{
- mockMvc.perform(options(url)
+ mockMvc.perform(options(URL)
.header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddresses)
.param("param1", "value1")
@@ -91,11 +70,6 @@ public class FullFilterIntegrationTest{
.param("_", "value3"))
.andExpect(status().isOk());
- //TODO: Fix logger testing
- /*
- verifyNoInteractions(logger);
- verify(mdc, times(1)).clear();
- verifyNoMoreInteractions(mdc);
- */
+ verify(fullFilter, times(1)).doFilterInternal(any(), any(), any());
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/CipherStreamControllerIntegrationTestBase.java b/src/test/java/com/mattrixwv/cipherstream/controller/CipherStreamControllerIntegrationTestBase.java
index 5f8615c..ee33698 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/CipherStreamControllerIntegrationTestBase.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/CipherStreamControllerIntegrationTestBase.java
@@ -1,15 +1,23 @@
package com.mattrixwv.cipherstream.controller;
+import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.Mockito.*;
+
+import java.io.IOException;
import java.util.UUID;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration;
import org.springframework.context.annotation.Import;
+import org.springframework.test.context.bean.override.mockito.MockitoSpyBean;
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
import com.mattrixwv.cipherstream.config.FullFilter;
+import jakarta.servlet.ServletException;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.node.ObjectNode;
@@ -17,58 +25,28 @@ import tools.jackson.databind.node.ObjectNode;
@Tag("integration-test")
@Import({AopAutoConfiguration.class, FullFilter.class, CipherStreamLoggingAspect.class})
public class CipherStreamControllerIntegrationTestBase{
- protected static final ObjectMapper mapper = new ObjectMapper();
+ //Filter
+ @MockitoSpyBean
+ private FullFilter fullFilter;
//Objects
protected ObjectNode decodedNode;
protected ObjectNode encodedNode;
//Fields
- protected static final String requestId = UUID.randomUUID().toString();
- protected static final String ipAddress = "192.168.1.1";
-
- //TODO: Fix Aspect testing
- //TODO: Fix logger testing
- //MDC
- //@Mock
- //protected MDCAdapter mdc;
-
- //Base
- //@Mock(name = "com.mattrixwv.cipherstream.controller.CipherStreamController")
- //protected Logger baseLogger;
+ protected ObjectMapper mapper;
+ protected ObjectNode blankNode;
+ protected static final String REQUEST_ID = UUID.randomUUID().toString();
+ protected static final String IP_ADDRESS = "192.168.1.1";
- //Misc
- //@Mock(name = "com.mattrixwv.cipherstream.config.FullFilter")
- //protected Logger filterLogger;
- //@Mock(name = "com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect")
- //protected Logger aspectLogger;
-
-
- /*
- protected void verifyFilter(String url){
- verify(filterLogger, never()).info(eq("Request parameters: {}"), any(StringBuilder.class));
- verify(mdc, times(1)).put(eq("requestId"), any());
- verify(mdc, times(1)).put("ip", ipAddress);
- verify(mdc, times(1)).put("url", url);
- verify(mdc, times(1)).clear();
+ @BeforeEach
+ public void setupJson(){
+ mapper = new ObjectMapper();
+ blankNode = mapper.createObjectNode();
}
- */
- /*
- protected void verifyAspectLogging(ObjectNode jsonNode){
- //Verify the MDC
- jsonNode.properties().forEach(entry -> {
- if(entry.getValue().isString()){
- verify(mdc, times(1)).put(entry.getKey(), entry.getValue().asString());
- }
- else{
- verify(mdc, times(1)).put(entry.getKey(), entry.getValue().toString());
- }
- });
- verifyNoMoreInteractions(mdc);
- //Verify the logger
- verify(aspectLogger, times(1)).info("CipherStream log");
- verifyNoMoreInteractions(aspectLogger);
+ @AfterEach
+ public void checkFilter() throws ServletException, IOException{
+ verify(fullFilter, times(1)).doFilter(any(), any(), any());
}
- */
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/ExceptionRestControllerTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/ExceptionRestControllerTest.java
index 095f8d3..6e23d09 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/ExceptionRestControllerTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/ExceptionRestControllerTest.java
@@ -23,15 +23,15 @@ public class ExceptionRestControllerTest{
@InjectMocks
private ExceptionRestController controller;
//Fields
- private static final String errorMessage = "Error message";
+ private static final String ERROR_MESSAGE = "Error message";
@Test
public void testInvalidCipherParameterHandler(){
//Setup variables
- InvalidCipherParameterException error = new InvalidCipherParameterException(errorMessage);
+ InvalidCipherParameterException error = new InvalidCipherParameterException(ERROR_MESSAGE);
ObjectNode expectedJson = mapper.createObjectNode();
- expectedJson.put("message", errorMessage);
+ expectedJson.put("message", ERROR_MESSAGE);
//Run the function
@@ -46,9 +46,9 @@ public class ExceptionRestControllerTest{
@Test
public void testGenericExceptionHandler(){
//Setup variables
- Exception error = new Exception(errorMessage);
+ Exception error = new Exception(ERROR_MESSAGE);
ObjectNode expectedJson = mapper.createObjectNode();
- expectedJson.put("message", errorMessage);
+ expectedJson.put("message", ERROR_MESSAGE);
//Run the function
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/HealthCheckControllerIntegrationTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/HealthCheckControllerIntegrationTest.java
index 8449f6d..c8d8995 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/HealthCheckControllerIntegrationTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/HealthCheckControllerIntegrationTest.java
@@ -1,22 +1,31 @@
package com.mattrixwv.cipherstream.controller;
+import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
+import java.io.IOException;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
-import org.mockito.Mock;
-import org.slf4j.spi.MDCAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration;
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
import org.springframework.context.annotation.Import;
+import org.springframework.test.context.bean.override.mockito.MockitoSpyBean;
import org.springframework.test.web.servlet.MockMvc;
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
import com.mattrixwv.cipherstream.config.FullFilter;
+import jakarta.servlet.ServletException;
+import tools.jackson.databind.ObjectMapper;
+import tools.jackson.databind.node.ObjectNode;
+
@Tag("integration-test")
@WebMvcTest(controllers = HealthCheckController.class)
@@ -24,34 +33,29 @@ import com.mattrixwv.cipherstream.config.FullFilter;
public class HealthCheckControllerIntegrationTest{
@Autowired
private MockMvc mockMvc;
- //MDC
- @Mock
- private MDCAdapter mdc;
- //Logging
- //TODO: Fix logger testing
- /*
- @Mock(name = "com.mattrixwv.cipherstream.controller.HealthCheckController")
- private Logger healthLogger;
- @Mock(name = "com.mattrixwv.cipherstream.config.FullFilter")
- private Logger filterLogger;
- @Mock(name = "com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect")
- protected Logger aspectLogger;
- */
+ @MockitoSpyBean
+ private FullFilter fullFilter;
+ //Fields
+ protected ObjectMapper mapper;
+ protected ObjectNode blankNode;
+
+
+ @BeforeEach
+ public void setupJson(){
+ mapper = new ObjectMapper();
+ blankNode = mapper.createObjectNode();
+ }
+
+
+ @AfterEach
+ public void checkFilter() throws ServletException, IOException{
+ verify(fullFilter, times(1)).doFilter(any(), any(), any());
+ }
@Test
public void testHealthCheck() throws Exception{
mockMvc.perform(options("/health"))
.andExpect(status().isOk());
-
- //Verify results
- //TODO: Fix logger testing
- /*
- verify(healthLogger, times(1)).debug("Health check");
- verifyNoInteractions(filterLogger);
- verifyNoInteractions(aspectLogger);
- verify(mdc, times(1)).clear();
- verifyNoMoreInteractions(mdc);
- */
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/combination/AdfgvxCipherControllerIntegrationTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/combination/AdfgvxCipherControllerIntegrationTest.java
index 20a2e45..074e30d 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/combination/AdfgvxCipherControllerIntegrationTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/combination/AdfgvxCipherControllerIntegrationTest.java
@@ -20,8 +20,6 @@ import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTe
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
-import tools.jackson.databind.node.ObjectNode;
-
@Tag("integration-test")
@WebMvcTest(controllers = AdfgvxCipherController.class)
@@ -30,21 +28,16 @@ public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControlle
private MockMvc mockMvc;
@Autowired
private AdfgvxCipherController adfgvxCipherController;
- //Loggers
- //TODO: Fix logger testing
- //@Mock(name = "com.mattrixwv.cipherstream.controller.combination.AdfgvxCipherController")
- //private Logger adfgvxLogger;
//Fields
- private static final ObjectNode blankNode = mapper.createObjectNode();
- private static final String url = "/adfgvx";
- private static final String decodedString = "Message to^encode";
- private static final String encodedString = "AXgvdavfxgagfa afag^aaxdxfgdagda";
- private static final String keyword = "keyword";
- private static final String squareKeyword = "SquareKeyword";
- private static final String adfgvxName = "adfgvxName";
- private static final String adfgvxDescription = "adfgvxDescription";
- private static final List adfgvxExplanation = List.of("adfgvxExplanation1", "adfgvxExplanation2", "adfgvxExplanation3");
- private static final List adfgvxFacts = List.of("adfgvxFact1", "adfgvxFact2", "adfgvxFact3");
+ private static final String URL = "/adfgvx";
+ private static final String DECODED_STRING = "Message to^encode";
+ private static final String ENCODED_STRING = "AXgvdavfxgagfa afag^aaxdxfgdagda";
+ private static final String KEYWORD = "keyword";
+ private static final String SQUARE_KEYWORD = "SquareKeyword";
+ private static final String ADFGVX_NAME = "adfgvxName";
+ private static final String ADFGVX_DESCRIPTION = "adfgvxDescription";
+ private static final List ADFGVX_EXPLANATION = List.of("adfgvxExplanation1", "adfgvxExplanation2", "adfgvxExplanation3");
+ private static final List ADFGVX_FACTS = List.of("adfgvxFact1", "adfgvxFact2", "adfgvxFact3");
@BeforeEach
@@ -53,147 +46,89 @@ public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControlle
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- decodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, squareKeyword);
- decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
- decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
+ decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ decodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, SQUARE_KEYWORD);
+ decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
+ decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
encodedNode = mapper.createObjectNode();
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- encodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, squareKeyword);
- encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
- encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
+ encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ encodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, SQUARE_KEYWORD);
+ encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
+ encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
- ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxName", adfgvxName);
- ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxDescription", adfgvxDescription);
- ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxExplanation", adfgvxExplanation);
- ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxFacts", adfgvxFacts);
+ ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxName", ADFGVX_NAME);
+ ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxDescription", ADFGVX_DESCRIPTION);
+ ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxExplanation", ADFGVX_EXPLANATION);
+ ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxFacts", ADFGVX_FACTS);
}
@Test
public void testGetCipherInfo() throws Exception{
- mockMvc.perform(get(url)
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress))
+ mockMvc.perform(get(URL)
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(adfgvxName))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(adfgvxDescription))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(ADFGVX_NAME))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(ADFGVX_DESCRIPTION))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(adfgvxExplanation.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(adfgvxExplanation.get(0), adfgvxExplanation.get(1), adfgvxExplanation.get(2))))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(ADFGVX_EXPLANATION.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(ADFGVX_EXPLANATION.get(0), ADFGVX_EXPLANATION.get(1), ADFGVX_EXPLANATION.get(2))))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(adfgvxFacts.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(adfgvxFacts.get(0), adfgvxFacts.get(1), adfgvxFacts.get(2))));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url);
- //Controller
- verify(adfgvxLogger, times(1)).info("Getting info for {}", adfgvxName);
- verifyNoMoreInteractions(adfgvxLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgvxName);
- */
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(ADFGVX_FACTS.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(ADFGVX_FACTS.get(0), ADFGVX_FACTS.get(1), ADFGVX_FACTS.get(2))));
}
@Test
public void testEncodeAdfgvx() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(decodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(adfgvxLogger, times(1)).info("Encoding {}", adfgvxName);
- verifyNoMoreInteractions(adfgvxLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgvxName);
- //Cipher Aspect
- verifyAspectLogging(decodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
}
@Test
public void testEncodeAdfgvx_error() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(adfgvxLogger, times(1)).info("Encoding {}", adfgvxName);
- verifyNoMoreInteractions(adfgvxLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgvxName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
@Test
public void testDecodeAdfgvx() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(encodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(adfgvxLogger, times(1)).info("Decoding {}", adfgvxName);
- verifyNoMoreInteractions(adfgvxLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgvxName);
- //Cipher Aspect
- verifyAspectLogging(encodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
}
@Test
public void testDecodeAdfgvx_error() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(adfgvxLogger, times(1)).info("Decoding {}", adfgvxName);
- verifyNoMoreInteractions(adfgvxLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgvxName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/combination/AdfgvxCipherControllerTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/combination/AdfgvxCipherControllerTest.java
index dac04ac..31d8b9e 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/combination/AdfgvxCipherControllerTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/combination/AdfgvxCipherControllerTest.java
@@ -33,23 +33,23 @@ public class AdfgvxCipherControllerTest{
private static final String SQUARE_KEYWORD = CipherParameterUtil.SQUARE_KEYWORD;
private static final String INPUT_STRING = "Message to-encode";
private static final String OUTPUT_STRING = "AXgvdavfxgagfa afag-aaxdxfgdagda";
- private static final String adfgvxName = "adfgvxName";
- private static final String adfgvxDescription = "adfgvxDescription";
- private static final List adfgvxExplanation = List.of("adfgvxExplanation1", "adfgvxExplanation2", "adfgvxExplanation3");
- private static final List adfgvxFacts = List.of("adfgvxFact1", "adfgvxFact2", "adfgvxFact3");
+ private static final String ADFGVX_NAME = "adfgvxName";
+ private static final String ADFGVX_DESCRIPTION = "adfgvxDescription";
+ private static final List ADFGVX_EXPLANATION = List.of("adfgvxExplanation1", "adfgvxExplanation2", "adfgvxExplanation3");
+ private static final List ADFGVX_FACTS = List.of("adfgvxFact1", "adfgvxFact2", "adfgvxFact3");
@BeforeEach
public void setup(){
- ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxName", adfgvxName);
- ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxDescription", adfgvxDescription);
- ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxExplanation", adfgvxExplanation);
- ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxFacts", adfgvxFacts);
+ ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxName", ADFGVX_NAME);
+ ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxDescription", ADFGVX_DESCRIPTION);
+ ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxExplanation", ADFGVX_EXPLANATION);
+ ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxFacts", ADFGVX_FACTS);
}
@Test
public void tetGetCipherInfo(){
- ObjectNode infoNode = CipherInfoUtil.buildInfoNode(adfgvxName, adfgvxDescription, adfgvxExplanation, adfgvxFacts);
+ ObjectNode infoNode = CipherInfoUtil.buildInfoNode(ADFGVX_NAME, ADFGVX_DESCRIPTION, ADFGVX_EXPLANATION, ADFGVX_FACTS);
ObjectNode returnedJson = adfgvxCipherController.getCipherInfo();
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/combination/AdfgxCipherControllerIntegrationTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/combination/AdfgxCipherControllerIntegrationTest.java
index f5a56d4..9beb5ad 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/combination/AdfgxCipherControllerIntegrationTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/combination/AdfgxCipherControllerIntegrationTest.java
@@ -20,8 +20,6 @@ import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTe
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
-import tools.jackson.databind.node.ObjectNode;
-
@Tag("integration-test")
@WebMvcTest(controllers = AdfgxCipherController.class)
@@ -30,21 +28,16 @@ public class AdfgxCipherControllerIntegrationTest extends CipherStreamController
private MockMvc mockMvc;
@Autowired
private AdfgxCipherController adfgxCipherController;
- //Loggers
- //TODO: Fix logger testing
- //@Mock(name = "com.mattrixwv.cipherstream.controller.combination.AdfgxCipherController")
- //private Logger adfgxLogger;
//Fields
- private static final ObjectNode blankNode = mapper.createObjectNode();
- private static final String url = "/adfgx";
- private static final String decodedString = "Message to^encode";
- private static final String encodedString = "AAgagadfagaxxd axdx^adafafxddgdf";
- private static final String keyword = "keyword";
- private static final String squareKeyword = "SquareKeyword";
- private static final String adfgxName = "adfgxName";
- private static final String adfgxDescription = "adfgxDescription";
- private static final List adfgxExplanation = List.of("adfgxExplanation1", "adfgxExplanation2", "adfgxExplanation3");
- private static final List adfgxFacts = List.of("adfgxFact1", "adfgxFact2", "adfgxFact3");
+ private static final String URL = "/adfgx";
+ private static final String DECODED_STRING = "Message to^encode";
+ private static final String ENCODED_STRING = "AAgagadfagaxxd axdx^adafafxddgdf";
+ private static final String KEYWORD = "keyword";
+ private static final String SQUARE_KEYWORD = "SquareKeyword";
+ private static final String ADFGX_NAME = "adfgxName";
+ private static final String ADFGX_DESCRIPTION = "adfgxDescription";
+ private static final List ADFGX_EXPLANATION = List.of("adfgxExplanation1", "adfgxExplanation2", "adfgxExplanation3");
+ private static final List ADFGX_FACTS = List.of("adfgxFact1", "adfgxFact2", "adfgxFact3");
@BeforeEach
@@ -53,147 +46,89 @@ public class AdfgxCipherControllerIntegrationTest extends CipherStreamController
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- decodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, squareKeyword);
- decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
- decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
+ decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ decodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, SQUARE_KEYWORD);
+ decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
+ decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
encodedNode = mapper.createObjectNode();
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- encodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, squareKeyword);
- encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
- encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
+ encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ encodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, SQUARE_KEYWORD);
+ encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
+ encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
- ReflectionTestUtils.setField(adfgxCipherController, "adfgxName", adfgxName);
- ReflectionTestUtils.setField(adfgxCipherController, "adfgxDescription", adfgxDescription);
- ReflectionTestUtils.setField(adfgxCipherController, "adfgxExplanation", adfgxExplanation);
- ReflectionTestUtils.setField(adfgxCipherController, "adfgxFacts", adfgxFacts);
+ ReflectionTestUtils.setField(adfgxCipherController, "adfgxName", ADFGX_NAME);
+ ReflectionTestUtils.setField(adfgxCipherController, "adfgxDescription", ADFGX_DESCRIPTION);
+ ReflectionTestUtils.setField(adfgxCipherController, "adfgxExplanation", ADFGX_EXPLANATION);
+ ReflectionTestUtils.setField(adfgxCipherController, "adfgxFacts", ADFGX_FACTS);
}
@Test
public void testGetCipherInfo() throws Exception{
- mockMvc.perform(get(url)
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress))
+ mockMvc.perform(get(URL)
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(adfgxName))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(adfgxDescription))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(ADFGX_NAME))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(ADFGX_DESCRIPTION))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(adfgxExplanation.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(adfgxExplanation.get(0), adfgxExplanation.get(1), adfgxExplanation.get(2))))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(ADFGX_EXPLANATION.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(ADFGX_EXPLANATION.get(0), ADFGX_EXPLANATION.get(1), ADFGX_EXPLANATION.get(2))))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(adfgxFacts.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(adfgxFacts.get(0), adfgxFacts.get(1), adfgxFacts.get(2))));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url);
- //Controller
- verify(adfgxLogger, times(1)).info("Getting info for {}", adfgxName);
- verifyNoMoreInteractions(adfgxLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgxName);
- */
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(ADFGX_FACTS.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(ADFGX_FACTS.get(0), ADFGX_FACTS.get(1), ADFGX_FACTS.get(2))));
}
@Test
public void testEncodeAdfgx() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(decodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(adfgxLogger, times(1)).info("Encoding {}", adfgxName);
- verifyNoMoreInteractions(adfgxLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgxName);
- //Cipher Aspect
- verifyAspectLogging(decodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
}
@Test
public void testEncodeAdfgx_error() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(adfgxLogger, times(1)).info("Encoding {}", adfgxName);
- verifyNoMoreInteractions(adfgxLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgxName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
@Test
public void testDecodeAdfgx() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(encodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(adfgxLogger, times(1)).info("Decoding {}", adfgxName);
- verifyNoMoreInteractions(adfgxLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgxName);
- //Cipher Aspect
- verifyAspectLogging(encodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
}
@Test
public void testDecodeAdfgvx_error() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(adfgxLogger, times(1)).info("Decoding {}", adfgxName);
- verifyNoMoreInteractions(adfgxLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgxName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/combination/AdfgxCipherControllerTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/combination/AdfgxCipherControllerTest.java
index f00da66..9d18cbf 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/combination/AdfgxCipherControllerTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/combination/AdfgxCipherControllerTest.java
@@ -33,23 +33,23 @@ public class AdfgxCipherControllerTest{
private static final String ADFGX_SQUARE_KEYWORD = CipherParameterUtil.SQUARE_KEYWORD;
private static final String ADFGX_INPUT_STRING = "Message to^encode";
private static final String ADFGX_OUTPUT_STRING = "AAgagadfagaxxd axdx^adafafxddgdf";
- private static final String adfgxName = "adfgxName";
- private static final String adfgxDescription = "adfgxDescription";
- private static final List adfgxExplanation = List.of("adfgxExplanation1", "adfgxExplanation2", "adfgxExplanation3");
- private static final List adfgxFacts = List.of("adfgxFact1", "adfgxFact2", "adfgxFact3");
+ private static final String ADFGX_NAME = "adfgxName";
+ private static final String ADFGX_DESCRIPTION = "adfgxDescription";
+ private static final List ADFGX_EXPLANATION = List.of("adfgxExplanation1", "adfgxExplanation2", "adfgxExplanation3");
+ private static final List ADFGX_FACTS = List.of("adfgxFact1", "adfgxFact2", "adfgxFact3");
@BeforeEach
public void setup(){
- ReflectionTestUtils.setField(adfgxCipherController, "adfgxName", adfgxName);
- ReflectionTestUtils.setField(adfgxCipherController, "adfgxDescription", adfgxDescription);
- ReflectionTestUtils.setField(adfgxCipherController, "adfgxExplanation", adfgxExplanation);
- ReflectionTestUtils.setField(adfgxCipherController, "adfgxFacts", adfgxFacts);
+ ReflectionTestUtils.setField(adfgxCipherController, "adfgxName", ADFGX_NAME);
+ ReflectionTestUtils.setField(adfgxCipherController, "adfgxDescription", ADFGX_DESCRIPTION);
+ ReflectionTestUtils.setField(adfgxCipherController, "adfgxExplanation", ADFGX_EXPLANATION);
+ ReflectionTestUtils.setField(adfgxCipherController, "adfgxFacts", ADFGX_FACTS);
}
@Test
public void testGetCipherInfo(){
- ObjectNode infoNode = CipherInfoUtil.buildInfoNode(adfgxName, adfgxDescription, adfgxExplanation, adfgxFacts);
+ ObjectNode infoNode = CipherInfoUtil.buildInfoNode(ADFGX_NAME, ADFGX_DESCRIPTION, ADFGX_EXPLANATION, ADFGX_FACTS);
ObjectNode returnedJson = adfgxCipherController.getCipherInfo();
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AffineCipherControllerIntegrationTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AffineCipherControllerIntegrationTest.java
index 2913c3c..25fcfc5 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AffineCipherControllerIntegrationTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AffineCipherControllerIntegrationTest.java
@@ -20,8 +20,6 @@ import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTe
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
-import tools.jackson.databind.node.ObjectNode;
-
@Tag("integration-test")
@WebMvcTest(controllers = AffineCipherController.class)
@@ -30,21 +28,16 @@ public class AffineCipherControllerIntegrationTest extends CipherStreamControlle
private MockMvc mockMvc;
@Autowired
private AffineCipherController affineCipherController;
- //Loggers
- //TODO: Fix logger testing
- //@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AffineCipherController")
- //private Logger affineLogger;
//Fields
- private static final ObjectNode blankNode = mapper.createObjectNode();
- 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 List affineExplanation = List.of("affineExplanation1", "affineExplanation2", "affineExplanation3");
- private static final List affineFacts = List.of("affineFact1", "affineFact2", "affineFact3");
+ private static final String URL = "/affine";
+ private static final String DECODED_STRING = "Message to^encode";
+ private static final String ENCODED_STRING = "Pbtthlb yz^burzwb";
+ private static final int KEY_1 = 5;
+ private static final int KEY_2 = 7;
+ private static final String AFFINE_NAME = "affineCipherName";
+ private static final String AFFINE_DESCRIPTION = "affineCipherDescription";
+ private static final List AFFINE_EXPLANATION = List.of("affineExplanation1", "affineExplanation2", "affineExplanation3");
+ private static final List AFFINE_FACTS = List.of("affineFact1", "affineFact2", "affineFact3");
@BeforeEach
@@ -53,147 +46,89 @@ public class AffineCipherControllerIntegrationTest extends CipherStreamControlle
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- decodedNode.put(CipherParameterUtil.AFFINE_KEY_1, key1);
- decodedNode.put(CipherParameterUtil.AFFINE_KEY_2, key2);
- decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
- decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
+ decodedNode.put(CipherParameterUtil.AFFINE_KEY_1, KEY_1);
+ decodedNode.put(CipherParameterUtil.AFFINE_KEY_2, KEY_2);
+ decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
+ decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
encodedNode = mapper.createObjectNode();
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- encodedNode.put(CipherParameterUtil.AFFINE_KEY_1, key1);
- encodedNode.put(CipherParameterUtil.AFFINE_KEY_2, key2);
- encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
- encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
+ encodedNode.put(CipherParameterUtil.AFFINE_KEY_1, KEY_1);
+ encodedNode.put(CipherParameterUtil.AFFINE_KEY_2, KEY_2);
+ encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
+ encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
- ReflectionTestUtils.setField(affineCipherController, "affineName", affineName);
- ReflectionTestUtils.setField(affineCipherController, "affineDescription", affineDescription);
- ReflectionTestUtils.setField(affineCipherController, "affineExplanation", affineExplanation);
- ReflectionTestUtils.setField(affineCipherController, "affineFacts", affineFacts);
+ ReflectionTestUtils.setField(affineCipherController, "affineName", AFFINE_NAME);
+ ReflectionTestUtils.setField(affineCipherController, "affineDescription", AFFINE_DESCRIPTION);
+ ReflectionTestUtils.setField(affineCipherController, "affineExplanation", AFFINE_EXPLANATION);
+ ReflectionTestUtils.setField(affineCipherController, "affineFacts", AFFINE_FACTS);
}
@Test
public void testGetCipherInfo() throws Exception{
- mockMvc.perform(get(url)
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress))
+ mockMvc.perform(get(URL)
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(affineDescription))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(affineName))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(AFFINE_DESCRIPTION))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(AFFINE_NAME))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(affineExplanation.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(affineExplanation.get(0), affineExplanation.get(1), affineExplanation.get(2))))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(AFFINE_EXPLANATION.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(AFFINE_EXPLANATION.get(0), AFFINE_EXPLANATION.get(1), AFFINE_EXPLANATION.get(2))))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(affineFacts.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(affineFacts.get(0), affineFacts.get(1), affineFacts.get(2))));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url);
- //Controller
- verify(affineLogger, times(1)).info("Getting info for {}", affineName);
- verifyNoMoreInteractions(affineLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
- */
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(AFFINE_FACTS.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(AFFINE_FACTS.get(0), AFFINE_FACTS.get(1), AFFINE_FACTS.get(2))));
}
@Test
public void testEncodeAffine() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(decodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(affineLogger, times(1)).info("Encoding {}", affineName);
- verifyNoMoreInteractions(affineLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
- //Cipher Aspect
- verifyAspectLogging(decodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
}
@Test
public void testEncodeAffine_error() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(affineLogger, times(1)).info("Encoding {}", affineName);
- verifyNoMoreInteractions(affineLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
@Test
public void testDecodeAffine() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(encodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(affineLogger, times(1)).info("Decoding {}", affineName);
- verifyNoMoreInteractions(affineLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
- //Cipher Aspect
- verifyAspectLogging(encodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
}
@Test
public void testDecodeAffine_error() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(affineLogger, times(1)).info("Decoding {}", affineName);
- verifyNoMoreInteractions(affineLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AffineCipherControllerTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AffineCipherControllerTest.java
index f8e286f..5cfda40 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AffineCipherControllerTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AffineCipherControllerTest.java
@@ -28,28 +28,28 @@ public class AffineCipherControllerTest{
private AffineCipherController affineCipherController;
//Fields
private static final ObjectMapper mapper = new ObjectMapper();
+ private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String AFFINE_INPUT_STRING = "Message to^encode";
private static final String AFFINE_OUTPUT_STRING = "Pbtthlb yz^burzwb";
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";
- private static final List affineExplanation = List.of("affineExplanation1", "affineExplanation2", "affineExplanation3");
- private static final List affineFacts = List.of("affineFact1", "affineFact2", "affineFact3");
+ private static final String AFFINE_NAME = "affineCipherName";
+ private static final String AFFINE_DESCRIPTION = "affineCipherDescription";
+ private static final List AFFINE_EXPLANATION = List.of("affineExplanation1", "affineExplanation2", "affineExplanation3");
+ private static final List AFFINE_FACTS = List.of("affineFact1", "affineFact2", "affineFact3");
@BeforeEach
public void setup(){
- ReflectionTestUtils.setField(affineCipherController, "affineName", affineName);
- ReflectionTestUtils.setField(affineCipherController, "affineDescription", affineDescription);
- ReflectionTestUtils.setField(affineCipherController, "affineExplanation", affineExplanation);
- ReflectionTestUtils.setField(affineCipherController, "affineFacts", affineFacts);
+ ReflectionTestUtils.setField(affineCipherController, "affineName", AFFINE_NAME);
+ ReflectionTestUtils.setField(affineCipherController, "affineDescription", AFFINE_DESCRIPTION);
+ ReflectionTestUtils.setField(affineCipherController, "affineExplanation", AFFINE_EXPLANATION);
+ ReflectionTestUtils.setField(affineCipherController, "affineFacts", AFFINE_FACTS);
}
@Test
public void testGetCipherInfo(){
- ObjectNode infoNode = CipherInfoUtil.buildInfoNode(affineName, affineDescription, affineExplanation, affineFacts);
+ ObjectNode infoNode = CipherInfoUtil.buildInfoNode(AFFINE_NAME, AFFINE_DESCRIPTION, AFFINE_EXPLANATION, AFFINE_FACTS);
ObjectNode returnedJson = affineCipherController.getCipherInfo();
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AtbashCipherControllerIntegrationTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AtbashCipherControllerIntegrationTest.java
index 5ce4fa5..cb60eba 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AtbashCipherControllerIntegrationTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AtbashCipherControllerIntegrationTest.java
@@ -20,8 +20,6 @@ import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTe
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
-import tools.jackson.databind.node.ObjectNode;
-
@Tag("integration-test")
@WebMvcTest(controllers = AtbashCipherController.class)
@@ -30,19 +28,14 @@ public class AtbashCipherControllerIntegrationTest extends CipherStreamControlle
private MockMvc mockMvc;
@Autowired
private AtbashCipherController atbashCipherController;
- //Loggers
- //TODO: Fix logger testing
- //@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AtbashCipherController")
- //protected Logger atbashLogger;
//Fields
- 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";
- private static final List atbashExplanation = List.of("atbashExplanation1", "atbashExplanation2", "atbashExplanation3");
- private static final List atbashFacts = List.of("atbashFact1", "atbashFact2", "atbashFact3");
+ private static final String URL = "/atbash";
+ private static final String DECODED_STRING = "Message to^encode";
+ private static final String ENCODED_STRING = "Nvhhztv gl^vmxlwv";
+ private static final String ATBASH_NAME = "atbashName";
+ private static final String ATBASH_DESCRIPTION = "atbashDescription";
+ private static final List ATBASH_EXPLANATION = List.of("atbashExplanation1", "atbashExplanation2", "atbashExplanation3");
+ private static final List ATBASH_FACTS = List.of("atbashFact1", "atbashFact2", "atbashFact3");
@BeforeEach
@@ -51,143 +44,85 @@ public class AtbashCipherControllerIntegrationTest extends CipherStreamControlle
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
- decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
+ decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
+ decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
encodedNode = mapper.createObjectNode();
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
- encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
+ encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
+ encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
- ReflectionTestUtils.setField(atbashCipherController, "atbashName", atbashName);
- ReflectionTestUtils.setField(atbashCipherController, "atbashDescription", atbashDescription);
- ReflectionTestUtils.setField(atbashCipherController, "atbashExplanation", atbashExplanation);
- ReflectionTestUtils.setField(atbashCipherController, "atbashFacts", atbashFacts);
+ ReflectionTestUtils.setField(atbashCipherController, "atbashName", ATBASH_NAME);
+ ReflectionTestUtils.setField(atbashCipherController, "atbashDescription", ATBASH_DESCRIPTION);
+ ReflectionTestUtils.setField(atbashCipherController, "atbashExplanation", ATBASH_EXPLANATION);
+ ReflectionTestUtils.setField(atbashCipherController, "atbashFacts", ATBASH_FACTS);
}
@Test
public void testGetCipherInfo() throws Exception{
- mockMvc.perform(get(url)
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress))
+ mockMvc.perform(get(URL)
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(atbashDescription))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(atbashName))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(ATBASH_DESCRIPTION))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(ATBASH_NAME))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(atbashExplanation.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(atbashExplanation.get(0), atbashExplanation.get(1), atbashExplanation.get(2))))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(ATBASH_EXPLANATION.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(ATBASH_EXPLANATION.get(0), ATBASH_EXPLANATION.get(1), ATBASH_EXPLANATION.get(2))))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(atbashFacts.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(atbashFacts.get(0), atbashFacts.get(1), atbashFacts.get(2))));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url);
- //Controller
- verify(atbashLogger, times(1)).info("Getting info for {}", atbashName);
- verifyNoMoreInteractions(atbashLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
- */
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(ATBASH_FACTS.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(ATBASH_FACTS.get(0), ATBASH_FACTS.get(1), ATBASH_FACTS.get(2))));
}
@Test
public void testEncodeAtbash() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(decodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(atbashLogger, times(1)).info("Encoding {}", atbashName);
- verifyNoMoreInteractions(atbashLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
- //Cipher Aspect
- verifyAspectLogging(decodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
}
@Test
public void testEncodeAtbash_error() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(atbashLogger, times(1)).info("Encoding {}", atbashName);
- verifyNoMoreInteractions(atbashLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
@Test
public void testDecodeAtbash() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(encodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(atbashLogger, times(1)).info("Decoding {}", atbashName);
- verifyNoMoreInteractions(atbashLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
- //Cipher Aspect
- verifyAspectLogging(encodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
}
@Test
public void testDecodeAtbash_error() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(atbashLogger, times(1)).info("Decoding {}", atbashName);
- verifyNoMoreInteractions(atbashLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AtbashCipherControllerTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AtbashCipherControllerTest.java
index 1547837..15967f5 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AtbashCipherControllerTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AtbashCipherControllerTest.java
@@ -31,24 +31,24 @@ public class AtbashCipherControllerTest{
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 String atbashName = "atbashName";
- private static final String atbashDescription = "atbashDescription";
- private static final List atbashExplanation = List.of("atbashExplanation1", "atbashExplanation2", "atbashExplanation3");
- private static final List atbashFacts = List.of("atbashFact1", "atbashFact2", "atbashFact3");
+ private static final String ATBASH_NAME = "atbashName";
+ private static final String ATBASH_DESCRIPTION = "atbashDescription";
+ private static final List ATBASH_EXPLANATION = List.of("atbashExplanation1", "atbashExplanation2", "atbashExplanation3");
+ private static final List ATBASH_FACTS = List.of("atbashFact1", "atbashFact2", "atbashFact3");
@BeforeEach
public void setup(){
- ReflectionTestUtils.setField(atbashCipherController, "atbashName", atbashName);
- ReflectionTestUtils.setField(atbashCipherController, "atbashDescription", atbashDescription);
- ReflectionTestUtils.setField(atbashCipherController, "atbashExplanation", atbashExplanation);
- ReflectionTestUtils.setField(atbashCipherController, "atbashFacts", atbashFacts);
+ ReflectionTestUtils.setField(atbashCipherController, "atbashName", ATBASH_NAME);
+ ReflectionTestUtils.setField(atbashCipherController, "atbashDescription", ATBASH_DESCRIPTION);
+ ReflectionTestUtils.setField(atbashCipherController, "atbashExplanation", ATBASH_EXPLANATION);
+ ReflectionTestUtils.setField(atbashCipherController, "atbashFacts", ATBASH_FACTS);
}
@Test
public void testGetCipherInfo(){
- ObjectNode infoNode = CipherInfoUtil.buildInfoNode(atbashName, atbashDescription, atbashExplanation, atbashFacts);
+ ObjectNode infoNode = CipherInfoUtil.buildInfoNode(ATBASH_NAME, ATBASH_DESCRIPTION, ATBASH_EXPLANATION, ATBASH_FACTS);
ObjectNode returnedJson = atbashCipherController.getCipherInfo();
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AutokeyCipherControllerIntegrationTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AutokeyCipherControllerIntegrationTest.java
index ed8e3f0..1ff0f17 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AutokeyCipherControllerIntegrationTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AutokeyCipherControllerIntegrationTest.java
@@ -20,8 +20,6 @@ import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTe
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
-import tools.jackson.databind.node.ObjectNode;
-
@Tag("integration-test")
@WebMvcTest(controllers = AutokeyCipherController.class)
@@ -30,20 +28,15 @@ public class AutokeyCipherControllerIntegrationTest extends CipherStreamControll
private MockMvc mockMvc;
@Autowired
private AutokeyCipherController autokeyCipherController;
- //Loggers
- //TODO: Fix logger testing
- //@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AutokeyCipherController")
- //protected Logger autokeyLogger;
//Fields
- 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";
- private static final List autokeyExplanation = List.of("autokeyExplanation1", "autokeyExplanation2", "autokeyExplanation3");
- private static final List autokeyFacts = List.of("autokeyFact1", "autokeyFact2", "autokeyFact3");
+ private static final String URL = "/autokey";
+ private static final String DECODED_STRING = "Message to^encode";
+ private static final String ENCODED_STRING = "Wiqooxh fs^wfcuhx";
+ private static final String KEYWORD = "keyword";
+ private static final String AUTOKEY_NAME = "autokeyName";
+ private static final String AUTOKEY_DESCRIPTION = "autokeyDescription";
+ private static final List AUTOKEY_EXPLANATION = List.of("autokeyExplanation1", "autokeyExplanation2", "autokeyExplanation3");
+ private static final List AUTOKEY_FACTS = List.of("autokeyFact1", "autokeyFact2", "autokeyFact3");
@BeforeEach
@@ -52,145 +45,87 @@ public class AutokeyCipherControllerIntegrationTest extends CipherStreamControll
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
- decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
+ decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
+ decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
encodedNode = mapper.createObjectNode();
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
- encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
+ encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
+ encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
- ReflectionTestUtils.setField(autokeyCipherController, "autokeyName", autokeyName);
- ReflectionTestUtils.setField(autokeyCipherController, "autokeyDescription", autokeyDescription);
- ReflectionTestUtils.setField(autokeyCipherController, "autokeyExplanation", autokeyExplanation);
- ReflectionTestUtils.setField(autokeyCipherController, "autokeyFacts", autokeyFacts);
+ ReflectionTestUtils.setField(autokeyCipherController, "autokeyName", AUTOKEY_NAME);
+ ReflectionTestUtils.setField(autokeyCipherController, "autokeyDescription", AUTOKEY_DESCRIPTION);
+ ReflectionTestUtils.setField(autokeyCipherController, "autokeyExplanation", AUTOKEY_EXPLANATION);
+ ReflectionTestUtils.setField(autokeyCipherController, "autokeyFacts", AUTOKEY_FACTS);
}
@Test
public void testGetCipherInfo() throws Exception{
- mockMvc.perform(get(url)
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress))
+ mockMvc.perform(get(URL)
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(autokeyDescription))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(autokeyName))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(AUTOKEY_DESCRIPTION))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(AUTOKEY_NAME))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(autokeyExplanation.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(autokeyExplanation.get(0), autokeyExplanation.get(1), autokeyExplanation.get(2))))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(AUTOKEY_EXPLANATION.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(AUTOKEY_EXPLANATION.get(0), AUTOKEY_EXPLANATION.get(1), AUTOKEY_EXPLANATION.get(2))))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(autokeyFacts.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(autokeyFacts.get(0), autokeyFacts.get(1), autokeyFacts.get(2))));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url);
- //Controller
- verify(autokeyLogger, times(1)).info("Getting info for {}", autokeyName);
- verifyNoMoreInteractions(autokeyLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
- */
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(AUTOKEY_FACTS.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(AUTOKEY_FACTS.get(0), AUTOKEY_FACTS.get(1), AUTOKEY_FACTS.get(2))));
}
@Test
public void testEncodeAutokey() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(decodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(autokeyLogger, times(1)).info("Encoding {}", autokeyName);
- verifyNoMoreInteractions(autokeyLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
- //Cipher Aspect
- verifyAspectLogging(decodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
}
@Test
public void testEncodeAutokey_error() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(autokeyLogger, times(1)).info("Encoding {}", autokeyName);
- verifyNoMoreInteractions(autokeyLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
@Test
public void testDecodeAutokey() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(encodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(autokeyLogger, times(1)).info("Decoding {}", autokeyName);
- verifyNoMoreInteractions(autokeyLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
- //Cipher Aspect
- verifyAspectLogging(encodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
}
@Test
public void testDecodeAutokey_error() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(autokeyLogger, times(1)).info("Decoding {}", autokeyName);
- verifyNoMoreInteractions(autokeyLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AutokeyCipherControllerTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AutokeyCipherControllerTest.java
index 88215fb..40fb892 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AutokeyCipherControllerTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/AutokeyCipherControllerTest.java
@@ -32,23 +32,23 @@ public class AutokeyCipherControllerTest{
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 String autokeyName = "autokeyName";
- private static final String autokeyDescription = "autokeyDescription";
- private static final List autokeyExplanation = List.of("autokeyExplanation1", "autokeyExplanation2", "autokeyExplanation3");
- private static final List autokeyFacts = List.of("autokeyFact1", "autokeyFact2", "autokeyFact3");
+ private static final String AUTOKEY_NAME = "autokeyName";
+ private static final String AUTOKEY_DESCRIPTION = "autokeyDescription";
+ private static final List AUTOKEY_EXPLANATION = List.of("autokeyExplanation1", "autokeyExplanation2", "autokeyExplanation3");
+ private static final List AUTOKEY_FACTS = List.of("autokeyFact1", "autokeyFact2", "autokeyFact3");
@BeforeEach
public void setup(){
- ReflectionTestUtils.setField(autokeyCipherController, "autokeyName", autokeyName);
- ReflectionTestUtils.setField(autokeyCipherController, "autokeyDescription", autokeyDescription);
- ReflectionTestUtils.setField(autokeyCipherController, "autokeyExplanation", autokeyExplanation);
- ReflectionTestUtils.setField(autokeyCipherController, "autokeyFacts", autokeyFacts);
+ ReflectionTestUtils.setField(autokeyCipherController, "autokeyName", AUTOKEY_NAME);
+ ReflectionTestUtils.setField(autokeyCipherController, "autokeyDescription", AUTOKEY_DESCRIPTION);
+ ReflectionTestUtils.setField(autokeyCipherController, "autokeyExplanation", AUTOKEY_EXPLANATION);
+ ReflectionTestUtils.setField(autokeyCipherController, "autokeyFacts", AUTOKEY_FACTS);
}
@Test
public void testGetCipherInfo(){
- ObjectNode infoNode = CipherInfoUtil.buildInfoNode(autokeyName, autokeyDescription, autokeyExplanation, autokeyFacts);
+ ObjectNode infoNode = CipherInfoUtil.buildInfoNode(AUTOKEY_NAME, AUTOKEY_DESCRIPTION, AUTOKEY_EXPLANATION, AUTOKEY_FACTS);
ObjectNode returnedJson = autokeyCipherController.getCipherInfo();
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BaconianCipherControllerIntegrationTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BaconianCipherControllerIntegrationTest.java
index 154b864..d7b5a17 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BaconianCipherControllerIntegrationTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BaconianCipherControllerIntegrationTest.java
@@ -20,8 +20,6 @@ import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTe
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
-import tools.jackson.databind.node.ObjectNode;
-
@Tag("integration-test")
@WebMvcTest(controllers = BaconianCipherController.class)
@@ -30,19 +28,14 @@ public class BaconianCipherControllerIntegrationTest extends CipherStreamControl
private MockMvc mockMvc;
@Autowired
private BaconianCipherController baconianCipherController;
- //Loggers
- //TODO: Fix logger testing
- //@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BaconianCipherController")
- //protected Logger baconianLogger;
//Fields
- 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";
- private static final List baconianExplanation = List.of("baconianExplanation1", "baconianExplanation2", "baconianExplanation3");
- private static final List baconianFacts = List.of("baconianFact1", "baconianFact2", "baconianFact3");
+ private static final String URL = "/baconian";
+ private static final String DECODED_STRING = "Message to^encode";
+ private static final String ENCODED_STRING = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
+ private static final String BACONIAN_NAME = "baconianName";
+ private static final String BACONIAN_DESCRIPTION = "baconianDescription";
+ private static final List BACONIAN_EXPLANATION = List.of("baconianExplanation1", "baconianExplanation2", "baconianExplanation3");
+ private static final List BACONIAN_FACTS = List.of("baconianFact1", "baconianFact2", "baconianFact3");
@BeforeEach
@@ -51,143 +44,85 @@ public class BaconianCipherControllerIntegrationTest extends CipherStreamControl
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
- decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
+ decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
+ decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
encodedNode = mapper.createObjectNode();
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
- encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString.replaceAll("[^a-zA-Z]", ""));
+ encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
+ encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING.replaceAll("[^a-zA-Z]", ""));
- ReflectionTestUtils.setField(baconianCipherController, "baconianName", baconianName);
- ReflectionTestUtils.setField(baconianCipherController, "baconianDescription", baconianDescription);
- ReflectionTestUtils.setField(baconianCipherController, "baconianExplanation", baconianExplanation);
- ReflectionTestUtils.setField(baconianCipherController, "baconianFacts", baconianFacts);
+ ReflectionTestUtils.setField(baconianCipherController, "baconianName", BACONIAN_NAME);
+ ReflectionTestUtils.setField(baconianCipherController, "baconianDescription", BACONIAN_DESCRIPTION);
+ ReflectionTestUtils.setField(baconianCipherController, "baconianExplanation", BACONIAN_EXPLANATION);
+ ReflectionTestUtils.setField(baconianCipherController, "baconianFacts", BACONIAN_FACTS);
}
@Test
public void testGetCipherInfo() throws Exception{
- mockMvc.perform(get(url)
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress))
+ mockMvc.perform(get(URL)
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(baconianDescription))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(baconianName))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(BACONIAN_DESCRIPTION))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(BACONIAN_NAME))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(baconianExplanation.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(baconianExplanation.get(0), baconianExplanation.get(1), baconianExplanation.get(2))))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(BACONIAN_EXPLANATION.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(BACONIAN_EXPLANATION.get(0), BACONIAN_EXPLANATION.get(1), BACONIAN_EXPLANATION.get(2))))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(baconianFacts.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(baconianFacts.get(0), baconianFacts.get(1), baconianFacts.get(2))));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url);
- //Controller
- verify(baconianLogger, times(1)).info("Getting info for {}", baconianName);
- verifyNoMoreInteractions(baconianLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
- */
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(BACONIAN_FACTS.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(BACONIAN_FACTS.get(0), BACONIAN_FACTS.get(1), BACONIAN_FACTS.get(2))));
}
@Test
public void testEncodeBaconian() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(decodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(baconianLogger, times(1)).info("Encoding {}", baconianName);
- verifyNoMoreInteractions(baconianLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
- //Cipher Aspect
- verifyAspectLogging(decodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
}
@Test
public void testEncodeBaconian_error() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(baconianLogger, times(1)).info("Encoding {}", baconianName);
- verifyNoMoreInteractions(baconianLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
@Test
public void testDecodeBaconian() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(encodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString.replaceAll("[^a-zA-Z]", "")));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(baconianLogger, times(1)).info("Decoding {}", baconianName);
- verifyNoMoreInteractions(baconianLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
- //Cipher Aspect
- verifyAspectLogging(encodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING.replaceAll("[^a-zA-Z]", "")));
}
@Test
public void testDecodeBaconian_error() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(baconianLogger, times(1)).info("Decoding {}", baconianName);
- verifyNoMoreInteractions(baconianLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BaconianCipherControllerTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BaconianCipherControllerTest.java
index bb2f973..c96200e 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BaconianCipherControllerTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BaconianCipherControllerTest.java
@@ -28,28 +28,28 @@ public class BaconianCipherControllerTest{
private BaconianCipherController baconianCipherController;
//Fields
private static final ObjectMapper mapper = new ObjectMapper();
+ private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String BACONIAN_INPUT_STRING = "Message to-encode";
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";
- private static final List baconianExplanation = List.of("baconianExplanation1", "baconianExplanation2", "baconianExplanation3");
- private static final List baconianFacts = List.of("baconianFact1", "baconianFact2", "baconianFact3");
+ private static final String BACONIAN_NAME = "baconianName";
+ private static final String BACONIAN_DESCRIPTION = "baconianDescription";
+ private static final List BACONIAN_EXPLANATION = List.of("baconianExplanation1", "baconianExplanation2", "baconianExplanation3");
+ private static final List BACONIAN_FACTS = List.of("baconianFact1", "baconianFact2", "baconianFact3");
@BeforeEach
public void setup(){
- ReflectionTestUtils.setField(baconianCipherController, "baconianName", baconianName);
- ReflectionTestUtils.setField(baconianCipherController, "baconianDescription", baconianDescription);
- ReflectionTestUtils.setField(baconianCipherController, "baconianExplanation", baconianExplanation);
- ReflectionTestUtils.setField(baconianCipherController, "baconianFacts", baconianFacts);
+ ReflectionTestUtils.setField(baconianCipherController, "baconianName", BACONIAN_NAME);
+ ReflectionTestUtils.setField(baconianCipherController, "baconianDescription", BACONIAN_DESCRIPTION);
+ ReflectionTestUtils.setField(baconianCipherController, "baconianExplanation", BACONIAN_EXPLANATION);
+ ReflectionTestUtils.setField(baconianCipherController, "baconianFacts", BACONIAN_FACTS);
}
@Test
public void tetGetCipherInfo(){
- ObjectNode infoNode = CipherInfoUtil.buildInfoNode(baconianName, baconianDescription, baconianExplanation, baconianFacts);
+ ObjectNode infoNode = CipherInfoUtil.buildInfoNode(BACONIAN_NAME, BACONIAN_DESCRIPTION, BACONIAN_EXPLANATION, BACONIAN_FACTS);
ObjectNode returnedJson = baconianCipherController.getCipherInfo();
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BaseXCipherControllerIntegrationTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BaseXCipherControllerIntegrationTest.java
index 478a4ed..8d9a0ed 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BaseXCipherControllerIntegrationTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BaseXCipherControllerIntegrationTest.java
@@ -20,8 +20,6 @@ import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTe
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
-import tools.jackson.databind.node.ObjectNode;
-
@Tag("integration-test")
@WebMvcTest(controllers = BaseXCipherController.class)
@@ -30,20 +28,15 @@ public class BaseXCipherControllerIntegrationTest extends CipherStreamController
private MockMvc mockMvc;
@Autowired
private BaseXCipherController baseXCipherController;
- //Loggers
- //TODO: Fix logger testing
- //@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BaseXCipherController")
- //protected Logger baseXLogger;
//Fields
- 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";
- private static final List baseXExplanation = List.of("baseXExplanation1", "baseXExplanation2", "baseXExplanation3");
- private static final List baseXFacts = List.of("baseXFact1", "baseXFact2", "baseXFact3");
+ private static final String URL = "/basex";
+ private static final String DECODED_STRING = "A+B@C d\te\nf";
+ private static final String ENCODED_STRING = "1000001 101011 1000010 1000000 1000011 100000 1100100 1001 1100101 1010 1100110";
+ private static final int BASE = 2;
+ private static final String BASE_X_NAME = "baseXName";
+ private static final String BASE_X_DESCRIPTION = "baseXDescription";
+ private static final List BASE_X_EXPLANATION = List.of("baseXExplanation1", "baseXExplanation2", "baseXExplanation3");
+ private static final List BASE_X_FACTS = List.of("baseXFact1", "baseXFact2", "baseXFact3");
@BeforeEach
@@ -52,145 +45,87 @@ public class BaseXCipherControllerIntegrationTest extends CipherStreamController
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- decodedNode.put(CipherParameterUtil.BASE_X_BASE, base);
- decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
- decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
+ decodedNode.put(CipherParameterUtil.BASE_X_BASE, BASE);
+ decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
+ decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
encodedNode = mapper.createObjectNode();
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- encodedNode.put(CipherParameterUtil.BASE_X_BASE, base);
- encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
- encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
+ encodedNode.put(CipherParameterUtil.BASE_X_BASE, BASE);
+ encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
+ encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
- ReflectionTestUtils.setField(baseXCipherController, "baseXName", baseXName);
- ReflectionTestUtils.setField(baseXCipherController, "baseXDescription", baseXDescription);
- ReflectionTestUtils.setField(baseXCipherController, "baseXExplanation", baseXExplanation);
- ReflectionTestUtils.setField(baseXCipherController, "baseXFacts", baseXFacts);
+ ReflectionTestUtils.setField(baseXCipherController, "baseXName", BASE_X_NAME);
+ ReflectionTestUtils.setField(baseXCipherController, "baseXDescription", BASE_X_DESCRIPTION);
+ ReflectionTestUtils.setField(baseXCipherController, "baseXExplanation", BASE_X_EXPLANATION);
+ ReflectionTestUtils.setField(baseXCipherController, "baseXFacts", BASE_X_FACTS);
}
@Test
public void testGetCipherInfo() throws Exception{
- mockMvc.perform(get(url)
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress))
+ mockMvc.perform(get(URL)
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(baseXDescription))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(baseXName))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(BASE_X_DESCRIPTION))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(BASE_X_NAME))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(baseXExplanation.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(baseXExplanation.get(0), baseXExplanation.get(1), baseXExplanation.get(2))))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(BASE_X_EXPLANATION.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(BASE_X_EXPLANATION.get(0), BASE_X_EXPLANATION.get(1), BASE_X_EXPLANATION.get(2))))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(baseXFacts.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(baseXFacts.get(0), baseXFacts.get(1), baseXFacts.get(2))));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url);
- //Controller
- verify(baseXLogger, times(1)).info("Getting info for {}", baseXName);
- verifyNoMoreInteractions(baseXLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
- */
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(BASE_X_FACTS.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(BASE_X_FACTS.get(0), BASE_X_FACTS.get(1), BASE_X_FACTS.get(2))));
}
@Test
public void testEncodeBaseXEncode() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(decodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(baseXLogger, times(1)).info("Encoding {}", baseXName);
- verifyNoMoreInteractions(baseXLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
- //Cipher Aspect
- verifyAspectLogging(decodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
}
@Test
public void testEncodeBaseX_error() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.INPUT_STRING + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(baseXLogger, times(1)).info("Encoding {}", baseXName);
- verifyNoMoreInteractions(baseXLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
@Test
public void testDecodeBaseXDecode() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(encodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(baseXLogger, times(1)).info("Decoding {}", baseXName);
- verifyNoMoreInteractions(baseXLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
- //Cipher Aspect
- verifyAspectLogging(encodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
}
@Test
public void testDecodeBaseX_error() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.INPUT_STRING + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(baseXLogger, times(1)).info("Decoding {}", baseXName);
- verifyNoMoreInteractions(baseXLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BaseXCipherControllerTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BaseXCipherControllerTest.java
index 1bee7e0..40821ed 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BaseXCipherControllerTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BaseXCipherControllerTest.java
@@ -32,23 +32,23 @@ public class BaseXCipherControllerTest{
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 String baseXName = "baseXName";
- private static final String baseXDescription = "baseXDescription";
- private static final List baseXExplanation = List.of("baseXExplanation1", "baseXExplanation2", "baseXExplanation3");
- private static final List baseXFacts = List.of("baseXFact1", "baseXFact2", "baseXFact3");
+ private static final String BASE_X_NAME = "baseXName";
+ private static final String BASE_X_DESCRIPTION = "baseXDescription";
+ private static final List BASE_X_EXPLANATION = List.of("baseXExplanation1", "baseXExplanation2", "baseXExplanation3");
+ private static final List BASE_X_FACTS = List.of("baseXFact1", "baseXFact2", "baseXFact3");
@BeforeEach
public void setup(){
- ReflectionTestUtils.setField(baseXCipherController, "baseXName", baseXName);
- ReflectionTestUtils.setField(baseXCipherController, "baseXDescription", baseXDescription);
- ReflectionTestUtils.setField(baseXCipherController, "baseXExplanation", baseXExplanation);
- ReflectionTestUtils.setField(baseXCipherController, "baseXFacts", baseXFacts);
+ ReflectionTestUtils.setField(baseXCipherController, "baseXName", BASE_X_NAME);
+ ReflectionTestUtils.setField(baseXCipherController, "baseXDescription", BASE_X_DESCRIPTION);
+ ReflectionTestUtils.setField(baseXCipherController, "baseXExplanation", BASE_X_EXPLANATION);
+ ReflectionTestUtils.setField(baseXCipherController, "baseXFacts", BASE_X_FACTS);
}
@Test
public void tetGetCipherInfo(){
- ObjectNode infoNode = CipherInfoUtil.buildInfoNode(baseXName, baseXDescription, baseXExplanation, baseXFacts);
+ ObjectNode infoNode = CipherInfoUtil.buildInfoNode(BASE_X_NAME, BASE_X_DESCRIPTION, BASE_X_EXPLANATION, BASE_X_FACTS);
ObjectNode returnedJson = baseXCipherController.getCipherInfo();
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BeaufortCipherControllerIntegrationTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BeaufortCipherControllerIntegrationTest.java
index 2335113..e66c98b 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BeaufortCipherControllerIntegrationTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BeaufortCipherControllerIntegrationTest.java
@@ -20,8 +20,6 @@ import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTe
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
-import tools.jackson.databind.node.ObjectNode;
-
@Tag("integration-test")
@WebMvcTest(controllers = BeaufortCipherController.class)
@@ -30,20 +28,15 @@ public class BeaufortCipherControllerIntegrationTest extends CipherStreamControl
private MockMvc mockMvc;
@Autowired
private BeaufortCipherController beaufortCipherController;
- //Loggers
- //TODO: Fix logger testing
- //@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BeaufortCipherController")
- //protected Logger beaufortLogger;
//Fields
- 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";
- private static final List beaufortExplanation = List.of("beaufortExplanation1", "beaufortExplanation2", "beaufortExplanation3");
- private static final List beaufortFacts = List.of("beaufortFact1", "beaufortFact2", "beaufortFact3");
+ private static final String URL = "/beaufort";
+ private static final String DECODED_STRING = "Message to^encode";
+ private static final String ENCODED_STRING = "Yageolz rq^ujmdag";
+ private static final String KEYWORD = "Ke*y word";
+ private static final String BEAUFORT_NAME = "beaufortName";
+ private static final String BEAUFORT_DESCRIPTION = "beaufortDescription";
+ private static final List BEAUFORT_EXPLANATION = List.of("beaufortExplanation1", "beaufortExplanation2", "beaufortExplanation3");
+ private static final List BEAUFORT_FACTS = List.of("beaufortFact1", "beaufortFact2", "beaufortFact3");
@BeforeEach
@@ -52,145 +45,87 @@ public class BeaufortCipherControllerIntegrationTest extends CipherStreamControl
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
- decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
+ decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
+ decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
encodedNode = mapper.createObjectNode();
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
- encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
+ encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
+ encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
- ReflectionTestUtils.setField(beaufortCipherController, "beaufortName", beaufortName);
- ReflectionTestUtils.setField(beaufortCipherController, "beaufortDescription", beaufortDescription);
- ReflectionTestUtils.setField(beaufortCipherController, "beaufortExplanation", beaufortExplanation);
- ReflectionTestUtils.setField(beaufortCipherController, "beaufortFacts", beaufortFacts);
+ ReflectionTestUtils.setField(beaufortCipherController, "beaufortName", BEAUFORT_NAME);
+ ReflectionTestUtils.setField(beaufortCipherController, "beaufortDescription", BEAUFORT_DESCRIPTION);
+ ReflectionTestUtils.setField(beaufortCipherController, "beaufortExplanation", BEAUFORT_EXPLANATION);
+ ReflectionTestUtils.setField(beaufortCipherController, "beaufortFacts", BEAUFORT_FACTS);
}
@Test
public void testGetCipherInfo() throws Exception{
- mockMvc.perform(get(url)
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress))
+ mockMvc.perform(get(URL)
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(beaufortDescription))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(beaufortName))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(BEAUFORT_DESCRIPTION))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(BEAUFORT_NAME))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(beaufortExplanation.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(beaufortExplanation.get(0), beaufortExplanation.get(1), beaufortExplanation.get(2))))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(BEAUFORT_EXPLANATION.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(BEAUFORT_EXPLANATION.get(0), BEAUFORT_EXPLANATION.get(1), BEAUFORT_EXPLANATION.get(2))))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(beaufortFacts.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(beaufortFacts.get(0), beaufortFacts.get(1), beaufortFacts.get(2))));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url);
- //Controller
- verify(beaufortLogger, times(1)).info("Getting info for {}", beaufortName);
- verifyNoMoreInteractions(beaufortLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
- */
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(BEAUFORT_FACTS.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(BEAUFORT_FACTS.get(0), BEAUFORT_FACTS.get(1), BEAUFORT_FACTS.get(2))));
}
@Test
public void testEncodeBeaufort() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(decodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(beaufortLogger, times(1)).info("Encoding {}", beaufortName);
- verifyNoMoreInteractions(beaufortLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
- //Cipher Aspect
- verifyAspectLogging(decodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
}
@Test
public void testEncodeAdfgvx_error() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(beaufortLogger, times(1)).info("Encoding {}", beaufortName);
- verifyNoMoreInteractions(beaufortLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
@Test
public void testDecodeBeaufort() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(encodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(beaufortLogger, times(1)).info("Decoding {}", beaufortName);
- verifyNoMoreInteractions(beaufortLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
- //Cipher Aspect
- verifyAspectLogging(encodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
}
@Test
public void testDecodeAdfgvx_error() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(beaufortLogger, times(1)).info("Decoding {}", beaufortName);
- verifyNoMoreInteractions(beaufortLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BeaufortCipherControllerTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BeaufortCipherControllerTest.java
index 95f7a3a..52878a1 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BeaufortCipherControllerTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/BeaufortCipherControllerTest.java
@@ -28,27 +28,27 @@ public class BeaufortCipherControllerTest{
private BeaufortCipherController beaufortCipherController;
//Fields
private static final ObjectMapper mapper = new ObjectMapper();
+ private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String BEAUFORT_KEYWORD = CipherParameterUtil.KEYWORD;
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";
- private static final List beaufortExplanation = List.of("beaufortExplanation1", "beaufortExplanation2", "beaufortExplanation3");
- private static final List beaufortFacts = List.of("beaufortFact1", "beaufortFact2", "beaufortFact3");
+ private static final String BEAUFORT_NAME = "beaufortName";
+ private static final String BEAUFORT_DESCRIPTION = "beaufortDescription";
+ private static final List BEAUFORT_EXPLANATION = List.of("beaufortExplanation1", "beaufortExplanation2", "beaufortExplanation3");
+ private static final List BEAUFORT_FACTS = List.of("beaufortFact1", "beaufortFact2", "beaufortFact3");
@BeforeEach
public void setup(){
- ReflectionTestUtils.setField(beaufortCipherController, "beaufortName", beaufortName);
- ReflectionTestUtils.setField(beaufortCipherController, "beaufortDescription", beaufortDescription);
- ReflectionTestUtils.setField(beaufortCipherController, "beaufortExplanation", beaufortExplanation);
- ReflectionTestUtils.setField(beaufortCipherController, "beaufortFacts", beaufortFacts);
+ ReflectionTestUtils.setField(beaufortCipherController, "beaufortName", BEAUFORT_NAME);
+ ReflectionTestUtils.setField(beaufortCipherController, "beaufortDescription", BEAUFORT_DESCRIPTION);
+ ReflectionTestUtils.setField(beaufortCipherController, "beaufortExplanation", BEAUFORT_EXPLANATION);
+ ReflectionTestUtils.setField(beaufortCipherController, "beaufortFacts", BEAUFORT_FACTS);
}
@Test
public void tetGetCipherInfo(){
- ObjectNode infoNode = CipherInfoUtil.buildInfoNode(beaufortName, beaufortDescription, beaufortExplanation, beaufortFacts);
+ ObjectNode infoNode = CipherInfoUtil.buildInfoNode(BEAUFORT_NAME, BEAUFORT_DESCRIPTION, BEAUFORT_EXPLANATION, BEAUFORT_FACTS);
ObjectNode returnedJson = beaufortCipherController.getCipherInfo();
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/CaesarCipherControllerIntegrationTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/CaesarCipherControllerIntegrationTest.java
index 6cd6510..7745b41 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/CaesarCipherControllerIntegrationTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/CaesarCipherControllerIntegrationTest.java
@@ -20,8 +20,6 @@ import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTe
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
-import tools.jackson.databind.node.ObjectNode;
-
@Tag("integration-test")
@WebMvcTest(controllers = CaesarCipherController.class)
@@ -30,20 +28,15 @@ public class CaesarCipherControllerIntegrationTest extends CipherStreamControlle
private MockMvc mockMvc;
@Autowired
private CaesarCipherController caesarCipherController;
- //Loggers
- //TODO: Fix logger testing
- //@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.CaesarCipherController")
- //protected Logger caesarLogger;
//Fields
- 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";
- private static final List caesarExplanation = List.of("caesarExplanation1", "caesarExplanation2", "caesarExplanation3");
- private static final List caesarFacts = List.of("caesarFact1", "caesarFact2", "caesarFact3");
+ private static final String URL = "/caesar";
+ private static final String DECODED_STRING = "The quick brown fox jumps over - the lazy dog";
+ private static final String ENCODED_STRING = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
+ private static final int SHIFT_AMOUNT = 23;
+ private static final String CAESAR_NAME = "caesarName";
+ private static final String CAESAR_DESCRIPTION = "caesarDescription";
+ private static final List CAESAR_EXPLANATION = List.of("caesarExplanation1", "caesarExplanation2", "caesarExplanation3");
+ private static final List CAESAR_FACTS = List.of("caesarFact1", "caesarFact2", "caesarFact3");
@BeforeEach
@@ -52,145 +45,87 @@ public class CaesarCipherControllerIntegrationTest extends CipherStreamControlle
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- decodedNode.put(CipherParameterUtil.CAESAR_SHIFT_AMOUNT, shiftAmount);
- decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
- decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
+ decodedNode.put(CipherParameterUtil.CAESAR_SHIFT_AMOUNT, SHIFT_AMOUNT);
+ decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
+ decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
encodedNode = mapper.createObjectNode();
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- encodedNode.put(CipherParameterUtil.CAESAR_SHIFT_AMOUNT, shiftAmount);
- encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
- encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
+ encodedNode.put(CipherParameterUtil.CAESAR_SHIFT_AMOUNT, SHIFT_AMOUNT);
+ encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
+ encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
- ReflectionTestUtils.setField(caesarCipherController, "caesarName", caesarName);
- ReflectionTestUtils.setField(caesarCipherController, "caesarDescription", caesarDescription);
- ReflectionTestUtils.setField(caesarCipherController, "caesarExplanation", caesarExplanation);
- ReflectionTestUtils.setField(caesarCipherController, "caesarFacts", caesarFacts);
+ ReflectionTestUtils.setField(caesarCipherController, "caesarName", CAESAR_NAME);
+ ReflectionTestUtils.setField(caesarCipherController, "caesarDescription", CAESAR_DESCRIPTION);
+ ReflectionTestUtils.setField(caesarCipherController, "caesarExplanation", CAESAR_EXPLANATION);
+ ReflectionTestUtils.setField(caesarCipherController, "caesarFacts", CAESAR_FACTS);
}
@Test
public void testGetCipherInfo() throws Exception{
- mockMvc.perform(get(url)
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress))
+ mockMvc.perform(get(URL)
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(caesarDescription))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(caesarName))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CAESAR_DESCRIPTION))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CAESAR_NAME))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(caesarExplanation.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(caesarExplanation.get(0), caesarExplanation.get(1), caesarExplanation.get(2))))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(CAESAR_EXPLANATION.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(CAESAR_EXPLANATION.get(0), CAESAR_EXPLANATION.get(1), CAESAR_EXPLANATION.get(2))))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(caesarFacts.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(caesarFacts.get(0), caesarFacts.get(1), caesarFacts.get(2))));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url);
- //Controller
- verify(caesarLogger, times(1)).info("Getting info for {}", caesarName);
- verifyNoMoreInteractions(caesarLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
- */
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(CAESAR_FACTS.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(CAESAR_FACTS.get(0), CAESAR_FACTS.get(1), CAESAR_FACTS.get(2))));
}
@Test
public void testEncodeCaesar() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(decodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(caesarLogger, times(1)).info("Encoding {}", caesarName);
- verifyNoMoreInteractions(caesarLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
- //Cipher Aspect
- verifyAspectLogging(decodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
}
@Test
public void testEncodeAdfgvx_error() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(caesarLogger, times(1)).info("Encoding {}", caesarName);
- verifyNoMoreInteractions(caesarLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
@Test
public void testDecodeCaesar() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(encodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(caesarLogger, times(1)).info("Decoding {}", caesarName);
- verifyNoMoreInteractions(caesarLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
- //Cipher Aspect
- verifyAspectLogging(encodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
}
@Test
public void testDecodeAdfgvx_error() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(caesarLogger, times(1)).info("Decoding {}", caesarName);
- verifyNoMoreInteractions(caesarLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/CaesarCipherControllerTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/CaesarCipherControllerTest.java
index 9eaca49..c1775a8 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/CaesarCipherControllerTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/CaesarCipherControllerTest.java
@@ -28,27 +28,27 @@ public class CaesarCipherControllerTest{
private CaesarCipherController caesarCipherController;
//Fields
private static final ObjectMapper mapper = new ObjectMapper();
+ private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String CAESAR_INPUT_STRING = "The quick brown fox jumps over - the lazy dog";
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";
- private static final List caesarExplanation = List.of("caesarExplanation1", "caesarExplanation2", "caesarExplanation3");
- private static final List caesarFacts = List.of("caesarFact1", "caesarFact2", "caesarFact3");
+ private static final String CAESAR_NAME = "caesarName";
+ private static final String CAESAR_DESCRIPTION = "caesarDescription";
+ private static final List CAESAR_EXPLANATION = List.of("caesarExplanation1", "caesarExplanation2", "caesarExplanation3");
+ private static final List CAESAR_FACTS = List.of("caesarFact1", "caesarFact2", "caesarFact3");
@BeforeEach
public void setup(){
- ReflectionTestUtils.setField(caesarCipherController, "caesarName", caesarName);
- ReflectionTestUtils.setField(caesarCipherController, "caesarDescription", caesarDescription);
- ReflectionTestUtils.setField(caesarCipherController, "caesarExplanation", caesarExplanation);
- ReflectionTestUtils.setField(caesarCipherController, "caesarFacts", caesarFacts);
+ ReflectionTestUtils.setField(caesarCipherController, "caesarName", CAESAR_NAME);
+ ReflectionTestUtils.setField(caesarCipherController, "caesarDescription", CAESAR_DESCRIPTION);
+ ReflectionTestUtils.setField(caesarCipherController, "caesarExplanation", CAESAR_EXPLANATION);
+ ReflectionTestUtils.setField(caesarCipherController, "caesarFacts", CAESAR_FACTS);
}
@Test
public void tetGetCipherInfo(){
- ObjectNode infoNode = CipherInfoUtil.buildInfoNode(caesarName, caesarDescription, caesarExplanation, caesarFacts);
+ ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CAESAR_NAME, CAESAR_DESCRIPTION, CAESAR_EXPLANATION, CAESAR_FACTS);
ObjectNode returnedJson = caesarCipherController.getCipherInfo();
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/OneTimePadCipherControllerIntegrationTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/OneTimePadCipherControllerIntegrationTest.java
index 9ea9a19..a311061 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/OneTimePadCipherControllerIntegrationTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/OneTimePadCipherControllerIntegrationTest.java
@@ -20,8 +20,6 @@ import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTe
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
-import tools.jackson.databind.node.ObjectNode;
-
@Tag("integration-test")
@WebMvcTest(controllers = OneTimePadCipherController.class)
@@ -30,20 +28,15 @@ public class OneTimePadCipherControllerIntegrationTest extends CipherStreamContr
private MockMvc mockMvc;
@Autowired
private OneTimePadCipherController oneTimePadCipherController;
- //Loggers
- //TODO: Fix logger testing
- //@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.OneTimePadCipherController")
- //protected Logger oneTimePadLogger;
//Fields
- 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";
- private static final List oneTimePadExplanation = List.of("oneTimePadExplanation1", "oneTimePadExplanation2", "oneTimePadExplanation3");
- private static final List oneTimePadFacts = List.of("oneTimePadFact1", "oneTimePadFact2", "oneTimePadFact3");
+ private static final String URL = "/oneTimePad";
+ private static final String DECODED_STRING = "Message to^encode";
+ private static final String ENCODED_STRING = "Wiqooxh mv^egkgws";
+ private static final String KEYWORD = "keywordThatIsTotallyRandom";
+ private static final String ONE_TIME_PAD_NAME = "oneTimePadName";
+ private static final String ONE_TIME_PAD_DESCRIPTION = "oneTimePadDescription";
+ private static final List ONE_TIME_PAD_EXPLANATION = List.of("oneTimePadExplanation1", "oneTimePadExplanation2", "oneTimePadExplanation3");
+ private static final List ONE_TIME_PAD_FACTS = List.of("oneTimePadFact1", "oneTimePadFact2", "oneTimePadFact3");
@BeforeEach
@@ -52,145 +45,87 @@ public class OneTimePadCipherControllerIntegrationTest extends CipherStreamContr
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
- decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
+ decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
+ decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
encodedNode = mapper.createObjectNode();
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
- encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
+ encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
+ encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
- ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadName", oneTimePadName);
- ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadDescription", oneTimePadDescription);
- ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadExplanation", oneTimePadExplanation);
- ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadFacts", oneTimePadFacts);
+ ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadName", ONE_TIME_PAD_NAME);
+ ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadDescription", ONE_TIME_PAD_DESCRIPTION);
+ ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadExplanation", ONE_TIME_PAD_EXPLANATION);
+ ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadFacts", ONE_TIME_PAD_FACTS);
}
@Test
public void testGetCipherInfo() throws Exception{
- mockMvc.perform(get(url)
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress))
+ mockMvc.perform(get(URL)
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(oneTimePadDescription))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(oneTimePadName))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(ONE_TIME_PAD_DESCRIPTION))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(ONE_TIME_PAD_NAME))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(oneTimePadExplanation.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(oneTimePadExplanation.get(0), oneTimePadExplanation.get(1), oneTimePadExplanation.get(2))))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(ONE_TIME_PAD_EXPLANATION.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(ONE_TIME_PAD_EXPLANATION.get(0), ONE_TIME_PAD_EXPLANATION.get(1), ONE_TIME_PAD_EXPLANATION.get(2))))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(oneTimePadFacts.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(oneTimePadFacts.get(0), oneTimePadFacts.get(1), oneTimePadFacts.get(2))));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url);
- //Controller
- verify(oneTimePadLogger, times(1)).info("Getting info for {}", oneTimePadName);
- verifyNoMoreInteractions(oneTimePadLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
- */
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(ONE_TIME_PAD_FACTS.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(ONE_TIME_PAD_FACTS.get(0), ONE_TIME_PAD_FACTS.get(1), ONE_TIME_PAD_FACTS.get(2))));
}
@Test
public void testEncodeOneTimePad() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(decodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(oneTimePadLogger, times(1)).info("Encoding {}", oneTimePadName);
- verifyNoMoreInteractions(oneTimePadLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
- //Cipher Aspect
- verifyAspectLogging(decodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
}
@Test
public void testEncodeAdfgvx_error() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(oneTimePadLogger, times(1)).info("Encoding {}", oneTimePadName);
- verifyNoMoreInteractions(oneTimePadLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
@Test
public void testDecodeOneTimePad() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(encodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(oneTimePadLogger, times(1)).info("Decoding {}", oneTimePadName);
- verifyNoMoreInteractions(oneTimePadLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
- //Cipher Aspect
- verifyAspectLogging(encodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
}
@Test
public void testDecodeAdfgvx_error() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(oneTimePadLogger, times(1)).info("Decoding {}", oneTimePadName);
- verifyNoMoreInteractions(oneTimePadLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/OneTimePadCipherControllerTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/OneTimePadCipherControllerTest.java
index 3d10791..ccb8e6c 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/OneTimePadCipherControllerTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/OneTimePadCipherControllerTest.java
@@ -32,23 +32,23 @@ public class OneTimePadCipherControllerTest{
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 String oneTimePadName = "oneTimePadName";
- private static final String oneTimePadDescription = "oneTimePadDescription";
- private static final List oneTimePadExplanation = List.of("oneTimePadExplanation1", "oneTimePadExplanation2", "oneTimePadExplanation3");
- private static final List oneTimePadFacts = List.of("oneTimePadFact1", "oneTimePadFact2", "oneTimePadFact3");
+ private static final String ONE_TIME_PAD_NAME = "oneTimePadName";
+ private static final String ONE_TIME_PAD_DESCRIPTION = "oneTimePadDescription";
+ private static final List ONE_TIME_PAD_EXPLANATION = List.of("oneTimePadExplanation1", "oneTimePadExplanation2", "oneTimePadExplanation3");
+ private static final List ONE_TIME_PAD_FACTS = List.of("oneTimePadFact1", "oneTimePadFact2", "oneTimePadFact3");
@BeforeEach
public void setup(){
- ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadName", oneTimePadName);
- ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadDescription", oneTimePadDescription);
- ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadExplanation", oneTimePadExplanation);
- ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadFacts", oneTimePadFacts);
+ ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadName", ONE_TIME_PAD_NAME);
+ ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadDescription", ONE_TIME_PAD_DESCRIPTION);
+ ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadExplanation", ONE_TIME_PAD_EXPLANATION);
+ ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadFacts", ONE_TIME_PAD_FACTS);
}
@Test
public void tetGetCipherInfo(){
- ObjectNode infoNode = CipherInfoUtil.buildInfoNode(oneTimePadName, oneTimePadDescription, oneTimePadExplanation, oneTimePadFacts);
+ ObjectNode infoNode = CipherInfoUtil.buildInfoNode(ONE_TIME_PAD_NAME, ONE_TIME_PAD_DESCRIPTION, ONE_TIME_PAD_EXPLANATION, ONE_TIME_PAD_FACTS);
ObjectNode returnedJson = oneTimePadCipherController.getCipherInfo();
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/PortaCipherControllerIntegrationTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/PortaCipherControllerIntegrationTest.java
index c7d622f..8c4855c 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/PortaCipherControllerIntegrationTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/PortaCipherControllerIntegrationTest.java
@@ -20,8 +20,6 @@ import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTe
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
-import tools.jackson.databind.node.ObjectNode;
-
@Tag("integration-test")
@WebMvcTest(controllers = PortaCipherController.class)
@@ -30,20 +28,15 @@ public class PortaCipherControllerIntegrationTest extends CipherStreamController
private MockMvc mockMvc;
@Autowired
private PortaCipherController portaCipherController;
- //Loggers
- //TODO: Fix logger testing
- //@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.PortaCipherController")
- //protected Logger portaLogger;
//Fields
- 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";
- private static final List portaExplanation = List.of("portaExplanation1", "portaExplanation2", "portaExplanation3");
- private static final List portaFacts = List.of("portaFact1", "portaFact2", "portaFact3");
+ private static final String URL = "/porta";
+ private static final String DECODED_STRING = "Message to^encode";
+ private static final String ENCODED_STRING = "Rtghuos bm^qcwgrw";
+ private static final String KEYWORD = "keyword";
+ private static final String PORTA_NAME = "portaName";
+ private static final String PORTA_DESCRIPTION = "portaDescription";
+ private static final List PORTA_EXPLANATION = List.of("portaExplanation1", "portaExplanation2", "portaExplanation3");
+ private static final List PORTA_FACTS = List.of("portaFact1", "portaFact2", "portaFact3");
@BeforeEach
@@ -52,153 +45,87 @@ public class PortaCipherControllerIntegrationTest extends CipherStreamController
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
- decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
+ decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
+ decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
encodedNode = mapper.createObjectNode();
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
- encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
+ encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
+ encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
- ReflectionTestUtils.setField(portaCipherController, "portaName", portaName);
- ReflectionTestUtils.setField(portaCipherController, "portaDescription", portaDescription);
- ReflectionTestUtils.setField(portaCipherController, "portaExplanation", portaExplanation);
- ReflectionTestUtils.setField(portaCipherController, "portaFacts", portaFacts);
+ ReflectionTestUtils.setField(portaCipherController, "portaName", PORTA_NAME);
+ ReflectionTestUtils.setField(portaCipherController, "portaDescription", PORTA_DESCRIPTION);
+ ReflectionTestUtils.setField(portaCipherController, "portaExplanation", PORTA_EXPLANATION);
+ ReflectionTestUtils.setField(portaCipherController, "portaFacts", PORTA_FACTS);
}
@Test
public void testGetCipherInfo() throws Exception{
- mockMvc.perform(get(url)
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress))
+ mockMvc.perform(get(URL)
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(portaDescription))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(portaName))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(PORTA_DESCRIPTION))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(PORTA_NAME))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(portaExplanation.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(portaExplanation.get(0), portaExplanation.get(1), portaExplanation.get(2))))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(PORTA_EXPLANATION.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(PORTA_EXPLANATION.get(0), PORTA_EXPLANATION.get(1), PORTA_EXPLANATION.get(2))))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(portaFacts.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(portaFacts.get(0), portaFacts.get(1), portaFacts.get(2))));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url);
- //Controller
- verify(portaLogger, times(1)).info("Getting info for {}", portaName);
- verifyNoMoreInteractions(portaLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
- */
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(PORTA_FACTS.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(PORTA_FACTS.get(0), PORTA_FACTS.get(1), PORTA_FACTS.get(2))));
}
@Test
public void testEncodePorta() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(decodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- verify(filterLogger, never()).info(eq("Request parameters: {}"), anyString());
- verify(mdc, times(1)).put("requestId", requestId);
- verify(mdc, times(1)).put("ip", ipAddress);
- verify(mdc, times(1)).put("url", url + "/encode");
- verify(mdc, times(1)).clear();
- //Controller
- verify(portaLogger, times(1)).info("Encoding {}", portaName);
- verifyNoMoreInteractions(portaLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
- //Cipher Aspect
- verifyAspectLogging(decodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
}
@Test
public void testEncodeAdfgvx_error() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(portaLogger, times(1)).info("Encoding {}", portaName);
- verifyNoMoreInteractions(portaLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
@Test
public void testDecodePorta() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(encodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- verify(filterLogger, never()).info(eq("Request parameters: {}"), anyString());
- verify(mdc, times(1)).put("requestId", requestId);
- verify(mdc, times(1)).put("ip", ipAddress);
- verify(mdc, times(1)).put("url", url + "/decode");
- verify(mdc, times(1)).clear();
- //Controller
- verify(portaLogger, times(1)).info("Decoding {}", portaName);
- verifyNoMoreInteractions(portaLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
- //Cipher Aspect
- verifyAspectLogging(encodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
}
@Test
public void testDecodeAdfgvx_error() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(portaLogger, times(1)).info("Decoding {}", portaName);
- verifyNoMoreInteractions(portaLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/PortaCipherControllerTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/PortaCipherControllerTest.java
index 0fc6cc7..b18f6e0 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/PortaCipherControllerTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/PortaCipherControllerTest.java
@@ -32,23 +32,23 @@ public class PortaCipherControllerTest{
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 String portaName = "portaName";
- private static final String portaDescription = "portaDescription";
- private static final List portaExplanation = List.of("portaExplanation1", "portaExplanation2", "portaExplanation3");
- private static final List portaFacts = List.of("portaFact1", "portaFact2", "portaFact3");
+ private static final String PORTA_NAME = "portaName";
+ private static final String PORTA_DESCRIPTION = "portaDescription";
+ private static final List PORTA_EXPLANATION = List.of("portaExplanation1", "portaExplanation2", "portaExplanation3");
+ private static final List PORTA_FACTS = List.of("portaFact1", "portaFact2", "portaFact3");
@BeforeEach
public void setup(){
- ReflectionTestUtils.setField(portaCipherController, "portaName", portaName);
- ReflectionTestUtils.setField(portaCipherController, "portaDescription", portaDescription);
- ReflectionTestUtils.setField(portaCipherController, "portaExplanation", portaExplanation);
- ReflectionTestUtils.setField(portaCipherController, "portaFacts", portaFacts);
+ ReflectionTestUtils.setField(portaCipherController, "portaName", PORTA_NAME);
+ ReflectionTestUtils.setField(portaCipherController, "portaDescription", PORTA_DESCRIPTION);
+ ReflectionTestUtils.setField(portaCipherController, "portaExplanation", PORTA_EXPLANATION);
+ ReflectionTestUtils.setField(portaCipherController, "portaFacts", PORTA_FACTS);
}
@Test
public void tetGetCipherInfo(){
- ObjectNode infoNode = CipherInfoUtil.buildInfoNode(portaName, portaDescription, portaExplanation, portaFacts);
+ ObjectNode infoNode = CipherInfoUtil.buildInfoNode(PORTA_NAME, PORTA_DESCRIPTION, PORTA_EXPLANATION, PORTA_FACTS);
ObjectNode returnedJson = portaCipherController.getCipherInfo();
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/SubstitutionCipherControllerIntegrationTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/SubstitutionCipherControllerIntegrationTest.java
index cb29505..ffdf222 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/SubstitutionCipherControllerIntegrationTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/SubstitutionCipherControllerIntegrationTest.java
@@ -20,8 +20,6 @@ import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTe
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
-import tools.jackson.databind.node.ObjectNode;
-
@Tag("integration-test")
@WebMvcTest(controllers = SubstitutionCipherController.class)
@@ -30,20 +28,15 @@ public class SubstitutionCipherControllerIntegrationTest extends CipherStreamCon
private MockMvc mockMvc;
@Autowired
private SubstitutionCipherController substitutionCipherController;
- //Loggers
- //TODO: Fix logger testing
- //@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.SubstitutionCipherController")
- //protected Logger substitutionLogger;
//Fields
- 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";
- private static final List substitutionExplanation = List.of("substitutionExplanation1", "substitutionExplanation2", "substitutionExplanation3");
- private static final List substitutionFacts = List.of("substitutionFact1", "substitutionFact2", "substitutionFact3");
+ private static final String URL = "/substitution";
+ private static final String DECODED_STRING = "Message to^encode";
+ private static final String ENCODED_STRING = "Oguucig vq^gpeqfg";
+ private static final String KEYWORD = "cdefghijklmnopqrstuvwxyzab";
+ private static final String SUBSTITUTION_NAME = "substitutionName";
+ private static final String SUBSTITUTION_DESCRIPTION = "substitutionDescription";
+ private static final List SUBSTITUTION_EXPLANATION = List.of("substitutionExplanation1", "substitutionExplanation2", "substitutionExplanation3");
+ private static final List SUBSTITUTION_FACTS = List.of("substitutionFact1", "substitutionFact2", "substitutionFact3");
@BeforeEach
@@ -52,145 +45,87 @@ public class SubstitutionCipherControllerIntegrationTest extends CipherStreamCon
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
- decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
+ decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
+ decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
encodedNode = mapper.createObjectNode();
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
- encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
+ encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
+ encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
- ReflectionTestUtils.setField(substitutionCipherController, "substitutionName", substitutionName);
- ReflectionTestUtils.setField(substitutionCipherController, "substitutionDescription", substitutionDescription);
- ReflectionTestUtils.setField(substitutionCipherController, "substitutionExplanation", substitutionExplanation);
- ReflectionTestUtils.setField(substitutionCipherController, "substitutionFacts", substitutionFacts);
+ ReflectionTestUtils.setField(substitutionCipherController, "substitutionName", SUBSTITUTION_NAME);
+ ReflectionTestUtils.setField(substitutionCipherController, "substitutionDescription", SUBSTITUTION_DESCRIPTION);
+ ReflectionTestUtils.setField(substitutionCipherController, "substitutionExplanation", SUBSTITUTION_EXPLANATION);
+ ReflectionTestUtils.setField(substitutionCipherController, "substitutionFacts", SUBSTITUTION_FACTS);
}
@Test
public void testGetCipherInfo() throws Exception{
- mockMvc.perform(get(url)
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress))
+ mockMvc.perform(get(URL)
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(substitutionDescription))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(substitutionName))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(SUBSTITUTION_DESCRIPTION))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(SUBSTITUTION_NAME))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(substitutionExplanation.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(substitutionExplanation.get(0), substitutionExplanation.get(1), substitutionExplanation.get(2))))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(SUBSTITUTION_EXPLANATION.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(SUBSTITUTION_EXPLANATION.get(0), SUBSTITUTION_EXPLANATION.get(1), SUBSTITUTION_EXPLANATION.get(2))))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(substitutionFacts.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(substitutionFacts.get(0), substitutionFacts.get(1), substitutionFacts.get(2))));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url);
- //Controller
- verify(substitutionLogger, times(1)).info("Getting info for {}", substitutionName);
- verifyNoMoreInteractions(substitutionLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
- */
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(SUBSTITUTION_FACTS.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(SUBSTITUTION_FACTS.get(0), SUBSTITUTION_FACTS.get(1), SUBSTITUTION_FACTS.get(2))));
}
@Test
public void testEncodeSubstitution() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(decodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(substitutionLogger, times(1)).info("Encoding {}", substitutionName);
- verifyNoMoreInteractions(substitutionLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
- //Cipher Aspect
- verifyAspectLogging(decodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
}
@Test
public void testEncodeAdfgvx_error() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(substitutionLogger, times(1)).info("Encoding {}", substitutionName);
- verifyNoMoreInteractions(substitutionLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
@Test
public void testDecodeSubstitution() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(encodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(substitutionLogger, times(1)).info("Decoding {}", substitutionName);
- verifyNoMoreInteractions(substitutionLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
- //Cipher Aspect
- verifyAspectLogging(encodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
}
@Test
public void testDecodeAdfgvx_error() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(substitutionLogger, times(1)).info("Decoding {}", substitutionName);
- verifyNoMoreInteractions(substitutionLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/SubstitutionCipherControllerTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/SubstitutionCipherControllerTest.java
index f7b42c4..c442e25 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/SubstitutionCipherControllerTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/SubstitutionCipherControllerTest.java
@@ -32,23 +32,23 @@ public class SubstitutionCipherControllerTest{
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 String substitutionName = "substitutionName";
- private static final String substitutionDescription = "substitutionDescription";
- private static final List substitutionExplanation = List.of("substitutionExplanation1", "substitutionExplanation2", "substitutionExplanation3");
- private static final List substitutionFacts = List.of("substitutionFact1", "substitutionFact2", "substitutionFact3");
+ private static final String SUBSTITUTION_NAME = "substitutionName";
+ private static final String SUBSTITUTION_DESCRIPTION = "substitutionDescription";
+ private static final List SUBSTITUTION_EXPLANATION = List.of("substitutionExplanation1", "substitutionExplanation2", "substitutionExplanation3");
+ private static final List SUBSTITUTION_FACTS = List.of("substitutionFact1", "substitutionFact2", "substitutionFact3");
@BeforeEach
public void setup(){
- ReflectionTestUtils.setField(substitutionCipherController, "substitutionName", substitutionName);
- ReflectionTestUtils.setField(substitutionCipherController, "substitutionDescription", substitutionDescription);
- ReflectionTestUtils.setField(substitutionCipherController, "substitutionExplanation", substitutionExplanation);
- ReflectionTestUtils.setField(substitutionCipherController, "substitutionFacts", substitutionFacts);
+ ReflectionTestUtils.setField(substitutionCipherController, "substitutionName", SUBSTITUTION_NAME);
+ ReflectionTestUtils.setField(substitutionCipherController, "substitutionDescription", SUBSTITUTION_DESCRIPTION);
+ ReflectionTestUtils.setField(substitutionCipherController, "substitutionExplanation", SUBSTITUTION_EXPLANATION);
+ ReflectionTestUtils.setField(substitutionCipherController, "substitutionFacts", SUBSTITUTION_FACTS);
}
@Test
public void tetGetCipherInfo(){
- ObjectNode infoNode = CipherInfoUtil.buildInfoNode(substitutionName, substitutionDescription, substitutionExplanation, substitutionFacts);
+ ObjectNode infoNode = CipherInfoUtil.buildInfoNode(SUBSTITUTION_NAME, SUBSTITUTION_DESCRIPTION, SUBSTITUTION_EXPLANATION, SUBSTITUTION_FACTS);
ObjectNode returnedJson = substitutionCipherController.getCipherInfo();
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/VigenereCipherControllerIntegrationTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/VigenereCipherControllerIntegrationTest.java
index 3aa9a11..a401881 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/VigenereCipherControllerIntegrationTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/VigenereCipherControllerIntegrationTest.java
@@ -20,8 +20,6 @@ import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTe
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
-import tools.jackson.databind.node.ObjectNode;
-
@Tag("integration-test")
@WebMvcTest(controllers = VigenereCipherController.class)
@@ -30,20 +28,15 @@ public class VigenereCipherControllerIntegrationTest extends CipherStreamControl
private MockMvc mockMvc;
@Autowired
private VigenereCipherController vigenereCipherController;
- //Loggers
- //TODO: Fix logger testing
- //@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.VigenereCipherController")
- //protected Logger vigenereLogger;
//Fields
- 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";
- private static final List vigenereExplanation = List.of("vigenereExplanation1", "vigenereExplanation2", "vigenereExplanation3");
- private static final List vigenereFacts = List.of("vigenereFact1", "vigenereFact2", "vigenereFact3");
+ private static final String URL = "/vigenere";
+ private static final String DECODED_STRING = "Message to^encode";
+ private static final String ENCODED_STRING = "Wiqooxh ds^cjqfgo";
+ private static final String KEYWORD = "keyword";
+ private static final String VIGENERE_NAME = "vigenereName";
+ private static final String VIGENERE_DESCRIPTION = "vigenereDescription";
+ private static final List VIGENERE_EXPLANATION = List.of("vigenereExplanation1", "vigenereExplanation2", "vigenereExplanation3");
+ private static final List VIGENERE_FACTS = List.of("vigenereFact1", "vigenereFact2", "vigenereFact3");
@BeforeEach
@@ -52,145 +45,87 @@ public class VigenereCipherControllerIntegrationTest extends CipherStreamControl
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
- decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
+ decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
+ decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
encodedNode = mapper.createObjectNode();
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
- encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
+ encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
+ encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
- ReflectionTestUtils.setField(vigenereCipherController, "vigenereName", vigenereName);
- ReflectionTestUtils.setField(vigenereCipherController, "vigenereDescription", vigenereDescription);
- ReflectionTestUtils.setField(vigenereCipherController, "vigenereExplanation", vigenereExplanation);
- ReflectionTestUtils.setField(vigenereCipherController, "vigenereFacts", vigenereFacts);
+ ReflectionTestUtils.setField(vigenereCipherController, "vigenereName", VIGENERE_NAME);
+ ReflectionTestUtils.setField(vigenereCipherController, "vigenereDescription", VIGENERE_DESCRIPTION);
+ ReflectionTestUtils.setField(vigenereCipherController, "vigenereExplanation", VIGENERE_EXPLANATION);
+ ReflectionTestUtils.setField(vigenereCipherController, "vigenereFacts", VIGENERE_FACTS);
}
@Test
public void testGetCipherInfo() throws Exception{
- mockMvc.perform(get(url)
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress))
+ mockMvc.perform(get(URL)
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(vigenereDescription))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(vigenereName))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(VIGENERE_DESCRIPTION))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(VIGENERE_NAME))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(vigenereExplanation.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(vigenereExplanation.get(0), vigenereExplanation.get(1), vigenereExplanation.get(2))))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(VIGENERE_EXPLANATION.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(VIGENERE_EXPLANATION.get(0), VIGENERE_EXPLANATION.get(1), VIGENERE_EXPLANATION.get(2))))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(vigenereFacts.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(vigenereFacts.get(0), vigenereFacts.get(1), vigenereFacts.get(2))));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url);
- //Controller
- verify(vigenereLogger, times(1)).info("Getting info for {}", vigenereName);
- verifyNoMoreInteractions(vigenereLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
- */
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(VIGENERE_FACTS.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(VIGENERE_FACTS.get(0), VIGENERE_FACTS.get(1), VIGENERE_FACTS.get(2))));
}
@Test
public void testEncodeVigenere() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(decodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(vigenereLogger, times(1)).info("Encoding {}", vigenereName);
- verifyNoMoreInteractions(vigenereLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
- //Cipher Aspect
- verifyAspectLogging(decodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
}
@Test
public void testEncodeAdfgvx_error() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(vigenereLogger, times(1)).info("Encoding {}", vigenereName);
- verifyNoMoreInteractions(vigenereLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
@Test
public void testDecodeVigenere() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(encodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(vigenereLogger, times(1)).info("Decoding {}", vigenereName);
- verifyNoMoreInteractions(vigenereLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
- //Cipher Aspect
- verifyAspectLogging(encodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
}
@Test
public void testDecodeAdfgvx_error() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(vigenereLogger, times(1)).info("Decoding {}", vigenereName);
- verifyNoMoreInteractions(vigenereLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/VigenereCipherControllerTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/VigenereCipherControllerTest.java
index 54aacde..cf46d7b 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/VigenereCipherControllerTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/monosubstitution/VigenereCipherControllerTest.java
@@ -32,23 +32,23 @@ public class VigenereCipherControllerTest{
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 String vigenereName = "vigenereName";
- private static final String vigenereDescription = "vigenereDescription";
- private static final List vigenereExplanation = List.of("vigenereExplanation1", "vigenereExplanation2", "vigenereExplanation3");
- private static final List vigenereFacts = List.of("vigenereFact1", "vigenereFact2", "vigenereFact3");
+ private static final String VIGENERE_NAME = "vigenereName";
+ private static final String VIGENERE_DESCRIPTION = "vigenereDescription";
+ private static final List VIGENERE_EXPLANATION = List.of("vigenereExplanation1", "vigenereExplanation2", "vigenereExplanation3");
+ private static final List VIGENERE_FACTS = List.of("vigenereFact1", "vigenereFact2", "vigenereFact3");
@BeforeEach
public void setup(){
- ReflectionTestUtils.setField(vigenereCipherController, "vigenereName", vigenereName);
- ReflectionTestUtils.setField(vigenereCipherController, "vigenereDescription", vigenereDescription);
- ReflectionTestUtils.setField(vigenereCipherController, "vigenereExplanation", vigenereExplanation);
- ReflectionTestUtils.setField(vigenereCipherController, "vigenereFacts", vigenereFacts);
+ ReflectionTestUtils.setField(vigenereCipherController, "vigenereName", VIGENERE_NAME);
+ ReflectionTestUtils.setField(vigenereCipherController, "vigenereDescription", VIGENERE_DESCRIPTION);
+ ReflectionTestUtils.setField(vigenereCipherController, "vigenereExplanation", VIGENERE_EXPLANATION);
+ ReflectionTestUtils.setField(vigenereCipherController, "vigenereFacts", VIGENERE_FACTS);
}
@Test
public void tetGetCipherInfo(){
- ObjectNode infoNode = CipherInfoUtil.buildInfoNode(vigenereName, vigenereDescription, vigenereExplanation, vigenereFacts);
+ ObjectNode infoNode = CipherInfoUtil.buildInfoNode(VIGENERE_NAME, VIGENERE_DESCRIPTION, VIGENERE_EXPLANATION, VIGENERE_FACTS);
ObjectNode returnedJson = vigenereCipherController.getCipherInfo();
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/BifidCipherControllerIntegrationTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/BifidCipherControllerIntegrationTest.java
index 0f95663..66bb6ed 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/BifidCipherControllerIntegrationTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/BifidCipherControllerIntegrationTest.java
@@ -20,8 +20,6 @@ import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTe
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
-import tools.jackson.databind.node.ObjectNode;
-
@Tag("integration-test")
@WebMvcTest(controllers = BifidCipherController.class)
@@ -30,20 +28,15 @@ public class BifidCipherControllerIntegrationTest extends CipherStreamController
private MockMvc mockMvc;
@Autowired
private BifidCipherController bifidCipherController;
- //Loggers
- //TODO: Fix logger testing
- //@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.BifidCipherController")
- //protected Logger bifidLogger;
//Fields
- private static final ObjectNode blankNode = mapper.createObjectNode();
- private static final String url = "/bifid";
- private static final String decodedString = "Message to^encode";
- private static final String encodedString = "Mqaokne kc^vdodzd";
- private static final String keyword = "keyword";
- private static final String bifidName = "bifidName";
- private static final String bifidDescription = "bifidDescription";
- private static final List bifidExplanation = List.of("bifidExplanation1", "bifidExplanation2", "bifidExplanation3");
- private static final List bifidFacts = List.of("bifidFact1", "bifidFact2", "bifidFact3");
+ private static final String URL = "/bifid";
+ private static final String DECODED_STRING = "Message to^encode";
+ private static final String ENCODED_STRING = "Mqaokne kc^vdodzd";
+ private static final String KEYWORD = "keyword";
+ private static final String BIFID_NAME = "bifidName";
+ private static final String BIFID_DESCRIPTION = "bifidDescription";
+ private static final List BIFID_EXPLANATION = List.of("bifidExplanation1", "bifidExplanation2", "bifidExplanation3");
+ private static final List BIFID_FACTS = List.of("bifidFact1", "bifidFact2", "bifidFact3");
@BeforeEach
@@ -52,145 +45,87 @@ public class BifidCipherControllerIntegrationTest extends CipherStreamController
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
- decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
+ decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
+ decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
encodedNode = mapper.createObjectNode();
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
- encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
+ encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
+ encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
- ReflectionTestUtils.setField(bifidCipherController, "bifidName", bifidName);
- ReflectionTestUtils.setField(bifidCipherController, "bifidDescription", bifidDescription);
- ReflectionTestUtils.setField(bifidCipherController, "bifidExplanation", bifidExplanation);
- ReflectionTestUtils.setField(bifidCipherController, "bifidFacts", bifidFacts);
+ ReflectionTestUtils.setField(bifidCipherController, "bifidName", BIFID_NAME);
+ ReflectionTestUtils.setField(bifidCipherController, "bifidDescription", BIFID_DESCRIPTION);
+ ReflectionTestUtils.setField(bifidCipherController, "bifidExplanation", BIFID_EXPLANATION);
+ ReflectionTestUtils.setField(bifidCipherController, "bifidFacts", BIFID_FACTS);
}
@Test
public void testGetCipherInfo() throws Exception{
- mockMvc.perform(get(url)
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress))
+ mockMvc.perform(get(URL)
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(bifidName))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(bifidDescription))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(BIFID_NAME))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(BIFID_DESCRIPTION))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(bifidExplanation.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(bifidExplanation.get(0), bifidExplanation.get(1), bifidExplanation.get(2))))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(BIFID_EXPLANATION.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(BIFID_EXPLANATION.get(0), BIFID_EXPLANATION.get(1), BIFID_EXPLANATION.get(2))))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(bifidFacts.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(bifidFacts.get(0), bifidFacts.get(1), bifidFacts.get(2))));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url);
- //Controller
- verify(bifidLogger, times(1)).info("Getting info for {}", bifidName);
- verifyNoMoreInteractions(bifidLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, bifidName);
- */
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(BIFID_FACTS.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(BIFID_FACTS.get(0), BIFID_FACTS.get(1), BIFID_FACTS.get(2))));
}
@Test
public void testEncodeBifid() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(decodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(bifidLogger, times(1)).info("Encoding {}", bifidName);
- verifyNoMoreInteractions(bifidLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, bifidName);
- //Cipher Aspect
- verifyAspectLogging(decodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
}
@Test
public void testEncodebifid_error() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(bifidLogger, times(1)).info("Encoding {}", bifidName);
- verifyNoMoreInteractions(bifidLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, bifidName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
@Test
public void testDecodeBifid() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(encodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(bifidLogger, times(1)).info("Decoding {}", bifidName);
- verifyNoMoreInteractions(bifidLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, bifidName);
- //Cipher Aspect
- verifyAspectLogging(encodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
}
@Test
public void testDecodebifid_error() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(bifidLogger, times(1)).info("Decoding {}", bifidName);
- verifyNoMoreInteractions(bifidLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, bifidName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/BifidCipherControllerTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/BifidCipherControllerTest.java
index 44a5ce1..112292b 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/BifidCipherControllerTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/BifidCipherControllerTest.java
@@ -32,23 +32,23 @@ public class BifidCipherControllerTest{
private static final String BIFID_INPUT_STRING = "Message to^encode";
private static final String BIFID_OUTPUT_STRING = "Mqaokne kc^vdodzd";
private static final String BIFID_KEYWORD = CipherParameterUtil.KEYWORD;
- private static final String bifidName = "bifidName";
- private static final String bifidDescription = "bifidDescription";
- private static final List bifidExplanation = List.of("bifidExplanation1", "bifidExplanation2", "bifidExplanation3");
- private static final List bifidFacts = List.of("bifidFact1", "bifidFact2", "bifidFact3");
+ private static final String BIFID_NAME = "bifidName";
+ private static final String BIFID_DESCRIPTION = "bifidDescription";
+ private static final List BIFID_EXPLANATION = List.of("bifidExplanation1", "bifidExplanation2", "bifidExplanation3");
+ private static final List BIFID_FACTS = List.of("bifidFact1", "bifidFact2", "bifidFact3");
@BeforeEach
public void setup(){
- ReflectionTestUtils.setField(bifidCipherController, "bifidName", bifidName);
- ReflectionTestUtils.setField(bifidCipherController, "bifidDescription", bifidDescription);
- ReflectionTestUtils.setField(bifidCipherController, "bifidExplanation", bifidExplanation);
- ReflectionTestUtils.setField(bifidCipherController, "bifidFacts", bifidFacts);
+ ReflectionTestUtils.setField(bifidCipherController, "bifidName", BIFID_NAME);
+ ReflectionTestUtils.setField(bifidCipherController, "bifidDescription", BIFID_DESCRIPTION);
+ ReflectionTestUtils.setField(bifidCipherController, "bifidExplanation", BIFID_EXPLANATION);
+ ReflectionTestUtils.setField(bifidCipherController, "bifidFacts", BIFID_FACTS);
}
@Test
public void tetGetCipherInfo(){
- ObjectNode infoNode = CipherInfoUtil.buildInfoNode(bifidName, bifidDescription, bifidExplanation, bifidFacts);
+ ObjectNode infoNode = CipherInfoUtil.buildInfoNode(BIFID_NAME, BIFID_DESCRIPTION, BIFID_EXPLANATION, BIFID_FACTS);
ObjectNode returnedJson = bifidCipherController.getCipherInfo();
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/ColumnarCipherControllerIntegrationTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/ColumnarCipherControllerIntegrationTest.java
index 21cd359..2cdbda2 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/ColumnarCipherControllerIntegrationTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/ColumnarCipherControllerIntegrationTest.java
@@ -20,8 +20,6 @@ import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTe
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
-import tools.jackson.databind.node.ObjectNode;
-
@Tag("integration-test")
@WebMvcTest(controllers = ColumnarCipherController.class)
@@ -30,20 +28,15 @@ public class ColumnarCipherControllerIntegrationTest extends CipherStreamControl
private MockMvc mockMvc;
@Autowired
private ColumnarCipherController columnarCipherController;
- //Loggers
- //TODO: Fix logger testing
- //@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.ColumnarCipherController")
- //protected Logger columnarLogger;
//Fields
- private static final ObjectNode blankNode = mapper.createObjectNode();
- private static final String url = "/columnar";
- private static final String decodedString = "Message to^encode";
- private static final String encodedString = "Edeomte ac^gosnse";
- private static final String keyword = "keyword";
- private static final String columnarName = "columnarName";
- private static final String columnarDescription = "columnarDescription";
- private static final List columnarExplanation = List.of("columnarExplanation1", "columnarExplanation2", "columnarExplanation3");
- private static final List columnarFacts = List.of("columnarFact1", "columnarFact2", "columnarFact3");
+ private static final String URL = "/columnar";
+ private static final String DECODED_STRING = "Message to^encode";
+ private static final String ENCODED_STRING = "Edeomte ac^gosnse";
+ private static final String KEYWORD = "keyword";
+ private static final String COLUMNAR_NAME = "columnarName";
+ private static final String COLUMNAR_DESCRIPTION = "columnarDescription";
+ private static final List COLUMNAR_EXPLANATION = List.of("columnarExplanation1", "columnarExplanation2", "columnarExplanation3");
+ private static final List COLUMNAR_FACTS = List.of("columnarFact1", "columnarFact2", "columnarFact3");
@BeforeEach
@@ -52,145 +45,87 @@ public class ColumnarCipherControllerIntegrationTest extends CipherStreamControl
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
- decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
+ decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
+ decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
encodedNode = mapper.createObjectNode();
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
- encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
+ encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
+ encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
- ReflectionTestUtils.setField(columnarCipherController, "columnarName", columnarName);
- ReflectionTestUtils.setField(columnarCipherController, "columnarDescription", columnarDescription);
- ReflectionTestUtils.setField(columnarCipherController, "columnarExplanation", columnarExplanation);
- ReflectionTestUtils.setField(columnarCipherController, "columnarFacts", columnarFacts);
+ ReflectionTestUtils.setField(columnarCipherController, "columnarName", COLUMNAR_NAME);
+ ReflectionTestUtils.setField(columnarCipherController, "columnarDescription", COLUMNAR_DESCRIPTION);
+ ReflectionTestUtils.setField(columnarCipherController, "columnarExplanation", COLUMNAR_EXPLANATION);
+ ReflectionTestUtils.setField(columnarCipherController, "columnarFacts", COLUMNAR_FACTS);
}
@Test
public void testGetCipherInfo() throws Exception{
- mockMvc.perform(get(url)
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress))
+ mockMvc.perform(get(URL)
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(columnarName))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(columnarDescription))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(COLUMNAR_NAME))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(COLUMNAR_DESCRIPTION))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(columnarExplanation.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(columnarExplanation.get(0), columnarExplanation.get(1), columnarExplanation.get(2))))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(COLUMNAR_EXPLANATION.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(COLUMNAR_EXPLANATION.get(0), COLUMNAR_EXPLANATION.get(1), COLUMNAR_EXPLANATION.get(2))))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(columnarFacts.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(columnarFacts.get(0), columnarFacts.get(1), columnarFacts.get(2))));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url);
- //Controller
- verify(columnarLogger, times(1)).info("Getting info for {}", columnarName);
- verifyNoMoreInteractions(columnarLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, columnarName);
- */
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(COLUMNAR_FACTS.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(COLUMNAR_FACTS.get(0), COLUMNAR_FACTS.get(1), COLUMNAR_FACTS.get(2))));
}
@Test
public void testEncodeColumnar() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(decodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(columnarLogger, times(1)).info("Encoding {}", columnarName);
- verifyNoMoreInteractions(columnarLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, columnarName);
- //Cipher Aspect
- verifyAspectLogging(decodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
}
@Test
public void testEncodecolumnar_error() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(columnarLogger, times(1)).info("Encoding {}", columnarName);
- verifyNoMoreInteractions(columnarLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, columnarName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
@Test
public void testDecodeColumnar() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(encodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(columnarLogger, times(1)).info("Decoding {}", columnarName);
- verifyNoMoreInteractions(columnarLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, columnarName);
- //Cipher Aspect
- verifyAspectLogging(encodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
}
@Test
public void testDecodecolumnar_error() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(columnarLogger, times(1)).info("Decoding {}", columnarName);
- verifyNoMoreInteractions(columnarLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, columnarName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/ColumnarCipherControllerTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/ColumnarCipherControllerTest.java
index 64679cd..8ce8808 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/ColumnarCipherControllerTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/ColumnarCipherControllerTest.java
@@ -32,24 +32,24 @@ public class ColumnarCipherControllerTest{
private static final String COLUMNAR_INPUT_STRING = "Message to*encode";
private static final String COLUMNAR_OUTPUT_STRING = "Edeomte ac*gosnse";
private static final String COLUMNAR_KEYWORD = CipherParameterUtil.KEYWORD;
- private static final String columnarName = "columnarName";
- private static final String columnarDescription = "columnarDescription";
- private static final List columnarExplanation = List.of("columnarExplanation1", "columnarExplanation2", "columnarExplanation3");
- private static final List columnarFacts = List.of("columnarFact1", "columnarFact2", "columnarFact3");
+ private static final String COLUMNAR_NAME = "columnarName";
+ private static final String COLUMNAR_DESCRIPTION = "columnarDescription";
+ private static final List COLUMNAR_EXPLANATION = List.of("columnarExplanation1", "columnarExplanation2", "columnarExplanation3");
+ private static final List COLUMNAR_FACTS = List.of("columnarFact1", "columnarFact2", "columnarFact3");
@BeforeEach
public void setup(){
- ReflectionTestUtils.setField(columnarCipherController, "columnarName", columnarName);
- ReflectionTestUtils.setField(columnarCipherController, "columnarDescription", columnarDescription);
- ReflectionTestUtils.setField(columnarCipherController, "columnarExplanation", columnarExplanation);
- ReflectionTestUtils.setField(columnarCipherController, "columnarFacts", columnarFacts);
+ ReflectionTestUtils.setField(columnarCipherController, "columnarName", COLUMNAR_NAME);
+ ReflectionTestUtils.setField(columnarCipherController, "columnarDescription", COLUMNAR_DESCRIPTION);
+ ReflectionTestUtils.setField(columnarCipherController, "columnarExplanation", COLUMNAR_EXPLANATION);
+ ReflectionTestUtils.setField(columnarCipherController, "columnarFacts", COLUMNAR_FACTS);
}
@Test
public void tetGetCipherInfo(){
- ObjectNode infoNode = CipherInfoUtil.buildInfoNode(columnarName, columnarDescription, columnarExplanation, columnarFacts);
+ ObjectNode infoNode = CipherInfoUtil.buildInfoNode(COLUMNAR_NAME, COLUMNAR_DESCRIPTION, COLUMNAR_EXPLANATION, COLUMNAR_FACTS);
ObjectNode returnedJson = columnarCipherController.getCipherInfo();
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/HillCipherControllerIntegrationTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/HillCipherControllerIntegrationTest.java
index e3c03e2..085bcb1 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/HillCipherControllerIntegrationTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/HillCipherControllerIntegrationTest.java
@@ -20,8 +20,6 @@ import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTe
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
-import tools.jackson.databind.node.ObjectNode;
-
@Tag("integration-test")
@WebMvcTest(controllers = HillCipherController.class)
@@ -30,20 +28,15 @@ public class HillCipherControllerIntegrationTest extends CipherStreamControllerI
private MockMvc mockMvc;
@Autowired
private HillCipherController hillCipherController;
- //Loggers
- //TODO: Fix logger testing
- //@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.HillCipherController")
- //protected Logger hillLogger;
//Fields
- private static final ObjectNode blankNode = mapper.createObjectNode();
- private static final String url = "/hill";
- private static final String decodedString = "Message to^encoded";
- private static final String encodedString = "Mgkeqge ul^ikhisplrd";
- private static final int[][] keyArray = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
- private static final String hillName = "hillName";
- private static final String hillDescription = "hillDescription";
- private static final List hillExplanation = List.of("hillExplanation1", "hillExplanation2", "hillExplanation3");
- private static final List hillFacts = List.of("hillFact1", "hillFact2", "hillFact3");
+ private static final String URL = "/hill";
+ private static final String DECODED_STRING = "Message to^encoded";
+ private static final String ENCODED_STRING = "Mgkeqge ul^ikhisplrd";
+ private static final int[][] KEY_ARRAY = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
+ private static final String HILL_NAME = "hillName";
+ private static final String HILL_DESCRIPTION = "hillDescription";
+ private static final List HILL_EXPLANATION = List.of("hillExplanation1", "hillExplanation2", "hillExplanation3");
+ private static final List HILL_FACTS = List.of("hillFact1", "hillFact2", "hillFact3");
@BeforeEach
@@ -52,145 +45,87 @@ public class HillCipherControllerIntegrationTest extends CipherStreamControllerI
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- decodedNode.set(CipherParameterUtil.HILL_KEY, mapper.valueToTree(keyArray));
- decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
- decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
+ decodedNode.set(CipherParameterUtil.HILL_KEY, mapper.valueToTree(KEY_ARRAY));
+ decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
+ decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
encodedNode = mapper.createObjectNode();
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- encodedNode.set(CipherParameterUtil.HILL_KEY, mapper.valueToTree(keyArray));
- encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
- encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString + "xx");
+ encodedNode.set(CipherParameterUtil.HILL_KEY, mapper.valueToTree(KEY_ARRAY));
+ encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
+ encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING + "xx");
- ReflectionTestUtils.setField(hillCipherController, "hillName", hillName);
- ReflectionTestUtils.setField(hillCipherController, "hillDescription", hillDescription);
- ReflectionTestUtils.setField(hillCipherController, "hillExplanation", hillExplanation);
- ReflectionTestUtils.setField(hillCipherController, "hillFacts", hillFacts);
+ ReflectionTestUtils.setField(hillCipherController, "hillName", HILL_NAME);
+ ReflectionTestUtils.setField(hillCipherController, "hillDescription", HILL_DESCRIPTION);
+ ReflectionTestUtils.setField(hillCipherController, "hillExplanation", HILL_EXPLANATION);
+ ReflectionTestUtils.setField(hillCipherController, "hillFacts", HILL_FACTS);
}
@Test
public void testGetCipherInfo() throws Exception{
- mockMvc.perform(get(url)
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress))
+ mockMvc.perform(get(URL)
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(hillName))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(hillDescription))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(HILL_NAME))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(HILL_DESCRIPTION))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(hillExplanation.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(hillExplanation.get(0), hillExplanation.get(1), hillExplanation.get(2))))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(HILL_EXPLANATION.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(HILL_EXPLANATION.get(0), HILL_EXPLANATION.get(1), HILL_EXPLANATION.get(2))))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(hillFacts.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(hillFacts.get(0), hillFacts.get(1), hillFacts.get(2))));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url);
- //Controller
- verify(hillLogger, times(1)).info("Getting info for {}", hillName);
- verifyNoMoreInteractions(hillLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
- */
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(HILL_FACTS.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(HILL_FACTS.get(0), HILL_FACTS.get(1), HILL_FACTS.get(2))));
}
@Test
public void testEncodeHill() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(decodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(hillLogger, times(1)).info("Encoding {}", hillName);
- verifyNoMoreInteractions(hillLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
- //Cipher Aspect
- verifyAspectLogging(decodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
}
@Test
public void testEncodehill_error() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(hillLogger, times(1)).info("Encoding {}", hillName);
- verifyNoMoreInteractions(hillLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
@Test
public void testDecodeHill() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(encodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString + "xx"));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(hillLogger, times(1)).info("Decoding {}", hillName);
- verifyNoMoreInteractions(hillLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
- //Cipher Aspect
- verifyAspectLogging(encodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING + "xx"));
}
@Test
public void testDecodehill_error() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(hillLogger, times(1)).info("Decoding {}", hillName);
- verifyNoMoreInteractions(hillLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/HillCipherControllerTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/HillCipherControllerTest.java
index ad867a8..c8d63e7 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/HillCipherControllerTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/HillCipherControllerTest.java
@@ -33,24 +33,24 @@ public class HillCipherControllerTest{
private static final String HILL_INPUT_STRING = "Message to^encode";
private static final String HILL_OUTPUT_STRING = "Mgkeqge ul^ikhisp";
private static final int[][] KEY = {{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
- private static final String hillName = "hillName";
- private static final String hillDescription = "hillDescription";
- private static final List hillExplanation = List.of("hillExplanation1", "hillExplanation2", "hillExplanation3");
- private static final List hillFacts = List.of("hillFact1", "hillFact2", "hillFact3");
+ private static final String HILL_NAME = "hillName";
+ private static final String HILL_DESCRIPTION = "hillDescription";
+ private static final List HILL_EXPLANATION = List.of("hillExplanation1", "hillExplanation2", "hillExplanation3");
+ private static final List HILL_FACTS = List.of("hillFact1", "hillFact2", "hillFact3");
@BeforeEach
public void setup(){
- ReflectionTestUtils.setField(hillCipherController, "hillName", hillName);
- ReflectionTestUtils.setField(hillCipherController, "hillDescription", hillDescription);
- ReflectionTestUtils.setField(hillCipherController, "hillExplanation", hillExplanation);
- ReflectionTestUtils.setField(hillCipherController, "hillFacts", hillFacts);
+ ReflectionTestUtils.setField(hillCipherController, "hillName", HILL_NAME);
+ ReflectionTestUtils.setField(hillCipherController, "hillDescription", HILL_DESCRIPTION);
+ ReflectionTestUtils.setField(hillCipherController, "hillExplanation", HILL_EXPLANATION);
+ ReflectionTestUtils.setField(hillCipherController, "hillFacts", HILL_FACTS);
}
@Test
public void tetGetCipherInfo(){
- ObjectNode infoNode = CipherInfoUtil.buildInfoNode(hillName, hillDescription, hillExplanation, hillFacts);
+ ObjectNode infoNode = CipherInfoUtil.buildInfoNode(HILL_NAME, HILL_DESCRIPTION, HILL_EXPLANATION, HILL_FACTS);
ObjectNode returnedJson = hillCipherController.getCipherInfo();
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/MorseCodeControllerIntegrationTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/MorseCodeControllerIntegrationTest.java
index 29d7a34..70c7557 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/MorseCodeControllerIntegrationTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/MorseCodeControllerIntegrationTest.java
@@ -20,8 +20,6 @@ import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTe
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
-import tools.jackson.databind.node.ObjectNode;
-
@Tag("integration-test")
@WebMvcTest(controllers = MorseCodeController.class)
@@ -30,157 +28,94 @@ public class MorseCodeControllerIntegrationTest extends CipherStreamControllerIn
private MockMvc mockMvc;
@Autowired
private MorseCodeController morseCodeController;
- //Loggers
- //TODO: Fix logger testing
- //@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.MorseCodeController")
- //protected Logger morseLogger;
//Fields
- private static final ObjectNode blankNode = mapper.createObjectNode();
- private static final String url = "/morse";
- private static final String decodedString = "Message to^encode123";
- private static final String encodedString = "-- . ... ... .- --. . - --- . -. -.-. --- -.. . .---- ..--- ...--";
- private static final String morseName = "morseName";
- private static final String morseDescription = "morseDescription";
- private static final List morseExplanation = List.of("morseExplanation1", "morseExplanation2", "morseExplanation3");
- private static final List morseFacts = List.of("morseFact1", "morseFact2", "morseFact3");
+ private static final String URL = "/morse";
+ private static final String DECODED_STRING = "Message to^encode123";
+ private static final String ENCODED_STRING = "-- . ... ... .- --. . - --- . -. -.-. --- -.. . .---- ..--- ...--";
+ private static final String MORSE_NAME = "morseName";
+ private static final String MORSE_DESCRIPTION = "morseDescription";
+ private static final List MORSE_EXPLANATION = List.of("morseExplanation1", "morseExplanation2", "morseExplanation3");
+ private static final List MORSE_FACTS = List.of("morseFact1", "morseFact2", "morseFact3");
@BeforeEach
public void setup(){
decodedNode = mapper.createObjectNode();
- decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
- decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
+ decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
+ decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
encodedNode = mapper.createObjectNode();
- encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
- encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString.toUpperCase().replaceAll("[^A-Z0-9]", ""));
+ encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
+ encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING.toUpperCase().replaceAll("[^A-Z0-9]", ""));
- ReflectionTestUtils.setField(morseCodeController, "morseName", morseName);
- ReflectionTestUtils.setField(morseCodeController, "morseDescription", morseDescription);
- ReflectionTestUtils.setField(morseCodeController, "morseExplanation", morseExplanation);
- ReflectionTestUtils.setField(morseCodeController, "morseFacts", morseFacts);
+ ReflectionTestUtils.setField(morseCodeController, "morseName", MORSE_NAME);
+ ReflectionTestUtils.setField(morseCodeController, "morseDescription", MORSE_DESCRIPTION);
+ ReflectionTestUtils.setField(morseCodeController, "morseExplanation", MORSE_EXPLANATION);
+ ReflectionTestUtils.setField(morseCodeController, "morseFacts", MORSE_FACTS);
}
@Test
public void testGetCipherInfo() throws Exception{
- mockMvc.perform(get(url)
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress))
+ mockMvc.perform(get(URL)
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(morseName))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(morseDescription))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(MORSE_NAME))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(MORSE_DESCRIPTION))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(morseExplanation.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(morseExplanation.get(0), morseExplanation.get(1), morseExplanation.get(2))))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(MORSE_EXPLANATION.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(MORSE_EXPLANATION.get(0), MORSE_EXPLANATION.get(1), MORSE_EXPLANATION.get(2))))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(morseFacts.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(morseFacts.get(0), morseFacts.get(1), morseFacts.get(2))));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url);
- //Controller
- verify(morseLogger, times(1)).info("Getting info for {}", morseName);
- verifyNoMoreInteractions(morseLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, morseName);
- */
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(MORSE_FACTS.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(MORSE_FACTS.get(0), MORSE_FACTS.get(1), MORSE_FACTS.get(2))));
}
@Test
public void testEncodeMorse() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(decodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(morseLogger, times(1)).info("Encoding {}", morseName);
- verifyNoMoreInteractions(morseLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, morseName);
- //Cipher Aspect
- verifyAspectLogging(decodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
}
@Test
public void testEncodemorse_error() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.INPUT_STRING + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(morseLogger, times(1)).info("Encoding {}", morseName);
- verifyNoMoreInteractions(morseLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, morseName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
@Test
public void testDecodeMorse() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(encodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString.toUpperCase().replaceAll("[^A-Z0-9]", "")));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(morseLogger, times(1)).info("Decoding {}", morseName);
- verifyNoMoreInteractions(morseLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, morseName);
- //Cipher Aspect
- verifyAspectLogging(encodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING.toUpperCase().replaceAll("[^A-Z0-9]", "")));
}
@Test
public void testDecodemorse_error() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.INPUT_STRING + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(morseLogger, times(1)).info("Decoding {}", morseName);
- verifyNoMoreInteractions(morseLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, morseName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/MorseCodeControllerTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/MorseCodeControllerTest.java
index cd28eba..3ed3336 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/MorseCodeControllerTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/MorseCodeControllerTest.java
@@ -31,24 +31,24 @@ public class MorseCodeControllerTest{
private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String MORSE_INPUT_STRING = "SOS";
private static final String MORSE_OUTPUT_STRING = "... --- ...";
- private static final String morseName = "morseName";
- private static final String morseDescription = "morseDescription";
- private static final List morseExplanation = List.of("morseExplanation1", "morseExplanation2", "morseExplanation3");
- private static final List morseFacts = List.of("morseFact1", "morseFact2", "morseFact3");
+ private static final String MORSE_NAME = "morseName";
+ private static final String MORSE_DESCRIPTION = "morseDescription";
+ private static final List MORSE_EXPLANATION = List.of("morseExplanation1", "morseExplanation2", "morseExplanation3");
+ private static final List MORSE_FACTS = List.of("morseFact1", "morseFact2", "morseFact3");
@BeforeEach
public void setup(){
- ReflectionTestUtils.setField(morseCodeController, "morseName", morseName);
- ReflectionTestUtils.setField(morseCodeController, "morseDescription", morseDescription);
- ReflectionTestUtils.setField(morseCodeController, "morseExplanation", morseExplanation);
- ReflectionTestUtils.setField(morseCodeController, "morseFacts", morseFacts);
+ ReflectionTestUtils.setField(morseCodeController, "morseName", MORSE_NAME);
+ ReflectionTestUtils.setField(morseCodeController, "morseDescription", MORSE_DESCRIPTION);
+ ReflectionTestUtils.setField(morseCodeController, "morseExplanation", MORSE_EXPLANATION);
+ ReflectionTestUtils.setField(morseCodeController, "morseFacts", MORSE_FACTS);
}
@Test
public void tetGetCipherInfo(){
- ObjectNode infoNode = CipherInfoUtil.buildInfoNode(morseName, morseDescription, morseExplanation, morseFacts);
+ ObjectNode infoNode = CipherInfoUtil.buildInfoNode(MORSE_NAME, MORSE_DESCRIPTION, MORSE_EXPLANATION, MORSE_FACTS);
ObjectNode returnedJson = morseCodeController.getCipherInfo();
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/PlayfairCipherControllerIntegrationTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/PlayfairCipherControllerIntegrationTest.java
index 40ef6f3..e007b4d 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/PlayfairCipherControllerIntegrationTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/PlayfairCipherControllerIntegrationTest.java
@@ -20,8 +20,6 @@ import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTe
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
-import tools.jackson.databind.node.ObjectNode;
-
@Tag("integration-test")
@WebMvcTest(controllers = PlayfairCipherController.class)
@@ -30,21 +28,16 @@ public class PlayfairCipherControllerIntegrationTest extends CipherStreamControl
private MockMvc mockMvc;
@Autowired
private PlayfairCipherController playfairCipherController;
- //Loggers
- //TODO: Fix logger testing
- //@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.PlayfairCipherController")
- //protected Logger playfairLogger;
//Fields
- private static final ObjectNode blankNode = mapper.createObjectNode();
- private static final String url = "/playfair";
- private static final String decodedString = "Hide the gold in - the@tree+stump";
- private static final String decodedStringPadded = "Hide the gold in - the@trexe+stump";
- private static final String encodedString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
- private static final String keyword = "Play-fair@Exam ple";
- private static final String playfairName = "playfairName";
- private static final String playfairDescription = "playfairDescription";
- private static final List playfairExplanation = List.of("playfairExplanation1", "playfairExplanation2", "playfairExplanation3");
- private static final List playfairFacts = List.of("playfairFact1", "playfairFact2", "playfairFact3");
+ private static final String URL = "/playfair";
+ private static final String DECODED_STRING = "Hide the gold in - the@tree+stump";
+ private static final String DECODED_STRING_PADDED = "Hide the gold in - the@trexe+stump";
+ private static final String ENCODED_STRING = "Bmod zbx dnab ek - udm@uixmm+ouvif";
+ private static final String KEYWORD = "Play-fair@Exam ple";
+ private static final String PLAYFAIR_NAME = "playfairName";
+ private static final String PLAYFAIR_DESCRIPTION = "playfairDescription";
+ private static final List PLAYFAIR_EXPLANATION = List.of("playfairExplanation1", "playfairExplanation2", "playfairExplanation3");
+ private static final List PLAYFAIR_FACTS = List.of("playfairFact1", "playfairFact2", "playfairFact3");
@BeforeEach
@@ -53,145 +46,87 @@ public class PlayfairCipherControllerIntegrationTest extends CipherStreamControl
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
- decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
+ decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
+ decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
encodedNode = mapper.createObjectNode();
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
- encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedStringPadded);
+ encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
+ encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING_PADDED);
- ReflectionTestUtils.setField(playfairCipherController, "playfairName", playfairName);
- ReflectionTestUtils.setField(playfairCipherController, "playfairDescription", playfairDescription);
- ReflectionTestUtils.setField(playfairCipherController, "playfairExplanation", playfairExplanation);
- ReflectionTestUtils.setField(playfairCipherController, "playfairFacts", playfairFacts);
+ ReflectionTestUtils.setField(playfairCipherController, "playfairName", PLAYFAIR_NAME);
+ ReflectionTestUtils.setField(playfairCipherController, "playfairDescription", PLAYFAIR_DESCRIPTION);
+ ReflectionTestUtils.setField(playfairCipherController, "playfairExplanation", PLAYFAIR_EXPLANATION);
+ ReflectionTestUtils.setField(playfairCipherController, "playfairFacts", PLAYFAIR_FACTS);
}
@Test
public void testGetCipherInfo() throws Exception{
- mockMvc.perform(get(url)
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress))
+ mockMvc.perform(get(URL)
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(playfairName))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(playfairDescription))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(PLAYFAIR_NAME))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(PLAYFAIR_DESCRIPTION))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(playfairExplanation.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(playfairExplanation.get(0), playfairExplanation.get(1), playfairExplanation.get(2))))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(PLAYFAIR_EXPLANATION.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(PLAYFAIR_EXPLANATION.get(0), PLAYFAIR_EXPLANATION.get(1), PLAYFAIR_EXPLANATION.get(2))))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(playfairFacts.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(playfairFacts.get(0), playfairFacts.get(1), playfairFacts.get(2))));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url);
- //Controller
- verify(playfairLogger, times(1)).info("Getting info for {}", playfairName);
- verifyNoMoreInteractions(playfairLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, playfairName);
- */
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(PLAYFAIR_FACTS.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(PLAYFAIR_FACTS.get(0), PLAYFAIR_FACTS.get(1), PLAYFAIR_FACTS.get(2))));
}
@Test
public void testEncodePlayfair() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(decodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(playfairLogger, times(1)).info("Encoding {}", playfairName);
- verifyNoMoreInteractions(playfairLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, playfairName);
- //Cipher Aspect
- verifyAspectLogging(decodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
}
@Test
public void testEncodeplayfair_error() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(playfairLogger, times(1)).info("Encoding {}", playfairName);
- verifyNoMoreInteractions(playfairLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, playfairName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
@Test
public void testDecodePlayfair() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(encodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedStringPadded));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(playfairLogger, times(1)).info("Decoding {}", playfairName);
- verifyNoMoreInteractions(playfairLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, playfairName);
- //Cipher Aspect
- verifyAspectLogging(encodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING_PADDED));
}
@Test
public void testDecodeplayfair_error() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(playfairLogger, times(1)).info("Decoding {}", playfairName);
- verifyNoMoreInteractions(playfairLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, playfairName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/PlayfairCipherControllerTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/PlayfairCipherControllerTest.java
index 2eab7de..a7eac08 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/PlayfairCipherControllerTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/PlayfairCipherControllerTest.java
@@ -33,24 +33,24 @@ public class PlayfairCipherControllerTest{
private static final String DECODED_INPUT_STRING = "Hide the gold in - the@trexe+stump";
private static final String PLAYFAIR_OUTPUT_STRING = "Bmod zbx dnab ek - udm@uixmm+ouvif";
private static final String PLAYFAIR_KEYWORD = "Play-fair@Exam ple";
- private static final String playfairName = "playfairName";
- private static final String playfairDescription = "playfairDescription";
- private static final List playfairExplanation = List.of("playfairExplanation1", "playfairExplanation2", "playfairExplanation3");
- private static final List playfairFacts = List.of("playfairFact1", "playfairFact2", "playfairFact3");
+ private static final String PLAYFAIR_NAME = "playfairName";
+ private static final String PLAYFAIR_DESCRIPTION = "playfairDescription";
+ private static final List PLAYFAIR_EXPLANATION = List.of("playfairExplanation1", "playfairExplanation2", "playfairExplanation3");
+ private static final List PLAYFAIR_FACTS = List.of("playfairFact1", "playfairFact2", "playfairFact3");
@BeforeEach
public void setup(){
- ReflectionTestUtils.setField(playfairCipherController, "playfairName", playfairName);
- ReflectionTestUtils.setField(playfairCipherController, "playfairDescription", playfairDescription);
- ReflectionTestUtils.setField(playfairCipherController, "playfairExplanation", playfairExplanation);
- ReflectionTestUtils.setField(playfairCipherController, "playfairFacts", playfairFacts);
+ ReflectionTestUtils.setField(playfairCipherController, "playfairName", PLAYFAIR_NAME);
+ ReflectionTestUtils.setField(playfairCipherController, "playfairDescription", PLAYFAIR_DESCRIPTION);
+ ReflectionTestUtils.setField(playfairCipherController, "playfairExplanation", PLAYFAIR_EXPLANATION);
+ ReflectionTestUtils.setField(playfairCipherController, "playfairFacts", PLAYFAIR_FACTS);
}
@Test
public void tetGetCipherInfo(){
- ObjectNode infoNode = CipherInfoUtil.buildInfoNode(playfairName, playfairDescription, playfairExplanation, playfairFacts);
+ ObjectNode infoNode = CipherInfoUtil.buildInfoNode(PLAYFAIR_NAME, PLAYFAIR_DESCRIPTION, PLAYFAIR_EXPLANATION, PLAYFAIR_FACTS);
ObjectNode returnedJson = playfairCipherController.getCipherInfo();
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/PolybiusSquareControllerIntegrationTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/PolybiusSquareControllerIntegrationTest.java
index ca6c351..55acdb9 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/PolybiusSquareControllerIntegrationTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/PolybiusSquareControllerIntegrationTest.java
@@ -20,8 +20,6 @@ import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTe
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
-import tools.jackson.databind.node.ObjectNode;
-
@Tag("integration-test")
@WebMvcTest(controllers = PolybiusSquareController.class)
@@ -30,20 +28,15 @@ public class PolybiusSquareControllerIntegrationTest extends CipherStreamControl
private MockMvc mockMvc;
@Autowired
private PolybiusSquareController polybiusSquareController;
- //Loggers
- //TODO: Fix logger testing
- //@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.PolybiusSquareController")
- //protected Logger polybiusLogger;
//Fields
- private static final ObjectNode blankNode = mapper.createObjectNode();
- private static final String url = "/polybius";
- private static final String decodedString = "Message to^encode";
- private static final String encodedString = "41124545233212 5115^124225152212";
- private static final String keyword = "keyword";
- private static final String polybiusName = "polybiusName";
- private static final String polybiusDescription = "polybiusDescription";
- private static final List polybiusExplanation = List.of("polybiusExplanation1", "polybiusExplanation2", "polybiusExplanation3");
- private static final List polybiusFacts = List.of("polybiusFact1", "polybiusFact2", "polybiusFact3");
+ private static final String URL = "/polybius";
+ private static final String DECODED_STRING = "Message to^encode";
+ private static final String ENCODED_STRING = "41124545233212 5115^124225152212";
+ private static final String KEYWORD = "keyword";
+ private static final String POLYBIUS_NAME = "polybiusName";
+ private static final String POLYBIUS_DESCRIPTION = "polybiusDescription";
+ private static final List POLYBIUS_EXPLANATION = List.of("polybiusExplanation1", "polybiusExplanation2", "polybiusExplanation3");
+ private static final List POLYBIUS_FACTS = List.of("polybiusFact1", "polybiusFact2", "polybiusFact3");
@BeforeEach
@@ -52,145 +45,87 @@ public class PolybiusSquareControllerIntegrationTest extends CipherStreamControl
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
- decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
+ decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
+ decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
encodedNode = mapper.createObjectNode();
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
- encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString.toUpperCase());
+ encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
+ encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING.toUpperCase());
- ReflectionTestUtils.setField(polybiusSquareController, "polybiusName", polybiusName);
- ReflectionTestUtils.setField(polybiusSquareController, "polybiusDescription", polybiusDescription);
- ReflectionTestUtils.setField(polybiusSquareController, "polybiusExplanation", polybiusExplanation);
- ReflectionTestUtils.setField(polybiusSquareController, "polybiusFacts", polybiusFacts);
+ ReflectionTestUtils.setField(polybiusSquareController, "polybiusName", POLYBIUS_NAME);
+ ReflectionTestUtils.setField(polybiusSquareController, "polybiusDescription", POLYBIUS_DESCRIPTION);
+ ReflectionTestUtils.setField(polybiusSquareController, "polybiusExplanation", POLYBIUS_EXPLANATION);
+ ReflectionTestUtils.setField(polybiusSquareController, "polybiusFacts", POLYBIUS_FACTS);
}
@Test
public void testGetCipherInfo() throws Exception{
- mockMvc.perform(get(url)
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress))
+ mockMvc.perform(get(URL)
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(polybiusName))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(polybiusDescription))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(POLYBIUS_NAME))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(POLYBIUS_DESCRIPTION))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(polybiusExplanation.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(polybiusExplanation.get(0), polybiusExplanation.get(1), polybiusExplanation.get(2))))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(POLYBIUS_EXPLANATION.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(POLYBIUS_EXPLANATION.get(0), POLYBIUS_EXPLANATION.get(1), POLYBIUS_EXPLANATION.get(2))))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(polybiusFacts.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(polybiusFacts.get(0), polybiusFacts.get(1), polybiusFacts.get(2))));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url);
- //Controller
- verify(polybiusLogger, times(1)).info("Getting info for {}", polybiusName);
- verifyNoMoreInteractions(polybiusLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, polybiusName);
- */
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(POLYBIUS_FACTS.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(POLYBIUS_FACTS.get(0), POLYBIUS_FACTS.get(1), POLYBIUS_FACTS.get(2))));
}
@Test
public void testEncodePolybius() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(decodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(polybiusLogger, times(1)).info("Encoding {}", polybiusName);
- verifyNoMoreInteractions(polybiusLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, polybiusName);
- //Cipher Aspect
- verifyAspectLogging(decodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
}
@Test
public void testEncodepolybius_error() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_WHITESPACE + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(polybiusLogger, times(1)).info("Encoding {}", polybiusName);
- verifyNoMoreInteractions(polybiusLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, polybiusName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
@Test
public void testDecodePolybius() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(encodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString.toUpperCase()));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(polybiusLogger, times(1)).info("Decoding {}", polybiusName);
- verifyNoMoreInteractions(polybiusLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, polybiusName);
- //Cipher Aspect
- verifyAspectLogging(encodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING.toUpperCase()));
}
@Test
public void testDecodepolybius_error() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_WHITESPACE + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(polybiusLogger, times(1)).info("Decoding {}", polybiusName);
- verifyNoMoreInteractions(polybiusLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, polybiusName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/PolybiusSquareControllerTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/PolybiusSquareControllerTest.java
index 8c0b6b4..7b0f7f3 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/PolybiusSquareControllerTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/PolybiusSquareControllerTest.java
@@ -32,23 +32,23 @@ public class PolybiusSquareControllerTest{
private static final String POLYBIUS_INPUT_STRING = "B A-T";
private static final String POLYBIUS_OUTPUT_STRING = "15 14-52";
private static final String POLYBIUS_KEYWORD = "Z Y+ X-";
- private static final String polybiusName = "polybiusName";
- private static final String polybiusDescription = "polybiusDescription";
- private static final List polybiusExplanation = List.of("PolybiusExplanation1", "PolybiusExplanation2", "PolybiusExplanation3");
- private static final List polybiusFacts = List.of("PolybiusFact1", "PolybiusFact2", "PolybiusFact3");
+ private static final String POLYBIUS_NAME = "polybiusName";
+ private static final String POLYBIUS_DESCRIPTION = "polybiusDescription";
+ private static final List POLYBIUS_EXPLANATION = List.of("PolybiusExplanation1", "PolybiusExplanation2", "PolybiusExplanation3");
+ private static final List POLYBIUS_FACTS = List.of("PolybiusFact1", "PolybiusFact2", "PolybiusFact3");
@BeforeEach
public void setup(){
- ReflectionTestUtils.setField(polybiusSquareController, "polybiusName", polybiusName);
- ReflectionTestUtils.setField(polybiusSquareController, "polybiusDescription", polybiusDescription);
- ReflectionTestUtils.setField(polybiusSquareController, "polybiusExplanation", polybiusExplanation);
- ReflectionTestUtils.setField(polybiusSquareController, "polybiusFacts", polybiusFacts);
+ ReflectionTestUtils.setField(polybiusSquareController, "polybiusName", POLYBIUS_NAME);
+ ReflectionTestUtils.setField(polybiusSquareController, "polybiusDescription", POLYBIUS_DESCRIPTION);
+ ReflectionTestUtils.setField(polybiusSquareController, "polybiusExplanation", POLYBIUS_EXPLANATION);
+ ReflectionTestUtils.setField(polybiusSquareController, "polybiusFacts", POLYBIUS_FACTS);
}
@Test
public void tetGetCipherInfo(){
- ObjectNode infoNode = CipherInfoUtil.buildInfoNode(polybiusName, polybiusDescription, polybiusExplanation, polybiusFacts);
+ ObjectNode infoNode = CipherInfoUtil.buildInfoNode(POLYBIUS_NAME, POLYBIUS_DESCRIPTION, POLYBIUS_EXPLANATION, POLYBIUS_FACTS);
ObjectNode returnedJson = polybiusSquareController.getCipherInfo();
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/RailFenceControllerIntegrationTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/RailFenceControllerIntegrationTest.java
index 1c4277d..f5c1b75 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/RailFenceControllerIntegrationTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/RailFenceControllerIntegrationTest.java
@@ -20,8 +20,6 @@ import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTe
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
-import tools.jackson.databind.node.ObjectNode;
-
@Tag("integration-test")
@WebMvcTest(controllers = RailFenceController.class)
@@ -30,20 +28,15 @@ public class RailFenceControllerIntegrationTest extends CipherStreamControllerIn
private MockMvc mockMvc;
@Autowired
private RailFenceController railFenceController;
- //Loggers
- //TODO: Fix logger testing
- //@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.RailFenceController")
- //protected Logger railFenceLogger;
//Fields
- private static final ObjectNode blankNode = mapper.createObjectNode();
- private static final String url = "/railFence";
- private static final String decodedString = "Message to^encode";
- private static final String encodedString = "Maooesg te^cdsene";
- private static final int rails = 3;
- private static final String railFenceName = "railFenceName";
- private static final String railFenceDescription = "railFenceDescription";
- private static final List railFenceExplanation = List.of("railFenceExplanation1", "railFenceExplanation2", "railFenceExplanation3");
- private static final List railFenceFacts = List.of("railFenceFact1", "railFenceFact2", "railFenceFact3");
+ private static final String URL = "/railFence";
+ private static final String DECODED_STRING = "Message to^encode";
+ private static final String ENCODED_STRING = "Maooesg te^cdsene";
+ private static final int RAILS = 3;
+ private static final String RAIL_FENCE_NAME = "railFenceName";
+ private static final String RAIL_FENCE_DESCRIPTION = "railFenceDescription";
+ private static final List RAIL_FENCE_EXPLANATION = List.of("railFenceExplanation1", "railFenceExplanation2", "railFenceExplanation3");
+ private static final List RAIL_FENCE_FACTS = List.of("railFenceFact1", "railFenceFact2", "railFenceFact3");
@BeforeEach
@@ -52,145 +45,87 @@ public class RailFenceControllerIntegrationTest extends CipherStreamControllerIn
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- decodedNode.put(CipherParameterUtil.RAIL_FENCE_RAILS, rails);
- decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
- decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
+ decodedNode.put(CipherParameterUtil.RAIL_FENCE_RAILS, RAILS);
+ decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
+ decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
encodedNode = mapper.createObjectNode();
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- encodedNode.put(CipherParameterUtil.RAIL_FENCE_RAILS, rails);
- encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
- encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
+ encodedNode.put(CipherParameterUtil.RAIL_FENCE_RAILS, RAILS);
+ encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
+ encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
- ReflectionTestUtils.setField(railFenceController, "railFenceName", railFenceName);
- ReflectionTestUtils.setField(railFenceController, "railFenceDescription", railFenceDescription);
- ReflectionTestUtils.setField(railFenceController, "railFenceExplanation", railFenceExplanation);
- ReflectionTestUtils.setField(railFenceController, "railFenceFacts", railFenceFacts);
+ ReflectionTestUtils.setField(railFenceController, "railFenceName", RAIL_FENCE_NAME);
+ ReflectionTestUtils.setField(railFenceController, "railFenceDescription", RAIL_FENCE_DESCRIPTION);
+ ReflectionTestUtils.setField(railFenceController, "railFenceExplanation", RAIL_FENCE_EXPLANATION);
+ ReflectionTestUtils.setField(railFenceController, "railFenceFacts", RAIL_FENCE_FACTS);
}
@Test
public void testGetCipherInfo() throws Exception{
- mockMvc.perform(get(url)
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress))
+ mockMvc.perform(get(URL)
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(railFenceName))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(railFenceDescription))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(RAIL_FENCE_NAME))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(RAIL_FENCE_DESCRIPTION))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(railFenceExplanation.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(railFenceExplanation.get(0), railFenceExplanation.get(1), railFenceExplanation.get(2))))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(RAIL_FENCE_EXPLANATION.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(RAIL_FENCE_EXPLANATION.get(0), RAIL_FENCE_EXPLANATION.get(1), RAIL_FENCE_EXPLANATION.get(2))))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(railFenceFacts.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(railFenceFacts.get(0), railFenceFacts.get(1), railFenceFacts.get(2))));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url);
- //Controller
- verify(railFenceLogger, times(1)).info("Getting info for {}", railFenceName);
- verifyNoMoreInteractions(railFenceLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, railFenceName);
- */
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(RAIL_FENCE_FACTS.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(RAIL_FENCE_FACTS.get(0), RAIL_FENCE_FACTS.get(1), RAIL_FENCE_FACTS.get(2))));
}
@Test
public void testEncodeRailFence() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(decodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(railFenceLogger, times(1)).info("Encoding {}", railFenceName);
- verifyNoMoreInteractions(railFenceLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, railFenceName);
- //Cipher Aspect
- verifyAspectLogging(decodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
}
@Test
public void testEncoderailFence_error() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(railFenceLogger, times(1)).info("Encoding {}", railFenceName);
- verifyNoMoreInteractions(railFenceLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, railFenceName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
@Test
public void testDecodeRailFence() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(encodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(railFenceLogger, times(1)).info("Decoding {}", railFenceName);
- verifyNoMoreInteractions(railFenceLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, railFenceName);
- //Cipher Aspect
- verifyAspectLogging(encodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
}
@Test
public void testDecoderailFence_error() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(railFenceLogger, times(1)).info("Decoding {}", railFenceName);
- verifyNoMoreInteractions(railFenceLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, railFenceName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/RailFenceControllerTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/RailFenceControllerTest.java
index 359ac4d..928cf02 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/RailFenceControllerTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/RailFenceControllerTest.java
@@ -32,24 +32,24 @@ public class RailFenceControllerTest{
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 static final String railFenceName = "railFenceName";
- private static final String railFenceDescription = "railFenceDescription";
- private static final List railFenceExplanation = List.of("railFenceExplanation1", "railFenceExplanation2", "railFenceExplanation3");
- private static final List railFenceFacts = List.of("railFenceFact1", "railFenceFact2", "railFenceFact3");
+ private static final String RAIL_FENCE_NAME = "railFenceName";
+ private static final String RAIL_FENCE_DESCRIPTION = "railFenceDescription";
+ private static final List RAIL_FENCE_EXPLANATION = List.of("railFenceExplanation1", "railFenceExplanation2", "railFenceExplanation3");
+ private static final List RAIL_FENCE_FACTS = List.of("railFenceFact1", "railFenceFact2", "railFenceFact3");
@BeforeEach
public void setup(){
- ReflectionTestUtils.setField(railFenceController, "railFenceName", railFenceName);
- ReflectionTestUtils.setField(railFenceController, "railFenceDescription", railFenceDescription);
- ReflectionTestUtils.setField(railFenceController, "railFenceExplanation", railFenceExplanation);
- ReflectionTestUtils.setField(railFenceController, "railFenceFacts", railFenceFacts);
+ ReflectionTestUtils.setField(railFenceController, "railFenceName", RAIL_FENCE_NAME);
+ ReflectionTestUtils.setField(railFenceController, "railFenceDescription", RAIL_FENCE_DESCRIPTION);
+ ReflectionTestUtils.setField(railFenceController, "railFenceExplanation", RAIL_FENCE_EXPLANATION);
+ ReflectionTestUtils.setField(railFenceController, "railFenceFacts", RAIL_FENCE_FACTS);
}
@Test
public void tetGetCipherInfo(){
- ObjectNode infoNode = CipherInfoUtil.buildInfoNode(railFenceName, railFenceDescription, railFenceExplanation, railFenceFacts);
+ ObjectNode infoNode = CipherInfoUtil.buildInfoNode(RAIL_FENCE_NAME, RAIL_FENCE_DESCRIPTION, RAIL_FENCE_EXPLANATION, RAIL_FENCE_FACTS);
ObjectNode returnedJson = railFenceController.getCipherInfo();
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/TrifidCipherControllerIntegrationTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/TrifidCipherControllerIntegrationTest.java
index 525d412..e1bbbc5 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/TrifidCipherControllerIntegrationTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/TrifidCipherControllerIntegrationTest.java
@@ -20,8 +20,6 @@ import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTe
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
-import tools.jackson.databind.node.ObjectNode;
-
@Tag("integration-test")
@WebMvcTest(controllers = TrifidCipherController.class)
@@ -30,22 +28,17 @@ public class TrifidCipherControllerIntegrationTest extends CipherStreamControlle
private MockMvc mockMvc;
@Autowired
private TrifidCipherController trifidCipherController;
- //TODO: Fix logger testing
- //Loggers
- //@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.TrifidCipherController")
- //protected Logger trifidLogger;
//Fields
- private static final ObjectNode blankNode = mapper.createObjectNode();
- private static final String url = "/trifid";
- private static final String decodedString = "Message to^encode+";
- private static final String encodedString = "Gqdokpd od^ljvflf+";
- private static final String keyword = "keyword";
- private static final String trifidFill = "=";
- private static final int grouplength = Integer.MAX_VALUE;
- private static final String trifidName = "trifidName";
- private static final String trifidDescription = "trifidDescription";
- private static final List trifidExplanation = List.of("trifidExplanation1", "trifidExplanation2", "trifidExplanation3");
- private static final List trifidFacts = List.of("trifidFact1", "trifidFact2", "trifidFact3");
+ private static final String URL = "/trifid";
+ private static final String DECODED_STRING = "Message to^encode+";
+ private static final String ENCODED_STRING = "Gqdokpd od^ljvflf+";
+ private static final String KEYWORD = "keyword";
+ private static final String TRIFID_FILL = "=";
+ private static final int GROUP_LENGTH = Integer.MAX_VALUE;
+ private static final String TRIFID_NAME = "trifidName";
+ private static final String TRIFID_DESCRIPTION = "trifidDescription";
+ private static final List TRIFID_EXPLANATION = List.of("trifidExplanation1", "trifidExplanation2", "trifidExplanation3");
+ private static final List TRIFID_FACTS = List.of("trifidFact1", "trifidFact2", "trifidFact3");
@BeforeEach
@@ -54,149 +47,91 @@ public class TrifidCipherControllerIntegrationTest extends CipherStreamControlle
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- decodedNode.put(CipherParameterUtil.TRIFID_FILL, trifidFill);
- decodedNode.put(CipherParameterUtil.TRIFID_GROUP_LENGTH, grouplength);
- decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
- decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
+ decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ decodedNode.put(CipherParameterUtil.TRIFID_FILL, TRIFID_FILL);
+ decodedNode.put(CipherParameterUtil.TRIFID_GROUP_LENGTH, GROUP_LENGTH);
+ decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
+ decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
encodedNode = mapper.createObjectNode();
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
- encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
- encodedNode.put(CipherParameterUtil.TRIFID_FILL, trifidFill);
- encodedNode.put(CipherParameterUtil.TRIFID_GROUP_LENGTH, grouplength);
- encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
- encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
+ encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
+ encodedNode.put(CipherParameterUtil.TRIFID_FILL, TRIFID_FILL);
+ encodedNode.put(CipherParameterUtil.TRIFID_GROUP_LENGTH, GROUP_LENGTH);
+ encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
+ encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
- ReflectionTestUtils.setField(trifidCipherController, "trifidName", trifidName);
- ReflectionTestUtils.setField(trifidCipherController, "trifidDescription", trifidDescription);
- ReflectionTestUtils.setField(trifidCipherController, "trifidExplanation", trifidExplanation);
- ReflectionTestUtils.setField(trifidCipherController, "trifidFacts", trifidFacts);
+ ReflectionTestUtils.setField(trifidCipherController, "trifidName", TRIFID_NAME);
+ ReflectionTestUtils.setField(trifidCipherController, "trifidDescription", TRIFID_DESCRIPTION);
+ ReflectionTestUtils.setField(trifidCipherController, "trifidExplanation", TRIFID_EXPLANATION);
+ ReflectionTestUtils.setField(trifidCipherController, "trifidFacts", TRIFID_FACTS);
}
@Test
public void testGetCipherInfo() throws Exception{
- mockMvc.perform(get(url)
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress))
+ mockMvc.perform(get(URL)
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(trifidName))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(trifidDescription))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(TRIFID_NAME))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(TRIFID_DESCRIPTION))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(trifidExplanation.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(trifidExplanation.get(0), trifidExplanation.get(1), trifidExplanation.get(2))))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(TRIFID_EXPLANATION.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(TRIFID_EXPLANATION.get(0), TRIFID_EXPLANATION.get(1), TRIFID_EXPLANATION.get(2))))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(trifidFacts.size())))
- .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(trifidFacts.get(0), trifidFacts.get(1), trifidFacts.get(2))));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url);
- //Controller
- verify(trifidLogger, times(1)).info("Getting info for {}", trifidName);
- verifyNoMoreInteractions(trifidLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, trifidName);
- */
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(TRIFID_FACTS.size())))
+ .andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(TRIFID_FACTS.get(0), TRIFID_FACTS.get(1), TRIFID_FACTS.get(2))));
}
@Test
public void testEncodeTrifid() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(decodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(trifidLogger, times(1)).info("Encoding {}", trifidName);
- verifyNoMoreInteractions(trifidLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, trifidName);
- //Cipher Aspect
- verifyAspectLogging(decodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
}
@Test
public void testEncodetrifid_error() throws Exception{
- mockMvc.perform(post(url + "/encode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/encode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/encode");
- //Controller
- verify(trifidLogger, times(1)).info("Encoding {}", trifidName);
- verifyNoMoreInteractions(trifidLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, trifidName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
@Test
public void testDecodeTrifid() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(encodedNode.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(trifidLogger, times(1)).info("Decoding {}", trifidName);
- verifyNoMoreInteractions(trifidLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, trifidName);
- //Cipher Aspect
- verifyAspectLogging(encodedNode);
- */
+ .andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
}
@Test
public void testDecodetrifid_error() throws Exception{
- mockMvc.perform(post(url + "/decode")
- .header("X-Request-Id", requestId)
- .header("X-Forwarded-For", ipAddress)
+ mockMvc.perform(post(URL + "/decode")
+ .header("X-Request-Id", REQUEST_ID)
+ .header("X-Forwarded-For", IP_ADDRESS)
.contentType(MediaType.APPLICATION_JSON)
.content(blankNode.toString()))
.andExpect(status().isBadRequest())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
-
- //Filter
- //TODO: Fix logger testing
- /*
- super.verifyFilter(url + "/decode");
- //Controller
- verify(trifidLogger, times(1)).info("Decoding {}", trifidName);
- verifyNoMoreInteractions(trifidLogger);
- verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, trifidName);
- //Cipher Aspect
- verifyNoInteractions(aspectLogger);
- */
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/TrifidCipherControllerTest.java b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/TrifidCipherControllerTest.java
index 75759ed..aa72dd8 100644
--- a/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/TrifidCipherControllerTest.java
+++ b/src/test/java/com/mattrixwv/cipherstream/controller/polysubstitution/TrifidCipherControllerTest.java
@@ -34,24 +34,24 @@ public class TrifidCipherControllerTest{
private static final String TRIFID_KEYWORD = CipherParameterUtil.KEYWORD;
private static final char TRIFID_FILL_ID = '+';
private static final int TRIFID_GROUP_LENGTH = 3;
- private static final String trifidName = "trifidName";
- private static final String trifidDescription = "trifidDescription";
- private static final List trifidExplanation = List.of("trifidExplanation1", "trifidExplanation2", "trifidExplanation3");
- private static final List trifidFacts = List.of("trifidFact1", "trifidFact2", "trifidFact3");
+ private static final String TRIFID_NAME = "trifidName";
+ private static final String TRIFID_DESCRIPTION = "trifidDescription";
+ private static final List TRIFID_EXPLANATION = List.of("trifidExplanation1", "trifidExplanation2", "trifidExplanation3");
+ private static final List TRIFID_FACTS = List.of("trifidFact1", "trifidFact2", "trifidFact3");
@BeforeEach
public void setup(){
- ReflectionTestUtils.setField(trifidCipherController, "trifidName", trifidName);
- ReflectionTestUtils.setField(trifidCipherController, "trifidDescription", trifidDescription);
- ReflectionTestUtils.setField(trifidCipherController, "trifidExplanation", trifidExplanation);
- ReflectionTestUtils.setField(trifidCipherController, "trifidFacts", trifidFacts);
+ ReflectionTestUtils.setField(trifidCipherController, "trifidName", TRIFID_NAME);
+ ReflectionTestUtils.setField(trifidCipherController, "trifidDescription", TRIFID_DESCRIPTION);
+ ReflectionTestUtils.setField(trifidCipherController, "trifidExplanation", TRIFID_EXPLANATION);
+ ReflectionTestUtils.setField(trifidCipherController, "trifidFacts", TRIFID_FACTS);
}
@Test
public void tetGetCipherInfo(){
- ObjectNode infoNode = CipherInfoUtil.buildInfoNode(trifidName, trifidDescription, trifidExplanation, trifidFacts);
+ ObjectNode infoNode = CipherInfoUtil.buildInfoNode(TRIFID_NAME, TRIFID_DESCRIPTION, TRIFID_EXPLANATION, TRIFID_FACTS);
ObjectNode returnedJson = trifidCipherController.getCipherInfo();