Search in sources :

Example 6 with Index

use of org.sonar.server.es.Index 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());
}
Also used : BaseDoc(org.sonar.server.es.BaseDoc) Index(org.sonar.server.es.Index) IndexType(org.sonar.server.es.IndexType) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 7 with Index

use of org.sonar.server.es.Index in project sonarqube by SonarSource.

the class NewRegularIndexTest method createTypeMapping_with_IndexRelationType_fails_with_IAE_if_mainType_does_not_match_defined_one.

@Test
public void createTypeMapping_with_IndexRelationType_fails_with_IAE_if_mainType_does_not_match_defined_one() {
    Index index = Index.withRelations(SOME_INDEX_NAME);
    IndexType.IndexMainType mainType = IndexType.main(index, "foo");
    NewRegularIndex underTest = new NewRegularIndex(index, defaultSettingsConfiguration);
    underTest.createTypeMapping(mainType);
    assertThatThrownBy(() -> underTest.createTypeMapping(IndexType.relation(IndexType.main(index, "donut"), "bar"))).isInstanceOf(IllegalArgumentException.class).hasMessage("main type of relation must be " + mainType);
}
Also used : Index(org.sonar.server.es.Index) IndexType(org.sonar.server.es.IndexType) Test(org.junit.Test)

Example 8 with Index

use of org.sonar.server.es.Index in project sonarqube by SonarSource.

the class NewRegularIndexTest method build_fails_with_ISE_if_index_accepts_relations_and_none_is_defined.

@Test
public void build_fails_with_ISE_if_index_accepts_relations_and_none_is_defined() {
    Index index = Index.withRelations(SOME_INDEX_NAME);
    NewRegularIndex underTest = new NewRegularIndex(index, defaultSettingsConfiguration);
    underTest.createTypeMapping(IndexType.main(index, "foo"));
    assertThatThrownBy(() -> underTest.build()).isInstanceOf(IllegalStateException.class).hasMessage("At least one relation must be defined when index accepts relations");
}
Also used : Index(org.sonar.server.es.Index) Test(org.junit.Test)

Example 9 with Index

use of org.sonar.server.es.Index in project sonarqube by SonarSource.

the class NewRegularIndexTest method build_defines_type_field_if_index_accepts_relations.

@Test
public void build_defines_type_field_if_index_accepts_relations() {
    Index someIndex = Index.withRelations(SOME_INDEX_NAME);
    NewRegularIndex underTest = new NewRegularIndex(someIndex, defaultSettingsConfiguration);
    underTest.createTypeMapping(IndexType.main(someIndex, "foo"));
    underTest.createTypeMapping(IndexType.relation(underTest.getMainType(), "bar"));
    BuiltIndex<NewRegularIndex> builtIndex = underTest.build();
    Map<String, Object> properties = (Map<String, Object>) builtIndex.getAttributes().get("properties");
    assertThat((Map) properties.get("indexType")).isEqualTo(ImmutableMap.of(TYPE, "keyword", NORMS, false, STORE, false, "doc_values", false));
}
Also used : Index(org.sonar.server.es.Index) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Example 10 with Index

use of org.sonar.server.es.Index in project sonarqube by SonarSource.

the class NewRegularIndexTest method build_does_not_define_type_field_if_index_does_not_accept_relations.

@Test
public void build_does_not_define_type_field_if_index_does_not_accept_relations() {
    Index someIndex = Index.simple(SOME_INDEX_NAME);
    NewRegularIndex underTest = new NewRegularIndex(someIndex, defaultSettingsConfiguration);
    underTest.createTypeMapping(IndexType.main(someIndex, "foo"));
    BuiltIndex<NewRegularIndex> builtIndex = underTest.build();
    Map<String, Object> properties = (Map<String, Object>) builtIndex.getAttributes().get("properties");
    assertThat(properties.get("indexType")).isNull();
}
Also used : Index(org.sonar.server.es.Index) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Index (org.sonar.server.es.Index)11 Test (org.junit.Test)10 ImmutableMap (com.google.common.collect.ImmutableMap)4 Map (java.util.Map)4 IndexType (org.sonar.server.es.IndexType)3 IndexMainType (org.sonar.server.es.IndexType.IndexMainType)2 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 HashMap (java.util.HashMap)1 MapSettings (org.sonar.api.config.internal.MapSettings)1 BaseDoc (org.sonar.server.es.BaseDoc)1