/* * Copyright (c) 2000-2006 JetBrains s.r.o. All Rights Reserved. */ /* * Created by IntelliJ IDEA. * User: Anna.Kozlova * Date: 18-Aug-2006 * Time: 13:42:59 */ package com.intellij.codeInspection; import com.intellij.codeInspection.ex.InspectionProfileImpl; import com.intellij.codeInspection.ex.InspectionToolRegistrar; import com.intellij.openapi.util.JDOMUtil; import com.intellij.profile.codeInspection.InspectionProfileManager; import com.intellij.testFramework.UsefulTestCase; import com.intellij.testFramework.fixtures.IdeaTestFixture; import com.intellij.testFramework.fixtures.JavaTestFixtureFactory; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; import java.io.IOException; import java.io.StringWriter; public class InspectionProfileTest extends UsefulTestCase { private static final String PROFILE = "ToConvert"; private final IdeaTestFixture myFixture = JavaTestFixtureFactory.getFixtureFactory().createLightFixtureBuilder().getFixture(); @Override protected void setUp() throws Exception { InspectionProfileImpl.INIT_INSPECTIONS = true; super.setUp(); myFixture.setUp(); InspectionToolRegistrar.getInstance().ensureInitialized(); } @Override protected void tearDown() throws Exception { myFixture.tearDown(); super.tearDown(); InspectionProfileImpl.INIT_INSPECTIONS = false; InspectionProfileManager.getInstance().deleteProfile(PROFILE); } public void testCopyProjectProfile() throws Exception { final Element element = loadProfile(); final InspectionProfileImpl profile = new InspectionProfileImpl(PROFILE); profile.readExternal(element); final ModifiableModel model = profile.getModifiableModel(); model.commit(); final Element copy = new Element("inspections"); profile.writeExternal(copy); StringWriter writer = new StringWriter(); JDOMUtil.writeElement(copy, writer, "\n"); assertTrue(writer.getBuffer().toString(), JDOMUtil.areElementsEqual(element, copy)); } public void testConvertOldProfile() throws Exception { final Element element = loadOldStyleProfile(); final InspectionProfileImpl profile = new InspectionProfileImpl(PROFILE); profile.readExternal(element); final ModifiableModel model = profile.getModifiableModel(); model.commit(); final Element copy = new Element("inspections"); profile.writeExternal(copy); StringWriter writer = new StringWriter(); JDOMUtil.writeElement(copy, writer, "\n"); assertTrue(writer.getBuffer().toString(), JDOMUtil.areElementsEqual(loadProfile(), copy)); } private static Element loadOldStyleProfile() throws IOException, JDOMException { final Document document = JDOMUtil.loadDocument("\n" + " "); return document.getRootElement(); } private static Element loadProfile() throws IOException, JDOMException { final Document document = JDOMUtil.loadDocument("\n" + " "); return document.getRootElement(); } public void testReloadProfileWithUnknownScopes() throws Exception { final Element element = JDOMUtil.loadDocument("\n" + " ").getRootElement(); final InspectionProfileImpl profile = new InspectionProfileImpl(PROFILE); profile.readExternal(element); final ModifiableModel model = profile.getModifiableModel(); model.commit(); final Element copy = new Element("inspections"); profile.writeExternal(copy); StringWriter writer = new StringWriter(); JDOMUtil.writeElement(copy, writer, "\n"); assertTrue(writer.getBuffer().toString(), JDOMUtil.areElementsEqual(element, copy)); } }