/* * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Contributors: * Thomas Roger */ package org.nuxeo.ecm.restapi.test; import static org.junit.Assert.assertEquals; import org.junit.Test; import org.junit.runner.RunWith; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.test.annotations.Granularity; import org.nuxeo.ecm.core.test.annotations.RepositoryConfig; import org.nuxeo.runtime.test.runner.Deploy; import org.nuxeo.runtime.test.runner.Features; import org.nuxeo.runtime.test.runner.FeaturesRunner; import org.nuxeo.runtime.test.runner.Jetty; import org.nuxeo.runtime.test.runner.LocalDeploy; import org.nuxeo.runtime.transaction.TransactionHelper; import com.sun.jersey.api.client.ClientResponse; /** * @since 7.2 */ @RunWith(FeaturesRunner.class) @Features({ RestServerFeature.class }) @Jetty(port = 18090) @RepositoryConfig(cleanup = Granularity.METHOD, init = RestServerInit.class) @Deploy({ "org.nuxeo.ecm.actions", "org.nuxeo.ecm.platform.rendition.api", "org.nuxeo.ecm.platform.rendition.core" }) @LocalDeploy("org.nuxeo.ecm.platform.restapi.test:renditions-test-contrib.xml") public class RenditionTest extends BaseTest { @Test public void shouldRetrieveTheRendition() { DocumentModel doc = session.createDocumentModel("/", "adoc", "File"); doc = session.createDocument(doc); TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); ClientResponse response = getResponse(RequestType.GET, "path" + doc.getPathAsString() + "/@rendition/dummyRendition"); assertEquals(200, response.getStatus()); assertEquals("adoc", response.getEntity(String.class)); } @Test public void shouldFailForNonExistingRendition() { DocumentModel doc = session.createDocumentModel("/", "adoc", "File"); doc = session.createDocument(doc); TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); ClientResponse response = getResponse(RequestType.GET, "path" + doc.getPathAsString() + "/@rendition/unexistingRendition"); assertEquals(500, response.getStatus()); // should be 404? } }