01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.solr.update;
17:
18: import java.io.ByteArrayInputStream;
19: import java.io.IOException;
20: import java.io.InputStream;
21: import java.util.ArrayList;
22: import java.util.Collection;
23: import java.util.HashMap;
24:
25: import org.apache.lucene.document.Document;
26: import org.apache.lucene.document.Field;
27: import org.apache.lucene.document.Field.Index;
28: import org.apache.lucene.document.Field.Store;
29: import org.apache.solr.core.SolrCore;
30: import org.apache.solr.core.SolrException;
31: import org.apache.solr.handler.XmlUpdateRequestHandler;
32: import org.apache.solr.request.MapSolrParams;
33: import org.apache.solr.request.SolrQueryRequestBase;
34: import org.apache.solr.request.SolrQueryResponse;
35: import org.apache.solr.util.AbstractSolrTestCase;
36: import org.apache.solr.util.ContentStream;
37:
38: /**
39: *
40: * @author ryan
41: *
42: */
43: public class DirectUpdateHandlerTest extends AbstractSolrTestCase {
44:
45: public String getSchemaFile() {
46: return "schema.xml";
47: }
48:
49: public String getSolrConfigFile() {
50: return "solrconfig.xml";
51: }
52:
53: public void testRequireUniqueKey() throws Exception {
54: SolrCore core = SolrCore.getSolrCore();
55:
56: UpdateHandler updater = core.getUpdateHandler();
57:
58: AddUpdateCommand cmd = new AddUpdateCommand();
59: cmd.overwriteCommitted = true;
60: cmd.overwritePending = true;
61: cmd.allowDups = false;
62:
63: // Add a valid document
64: cmd.doc = new Document();
65: cmd.doc.add(new Field("id", "AAA", Store.YES,
66: Index.UN_TOKENIZED));
67: cmd.doc.add(new Field("subject", "xxxxx", Store.YES,
68: Index.UN_TOKENIZED));
69: updater.addDoc(cmd);
70:
71: // Add a document with multiple ids
72: cmd.indexedId = null; // reset the id for this add
73: cmd.doc = new Document();
74: cmd.doc.add(new Field("id", "AAA", Store.YES,
75: Index.UN_TOKENIZED));
76: cmd.doc.add(new Field("id", "BBB", Store.YES,
77: Index.UN_TOKENIZED));
78: cmd.doc.add(new Field("subject", "xxxxx", Store.YES,
79: Index.UN_TOKENIZED));
80: try {
81: updater.addDoc(cmd);
82: fail("added a document with multiple ids");
83: } catch (SolrException ex) {
84: } // expected
85:
86: // Add a document without an id
87: cmd.indexedId = null; // reset the id for this add
88: cmd.doc = new Document();
89: cmd.doc.add(new Field("subject", "xxxxx", Store.YES,
90: Index.UN_TOKENIZED));
91: try {
92: updater.addDoc(cmd);
93: fail("added a document without an ids");
94: } catch (SolrException ex) {
95: } // expected
96: }
97:
98: }
|