Search in sources :

Example 16 with SearchResult

use of com.netflix.conductor.common.run.SearchResult in project conductor by Netflix.

the class TaskResourceTest method search.

@Test
public void search() {
    Task task = new Task();
    task.setTaskType("SIMPLE");
    task.setWorkerId("123");
    task.setDomain("test");
    task.setStatus(Task.Status.IN_PROGRESS);
    TaskSummary taskSummary = new TaskSummary(task);
    ArrayList<TaskSummary> listOfTaskSummary = new ArrayList<TaskSummary>() {

        {
            add(taskSummary);
        }
    };
    SearchResult<TaskSummary> searchResult = new SearchResult<TaskSummary>(100, listOfTaskSummary);
    listOfTaskSummary.add(taskSummary);
    when(mockTaskService.search(anyInt(), anyInt(), anyString(), anyString(), anyString())).thenReturn(searchResult);
    assertEquals(searchResult, taskResource.search(0, 100, "asc", "*", "*"));
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) TaskSummary(com.netflix.conductor.common.run.TaskSummary) ArrayList(java.util.ArrayList) SearchResult(com.netflix.conductor.common.run.SearchResult) Test(org.junit.Test)

Example 17 with SearchResult

use of com.netflix.conductor.common.run.SearchResult in project conductor by Netflix.

the class WorkflowClientTest method testSearchV2.

@Test
public void testSearchV2() {
    ClientResponse clientResponse = mock(ClientResponse.class);
    SearchResult<Workflow> workflowSearchResult = new SearchResult<>();
    workflowSearchResult.setTotalHits(1);
    Workflow workflow = new Workflow();
    workflowSearchResult.setResults(Collections.singletonList(workflow));
    when(clientResponse.getEntity(argThat((GenericType<SearchResult<Workflow>> type) -> ((ParameterizedTypeImpl) type.getType()).getRawType().equals(SearchResult.class) && ((ParameterizedTypeImpl) type.getType()).getActualTypeArguments()[0].equals(Workflow.class)))).thenReturn(workflowSearchResult);
    when(clientHandler.handle(argThat(argument -> argument.getURI().equals(URI.create("http://myuri:8080/workflow/search-v2?query=my_complex_query"))))).thenReturn(clientResponse);
    SearchResult<Workflow> searchResult = workflowClient.searchV2("my_complex_query");
    assertEquals(1, searchResult.getTotalHits());
    assertEquals(Collections.singletonList(workflow), searchResult.getResults());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ClientHandler(com.sun.jersey.api.client.ClientHandler) SearchResult(com.netflix.conductor.common.run.SearchResult) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ClientResponse(com.sun.jersey.api.client.ClientResponse) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) Workflow(com.netflix.conductor.common.run.Workflow) GenericType(com.sun.jersey.api.client.GenericType) ParameterizedTypeImpl(sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl) URI(java.net.URI) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) Before(org.junit.Before) TestCase.assertEquals(junit.framework.TestCase.assertEquals) Mockito.mock(org.mockito.Mockito.mock) Workflow(com.netflix.conductor.common.run.Workflow) SearchResult(com.netflix.conductor.common.run.SearchResult) ParameterizedTypeImpl(sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl) Test(org.junit.Test)

Example 18 with SearchResult

use of com.netflix.conductor.common.run.SearchResult in project conductor by Netflix.

the class WorkflowClientTest method testSearchWithParams.

