Skip to content

Commit

Permalink
Merge branch 'master' into add-otlp-custom-header-support
Browse files Browse the repository at this point in the history
  • Loading branch information
predic8 authored Aug 14, 2024
2 parents c0b8f00 + 4acadfb commit 18edd0e
Showing 1 changed file with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void accessBindings() throws Exception {
}

@Test
public void xmlFromFileTest() throws Exception {
void xmlFromFileTest() throws Exception {
setAndHandleRequest("./project_template.xml");
assertEquals("minister", evaluateXPathAndReturnFirstNode(createXPathExpression("/project/part[2]/title")).trim());
}
Expand All @@ -172,7 +172,7 @@ private String evaluateXPathAndReturnFirstNode(XPathExpression xpath) throws XPa
}

@Test
public void nonXmlTemplateListTest() throws Exception {
void nonXmlTemplateListTest() throws Exception {
setAndHandleRequest("./template_test.json");

assertEquals("food1",
Expand All @@ -184,7 +184,7 @@ public void nonXmlTemplateListTest() throws Exception {
}

@Test
public void initTest() {
void initTest() {
assertThrows(IllegalStateException.class, () -> {
ti.setLocation("./template_test.json");
ti.setTextTemplate("${minister}");
Expand All @@ -193,15 +193,15 @@ public void initTest() {
}

@Test
public void notFoundTemplateException() {
void notFoundTemplateException() {
assertThrows(ResourceRetrievalException.class, () -> {
ti.setLocation("./not_existent_file");
ti.init(router);
});
}

@Test
public void innerTagTest() throws Exception {
void innerTagTest() throws Exception {
ti.setTextTemplate("${title}");
ti.init(router);
ti.handleRequest(exc);
Expand All @@ -228,6 +228,24 @@ void contentTypeTestNoXml() throws Exception {
assertEquals("text/plain",exc.getRequest().getHeader().getContentType());
}

@Test
void testPrettify() {
String inputJson = "\t{\n\n\t\t\"name\":\"John\"\t\t,\"age\":30}";
String expectedPrettyJson = """
{
"name" : "John",
"age" : 30
}""";
String result = ti.prettifyJson(inputJson);
assertEquals(expectedPrettyJson, result);
}

@Test
void testPrettifyWithInvalidJson() {
String invalidJson = "{name:\"John\",age:30}";
assertEquals(invalidJson, ti.prettifyJson(invalidJson));
}

private void setAndHandleRequest(String location) throws Exception {
ti.setLocation(location);
ti.init(router);
Expand Down

0 comments on commit 18edd0e

Please sign in to comment.