/**
   * スクリプトからExt_MailSenderクラスを呼び出せること. Extensionの MailSenderテスト用。 <br>
   * 本テストを動作させるためには、Ext_MailSenderの jarファイル、プロパティファイルが必要。<br>
   * <br>
   */
  @Test
  public final void スクリプトからExt_MailSenderクラスを呼び出せること() {

    SimpleSmtpServer smtpServer = SimpleSmtpServer.start(1025);

    try {
      String url;
      String testSrc = "callExtensionMailSender.js";
      HttpUriRequest req = null;
      String requestJson =
          "{\"to\":[{\"address\":\"[email protected]\",\"name\":\"テストユーザ1\"},"
              + "{\"address\":\"[email protected]\",\"name\":\"テストユーザ2\"}],"
              + "\"cc\":[{\"address\":\"[email protected]\",\"name\":\"テストユーザ3\"}],"
              + "\"bcc\":[{\"address\":\"[email protected]\",\"name\":\"テストユーザ4\"}],"
              + "\"from\":{\"address\":\"[email protected]\",\"name\":\"テストユーザ5\"},"
              + "\"reply-to\":[{\"address\":\"[email protected]\",\"name\":\"テストユーザ6\"}],"
              + "\"subject\":\"タイトル\",\"text\":\"メール本文の内容\",\"charset\":\"ISO-2022-JP\","
              + "\"envelope-from\":\"[email protected]\",\"headers\":{\"Organization\":\"personium\"}}";

      try {
        if (isServiceTest) {
          // スクリプトの登録 (Davのput)
          putScript(testSrc, "test.js");
          url = requestUrl();
        } else {
          url = requestUrl(testSrc);
        }
        // サービスの実行
        req = new DcRequestBuilder().url(url).method("POST").body(requestJson).token(token).build();
        req.setHeader(KEY_HEADER_BASEURL, baseUrl);
        String version = getVersion();
        if (version != null && !(version.equals(""))) {
          req.setHeader("X-Dc-Version", version);
        }

        HttpResponse objResponse;
        objResponse = httpClient.execute(req);
        DcResponse dcRes = new DcResponse(objResponse);

        assertEquals(HttpStatus.SC_OK, dcRes.getStatusCode());
        assertEquals("Successfully sent a mail.", dcRes.bodyAsString());

        if (!isServiceTest) {
          // ITの場合はローカル以外のSMTPサーバに送信するためチェック不可
          assertEquals(1, smtpServer.getReceivedEmailSize());
        }

      } catch (DaoException e) {
        fail(e.getMessage());
      } catch (ClientProtocolException e) {
        fail(e.getMessage());
      } catch (IOException e) {
        fail(e.getMessage());
      } finally {
        if (isServiceTest) {
          // スクリプトの削除(Davのdel)
          try {
            testSvcCol.del("test.js");
          } catch (DaoException e) {
            fail(e.getMessage());
          }
        }
      }
    } finally {
      smtpServer.stop();
    }
  }
  /** Ext_AWSSecurityTokenServiceクラスのFederationToken取得でエラーが発生した場合エラーメッセージが返却されること. */
  @SuppressWarnings("unchecked")
  @Test
  public final void Ext_AWSSecurityTokenServiceクラスのFederationToken取得でエラーが発生した場合エラーメッセージが返却されること() {

    Properties properties = new Properties();
    InputStream configFileStream =
        ClassLoader.getSystemResourceAsStream("extension-test-config.properties");
    try {
      properties.load(configFileStream);
    } catch (IOException e) {
      fail("properties load failuer");
    }

    String url;
    String testSrc = "callExtension_AWSSecurityTokenService_getFederationToken.js";
    HttpUriRequest req = null;
    JSONObject requestBody = new JSONObject();
    requestBody.put("AccessKeyId", properties.getProperty("AccessKeyId"));
    requestBody.put("SecretAccessKey", "dummySecretAccessKey");
    requestBody.put("ProxyHost", properties.getProperty("ProxyHost", null));
    requestBody.put("ProxyPort", Integer.parseInt(properties.getProperty("ProxyPort", "80")));
    requestBody.put("ProxyUser", properties.getProperty("ProxyUser", null));
    requestBody.put("ProxyPassword", properties.getProperty("ProxyPassword", null));
    requestBody.put("durationSeconds", null);

    System.out.println(requestBody.toJSONString());
    try {
      if (isServiceTest) {
        // スクリプトの登録 (Davのput)
        putScript(testSrc, "test.js");
        url = requestUrl();
      } else {
        url = requestUrl(testSrc);
      }
      // サービスの実行(durationSeconds省略)
      req =
          new DcRequestBuilder()
              .url(url)
              .method("POST")
              .body(requestBody.toJSONString())
              .token(token)
              .build();
      req.setHeader(KEY_HEADER_BASEURL, baseUrl);
      String version = getVersion();
      if (version != null && !(version.equals(""))) {
        req.setHeader("X-Dc-Version", version);
      }

      HttpResponse objResponse;
      objResponse = httpClient.execute(req);
      DcResponse dcRes = new DcResponse(objResponse);

      assertEquals(418, dcRes.getStatusCode());
      System.out.println(dcRes.bodyAsString());
    } catch (DaoException e) {
      fail(e.getMessage());
    } catch (ClientProtocolException e) {
      fail(e.getMessage());
    } catch (IOException e) {
      fail(e.getMessage());
    } finally {
      if (isServiceTest) {
        // スクリプトの削除(Davのdel)
        try {
          testSvcCol.del("test.js");
        } catch (DaoException e) {
          fail(e.getMessage());
        }
      }
    }
  }