@Test
public void testSearchWithParams() {
    ClientResponse clientResponse = mock(ClientResponse.class);
    SearchResult<WorkflowSummary> workflowSearchResult = new SearchResult<>();
    workflowSearchResult.setTotalHits(1);
    WorkflowSummary workflowSummary = new WorkflowSummary(new Workflow());
    workflowSearchResult.setResults(Collections.singletonList(workflowSummary));
    when(clientResponse.getEntity(argThat((GenericType<SearchResult<WorkflowSummary>> type) -> ((ParameterizedTypeImpl) type.getType()).getRawType().equals(SearchResult.class) && ((ParameterizedTypeImpl) type.getType()).getActualTypeArguments()[0].equals(WorkflowSummary.class)))).thenReturn(workflowSearchResult);
    when(clientHandler.handle(argThat(argument -> argument.getURI().equals(URI.create("http://myuri:8080/workflow/search?start=0&size=10&sort=sort&freeText=text&query=my_complex_query"))))).thenReturn(clientResponse);
    SearchResult<WorkflowSummary> searchResult = workflowClient.search(0, 10, "sort", "text", "my_complex_query");
    assertEquals(1, searchResult.getTotalHits());
    assertEquals(Collections.singletonList(workflowSummary), searchResult.getResults());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ClientHandler(com.sun.jersey.api.client.ClientHandler) SearchResult(com.netflix.conductor.common.run.SearchResult) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ClientResponse(com.sun.jersey.api.client.ClientResponse) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) Workflow(com.netflix.conductor.common.run.Workflow) GenericType(com.sun.jersey.api.client.GenericType) ParameterizedTypeImpl(sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl) URI(java.net.URI) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) Before(org.junit.Before) TestCase.assertEquals(junit.framework.TestCase.assertEquals) Mockito.mock(org.mockito.Mockito.mock) WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) Workflow(com.netflix.conductor.common.run.Workflow) SearchResult(com.netflix.conductor.common.run.SearchResult) ParameterizedTypeImpl(sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl) Test(org.junit.Test)

Example 19 with SearchResult

use of com.netflix.conductor.common.run.SearchResult in project conductor by Netflix.

the class WorkflowClientTest method testSearchV2WithParams.

@Test
public void testSearchV2WithParams() {
    ClientResponse clientResponse = mock(ClientResponse.class);
    SearchResult<Workflow> workflowSearchResult = new SearchResult<>();
    workflowSearchResult.setTotalHits(1);
    Workflow workflow = new Workflow();
    workflowSearchResult.setResults(Collections.singletonList(workflow));
    when(clientResponse.getEntity(argThat((GenericType<SearchResult<Workflow>> type) -> ((ParameterizedTypeImpl) type.getType()).getRawType().equals(SearchResult.class) && ((ParameterizedTypeImpl) type.getType()).getActualTypeArguments()[0].equals(Workflow.class)))).thenReturn(workflowSearchResult);
    when(clientHandler.handle(argThat(argument -> argument.getURI().equals(URI.create("http://myuri:8080/workflow/search-v2?start=0&size=10&sort=sort&freeText=text&query=my_complex_query"))))).thenReturn(clientResponse);
    SearchResult<Workflow> searchResult = workflowClient.searchV2(0, 10, "sort", "text", "my_complex_query");
    assertEquals(1, searchResult.getTotalHits());
    assertEquals(Collections.singletonList(workflow), searchResult.getResults());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ClientHandler(com.sun.jersey.api.client.ClientHandler) SearchResult(com.netflix.conductor.common.run.SearchResult) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ClientResponse(com.sun.jersey.api.client.ClientResponse) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) Workflow(com.netflix.conductor.common.run.Workflow) GenericType(com.sun.jersey.api.client.GenericType) ParameterizedTypeImpl(sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl) URI(java.net.URI) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) Before(org.junit.Before) TestCase.assertEquals(junit.framework.TestCase.assertEquals) Mockito.mock(org.mockito.Mockito.mock) Workflow(com.netflix.conductor.common.run.Workflow) SearchResult(com.netflix.conductor.common.run.SearchResult) ParameterizedTypeImpl(sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl) Test(org.junit.Test)

Aggregations

SearchResult (com.netflix.conductor.common.run.SearchResult)19 Test (org.junit.Test)14 Workflow (com.netflix.conductor.common.run.Workflow)12 WorkflowSummary (com.netflix.conductor.common.run.WorkflowSummary)9 Collections (java.util.Collections)5 SearchPb (com.netflix.conductor.grpc.SearchPb)4 WorkflowServicePb (com.netflix.conductor.grpc.WorkflowServicePb)4 ClientHandler (com.sun.jersey.api.client.ClientHandler)4 ClientResponse (com.sun.jersey.api.client.ClientResponse)4 GenericType (com.sun.jersey.api.client.GenericType)4 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)4 StreamObserver (io.grpc.stub.StreamObserver)4 URI (java.net.URI)4 LinkedList (java.util.LinkedList)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 TestCase.assertEquals (junit.framework.TestCase.assertEquals)4 SearchResponse (org.elasticsearch.action.search.SearchResponse)4 Before (org.junit.Before)4 RunWith (org.junit.runner.RunWith)4