Пример #1
0
  @Test
  public void testCopyFieldAccuracy() throws Exception {
    SchemaRequest.CopyFields copyFieldsSchemaRequest = new SchemaRequest.CopyFields();
    SchemaResponse.CopyFieldsResponse initialCopyFieldsResponse =
        copyFieldsSchemaRequest.process(getSolrClient());
    List<Map<String, Object>> initialCopyFieldsAttributes =
        initialCopyFieldsResponse.getCopyFields();

    String srcFieldName = "copyfield";
    String destFieldName1 = "destField1", destFieldName2 = "destField2";
    createStoredStringField(srcFieldName, getSolrClient());
    createStoredStringField(destFieldName1, getSolrClient());
    createStoredStringField(destFieldName2, getSolrClient());

    SchemaRequest.AddCopyField addCopyFieldRequest =
        new SchemaRequest.AddCopyField(srcFieldName, Arrays.asList(destFieldName1, destFieldName2));
    SchemaResponse.UpdateResponse addCopyFieldResponse =
        addCopyFieldRequest.process(getSolrClient());
    assertValidSchemaResponse(addCopyFieldResponse);

    SchemaResponse.CopyFieldsResponse currentCopyFieldsResponse =
        copyFieldsSchemaRequest.process(getSolrClient());
    List<Map<String, Object>> currentCopyFields = currentCopyFieldsResponse.getCopyFields();
    assertEquals(initialCopyFieldsAttributes.size() + 2, currentCopyFields.size());
  }
Пример #2
0
  @Test
  public void copyFieldsShouldFailWhenOneOfTheFieldsDoesntExistInTheSchema() throws Exception {
    String srcFieldName = "srcnotexist";
    String destFieldName1 = "destNotExist1", destFieldName2 = "destNotExist2";

    SchemaRequest.AddCopyField addCopyFieldRequest =
        new SchemaRequest.AddCopyField(srcFieldName, Arrays.asList(destFieldName1, destFieldName2));
    SchemaResponse.UpdateResponse addCopyFieldResponse =
        addCopyFieldRequest.process(getSolrClient());
    assertNotNull(addCopyFieldResponse.getResponse().get("errors"));
  }
Пример #3
0
  @Test
  public void testDeleteCopyFieldAccuracy() throws Exception {
    String srcFieldName = "copyfield";
    String destFieldName1 = "destField1", destFieldName2 = "destField2";
    createStoredStringField(srcFieldName, getSolrClient());
    createStoredStringField(destFieldName1, getSolrClient());
    createStoredStringField(destFieldName2, getSolrClient());

    SchemaRequest.AddCopyField addCopyFieldRequest =
        new SchemaRequest.AddCopyField(srcFieldName, Arrays.asList(destFieldName1, destFieldName2));
    SchemaResponse.UpdateResponse addCopyFieldResponse =
        addCopyFieldRequest.process(getSolrClient());
    System.out.println(addCopyFieldResponse);
    assertValidSchemaResponse(addCopyFieldResponse);

    SchemaRequest.DeleteCopyField deleteCopyFieldRequest1 =
        new SchemaRequest.DeleteCopyField(srcFieldName, Arrays.asList(destFieldName1));
    assertValidSchemaResponse(deleteCopyFieldRequest1.process(getSolrClient()));

    SchemaRequest.DeleteCopyField deleteCopyFieldRequest2 =
        new SchemaRequest.DeleteCopyField(srcFieldName, Arrays.asList(destFieldName2));
    assertValidSchemaResponse(deleteCopyFieldRequest2.process(getSolrClient()));
  }
Пример #4
0
  @Test
  public void testCopyFieldWithMaxCharsAccuracy() throws Exception {
    SchemaRequest.CopyFields copyFieldsSchemaRequest = new SchemaRequest.CopyFields();
    SchemaResponse.CopyFieldsResponse initialCopyFieldsResponse =
        copyFieldsSchemaRequest.process(getSolrClient());
    List<Map<String, Object>> initialCopyFieldsAttributes =
        initialCopyFieldsResponse.getCopyFields();

    String srcFieldName = "copyfield";
    String destFieldName1 = "destField1", destFieldName2 = "destField2";
    createStoredStringField(srcFieldName, getSolrClient());
    createStoredStringField(destFieldName1, getSolrClient());
    createStoredStringField(destFieldName2, getSolrClient());

    Integer maxChars = 200;
    SchemaRequest.AddCopyField addCopyFieldRequest =
        new SchemaRequest.AddCopyField(
            srcFieldName, Arrays.asList(destFieldName1, destFieldName2), maxChars);
    SchemaResponse.UpdateResponse addCopyFieldResponse =
        addCopyFieldRequest.process(getSolrClient());
    assertValidSchemaResponse(addCopyFieldResponse);

    SchemaResponse.CopyFieldsResponse currentCopyFieldsResponse =
        copyFieldsSchemaRequest.process(getSolrClient());
    List<Map<String, Object>> currentCopyFields = currentCopyFieldsResponse.getCopyFields();
    assertEquals(initialCopyFieldsAttributes.size() + 2, currentCopyFields.size());
    for (Map<String, Object> currentCopyField : currentCopyFields) {
      if (srcFieldName.equals(currentCopyField.get("source"))) {
        String currentDestFieldName = (String) currentCopyField.get("dest");
        int currentMaxChars = (Integer) currentCopyField.get("maxChars");
        assertThat(
            currentDestFieldName, anyOf(is(equalTo(destFieldName1)), is(equalTo(destFieldName2))));
        assertTrue(maxChars == currentMaxChars);
      }
    }
  }