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 = AdfgxCipherController.class)
|
|
public class AdfgxCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
|
@Autowired
|
|
private MockMvc mockMvc;
|
|
@Autowired
|
|
private AdfgxCipherController adfgxCipherController;
|
|
//Fields
|
|
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<String> ADFGX_EXPLANATION = List.of("adfgxExplanation1", "adfgxExplanation2", "adfgxExplanation3");
|
|
private static final List<String> ADFGX_FACTS = List.of("adfgxFact1", "adfgxFact2", "adfgxFact3");
|
|
|
|
|
|
@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(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", REQUEST_ID)
|
|
.header("X-Forwarded-For", IP_ADDRESS))
|
|
.andExpect(status().isOk())
|
|
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
|
.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(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(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", 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 testEncodeAdfgx_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 testDecodeAdfgx() 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));
|
|
}
|
|
}
|