Skip to content

Commit

Permalink
fix #582 - handle gracefully a null failure.getMessageCode()
Browse files Browse the repository at this point in the history
  • Loading branch information
sammefford committed Dec 6, 2016
1 parent 1856ca9 commit 3140e52
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4268,7 +4268,7 @@ private void checkStatus(ClientResponse response,
+ " " + entityType + " at " + path,
failure);
}
if (failure.getMessageCode().equals("RESTAPI-CONTENTNOVERSION")) {
if ("RESTAPI-CONTENTNOVERSION".equals(failure.getMessageCode())) {
throw new FailedRequestException("Content version required to " +
operation + " " + entityType + " at " + path, failure);
} else if (status == ClientResponse.Status.FORBIDDEN) {
Expand Down
21 changes: 18 additions & 3 deletions src/test/java/com/marklogic/client/test/EvalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.IOException;
import java.math.BigInteger;
Expand Down Expand Up @@ -44,6 +46,7 @@
import com.marklogic.client.DatabaseClient;
import com.marklogic.client.DatabaseClientFactory;
import com.marklogic.client.DatabaseClientFactory.Authentication;
import com.marklogic.client.FailedRequestException;
import com.marklogic.client.Transaction;
import com.marklogic.client.admin.ExtensionLibrariesManager;
import com.marklogic.client.document.DocumentWriteSet;
Expand All @@ -67,11 +70,11 @@
public class EvalTest {
private static GregorianCalendar septFirst = new GregorianCalendar(TimeZone.getTimeZone("CET"));
private static ExtensionLibrariesManager libMgr;
private static DatabaseClient adminClient = Common.newAdminClient();

@BeforeClass
public static void beforeClass() {
Common.connectAdmin();
libMgr = Common.client.newServerConfigManager().newExtensionLibrariesManager();
libMgr = adminClient.newServerConfigManager().newExtensionLibrariesManager();
Common.connectEval();

septFirst.set(2014, Calendar.SEPTEMBER, 1, 0, 0, 0);
Expand All @@ -80,6 +83,7 @@ public static void beforeClass() {
}
@AfterClass
public static void afterClass() {
adminClient.release();
Common.release();
}

Expand Down Expand Up @@ -449,5 +453,16 @@ public void test_171() throws Exception{
t1.rollback();
}
}
}
}

@Test
public void test_582_need_privilege() throws Exception{
try {
assertEquals("hello", adminClient.newServerEval()
.xquery("'hello'").eval().next().getString());
fail("a FailedRequestException should have been thrown since rest_admin doesn't have eval privileges");
} catch (FailedRequestException fre) {
assertTrue(fre.getMessage().contains("SEC-PRIV: Need privilege: http://marklogic.com/xdmp/privileges/xdbc-eval"));
}
}
}

0 comments on commit 3140e52

Please sign in to comment.