86 lines
3.4 KiB
Java
86 lines
3.4 KiB
Java
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
|
|
|
|
|
import static org.mockito.Mockito.*;
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Tag;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
|
|
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
|
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
|
|
|
|
|
@Tag("integration-test")
|
|
@WebMvcTest(controllers = BaconianCipherController.class)
|
|
public class BaconianCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
|
@Autowired
|
|
private MockMvc mockMvc;
|
|
//Fields
|
|
private String url = "/cipherStream/baconian";
|
|
private String decodedString = "Message to^encode";
|
|
private String encodedString = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
|
|
|
|
|
@BeforeEach
|
|
public void setup(){
|
|
decodedNode = mapper.createObjectNode();
|
|
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);
|
|
|
|
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]", ""));
|
|
}
|
|
|
|
@Test
|
|
public void testEncodeBaconian() throws Exception{
|
|
mockMvc.perform(get(url + "/encode")
|
|
.header("X-Request-Id", requestId)
|
|
.header("X-Forwarded-For", "192.168.1.1")
|
|
.contentType(MediaType.APPLICATION_JSON)
|
|
.content(decodedNode.toString()))
|
|
.andExpect(status().isOk())
|
|
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
|
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
|
|
|
//Filter
|
|
super.verifyFilter(url + "/encode");
|
|
//Controller
|
|
verify(baconianLogger, times(1)).info("Encoding Baconian");
|
|
//Cipher Aspect
|
|
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
|
}
|
|
|
|
@Test
|
|
public void testDecodeBaconian() throws Exception{
|
|
mockMvc.perform(get(url + "/decode")
|
|
.header("X-Request-Id", requestId)
|
|
.header("X-Forwarded-For", "192.168.1.1")
|
|
.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
|
|
super.verifyFilter(url + "/decode");
|
|
//Controller
|
|
verify(baconianLogger, times(1)).info("Decoding Baconian");
|
|
//Cipher Aspect
|
|
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
|
}
|
|
}
|