Skip to content

Commit

Permalink
added more diagnostic tests
Browse files Browse the repository at this point in the history
Signed-off-by: Arun Venmany <[email protected]>
  • Loading branch information
arunvenmany-ibm committed Feb 17, 2025
1 parent e1c493a commit 23bfa84
Showing 1 changed file with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1199,4 +1199,91 @@ public void testConfigElementDiagnosticsAndCodeActionWithVersionless() throws Ba
codeActions.get(6), codeActions.get(7), codeActions.get(8), codeActions.get(9)
);
}

@Test
public void testVariableNameEmptyDiagnostic() {
String serverXML = String.join(newLine, //
"<server description=\"Sample Liberty server\">", //
" <featureManager>", //
" <platform>javaee-6.0</platform>", //
" <feature>acmeCA-2.0</feature>", //
" </featureManager>", //
" <variable name=\"\" value=\"9080\"/>", //
" <httpEndpoint host=\"*\" httpPort=\"${default.http.port}\"\n",//
" httpsPort=\"${default.https.port}\" id=\"defaultHttpEndpoint\"/>",//
"</server>" //
);
Map<String, String> propsMap = new HashMap<>();
propsMap.put("default.http.port", "9080");
propsMap.put("default.https.port", "9443");
Properties props = new Properties();
props.putAll(propsMap);
when(settingsService.getVariablesForServerXml(any())).thenReturn(props);
Diagnostic invalid1 = new Diagnostic();
invalid1.setRange(r(5, 1, 5, 33));
invalid1.setCode(LibertyDiagnosticParticipant.INCORRECT_VARIABLE_CODE);
invalid1.setMessage("ERROR: The variable should have a valid name defined in name attribute.");
invalid1.setSource("liberty-lemminx");
invalid1.setSeverity(DiagnosticSeverity.Error);

XMLAssert.testDiagnosticsFor(serverXML, null, null, serverXMLURI, false, invalid1);
}

@Test
public void testVariableValueEmptyDiagnostic() {
String serverXML = String.join(newLine, //
"<server description=\"Sample Liberty server\">", //
" <featureManager>", //
" <platform>javaee-6.0</platform>", //
" <feature>acmeCA-2.0</feature>", //
" </featureManager>", //
" <variable name=\"httpPort\" value=\"\"/>", //
" <httpEndpoint host=\"*\" httpPort=\"${default.http.port}\"\n",//
" httpsPort=\"${default.https.port}\" id=\"defaultHttpEndpoint\"/>",//
"</server>" //
);
Map<String, String> propsMap = new HashMap<>();
propsMap.put("default.http.port", "9080");
propsMap.put("default.https.port", "9443");
Properties props = new Properties();
props.putAll(propsMap);
when(settingsService.getVariablesForServerXml(any())).thenReturn(props);
Diagnostic invalid1 = new Diagnostic();
invalid1.setRange(r(5, 1, 5, 37));
invalid1.setCode(LibertyDiagnosticParticipant.INCORRECT_VARIABLE_CODE);
invalid1.setMessage("ERROR: The variable \"httpPort\" should have a valid value defined.");
invalid1.setSource("liberty-lemminx");
invalid1.setSeverity(DiagnosticSeverity.Error);

XMLAssert.testDiagnosticsFor(serverXML, null, null, serverXMLURI, false, invalid1);
}

@Test
public void testVariableDefaultValueEmptyDiagnostic() {
String serverXML = String.join(newLine, //
"<server description=\"Sample Liberty server\">", //
" <featureManager>", //
" <platform>javaee-6.0</platform>", //
" <feature>acmeCA-2.0</feature>", //
" </featureManager>", //
" <variable name=\"httpPort\" defaultValue=\"\"/>", //
" <httpEndpoint host=\"*\" httpPort=\"${default.http.port}\"\n",//
" httpsPort=\"${default.https.port}\" id=\"defaultHttpEndpoint\"/>",//
"</server>" //
);
Map<String, String> propsMap = new HashMap<>();
propsMap.put("default.http.port", "9080");
propsMap.put("default.https.port", "9443");
Properties props = new Properties();
props.putAll(propsMap);
when(settingsService.getVariablesForServerXml(any())).thenReturn(props);
Diagnostic invalid1 = new Diagnostic();
invalid1.setRange(r(5, 1, 5, 44));
invalid1.setCode(LibertyDiagnosticParticipant.INCORRECT_VARIABLE_CODE);
invalid1.setMessage("ERROR: The variable \"httpPort\" should have a valid value defined.");
invalid1.setSource("liberty-lemminx");
invalid1.setSeverity(DiagnosticSeverity.Error);

XMLAssert.testDiagnosticsFor(serverXML, null, null, serverXMLURI, false, invalid1);
}
}

0 comments on commit 23bfa84

Please sign in to comment.