2 * Copyright 2000-2015 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.theoryinpractice.testng.model;
18 import com.intellij.execution.CantRunException;
19 import com.intellij.execution.configurations.RuntimeConfigurationException;
20 import com.intellij.openapi.util.Comparing;
21 import com.intellij.openapi.vfs.VirtualFile;
22 import com.intellij.psi.PsiClass;
23 import com.intellij.psi.PsiElement;
24 import com.intellij.psi.PsiFile;
25 import com.intellij.psi.PsiMethod;
26 import com.intellij.psi.util.PsiUtilCore;
27 import com.intellij.psi.xml.XmlFile;
28 import com.theoryinpractice.testng.configuration.TestNGConfiguration;
29 import org.testng.xml.Parser;
31 import java.util.List;
34 public class TestNGTestSuite extends TestNGTestObject {
35 private static final Object PARSE_LOCK = new Object();
36 public TestNGTestSuite(TestNGConfiguration config) {
41 public void fillTestObjects(Map<PsiClass, Map<PsiMethod, List<String>>> classes) throws CantRunException {}
44 public String getGeneratedName() {
45 return myConfig.getPersistantData().getSuiteName();
49 public String getActionName() {
50 return myConfig.getPersistantData().getSuiteName();
54 public void checkConfiguration() throws RuntimeConfigurationException {
55 final TestData data = myConfig.getPersistantData();
57 final Parser parser = new Parser(data.getSuiteName());
58 parser.setLoadClasses(false);
59 synchronized (PARSE_LOCK) {
60 parser.parse();//try to parse suite.xml
64 throw new RuntimeConfigurationException("Unable to parse '" + data.getSuiteName() + "' specified");
69 public boolean isConfiguredByElement(PsiElement element) {
70 final PsiFile containingFile = element.getContainingFile();
71 if (containingFile instanceof XmlFile) {
72 final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(containingFile);
73 return virtualFile != null && Comparing.strEqual(myConfig.getPersistantData().getSuiteName(), virtualFile.getPath());