135 lines
6.1 KiB
Java
135 lines
6.1 KiB
Java
package com.mattrixwv.cipherstream.controller.combination;
|
|
|
|
|
|
import static org.hamcrest.Matchers.*;
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
|
|
|
import java.util.List;
|
|
|
|
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.webmvc.test.autoconfigure.WebMvcTest;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.test.util.ReflectionTestUtils;
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
|
|
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
|
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
|
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
|
|
|
|
|
@Tag("integration-test")
|
|
@WebMvcTest(controllers = AdfgvxCipherController.class)
|
|
public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
|
@Autowired
|
|
private MockMvc mockMvc;
|
|
@Autowired
|
|
private AdfgvxCipherController adfgvxCipherController;
|
|
//Fields
|
|
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<String> ADFGVX_EXPLANATION = List.of("adfgvxExplanation1", "adfgvxExplanation2", "adfgvxExplanation3");
|
|
private static final List<String> ADFGVX_FACTS = List.of("adfgvxFact1", "adfgvxFact2", "adfgvxFact3");
|
|
|
|
|
|
@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.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, SQUARE_KEYWORD);
|
|
encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
|
|
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
|
|
|
|
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", REQUEST_ID)
|
|
.header("X-Forwarded-For", IP_ADDRESS))
|
|
.andExpect(status().isOk())
|
|
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
|
.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(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(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", 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(ENCODED_STRING));
|
|
}
|
|
|
|
@Test
|
|
public void testEncodeAdfgvx_error() throws Exception{
|
|
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));
|
|
}
|
|
|
|
@Test
|
|
public void testDecodeAdfgvx() throws Exception{
|
|
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(DECODED_STRING));
|
|
}
|
|
|
|
@Test
|
|
public void testDecodeAdfgvx_error() throws Exception{
|
|
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));
|
|
}
|
|
}
|