Commit 8f0aecff authored by Feng Xue's avatar Feng Xue

Add unit test cases to added etag filter

Add the test cases to the correlation, cube and regression
instead of the original ones
parent f001af57
......@@ -78,34 +78,6 @@ public class CommonEntityTagFilterTest extends EntityTagFilterTest {
verify(response).setStatus(304);
}
// @Test
// public void testFilteringOnCube() throws Exception {
// when(request.getRequestURL()).thenReturn(new StringBuffer("http://example.com/cube/cube1234"));
// when(request.getRequestURI()).thenReturn("/cube/cube1234");
// when(request.getHeader("If-None-Match")).thenReturn("7fc6e13a37bb838767eead28c1581075");
//
// EntityTagFilter filter = new CommonEntityTagFilter(serverHandler);
// filter.doFilter(request, response, chain);
//
// verify(bank).get("cube1234");
// verify(response).setStatus(304);
// }
//
// @Test
// public void testFilteringOnCubeWithRequest() throws Exception {
// when(request.getRequestURL()).thenReturn(
// new StringBuffer("http://example.com/cube/cube1234?q={\"dimensions\":[{\"id\":\"dimensionID1\",\"members\":[\"memberID1\",\"memberID2\"]}],\"measures\":[\"measureID1\",\"measureID2\"]}"));
// when(request.getRequestURI()).thenReturn("/cube/cube1234");
// when(request.getParameter("q")).thenReturn("{\"dimensions\":[{\"id\":\"dimensionID1\",\"members\":[\"memberID1\",\"memberID2\"]}],\"measures\":[\"measureID1\",\"measureID2\"]}");
// when(request.getHeader("If-None-Match")).thenReturn("810397a21017716ed794183f92c6b8c2");
//
// EntityTagFilter filter = new CommonEntityTagFilter(serverHandler);
// filter.doFilter(request, response, chain);
//
// verify(bank).get("cube1234");
// verify(response).setStatus(304);
// }
@Before
public void setUp() throws Exception {
commonSetUp();
......
package com.nesstar.rest.filters;
import com.nesstar.api.Variable;
import com.nesstar.rest.common.ETag;
import com.nesstar.rest.common.ServerHandler;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ServerHandler.class, ETag.class})
public class CorrelationEntityTagFilterTest extends EntityTagFilterTest {
@Test
public void testSimpleCorrelation() throws Exception {
when(request.getRequestURL()).thenReturn(new StringBuffer("http://example.com/study/study1234/correlate?corrVar=var1&corrVar=var2"));
when(request.getRequestURI()).thenReturn("/study/study1234/correlate");
when(request.getHeader("If-None-Match")).thenReturn("b3887a8322bf988fb29fc758480212bd");
Variable var1 = mock(Variable.class);
Variable var2 = mock(Variable.class);
when(var1.getId()).thenReturn("var1");
when(var1.getTimeStamp()).thenReturn(createDate());
when(var2.getId()).thenReturn("var2");
when(var2.getTimeStamp()).thenReturn(createDate());
when(bank.get("var1")).thenReturn(var1);
when(bank.get("var2")).thenReturn(var2);
EntityTagFilter filter = new CorrelationEntityTagFilter(serverHandler);
filter.doFilter(request, response, chain);
verify(response).setStatus(304);
}
@Test
public void testComplexCorrelation() throws Exception {
when(request.getRequestURL()).thenReturn(new StringBuffer("http://example.com/study/study1234/correlate?corrVar=var1&corrVar=var2&wgtVar=var11&caseSubset=ID(%27var1%27)%3CID(%27category_0_0%27)"));
when(request.getRequestURI()).thenReturn("/study/study1234/correlate");
when(request.getHeader("If-None-Match")).thenReturn("f66e0cd97dec4b3098ffe651581f5723");
when(request.getParameterValues("wgtVar")).thenReturn(new String[] { "var11" });
when(request.getParameter("caseSubset")).thenReturn("foo<bar");
Variable var1 = mock(Variable.class);
Variable var2 = mock(Variable.class);
Variable weight = mock(Variable.class);
when(var1.getId()).thenReturn("var1");
when(var1.getTimeStamp()).thenReturn(createDate());
when(var2.getId()).thenReturn("var2");
when(var2.getTimeStamp()).thenReturn(createDate());
when(weight.getId()).thenReturn("var11");
when(weight.getTimeStamp()).thenReturn(createDate());
when(bank.get("var1")).thenReturn(var1);
when(bank.get("var2")).thenReturn(var2);
when(bank.get("var11")).thenReturn(weight);
EntityTagFilter filter = new CorrelationEntityTagFilter(serverHandler);
filter.doFilter(request, response, chain);
verify(response).setStatus(304);
}
@Before
public void setUp() throws Exception {
commonSetUp();
}
}
package com.nesstar.rest.filters;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import com.nesstar.api.cube.Cube;
import com.nesstar.rest.common.ETag;
import com.nesstar.rest.common.ServerHandler;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ServerHandler.class, ETag.class})
public class CubeEntityTagFilterTest extends EntityTagFilterTest{
@Test
public void testFilteringOnCube() throws Exception {
when(request.getRequestURL()).thenReturn(new StringBuffer("http://example.com/cube/cube1234"));
when(request.getRequestURI()).thenReturn("/cube/cube1234");
when(request.getHeader("If-None-Match")).thenReturn("e82900cb24a5c9109973951fd8f9d95");
EntityTagFilter filter = new CubeEntityTagFilter(serverHandler);
filter.doFilter(request, response, chain);
verify(response).setStatus(304);
}
@Test
public void testFilteringOnCubeWithRequest() throws Exception {
when(request.getRequestURL()).thenReturn(
new StringBuffer("http://example.com/cube/cube1234?q={\"dimensions\":[{\"id\":\"dimensionID1\",\"members\":[\"memberID1\",\"memberID2\"]}],\"measures\":[\"measureID1\",\"measureID2\"]}"));
when(request.getRequestURI()).thenReturn("/cube/cube1234");
when(request.getParameter("q")).thenReturn("{\"dimensions\":[{\"id\":\"dimensionID1\",\"members\":[\"memberID1\",\"memberID2\"]}],\"measures\":[\"measureID1\",\"measureID2\"]}");
when(request.getHeader("If-None-Match")).thenReturn("176481d3e6729a980c760cce59c8b1e6");
EntityTagFilter filter = new CubeEntityTagFilter(serverHandler);
filter.doFilter(request, response, chain);
verify(response).setStatus(304);
}
@Before
public void setUp() throws Exception {
commonSetUp();
Cube cube = mock(Cube.class);
when(request.getHeader(anyString())).thenReturn("1234"); // TODO: set this. ...
when(bank.get("cube1234")).thenReturn(cube);
when(cube.getId()).thenReturn("cube1234");
when(cube.getTimeStamp()).thenReturn(createDate());
}
}
package com.nesstar.rest.filters;
import com.nesstar.api.Variable;
import com.nesstar.rest.common.ETag;
import com.nesstar.rest.common.ServerHandler;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ServerHandler.class, ETag.class})
public class RegressionEntityTagFilterTest extends EntityTagFilterTest{
@Test
public void testSimpleRegression() throws Exception {
when(request.getRequestURL()).thenReturn(new StringBuffer("http://example.com/study/study1234/regress?depVar=var1&indVar=var2"));
when(request.getRequestURI()).thenReturn("/study/study1234/regress");
when(request.getHeader("If-None-Match")).thenReturn("9bdaca607b671ec92842a6b4697a9598");
Variable var1 = mock(Variable.class);
Variable var2 = mock(Variable.class);
when(var1.getId()).thenReturn("var1");
when(var1.getTimeStamp()).thenReturn(createDate());
when(var2.getId()).thenReturn("var2");
when(var2.getTimeStamp()).thenReturn(createDate());
when(bank.get("var1")).thenReturn(var1);
when(bank.get("var2")).thenReturn(var2);
EntityTagFilter filter = new RegressionEntityTagFilter(serverHandler);
filter.doFilter(request, response, chain);
verify(response).setStatus(304);
}
@Test
public void testComplexRegression() throws Exception {
when(request.getRequestURL()).thenReturn(new StringBuffer("http://example.com/study/study1234/regress?depVar=var1&indVar=var2&wgtVar=var11&caseSubset=ID(%27var1%27)%3CID(%27category_0_0%27)"));
when(request.getRequestURI()).thenReturn("/study/study1234/regress");
when(request.getHeader("If-None-Match")).thenReturn("24261e5487ac3e5870aeb2363ca9fa16");
when(request.getParameterValues("wgtVar")).thenReturn(new String[] { "var11" });
when(request.getParameter("caseSubset")).thenReturn("foo<bar");
Variable var1 = mock(Variable.class);
Variable var2 = mock(Variable.class);
Variable weight = mock(Variable.class);
when(var1.getId()).thenReturn("var1");
when(var1.getTimeStamp()).thenReturn(createDate());
when(var2.getId()).thenReturn("var2");
when(var2.getTimeStamp()).thenReturn(createDate());
when(weight.getId()).thenReturn("var11");
when(weight.getTimeStamp()).thenReturn(createDate());
when(bank.get("var1")).thenReturn(var1);
when(bank.get("var2")).thenReturn(var2);
when(bank.get("var11")).thenReturn(weight);
EntityTagFilter filter = new RegressionEntityTagFilter(serverHandler);
filter.doFilter(request, response, chain);
verify(response).setStatus(304);
}
@Before
public void setUp() throws Exception {
commonSetUp();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment