diff options
Diffstat (limited to 'aai-resources/src/test/java/org/onap/aai/interceptors/AAILogJAXRSInInterceptorTest.java')
-rw-r--r-- | aai-resources/src/test/java/org/onap/aai/interceptors/AAILogJAXRSInInterceptorTest.java | 162 |
1 files changed, 153 insertions, 9 deletions
diff --git a/aai-resources/src/test/java/org/onap/aai/interceptors/AAILogJAXRSInInterceptorTest.java b/aai-resources/src/test/java/org/onap/aai/interceptors/AAILogJAXRSInInterceptorTest.java index 3b1dac2..40de5a9 100644 --- a/aai-resources/src/test/java/org/onap/aai/interceptors/AAILogJAXRSInInterceptorTest.java +++ b/aai-resources/src/test/java/org/onap/aai/interceptors/AAILogJAXRSInInterceptorTest.java @@ -26,35 +26,179 @@ import org.apache.cxf.message.ExchangeImpl; import org.apache.cxf.message.Message; import org.junit.Before; import org.junit.Test; -import org.onap.aai.AAISetup; import java.io.IOException; import java.io.InputStream; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; -public class AAILogJAXRSInInterceptorTest extends AAISetup { +public class AAILogJAXRSInInterceptorTest { private AAILogJAXRSInInterceptor aaiLogJAXRSInInterceptor; + private Message message; + private Exchange exchange; + private InputStream is; + private Map<String, List<String>> headers; + + @Before public void setup(){ + aaiLogJAXRSInInterceptor = new AAILogJAXRSInInterceptor(); + + message = mock(Message.class); + exchange = spy(new ExchangeImpl()); + + is = getClass().getClassLoader().getResourceAsStream("logback.xml"); + + headers = new HashMap<>(); + headers.put("X-FromAppId", Arrays.asList("JUNIT")); + headers.put("X-TransactionId", Arrays.asList("JUNIT")); + headers.put("Content-Type", Arrays.asList("application/json")); + headers.put("Accept", Arrays.asList("application/json")); } @Test public void testHandleMessageWhenNotCamelRequest() throws IOException { - Message message = mock(Message.class); - Exchange exchange = new ExchangeImpl(); - InputStream is = getClass().getClassLoader().getResourceAsStream("logback.xml"); + when(message.getExchange()).thenReturn(exchange); + when(message.getContent(InputStream.class)).thenReturn(is); + when(message.get(Message.PROTOCOL_HEADERS)).thenReturn(headers); + when(message.get(Message.CONTENT_TYPE)).thenReturn("*/*"); + + when(message.get("CamelHttpUrl")).thenReturn("/somestring"); + aaiLogJAXRSInInterceptor.handleMessage(message); + } + + @Test + public void testHandleMessageWhenUUIDHasMultiple() throws IOException { + + Map<String, List<String>> headers = new HashMap<>(); + + headers.put("X-FromAppId", Arrays.asList("JUNIT")); + headers.put("X-TransactionId", Arrays.asList("jfasodjf:fjaosjfidsaj:afsidjfaodfja")); + headers.put("Content-Type", Arrays.asList("application/json")); + headers.put("Accept", Arrays.asList("application/json")); + + when(message.getExchange()).thenReturn(exchange); + when(message.getContent(InputStream.class)).thenReturn(is); + when(message.get(Message.PROTOCOL_HEADERS)).thenReturn(headers); + when(message.get(Message.CONTENT_TYPE)).thenReturn("*/*"); + + when(message.get("CamelHttpUrl")).thenReturn("/somestring"); + aaiLogJAXRSInInterceptor.handleMessage(message); + } + + @Test + public void testHandleMessageWhenMissingTransactionId() throws IOException { + + Map<String, List<String>> headers = new HashMap<>(); + + headers.put("X-FromAppId", Arrays.asList("JUNIT")); + headers.put("Content-Type", Arrays.asList("application/json")); + headers.put("Accept", Arrays.asList("application/json")); + + when(message.getExchange()).thenReturn(exchange); + when(message.getContent(InputStream.class)).thenReturn(is); + when(message.get(Message.PROTOCOL_HEADERS)).thenReturn(headers); + when(message.get(Message.CONTENT_TYPE)).thenReturn("*/*"); + + when(message.get("CamelHttpUrl")).thenReturn("/somestring"); + aaiLogJAXRSInInterceptor.handleMessage(message); + } + + @Test + public void testHandleMessageWhenMissingContentType() throws IOException { + + Map<String, List<String>> headers = new HashMap<>(); + + headers.put("X-FromAppId", Arrays.asList("JUNIT")); + headers.put("X-TransactionId", Arrays.asList("jfasodjf:fjaosjfidsaj:afsidjfaodfja")); + headers.put("Accept", Arrays.asList("application/json")); when(message.getExchange()).thenReturn(exchange); when(message.getContent(InputStream.class)).thenReturn(is); + when(message.get(Message.PROTOCOL_HEADERS)).thenReturn(headers); + when(message.get(Message.CONTENT_TYPE)).thenReturn("*/*"); -// when(message.get(Message.QUERY_STRING)).thenReturn("/somestring"); when(message.get("CamelHttpUrl")).thenReturn("/somestring"); aaiLogJAXRSInInterceptor.handleMessage(message); } -} + + @Test + public void testHandleMessageWhenQueryExistsAndUriEcho() throws IOException { + + Map<String, List<String>> headers = new HashMap<>(); + + headers.put("X-FromAppId", Arrays.asList("JUNIT")); + headers.put("X-TransactionId", Arrays.asList("jfasodjf:fjaosjfidsaj:afsidjfaodfja")); + headers.put("Content-Type", Arrays.asList("application/json")); + headers.put("Accept", Arrays.asList("application/json")); + + when(message.getExchange()).thenReturn(exchange); + when(message.getContent(InputStream.class)).thenReturn(is); + when(message.get(Message.PROTOCOL_HEADERS)).thenReturn(headers); + when(message.get(Message.CONTENT_TYPE)).thenReturn("*/*"); + when(message.get(Message.QUERY_STRING)).thenReturn(null); + when(exchange.containsKey("AAI_LOGGING_HBASE_ENABLED")).thenReturn(true); + when(exchange.remove("AAI_LOGGING_HBASE_ENABLED")).thenReturn(""); + when(exchange.containsKey("AAI_LOGGING_TRACE_ENABLED")).thenReturn(true); + when(exchange.remove("AAI_LOGGING_TRACE_ENABLED")).thenReturn(""); + when(message.get("CamelHttpUrl")).thenReturn("/util/echo"); + aaiLogJAXRSInInterceptor.handleMessage(message); + } + + @Test + public void testHandleMessageWhenQueryExistsAndUriTranslog() throws IOException { + + Map<String, List<String>> headers = new HashMap<>(); + + headers.put("X-FromAppId", Arrays.asList("JUNIT")); + headers.put("X-TransactionId", Arrays.asList("jfasodjf:fjaosjfidsaj:afsidjfaodfja")); + headers.put("Content-Type", Arrays.asList("application/json")); + headers.put("Accept", Arrays.asList("application/json")); + + when(message.getExchange()).thenReturn(exchange); + when(message.getContent(InputStream.class)).thenReturn(is); + when(message.get(Message.PROTOCOL_HEADERS)).thenReturn(headers); + when(message.get(Message.CONTENT_TYPE)).thenReturn("*/*"); + when(message.get(Message.QUERY_STRING)).thenReturn(null); + when(exchange.containsKey("AAI_LOGGING_HBASE_ENABLED")).thenReturn(true); + when(exchange.remove("AAI_LOGGING_HBASE_ENABLED")).thenReturn(""); + when(exchange.containsKey("AAI_LOGGING_TRACE_ENABLED")).thenReturn(true); + when(exchange.remove("AAI_LOGGING_TRACE_ENABLED")).thenReturn(""); + when(message.get("CamelHttpUrl")).thenReturn("/translog/"); + aaiLogJAXRSInInterceptor.handleMessage(message); + } + + @Test + public void testHandleMessageWhenPutMessageKeyReturnsException() throws IOException { + + Map<String, List<String>> headers = new HashMap<>(); + + headers.put("X-FromAppId", Arrays.asList("JUNIT")); + headers.put("X-TransactionId", Arrays.asList("jfasodjf:fjaosjfidsaj:afsidjfaodfja")); + headers.put("Content-Type", Arrays.asList("application/json")); + headers.put("Accept", Arrays.asList("application/json")); + + when(message.getExchange()).thenReturn(exchange); + when(message.getContent(InputStream.class)).thenReturn(is); + when(message.get(Message.PROTOCOL_HEADERS)).thenReturn(headers); + when(message.get(Message.CONTENT_TYPE)).thenReturn("*/*"); + when(message.get(Message.QUERY_STRING)).thenReturn(null); + when(exchange.containsKey("AAI_LOGGING_HBASE_ENABLED")).thenReturn(true); + when(exchange.remove("AAI_LOGGING_HBASE_ENABLED")).thenReturn(""); + when(exchange.containsKey("AAI_LOGGING_TRACE_ENABLED")).thenReturn(true); + when(exchange.remove("AAI_LOGGING_TRACE_ENABLED")).thenReturn(""); + when(message.get("CamelHttpUrl")).thenReturn("/translog/"); + when(message.get(Message.ENCODING)).thenReturn("http"); + when(message.get(Message.RESPONSE_CODE)).thenReturn(200); + + aaiLogJAXRSInInterceptor.handleMessage(message); + } +}
\ No newline at end of file |