@Test public void getDataForNonExistingTarget() throws Exception { m_requestPathInfo = "/nonexisting/versions/2.0.0"; m_servlet.doGet(m_request, m_response); assertResponseCode(HttpServletResponse.SC_NOT_FOUND); }
@Test() public void getDowngradeFixPackageWithNonExistingToVersion() throws Exception { // try to request a version range with a non-existing from-version, should cause a complete (non-fix) package to // be returned... m_requestPathInfo = "/existing/versions/1.0.0"; m_requestCurrentParameter = "2.0.0"; m_servlet.doGet(m_request, m_response); assertResponseCode(HttpServletResponse.SC_NOT_FOUND); }
@Test() public void getUpgradeFixPackageWithNonExistingToVersion() throws Exception { // try to request a version range with a non-existing from-version, should cause a complete (non-fix) package to // be returned... m_requestPathInfo = "/existing/versions/3.0.0"; m_requestCurrentParameter = "2.0.0"; m_servlet.doGet(m_request, m_response); assertResponseCode(HttpServletResponse.SC_NOT_FOUND); }
@Test() public void getUpgradeWithNonExistingToVersion() throws Exception { // try to request a version range with a non-existing from-version, should cause a complete (non-fix) package to // be returned... m_requestPathInfo = "/existing/versions/3.0.0"; m_requestCurrentParameter = null; m_servlet.doGet(m_request, m_response); assertResponseCode(HttpServletResponse.SC_NOT_FOUND); }
@Test public void getVersionsExistingTarget() throws Exception { m_requestPathInfo = "/existing/versions"; m_servlet.doGet(m_request, m_response); assertResponseCode(HttpServletResponse.SC_OK); assertEquals(m_responseOutputStream.toString(), "2.0.0\n", "Expected to get version 2.0.0 in the response"); }
@Test public void getDataForBadURL() throws Exception { HttpServletRequest garbage = createMockObjectAdapter(HttpServletRequest.class, new Object() { @SuppressWarnings("unused") public String getPathInfo() { return "/"; } }); m_servlet.doGet(garbage, m_response); assertResponseCode(HttpServletResponse.SC_BAD_REQUEST); }
@Test public void getVersionsNonExistingTarget() throws Exception { m_requestPathInfo = "/nonexisting/versions"; m_servlet.doGet(m_request, m_response); assertResponseCode(HttpServletResponse.SC_NOT_FOUND); assertResponseOutput(-1, 0); }
@Test public void getRangeDataForExistingTarget_badHeaderValue() throws Exception { // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.16 // If the server ignores a byte-range-spec because it is syntactically invalid, the server SHOULD treat the // request as if the invalid Range header field did not exist. (Normally, this means return a 200 response // containing the full entity). m_requestPathInfo = "/existing/versions/2.0.0"; m_requestRangeHeader = "bytes=a-1"; m_servlet.doGet(m_request, m_response); assertResponseCode(HttpServletResponse.SC_OK); assertResponseHeaderNotPresent("Content-Length"); assertResponseOutput(0, 100); }
@Test public void getRangeDataForExistingTarget_first0lastOK() throws Exception { // valid range starting at 0 m_requestPathInfo = "/existing/versions/2.0.0"; m_requestRangeHeader = "bytes=0-10"; m_servlet.doGet(m_request, m_response); assertResponseCode(HttpServletResponse.SC_PARTIAL_CONTENT); assertResponseHeaderNotPresent("Content-Length"); assertResponseHeaderValue("Content-Range", "bytes 0-10/*"); }
@Test public void getRangeDataForExistingTarget_firstOKlastTooSmall() throws Exception { // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.1 // If the last-byte-pos value is present, it MUST be greater than or equal to the first-byte-pos in that // byte-range-spec, or the byte- range-spec is syntactically invalid. // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.16 // If the server ignores a byte-range-spec because it is syntactically invalid, the server SHOULD treat the // request as if the invalid Range header field did not exist. (Normally, this means return a 200 response // containing the full entity). m_requestPathInfo = "/existing/versions/2.0.0"; m_requestRangeHeader = "bytes=2-1"; m_servlet.doGet(m_request, m_response); assertResponseCode(HttpServletResponse.SC_OK); assertResponseHeaderNotPresent("Content-Length"); assertResponseOutput(0, 100); }
@Test() public void getRangeDataForExistingTarget_firstOKlastOK() throws Exception { // valid range not starting at 0 m_requestPathInfo = "/existing/versions/2.0.0"; m_requestRangeHeader = "bytes=2-50"; m_servlet.doGet(m_request, m_response); assertResponseCode(HttpServletResponse.SC_PARTIAL_CONTENT); assertResponseHeaderNotPresent("Content-Length"); assertResponseHeaderValue("Content-Range", "bytes 2-50/*"); assertResponseOutput(2, 49); }
@Test public void getRangeDataForExistingTarget_firstTooBiglastTooBig() throws Exception { // invalid range: start=toobig end=toobig m_requestPathInfo = "/existing/versions/2.0.0"; m_requestRangeHeader = "bytes=100-110"; m_servlet.doGet(m_request, m_response); assertResponseCode(HttpServletResponse.SC_PARTIAL_CONTENT); assertResponseHeaderValue("Content-Range", "bytes 100-110/*"); assertResponseHeaderNotPresent("Content-Length"); assertResponseOutput(-1, 0); }
@Test public void getRangeDataForExistingTarget_firstOKlastANY() throws Exception { // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.1 // If the last-byte-pos value is absent, or if the value is greater than or equal to the current length of the // entity-body, last-byte-pos is taken to be equal to one less than the current length of the entity- body in // bytes. m_requestPathInfo = "/existing/versions/2.0.0"; m_requestRangeHeader = "bytes=2-"; m_servlet.doGet(m_request, m_response); assertResponseCode(HttpServletResponse.SC_PARTIAL_CONTENT); assertResponseHeaderNotPresent("Content-Length"); assertResponseHeaderValue("Content-Range", "bytes 2-/*"); assertResponseOutput(2, 98); }
@Test public void getRangeDataForExistingTarget_firstOKlastOK2() throws Exception { // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.1 // If the last-byte-pos value is absent, or if the value is greater than or equal to the current length of the // entity-body, last-byte-pos is taken to be equal to one less than the current length of the entity- body in // bytes. m_requestPathInfo = "/existing/versions/2.0.0"; m_requestRangeHeader = "bytes=2-99"; m_servlet.doGet(m_request, m_response); assertResponseCode(HttpServletResponse.SC_PARTIAL_CONTENT); assertResponseHeaderNotPresent("Content-Length"); assertResponseHeaderValue("Content-Range", "bytes 2-99/*"); assertResponseOutput(2, 98); }
@Test public void getRangeDataForExistingTarget_firstOKlastTooBig() throws Exception { // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.1 // If the last-byte-pos value is absent, or if the value is greater than or equal to the current length of the // entity-body, last-byte-pos is taken to be equal to one less than the current length of the entity- body in // bytes. m_requestPathInfo = "/existing/versions/2.0.0"; m_requestRangeHeader = "bytes=2-100"; m_servlet.doGet(m_request, m_response); assertResponseCode(HttpServletResponse.SC_PARTIAL_CONTENT); assertResponseHeaderNotPresent("Content-Length"); assertResponseHeaderValue("Content-Range", "bytes 2-100/*"); assertResponseOutput(2, 98); }
@Test() public void getUpgradeFixPackageWithExistingFromVersion() throws Exception { // try to request a version range with an existing from-version, should cause a fix package to be returned... m_requestPathInfo = "/existing/versions/2.0.0"; m_requestCurrentParameter = "2.0.0"; m_servlet.doGet(m_request, m_response); assertResponseCode(HttpServletResponse.SC_OK); assertResponseOutput(0, 100); assertGeneratorTargetId("existing"); assertGeneratorToVersion("2.0.0"); assertGeneratorFromVersion("2.0.0"); }
@Test() public void getUpgradeFixPackageWithNonExistingFromVersion() throws Exception { // try to request a version range with a non-existing from-version, should cause a complete (non-fix) package to // be returned... m_requestPathInfo = "/existing/versions/2.0.0"; m_requestCurrentParameter = "1.0.0"; m_servlet.doGet(m_request, m_response); assertResponseCode(HttpServletResponse.SC_OK); assertResponseOutput(0, 100); assertGeneratorTargetId("existing"); assertGeneratorToVersion("2.0.0"); assertGeneratorFromVersion(null); }
@Test public void getDataForExistingTarget() throws Exception { m_requestPathInfo = "/existing/versions/2.0.0"; m_servlet.doGet(m_request, m_response); assertResponseCode(HttpServletResponse.SC_OK); assertResponseHeaderNotPresent("Content-Length"); assertResponseOutput(0, 100); assertGeneratorTargetId("existing"); assertGeneratorToVersion("2.0.0"); }
@Test() public void getUpgradeWithExistingToVersion() throws Exception { // try to request a version range with a non-existing from-version, should cause a complete (non-fix) package to // be returned... m_requestPathInfo = "/existing/versions/2.0.0"; m_requestCurrentParameter = null; m_servlet.doGet(m_request, m_response); assertResponseCode(HttpServletResponse.SC_OK); assertResponseOutput(0, 100); assertGeneratorTargetId("existing"); assertGeneratorToVersion("2.0.0"); assertGeneratorFromVersion(null); }