Skip to content

Commit

Permalink
Address comments and improve code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sadilchamishka committed Sep 20, 2024
1 parent e6a3f48 commit b535b22
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ public Organization addOrganization(Organization organization) throws Organizati
try {
deleteOrganization(organization.getId());
} catch (OrganizationManagementException exception) {
LOG.error("Server encountered error while delete organization as rollback of organization " +
"creation failure", exception);
LOG.error("The server encountered an error while deleting the organization due to a rollback " +
"after a failed organization creation.", exception);
}
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,21 @@ public void testGetParentOrganizationId() throws OrganizationManagementException
Assert.assertEquals(organizationManager.getParentOrganizationId(ORG2_ID), ORG1_ID);
}

@Test(expectedExceptions = OrganizationManagementException.class,
expectedExceptionsMessageRegExp = ".*Server encountered error while executing post listeners.*")
public void testAddOrganizationFailWhileRoleBack() throws Exception {

Organization sampleOrganization = getOrganization(UUID.randomUUID().toString(), NEW_ORG_NAME, ORG_DESCRIPTION,
SUPER_ORG_ID, STRUCTURAL.toString());
TestUtils.mockCarbonContext(SUPER_ORG_ID);
OrganizationManagerListener mockOrgMgtListener = OrganizationManagementDataHolder.getInstance().getOrganizationManagerListener();
Mockito.doThrow(new OrganizationManagementException("Server encountered error while executing post listeners."))
.when(mockOrgMgtListener).postAddOrganization(sampleOrganization);
Mockito.doThrow(new OrganizationManagementException("Server encountered error while deleting organization."))
.when(mockOrgMgtListener).preDeleteOrganization(sampleOrganization.getId());
organizationManager.addOrganization(sampleOrganization);
}

private void setOrganizationAttributes(Organization organization, String key, String value) {

OrganizationAttribute organizationAttribute = new OrganizationAttribute(key, value);
Expand Down

0 comments on commit b535b22

Please sign in to comment.