Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gsergiu committed Nov 13, 2024
1 parent b74bbdb commit cebf14f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public enum SetPageProfile implements UserSetProfile{
SetPageProfile(String profileParamValue, List<String> aliases, String ldPreference, String preferenceApplied) {
this.aliases = aliases;
this.profileParamValue = profileParamValue;
this.ldPreference = ldPreference;
this.preferenceApplied = preferenceApplied;
}

Expand All @@ -36,9 +37,9 @@ public String getPreferenceApplied() {
return preferenceApplied;
}

public static SetPageProfile getByLdProfile(String ldProfile) {
public static SetPageProfile getByLdPreference(String ldPreference) {
for(SetPageProfile profile : SetPageProfile.values()) {
if(profile.getProfileParamValue() != null && profile.getProfileParamValue().equals(ldProfile)) {
if(profile.getLdPreference() != null && profile.getLdPreference().equals(ldPreference)) {
return profile;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private boolean hasNameOrAlias(String urlParamValue, UserSetProfile profile) {
public List<SetPageProfile> getSetPageProfiles(String profileStr, String preferHeader) throws UserSetProfileValidationException {
List<SetPageProfile> setPageProfiles = new ArrayList<>();

if (StringUtils.isEmpty(profileStr)) {
if (StringUtils.isEmpty(preferHeader) && StringUtils.isEmpty(profileStr)) {
//quick return if empty
return setPageProfiles;
}
Expand All @@ -57,7 +57,7 @@ private void parsePreferHeader(String preferHeader, List<SetPageProfile> setPag
throw new UserSetProfileValidationException("Cannot extract profile specification from prefer header: " + preferHeader);
}

SetPageProfile profile = SetPageProfile.getByLdProfile(ldProfile);
SetPageProfile profile = SetPageProfile.getByLdPreference(ldProfile);
if(profile == null) {
throw new UserSetProfileValidationException("Invalid profile required through prefer header: " + ldProfile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import eu.europeana.set.definitions.model.vocabulary.SetProfileHelper;
import eu.europeana.set.definitions.model.vocabulary.SetResourceProfile;
import eu.europeana.set.stats.service.UsageStatsService;
import eu.europeana.set.web.config.UserSetI18nConstants;
import eu.europeana.set.web.http.UserSetHttpHeaders;
import eu.europeana.set.web.model.search.CollectionPage;
import eu.europeana.set.web.search.UserSetLdSerializer;
Expand Down Expand Up @@ -131,9 +132,13 @@ protected List<SetPageProfile> getProfilesFromRequest(String profile, HttpServle
try {
profiles = getProfileHelper().getSetPageProfiles(profile, preferHeader);
} catch (UserSetProfileValidationException e) {
String paramValue = StringUtils.isNotEmpty(preferHeader)? preferHeader : profile;
throw new ParamValidationException(I18nConstants.INVALID_PARAM_VALUE,
I18nConstants.INVALID_PARAM_VALUE, new String[] {CommonApiConstants.QUERY_PARAM_PROFILE, paramValue}, e);
if(StringUtils.isNotEmpty(preferHeader)) {
throw new ParamValidationException(UserSetI18nConstants.INVALID_HEADER_VALUE,
UserSetI18nConstants.INVALID_HEADER_VALUE, new String[] {PREFER, preferHeader}, e);
}else {
throw new ParamValidationException(I18nConstants.INVALID_PARAM_VALUE,
I18nConstants.INVALID_PARAM_VALUE, new String[] {CommonApiConstants.QUERY_PARAM_PROFILE, profile}, e);
}
}
return profiles;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import eu.europeana.api.commons.definitions.config.i18n.I18nConstants;
import eu.europeana.api.commons.web.exception.HttpException;
import eu.europeana.set.definitions.model.UserSet;
import eu.europeana.set.definitions.model.vocabulary.ProfileConstants;
Expand Down Expand Up @@ -78,7 +79,8 @@ public void testGetHeaderProfileInvalidHeaderFormat() {
"Something went wrong, check preferHeader "
);

assertTrue(StringUtils.equals(thrown.getMessage(), UserSetI18nConstants.INVALID_HEADER_FORMAT));
//assertTrue(StringUtils.equals(thrown.getMessage(), UserSetI18nConstants.INVALID_HEADER_FORMAT));
assertTrue(StringUtils.equals(thrown.getMessage(), UserSetI18nConstants.INVALID_HEADER_VALUE));
}

@Test
Expand Down

0 comments on commit cebf14f

Please sign in to comment.