diff options
author | 2019-09-09 20:55:15 +0000 | |
---|---|---|
committer | 2019-09-19 12:57:18 +0000 | |
commit | d815d848cd83cfb9180286af5bc8a7516f4eafe9 (patch) | |
tree | 5479796e4553cea9ea98d15450d9bffbcc41774a /filters/provider/src/test/java/org | |
parent | 5439ed46b5392671137d4f73445f075e47938191 (diff) |
update filters
replace legacy filters with common filters
Issue-ID: CCSDK-1698
Signed-off-by: Smokowski, Kevin (ks6305) <kevin.smokowski@att.com>
Change-Id: Id6b1f003f19105956d221d5bfd31390ac096c9bc
Diffstat (limited to 'filters/provider/src/test/java/org')
3 files changed, 23 insertions, 236 deletions
diff --git a/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/ControllerAuditLogFilterTest.java b/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/ControllerAuditLogFilterTest.java new file mode 100644 index 00000000..9d0357a9 --- /dev/null +++ b/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/ControllerAuditLogFilterTest.java @@ -0,0 +1,23 @@ +package org.onap.ccsdk.sli.core.filters; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; + +public class ControllerAuditLogFilterTest { + + @Test + public void getSimpleSiid() throws Exception { + ControllerAuditLogFilter filter = new ControllerAuditLogFilter(); + String siid = filter.getServiceInstanceId("/restconf/config/Layer3API:services/service-list/100"); + assertEquals("100", siid); + } + + @Test + public void getSimpleComplexSiid() throws Exception { + ControllerAuditLogFilter filter = new ControllerAuditLogFilter(); + String siid = filter.getServiceInstanceId( + "/restconf/config/Layer3API:services/service-list/1337/service-data/oper-status"); + assertEquals("1337", siid); + } + +} diff --git a/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/TestLogFilter.java b/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/TestLogFilter.java deleted file mode 100644 index a900b246..00000000 --- a/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/TestLogFilter.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * - */ -package org.onap.ccsdk.sli.core.filters; - -import static org.junit.Assert.*; -import org.apache.commons.codec.binary.Base64; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import static org.mockito.Mockito.*; -import java.io.IOException; -import java.util.UUID; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * @author dt5972 - * - */ -public class TestLogFilter { - - LogFilter logFilter; - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - logFilter = new LogFilter(); - logFilter.init(null); - } - - /** - * @throws java.lang.Exception - */ - @After - public void tearDown() throws Exception { - logFilter.destroy(); - } - - /** - * Test method for {@link org.onap.ccsdk.sli.core.filters.LogFilter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)}. - * @throws ServletException - * @throws IOException - */ - @Test - public void testDoFilter() throws IOException, ServletException { - - // Test failed request with minimal headers - HttpServletRequest servletReq = mock(HttpServletRequest.class); - when(servletReq.getRequestURL()).thenReturn(new StringBuffer("SLI-API:healthcheck")); - when(servletReq.getPathInfo()).thenReturn("/hello:world"); - HttpServletResponse servletResp = mock(HttpServletResponse.class); - when(servletResp.getStatus()).thenReturn(400); - FilterChain filterChain = mock(FilterChain.class); - logFilter.doFilter(servletReq, servletResp, filterChain); - - // Test successful request with valid header - when(servletReq.getHeader(LogFilter.REQUEST_ID)).thenReturn(UUID.randomUUID().toString()); - when(servletReq.getHeader("Authorization")).thenReturn("Basic "+Base64.encodeBase64String("username:password".getBytes())); - when(servletResp.getStatus()).thenReturn(200); - logFilter.doFilter(servletReq, servletResp, filterChain); - - - } - -} diff --git a/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/TestRequestResponseLoggingFilter.java b/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/TestRequestResponseLoggingFilter.java deleted file mode 100644 index 7ce856e6..00000000 --- a/filters/provider/src/test/java/org/onap/ccsdk/sli/core/filters/TestRequestResponseLoggingFilter.java +++ /dev/null @@ -1,165 +0,0 @@ -/** - * - */ -package org.onap.ccsdk.sli.core.filters; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.StringBufferInputStream; -import java.io.StringReader; -import java.util.LinkedList; -import java.util.UUID; -import java.util.Vector; -import javax.servlet.FilterChain; -import javax.servlet.ReadListener; -import javax.servlet.ServletException; -import javax.servlet.ServletInputStream; -import javax.servlet.ServletOutputStream; -import javax.servlet.WriteListener; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.apache.commons.codec.binary.Base64; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -/** - * @author dt5972 - * - */ -public class TestRequestResponseLoggingFilter { - - RequestResponseLoggingFilter filter; - - private class DummyServletInputStream extends ServletInputStream { - - InputStream stream; - - public DummyServletInputStream(InputStream stream) { - this.stream = stream; - } - - - @Override - public void close() throws IOException { - super.close(); - stream.close(); - } - - - @Override - public int read() throws IOException { - return stream.read(); - } - - - @Override - public boolean isFinished() { - try { - return stream.available() < 1; - } catch (IOException e) { - return true; - } - } - - - @Override - public boolean isReady() { - // TODO Auto-generated method stub - return true; - } - - - @Override - public void setReadListener(ReadListener arg0) { - // TODO Auto-generated method stub - - } - - - - } - - private class DummyServletOutputStream extends ServletOutputStream { - - OutputStream ostr; - - public DummyServletOutputStream(OutputStream ostr) { - this.ostr = ostr; - } - - @Override - public void write(int b) throws IOException { - ostr.write(b); - } - - @Override - public boolean isReady() { - return true; - } - - @Override - public void setWriteListener(WriteListener arg0) { - - } - - } - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - filter = new RequestResponseLoggingFilter(); - filter.init(null); - } - - /** - * @throws java.lang.Exception - */ - @After - public void tearDown() throws Exception {} - - /** - * Test method for {@link org.onap.ccsdk.sli.core.filters.RequestResponseLoggingFilter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)}. - * @throws IOException - * @throws ServletException - */ - @Test - public void testDoFilter() throws IOException, ServletException { - - HttpServletRequest request = mock(HttpServletRequest.class); - String msgBody = "hello world"; - InputStream reqInputStream = new ByteArrayInputStream(msgBody.getBytes()); - when(request.getInputStream()).thenReturn(new DummyServletInputStream(reqInputStream)); - when(request.getMethod()).thenReturn("POST"); - when(request.getRequestURL()).thenReturn(new StringBuffer("/HELLO:world")); - when(request.getPathInfo()).thenReturn("/hello:world"); - Vector<String> headerList = new Vector<>(); - headerList.add(LogFilter.REQUEST_ID); - headerList.add("Authorization"); - when(request.getHeaderNames()).thenReturn(headerList.elements()); - - when(request.getHeader(LogFilter.REQUEST_ID)).thenReturn(UUID.randomUUID().toString()); - when(request.getHeader("Authorization")).thenReturn("Basic "+Base64.encodeBase64String("username:password".getBytes())); - - HttpServletResponse response = mock(HttpServletResponse.class); - OutputStream outStr = new ByteArrayOutputStream(); - when(response.getOutputStream()).thenReturn(new DummyServletOutputStream(outStr)); - - FilterChain filterChain = mock(FilterChain.class); - - filter.doFilter(request, response, filterChain); - - - - } - -} |