Example #1
0
  /** Boxインストールで作成する場合のコレクション配下のファイル最大数チェックのテスト. */
  @Test
  public final void Boxインストールで作成する場合のコレクション配下のファイル最大数チェックのテスト() {
    // 本テストでは子要素の最大数:20 コレクションの最大階層数:5の設定となっていることを前提とし、
    // WebDavコレクションの子要素数21(全てWebDavファイル)のBarファイルを登録して、エラーとなることを確認する。
    final String barFilePath = "/V1_1_2_bar_webdav_file_count_error.bar";
    String cellName = "collectionLimitCell";
    String box = INSTALL_TARGET;

    try {
      // テスト用Cellの作成
      CellUtils.create(cellName, TOKEN, HttpStatus.SC_CREATED);

      TResponse res = null;
      File barFile = new File(RESOURCE_PATH + barFilePath);
      byte[] body = BarInstallTestUtils.readBarFile(barFile);
      Map<String, String> headers = new LinkedHashMap<String, String>();
      headers.put(HttpHeaders.CONTENT_TYPE, REQ_CONTENT_TYPE);
      headers.put(HttpHeaders.CONTENT_LENGTH, String.valueOf(body.length));

      res = BarInstallTestUtils.request(REQUEST_NORM_FILE, cellName, box, headers, body);
      res.statusCode(HttpStatus.SC_ACCEPTED);
      String location = res.getHeader(HttpHeaders.LOCATION);
      String expected = UrlUtils.cellRoot(cellName) + box;
      assertEquals(expected, location);

      BarInstallTestUtils.assertBarInstallStatus(
          location, DEFAULT_SCHEMA_URL, ProgressInfo.STATUS.FAILED);
    } finally {
      // Cellの再帰的削除
      Setup.cellBulkDeletion(cellName);
    }
  }
  /** barファイルインストール受付時に400エラーとなったイベントログが取得できること. */
  @Test
  public final void barファイルインストール受付時に400エラーとなったイベントログが取得できること() {
    try {
      // CELL作成
      CellUtils.create(UNIT_USER_CELL, AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_CREATED);

      // Barインストール実施
      String reqCell = UNIT_USER_CELL;
      String reqPath = INSTALL_TARGET;

      TResponse res = null;
      File barFile = new File(RESOURCE_PATH + BAR_FILE_MINIMUM);
      byte[] body = BarInstallTestUtils.readBarFile(barFile);
      Map<String, String> headers = new LinkedHashMap<String, String>();
      headers.put(HttpHeaders.CONTENT_LENGTH, String.valueOf(body.length));

      res = BarInstallTestUtils.request(REQUEST_NOTYPE_FILE, reqCell, reqPath, headers, body);
      res.statusCode(HttpStatus.SC_BAD_REQUEST);

      // イベント取得
      TResponse response =
          Http.request("cell/log-get.txt")
              .with("METHOD", HttpMethod.GET)
              .with("token", AbstractCase.MASTER_TOKEN_NAME)
              .with("cellPath", UNIT_USER_CELL)
              .with("collection", CURRENT_COLLECTION)
              .with("fileName", DEFAULT_LOG)
              .with("ifNoneMatch", "*")
              .returns();
      response.debug();

      // レスポンスの解析
      List<String[]> lines = BarInstallTestUtils.getListedBody(response.getBody());
      int count = 0;
      for (String[] line : lines) {
        if (line[6].equals(WebDAVMethod.MKCOL.toString())) {
          assertEquals("400", line[8].trim());
          break;
        }
        count++;
      }
      assertTrue(count < lines.size());
    } finally {
      // CELL削除
      CellUtils.delete(AbstractCase.MASTER_TOKEN_NAME, UNIT_USER_CELL);
    }
  }
  /**
   * check response body.
   *
   * @param res TResponse
   * @param expectedResBody Expected response body
   */
  public static void checkBatchResponseBody(TResponse res, String expectedResBody) {
    String[] arrResBody = res.getBody().split("\n");
    String[] arrExpResBody = expectedResBody.split("\n");

    ODataBatchResponseParser parser = new ODataBatchResponseParser();

    List<ODataResponse> odResEx = parser.parse(expectedResBody, arrExpResBody[0]);
    List<ODataResponse> odResAc = parser.parse(res.getBody(), arrResBody[0]);

    // check if # parts equals
    assertTrue(
        "inconsistent #Parts. #expected=" + odResEx.size() + ", while #actual=" + odResAc.size(),
        odResAc.size() == odResEx.size());

    for (int i = 0; i < odResEx.size(); i++) {
      ODataResponse resEx = odResEx.get(i);
      ODataResponse resAc = odResAc.get(i);
      // should be same status code
      org.junit.Assert.assertEquals(resEx.getStatusCode(), resAc.getStatusCode());
      org.junit.Assert.assertEquals(resEx.bodyAsString(), resAc.bodyAsString());

      for (String headerKey : resEx.getHeaders().keySet()) {
        String hValueEx = resEx.getHeader(headerKey);
        String hValueAc = resAc.getHeader(headerKey);
        Pattern p = Pattern.compile(hValueEx);
        Matcher m = p.matcher(hValueAc);
        assertTrue(
            "Header "
                + headerKey
                + " should match.\n\n Expected\n"
                + hValueEx
                + "\nActual\n"
                + hValueAc,
            hValueEx.equals(hValueAc) || m.matches());
      }
    }
    // assertFalse("res body shorter than expected", arrResBody.length < arrExpResBody.length);

  }
  /** barファイルインストール後イベントログを取得して正常終了すること. */
  @Test
  public final void barファイルインストール後イベントログを取得して正常終了すること() {
    try {
      // CELL作成
      CellUtils.create(UNIT_USER_CELL, AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_CREATED);

      // Barインストール実施
      String reqCell = UNIT_USER_CELL;
      String reqPath = INSTALL_TARGET;

      TResponse res = null;
      File barFile = new File(RESOURCE_PATH + BAR_FILE_MINIMUM);
      byte[] body = BarInstallTestUtils.readBarFile(barFile);
      Map<String, String> headers = new LinkedHashMap<String, String>();
      headers.put(HttpHeaders.CONTENT_TYPE, REQ_CONTENT_TYPE);
      headers.put(HttpHeaders.CONTENT_LENGTH, String.valueOf(body.length));

      res = BarInstallTestUtils.request(REQUEST_NORM_FILE, reqCell, reqPath, headers, body);
      res.statusCode(HttpStatus.SC_ACCEPTED);
      String location = res.getHeader(HttpHeaders.LOCATION);
      String expected = UrlUtils.cellRoot(reqCell) + reqPath;
      assertEquals(expected, location);

      BarInstallTestUtils.assertBarInstallStatus(
          location, DEFAULT_SCHEMA_URL, ProgressInfo.STATUS.COMPLETED);

      // イベント取得
      TResponse response =
          Http.request("cell/log-get.txt")
              .with("METHOD", HttpMethod.GET)
              .with("token", AbstractCase.MASTER_TOKEN_NAME)
              .with("cellPath", UNIT_USER_CELL)
              .with("collection", CURRENT_COLLECTION)
              .with("fileName", DEFAULT_LOG)
              .with("ifNoneMatch", "*")
              .returns();
      response.debug();

      // レスポンスの解析
      List<String[]> lines = BarInstallTestUtils.getListedBody(response.getBody());
      int count = 0;
      for (String[] line : lines) {
        if (line[6].equals(WebDAVMethod.MKCOL.toString())) {
          assertEquals("202", line[8].trim());
          break;
        }
        count++;
      }
      assertTrue(count < lines.size());
      lines.remove(count);

      int index = 0;
      checkResponseLog(
          lines,
          "[INFO ]",
          "server",
          "PL-BI-1000",
          UrlUtils.getBaseUrl() + "/UnitUserCell/installBox",
          "Bar installation started.",
          index++);
      checkResponseLog(
          lines,
          "[INFO ]",
          "server",
          "PL-BI-1001",
          "bar/00_meta/00_manifest.json",
          "Installation started.",
          index++);
      checkResponseLog(
          lines,
          "[INFO ]",
          "server",
          "PL-BI-1003",
          "bar/00_meta/00_manifest.json",
          "Installation completed.",
          index++);
      checkResponseLog(
          lines,
          "[INFO ]",
          "server",
          "PL-BI-1001",
          "bar/00_meta/90_rootprops.xml",
          "Installation started.",
          index++);
      checkResponseLog(
          lines,
          "[INFO ]",
          "server",
          "PL-BI-1003",
          "bar/00_meta/90_rootprops.xml",
          "Installation completed.",
          index++);
      checkResponseLog(
          lines,
          "[INFO ]",
          "server",
          "PL-BI-0000",
          UrlUtils.getBaseUrl() + "/UnitUserCell/installBox",
          "Bar installation completed.",
          index++);
      response.statusCode(HttpStatus.SC_OK);
    } finally {
      cleanup();
      // CELL削除
      CellUtils.delete(AbstractCase.MASTER_TOKEN_NAME, UNIT_USER_CELL);
    }
  }