Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
rhbz831479 - REST return 400 bad request for invalid extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed Apr 28, 2014
1 parent c7ca62a commit c79f3d1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Expand Up @@ -1345,9 +1345,12 @@ public static void validateExtensions(Set<String> requestedExt) {
@SuppressWarnings("unchecked")
Collection<String> invalidExtensions =
CollectionUtils.subtract(requestedExt, validExtensions);
throw new RuntimeException(
"Unsupported Extensions within this context: "
+ StringUtils.join(invalidExtensions, ","));
Response response =
Response.status(Status.BAD_REQUEST)
.entity("Unsupported Extensions within this context: "
+ StringUtils.join(invalidExtensions, ","))
.build();
throw new WebApplicationException(response);
}
}

Expand Down
Expand Up @@ -3,6 +3,7 @@
import javax.ws.rs.core.Response.Status;
import javax.xml.bind.JAXBException;

import org.hamcrest.Matchers;
import org.jboss.resteasy.client.ClientResponse;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
Expand All @@ -19,6 +20,8 @@
import org.zanata.security.ZanataIdentity;
import org.zanata.service.impl.*;

import com.google.gwt.thirdparty.guava.common.collect.Sets;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

Expand Down Expand Up @@ -171,6 +174,17 @@ public void testPutGetNoExtensionTranslation(String desc,
assertThat(base.toString(), is(get.toString()));
}

@Test
public void invalidExtensionWillGetBadRequest() {
Resource res = resourceTestFactory.getTextFlowTest();
ClientResponse<TranslationsResource> response =
translationResource.getTranslations(res.getName(), DE,
Sets.newHashSet("invalidExt"), true, "etag");

assertThat(response.getStatus(),
Matchers.equalTo(Status.BAD_REQUEST.getStatusCode()));
}

private <T> T cloneDTO(T dto) {
try {
return (T) DTOUtil.toObject(DTOUtil.toXML(dto), dto.getClass());
Expand Down

0 comments on commit c79f3d1

Please sign in to comment.