Initial commit

This commit is contained in:
2024-04-07 19:41:57 -04:00
parent 2b3212cb44
commit 8f0d1c64bd
95 changed files with 6787 additions and 45 deletions

View File

@@ -0,0 +1,103 @@
package com.mattrixwv.cipherstream.controller;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.util.UUID;
import org.junit.jupiter.api.Tag;
import org.mockito.Mock;
import org.slf4j.Logger;
import org.slf4j.spi.MDCAdapter;
import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration;
import org.springframework.context.annotation.Import;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
import com.mattrixwv.cipherstream.config.FullFilter;
@Tag("integration-test")
@Import({AopAutoConfiguration.class, FullFilter.class, CipherStreamLoggingAspect.class})
public class CipherStreamControllerIntegrationTestBase{
protected static final ObjectMapper mapper = new ObjectMapper();
//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";
//MDC
@Mock
protected MDCAdapter mdc;
//Base
@Mock(name = "com.mattrixwv.cipherstream.controller.CipherStreamController")
protected Logger baseLogger;
//Combination
@Mock(name = "com.mattrixwv.cipherstream.controller.combination.AdfgvxCipherController")
protected Logger adfgvxLogger;
@Mock(name = "com.mattrixwv.cipherstream.controller.combination.AdfgxCipherController")
protected Logger adfgxLogger;
//Monosubstitution
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AffineCipherController")
protected Logger affineLogger;
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AtbashCipherController")
protected Logger atbashLogger;
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AutokeyCipherController")
protected Logger autokeyLogger;
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BaconianCipherController")
protected Logger baconianLogger;
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BaseXCipherController")
protected Logger baseXLogger;
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BeaufortCipherController")
protected Logger beaufortLogger;
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.CaesarCipherController")
protected Logger caesarLogger;
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.OneTimePadCipherController")
protected Logger oneTimePadLogger;
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.PortaCipherController")
protected Logger portaLogger;
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.SubstitutionCipherController")
protected Logger substitutionLogger;
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.VigenereCipherController")
protected Logger vigenereLogger;
//Polysubstitution
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.BifidCipherController")
protected Logger bifidLogger;
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.ColumnarCipherController")
protected Logger columnarLogger;
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.HillCipherController")
protected Logger hillLogger;
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.MorseCodeController")
protected Logger morseLogger;
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.PlayfairCipherController")
protected Logger playfiarLogger;
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.PolybiusSquareController")
protected Logger polybiusLogger;
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.RailFenceController")
protected Logger railFenceLogger;
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.TrifidCipherController")
protected Logger trifidLogger;
//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();
}
}