@Test
@TestDir
@TestJetty
@TestHdfs
public void testNoRedirectWithData() throws Exception {

  createHttpFSServer(false, false);
  final String path = "/file";
  final String username = HadoopUsersConfTestHelper.getHadoopUsers()[0];
  // file creation which should not redirect
  URL url = new URL(TestJettyHelper.getJettyURL(),
      MessageFormat.format(
          "/webhdfs/v1{0}?user.name={1}&op=CREATE&data=true&noredirect=true",
          path, username));
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  conn.setRequestMethod(HttpMethod.PUT);
  conn.setRequestProperty("Content-Type", MediaType.APPLICATION_OCTET_STREAM);
  conn.setDoOutput(true);
  conn.connect();
  Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
  JSONObject json = (JSONObject) new JSONParser()
      .parse(new InputStreamReader(conn.getInputStream()));
  // get the location to write
  String location = (String) json.get("Location");
  Assert.assertTrue(location.contains(DataParam.NAME));
  Assert.assertTrue(location.contains("CREATE"));
  url = new URL(location);
  conn = (HttpURLConnection) url.openConnection();
  conn.setRequestMethod(HttpMethod.PUT);
  conn.setRequestProperty("Content-Type", MediaType.APPLICATION_OCTET_STREAM);
  conn.setDoOutput(true);
  conn.connect();
  final String writeStr = "write some content";
  OutputStream os = conn.getOutputStream();
  os.write(writeStr.getBytes());
  os.close();
  // Verify that file got created
  Assert.assertEquals(HttpURLConnection.HTTP_CREATED, conn.getResponseCode());
  json = (JSONObject) new JSONParser()
      .parse(new InputStreamReader(conn.getInputStream()));
  location = (String) json.get("Location");
  Assert.assertEquals(TestJettyHelper.getJettyURL() + "/webhdfs/v1" + path,
      location);
}