dao = spy(dao); doReturn("name:in").when(dao).getFilterIdsRaw(anyString()); when(gateway.getByFilterIds(anyList())).thenReturn(response); attributesForActivation.put("active", true); attributesForActivation.put("canary", false); inOrder.verify(gateway, times(1)).upsert(filter + "_3", attributesForActivation); inOrder.verify(gateway, times(0)).upsert(filter + "_3", attributesForDeactivation);
/** * We can't unit test the CQL query or how Cassandra will behave, that will have to be manually confirmed. * We can however test that whatever rows are returned do end up in the List<EndpointURI> that we expect. */ @SuppressWarnings("unchecked") @Test public void testGetAllEndpointsReturnsResults() { ZuulFilterDAO dao = new ZuulFilterDAOCassandra(gateway); // setup empty response String fids = "filter1|filter2"; /* create mock response data */ Row<String, String> row0 = mockRow(); ColumnList<String> columnList0 = mockColumnList(row0); mockColumn(columnList0, "filter_ids", fids); // when(response.getRowByIndex(0)).thenReturn(row0); Iterator<Row<String, String>> iterator = (Iterator<Row<String, String>>) mock(Iterator.class); when(response.iterator()).thenReturn(iterator); when(iterator.hasNext()).thenReturn(true, false); // 1 row when(iterator.next()).thenReturn(row0, (Row) null); when(gateway.select(anyString())).thenReturn(response); when(response.isEmpty()).thenReturn(false); when(response.size()).thenReturn(1); /* exercise the method we're testing */ List<String> list = dao.getAllFilterIDs(); /* validate responses */ assertEquals("filter1", list.get(0)); assertEquals("filter2", list.get(1)); }
private void removeFilterIdFromIndex(String index, String filter_id) { List<String> filters = getFilterIdsIndex(index); if (filters.contains(filter_id)) { filters.remove(filter_id); String filterList = toFilterList(filters); cassandraGateway.updateFilterIndex(index, filterList); } }
when(gateway.getByFilterIds(anyList())).thenReturn(response3, response, response2); attributesForActivation.put("active", true); attributesForActivation.put("canary", false); inOrder.verify(gateway, times(1)).upsert(filter + "_4", attributesForActivation); inOrder.verify(gateway).upsert(filter + "_3", attributesForDeactivation);
when(gateway.getByFilterIds(anyList())).thenReturn(response3, response, response2); attributesForActivation.put("active", true); attributesForActivation.put("canary", false); inOrder.verify(gateway, times(1)).upsert(filter + "_4", attributesForActivation); inOrder.verify(gateway).upsert(filter + "_3", attributesForDeactivation);
doReturn(response).when(testGateway).getByFilterIds(anyList());
attributesForActivation.put("active", true); attributesForActivation.put("canary", false); doThrow(new RuntimeException()).when(gateway).upsert(filter + "_4", attributesForActivation); when(gateway.getByFilterIds(anyList())).thenReturn(response); verify(gateway, times(0)).upsert(filter + "_3", attributesForDeactivation);
when(response.size()).thenReturn(2); when(gateway.getByFilterIds(anyList())).thenReturn(response);
doReturn(response).when(testGateway).getByFilterIds(anyList());
attributesForActivation.put("active", true); attributesForActivation.put("canary", false); doThrow(new RuntimeException()).when(gateway).upsert(filter + "_4", attributesForActivation); when(gateway.getByFilterIds(anyList())).thenReturn(response); verify(gateway, times(0)).upsert(filter + "_3", attributesForDeactivation);
when(response.size()).thenReturn(2); when(gateway.getByFilterIds(anyList())).thenReturn(response);
dao = spy(dao); doReturn("name:type").when(dao).getFilterIdsRaw(anyString()); when(gateway.getByFilterIds(anyList())).thenReturn(response);
dao = spy(dao); doReturn("name:type").when(dao).getFilterIdsRaw(anyString()); when(gateway.getByFilterIds(anyList())).thenReturn(response); attributesForActivation.put("active", true); attributesForActivation.put("canary", false); inOrder.verify(gateway, times(1)).upsert(filter + "_3", attributesForActivation); inOrder.verify(gateway, times(0)).upsert(filter + "_3", attributesForDeactivation);
when(gateway.getByFilterIds(anyList())).thenReturn(response);
when(gateway.getByFilterIds(anyList())).thenReturn(response); when(response.isEmpty()).thenReturn(false); when(response.size()).thenReturn(1);
when(response.size()).thenReturn(1); when(gateway.getByFilterIds(anyList())).thenReturn(response);
when(response.size()).thenReturn(1); when(gateway.getByFilterIds(anyList())).thenReturn(response);
when(gateway.getByFilterIds(anyList())).thenReturn(response);
dao = spy(dao); doReturn("name:in").when(dao).getFilterIdsRaw(anyString()); when(gateway.getByFilterIds(anyList())).thenReturn(response);
attributesForActivation.put("active", true); attributesForActivation.put("canary", false); cassandraGateway.upsert(filter_id + "_" + revision, attributesForActivation); Map<String, Object> attributesForDeactivation = new HashMap<String, Object>(); attributesForDeactivation.put("active", false); cassandraGateway.upsert(filter_id + "_" + revisionToDeactivate, attributesForDeactivation);