use of java.util.AbstractMap.SimpleEntry in project ddf by codice.
the class SolrProviderTest method testUpdateNonUniqueAttributeValue.
/**
* Tests if we catch properly the case that the attribute value matches multiple Metacards.
*
* @throws IngestException
* @throws UnsupportedQueryException
*/
@Test(expected = IngestException.class)
public void testUpdateNonUniqueAttributeValue() throws IngestException, UnsupportedQueryException {
deleteAllIn(provider);
MockMetacard m1 = new MockMetacard(Library.getFlagstaffRecord());
MockMetacard m2 = new MockMetacard(Library.getFlagstaffRecord());
MockMetacard m3 = new MockMetacard(Library.getFlagstaffRecord());
List<Metacard> list = Arrays.asList((Metacard) m1, m2, m3);
create(list);
provider.update(new UpdateRequest() {
@Override
public boolean hasProperties() {
return false;
}
@Override
public Serializable getPropertyValue(String name) {
return null;
}
@Override
public Set<String> getPropertyNames() {
return null;
}
@Override
public Map<String, Serializable> getProperties() {
return null;
}
@Override
public boolean containsPropertyName(String name) {
return false;
}
@Override
public List<Entry<Serializable, Metacard>> getUpdates() {
MockMetacard newMetacard = new MockMetacard(Library.getShowLowRecord());
List<Entry<Serializable, Metacard>> updateList = new ArrayList<Entry<Serializable, Metacard>>();
updateList.add(new SimpleEntry<Serializable, Metacard>(MockMetacard.DEFAULT_TITLE, newMetacard));
return updateList;
}
@Override
public String getAttributeName() {
return Metacard.TITLE;
}
});
}
use of java.util.AbstractMap.SimpleEntry in project ddf by codice.
the class SolrProviderTest method testUpdateUnknownAttribute.
/**
* Testing update operation of unknown attribute. Should return no results.
*
* @throws IngestException
* @throws UnsupportedQueryException
*/
public void testUpdateUnknownAttribute() throws IngestException, UnsupportedQueryException {
deleteAllIn(provider);
UpdateResponse response = provider.update(new UpdateRequest() {
@Override
public boolean hasProperties() {
return false;
}
@Override
public Serializable getPropertyValue(String name) {
return null;
}
@Override
public Set<String> getPropertyNames() {
return null;
}
@Override
public Map<String, Serializable> getProperties() {
return null;
}
@Override
public boolean containsPropertyName(String name) {
return false;
}
@Override
public List<Entry<Serializable, Metacard>> getUpdates() {
MockMetacard newMetacard = new MockMetacard(Library.getShowLowRecord());
List<Entry<Serializable, Metacard>> updateList = new ArrayList<Entry<Serializable, Metacard>>();
updateList.add(new SimpleEntry<Serializable, Metacard>(MockMetacard.DEFAULT_TITLE, newMetacard));
return updateList;
}
@Override
public String getAttributeName() {
return "dataAccess";
}
});
assertEquals(0, response.getUpdatedMetacards().size());
}
use of java.util.AbstractMap.SimpleEntry in project ddf by codice.
the class CatalogFrameworkImplTest method testUpdateWithStores.
// TODO (DDF-2436) -
@Ignore
@Test
public void testUpdateWithStores() throws Exception {
MockEventProcessor eventAdmin = new MockEventProcessor();
MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<>(), true, new Date());
Map<String, CatalogStore> storeMap = new HashMap<>();
Map<String, FederatedSource> sourceMap = new HashMap<>();
MockCatalogStore store = new MockCatalogStore("catalogStoreId-1", true);
storeMap.put(store.getId(), store);
sourceMap.put(store.getId(), store);
CatalogFramework framework = createDummyCatalogFramework(provider, storeMap, sourceMap, eventAdmin);
FilterFactory filterFactory = new FilterFactoryImpl();
Filter filter = filterFactory.like(filterFactory.property(Metacard.METADATA), "*", "*", "?", "/", false);
List<Metacard> metacards = new ArrayList<>();
String id = UUID.randomUUID().toString();
MetacardImpl newCard = new MetacardImpl();
newCard.setId(id);
newCard.setAttribute("myKey", "myValue1");
metacards.add(newCard);
Map<String, Serializable> reqProps = new HashMap<>();
HashSet<String> destinations = new HashSet<>();
destinations.add("mockMemoryProvider");
destinations.add("catalogStoreId-1");
framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
MetacardImpl updateCard = new MetacardImpl();
updateCard.setId(id);
updateCard.setAttribute("myKey", "myValue2");
List<Entry<Serializable, Metacard>> updates = new ArrayList<>();
updates.add(new SimpleEntry<>(id, updateCard));
destinations.remove("mockMemoryProvider");
framework.update(new UpdateRequestImpl(updates, Metacard.ID, new HashMap<>(), destinations));
assertThat(provider.hasReceivedUpdateByIdentifier(), is(false));
assertThat(store.hasReceivedUpdateByIdentifier(), is(true));
QueryResponse storeResponse = framework.query(new QueryRequestImpl(new QueryImpl(filter), destinations));
assertThat(storeResponse.getResults().size(), is(1));
assertThat(storeResponse.getResults().get(0).getMetacard().getAttribute("myKey").getValue(), equalTo("myValue2"));
destinations.clear();
QueryResponse providerResponse = framework.query(new QueryRequestImpl(new QueryImpl(filter), destinations));
assertThat(providerResponse.getResults().size(), is(1));
assertThat(providerResponse.getResults().get(0).getMetacard().getAttribute("myKey").getValue(), equalTo("myValue1"));
}
use of java.util.AbstractMap.SimpleEntry in project checkstyle by checkstyle.
the class VariableDeclarationUsageDistanceCheck method calculateDistanceBetweenScopes.
/**
* Calculates distance between declaration of variable and its first usage
* in multiple scopes.
* @param ast
* Regular node of Ast which is checked for content of checking
* variable.
* @param variable
* Variable which distance is calculated for.
* @return entry which contains expression with variable usage and distance.
*/
private static Entry<DetailAST, Integer> calculateDistanceBetweenScopes(DetailAST ast, DetailAST variable) {
int dist = 0;
DetailAST currentScopeAst = ast;
DetailAST variableUsageAst = null;
while (currentScopeAst != null) {
final Entry<List<DetailAST>, Integer> searchResult = searchVariableUsageExpressions(variable, currentScopeAst);
currentScopeAst = null;
final List<DetailAST> variableUsageExpressions = searchResult.getKey();
dist += searchResult.getValue();
// this scope and count distance until variable usage.
if (variableUsageExpressions.size() == 1) {
final DetailAST blockWithVariableUsage = variableUsageExpressions.get(0);
DetailAST exprWithVariableUsage = null;
switch(blockWithVariableUsage.getType()) {
case TokenTypes.VARIABLE_DEF:
case TokenTypes.EXPR:
dist++;
break;
case TokenTypes.LITERAL_FOR:
case TokenTypes.LITERAL_WHILE:
case TokenTypes.LITERAL_DO:
exprWithVariableUsage = getFirstNodeInsideForWhileDoWhileBlocks(blockWithVariableUsage, variable);
break;
case TokenTypes.LITERAL_IF:
exprWithVariableUsage = getFirstNodeInsideIfBlock(blockWithVariableUsage, variable);
break;
case TokenTypes.LITERAL_SWITCH:
exprWithVariableUsage = getFirstNodeInsideSwitchBlock(blockWithVariableUsage, variable);
break;
case TokenTypes.LITERAL_TRY:
exprWithVariableUsage = getFirstNodeInsideTryCatchFinallyBlocks(blockWithVariableUsage, variable);
break;
default:
exprWithVariableUsage = blockWithVariableUsage.getFirstChild();
}
currentScopeAst = exprWithVariableUsage;
if (exprWithVariableUsage == null) {
variableUsageAst = blockWithVariableUsage;
} else {
variableUsageAst = exprWithVariableUsage;
}
} else // distance until variable first usage.
if (variableUsageExpressions.size() > 1) {
dist++;
variableUsageAst = variableUsageExpressions.get(0);
} else // If there's no any variable usage, then distance = 0.
{
variableUsageAst = null;
}
}
return new SimpleEntry<>(variableUsageAst, dist);
}
use of java.util.AbstractMap.SimpleEntry in project checkstyle by checkstyle.
the class VariableDeclarationUsageDistanceCheck method calculateDistanceInSingleScope.
/**
* Calculates distance between declaration of variable and its first usage
* in single scope.
* @param semicolonAst
* Regular node of Ast which is checked for content of checking
* variable.
* @param variableIdentAst
* Variable which distance is calculated for.
* @return entry which contains expression with variable usage and distance.
*/
private static Entry<DetailAST, Integer> calculateDistanceInSingleScope(DetailAST semicolonAst, DetailAST variableIdentAst) {
int dist = 0;
boolean firstUsageFound = false;
DetailAST currentAst = semicolonAst;
DetailAST variableUsageAst = null;
while (!firstUsageFound && currentAst != null && currentAst.getType() != TokenTypes.RCURLY) {
if (currentAst.getFirstChild() != null) {
if (isChild(currentAst, variableIdentAst)) {
dist = getDistToVariableUsageInChildNode(currentAst, variableIdentAst, dist);
variableUsageAst = currentAst;
firstUsageFound = true;
} else if (currentAst.getType() != TokenTypes.VARIABLE_DEF) {
dist++;
}
}
currentAst = currentAst.getNextSibling();
}
// If variable wasn't used after its declaration, distance is 0.
if (!firstUsageFound) {
dist = 0;
}
return new SimpleEntry<>(variableUsageAst, dist);
}
Aggregations