-
Notifications
You must be signed in to change notification settings - Fork 74
Description
For a negative test, with OKHttp library , the exception throw is not the one expected by the test. The test is expecting com.marklogic.client.ForbiddenUserException but receives com.marklogic.client.FailedRequestException
Here is the test:
@test
// Negative test
// Test inserting a temporal document as REST reader who does not have the privilege for the
// operation
public void testInsertJSONDocumentUsingAsRESTReader() throws Exception {
// Now insert a JSON document
String jsonDocId = "javaSingleJSONDoc.json";
boolean exceptionThrown = false;
System.out
.println("Inside testInsertJSONDocumentUsingNonExistingTemporalCollection");
JacksonDatabindHandle<ObjectNode> handle = getJSONDocumentHandle(
"2001-01-01T00:00:00", "2011-12-31T23:59:59", "999 Skyway Park - JSON",
jsonDocId);
JSONDocumentManager docMgr = readerClient.newJSONDocumentManager();
docMgr.setMetadataCategories(Metadata.ALL);
// put meta-data
DocumentMetadataHandle mh = setMetadata(false);
try {
docMgr.write(jsonDocId, mh, handle, null, null, temporalCollectionName);
} catch (com.marklogic.client.ForbiddenUserException ex) {
String message = ex.getFailedRequest().getMessageCode();
int statusCode = ex.getFailedRequest().getStatusCode();
exceptionThrown = true;
System.out.println(message);
System.out.println(statusCode);
assertTrue("Error Message", message.equals("SEC-PRIV"));
assertTrue("Status code", (statusCode == 403));
}
assertTrue("Exception not thrown for invalid temporal collection",
exceptionThrown);
}
Here is the stack trace:
com.marklogic.client.FailedRequestException: Local message: Precondition required to write document. Server Message: You do not have permission to this method and URL.
at com.marklogic.client.impl.OkHttpServices.putPostDocumentImpl(OkHttpServices.java:1545)
at com.marklogic.client.impl.OkHttpServices.putDocument(OkHttpServices.java:1211)
at com.marklogic.client.impl.DocumentManagerImpl.write(DocumentManagerImpl.java:836)
at com.marklogic.client.impl.DocumentManagerImpl.write(DocumentManagerImpl.java:708)
at com.marklogic.client.impl.DocumentManagerImpl.write(DocumentManagerImpl.java:698)
at com.marklogic.client.functionaltest.TestBiTemporal.testInsertJSONDocumentUsingAsRESTReader(TestBiTemporal.java:2906)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)