Skip to content
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.meilisearch.sdk.model;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
Expand All @@ -11,9 +13,9 @@
*/
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class LocalizedAttribute {
protected String[] attributePatterns;
protected String[] locales;

public LocalizedAttribute() {}
}
96 changes: 95 additions & 1 deletion src/test/java/com/meilisearch/integration/SettingsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.meilisearch.sdk.Index;
import com.meilisearch.sdk.model.FacetSortValue;
import com.meilisearch.sdk.model.Faceting;
import com.meilisearch.sdk.model.LocalizedAttribute;
import com.meilisearch.sdk.model.Pagination;
import com.meilisearch.sdk.model.Settings;
import com.meilisearch.sdk.model.TaskInfo;
Expand Down Expand Up @@ -445,7 +446,7 @@ public void testGetDisplayedAttributesSettings() throws Exception {

assertThat(
initialDisplayedAttributes,
is(arrayWithSize(initialSettings.getSearchableAttributes().length)));
is(arrayWithSize(initialSettings.getDisplayedAttributes().length)));
assertThat(
initialDisplayedAttributes, is(equalTo(initialSettings.getDisplayedAttributes())));
}
Expand Down Expand Up @@ -492,6 +493,99 @@ public void testResetDisplayedAttributesSettings() throws Exception {
is(not(arrayWithSize(updatedDisplayedAttributes.length))));
}

/** Tests of the localization attributes setting methods */
@Test
@DisplayName("Test get localized attributes settings by uid")
public void testGetLocalizedAttributesSettings() throws Exception {
Index index = createIndex("testGetLocalizedAttributesSettings");
Settings initialSettings = index.getSettings();
LocalizedAttribute[] initialLocalizedAttributes = index.getLocalizedAttributesSettings();

assertThat(
initialLocalizedAttributes, is(equalTo(initialSettings.getLocalizedAttributes())));
assertThat(
initialLocalizedAttributes, is(equalTo(initialSettings.getLocalizedAttributes())));
}

@Test
@DisplayName("Test update localized attributes settings")
public void testUpdateLocalizedAttributesSettings() throws Exception {
Index index = createIndex("testUpdateLocalizedAttributesSettings");
LocalizedAttribute[] initialLocalizedAttributes = index.getLocalizedAttributesSettings();

LocalizedAttribute firstAttribute = new LocalizedAttribute();
LocalizedAttribute secondAttribute = new LocalizedAttribute();

firstAttribute.setAttributePatterns(new String[] {"title", "description"});
firstAttribute.setLocales(new String[] {"eng", "fra"});

secondAttribute.setAttributePatterns(new String[] {"genre", "release_date"});
secondAttribute.setLocales(new String[] {"rus"});

LocalizedAttribute[] newLocalizedAttributes =
new LocalizedAttribute[] {firstAttribute, secondAttribute};

index.waitForTask(
index.updateLocalizedAttributesSettings(newLocalizedAttributes).getTaskUid());
LocalizedAttribute[] updatedLocalizedAttributes = index.getLocalizedAttributesSettings();

assertThat(updatedLocalizedAttributes, is(arrayWithSize(newLocalizedAttributes.length)));
assertThat(
updatedLocalizedAttributes[0].getAttributePatterns(),
is(equalTo(newLocalizedAttributes[0].getAttributePatterns())));
assertThat(
updatedLocalizedAttributes[0].getLocales(),
is(equalTo(newLocalizedAttributes[0].getLocales())));
assertThat(
updatedLocalizedAttributes[1].getAttributePatterns(),
is(equalTo(newLocalizedAttributes[1].getAttributePatterns())));
assertThat(
updatedLocalizedAttributes[1].getLocales(),
is(equalTo(newLocalizedAttributes[1].getLocales())));
assertThat(updatedLocalizedAttributes, is(not(equalTo(initialLocalizedAttributes))));
}

@Test
@DisplayName("Test reset localized attributes settings")
public void testResetLocalizedAttributesSettings() throws Exception {
Index index = createIndex("testResetLocalizedAttributesSettings");
LocalizedAttribute[] initialLocalizedAttributes = index.getLocalizedAttributesSettings();
LocalizedAttribute firstAttribute = new LocalizedAttribute();
LocalizedAttribute secondAttribute = new LocalizedAttribute();

firstAttribute.setAttributePatterns(new String[] {"title", "description"});
firstAttribute.setLocales(new String[] {"eng", "fra"});

secondAttribute.setAttributePatterns(new String[] {"genre", "release_date"});
secondAttribute.setLocales(new String[] {"rus"});

LocalizedAttribute[] newLocalizedAttributes =
new LocalizedAttribute[] {firstAttribute, secondAttribute};

index.waitForTask(
index.updateLocalizedAttributesSettings(newLocalizedAttributes).getTaskUid());
LocalizedAttribute[] updatedLocalizedAttributes = index.getLocalizedAttributesSettings();

index.waitForTask(index.resetDisplayedAttributesSettings().getTaskUid());
LocalizedAttribute[] localizedAttributesAfterReset = index.getLocalizedAttributesSettings();

assertThat(updatedLocalizedAttributes, is(arrayWithSize(newLocalizedAttributes.length)));
assertThat(
updatedLocalizedAttributes[0].getAttributePatterns(),
is(equalTo(newLocalizedAttributes[0].getAttributePatterns())));
assertThat(
updatedLocalizedAttributes[0].getLocales(),
is(equalTo(newLocalizedAttributes[0].getLocales())));
assertThat(
updatedLocalizedAttributes[1].getAttributePatterns(),
is(equalTo(newLocalizedAttributes[1].getAttributePatterns())));
assertThat(
updatedLocalizedAttributes[1].getLocales(),
is(equalTo(newLocalizedAttributes[1].getLocales())));
assertThat(updatedLocalizedAttributes, is(not(equalTo(initialLocalizedAttributes))));
assertThat(localizedAttributesAfterReset, is(not(equalTo(updatedLocalizedAttributes))));
}

/** Tests of the filterable attributes setting methods */
@Test
@DisplayName("Test get filterable attributes settings by uid")
Expand Down

0 comments on commit 382e47b

Please sign in to comment.