/*
 * Copyright 2000-2015 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.lang.properties.xml;

import com.intellij.openapi.application.PluginPathManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
import com.intellij.util.indexing.FileContentImpl;

import java.util.Map;

/**
 * @author Dmitry Avdeev
 */
public class XmlPropertiesIndexTest extends BasePlatformTestCase {

  public void testIndex() {
    final VirtualFile file = myFixture.configureByFile("foo.xml").getVirtualFile();
    Map<XmlPropertiesIndex.Key, String> map = new XmlPropertiesIndex().map(FileContentImpl.createByFile(file));

    assertEquals(3, map.size());
    assertEquals("bar", map.get(new XmlPropertiesIndex.Key("foo")));
    assertEquals("baz", map.get(new XmlPropertiesIndex.Key("fu")));
    assertTrue(map.containsKey(XmlPropertiesIndex.MARKER_KEY));
  }

  public void testSystemId() {
    final VirtualFile file = myFixture.configureByFile("wrong.xml").getVirtualFile();
    Map<XmlPropertiesIndex.Key, String> map = new XmlPropertiesIndex().map(FileContentImpl.createByFile(file));

    assertEquals(0, map.size());
  }

  @Override
  protected String getTestDataPath() {
    return PluginPathManager.getPluginHomePath("properties") + "/testData/xml/";
  }
}

@@ -765,104 +765,410 @@
 lij.
-testFramework.fixtures.BasePlatformTestCase;%0Aimport com.intellij.util.indexing.FileContentImpl;%0A
+psi.PsiFile;%0Aimport com.intellij.psi.search.GlobalSearchScope;%0Aimport com.intellij.psi.xml.XmlFile;%0Aimport com.intellij.testFramework.fixtures.BasePlatformTestCase;%0Aimport com.intellij.util.CommonProcessors;%0Aimport com.intellij.util.indexing.FileBasedIndex;%0Aimport com.intellij.util.indexing.FileContentImpl;%0Aimport org.jetbrains.annotations.NotNull;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;
 %0Aimp
@@ -1320,35 +1320,28 @@
 ) %7B%0A    
-final Virtual
+Psi
 File 
-f
+psiF
 ile = my
@@ -1370,24 +1370,62 @@
 e(%22foo.xml%22)
+;%0A    final VirtualFile file = psiFile
 .getVirtualF
@@ -1585,36 +1585,40 @@
     
-assertEquals(%22bar%22, map.get(
+XmlPropertiesIndex.Key fooKey = 
 new 
@@ -1646,16 +1646,56 @@
 y(%22foo%22)
+;%0A    assertEquals(%22bar%22, map.get(fooKey
 ));%0A    
@@ -1821,16 +1821,382 @@
 R_KEY));
+%0A%0A    assertTrue(XmlPropertiesIndex.isPropertiesFile((XmlFile)psiFile));%0A%0A    List%3CString%3E values = new ArrayList%3C%3E();%0A    FileBasedIndex.getInstance().processValues(%0A      XmlPropertiesIndex.NAME,%0A      fooKey,%0A      null,%0A      (file1, value) -%3E values.add(value),%0A      GlobalSearchScope.allScope(getProject()));%0A    assertEquals(%22bar%22, assertOneElement(values));
 %0A  %7D%0A%0A  
@@ -2228,35 +2228,28 @@
 ) %7B%0A    
-final Virtual
+Psi
 File 
-f
+psiF
 ile = my
@@ -2284,16 +2284,54 @@
 ng.xml%22)
+;%0A    final VirtualFile file = psiFile
 .getVirt
@@ -2486,16 +2486,89 @@
 size());
+%0A%0A    assertFalse(XmlPropertiesIndex.isPropertiesFile((XmlFile)psiFile));
 %0A  %7D%0A%0A  

extend test