use of org.sonar.server.es.BaseDoc in project sonarqube by SonarSource.
the class BaseDocTest method getField_fails_if_missing_field.
@Test
public void getField_fails_if_missing_field() {
Map<String, Object> fields = Collections.emptyMap();
BaseDoc doc = new BaseDoc(someType, fields) {
@Override
public String getId() {
return null;
}
};
try {
doc.getNullableField("a_string");
fail();
} catch (IllegalStateException e) {
assertThat(e).hasMessage("Field a_string not specified in query options");
}
}
use of org.sonar.server.es.BaseDoc in project sonarqube by SonarSource.
the class BaseDocTest method getFields_fails_with_ISE_if_setParent_has_not_been_called_on_IndexRelationType.
@Test
public void getFields_fails_with_ISE_if_setParent_has_not_been_called_on_IndexRelationType() {
IndexType.IndexRelationType relationType = IndexType.relation(IndexType.main(Index.withRelations("foo"), "bar"), "donut");
BaseDoc doc = new BaseDoc(relationType) {
@Override
public String getId() {
throw new UnsupportedOperationException("getId not implemented");
}
};
assertThatThrownBy(() -> doc.getFields()).isInstanceOf(IllegalStateException.class).hasMessage("parent must be set on a doc associated to a IndexRelationType (see BaseDoc#setParent(String))");
}
use of org.sonar.server.es.BaseDoc in project sonarqube by SonarSource.
the class BaseDocTest method getField.
@Test
public void getField() {
Map<String, Object> fields = new HashMap<>();
fields.put("a_string", "foo");
fields.put("a_int", 42);
fields.put("a_null", null);
BaseDoc doc = new BaseDoc(someType, fields) {
@Override
public String getId() {
return null;
}
};
assertThat((String) doc.getNullableField("a_string")).isEqualTo("foo");
assertThat((int) doc.getNullableField("a_int")).isEqualTo(42);
assertThat((String) doc.getNullableField("a_null")).isNull();
}
use of org.sonar.server.es.BaseDoc in project sonarqube by SonarSource.
the class BaseDocTest method getFieldAsDate.
@Test
public void getFieldAsDate() {
BaseDoc doc = new BaseDoc(someType, new HashMap<>()) {
@Override
public String getId() {
return null;
}
};
Date now = new Date();
doc.setField("javaDate", now);
assertThat(doc.getFieldAsDate("javaDate")).isEqualToIgnoringMillis(now);
doc.setField("stringDate", EsUtils.formatDateTime(now));
assertThat(doc.getFieldAsDate("stringDate")).isEqualToIgnoringMillis(now);
}
use of org.sonar.server.es.BaseDoc in project sonarqube by SonarSource.
the class BaseDocTest method getFields_contains_join_field_and_indexType_field_when_setParent_has_been_called_on_IndexRelationType.
@Test
public void getFields_contains_join_field_and_indexType_field_when_setParent_has_been_called_on_IndexRelationType() {
Index index = Index.withRelations("foo");
IndexType.IndexRelationType relationType = IndexType.relation(IndexType.main(index, "bar"), "donut");
BaseDoc doc = new BaseDoc(relationType) {
{
setParent("miam");
}
@Override
public String getId() {
throw new UnsupportedOperationException("getId not implemented");
}
};
Map<String, Object> fields = doc.getFields();
assertThat((Map) fields.get(index.getJoinField())).isEqualTo(ImmutableMap.of("name", relationType.getName(), "parent", "miam"));
assertThat(fields).containsEntry("indexType", relationType.getName());
}