Search in sources :

Example 1 with IsEqual

use of org.hamcrest.core.IsEqual in project ddf by codice.

the class TestCswQueryResponseTransformer method whenEmptyResultListExpectOnlyThreeXMLNodes.

@Test
public void whenEmptyResultListExpectOnlyThreeXMLNodes() throws CatalogTransformerException, IOException {
    // when
    when(mockPrintWriterProvider.build((Class<Metacard>) notNull())).thenReturn(mockPrintWriter);
    when(mockPrintWriter.makeString()).thenReturn(new String());
    when(mockSourceResponse.getResults()).thenReturn(Collections.emptyList());
    when(mockSourceResponse.getRequest()).thenReturn(mockQueryRequest);
    when(mockQueryRequest.getQuery()).thenReturn(mockQuery);
    when(mockArguments.get(CswConstants.RESULT_TYPE_PARAMETER)).thenReturn(ResultType.RESULTS);
    when(mockTransformerManager.getTransformerBySchema(anyString())).thenReturn(mockMetacardTransformer);
    // given
    transformer.init();
    transformer.transform(mockSourceResponse, mockArguments);
    transformer.destroy();
    // then
    ArgumentCaptor<String> pwCaptor = ArgumentCaptor.forClass(String.class);
    verify(mockPrintWriter, times(3)).startNode(pwCaptor.capture());
    List<String> values = pwCaptor.getAllValues();
    assertThat("Missing XML node.", values.get(0), new IsEqual(CswQueryResponseTransformer.RECORDS_RESPONSE_QNAME));
    assertThat("Missing XML node.", values.get(1), new IsEqual(CswQueryResponseTransformer.SEARCH_STATUS_QNAME));
    assertThat("Missing XML node.", values.get(2), new IsEqual(CswQueryResponseTransformer.SEARCH_RESULTS_QNAME));
}
Also used : Metacard(ddf.catalog.data.Metacard) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.Test)

Example 2 with IsEqual

use of org.hamcrest.core.IsEqual in project jbosstools-openshift by jbosstools.

the class AbstractOpenShiftExplorerItem method expand.

public void expand() {
    activateOpenShiftExplorerView();
    item.expand();
    // There can be some processing, wait for it
    new WaitWhile(new JobIsRunning(new Matcher[] { new IsEqual<String>("Loading OpenShift resources...") }), TimePeriod.DEFAULT);
}
Also used : WaitWhile(org.eclipse.reddeer.common.wait.WaitWhile) Matcher(org.hamcrest.Matcher) JobIsRunning(org.eclipse.reddeer.workbench.core.condition.JobIsRunning) IsEqual(org.hamcrest.core.IsEqual)

Example 3 with IsEqual

use of org.hamcrest.core.IsEqual in project ddf by codice.

the class TestCswQueryResponseTransformer method whenQueryByHitsThenTransformZeroMetacards.

@Test
public void whenQueryByHitsThenTransformZeroMetacards() throws CatalogTransformerException, IOException {
    // when
    when(mockPrintWriterProvider.build((Class<Metacard>) notNull())).thenReturn(mockPrintWriter);
    when(mockPrintWriter.makeString()).thenReturn(new String());
    when(mockSourceResponse.getResults()).thenReturn(createResults(1, 10));
    when(mockSourceResponse.getRequest()).thenReturn(mockQueryRequest);
    when(mockQueryRequest.getQuery()).thenReturn(mockQuery);
    when(mockArguments.get(CswConstants.RESULT_TYPE_PARAMETER)).thenReturn(ResultType.HITS);
    // given
    transformer.init();
    transformer.transform(mockSourceResponse, mockArguments);
    transformer.destroy();
    // then
    ArgumentCaptor<String> tmCaptor = ArgumentCaptor.forClass(String.class);
    verify(mockTransformerManager, never()).getTransformerBySchema(tmCaptor.capture());
    ArgumentCaptor<Map> mapCaptor = ArgumentCaptor.forClass(Map.class);
    ArgumentCaptor<Metacard> mcCaptor = ArgumentCaptor.forClass(Metacard.class);
    verify(mockMetacardTransformer, never()).transform(mcCaptor.capture(), mapCaptor.capture());
    ArgumentCaptor<String> keyCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> valCaptor = ArgumentCaptor.forClass(String.class);
    verify(mockPrintWriter, atLeastOnce()).addAttribute(keyCaptor.capture(), valCaptor.capture());
    List<String> keys = keyCaptor.getAllValues();
    List<String> vals = valCaptor.getAllValues();
    int numAttrKeyIndex = keys.indexOf(CswQueryResponseTransformer.NUMBER_OF_RECORDS_RETURNED_ATTRIBUTE);
    assertThat("Missing XML attribute.", numAttrKeyIndex != -1, is(true));
    String numAttrValue = vals.get(numAttrKeyIndex);
    assertThat("Missing XML attribute value.", numAttrValue, new IsEqual("0"));
}
Also used : Metacard(ddf.catalog.data.Metacard) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.Test)

Aggregations

IsEqual (org.hamcrest.core.IsEqual)3 Metacard (ddf.catalog.data.Metacard)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Test (org.junit.Test)2 Matchers.anyString (org.mockito.Matchers.anyString)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 WaitWhile (org.eclipse.reddeer.common.wait.WaitWhile)1 JobIsRunning (org.eclipse.reddeer.workbench.core.condition.JobIsRunning)1 Matcher (org.hamcrest.Matcher)1 Matchers.anyMap (org.mockito.Matchers.anyMap)1