X-Git-Url: https://gerrit.onap.org/r/gitweb?p=dmaap%2Fdatarouter.git;a=blobdiff_plain;f=datarouter-prov%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fprovisioning%2FSubscriptionServletTest.java;h=4a410dddbccff7c2d9b4f2525b9d465e3e373032;hp=a0514a697ca5335a61cd47775741ce7664adfd84;hb=98572b78fcce9ff28fa7429c9265812bd1e78bf2;hpb=118900e50d71a3db8bd6e304151cc7c20b4fbda9 diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java old mode 100644 new mode 100755 index a0514a69..4a410ddd --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java @@ -22,28 +22,37 @@ ******************************************************************************/ package org.onap.dmaap.datarouter.provisioning; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.read.ListAppender; import org.apache.commons.lang3.reflect.FieldUtils; import org.jetbrains.annotations.NotNull; -import org.json.JSONArray; import org.json.JSONObject; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.onap.dmaap.datarouter.authz.AuthorizationResponse; import org.onap.dmaap.datarouter.authz.Authorizer; import org.onap.dmaap.datarouter.provisioning.beans.Deleteable; -import org.onap.dmaap.datarouter.provisioning.beans.Insertable; +import org.onap.dmaap.datarouter.provisioning.beans.SubDelivery; import org.onap.dmaap.datarouter.provisioning.beans.Subscription; import org.onap.dmaap.datarouter.provisioning.beans.Updateable; +import org.onap.dmaap.datarouter.provisioning.utils.DB; +import org.onap.dmaap.datarouter.provisioning.utils.PasswordProcessor; import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; +import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; import javax.servlet.ServletInputStream; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.sql.SQLException; import java.util.HashSet; import java.util.Set; @@ -53,19 +62,45 @@ import static org.onap.dmaap.datarouter.provisioning.BaseServlet.BEHALF_HEADER; @RunWith(PowerMockRunner.class) -@SuppressStaticInitializationFor("org.onap.dmaap.datarouter.provisioning.beans.Subscription") -public class SubscriptionServletTest extends DrServletTestBase{ +@PrepareForTest(PasswordProcessor.class) +public class SubscriptionServletTest extends DrServletTestBase { + private static EntityManagerFactory emf; + private static EntityManager em; private SubscriptionServlet subscriptionServlet; + private DB db; + private final String URL= "https://172.100.0.5"; + private final String USER = "user1"; + private final String PASSWORD="password1"; + @Mock private HttpServletRequest request; @Mock private HttpServletResponse response; + private ListAppender listAppender; + + @BeforeClass + public static void init() { + emf = Persistence.createEntityManagerFactory("dr-unit-tests"); + em = emf.createEntityManager(); + System.setProperty( + "org.onap.dmaap.datarouter.provserver.properties", + "src/test/resources/h2Database.properties"); + } + + @AfterClass + public static void tearDownClass() { + em.clear(); + em.close(); + emf.close(); + } + @Before public void setUp() throws Exception { - super.setUp(); + listAppender = setTestLogger(SubscriptionServlet.class); subscriptionServlet = new SubscriptionServlet(); + db = new DB(); setAuthoriserToReturnRequestIsAuthorized(); setPokerToNotCreateTimersWhenDeleteSubscriptionIsCalled(); setupValidAuthorisedRequest(); @@ -77,6 +112,7 @@ public class SubscriptionServletTest extends DrServletTestBase{ when(request.isSecure()).thenReturn(false); subscriptionServlet.doDelete(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); + verifyEnteringExitCalled(listAppender); } @Test @@ -95,7 +131,7 @@ public class SubscriptionServletTest extends DrServletTestBase{ @Test public void Given_Request_Is_HTTP_DELETE_And_Subscription_Id_Is_Invalid_Then_Not_Found_Response_Is_Generated() throws Exception { - setSubscriptionToReturnInvalidSubscriptionIdSupplied(); + when(request.getPathInfo()).thenReturn("/123"); subscriptionServlet.doDelete(request, response); verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), argThat(notNullValue(String.class))); } @@ -119,14 +155,22 @@ public class SubscriptionServletTest extends DrServletTestBase{ } @Test - public void Given_Request_Is_HTTP_DELETE_And_Delete_On_Database_Succeeds_A_NO_CONTENT_Response_Is_Generated() throws Exception { - SubscriptionServlet subscriptionServlet = new SubscriptionServlet(){ - public boolean doDelete(Deleteable deletable){ - return true; - } - }; + public void Given_Request_Is_HTTP_DELETE_And_AAF_CADI_Is_Enabled_Without_Permissions_Then_Forbidden_Response_Is_Generated() throws Exception { + when(request.getHeader("Content-Type")).thenReturn("application/vnd.dmaap-dr.subscription; version=1.0"); + when(request.getPathInfo()).thenReturn("/2"); + subscriptionServlet.doDelete(request, response); + verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), contains("AAF disallows access")); + } + + @Test + public void Given_Request_Is_HTTP_DELETE_And_AAF_CADI_Is_Enabled_With_Permissions_Then_A_NO_CONTENT_Response_Is_Generated() throws Exception { + when(request.getHeader("Content-Type")).thenReturn("application/vnd.dmaap-dr.subscription; version=1.0"); + when(request.getPathInfo()).thenReturn("/2"); + when(request.isUserInRole("org.onap.dmaap-dr.sub|*|delete")).thenReturn(true); subscriptionServlet.doDelete(request, response); verify(response).setStatus(eq(HttpServletResponse.SC_NO_CONTENT)); + verifyEnteringExitCalled(listAppender); + resetAafSubscriptionInDB(); } @Test @@ -134,6 +178,7 @@ public class SubscriptionServletTest extends DrServletTestBase{ when(request.isSecure()).thenReturn(false); subscriptionServlet.doGet(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); + verifyEnteringExitCalled(listAppender); } @Test @@ -152,7 +197,7 @@ public class SubscriptionServletTest extends DrServletTestBase{ @Test public void Given_Request_Is_HTTP_GET_And_Subscription_Id_Is_Invalid_Then_Not_Found_Response_Is_Generated() throws Exception { - setSubscriptionToReturnInvalidSubscriptionIdSupplied(); + when(request.getPathInfo()).thenReturn("/123"); subscriptionServlet.doGet(request, response); verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), argThat(notNullValue(String.class))); } @@ -166,20 +211,11 @@ public class SubscriptionServletTest extends DrServletTestBase{ @Test public void Given_Request_Is_HTTP_GET_And_Request_Succeeds() throws Exception { - JSONObject JSObject = buildRequestJsonObject(); - JSONObject jo = new JSONObject(); - jo.put("name", "stub_name"); - jo.put("version", "2.0"); - jo.put("metadataOnly", true); - jo.put("suspend", true); - jo.put("delivery", JSObject); - Subscription sub = new Subscription(jo); - PowerMockito.mockStatic(Subscription.class); - PowerMockito.when(Subscription.getSubscriptionById(anyInt())).thenReturn(sub); ServletOutputStream outStream = mock(ServletOutputStream.class); when(response.getOutputStream()).thenReturn(outStream); subscriptionServlet.doGet(request, response); verify(response).setStatus(eq(HttpServletResponse.SC_OK)); + verifyEnteringExitCalled(listAppender); } @Test @@ -187,6 +223,7 @@ public class SubscriptionServletTest extends DrServletTestBase{ when(request.isSecure()).thenReturn(false); subscriptionServlet.doPut(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); + verifyEnteringExitCalled(listAppender); } @Test @@ -205,7 +242,7 @@ public class SubscriptionServletTest extends DrServletTestBase{ @Test public void Given_Request_Is_HTTP_PUT_And_Subscription_Id_Is_Invalid_Then_Not_Found_Response_Is_Generated() throws Exception { - setSubscriptionToReturnInvalidSubscriptionIdSupplied(); + when(request.getPathInfo()).thenReturn("/123"); subscriptionServlet.doPut(request, response); verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), argThat(notNullValue(String.class))); } @@ -213,10 +250,83 @@ public class SubscriptionServletTest extends DrServletTestBase{ @Test public void Given_Request_Is_HTTP_PUT_And_Request_Is_Not_Authorized_Then_Forbidden_Response_Is_Generated() throws Exception { setAuthoriserToReturnRequestNotAuthorized(); + when(request.getHeader("Content-Type")).thenReturn("application/vnd.dmaap-dr.subscription; version=1.0"); + JSONObject JSObject = buildRequestJsonObject(); + SubscriptionServlet subscriptionServlet = new SubscriptionServlet() { + protected JSONObject getJSONfromInput(HttpServletRequest req) { + JSONObject jo = new JSONObject(); + jo.put("name", "stub_name"); + jo.put("version", "2.0"); + jo.put("metadataOnly", true); + jo.put("suspend", true); + jo.put("delivery", JSObject); + jo.put("aaf_instance", "legacy"); + jo.put("follow_redirect", false); + jo.put("decompress", true); + jo.put("sync", true); + jo.put("changeowner", true); + return jo; + } + }; subscriptionServlet.doPut(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); } + @Test + public void Given_Request_Is_HTTP_PUT_And_AAF_CADI_Is_Enabled_Without_Permissions_Then_Forbidden_Response_Is_Generated() throws Exception { + when(request.getHeader("Content-Type")).thenReturn("application/vnd.dmaap-dr.subscription; version=1.0"); + when(request.getPathInfo()).thenReturn("/3"); + JSONObject JSObject = buildRequestJsonObject(); + SubscriptionServlet subscriptionServlet = new SubscriptionServlet() { + protected JSONObject getJSONfromInput(HttpServletRequest req) { + JSONObject jo = new JSONObject(); + jo.put("name", "stub_name"); + jo.put("version", "2.0"); + jo.put("metadataOnly", true); + jo.put("suspend", true); + jo.put("delivery", JSObject); + jo.put("aaf_instance", "*"); + jo.put("follow_redirect", false); + jo.put("sync", true); + jo.put("changeowner", true); + return jo; + } + }; + subscriptionServlet.doPut(request, response); + verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), contains("AAF disallows access")); + } + + @Test + public void Given_Request_Is_HTTP_PUT_And_AAF_CADI_Is_Enabled_With_Permissions_Then_OK_Response_Is_Generated() throws Exception { + ServletOutputStream outStream = mock(ServletOutputStream.class); + when(response.getOutputStream()).thenReturn(outStream); + when(request.getHeader("X-DMAAP-DR-ON-BEHALF-OF-GROUP")).thenReturn("stub_subjectGroup"); + when(request.getHeader("Content-Type")).thenReturn("application/vnd.dmaap-dr.subscription; version=1.0"); + when(request.getPathInfo()).thenReturn("/3"); + when(request.isUserInRole("org.onap.dmaap-dr.sub|*|edit")).thenReturn(true); + PowerMockito.mockStatic(PasswordProcessor.class); + JSONObject JSObject = buildRequestJsonObject(); + SubscriptionServlet subscriptionServlet = new SubscriptionServlet() { + protected JSONObject getJSONfromInput(HttpServletRequest req) { + JSONObject jo = new JSONObject(); + jo.put("name", "stub_name"); + jo.put("version", "2.0"); + jo.put("metadataOnly", true); + jo.put("suspend", true); + jo.put("delivery", JSObject); + jo.put("aaf_instance", "*"); + jo.put("follow_redirect", false); + jo.put("sync", true); + return jo; + } + }; + subscriptionServlet.doPut(request, response); + verify(response).setStatus(eq(HttpServletResponse.SC_OK)); + resetAafSubscriptionInDB(); + addNewSubscriptionInDB(); + verifyEnteringExitCalled(listAppender); + } + @Test public void Given_Request_Is_HTTP_PUT_And_Content_Header_Is_Not_Supported_Type_Then_Unsupported_Media_Type_Response_Is_Generated() throws Exception { when(request.getContentType()).thenReturn("stub_ContentType"); @@ -226,7 +336,7 @@ public class SubscriptionServletTest extends DrServletTestBase{ @Test public void Given_Request_Is_HTTP_PUT_And_Request_Contains_Badly_Formed_JSON_Then_Bad_Request_Response_Is_Generated() throws Exception { - when(request.getHeader("Content-Type")).thenReturn("application/vnd.att-dr.subscription; version=1.0"); + when(request.getHeader("Content-Type")).thenReturn("application/vnd.dmaap-dr.subscription; version=1.0"); ServletInputStream inStream = mock(ServletInputStream.class); when(request.getInputStream()).thenReturn(inStream); subscriptionServlet.doPut(request, response); @@ -235,7 +345,7 @@ public class SubscriptionServletTest extends DrServletTestBase{ @Test public void Given_Request_Is_HTTP_PUT_And_Subscription_Object_Is_Invalid_Bad_Request_Response_Is_Generated() throws Exception { - when(request.getHeader("Content-Type")).thenReturn("application/vnd.att-dr.subscription; version=1.0"); + when(request.getHeader("Content-Type")).thenReturn("application/vnd.dmaap-dr.subscription; version=1.0"); SubscriptionServlet subscriptionServlet = new SubscriptionServlet() { protected JSONObject getJSONfromInput(HttpServletRequest req) { JSONObject jo = new JSONObject(); @@ -247,9 +357,9 @@ public class SubscriptionServletTest extends DrServletTestBase{ } @Test - public void Given_Request_Is_HTTP_PUT_And_Subscriber_Modified_By_Different_Creator() throws Exception { - when(request.getHeader("X-ATT-DR-ON-BEHALF-OF-GROUP")).thenReturn(null); - when(request.getHeader("Content-Type")).thenReturn("application/vnd.att-dr.subscription; version=1.0"); + public void Given_Request_Is_HTTP_PUT_And_Subscriber_Modified_By_Different_Creator_Then_Bad_Request_Is_Generated() throws Exception { + when(request.getHeader("X-DMAAP-DR-ON-BEHALF-OF-GROUP")).thenReturn(null); + when(request.getHeader("Content-Type")).thenReturn("application/vnd.dmaap-dr.subscription; version=1.0"); JSONObject JSObject = buildRequestJsonObject(); SubscriptionServlet subscriptionServlet = new SubscriptionServlet() { protected JSONObject getJSONfromInput(HttpServletRequest req) { @@ -258,7 +368,13 @@ public class SubscriptionServletTest extends DrServletTestBase{ jo.put("version", "2.0"); jo.put("metadataOnly", true); jo.put("suspend", true); + jo.put("privilegedSubscriber", true); + jo.put("decompress", true); jo.put("delivery", JSObject); + jo.put("aaf_instance", "legacy"); + jo.put("follow_redirect", false); + jo.put("subscriber", "differentSubscriber"); + jo.put("sync", true); return jo; } }; @@ -268,8 +384,8 @@ public class SubscriptionServletTest extends DrServletTestBase{ @Test public void Given_Request_Is_HTTP_PUT_And_Update_Fails() throws Exception { - when(request.getHeader("X-ATT-DR-ON-BEHALF-OF-GROUP")).thenReturn("stub_subjectGroup"); - when(request.getHeader("Content-Type")).thenReturn("application/vnd.att-dr.subscription; version=1.0"); + when(request.getHeader("X-DMAAP-DR-ON-BEHALF-OF-GROUP")).thenReturn("stub_subjectGroup"); + when(request.getHeader("Content-Type")).thenReturn("application/vnd.dmaap-dr.subscription; version=1.0"); JSONObject JSObject = buildRequestJsonObject(); SubscriptionServlet subscriptionServlet = new SubscriptionServlet() { protected JSONObject getJSONfromInput(HttpServletRequest req) { @@ -278,7 +394,12 @@ public class SubscriptionServletTest extends DrServletTestBase{ jo.put("version", "2.0"); jo.put("metadataOnly", true); jo.put("suspend", true); + jo.put("privilegedSubscriber", true); jo.put("delivery", JSObject); + jo.put("aaf_instance", "legacy"); + jo.put("decompress", true); + jo.put("follow_redirect", false); + jo.put("sync", true); return jo; } @@ -295,8 +416,9 @@ public class SubscriptionServletTest extends DrServletTestBase{ public void Given_Request_Is_HTTP_PUT_And_Update_Succeeds() throws Exception { ServletOutputStream outStream = mock(ServletOutputStream.class); when(response.getOutputStream()).thenReturn(outStream); - when(request.getHeader("X-ATT-DR-ON-BEHALF-OF-GROUP")).thenReturn("stub_subjectGroup"); - when(request.getHeader("Content-Type")).thenReturn("application/vnd.att-dr.subscription; version=1.0"); + when(request.getHeader("X-DMAAP-DR-ON-BEHALF-OF-GROUP")).thenReturn("stub_subjectGroup"); + when(request.getHeader("Content-Type")).thenReturn("application/vnd.dmaap-dr.subscription; version=1.0"); + PowerMockito.mockStatic(PasswordProcessor.class); JSONObject JSObject = buildRequestJsonObject(); SubscriptionServlet subscriptionServlet = new SubscriptionServlet() { protected JSONObject getJSONfromInput(HttpServletRequest req) { @@ -305,17 +427,20 @@ public class SubscriptionServletTest extends DrServletTestBase{ jo.put("version", "2.0"); jo.put("metadataOnly", true); jo.put("suspend", true); + jo.put("privilegedSubscriber", true); + jo.put("decompress", true); jo.put("delivery", JSObject); + jo.put("aaf_instance", "legacy"); + jo.put("follow_redirect", false); + jo.put("sync", true); + jo.put("changeowner", true); return jo; } - - @Override - protected boolean doUpdate(Updateable bean) { - return true; - } }; subscriptionServlet.doPut(request, response); verify(response).setStatus(eq(HttpServletResponse.SC_OK)); + changeSubscriptionBackToNormal(); + verifyEnteringExitCalled(listAppender); } @Test @@ -323,6 +448,7 @@ public class SubscriptionServletTest extends DrServletTestBase{ when(request.isSecure()).thenReturn(false); subscriptionServlet.doPost(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); + verifyEnteringExitCalled(listAppender); } @Test @@ -341,7 +467,7 @@ public class SubscriptionServletTest extends DrServletTestBase{ @Test public void Given_Request_Is_HTTP_POST_And_Subscription_Id_Is_Invalid_Then_Not_Found_Response_Is_Generated() throws Exception { - setSubscriptionToReturnInvalidSubscriptionIdSupplied(); + when(request.getPathInfo()).thenReturn("/123"); subscriptionServlet.doPost(request, response); verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class))); } @@ -355,7 +481,7 @@ public class SubscriptionServletTest extends DrServletTestBase{ @Test public void Given_Request_Is_HTTP_POST_And_Request_Is_Not_Authorized_Then_Forbidden_Response_Is_Generated() throws Exception { - when(request.getHeader(anyString())).thenReturn("application/vnd.att-dr.subscription-control"); + when(request.getHeader(anyString())).thenReturn("application/vnd.dmaap-dr.subscription-control"); setAuthoriserToReturnRequestNotAuthorized(); subscriptionServlet.doPost(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); @@ -363,7 +489,7 @@ public class SubscriptionServletTest extends DrServletTestBase{ @Test public void Given_Request_Is_HTTP_POST_And_Request_Contains_Badly_Formed_JSON_Then_Bad_Request_Response_Is_Generated() throws Exception { - when(request.getHeader("Content-Type")).thenReturn("application/vnd.att-dr.subscription-control; version=1.0"); + when(request.getHeader("Content-Type")).thenReturn("application/vnd.dmaap-dr.subscription-control; version=1.0"); ServletInputStream inStream = mock(ServletInputStream.class); when(request.getInputStream()).thenReturn(inStream); subscriptionServlet.doPost(request, response); @@ -372,8 +498,8 @@ public class SubscriptionServletTest extends DrServletTestBase{ @Test public void Given_Request_Is_HTTP_POST_And_Post_Fails() throws Exception { - when(request.getHeader("X-ATT-DR-ON-BEHALF-OF-GROUP")).thenReturn("stub_subjectGroup"); - when(request.getHeader("Content-Type")).thenReturn("application/vnd.att-dr.subscription-control; version=1.0"); + when(request.getHeader("X-DMAAP-DR-ON-BEHALF-OF-GROUP")).thenReturn("stub_subjectGroup"); + when(request.getHeader("Content-Type")).thenReturn("application/vnd.dmaap-dr.subscription-control; version=1.0"); JSONObject JSObject = buildRequestJsonObject(); SubscriptionServlet subscriptionServlet = new SubscriptionServlet() { protected JSONObject getJSONfromInput(HttpServletRequest req) { @@ -394,8 +520,8 @@ public class SubscriptionServletTest extends DrServletTestBase{ public void Given_Request_Is_HTTP_POST_And_Post_Succeeds() throws Exception { ServletOutputStream outStream = mock(ServletOutputStream.class); when(response.getOutputStream()).thenReturn(outStream); - when(request.getHeader("X-ATT-DR-ON-BEHALF-OF-GROUP")).thenReturn("stub_subjectGroup"); - when(request.getHeader("Content-Type")).thenReturn("application/vnd.att-dr.subscription-control; version=1.0"); + when(request.getHeader("X-DMAAP-DR-ON-BEHALF-OF-GROUP")).thenReturn("stub_subjectGroup"); + when(request.getHeader("Content-Type")).thenReturn("application/vnd.dmaap-dr.subscription-control; version=1.0"); JSONObject JSObject = buildRequestJsonObject(); SubscriptionServlet subscriptionServlet = new SubscriptionServlet() { protected JSONObject getJSONfromInput(HttpServletRequest req) { @@ -405,12 +531,17 @@ public class SubscriptionServletTest extends DrServletTestBase{ jo.put("metadataOnly", true); jo.put("suspend", true); jo.put("delivery", JSObject); + jo.put("privilegedSubscriber", false); + jo.put("aaf_instance", "legacy"); + jo.put("follow_redirect", false); + jo.put("decompress", false); jo.put("failed", false); return jo; } }; subscriptionServlet.doPost(request, response); verify(response).setStatus(eq(HttpServletResponse.SC_ACCEPTED)); + verifyEnteringExitCalled(listAppender); } @NotNull @@ -423,13 +554,6 @@ public class SubscriptionServletTest extends DrServletTestBase{ return JSObject; } - private void initialiseBaseServletToBypassRetreiviingInitialisationParametersFromDatabase() throws IllegalAccessException { - 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 authAddressesAndNetworks = new HashSet(); @@ -443,20 +567,7 @@ public class SubscriptionServletTest extends DrServletTestBase{ } private void setValidPathInfoInHttpHeader() { - when(request.getPathInfo()).thenReturn("/123"); - } - - private void setSubscriptionToReturnInvalidSubscriptionIdSupplied() { - PowerMockito.mockStatic(Subscription.class); - PowerMockito.when(Subscription.getSubscriptionById(anyInt())).thenReturn(null); - } - - private void setSubscriptionToReturnValidSubscriptionForSuppliedId() { - PowerMockito.mockStatic(Subscription.class); - Subscription subscription = mock(Subscription.class); - PowerMockito.when(Subscription.getSubscriptionById(anyInt())).thenReturn(subscription); - when(subscription.getSubscriber()).thenReturn("Stub_Value"); - when(subscription.asJSONObject()).thenReturn(mock(JSONObject.class)); + when(request.getPathInfo()).thenReturn("/1"); } private void setAuthoriserToReturnRequestNotAuthorized() throws IllegalAccessException { @@ -484,6 +595,51 @@ public class SubscriptionServletTest extends DrServletTestBase{ setUpValidSecurityOnHttpRequest(); setBehalfHeader("Stub_Value"); setValidPathInfoInHttpHeader(); - setSubscriptionToReturnValidSubscriptionForSuppliedId(); + } + + private void changeSubscriptionBackToNormal() throws SQLException { + Subscription subscription = new Subscription("https://172.100.0.5", "user1", "password1"); + subscription.setSubid(1); + subscription.setSubscriber("user1"); + subscription.setFeedid(1); + SubDelivery subDelivery = new SubDelivery(URL, USER, PASSWORD, true); + subscription.setDelivery(subDelivery); + subscription.setGroupid(1); + subscription.setMetadataOnly(false); + subscription.setSuspended(false); + subscription.setPrivilegedSubscriber(false); + subscription.setDecompress(false); + subscription.changeOwnerShip(); + subscription.doUpdate(db.getConnection()); + } + + private void resetAafSubscriptionInDB() throws SQLException { + Subscription subscription = new Subscription("https://172.100.0.5:8080", "user2", "password2"); + subscription.setSubid(2); + subscription.setSubscriber("user2"); + subscription.setFeedid(1); + SubDelivery subDelivery = new SubDelivery(URL, USER, PASSWORD, true); + subscription.setDelivery(subDelivery); + subscription.setGroupid(1); + subscription.setMetadataOnly(false); + subscription.setSuspended(false); + subscription.setAafInstance("https://aaf-onap-test.osaaf.org:8095"); + subscription.setDecompress(false); + subscription.setPrivilegedSubscriber(false); + subscription.doUpdate(db.getConnection()); + } + + private void addNewSubscriptionInDB() throws SQLException { + Subscription subscription = new Subscription("https://172.100.0.6:8080", "user3", "password3"); + subscription.setSubid(3); + subscription.setSubscriber("user3"); + subscription.setFeedid(1); + SubDelivery subDelivery = new SubDelivery(URL, USER, PASSWORD, true); + subscription.setDelivery(subDelivery); + subscription.setGroupid(1); + subscription.setMetadataOnly(false); + subscription.setSuspended(false); + subscription.setDecompress(false); + subscription.doInsert(db.getConnection()); } } \ No newline at end of file