Example #1
0
 /**
  * This method performs create operation using request body.
  *
  * @param body POST Request Body
  * @return JSONObject as response
  * @throws DaoException Exception thrown
  */
 JSONObject internalCreate(HashMap<String, Object> body) throws DaoException {
   String url = this.getUrl();
   IRestAdapter rest = RestAdapterFactory.create(accessor);
   DcResponse res = rest.post(url, JSONObject.toJSONString(body), RestAdapter.CONTENT_TYPE_JSON);
   JSONObject json = (JSONObject) ((JSONObject) res.bodyAsJson().get("d")).get("results");
   return json;
 }
Example #2
0
 /**
  * This method appends query string to execute Query for Search.
  *
  * @param query Query object
  * @return JSON response
  * @throws DaoException Exception thrown
  */
 @SuppressWarnings("unchecked")
 @Override
 public HashMap<String, Object> doSearch(Query query) throws DaoException {
   StringBuilder sb = new StringBuilder(this.getUrl());
   String qry = query.makeQueryString();
   if (qry != null && !"".equals(qry)) {
     sb.append("?" + qry);
   }
   IRestAdapter rest = RestAdapterFactory.create(accessor);
   DcResponse res = rest.get(sb.toString(), RestAdapter.CONTENT_TYPE_JSON);
   return (HashMap<String, Object>) ((JSONObject) res.bodyAsJson());
 }
Example #3
0
 /**
  * This method performs retrieve operation.
  *
  * @param id composite key url encoding the target
  * @return JSONObject as response
  * @throws DaoException Exception thrown
  */
 JSONObject internalRetrieveMultikey(String id) throws DaoException {
   DcResponse res = internalRetrieveMultikeyAsDcResponse(id);
   JSONObject json = (JSONObject) ((JSONObject) res.bodyAsJson().get("d")).get("results");
   return json;
 }
  /**
   * スクリプトから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のSessionToken取得が行えること. Extensionの
   * AWSSecurityTokenServiceテスト用。
   */
  @SuppressWarnings("unchecked")
  @Test
  public final void スクリプトからExt_AWSSecurityTokenServiceのSessionToken取得が行えること() {

    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_getSessionToken.js";
    HttpUriRequest req = null;
    JSONObject requestBody = new JSONObject();
    requestBody.put("AccessKeyId", properties.getProperty("AccessKeyId"));
    requestBody.put("SecretAccessKey", properties.getProperty("SecretAccessKey"));
    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(HttpStatus.SC_OK, dcRes.getStatusCode());
      JSONObject credentials = (JSONObject) dcRes.bodyAsJson().get("Credentials");
      System.out.println(credentials.toJSONString());
      assertNotNull(credentials);

      // サービスの実行(durationSeconds指定)
      requestBody.put("durationSeconds", 900);
      req =
          new DcRequestBuilder()
              .url(url)
              .method("POST")
              .body(requestBody.toJSONString())
              .token(token)
              .build();
      req.setHeader(KEY_HEADER_BASEURL, baseUrl);
      version = getVersion();
      if (version != null && !(version.equals(""))) {
        req.setHeader("X-Dc-Version", version);
      }

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

      assertEquals(HttpStatus.SC_OK, dcRes.getStatusCode());
      credentials = (JSONObject) dcRes.bodyAsJson().get("Credentials");
      System.out.println(credentials.toJSONString());
      assertNotNull(credentials);

    } 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());
        }
      }
    }
  }