import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
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.provisioning.utils.DB;
import org.powermock.modules.junit4.PowerMockRunner;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-
-
@RunWith(PowerMockRunner.class)
public class StatisticsServletTest {
@Mock
private HttpServletResponse response;
- private DB db;
-
private static EntityManagerFactory emf;
private static EntityManager em;
@Before
public void setUp() throws Exception {
statisticsServlet = new StatisticsServlet();
- db = new DB();
buildRequestParameters();
}
@Test
public void Given_Request_Is_HTTP_GET_With_GroupId_But_No_FeedId_Parameters_Then_Request_Succeeds()
throws Exception {
- addAliasForSubstringIndex();
ServletOutputStream outStream = mock(ServletOutputStream.class);
when(response.getOutputStream()).thenReturn(outStream);
statisticsServlet.doGet(request, response);
@Test
public void Given_Request_Is_HTTP_GET_With_GroupId_And_FeedId_Parameters_Then_Request_Succeeds()
throws Exception {
- addAliasForSubstringIndex();
when(request.getParameter("feedid")).thenReturn("1");
when(request.getParameter("statusCode")).thenReturn("500");
ServletOutputStream outStream = mock(ServletOutputStream.class);
when(request.getParameter("groupid")).thenReturn("1");
when(request.getParameter("subid")).thenReturn("1");
}
- private void addAliasForSubstringIndex() throws SQLException {
- String sql = "CREATE ALIAS IF NOT EXISTS `SUBSTRING_INDEX`AS $$ String Function(String one, String two, String three){ return \"url\"; }$$;";
- Connection conn = db.getConnection();
- PreparedStatement pst = conn.prepareStatement(sql);
- pst.execute();
- }
}