Example #1
0
  @Test
  public void testTranslate() throws IOException {
    String expectedXMLFilePath = getJSONFixtureFile("expected.xml");

    File expectedXMLFile = new File(expectedXMLFilePath);
    String expectedXML = FileUtils.readFileToString(expectedXMLFile);
    String expectedJSONStr =
        JSONTranslator.translateXMLToJSON(Constants.MIME_APPLICATION_JSON, null, expectedXML);

    String actualXMLFilePath = getJSONFixtureFile("actual.xml");

    File actualXMLFile = new File(actualXMLFilePath);
    String actualXML = FileUtils.readFileToString(actualXMLFile);
    String actualJSONStr =
        JSONTranslator.translateXMLToJSON(Constants.MIME_APPLICATION_JSON, null, actualXML);

    Assert.assertEquals(expectedJSONStr, actualJSONStr);
  }
Example #2
0
  private void doTest(String actualJSONDataURL, String expectedXMLDataURL) throws Exception {

    WebConversation wc = new WebConversation();

    WebRequest jsonDataRequest =
        SecurityUtil.getSecuredRequest(
            wc, "http://127.0.0.1:" + AllTests.WEBAPP_PORT + actualJSONDataURL);
    WebResponse jsonDataResponse = wc.getResponse(jsonDataRequest);
    String actual = jsonDataResponse.getText();

    WebRequest xmlDataRequest =
        SecurityUtil.getSecuredRequest(
            wc, "http://127.0.0.1:" + AllTests.WEBAPP_PORT + expectedXMLDataURL);
    WebResponse xmlDataResponse = wc.getResponse(xmlDataRequest);

    String xml = xmlDataResponse.getText();
    String expected = JSONTranslator.translateXMLToJSON("application/json", null, xml);
    expected = "fun" + " && " + "fun" + "(" + expected + ")";

    Assert.assertEquals(expected, actual);
  }