|
9 | 9 | import org.testng.annotations.Parameters; |
10 | 10 | import org.testng.annotations.Test; |
11 | 11 |
|
| 12 | +import com.axway.apim.adapter.APIManagerAdapter; |
12 | 13 | import com.axway.apim.api.model.apps.ClientApplication; |
13 | 14 | import com.axway.apim.lib.errorHandling.AppException; |
14 | 15 | import com.axway.apim.user.it.ExportUserTestAction; |
@@ -61,50 +62,62 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio |
61 | 62 |
|
62 | 63 | echo("####### Try to login with created user #######"); |
63 | 64 | http(builder -> builder.client("apiManager").send().post("/login").payload("username=${loginName}&password=${password}&success=/title").header("Content-Type", "application/x-www-form-urlencoded")); |
64 | | - |
65 | | - echo("####### Change some user details #######"); |
66 | | - variable("phone", "+1111111111111"); |
67 | | - variable("mobile", "+2222222222222"); |
68 | | - variable("userCustomProperty1", "Changed custom value 1"); |
69 | | - variable("userCustomProperty2", "3"); |
70 | | - variable("userCustomProperty3", "false"); |
71 | | - importApp.doExecute(context); |
72 | | - |
73 | | - echo("####### Validate details of user: '${loginName}' (ID: ${userId}) have changed #######"); |
74 | | - http(builder -> builder.client("apiManager").send().get("/users/${userId}").header("Content-Type", "application/json")); |
75 | | - http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON) |
76 | | - .validate("$.[?(@.loginName=='${loginName}')].userCustomProperty1", "Changed custom value 1") |
77 | | - .validate("$.[?(@.loginName=='${loginName}')].userCustomProperty2", "3") |
78 | | - .validate("$.[?(@.loginName=='${loginName}')].userCustomProperty3", "false") |
79 | | - .validate("$.[?(@.loginName=='${loginName}')].phone", "+1111111111111") |
80 | | - .validate("$.[?(@.loginName=='${loginName}')].mobile", "+2222222222222")); |
81 | | - |
82 | | - echo("####### Re-Import same user - Should be a No-Change #######"); |
83 | | - createVariable(PARAM_EXPECTED_RC, "10"); |
84 | | - importApp.doExecute(context); |
85 | | - |
86 | | - echo("####### Export the user #######"); |
87 | | - variable("targetFolder", "citrus:systemProperty('java.io.tmpdir')"); |
88 | | - createVariable(PARAM_TARGET, exportApp.getTestDirectory().getPath()); |
89 | | - createVariable(PARAM_LOGINNAME, "${loginName}"); |
90 | | - createVariable(PARAM_OUTPUT_FORMAT, "json"); |
91 | | - createVariable(PARAM_EXPECTED_RC, "0"); |
92 | | - exportApp.doExecute(context); |
93 | | - |
94 | | - Assert.assertEquals(exportApp.getLastResult().getExportedFiles().size(), 1, "One exported user is expected."); |
95 | | - String exportedConfig = exportApp.getLastResult().getExportedFiles().get(0); |
96 | | - |
97 | | - ClientApplication exportedUser = mapper.readValue(new File(exportedConfig), ClientApplication.class); |
98 | | - |
99 | | - Assert.assertNotNull(exportedUser.getCustomProperties(), "Exported user must have custom properties"); |
100 | | - Assert.assertEquals(exportedUser.getCustomProperties().size(), 3, "Exported user must have 3 custom properties"); |
101 | | - Assert.assertEquals(exportedUser.getCustomProperties().get("userCustomProperty1"), "Changed custom value 1"); |
102 | | - Assert.assertEquals(exportedUser.getCustomProperties().get("userCustomProperty2"), "3"); |
103 | | - Assert.assertEquals(exportedUser.getCustomProperties().get("userCustomProperty3"), "false"); |
104 | | - |
105 | | - echo("####### Re-Import EXPORTED user - Should be a No-Change #######"); |
106 | | - createVariable(PARAM_CONFIGFILE, exportedConfig); |
107 | | - createVariable("expectedReturnCode", "10"); |
108 | | - importApp.doExecute(context); |
| 65 | + |
| 66 | + /* |
| 67 | + * The following tests are only executed on newer API Manager versions. On older versions, updating a user fails with the error message: |
| 68 | + * {"errors":[{"code":500, "message": "Internal server error"}]}. |
| 69 | + * The API Manager reports this in the trace log: |
| 70 | + * java.lang.IllegalArgumentException: Cannot refine property with name: orgs2Role, as this property is not defined in the type: API Portal_PortalUsers |
| 71 | + * The reason is that the FED file: swagger-promote-7.7-20200130.fed for building the test images of earlier versions did not yet |
| 72 | + * include the update of the KPS table PortalUsers. |
| 73 | + * So the conclusion is that the CLI code works and there is no problem at this point with the CLI. The effort to update the test images |
| 74 | + * is in no relation to the benefit. |
| 75 | + */ |
| 76 | + if(APIManagerAdapter.hasAPIManagerVersion("7.7.20200930")) { |
| 77 | + echo("####### Change some user details #######"); |
| 78 | + variable("phone", "+1111111111111"); |
| 79 | + variable("mobile", "+2222222222222"); |
| 80 | + variable("userCustomProperty1", "Changed custom value 1"); |
| 81 | + variable("userCustomProperty2", "3"); |
| 82 | + variable("userCustomProperty3", "false"); |
| 83 | + importApp.doExecute(context); |
| 84 | + |
| 85 | + echo("####### Validate details of user: '${loginName}' (ID: ${userId}) have changed #######"); |
| 86 | + http(builder -> builder.client("apiManager").send().get("/users/${userId}").header("Content-Type", "application/json")); |
| 87 | + http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON) |
| 88 | + .validate("$.[?(@.loginName=='${loginName}')].userCustomProperty1", "Changed custom value 1") |
| 89 | + .validate("$.[?(@.loginName=='${loginName}')].userCustomProperty2", "3") |
| 90 | + .validate("$.[?(@.loginName=='${loginName}')].userCustomProperty3", "false") |
| 91 | + .validate("$.[?(@.loginName=='${loginName}')].phone", "+1111111111111") |
| 92 | + .validate("$.[?(@.loginName=='${loginName}')].mobile", "+2222222222222")); |
| 93 | + |
| 94 | + echo("####### Re-Import same user - Should be a No-Change #######"); |
| 95 | + createVariable(PARAM_EXPECTED_RC, "10"); |
| 96 | + importApp.doExecute(context); |
| 97 | + |
| 98 | + echo("####### Export the user #######"); |
| 99 | + variable("targetFolder", "citrus:systemProperty('java.io.tmpdir')"); |
| 100 | + createVariable(PARAM_TARGET, exportApp.getTestDirectory().getPath()); |
| 101 | + createVariable(PARAM_LOGINNAME, "${loginName}"); |
| 102 | + createVariable(PARAM_OUTPUT_FORMAT, "json"); |
| 103 | + createVariable(PARAM_EXPECTED_RC, "0"); |
| 104 | + exportApp.doExecute(context); |
| 105 | + |
| 106 | + Assert.assertEquals(exportApp.getLastResult().getExportedFiles().size(), 1, "One exported user is expected."); |
| 107 | + String exportedConfig = exportApp.getLastResult().getExportedFiles().get(0); |
| 108 | + |
| 109 | + ClientApplication exportedUser = mapper.readValue(new File(exportedConfig), ClientApplication.class); |
| 110 | + |
| 111 | + Assert.assertNotNull(exportedUser.getCustomProperties(), "Exported user must have custom properties"); |
| 112 | + Assert.assertEquals(exportedUser.getCustomProperties().size(), 3, "Exported user must have 3 custom properties"); |
| 113 | + Assert.assertEquals(exportedUser.getCustomProperties().get("userCustomProperty1"), "Changed custom value 1"); |
| 114 | + Assert.assertEquals(exportedUser.getCustomProperties().get("userCustomProperty2"), "3"); |
| 115 | + Assert.assertEquals(exportedUser.getCustomProperties().get("userCustomProperty3"), "false"); |
| 116 | + |
| 117 | + echo("####### Re-Import EXPORTED user - Should be a No-Change #######"); |
| 118 | + createVariable(PARAM_CONFIGFILE, exportedConfig); |
| 119 | + createVariable("expectedReturnCode", "10"); |
| 120 | + importApp.doExecute(context); |
| 121 | + } |
109 | 122 | } |
110 | 123 | } |
0 commit comments