diff options
Diffstat (limited to 'datarouter-prov/src/test/java')
4 files changed, 61 insertions, 45 deletions
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java index 99142ac9..757852aa 100644 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java @@ -24,29 +24,23 @@ package org.onap.dmaap.datarouter.provisioning; import org.apache.commons.lang3.reflect.FieldUtils; -import org.apache.log4j.Logger; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.runners.MockitoJUnitRunner; -import org.onap.dmaap.datarouter.provisioning.utils.DB; import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.util.HashSet; -import java.util.Properties; import java.util.Set; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) -public class BaseServletTest { +public class BaseServletTest extends DrServletTestBase { private BaseServlet baseServlet; @@ -55,13 +49,7 @@ public class BaseServletTest { @Before public void setUp() throws Exception { - Properties props = new Properties(); - props.setProperty("org.onap.dmaap.datarouter.provserver.isaddressauthenabled", "false"); - FieldUtils.writeDeclaredStaticField(DB.class, "props", props, true); - FieldUtils.writeDeclaredStaticField(BaseServlet.class, "startmsgFlag", false, true); - SynchronizerTask synchronizerTask = mock(SynchronizerTask.class); - when(synchronizerTask.getState()).thenReturn(SynchronizerTask.UNKNOWN); - FieldUtils.writeDeclaredStaticField(BaseServlet.class, "synctask", synchronizerTask, true); + super.setUp(); baseServlet = new BaseServlet(); } diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java new file mode 100644 index 00000000..cf035121 --- /dev/null +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * ============LICENSE_START================================================== + * * org.onap.dmaap + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ + +package org.onap.dmaap.datarouter.provisioning; + +import org.apache.commons.lang3.reflect.FieldUtils; +import org.junit.After; +import org.junit.Before; +import org.onap.dmaap.datarouter.provisioning.utils.DB; +import java.util.Properties; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class DrServletTestBase { + + @Before + public void setUp() throws Exception { + Properties props = new Properties(); + props.setProperty("org.onap.dmaap.datarouter.provserver.isaddressauthenabled", "false"); + FieldUtils.writeDeclaredStaticField(DB.class, "props", props, true); + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "startmsgFlag", false, true); + SynchronizerTask synchronizerTask = mock(SynchronizerTask.class); + when(synchronizerTask.getState()).thenReturn(SynchronizerTask.UNKNOWN); + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "synctask", synchronizerTask, true); + } + + @After + public void tearDown() throws Exception { + + } +} diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java index bf0c2b70..d65b1f97 100644 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java @@ -32,7 +32,6 @@ import org.onap.dmaap.datarouter.authz.AuthorizationResponse; import org.onap.dmaap.datarouter.authz.Authorizer; import org.onap.dmaap.datarouter.provisioning.beans.Feed; import org.onap.dmaap.datarouter.provisioning.beans.Updateable; -import org.onap.dmaap.datarouter.provisioning.utils.DB; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; import org.powermock.modules.junit4.PowerMockRunner; @@ -42,7 +41,6 @@ import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.HashSet; -import java.util.Properties; import java.util.Set; import static org.hamcrest.Matchers.notNullValue; @@ -52,7 +50,7 @@ import static org.onap.dmaap.datarouter.provisioning.BaseServlet.BEHALF_HEADER; @RunWith(PowerMockRunner.class) @SuppressStaticInitializationFor("org.onap.dmaap.datarouter.provisioning.beans.Feed") -public class FeedServletTest { +public class FeedServletTest extends DrServletTestBase { private static FeedServlet feedServlet; @@ -63,7 +61,7 @@ public class FeedServletTest { @Before public void setUp() throws Exception { - initialiseBaseServletToBypassRetreiviingInitialisationParametersFromDatabase(); + super.setUp(); feedServlet = new FeedServlet(); setAuthoriserToReturnRequestIsAuthorized(); setPokerToNotCreateTimersWhenDeleteFeedIsCalled(); @@ -248,18 +246,6 @@ public class FeedServletTest { verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class))); } - - private void initialiseBaseServletToBypassRetreiviingInitialisationParametersFromDatabase() - throws IllegalAccessException { - Properties props = new Properties(); - props.setProperty("org.onap.dmaap.datarouter.provserver.isaddressauthenabled", "false"); - FieldUtils.writeDeclaredStaticField(DB.class, "props", props, true); - FieldUtils.writeDeclaredStaticField(BaseServlet.class, "startmsgFlag", false, true); - SynchronizerTask synchronizerTask = mock(SynchronizerTask.class); - when(synchronizerTask.getState()).thenReturn(SynchronizerTask.UNKNOWN); - FieldUtils.writeDeclaredStaticField(SynchronizerTask.class, "synctask", synchronizerTask, true); - } - private void setUpValidSecurityOnHttpRequest() throws Exception { when(request.isSecure()).thenReturn(true); Set<String> authAddressesAndNetworks = new HashSet<String>(); diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/GroupServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/GroupServletTest.java index 1646fba7..ed0e2572 100755 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/GroupServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/GroupServletTest.java @@ -42,7 +42,6 @@ import javax.servlet.ServletInputStream; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - import java.util.HashSet; import java.util.Set; @@ -50,14 +49,12 @@ import static org.hamcrest.Matchers.notNullValue; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.argThat; import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import static org.onap.dmaap.datarouter.provisioning.BaseServlet.BEHALF_HEADER; @RunWith(PowerMockRunner.class) @SuppressStaticInitializationFor("org.onap.dmaap.datarouter.provisioning.beans.Group") -public class GroupServletTest { +public class GroupServletTest extends DrServletTestBase { private GroupServlet groupServlet; @Mock @@ -68,7 +65,7 @@ public class GroupServletTest { @Before public void setUp() throws Exception { - initialiseBaseServletToBypassRetreiviingInitialisationParametersFromDatabase(); + super.setUp(); groupServlet = new GroupServlet(); setAuthoriserToReturnRequestIsAuthorized(); setPokerToNotCreateTimersWhenDeleteFeedIsCalled(); @@ -245,13 +242,6 @@ public class GroupServletTest { verify(response).sendError(eq(HttpServletResponse.SC_METHOD_NOT_ALLOWED), argThat(notNullValue(String.class))); } - private void initialiseBaseServletToBypassRetreiviingInitialisationParametersFromDatabase() throws IllegalAccessException { - FieldUtils.writeDeclaredStaticField(BaseServlet.class, "startmsg_flag", false, true); - SynchronizerTask synchronizerTask = mock(SynchronizerTask.class); - when(synchronizerTask.getState()).thenReturn(SynchronizerTask.UNKNOWN); - FieldUtils.writeDeclaredStaticField(BaseServlet.class, "synctask", synchronizerTask, true); - } - private void setAuthoriserToReturnRequestIsAuthorized() throws IllegalAccessException { AuthorizationResponse authResponse = mock(AuthorizationResponse.class); Authorizer authorizer = mock(Authorizer.class); @@ -262,7 +252,7 @@ public class GroupServletTest { private void setPokerToNotCreateTimersWhenDeleteFeedIsCalled() throws Exception { Poker poker = mock(Poker.class); - FieldUtils.writeDeclaredStaticField(Poker.class, "p", poker, true); + FieldUtils.writeDeclaredStaticField(Poker.class, "poker", poker, true); } private void setUpValidAuthorisedRequest() throws Exception { @@ -277,7 +267,7 @@ public class GroupServletTest { Set<String> authAddressesAndNetworks = new HashSet<String>(); authAddressesAndNetworks.add(("127.0.0.1")); FieldUtils.writeDeclaredStaticField(BaseServlet.class, "authorizedAddressesAndNetworks", authAddressesAndNetworks, true); - FieldUtils.writeDeclaredStaticField(BaseServlet.class, "require_cert", false, true); + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "requireCert", false, true); } private void setBehalfHeader(String headerValue) { |