Skip to content

Commit

Permalink
Feature/reserve index (Azure#66)
Browse files Browse the repository at this point in the history
Added sync and async test canUseIndexWithReservedName()
  • Loading branch information
Humoiz authored Sep 11, 2019
1 parent acc5a0d commit 85e0473
Show file tree
Hide file tree
Showing 9 changed files with 328 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@
import com.azure.search.data.generated.models.IndexAction;
import com.azure.search.data.generated.models.IndexActionType;
import com.azure.search.data.generated.models.IndexBatch;
import com.azure.search.data.models.Book;
import com.azure.search.service.models.DataType;
import com.azure.search.service.models.Field;
import com.azure.search.service.models.Index;
import com.azure.search.data.models.Book;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.azure.search.data.models.Hotel;
import io.netty.handler.codec.http.HttpResponseStatus;

import org.junit.Assert;

import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

import java.util.*;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -62,6 +62,32 @@ public void indexWithInvalidDocumentThrowsException() {
});
}

@Override
public void canUseIndexWithReservedName() {

Index indexWithReservedName = new Index()
.withName("prototype")
.withFields(Collections.singletonList(new Field().withName("ID").withType(DataType.EDM_STRING).withKey(Boolean.TRUE)));

if (!interceptorManager.isPlaybackMode()) {
searchServiceClient.indexes().create(indexWithReservedName);
}

Map<String, Object> indexData = new HashMap<>();
indexData.put("ID", "1");

client.setIndexName(indexWithReservedName.name())
.index(new IndexBatch()
.actions(Collections.singletonList(new IndexAction()
.actionType(IndexActionType.UPLOAD)
.additionalProperties(indexData)))).block();

StepVerifier
.create(client.getDocument("1"))
.assertNext(result -> Assert.assertNotNull(result))
.verifyComplete();
}

@Override
public void canRoundtripBoundaryValues() throws Exception {
JsonApi jsonApi = JsonWrapper.newInstance(JacksonDeserializer.class);
Expand Down Expand Up @@ -90,6 +116,7 @@ public void canRoundtripBoundaryValues() throws Exception {
})
.verifyComplete();
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,23 @@
import com.azure.search.data.generated.models.IndexAction;
import com.azure.search.data.generated.models.IndexActionType;
import com.azure.search.data.generated.models.IndexBatch;
import com.azure.search.data.models.Book;
import com.azure.search.service.models.DataType;
import com.azure.search.service.models.Field;
import com.azure.search.service.models.Index;
import com.azure.search.data.models.Book;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.azure.search.data.models.Hotel;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.rules.ExpectedException;

import java.util.*;
import java.util.stream.Collectors;
import java.io.InputStreamReader;
import java.io.Reader;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class IndexingSyncTests extends IndexingTestBase {
private SearchIndexClient client;
Expand All @@ -54,6 +53,28 @@ public void indexWithInvalidDocumentThrowsException() {
client.index(new IndexBatch().actions(indexActions));
}

@Override
public void canUseIndexWithReservedName() {
Index indexWithReservedName = new Index()
.withName("prototype")
.withFields(Collections.singletonList(new Field().withName("ID").withType(DataType.EDM_STRING).withKey(Boolean.TRUE)));

if (!interceptorManager.isPlaybackMode()) {
searchServiceClient.indexes().create(indexWithReservedName);
}
Map<String, Object> indexData = new HashMap<>();
indexData.put("ID", "1");

client.setIndexName(indexWithReservedName.name())
.index(new IndexBatch()
.actions(Collections.singletonList(new IndexAction()
.actionType(IndexActionType.UPLOAD)
.additionalProperties(indexData))));

Document actual = client.getDocument("1");
Assert.assertNotNull(actual);
}

@Override
public void canRoundtripBoundaryValues() throws Exception {
JsonApi jsonApi = JsonWrapper.newInstance(JacksonDeserializer.class);
Expand All @@ -79,6 +100,7 @@ public void canRoundtripBoundaryValues() throws Exception {
Hotel actual = doc.as(Hotel.class);
Assert.assertEquals(expected, actual);
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.azure.search.data.models.Hotel;
import com.azure.search.data.models.HotelAddress;
import com.azure.search.data.models.HotelRoom;

import org.junit.Test;

import java.text.ParseException;
Expand Down Expand Up @@ -48,6 +49,9 @@ protected void beforeTest() {
@Test
public abstract void indexWithInvalidDocumentThrowsException();

@Test
public abstract void canUseIndexWithReservedName();

@Test
public abstract void canRoundtripBoundaryValues() throws Exception;

Expand Down
Loading

0 comments on commit 85e0473

Please sign in to comment.