Skip to content
Snippets Groups Projects
Commit 527038c8 authored by Lars Johansson's avatar Lars Johansson
Browse files

Refactor utilities for integration tests

parent 63d93b1c
No related branches found
No related tags found
No related merge requests found
...@@ -414,66 +414,6 @@ public class ITUtilNameElement { ...@@ -414,66 +414,6 @@ public class ITUtilNameElement {
// ---------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------------
/**
* Utility method to (try to) validate a name element from given json and assert expected response.
* Method expected to NOT succeed to validate
* but instead assert response code (possibly also a non-empty message).
*
* @param json json
* @param nameCommand name command
* @param responseCode response code
*/
public static void assertValidate(String json, NameCommand nameCommand, int responseCode) {
assertValidate(AuthorizationChoice.NONE, json, nameCommand, responseCode, Boolean.FALSE, Boolean.FALSE);
}
/**
* Utility method to (try to) validate a name element from given json and assert expected response.
* Method expected to NOT succeed to validate
* but instead assert response code (possibly also a non-empty message).
*
* @param json json
* @param nameCommand name command
* @param responseCode response code
* @param expected expected
* @param expectedMessageEmpty expected message empty
*/
public static void assertValidate(String json, NameCommand nameCommand, int responseCode, Boolean expected, Boolean expectedMessageEmpty) {
assertValidate(AuthorizationChoice.NONE, json, nameCommand, responseCode, expected, expectedMessageEmpty);
}
/**
* Utility method to (try to) validate a name element from given json and assert expected response.
* Method expected to NOT succeed to validate
* but instead assert response code (possibly also a non-empty message).
*
* @param authorizationChoice authorization choice (none, user, admin)
* @param json json
* @param nameCommand name command
* @param responseCode response code
* @param expected expected
* @param expectedMessageEmpty expected message empty
*/
public static void assertValidate(AuthorizationChoice authorizationChoice, String json, NameCommand nameCommand, int responseCode, Boolean expected, Boolean expectedMessageEmpty) {
String validatePath = getValidatePath(nameCommand);
try {
String[] response = null;
response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(authorizationChoice, EndpointChoice.NAMES, validatePath, json));
ITUtil.assertResponseLength2Code(response, responseCode);
if (response[1] != null) {
ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), expected, expectedMessageEmpty);
}
} catch (IOException e) {
fail();
} catch (InterruptedException e) {
fail();
} catch (Exception e) {
fail();
}
}
// --------------------
/** /**
* Utility method to validate name element command for create and assert expected response. * Utility method to validate name element command for create and assert expected response.
* *
...@@ -484,7 +424,7 @@ public class ITUtilNameElement { ...@@ -484,7 +424,7 @@ public class ITUtilNameElement {
*/ */
public static void assertValidate(NameElementCommandCreate nameElementCommand, NameCommand nameCommand, String index, Boolean expected) { public static void assertValidate(NameElementCommandCreate nameElementCommand, NameCommand nameCommand, String index, Boolean expected) {
nameElementCommand.setIndex(index); nameElementCommand.setIndex(index);
assertValidate(AuthorizationChoice.NONE, object2Json(new NameElementCommandCreate[] {nameElementCommand}), nameCommand, expected); assertValidate(AuthorizationChoice.NONE, object2Json(new NameElementCommandCreate[] {nameElementCommand}), nameCommand, HttpURLConnection.HTTP_OK, expected);
} }
/** /**
* Utility method to validate name element command for create and assert expected response. * Utility method to validate name element command for create and assert expected response.
...@@ -494,7 +434,7 @@ public class ITUtilNameElement { ...@@ -494,7 +434,7 @@ public class ITUtilNameElement {
* @param expected expected response * @param expected expected response
*/ */
public static void assertValidate(NameElementCommandCreate nameElementCommand, NameCommand nameCommand, Boolean expected) { public static void assertValidate(NameElementCommandCreate nameElementCommand, NameCommand nameCommand, Boolean expected) {
assertValidate(AuthorizationChoice.NONE, object2Json(new NameElementCommandCreate[] {nameElementCommand}), nameCommand, expected); assertValidate(AuthorizationChoice.NONE, object2Json(new NameElementCommandCreate[] {nameElementCommand}), nameCommand, HttpURLConnection.HTTP_OK, expected);
} }
/** /**
* Utility method to validate name element command for update and assert expected response. * Utility method to validate name element command for update and assert expected response.
...@@ -504,7 +444,7 @@ public class ITUtilNameElement { ...@@ -504,7 +444,7 @@ public class ITUtilNameElement {
* @param expected expected response * @param expected expected response
*/ */
public static void assertValidate(NameElementCommandUpdate nameElementCommand, NameCommand nameCommand, Boolean expected) { public static void assertValidate(NameElementCommandUpdate nameElementCommand, NameCommand nameCommand, Boolean expected) {
assertValidate(AuthorizationChoice.NONE, object2Json(new NameElementCommandUpdate[] {nameElementCommand}), nameCommand, expected); assertValidate(AuthorizationChoice.NONE, object2Json(new NameElementCommandUpdate[] {nameElementCommand}), nameCommand, HttpURLConnection.HTTP_OK, expected);
} }
/** /**
* Utility method to validate name element command for confirm and assert expected response. * Utility method to validate name element command for confirm and assert expected response.
...@@ -514,7 +454,7 @@ public class ITUtilNameElement { ...@@ -514,7 +454,7 @@ public class ITUtilNameElement {
* @param expected expected response * @param expected expected response
*/ */
public static void assertValidate(NameElementCommandConfirm nameElementCommand, NameCommand nameCommand, Boolean expected) { public static void assertValidate(NameElementCommandConfirm nameElementCommand, NameCommand nameCommand, Boolean expected) {
assertValidate(AuthorizationChoice.NONE, object2Json(new NameElementCommandConfirm[] {nameElementCommand}), nameCommand, expected); assertValidate(AuthorizationChoice.NONE, object2Json(new NameElementCommandConfirm[] {nameElementCommand}), nameCommand, HttpURLConnection.HTTP_OK, expected);
} }
/** /**
* Utility method to validate name element commands for create and assert expected response. * Utility method to validate name element commands for create and assert expected response.
...@@ -524,7 +464,7 @@ public class ITUtilNameElement { ...@@ -524,7 +464,7 @@ public class ITUtilNameElement {
* @param expected expected response * @param expected expected response
*/ */
public static void assertValidate(NameElementCommandCreate[] nameElementCommands, NameCommand nameCommand, Boolean expected) { public static void assertValidate(NameElementCommandCreate[] nameElementCommands, NameCommand nameCommand, Boolean expected) {
assertValidate(AuthorizationChoice.NONE, object2Json(nameElementCommands), nameCommand, expected); assertValidate(AuthorizationChoice.NONE, object2Json(nameElementCommands), nameCommand, HttpURLConnection.HTTP_OK, expected);
} }
/** /**
* Utility method to validate name element commands for update and assert expected response. * Utility method to validate name element commands for update and assert expected response.
...@@ -534,7 +474,7 @@ public class ITUtilNameElement { ...@@ -534,7 +474,7 @@ public class ITUtilNameElement {
* @param expected expected response * @param expected expected response
*/ */
public static void assertValidate(NameElementCommandUpdate[] nameElementCommands, NameCommand nameCommand, Boolean expected) { public static void assertValidate(NameElementCommandUpdate[] nameElementCommands, NameCommand nameCommand, Boolean expected) {
assertValidate(AuthorizationChoice.NONE, object2Json(nameElementCommands), nameCommand, expected); assertValidate(AuthorizationChoice.NONE, object2Json(nameElementCommands), nameCommand, HttpURLConnection.HTTP_OK, expected);
} }
/** /**
* Utility method to validate name element commands for confirm and assert expected response. * Utility method to validate name element commands for confirm and assert expected response.
...@@ -544,7 +484,17 @@ public class ITUtilNameElement { ...@@ -544,7 +484,17 @@ public class ITUtilNameElement {
* @param expected expected response * @param expected expected response
*/ */
public static void assertValidate(NameElementCommandConfirm[] nameElementCommands, NameCommand nameCommand, Boolean expected) { public static void assertValidate(NameElementCommandConfirm[] nameElementCommands, NameCommand nameCommand, Boolean expected) {
assertValidate(AuthorizationChoice.NONE, object2Json(nameElementCommands), nameCommand, expected); assertValidate(AuthorizationChoice.NONE, object2Json(nameElementCommands), nameCommand, HttpURLConnection.HTTP_OK, expected);
}
/**
* Utility method to validate json and assert expected response.
*
* @param json json
* @param nameCommand name command
* @param responseCode response code
*/
public static void assertValidate(String json, NameCommand nameCommand, int responseCode) {
assertValidate(AuthorizationChoice.NONE, json, nameCommand, responseCode, null);
} }
/** /**
* Utility method to validate json and assert expected response. * Utility method to validate json and assert expected response.
...@@ -552,17 +502,20 @@ public class ITUtilNameElement { ...@@ -552,17 +502,20 @@ public class ITUtilNameElement {
* @param authorizationChoice authorization choice (none, user, admin) * @param authorizationChoice authorization choice (none, user, admin)
* @param json json * @param json json
* @param nameCommand name command * @param nameCommand name command
* @param responseCode response code
* @param expected expected response * @param expected expected response
*/ */
public static void assertValidate(AuthorizationChoice authorizationChoice, String json, NameCommand nameCommand, Boolean expected) { public static void assertValidate(AuthorizationChoice authorizationChoice, String json, NameCommand nameCommand, int responseCode, Boolean expected) {
String path = getValidatePath(nameCommand); String path = getValidatePath(nameCommand);
try { try {
String[] response = null; String[] response = null;
response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(authorizationChoice, EndpointChoice.NAMES, path, json)); response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(authorizationChoice, EndpointChoice.NAMES, path, json));
ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); ITUtil.assertResponseLength2Code(response, responseCode);
ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), expected); if (expected != null) {
ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), expected);
}
} catch (IOException e) { } catch (IOException e) {
fail(); fail();
} catch (InterruptedException e) { } catch (InterruptedException e) {
......
...@@ -403,45 +403,6 @@ public class ITUtilStructureElement { ...@@ -403,45 +403,6 @@ public class ITUtilStructureElement {
// ---------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------------
/**
* Utility method to (try to) validate a structure element from given json and assert expected response.
* Method expected to NOT succeed to validate
* but instead assert response code (possibly also a non-empty message).
*
* @param json json
* @param structureCommand structure command
* @param responseCode response code
*/
public static void assertValidate(String json, StructureCommand structureCommand, int responseCode) {
assertValidate(AuthorizationChoice.NONE, json, structureCommand, responseCode);
}
/**
* Utility method to (try to) validate a structure element from given json and assert expected response.
* Method expected to NOT succeed to validate
* but instead assert response code (possibly also a non-empty message).
*
* @param authorizationChoice authorization choice (none, user, admin)
* @param json json
* @param structureCommand structure command
* @param responseCode response code
*/
public static void assertValidate(AuthorizationChoice authorizationChoice, String json, StructureCommand structureCommand, int responseCode) {
String validatePath = getValidatePath(structureCommand);
try {
String[] response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(authorizationChoice, EndpointChoice.STRUCTURES, validatePath, json));
ITUtil.assertResponseLength2Code(response, responseCode);
} catch (IOException e) {
fail();
} catch (InterruptedException e) {
fail();
} catch (Exception e) {
fail();
}
}
// --------------------
/** /**
* Utility method to validate structure element command for create and assert expected response. * Utility method to validate structure element command for create and assert expected response.
* *
...@@ -450,7 +411,7 @@ public class ITUtilStructureElement { ...@@ -450,7 +411,7 @@ public class ITUtilStructureElement {
* @param expected expected response * @param expected expected response
*/ */
public static void assertValidate(StructureElementCommandCreate structureElementCommand, StructureCommand structureCommand, Boolean expected) { public static void assertValidate(StructureElementCommandCreate structureElementCommand, StructureCommand structureCommand, Boolean expected) {
assertValidate(AuthorizationChoice.NONE, object2Json(new StructureElementCommandCreate[] {structureElementCommand}), structureCommand, expected); assertValidate(AuthorizationChoice.NONE, object2Json(new StructureElementCommandCreate[] {structureElementCommand}), structureCommand, HttpURLConnection.HTTP_OK, expected);
} }
/** /**
* Utility method to validate structure element command for update and assert expected response. * Utility method to validate structure element command for update and assert expected response.
...@@ -460,7 +421,7 @@ public class ITUtilStructureElement { ...@@ -460,7 +421,7 @@ public class ITUtilStructureElement {
* @param expected expected response * @param expected expected response
*/ */
public static void assertValidate(StructureElementCommandUpdate structureElementCommand, StructureCommand structureCommand, Boolean expected) { public static void assertValidate(StructureElementCommandUpdate structureElementCommand, StructureCommand structureCommand, Boolean expected) {
assertValidate(AuthorizationChoice.NONE, object2Json(new StructureElementCommandUpdate[] {structureElementCommand}), structureCommand, expected); assertValidate(AuthorizationChoice.NONE, object2Json(new StructureElementCommandUpdate[] {structureElementCommand}), structureCommand, HttpURLConnection.HTTP_OK, expected);
} }
/** /**
* Utility method to validate structure element command for confirm and assert expected response. * Utility method to validate structure element command for confirm and assert expected response.
...@@ -470,7 +431,7 @@ public class ITUtilStructureElement { ...@@ -470,7 +431,7 @@ public class ITUtilStructureElement {
* @param expected expected response * @param expected expected response
*/ */
public static void assertValidate(StructureElementCommandConfirm structureElementCommand, StructureCommand structureCommand, Boolean expected) { public static void assertValidate(StructureElementCommandConfirm structureElementCommand, StructureCommand structureCommand, Boolean expected) {
assertValidate(AuthorizationChoice.NONE, object2Json(new StructureElementCommandConfirm[] {structureElementCommand}), structureCommand, expected); assertValidate(AuthorizationChoice.NONE, object2Json(new StructureElementCommandConfirm[] {structureElementCommand}), structureCommand, HttpURLConnection.HTTP_OK, expected);
} }
/** /**
* Utility method to validate structure element commands for create and assert expected response. * Utility method to validate structure element commands for create and assert expected response.
...@@ -480,7 +441,7 @@ public class ITUtilStructureElement { ...@@ -480,7 +441,7 @@ public class ITUtilStructureElement {
* @param expected expected response * @param expected expected response
*/ */
public static void assertValidate(StructureElementCommandCreate[] structureElementCommands, StructureCommand structureCommand, Boolean expected) { public static void assertValidate(StructureElementCommandCreate[] structureElementCommands, StructureCommand structureCommand, Boolean expected) {
assertValidate(AuthorizationChoice.NONE, object2Json(structureElementCommands), structureCommand, expected); assertValidate(AuthorizationChoice.NONE, object2Json(structureElementCommands), structureCommand, HttpURLConnection.HTTP_OK, expected);
} }
/** /**
* Utility method to validate structure element commands for update and assert expected response. * Utility method to validate structure element commands for update and assert expected response.
...@@ -490,7 +451,7 @@ public class ITUtilStructureElement { ...@@ -490,7 +451,7 @@ public class ITUtilStructureElement {
* @param expected expected response * @param expected expected response
*/ */
public static void assertValidate(StructureElementCommandUpdate[] structureElementCommands, StructureCommand structureCommand, Boolean expected) { public static void assertValidate(StructureElementCommandUpdate[] structureElementCommands, StructureCommand structureCommand, Boolean expected) {
assertValidate(AuthorizationChoice.NONE, object2Json(structureElementCommands), structureCommand, expected); assertValidate(AuthorizationChoice.NONE, object2Json(structureElementCommands), structureCommand, HttpURLConnection.HTTP_OK, expected);
} }
/** /**
* Utility method to validate structure element commands for confirm and assert expected response. * Utility method to validate structure element commands for confirm and assert expected response.
...@@ -500,7 +461,17 @@ public class ITUtilStructureElement { ...@@ -500,7 +461,17 @@ public class ITUtilStructureElement {
* @param expected expected response * @param expected expected response
*/ */
public static void assertValidate(StructureElementCommandConfirm[] structureElementCommands, StructureCommand structureCommand, Boolean expected) { public static void assertValidate(StructureElementCommandConfirm[] structureElementCommands, StructureCommand structureCommand, Boolean expected) {
assertValidate(AuthorizationChoice.NONE, object2Json(structureElementCommands), structureCommand, expected); assertValidate(AuthorizationChoice.NONE, object2Json(structureElementCommands), structureCommand, HttpURLConnection.HTTP_OK, expected);
}
/**
* Utility method to validate structure elements and assert expected response.
*
* @param json json
* @param structureCommand structure command
* @param responseCode response code
*/
public static void assertValidate(String json, StructureCommand structureCommand, int responseCode) {
assertValidate(AuthorizationChoice.NONE, json, structureCommand, responseCode, null);
} }
/** /**
* Utility method to validate structure elements and assert expected response. * Utility method to validate structure elements and assert expected response.
...@@ -508,17 +479,20 @@ public class ITUtilStructureElement { ...@@ -508,17 +479,20 @@ public class ITUtilStructureElement {
* @param authorizationChoice authorization choice (none, user, admin) * @param authorizationChoice authorization choice (none, user, admin)
* @param json json * @param json json
* @param structureCommand structure command * @param structureCommand structure command
* @param responseCode response code
* @param expected expected response * @param expected expected response
*/ */
public static void assertValidate(AuthorizationChoice authorizationChoice, String json, StructureCommand structureCommand, Boolean expected) { public static void assertValidate(AuthorizationChoice authorizationChoice, String json, StructureCommand structureCommand, int responseCode, Boolean expected) {
String path = getValidatePath(structureCommand); String path = getValidatePath(structureCommand);
try { try {
String[] response = null; String[] response = null;
response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(authorizationChoice, EndpointChoice.STRUCTURES, path, json)); response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(authorizationChoice, EndpointChoice.STRUCTURES, path, json));
ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); ITUtil.assertResponseLength2Code(response, responseCode);
ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), expected); if (expected != null) {
ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), expected);
}
} catch (IOException e) { } catch (IOException e) {
fail(); fail();
} catch (InterruptedException e) { } catch (InterruptedException e) {
......
...@@ -504,7 +504,7 @@ class NamesIT { ...@@ -504,7 +504,7 @@ class NamesIT {
ITUtilNameElement.assertValidate( ITUtilNameElement.assertValidate(
"[" + mapper.writeValueAsString(nameElementCommandCreate) + "," + mapper.writeValueAsString(nameElementCommandCreate2) + "]", "[" + mapper.writeValueAsString(nameElementCommandCreate) + "," + mapper.writeValueAsString(nameElementCommandCreate2) + "]",
NameCommand.CREATE, HttpURLConnection.HTTP_OK, Boolean.TRUE, Boolean.TRUE); NameCommand.CREATE, HttpURLConnection.HTTP_OK);
ITUtilNameElement.assertValidate(nameElementCommandCreate, NameCommand.CREATE, Boolean.TRUE); ITUtilNameElement.assertValidate(nameElementCommandCreate, NameCommand.CREATE, Boolean.TRUE);
ITUtilNameElement.assertValidate(nameElementCommandCreate2, NameCommand.CREATE, Boolean.TRUE); ITUtilNameElement.assertValidate(nameElementCommandCreate2, NameCommand.CREATE, Boolean.TRUE);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment