Skip to content

Commit

Permalink
Fix ErrorProne errors in tests.
Browse files Browse the repository at this point in the history
Also fix some of the hundreds of warnings.  This uncovered still more
warnings that hadn't been previously reported, probably because there are
simply too many.
  • Loading branch information
mwoodiupui committed Sep 18, 2024
1 parent 353cf71 commit 082756f
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public void initialize(final ConfigurableApplicationContext applicationContext)
* Initially look for JNDI Resource called "java:/comp/env/dspace.dir".
* If not found, use value provided in "dspace.dir" in Spring Environment
*/
@SuppressWarnings("BanJNDI")
private String getDSpaceHome(ConfigurableEnvironment environment) {
// Load the "dspace.dir" property from Spring's configuration.
// This gives us the location of our DSpace configuration, which is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import com.fasterxml.jackson.databind.JsonNode;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.logging.log4j.Logger;
import org.dspace.app.rest.exception.DSpaceBadRequestException;
import org.dspace.app.rest.exception.RESTAuthorizationException;
import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
Expand All @@ -26,7 +25,6 @@
import org.dspace.app.rest.model.RestAddressableModel;
import org.dspace.app.rest.model.patch.Patch;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.service.MetadataFieldService;
import org.dspace.core.Context;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public class AuthorizationFeatureRestRepositoryIT extends AbstractControllerInte
@Autowired
private AuthorizationFeatureService authzFeatureService;

@Test
/**
* All the features should be returned
* All the features should be returned.
*
* @throws Exception
*/
@Test
public void findAllTest() throws Exception {
int featuresNum = authzFeatureService.findAll().size();
int expReturn = featuresNum > 20 ? 20 : featuresNum;
Expand All @@ -62,20 +62,20 @@ public void findAllTest() throws Exception {

}

@Test
/**
* The feature endpoint must provide proper pagination. Unauthorized and
* forbidden scenarios are managed in the findAllTest
*
* @throws Exception
*/
@Test
public void findAllWithPaginationTest() throws Exception {
int featuresNum = authzFeatureService.findAll().size();

String adminToken = getAuthToken(admin.getEmail(), password);
List<String> featureIDs = new ArrayList<String>();
List<String> featureIDs = new ArrayList<>();
for (int page = 0; page < featuresNum; page++) {
AtomicReference<String> idRef = new AtomicReference<String>();
AtomicReference<String> idRef = new AtomicReference<>();

getClient(adminToken)
.perform(get("/api/authz/features").param("page", String.valueOf(page)).param("size", "1"))
Expand All @@ -101,12 +101,13 @@ public void findAllWithPaginationTest() throws Exception {
}
}

@Test
/**
* The feature resource endpoint must expose the proper structure and be reserved to administrators
* The feature resource endpoint must expose the proper structure and be
* reserved to administrators.
*
* @throws Exception
*/
@Test
public void findOneTest() throws Exception {
getClient().perform(get("/api/authz/features/withdrawItem")).andExpect(status().isOk())
.andExpect(jsonPath("$.id", is("withdrawItem")))
Expand All @@ -121,12 +122,12 @@ public void findOneNotFoundTest() throws Exception {

}

@Test
/**
* It should be possible to find features by resourcetype. The endpoint is only available to administrators
*
* @throws Exception
*/
@Test
public void findByResourceTypeTest() throws Exception {
AuthorizationFeature alwaysTrueFeature = authzFeatureService.find(AlwaysTrueFeature.NAME);
String adminToken = getAuthToken(admin.getEmail(), password);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public class AuthorizationFeatureServiceIT extends AbstractControllerIntegration
@Autowired
private AuthorizationFeatureService authzFeatureService;

@Test
/**
* All the features available in the Sprint Context should be returned
* All the features available in the Sprint Context should be returned.
*
* @throws Exception
*/
@Test
public void findAllTest() throws Exception {
List<AuthorizationFeature> authzFeatureServiceFindAll = authzFeatureService.findAll();

Expand All @@ -70,12 +70,13 @@ public void findAllTest() throws Exception {
equalTo(featureNames.size()));
}

@Test
/**
* The find method should return existing feature and null in the case the feature doesn't exist
* The find method should return existing feature or {@code null} in the
* case the feature doesn't exist.
*
* @throws Exception
*/
@Test
public void findTest() throws Exception {
AuthorizationFeature aFeature = authzFeatureService.find(AlwaysTrueFeature.NAME);
assertThat("check that one of our mock feature is retrieved", aFeature.getName(),
Expand All @@ -85,12 +86,12 @@ public void findTest() throws Exception {
assertThat("check that not existing feature name return null", aNotExistingFeature, equalTo(null));
}

@Test
/**
* The findByResourceType must return only features that support the specified type
* The findByResourceType must return only features that support the specified type.
*
* @throws Exception
*/
@Test
public void findByResourceTypeTest() throws Exception {
// we have at least one feature that support the Site object
final String siteUniqueType = SiteRest.CATEGORY + "." + SiteRest.NAME;
Expand Down Expand Up @@ -119,12 +120,13 @@ public void findByResourceTypeTest() throws Exception {
assertThat(notExistingTypeFeatures.size(), equalTo(0));
}

@Test
/**
* The isAuthorized must return true for authorized feature and false for not authorized feature
* The isAuthorized must return {@code true} for authorized feature and
* {@code false} for not authorized feature.
*
* @throws Exception
*/
@Test
public void isAuthorizedTest() throws Exception {
Site site = siteService.findSite(context);
SiteRest siteRest = siteConverter.convert(site, DefaultProjection.DEFAULT);
Expand Down
Loading

0 comments on commit 082756f

Please sign in to comment.