Skip to content

Commit dc8ddc6

Browse files
author
Chris Wiechmann
committed
#69 Fixing an error when updating organizations
Also added error handling, when an Org-Admin tries to create a new organization.
1 parent ac02eb9 commit dc8ddc6

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerOrganizationAdapter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,15 @@ public Organization createOrUpdateOrganization(Organization desiredOrg, Organiza
122122
try {
123123
URI uri;
124124
if(actualOrg==null) {
125+
if(!APIManagerAdapter.hasAdminAccount()) {
126+
throw new AppException("Admin account is required to create a new organization", ErrorCode.NO_ADMIN_ROLE_USER);
127+
}
125128
uri = new URIBuilder(cmd.getAPIManagerURL()).setPath(RestAPICall.API_VERSION+"/organizations").build();
126129
} else {
127130
uri = new URIBuilder(cmd.getAPIManagerURL()).setPath(RestAPICall.API_VERSION+"/organizations/"+actualOrg.getId()).build();
128131
}
129132
FilterProvider filter = new SimpleFilterProvider().setDefaultFilter(
130-
SimpleBeanPropertyFilter.serializeAllExcept(new String[] {"image"}));
133+
SimpleBeanPropertyFilter.serializeAllExcept(new String[] {"image", "createdOn"}));
131134
mapper.setFilterProvider(filter);
132135
mapper.setSerializationInclusion(Include.NON_NULL);
133136
try {
@@ -137,6 +140,7 @@ public Organization createOrUpdateOrganization(Organization desiredOrg, Organiza
137140
HttpEntity entity = new StringEntity(json);
138141
request = new POSTRequest(entity, uri, true);
139142
} else {
143+
desiredOrg.setId(actualOrg.getId());
140144
String json = mapper.writeValueAsString(desiredOrg);
141145
HttpEntity entity = new StringEntity(json);
142146
request = new PUTRequest(entity, uri, true);

modules/organizations/src/test/java/com/axway/apim/organization/orgImport/ImportSimpleOrganizationTestIT.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
3333

3434
variable("orgNumber", RandomNumberFunction.getRandomNumber(4, true));
3535
variable("orgName", "My-Org-${orgNumber}");
36+
variable("orgDescription", "A description for my org");
37+
// This test must be executed with an Admin-Account as we need to create a new organization
38+
variable("oadminUsername1", "apiadmin");
39+
variable("oadminPassword1", "changeme");
3640

3741
echo("####### Import organization: '${orgName}' #######");
3842
createVariable(OrganizationImportTestAction.CONFIG, PACKAGE + "SingleOrganization.json");
@@ -50,6 +54,11 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
5054
createVariable("expectedReturnCode", "10");
5155
orgImport.doExecute(context);
5256

57+
echo("####### Change the description and import it again #######");
58+
variable("orgDescription", "My changed org description");
59+
createVariable("expectedReturnCode", "0");
60+
orgImport.doExecute(context);
61+
5362
echo("####### Export the organization #######");
5463
ErrorState.deleteInstance();
5564
variable("targetFolder", "citrus:systemProperty('java.io.tmpdir')");

modules/organizations/src/test/resources/com/axway/apim/organization/orgImport/SingleOrganization.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name" : "${orgName}",
3-
"description" : "Test Org 6425",
3+
"description" : "${orgDescription}",
44
"restricted" : false,
55
"enabled" : true,
66
"development" : true,

0 commit comments

Comments
 (0)