+++ /dev/null
-/*\r
- * ============LICENSE_START=======================================================\r
- * Copyright (C) 2019 Nordix Foundation.\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * SPDX-License-Identifier: Apache-2.0\r
- * ============LICENSE_END=========================================================\r
- */\r
-\r
-package org.onap.dmaap.datarouter.node;\r
-\r
-import static org.mockito.Mockito.doThrow;\r
-import static org.mockito.Mockito.mock;\r
-import static org.mockito.Mockito.times;\r
-import static org.mockito.Mockito.verify;\r
-import static org.mockito.Mockito.when;\r
-\r
-import java.io.IOException;\r
-import javax.servlet.FilterChain;\r
-import javax.servlet.ServletException;\r
-import javax.servlet.http.HttpServletRequest;\r
-import javax.servlet.http.HttpServletResponse;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.junit.runner.RunWith;\r
-import org.mockito.Mock;\r
-import org.onap.aaf.cadi.PropAccess;\r
-import org.onap.aaf.cadi.filter.CadiFilter;\r
-import org.powermock.api.mockito.PowerMockito;\r
-import org.powermock.api.support.membermodification.MemberMatcher;\r
-import org.powermock.core.classloader.annotations.PowerMockIgnore;\r
-import org.powermock.core.classloader.annotations.PrepareForTest;\r
-import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;\r
-import org.powermock.modules.junit4.PowerMockRunner;\r
-\r
-@SuppressStaticInitializationFor("org.onap.dmaap.datarouter.node.NodeConfigManager")\r
-@PrepareForTest({CadiFilter.class})\r
-@RunWith(PowerMockRunner.class)\r
-@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})\r
-public class DRNodeCadiFilterTest {\r
-\r
- @Mock\r
- private PropAccess access;\r
-\r
- @Mock\r
- private HttpServletRequest request;\r
-\r
- @Mock\r
- private HttpServletResponse response;\r
-\r
- @Mock\r
- private FilterChain chain;\r
-\r
- private DRNodeCadiFilter cadiFilter;\r
-\r
-\r
- @Before\r
- public void setUp() throws ServletException {\r
- cadiFilter = new DRNodeCadiFilter(false, access);\r
- }\r
-\r
- @Test\r
- public void Given_doFilter_Called_And_Method_Is_GET_And_AAF_DB_Instance_Is_NULL_Then_Chain_doFilter_Called()\r
- throws Exception {\r
- PowerMockito.mockStatic(NodeConfigManager.class);\r
- NodeConfigManager config = mock(NodeConfigManager.class);\r
-\r
- PowerMockito.when(NodeConfigManager.getInstance()).thenReturn(config);\r
- PowerMockito.when(config.getAafInstance("/other/5")).thenReturn("legacy");\r
- when(request.getPathInfo()).thenReturn("/publish/5");\r
- when(request.getMethod()).thenReturn("GET");\r
- cadiFilter.doFilter(request, response, chain);\r
- verify(chain, times(1)).doFilter(request, response);\r
- }\r
-\r
- @Test\r
- public void Given_doFilter_Called_And_Method_Is_GET_And_Path_Includes_Internal_Then_Chain_doFilter_Called()\r
- throws Exception {\r
- PowerMockito.mockStatic(NodeConfigManager.class);\r
- NodeConfigManager config = mock(NodeConfigManager.class);\r
-\r
- PowerMockito.when(NodeConfigManager.getInstance()).thenReturn(config);\r
- PowerMockito.when(config.getAafInstance("/other/5")).thenReturn("legacy");\r
- when(request.getPathInfo()).thenReturn("/internal/5");\r
- when(request.getMethod()).thenReturn("GET");\r
- cadiFilter.doFilter(request, response, chain);\r
- verify(chain, times(1)).doFilter(request, response);\r
- }\r
-\r
- @Test\r
- public void Given_doFilter_Called_And_Method_Is_GET_And_AAF_DB_Is_Not_Null_Then_Super_doFilter_Called()\r
- throws Exception {\r
- PowerMockito.mockStatic(NodeConfigManager.class);\r
- NodeConfigManager config = mock(NodeConfigManager.class);\r
-\r
- PowerMockito.when(NodeConfigManager.getInstance()).thenReturn(config);\r
- PowerMockito.when(config.getAafInstance("5")).thenReturn("EXISTS");\r
- when(request.getPathInfo()).thenReturn("/publish/5/fileId");\r
- when(request.getMethod()).thenReturn("GET");\r
- PowerMockito.suppress(MemberMatcher.methodsDeclaredIn(CadiFilter.class));\r
- cadiFilter.doFilter(request, response, chain);\r
- verify(chain, times(0)).doFilter(request, response);\r
- }\r
-\r
- @Test\r
- public void Given_getFileid_Called_And_SendError_Fails_Then_Throw_IOException_And_Call_chain_doFilter()\r
- throws Exception {\r
- PowerMockito.mockStatic(NodeConfigManager.class);\r
- NodeConfigManager config = mock(NodeConfigManager.class);\r
-\r
- PowerMockito.when(NodeConfigManager.getInstance()).thenReturn(config);\r
- when(request.getPathInfo()).thenReturn("/publish/5");\r
- when(request.getMethod()).thenReturn("DELETE");\r
- doThrow(new IOException()).when(response).sendError(HttpServletResponse.SC_NOT_FOUND,\r
- "Invalid request URI. Expecting <feed-publishing-url>/<fileid>. Possible missing fileid.");\r
- cadiFilter.doFilter(request, response, chain);\r
- verify(chain, times(1)).doFilter(request, response);\r
- }\r
-}\r