Search in sources :

Example 1 with Mutable

use of org.cometd.bayeux.server.ServerMessage.Mutable in project ddf by codice.

the class SearchControllerTest method testMetacardTypeValuesCacheDisabled.

@Test
public void testMetacardTypeValuesCacheDisabled() throws Exception {
    final String ID = "id";
    Set<String> srcIds = new HashSet<String>();
    srcIds.add(ID);
    BayeuxServer bayeuxServer = mock(BayeuxServer.class);
    ServerChannel channel = mock(ServerChannel.class);
    ArgumentCaptor<ServerMessage.Mutable> reply = ArgumentCaptor.forClass(ServerMessage.Mutable.class);
    when(bayeuxServer.getChannel(any(String.class))).thenReturn(channel);
    SearchRequest request = new SearchRequest(srcIds, getQueryRequest("title LIKE 'Meta*'"), ID);
    searchController.setBayeuxServer(bayeuxServer);
    // Disable Cache
    searchController.setCacheDisabled(true);
    searchController.executeQuery(request, mockServerSession, null);
    verify(channel, timeout(1000).only()).publish(any(ServerSession.class), reply.capture());
    List<Mutable> replies = reply.getAllValues();
    assertReplies(replies);
}
Also used : Mutable(org.cometd.bayeux.server.ServerMessage.Mutable) SearchRequest(org.codice.ddf.ui.searchui.query.model.SearchRequest) ServerSession(org.cometd.bayeux.server.ServerSession) BayeuxServer(org.cometd.bayeux.server.BayeuxServer) ServerMessage(org.cometd.bayeux.server.ServerMessage) Matchers.anyString(org.mockito.Matchers.anyString) ServerChannel(org.cometd.bayeux.server.ServerChannel) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with Mutable

use of org.cometd.bayeux.server.ServerMessage.Mutable in project ddf by codice.

the class SearchControllerTest method testMetacardTypeValuesCacheEnabled.

@Test
public void testMetacardTypeValuesCacheEnabled() throws Exception {
    final String ID = "id";
    Set<String> srcIds = new HashSet<>();
    srcIds.add(ID);
    BayeuxServer bayeuxServer = mock(BayeuxServer.class);
    ServerChannel channel = mock(ServerChannel.class);
    ArgumentCaptor<ServerMessage.Mutable> reply = ArgumentCaptor.forClass(ServerMessage.Mutable.class);
    when(bayeuxServer.getChannel(any(String.class))).thenReturn(channel);
    SearchRequest request = new SearchRequest(srcIds, getQueryRequest("title LIKE 'Meta*'"), ID);
    searchController.setBayeuxServer(bayeuxServer);
    searchController.setCacheDisabled(false);
    searchController.executeQuery(request, mockServerSession, null);
    verify(channel, timeout(1000).times(2)).publish(any(ServerSession.class), reply.capture());
    List<Mutable> replies = reply.getAllValues();
    assertReplies(replies);
}
Also used : Mutable(org.cometd.bayeux.server.ServerMessage.Mutable) SearchRequest(org.codice.ddf.ui.searchui.query.model.SearchRequest) ServerSession(org.cometd.bayeux.server.ServerSession) BayeuxServer(org.cometd.bayeux.server.BayeuxServer) ServerMessage(org.cometd.bayeux.server.ServerMessage) Matchers.anyString(org.mockito.Matchers.anyString) ServerChannel(org.cometd.bayeux.server.ServerChannel) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with Mutable

use of org.cometd.bayeux.server.ServerMessage.Mutable in project ddf by codice.

the class SearchControllerTest method assertReplies.

private void assertReplies(List<Mutable> replies) {
    for (Mutable reply : replies) {
        assertThat(reply, is(not(nullValue())));
        assertThat(reply.getDataAsMap().get(Search.METACARD_TYPES), is(not(nullValue())));
        assertThat(reply.getDataAsMap().get(Search.METACARD_TYPES), instanceOf(Map.class));
        @SuppressWarnings("unchecked") Map<String, Object> types = (Map<String, Object>) reply.getDataAsMap().get(Search.METACARD_TYPES);
        assertThat(types.get("ddf.metacard"), is(not(nullValue())));
        assertThat(types.get("ddf.metacard"), instanceOf(Map.class));
        @SuppressWarnings("unchecked") Map<String, Map<String, Object>> typeInfo = (Map<String, Map<String, Object>>) types.get("ddf.metacard");
        assertThat((String) typeInfo.get("effective").get("format"), is("DATE"));
        assertThat((String) typeInfo.get("modified").get("format"), is("DATE"));
        assertThat((String) typeInfo.get("created").get("format"), is("DATE"));
        assertThat((String) typeInfo.get("expiration").get("format"), is("DATE"));
        assertThat((String) typeInfo.get("id").get("format"), is("STRING"));
        assertThat((String) typeInfo.get("title").get("format"), is("STRING"));
        assertThat((String) typeInfo.get("metadata-content-type").get("format"), is("STRING"));
        assertThat((String) typeInfo.get("metadata-content-type-version").get("format"), is("STRING"));
        assertThat((String) typeInfo.get("metadata-target-namespace").get("format"), is("STRING"));
        assertThat((String) typeInfo.get("resource-uri").get("format"), is("STRING"));
        assertThat((Boolean) typeInfo.get("resource-uri").get("indexed"), is(true));
        // since resource-size is not indexed, it should be filtered out
        assertThat((Boolean) typeInfo.get("resource-size").get("indexed"), is(false));
        assertThat((String) typeInfo.get("metadata").get("format"), is("XML"));
        assertThat((String) typeInfo.get("location").get("format"), is("GEOMETRY"));
    }
}
Also used : Mutable(org.cometd.bayeux.server.ServerMessage.Mutable) Matchers.anyString(org.mockito.Matchers.anyString) Map(java.util.Map)

Aggregations

Mutable (org.cometd.bayeux.server.ServerMessage.Mutable)3 Matchers.anyString (org.mockito.Matchers.anyString)3 HashSet (java.util.HashSet)2 SearchRequest (org.codice.ddf.ui.searchui.query.model.SearchRequest)2 BayeuxServer (org.cometd.bayeux.server.BayeuxServer)2 ServerChannel (org.cometd.bayeux.server.ServerChannel)2 ServerMessage (org.cometd.bayeux.server.ServerMessage)2 ServerSession (org.cometd.bayeux.server.ServerSession)2 Test (org.junit.Test)2 Map (java.util.Map)1