|
| 1 | +/* |
| 2 | + * Copyright 2012-2014 MarkLogic Corporation |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.marklogic.client.test; |
| 17 | + |
| 18 | +import static org.junit.Assert.assertEquals; |
| 19 | + |
| 20 | +import org.junit.Test; |
| 21 | + |
| 22 | +import com.marklogic.client.DatabaseClient; |
| 23 | +import com.marklogic.client.DatabaseClientFactory; |
| 24 | +import com.marklogic.client.DatabaseClientFactory.Authentication; |
| 25 | +import com.marklogic.client.document.TextDocumentManager; |
| 26 | +import com.marklogic.client.io.StringHandle; |
| 27 | + |
| 28 | +public class InvalidUserTest { |
| 29 | + @Test |
| 30 | + public void testInvalidUserAuth() { |
| 31 | + |
| 32 | + // create the client |
| 33 | + DatabaseClient client = DatabaseClientFactory.newClient( |
| 34 | + "localhost", 8012, "MyFooUser", "x", Authentication.DIGEST); |
| 35 | + |
| 36 | + |
| 37 | + String expectedException = "com.marklogic.client.FailedRequestException: " + |
| 38 | + "Local message: write failed: Unauthorized. Server Message: Unauthorized"; |
| 39 | + String exception = ""; |
| 40 | + |
| 41 | + String docId = "/example/text.txt"; |
| 42 | + TextDocumentManager docMgr = client.newTextDocumentManager(); |
| 43 | + // write doc |
| 44 | + try |
| 45 | + { |
| 46 | + // make use of the client connection |
| 47 | + StringHandle handle = new StringHandle(); |
| 48 | + handle.set("A simple text document"); |
| 49 | + docMgr.write(docId, handle); |
| 50 | + assertEquals(expectedException, exception); |
| 51 | + docMgr.delete(docId); |
| 52 | + } |
| 53 | + catch (Exception e) { |
| 54 | + exception = e.toString(); |
| 55 | + } finally { |
| 56 | + client.release(); |
| 57 | + } |
| 58 | + |
| 59 | + } |
| 60 | +} |
0 commit comments