Search in sources :

Example 26 with SimpleEntry

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;
        }
    });
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) UpdateRequest(ddf.catalog.operation.UpdateRequest) SimpleEntry(java.util.AbstractMap.SimpleEntry) Matchers.containsString(org.hamcrest.Matchers.containsString) Metacard(ddf.catalog.data.Metacard) Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Map(java.util.Map) Test(org.junit.Test)

Example 27 with SimpleEntry

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());
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) UpdateRequest(ddf.catalog.operation.UpdateRequest) SimpleEntry(java.util.AbstractMap.SimpleEntry) Matchers.containsString(org.hamcrest.Matchers.containsString) UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Map(java.util.Map)

Example 28 with SimpleEntry

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"));
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) FilterFactory(org.opengis.filter.FilterFactory) CatalogStore(ddf.catalog.source.CatalogStore) Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) QueryImpl(ddf.catalog.operation.impl.QueryImpl) CatalogFramework(ddf.catalog.CatalogFramework) HashSet(java.util.HashSet) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) FederatedSource(ddf.catalog.source.FederatedSource) Metacard(ddf.catalog.data.Metacard) Filter(org.opengis.filter.Filter) QueryResponse(ddf.catalog.operation.QueryResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 29 with SimpleEntry

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);
}
Also used : SimpleEntry(java.util.AbstractMap.SimpleEntry) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) List(java.util.List) ArrayList(java.util.ArrayList)

Example 30 with SimpleEntry

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);
}
Also used : SimpleEntry(java.util.AbstractMap.SimpleEntry) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST)

Aggregations

SimpleEntry (java.util.AbstractMap.SimpleEntry)47 Test (org.junit.Test)24 ArrayList (java.util.ArrayList)21 HashMap (java.util.HashMap)15 CucumberFeature (cucumber.runtime.model.CucumberFeature)10 Result (gherkin.formatter.model.Result)10 Entry (java.util.Map.Entry)10 HashSet (java.util.HashSet)9 Map (java.util.Map)8 Metacard (ddf.catalog.data.Metacard)7 Serializable (java.io.Serializable)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 List (java.util.List)6 UpdateRequest (ddf.catalog.operation.UpdateRequest)5 Set (java.util.Set)5 Configuration (org.apache.commons.configuration.Configuration)5 ZookeeperConfigurationProvider (com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationProvider)4 LinkedList (java.util.LinkedList)4 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)3 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)3