Change-Id: I42623a0650877fa9747a2f2983b0512bec616437
Signed-off-by: Mariusz Sobucki <mariusz.sobucki@ericsson.com>
Issue-ID: DMAAP-101
@SuppressWarnings("resource")\r
Connection conn = db.getConnection();\r
Statement stmt = conn.createStatement();\r
@SuppressWarnings("resource")\r
Connection conn = db.getConnection();\r
Statement stmt = conn.createStatement();\r
- String sql = "select KEYNAME, VALUE from PARAMETERS where KEYNAME = \"" + k + "\"";\r
+ String sql = "select KEYNAME, VALUE from PARAMETERS where KEYNAME = '" + k + "'";\r
ResultSet rs = stmt.executeQuery(sql);\r
if (rs.next()) {\r
v = new Parameters(rs);\r
ResultSet rs = stmt.executeQuery(sql);\r
if (rs.next()) {\r
v = new Parameters(rs);\r
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.onap.dmaap.datarouter.provisioning.beans.Subscription;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.powermock.modules.junit4.PowerMockRunner;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.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.powermock.api.mockito.PowerMockito.when;
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.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@RunWith(PowerMockRunner.class)
-@SuppressStaticInitializationFor({"org.onap.dmaap.datarouter.provisioning.beans.Subscription"})
public class LogServletTest extends DrServletTestBase {
public class LogServletTest extends DrServletTestBase {
+ private static EntityManagerFactory emf;
+ private static EntityManager em;
private static LogServlet logServlet;
@Mock
private static LogServlet logServlet;
@Mock
@Mock
private HttpServletResponse response;
@Mock
private HttpServletResponse response;
+ @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 {
@Before
public void setUp() throws Exception {
logServlet = new LogServlet(true);
setUpValidParameterValuesForMap();
}
logServlet = new LogServlet(true);
setUpValidParameterValuesForMap();
}
- public void Given_Request_Is_HTTP_GET_And_Has_Bad_Type()
+ public void Given_Request_Is_HTTP_GET_And_Has_Bad_Type_Then_Bad_Request_Response_Is_Generated()
throws Exception {
when(request.getParameter("type")).thenReturn("bad_type");
logServlet.doGet(request, response);
throws Exception {
when(request.getParameter("type")).thenReturn("bad_type");
logServlet.doGet(request, response);
- public void Given_Request_Is_HTTP_GET_And_Has_Bad_PublishID()
+ public void Given_Request_Is_HTTP_GET_And_Has_Bad_PublishID_Then_Bad_Request_Response_Is_Generated()
throws Exception {
when(request.getParameter("publishId")).thenReturn("bad_PublishID'");
logServlet.doGet(request, response);
throws Exception {
when(request.getParameter("publishId")).thenReturn("bad_PublishID'");
logServlet.doGet(request, response);
- public void Given_Request_Is_HTTP_GET_And_Has_Bad_StatusCode()
+ public void Given_Request_Is_HTTP_GET_And_Has_Bad_StatusCode_Then_Bad_Request_Response_Is_Generated()
throws Exception {
when(request.getParameter("statusCode")).thenReturn("1'");
logServlet.doGet(request, response);
throws Exception {
when(request.getParameter("statusCode")).thenReturn("1'");
logServlet.doGet(request, response);
- public void Given_Request_Is_HTTP_GET_And_Is_FeedLog()
+ public void Given_Request_Is_HTTP_GET_And_Is_FeedLog_A_STATUS_OK_Response_Is_Generated()
throws Exception {
logServlet.doGet(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_OK));
}
throws Exception {
logServlet.doGet(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_OK));
}
- @Test
- public void Given_Request_Is_HTTP_GET_And_Is_Not_FeedLog()
- throws Exception {
- LogServlet logServletNotFeedlog = new LogServlet(false);
- PowerMockito.mockStatic(Subscription.class);
- PowerMockito.when(Subscription.getSubscriptionById(anyInt())).thenReturn(mock(Subscription.class));
- logServletNotFeedlog.doGet(request, response);
- verify(response).setStatus(eq(HttpServletResponse.SC_OK));
- }
-
@Test
public void Given_Request_Is_HTTP_PUT_And_Is_Not_Allowed_Then_Forbidden_Response_Is_Generated()
throws Exception {
@Test
public void Given_Request_Is_HTTP_PUT_And_Is_Not_Allowed_Then_Forbidden_Response_Is_Generated()
throws Exception {
- public void Given_Request_Is_GetPublishRecordsForFeed_And_Type_Is_Publish()
+ public void Given_Request_Is_GetPublishRecordsForFeed_And_Type_Is_Publish_A_STATUS_OK_Response_Is_Generated()
throws Exception {
when(request.getParameter("type")).thenReturn("pub");
when(request.getParameter("expiryReason")).thenReturn(null);
throws Exception {
when(request.getParameter("type")).thenReturn("pub");
when(request.getParameter("expiryReason")).thenReturn(null);
- public void Given_Request_Is_getDeliveryRecordsForFeed_And_Type_Is_Delivery()
+ public void Given_Request_Is_getDeliveryRecordsForFeed_And_Type_Is_Delivery_A_STATUS_OK_Response_Is_Generated()
throws Exception {
when(request.getParameter("type")).thenReturn("del");
when(request.getParameter("expiryReason")).thenReturn(null);
throws Exception {
when(request.getParameter("type")).thenReturn("del");
when(request.getParameter("expiryReason")).thenReturn(null);
- public void Given_Request_Is_getExpiryRecordsForFeed_And_Type_Is_Expire()
+ public void Given_Request_Is_getExpiryRecordsForFeed_And_Type_Is_Expire_A_STATUS_OK_Response_Is_Generated()
throws Exception {
when(request.getParameter("type")).thenReturn("exp");
when(request.getParameter("statusCode")).thenReturn(null);
throws Exception {
when(request.getParameter("type")).thenReturn("exp");
when(request.getParameter("statusCode")).thenReturn(null);
- public void Given_Request_Is_getDeliveryRecordsForSubscription_And_Type_Is_Delivery()
+ public void Given_Request_Is_getDeliveryRecordsForSubscription_And_Type_Is_Delivery_A_STATUS_OK_Response_Is_Generated()
throws Exception {
LogServlet logServletNotFeedlog = new LogServlet(false);
when(request.getParameter("type")).thenReturn("del");
when(request.getParameter("statusCode")).thenReturn(null);
when(request.getParameter("expiryReason")).thenReturn(null);
throws Exception {
LogServlet logServletNotFeedlog = new LogServlet(false);
when(request.getParameter("type")).thenReturn("del");
when(request.getParameter("statusCode")).thenReturn(null);
when(request.getParameter("expiryReason")).thenReturn(null);
- PowerMockito.mockStatic(Subscription.class);
- PowerMockito.when(Subscription.getSubscriptionById(anyInt())).thenReturn(mock(Subscription.class));
logServletNotFeedlog.doGet(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_OK));
}
@Test
logServletNotFeedlog.doGet(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_OK));
}
@Test
- public void Given_Request_Is_getExpiryRecordsForSubscription_And_Type_Is_Expiry()
+ public void Given_Request_Is_getExpiryRecordsForSubscription_And_Type_Is_Expiry_A_STATUS_OK_Response_Is_Generated()
throws Exception {
LogServlet logServletNotFeedlog = new LogServlet(false);
when(request.getParameter("type")).thenReturn("exp");
when(request.getParameter("statusCode")).thenReturn(null);
when(request.getParameter("expiryReason")).thenReturn(null);
throws Exception {
LogServlet logServletNotFeedlog = new LogServlet(false);
when(request.getParameter("type")).thenReturn("exp");
when(request.getParameter("statusCode")).thenReturn(null);
when(request.getParameter("expiryReason")).thenReturn(null);
- PowerMockito.mockStatic(Subscription.class);
- PowerMockito.when(Subscription.getSubscriptionById(anyInt())).thenReturn(mock(Subscription.class));
logServletNotFeedlog.doGet(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_OK));
}
logServletNotFeedlog.doGet(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_OK));
}
INSERT INTO GROUPS(GROUPID, AUTHID, NAME, DESCRIPTION, CLASSIFICATION, MEMBERS)
VALUES (1, 'Basic dXNlcjE6cGFzc3dvcmQx', 'Group1', 'First Group for testing', 'Class1', 'Member1');
INSERT INTO GROUPS(GROUPID, AUTHID, NAME, DESCRIPTION, CLASSIFICATION, MEMBERS)
VALUES (1, 'Basic dXNlcjE6cGFzc3dvcmQx', 'Group1', 'First Group for testing', 'Class1', 'Member1');
+
+INSERT INTO SUBSCRIPTIONS(SUBID, FEEDID, DELIVERY_URL, DELIVERY_USER, DELIVERY_PASSWORD, SUBSCRIBER, SELF_LINK, LOG_LINK)
+VALUES (23, 1, 'http://delivery_url', 'user1', 'somepassword', 'sub123', 'selflink', 'loglink');
# Database access
org.onap.dmaap.datarouter.db.driver = org.h2.Driver
org.onap.dmaap.datarouter.db.url = jdbc:h2:mem:test;DB_CLOSE_DELAY=-1
# Database access
org.onap.dmaap.datarouter.db.driver = org.h2.Driver
org.onap.dmaap.datarouter.db.url = jdbc:h2:mem:test;DB_CLOSE_DELAY=-1
+org.onap.dmaap.datarouter.provserver.isaddressauthenabled = true
\ No newline at end of file