lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From no...@apache.org
Subject [1/3] lucene-solr git commit: SOLR-8029 renamed class/dirs and removed the 'v2' part
Date Thu, 11 Feb 2016 21:11:07 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/apiv2 292fe4a19 -> 3cfebd53f


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3cfebd53/solr/core/src/test/org/apache/solr/handler/admin/TestApiFramework.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/TestApiFramework.java b/solr/core/src/test/org/apache/solr/handler/admin/TestApiFramework.java
new file mode 100644
index 0000000..53735bf
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/handler/admin/TestApiFramework.java
@@ -0,0 +1,184 @@
+package org.apache.solr.handler.admin;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.common.params.MapSolrParams;
+import org.apache.solr.common.util.Predicate;
+import org.apache.solr.common.util.StrUtils;
+import org.apache.solr.common.util.Utils;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.PluginBag;
+import org.apache.solr.handler.PingRequestHandler;
+import org.apache.solr.handler.SchemaHandler;
+import org.apache.solr.handler.SolrConfigHandler;
+import org.apache.solr.request.LocalSolrQueryRequest;
+import org.apache.solr.request.SolrRequestHandler;
+import org.apache.solr.response.SolrQueryResponse;
+import org.apache.solr.v2api.Api;
+import org.apache.solr.v2api.V2HttpCall;
+import org.apache.solr.v2api.V2RequestContext;
+
+import static org.apache.solr.client.solrj.SolrRequest.METHOD.GET;
+import static org.apache.solr.common.params.CommonParams.COLLECTIONS_HANDLER_PATH;
+import static org.apache.solr.common.params.CommonParams.CORES_HANDLER_PATH;
+import static org.apache.solr.common.util.Map2.NOT_NULL;
+import static org.apache.solr.handler.admin.TestCollectionAPIs.getV2RequestContext;
+
+public class TestApiFramework extends SolrTestCaseJ4 {
+
+  public void testFramework() {
+    Map<String, Object[]> calls = new HashMap<>();
+    Map<String, Object> out = new HashMap<>();
+    CoreContainer mockCC = TestCoreAdminApis.getCoreContainerMock(calls, out);
+    PluginBag<SolrRequestHandler> containerHandlers = new PluginBag<>(SolrRequestHandler.class,
null, false);
+    containerHandlers.put(COLLECTIONS_HANDLER_PATH, new TestCollectionAPIs.MockCollectionsHandler());
+    containerHandlers.put(CORES_HANDLER_PATH, new CoreAdminHandler(mockCC));
+    out.put("getRequestHandlers", containerHandlers);
+
+    PluginBag<SolrRequestHandler> coreHandlers = new PluginBag<>(SolrRequestHandler.class,
null, false);
+    coreHandlers.put("/schema", new SchemaHandler());
+    coreHandlers.put("/config", new SolrConfigHandler());
+    coreHandlers.put("/admin/ping", new PingRequestHandler());
+
+    Map<String, String> parts = new HashMap<>();
+    String fullPath = "/collections/hello/shards";
+    Api api = V2HttpCall.getApiInfo(containerHandlers, fullPath, "GET",
+        mockCC, "collections", fullPath, parts);
+    assertNotNull(api);
+    assertConditions(api.getSpec(), Utils.makeMap(
+        "/methods[0]", "GET",
+        "/methods[1]", "POST",
+        "/commands/create", NOT_NULL));
+    assertEquals("hello", parts.get("collection"));
+
+    parts = new HashMap<>();
+    api = V2HttpCall.getApiInfo(containerHandlers, "/collections/hello/shards/shard1", "GET",
+        mockCC, "collections", null, parts);
+    assertConditions(api.getSpec(), Utils.makeMap(
+        "/methods[0]", "POST",
+        "/methods[1]", "GET",
+        "/methods[2]", "DELETE",
+        "/commands/split", NOT_NULL,
+        "/commands/add-replica", NOT_NULL,
+        "/commands/force-leader", NOT_NULL
+    ));
+    assertEquals("hello", parts.get("collection"));
+    assertEquals("shard1", parts.get("shard"));
+
+
+    parts = new HashMap<>();
+    api = V2HttpCall.getApiInfo(containerHandlers, "/collections/hello/shards/shard1/replica1",
"GET",
+        mockCC, "collections", null, parts);
+    assertConditions(api.getSpec(), Utils.makeMap(
+        "/methods[0]", "GET",
+        "/methods[1]", "POST",
+        "/commands/set", NOT_NULL
+    ));
+    assertEquals("hello", parts.get("collection"));
+    assertEquals("shard1", parts.get("shard"));
+    assertEquals("replica1", parts.get("replica"));
+
+    api = V2HttpCall.getApiInfo(containerHandlers, "/collections/hello/shards/shard1/replica1",
"DELETE",
+        mockCC, "collections", null, parts);
+    assertConditions(api.getSpec(), Utils.makeMap(
+        "/methods[0]", "DELETE",
+        "/url/params/onlyIfDown/type", "boolean"
+    ));
+    assertEquals("hello", parts.get("collection"));
+    assertEquals("shard1", parts.get("shard"));
+    assertEquals("replica1", parts.get("replica"));
+
+    SolrQueryResponse rsp = invoke(containerHandlers, "/collections/_introspect", GET, mockCC);
+
+    assertConditions(rsp.getValues().asMap(2), Utils.makeMap(
+        "/spec[0]/methods[0]", "POST",
+        "/spec[0]/methods[1]", "GET"));
+
+    rsp = invoke(coreHandlers, "/collections/hello/schema/_introspect", GET, mockCC);
+    assertConditions(rsp.getValues().asMap(2), Utils.makeMap(
+        "/spec[0]/methods[0]", "POST",
+        "/spec[0]/commands", NOT_NULL,
+        "/spec[1]/methods[0]", "GET"));
+
+    rsp = invoke(coreHandlers, "/collections/hello", GET, mockCC);
+    assertConditions(rsp.getValues().asMap(2), Utils.makeMap(
+        "/availableSubPaths", NOT_NULL,
+        "availableSubPaths /collections/hello/config/jmx", NOT_NULL,
+        "availableSubPaths /collections/hello/schema", NOT_NULL,
+        "availableSubPaths /collections/hello/shards", NOT_NULL,
+        "availableSubPaths /collections/hello/shards/{shard}", NOT_NULL,
+        "availableSubPaths /collections/hello/shards/{shard}/{replica}", NOT_NULL
+    ));
+
+    rsp = invoke(coreHandlers,"/collections/hello/schema",SolrRequest.METHOD.POST, mockCC);
+
+
+
+  }
+
+  private SolrQueryResponse invoke(PluginBag<SolrRequestHandler> reqHandlers, String
path, SolrRequest.METHOD method,
+                                   CoreContainer mockCC) {
+    HashMap<String, String> parts = new HashMap<>();
+    boolean containerHandlerLookup = mockCC.getRequestHandlers() == reqHandlers;
+    String fullPath = path;
+    String prefix = null;
+    if (!containerHandlerLookup) {
+      int idx = path.indexOf('/', 1);
+      prefix = path.substring(1, idx);
+      if (idx > 0) idx = path.indexOf('/', idx + 1);
+      path = idx == -1 ? "/" : path.substring(idx);
+    }
+
+    Api api = V2HttpCall.getApiInfo(reqHandlers, path, "GET", mockCC, prefix, fullPath, parts);
+    LocalSolrQueryRequest req = new LocalSolrQueryRequest(null, new MapSolrParams(new HashMap<>()));
+    V2RequestContext ctx = getV2RequestContext( path, method, null, mockCC, parts, api, req);
+    api.call(ctx);
+    return ctx.getResponse();
+
+  }
+
+
+  private void assertConditions(Map root, Map conditions) {
+    for (Object o : conditions.entrySet()) {
+      Map.Entry e = (Map.Entry) o;
+      String path = (String) e.getKey();
+      List<String> parts = StrUtils.splitSmart(path, path.charAt(0) == '/' ?  '/':'
');
+      if (parts.get(0).isEmpty()) parts.remove(0);
+      Object val = Utils.getObjectByPath(root, false, parts);
+      if (e.getValue() instanceof Predicate) {
+        Predicate value = (Predicate) e.getValue();
+        String err = value.test(val);
+        if(err != null){
+          assertEquals(err + " for " + e.getKey() + " in :" + Utils.toJSONString(root), e.getValue(),
val);
+        }
+
+      } else {
+        assertEquals("incorrect value for path " + e.getKey() + " in :" + Utils.toJSONString(root),
e.getValue(), val);
+      }
+    }
+
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3cfebd53/solr/core/src/test/org/apache/solr/handler/admin/TestCollectionAPIs.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/TestCollectionAPIs.java b/solr/core/src/test/org/apache/solr/handler/admin/TestCollectionAPIs.java
new file mode 100644
index 0000000..4b538b4
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/handler/admin/TestCollectionAPIs.java
@@ -0,0 +1,153 @@
+package org.apache.solr.handler.admin;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+
+import java.io.StringReader;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.common.cloud.ZkNodeProps;
+import org.apache.solr.common.params.MapSolrParams;
+import org.apache.solr.common.util.Utils;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.request.LocalSolrQueryRequest;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.response.SolrQueryResponse;
+import org.apache.solr.util.CommandOperation;
+import org.apache.solr.v2api.Api;
+import org.apache.solr.v2api.ApiBag;
+import org.apache.solr.v2api.V2HttpCall;
+import org.apache.solr.v2api.V2RequestContext;
+
+import static org.apache.solr.cloud.Overseer.QUEUE_OPERATION;
+
+public class TestCollectionAPIs extends SolrTestCaseJ4 {
+
+  public void testCreate() throws Exception{
+    MockCollectionsHandler collectionsHandler = new MockCollectionsHandler();
+    ApiBag apiBag = new ApiBag();
+    Collection<Api> apis = collectionsHandler.getApis();
+    for (Api api : apis) apiBag.register(api, Collections.EMPTY_MAP);
+    //test a simple create collection call
+    V2RequestContext ctx = makeCall(apiBag, "/collections", SolrRequest.METHOD.POST,
+        "{create:{name:'newcoll', config:'schemaless', numShards:2, replicationFactor:2 }}",
null);
+    assertMapEqual((Map) Utils.fromJSONString("{name:newcoll, fromApi:'true', replicationFactor:'2',
collection.configName:schemaless, numShards:'2', stateFormat:'2', operation:create}"),
+        (ZkNodeProps) ctx.getSolrRequest().getContext().get(ZkNodeProps.class.getName()));
+
+    //test a create collection with custom properties
+    ctx = makeCall(apiBag, "/collections", SolrRequest.METHOD.POST,
+        "{create:{name:'newcoll', config:'schemaless', numShards:2, replicationFactor:2,
properties:{prop1:'prop1val', prop2: prop2val} }}", null);
+
+    assertMapEqual(
+        (Map) Utils.fromJSONString("{name:newcoll, fromApi:'true', replicationFactor:'2',
collection.configName:schemaless, numShards:'2', stateFormat:'2', operation:create, property.prop1:prop1val,
property.prop2:prop2val}"),
+        (ZkNodeProps) ctx.getSolrRequest().getContext().get(ZkNodeProps.class.getName()));
+
+  }
+
+  public static V2RequestContext makeCall(final ApiBag apiBag, final String path, final SolrRequest.METHOD
method,
+                                    final String payload, final CoreContainer cc) throws
Exception {
+    final HashMap<String, String> parts = new HashMap<>();
+    Api api = apiBag.lookup(path, method.toString(), parts);
+    if (api == null) throw new RuntimeException("No handler at path :" + path);
+    LocalSolrQueryRequest req = new LocalSolrQueryRequest(null, new MapSolrParams(new HashMap<>()));
+    V2RequestContext ctx = getV2RequestContext(path, method, payload, cc, parts, api, req);
+    api.call(ctx);
+    return ctx;
+  }
+
+  public static V2RequestContext getV2RequestContext(final String path,
+                                                     final SolrRequest.METHOD method,
+                                                     final String payload,
+                                                     final CoreContainer cc,
+                                                     final HashMap<String, String>
parts,
+                                                     final Api api,
+                                                     final LocalSolrQueryRequest req) {
+    return new V2RequestContext() {
+      SolrQueryResponse rsp = new SolrQueryResponse();
+
+      @Override
+      public SolrQueryResponse getResponse() {
+        return rsp;
+      }
+
+      @Override
+      public CoreContainer getCoreContainer() {
+        return cc;
+      }
+
+      @Override
+      public SolrQueryRequest getSolrRequest() {
+        return req;
+      }
+
+      @Override
+      public String getPath() {
+        return path;
+      }
+
+      @Override
+      public Map<String, String> getPathValues() {
+        return parts;
+      }
+
+      @Override
+      public List<CommandOperation> getCommands(boolean validateInput) {
+        return V2HttpCall.getCommandOperations(new StringReader(payload), api.getSpec(),
rsp);
+      }
+
+      @Override
+      public String getHttpMethod() {
+        return method.toString();
+      }
+    };
+  }
+
+  private void assertMapEqual(Map expected, ZkNodeProps actual) {
+    assertEquals(expected.size(), actual.getProperties().size());
+    for (Object o : expected.entrySet()) {
+      Map.Entry e = (Map.Entry) o;
+      assertEquals(e.getValue(), actual.get((String) e.getKey()));
+    }
+  }
+
+  static class MockCollectionsHandler extends CollectionsHandler {
+    LocalSolrQueryRequest req;
+
+    MockCollectionsHandler() {
+
+    }
+
+
+    @Override
+    protected void invokeAction(SolrQueryRequest req, SolrQueryResponse rsp, CollectionOperation
operation) throws Exception {
+      Map<String, Object> result = operation.call(req, rsp, this);
+      if (result != null) {
+        result.put(QUEUE_OPERATION, operation.action.toLower());
+        req.getContext().put(ZkNodeProps.class.getName(),new ZkNodeProps(result) );
+      }
+    }
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3cfebd53/solr/core/src/test/org/apache/solr/handler/admin/TestCoreAdminApis.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/TestCoreAdminApis.java b/solr/core/src/test/org/apache/solr/handler/admin/TestCoreAdminApis.java
new file mode 100644
index 0000000..b6ad4c5
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/handler/admin/TestCoreAdminApis.java
@@ -0,0 +1,102 @@
+package org.apache.solr.handler.admin;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.PluginBag;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.v2api.Api;
+import org.apache.solr.v2api.ApiBag;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+
+import static org.easymock.EasyMock.getCurrentArguments;
+
+public class TestCoreAdminApis extends SolrTestCaseJ4 {
+
+  public void testCreate() throws Exception {
+    Map<String, Object[]> calls = new HashMap<>();
+    CoreContainer mockCC = getCoreContainerMock(calls, new HashMap<>());
+
+    CoreAdminHandler  coreAdminHandler = new CoreAdminHandler(mockCC);
+    ApiBag apiBag = new ApiBag();
+    for (Api api : coreAdminHandler.getApis()) {
+      apiBag.register(api, Collections.EMPTY_MAP);
+    }
+    TestCollectionAPIs.makeCall(apiBag, "/cores", SolrRequest.METHOD.POST,
+        "{create:{name: hello, instanceDir : someDir, config : 'solrconfig.xml', schema:
'schema.xml'}}", mockCC);
+    Object[] create = calls.get("create");
+    assertEquals("hello" ,create[0]);
+    HashMap expected = new HashMap();
+    expected.put("schema", "schema.xml");
+    expected.put("config", "solrconfig.xml");
+    assertEquals(expected ,create[2]);
+
+  }
+
+  public static CoreContainer getCoreContainerMock(final Map<String, Object[]> in,Map<String,Object>
out ) {
+    CoreContainer mockCC = EasyMock.createMock(CoreContainer.class);
+    EasyMock.reset(mockCC);
+    mockCC.create(EasyMock.anyObject(String.class), EasyMock.anyObject(Path.class ) ,EasyMock.anyObject(Map.class));
+    EasyMock.expectLastCall().andAnswer(new IAnswer<SolrCore>() {
+      @Override
+      public SolrCore answer() throws Throwable {
+        in.put("create", getCurrentArguments());
+        return null;
+      }
+    }).anyTimes();
+
+    mockCC.getCoreRootDirectory();
+    EasyMock.expectLastCall().andAnswer(new IAnswer<Path>() {
+      @Override
+      public Path answer() throws Throwable {
+        return Paths.get("coreroot");
+      }
+    }).anyTimes();
+    mockCC.getContainerProperties();
+    EasyMock.expectLastCall().andAnswer(new IAnswer<Properties>() {
+      @Override
+      public Properties answer() throws Throwable {
+        return new Properties();
+      }
+    }).anyTimes();
+
+    mockCC.getRequestHandlers();
+    EasyMock.expectLastCall().andAnswer(new IAnswer<PluginBag>() {
+      @Override
+      public PluginBag answer() throws Throwable {
+        return (PluginBag)out.get("getRequestHandlers");
+      }
+    }).anyTimes();
+
+    EasyMock.replay(mockCC);
+    return mockCC;
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3cfebd53/solr/core/src/test/org/apache/solr/handler/admin/TestV2CollectionAPIs.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/TestV2CollectionAPIs.java b/solr/core/src/test/org/apache/solr/handler/admin/TestV2CollectionAPIs.java
deleted file mode 100644
index 8f87352..0000000
--- a/solr/core/src/test/org/apache/solr/handler/admin/TestV2CollectionAPIs.java
+++ /dev/null
@@ -1,160 +0,0 @@
-package org.apache.solr.handler.admin;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.StringReader;
-import java.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.client.solrj.SolrRequest;
-import org.apache.solr.common.cloud.ZkNodeProps;
-import org.apache.solr.common.params.MapSolrParams;
-import org.apache.solr.common.util.Lookup;
-import org.apache.solr.common.util.Map2;
-import org.apache.solr.common.util.Utils;
-import org.apache.solr.core.CoreContainer;
-import org.apache.solr.request.LocalSolrQueryRequest;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.response.SolrQueryResponse;
-import org.apache.solr.servlet.SolrDispatchFilter;
-import org.apache.solr.util.CommandOperation;
-import org.apache.solr.v2api.ApiBag;
-import org.apache.solr.v2api.V2Api;
-import org.apache.solr.v2api.V2HttpCall;
-import org.apache.solr.v2api.V2RequestContext;
-import org.apache.zookeeper.server.ByteBufferInputStream;
-
-import static org.apache.solr.cloud.Overseer.QUEUE_OPERATION;
-
-public class TestV2CollectionAPIs extends SolrTestCaseJ4 {
-
-  public void testCreate() throws Exception{
-    MockCollectionsHandler collectionsHandler = new MockCollectionsHandler();
-    ApiBag apiBag = new ApiBag();
-    Collection<V2Api> apis = collectionsHandler.getApis();
-    for (V2Api api : apis) apiBag.register(api, Collections.EMPTY_MAP);
-    //test a simple create collection call
-    V2RequestContext ctx = makeCall(apiBag, "/collections", SolrRequest.METHOD.POST,
-        "{create:{name:'newcoll', config:'schemaless', numShards:2, replicationFactor:2 }}",
null);
-    assertMapEqual((Map) Utils.fromJSONString("{name:newcoll, fromApi:'true', replicationFactor:'2',
collection.configName:schemaless, numShards:'2', stateFormat:'2', operation:create}"),
-        (ZkNodeProps) ctx.getSolrRequest().getContext().get(ZkNodeProps.class.getName()));
-
-    //test a create collection with custom properties
-    ctx = makeCall(apiBag, "/collections", SolrRequest.METHOD.POST,
-        "{create:{name:'newcoll', config:'schemaless', numShards:2, replicationFactor:2,
properties:{prop1:'prop1val', prop2: prop2val} }}", null);
-
-    assertMapEqual(
-        (Map) Utils.fromJSONString("{name:newcoll, fromApi:'true', replicationFactor:'2',
collection.configName:schemaless, numShards:'2', stateFormat:'2', operation:create, property.prop1:prop1val,
property.prop2:prop2val}"),
-        (ZkNodeProps) ctx.getSolrRequest().getContext().get(ZkNodeProps.class.getName()));
-
-  }
-
-  public static V2RequestContext makeCall(final ApiBag apiBag, final String path, final SolrRequest.METHOD
method,
-                                    final String payload, final CoreContainer cc) throws
Exception {
-    final HashMap<String, String> parts = new HashMap<>();
-    V2Api api = apiBag.lookup(path, method.toString(), parts);
-    if (api == null) throw new RuntimeException("No handler at path :" + path);
-    LocalSolrQueryRequest req = new LocalSolrQueryRequest(null, new MapSolrParams(new HashMap<String,
String>()));
-    V2RequestContext ctx = getV2RequestContext(path, method, payload, cc, parts, api, req);
-    api.call(ctx);
-    return ctx;
-  }
-
-  public static V2RequestContext getV2RequestContext(final String path,
-                                                     final SolrRequest.METHOD method,
-                                                     final String payload,
-                                                     final CoreContainer cc,
-                                                     final HashMap<String, String>
parts,
-                                                     final V2Api api,
-                                                     final LocalSolrQueryRequest req) {
-    return new V2RequestContext() {
-      SolrQueryResponse rsp = new SolrQueryResponse();
-
-      @Override
-      public SolrQueryResponse getResponse() {
-        return rsp;
-      }
-
-      @Override
-      public CoreContainer getCoreContainer() {
-        return cc;
-      }
-
-      @Override
-      public SolrQueryRequest getSolrRequest() {
-        return req;
-      }
-
-      @Override
-      public String getPath() {
-        return path;
-      }
-
-      @Override
-      public Map<String, String> getPathValues() {
-        return parts;
-      }
-
-      @Override
-      public List<CommandOperation> getCommands(boolean validateInput) {
-        return V2HttpCall.getCommandOperations(new StringReader(payload), api.getSpec(),
rsp);
-      }
-
-      @Override
-      public String getHttpMethod() {
-        return method.toString();
-      }
-    };
-  }
-
-  private void assertMapEqual(Map expected, ZkNodeProps actual) {
-    assertEquals(expected.size(), actual.getProperties().size());
-    for (Object o : expected.entrySet()) {
-      Map.Entry e = (Map.Entry) o;
-      assertEquals(e.getValue(), actual.get((String) e.getKey()));
-    }
-  }
-
-  static class MockCollectionsHandler extends CollectionsHandler {
-    LocalSolrQueryRequest req;
-
-    MockCollectionsHandler() {
-
-    }
-
-
-    @Override
-    protected void invokeAction(SolrQueryRequest req, SolrQueryResponse rsp, CollectionOperation
operation) throws Exception {
-      Map<String, Object> result = operation.call(req, rsp, this);
-      if (result != null) {
-        result.put(QUEUE_OPERATION, operation.action.toLower());
-        req.getContext().put(ZkNodeProps.class.getName(),new ZkNodeProps(result) );
-      }
-    }
-  }
-
-
-}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3cfebd53/solr/core/src/test/org/apache/solr/handler/admin/TestV2CoreAdminAPIs.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/TestV2CoreAdminAPIs.java b/solr/core/src/test/org/apache/solr/handler/admin/TestV2CoreAdminAPIs.java
deleted file mode 100644
index aeee949..0000000
--- a/solr/core/src/test/org/apache/solr/handler/admin/TestV2CoreAdminAPIs.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package org.apache.solr.handler.admin;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-
-
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.client.solrj.SolrRequest;
-import org.apache.solr.common.util.Lookup;
-import org.apache.solr.common.util.Map2;
-import org.apache.solr.core.CoreContainer;
-import org.apache.solr.core.PluginBag;
-import org.apache.solr.core.SolrCore;
-import org.apache.solr.v2api.ApiBag;
-import org.apache.solr.v2api.V2Api;
-import org.easymock.EasyMock;
-import org.easymock.IAnswer;
-
-import static org.easymock.EasyMock.getCurrentArguments;
-
-public class TestV2CoreAdminAPIs extends SolrTestCaseJ4 {
-
-  public void testCreate() throws Exception {
-    Map<String, Object[]> calls = new HashMap<>();
-    CoreContainer mockCC = getCoreContainerMock(calls, new HashMap<>());
-
-    CoreAdminHandler  coreAdminHandler = new CoreAdminHandler(mockCC);
-    ApiBag apiBag = new ApiBag();
-    for (V2Api v2Api : coreAdminHandler.getApis()) {
-      apiBag.register(v2Api, Collections.EMPTY_MAP);
-    }
-    TestV2CollectionAPIs.makeCall(apiBag,"/cores", SolrRequest.METHOD.POST ,
-        "{create:{name: hello, instanceDir : someDir, config : 'solrconfig.xml', schema:
'schema.xml'}}", mockCC);
-    Object[] create = calls.get("create");
-    assertEquals("hello" ,create[0]);
-    HashMap expected = new HashMap();
-    expected.put("schema", "schema.xml");
-    expected.put("config", "solrconfig.xml");
-    assertEquals(expected ,create[2]);
-
-  }
-
-  public static CoreContainer getCoreContainerMock(final Map<String, Object[]> in,Map<String,Object>
out ) {
-    CoreContainer mockCC = EasyMock.createMock(CoreContainer.class);
-    EasyMock.reset(mockCC);
-    mockCC.create(EasyMock.anyObject(String.class), EasyMock.anyObject(Path.class ) ,EasyMock.anyObject(Map.class));
-    EasyMock.expectLastCall().andAnswer(new IAnswer<SolrCore>() {
-      @Override
-      public SolrCore answer() throws Throwable {
-        in.put("create", getCurrentArguments());
-        return null;
-      }
-    }).anyTimes();
-
-    mockCC.getCoreRootDirectory();
-    EasyMock.expectLastCall().andAnswer(new IAnswer<Path>() {
-      @Override
-      public Path answer() throws Throwable {
-        return Paths.get("coreroot");
-      }
-    }).anyTimes();
-    mockCC.getContainerProperties();
-    EasyMock.expectLastCall().andAnswer(new IAnswer<Properties>() {
-      @Override
-      public Properties answer() throws Throwable {
-        return new Properties();
-      }
-    }).anyTimes();
-
-    mockCC.getRequestHandlers();
-    EasyMock.expectLastCall().andAnswer(new IAnswer<PluginBag>() {
-      @Override
-      public PluginBag answer() throws Throwable {
-        return (PluginBag)out.get("getRequestHandlers");
-      }
-    }).anyTimes();
-
-    EasyMock.replay(mockCC);
-    return mockCC;
-  }
-
-
-}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3cfebd53/solr/core/src/test/org/apache/solr/handler/admin/TestV2Framework.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/TestV2Framework.java b/solr/core/src/test/org/apache/solr/handler/admin/TestV2Framework.java
deleted file mode 100644
index 81104c8..0000000
--- a/solr/core/src/test/org/apache/solr/handler/admin/TestV2Framework.java
+++ /dev/null
@@ -1,187 +0,0 @@
-package org.apache.solr.handler.admin;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.client.solrj.SolrRequest;
-import org.apache.solr.common.params.MapSolrParams;
-import org.apache.solr.common.util.Lookup;
-import org.apache.solr.common.util.Map2;
-import org.apache.solr.common.util.Predicate;
-import org.apache.solr.common.util.StrUtils;
-import org.apache.solr.common.util.Utils;
-import org.apache.solr.core.CoreContainer;
-import org.apache.solr.core.PluginBag;
-import org.apache.solr.handler.PingRequestHandler;
-import org.apache.solr.handler.SchemaHandler;
-import org.apache.solr.handler.SolrConfigHandler;
-import org.apache.solr.request.LocalSolrQueryRequest;
-import org.apache.solr.request.SolrRequestHandler;
-import org.apache.solr.response.SolrQueryResponse;
-import org.apache.solr.v2api.PathTrie;
-import org.apache.solr.v2api.V2Api;
-import org.apache.solr.v2api.V2HttpCall;
-import org.apache.solr.v2api.V2RequestContext;
-
-import static org.apache.solr.client.solrj.SolrRequest.METHOD.GET;
-import static org.apache.solr.common.params.CommonParams.COLLECTIONS_HANDLER_PATH;
-import static org.apache.solr.common.params.CommonParams.CORES_HANDLER_PATH;
-import static org.apache.solr.common.util.Map2.NOT_NULL;
-import static org.apache.solr.handler.admin.TestV2CollectionAPIs.getV2RequestContext;
-
-public class TestV2Framework extends SolrTestCaseJ4 {
-
-  public void testFramework() {
-    Map<String, Object[]> calls = new HashMap<>();
-    Map<String, Object> out = new HashMap<>();
-    CoreContainer mockCC = TestV2CoreAdminAPIs.getCoreContainerMock(calls, out);
-    PluginBag<SolrRequestHandler> containerHandlers = new PluginBag<>(SolrRequestHandler.class,
null, false);
-    containerHandlers.put(COLLECTIONS_HANDLER_PATH, new TestV2CollectionAPIs.MockCollectionsHandler());
-    containerHandlers.put(CORES_HANDLER_PATH, new CoreAdminHandler(mockCC));
-    out.put("getRequestHandlers", containerHandlers);
-
-    PluginBag<SolrRequestHandler> coreHandlers = new PluginBag<>(SolrRequestHandler.class,
null, false);
-    coreHandlers.put("/schema", new SchemaHandler());
-    coreHandlers.put("/config", new SolrConfigHandler());
-    coreHandlers.put("/admin/ping", new PingRequestHandler());
-
-    Map<String, String> parts = new HashMap<>();
-    String fullPath = "/collections/hello/shards";
-    V2Api api = V2HttpCall.getApiInfo(containerHandlers, fullPath, "GET",
-        mockCC, "collections", fullPath, parts);
-    assertNotNull(api);
-    assertConditions(api.getSpec(), Utils.makeMap(
-        "/methods[0]", "GET",
-        "/methods[1]", "POST",
-        "/commands/create", NOT_NULL));
-    assertEquals("hello", parts.get("collection"));
-
-    parts = new HashMap<>();
-    api = V2HttpCall.getApiInfo(containerHandlers, "/collections/hello/shards/shard1", "GET",
-        mockCC, "collections", null, parts);
-    assertConditions(api.getSpec(), Utils.makeMap(
-        "/methods[0]", "POST",
-        "/methods[1]", "GET",
-        "/methods[2]", "DELETE",
-        "/commands/split", NOT_NULL,
-        "/commands/add-replica", NOT_NULL,
-        "/commands/force-leader", NOT_NULL
-    ));
-    assertEquals("hello", parts.get("collection"));
-    assertEquals("shard1", parts.get("shard"));
-
-
-    parts = new HashMap<>();
-    api = V2HttpCall.getApiInfo(containerHandlers, "/collections/hello/shards/shard1/replica1",
"GET",
-        mockCC, "collections", null, parts);
-    assertConditions(api.getSpec(), Utils.makeMap(
-        "/methods[0]", "GET",
-        "/methods[1]", "POST",
-        "/commands/set", NOT_NULL
-    ));
-    assertEquals("hello", parts.get("collection"));
-    assertEquals("shard1", parts.get("shard"));
-    assertEquals("replica1", parts.get("replica"));
-
-    api = V2HttpCall.getApiInfo(containerHandlers, "/collections/hello/shards/shard1/replica1",
"DELETE",
-        mockCC, "collections", null, parts);
-    assertConditions(api.getSpec(), Utils.makeMap(
-        "/methods[0]", "DELETE",
-        "/url/params/onlyIfDown/type", "boolean"
-    ));
-    assertEquals("hello", parts.get("collection"));
-    assertEquals("shard1", parts.get("shard"));
-    assertEquals("replica1", parts.get("replica"));
-
-    SolrQueryResponse rsp = invoke(containerHandlers, "/collections/_introspect", GET, mockCC);
-
-    assertConditions(rsp.getValues().asMap(2), Utils.makeMap(
-        "/spec[0]/methods[0]", "POST",
-        "/spec[0]/methods[1]", "GET"));
-
-    rsp = invoke(coreHandlers, "/collections/hello/schema/_introspect", GET, mockCC);
-    assertConditions(rsp.getValues().asMap(2), Utils.makeMap(
-        "/spec[0]/methods[0]", "POST",
-        "/spec[0]/commands", NOT_NULL,
-        "/spec[1]/methods[0]", "GET"));
-
-    rsp = invoke(coreHandlers, "/collections/hello", GET, mockCC);
-    assertConditions(rsp.getValues().asMap(2), Utils.makeMap(
-        "/availableSubPaths", NOT_NULL,
-        "availableSubPaths /collections/hello/config/jmx", NOT_NULL,
-        "availableSubPaths /collections/hello/schema", NOT_NULL,
-        "availableSubPaths /collections/hello/shards", NOT_NULL,
-        "availableSubPaths /collections/hello/shards/{shard}", NOT_NULL,
-        "availableSubPaths /collections/hello/shards/{shard}/{replica}", NOT_NULL
-    ));
-
-    rsp = invoke(coreHandlers,"/collections/hello/schema",SolrRequest.METHOD.POST, mockCC);
-
-
-
-  }
-
-  private SolrQueryResponse invoke(PluginBag<SolrRequestHandler> reqHandlers, String
path, SolrRequest.METHOD method,
-                                   CoreContainer mockCC) {
-    HashMap<String, String> parts = new HashMap<>();
-    boolean containerHandlerLookup = mockCC.getRequestHandlers() == reqHandlers;
-    String fullPath = path;
-    String prefix = null;
-    if (!containerHandlerLookup) {
-      int idx = path.indexOf('/', 1);
-      prefix = path.substring(1, idx);
-      if (idx > 0) idx = path.indexOf('/', idx + 1);
-      path = idx == -1 ? "/" : path.substring(idx);
-    }
-
-    V2Api api = V2HttpCall.getApiInfo(reqHandlers, path, "GET", mockCC, prefix, fullPath,
parts);
-    LocalSolrQueryRequest req = new LocalSolrQueryRequest(null, new MapSolrParams(new HashMap<>()));
-    V2RequestContext ctx = getV2RequestContext( path, method, null, mockCC, parts, api, req);
-    api.call(ctx);
-    return ctx.getResponse();
-
-  }
-
-
-  private void assertConditions(Map root, Map conditions) {
-    for (Object o : conditions.entrySet()) {
-      Map.Entry e = (Map.Entry) o;
-      String path = (String) e.getKey();
-      List<String> parts = StrUtils.splitSmart(path, path.charAt(0) == '/' ?  '/':'
');
-      if (parts.get(0).isEmpty()) parts.remove(0);
-      Object val = Utils.getObjectByPath(root, false, parts);
-      if (e.getValue() instanceof Predicate) {
-        Predicate value = (Predicate) e.getValue();
-        String err = value.test(val);
-        if(err != null){
-          assertEquals(err + " for " + e.getKey() + " in :" + Utils.toJSONString(root), e.getValue(),
val);
-        }
-
-      } else {
-        assertEquals("incorrect value for path " + e.getKey() + " in :" + Utils.toJSONString(root),
e.getValue(), val);
-      }
-    }
-
-  }
-
-
-}


Mime
View raw message