diff --git a/backend/.gitignore b/backend/.gitignore index 731f40bf3abe919c1748a6baedd6f4852f8709de..44cceecb40e7d964c74026c81082be1cb7cae0d9 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -26,6 +26,7 @@ yarn-error.log* src/main/resources/static src/main/resources/templates +src/test/ target .settings .project diff --git a/backend/src/test/java/io/metersphere/ApplicationTests.java b/backend/src/test/java/io/metersphere/ApplicationTests.java deleted file mode 100644 index 4806fcfaba2d5c370f3728cb42e8f2946c97a213..0000000000000000000000000000000000000000 --- a/backend/src/test/java/io/metersphere/ApplicationTests.java +++ /dev/null @@ -1,54 +0,0 @@ -package io.metersphere; - - -import io.metersphere.base.domain.SystemParameter; -import io.metersphere.base.mapper.UserMapper; -import io.metersphere.commons.constants.ParamConstants; -import io.metersphere.commons.utils.CompressUtils; -import io.metersphere.service.RegistryParamService; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import javax.annotation.Resource; -import java.util.List; - -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class ApplicationTests { - @Resource - UserMapper userMapper; - @Resource - private RegistryParamService registryParamService; - - @Test - public void test1() { - final Object test = CompressUtils.zip("test".getBytes()); - final Object unzip = CompressUtils.unzip(test); - System.out.println(new String((byte[]) unzip)); - } - - @Test - public void test2() { - List registry = registryParamService.getRegistry(ParamConstants.Classify.REGISTRY.getValue()); - System.out.println(registry); - for (SystemParameter sp : registry) { - if ("registry.password".equals(sp.getParamKey())) { - sp.setParamValue("Calong@2015"); - } - if ("registry.url".equals(sp.getParamKey())) { - sp.setParamValue("registry.fit2cloud.com"); - } - if ("registry.repo".equals(sp.getParamKey())) { - sp.setParamValue("metersphere"); - } - if ("registry.username".equals(sp.getParamKey())) { - sp.setParamValue("developer"); - } - } - registryParamService.updateRegistry(registry); - } - - -} diff --git a/backend/src/test/java/io/metersphere/BaseTest.java b/backend/src/test/java/io/metersphere/BaseTest.java deleted file mode 100644 index 8c56d027abb4c9a7ef913dd58c370ca6b739e66f..0000000000000000000000000000000000000000 --- a/backend/src/test/java/io/metersphere/BaseTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.metersphere; - -import io.fabric8.kubernetes.api.model.Pod; -import io.fabric8.kubernetes.api.model.PodList; -import io.fabric8.kubernetes.client.ConfigBuilder; -import io.fabric8.kubernetes.client.DefaultKubernetesClient; -import io.fabric8.kubernetes.client.KubernetesClient; -import org.junit.Before; -import org.junit.Test; - -public class BaseTest { - protected KubernetesClient kubernetesClient; - - @Before - public void before() { - - try { - ConfigBuilder configBuilder = new ConfigBuilder(); - configBuilder.withMasterUrl("https://172.16.10.93:6443"); - kubernetesClient = new DefaultKubernetesClient(configBuilder.build()); - } catch (Exception e) { - System.out.println(e.getMessage()); - } - - } - - @Test - public void test1() { - PodList list = kubernetesClient.pods().list(); - for (Pod item : list.getItems()) { - System.out.println(item); - } - } -} diff --git a/backend/src/test/java/io/metersphere/JmxFileParseTest.java b/backend/src/test/java/io/metersphere/JmxFileParseTest.java deleted file mode 100644 index 783ebb93bb7bffa95a082bccc10377994139be75..0000000000000000000000000000000000000000 --- a/backend/src/test/java/io/metersphere/JmxFileParseTest.java +++ /dev/null @@ -1,536 +0,0 @@ -package io.metersphere; - -import io.metersphere.config.KafkaProperties; -import org.apache.commons.lang3.StringUtils; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; - -import javax.annotation.Resource; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; -import java.io.File; -import java.io.FileInputStream; -import java.io.StringWriter; - -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class JmxFileParseTest { - private final static String HASH_TREE_ELEMENT = "hashTree"; - private final static String TEST_PLAN = "TestPlan"; - private final static String STRING_PROP = "stringProp"; - private final static String CONCURRENCY_THREAD_GROUP = "com.blazemeter.jmeter.threads.concurrency.ConcurrencyThreadGroup"; - private final static String VARIABLE_THROUGHPUT_TIMER = "kg.apc.jmeter.timers.VariableThroughputTimer"; - private final static String BACKEND_LISTENER = "BackendListener"; - private final static String THREAD_GROUP = "ThreadGroup"; - private final static String CONFIG_TEST_ELEMENT = "ConfigTestElement"; - private final static String DNS_CACHE_MANAGER = "DNSCacheManager"; - private final static String ARGUMENTS = "Arguments"; - @Resource - private KafkaProperties kafkaProperties; - - @Test - public void testProperties() { - System.out.println(kafkaProperties.getSsl()); - } - - @Test - public void parse() throws Exception { - File file = new File("/Users/liuruibin/Downloads/blaze_meter_dev2.jmx"); - file = new File("/Users/liuruibin/Desktop/041301.jmx"); - - final FileInputStream inputStream = new FileInputStream(file); - final InputSource inputSource = new InputSource(inputStream); - - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - - DocumentBuilder docBuilder = factory.newDocumentBuilder(); - final Document document = docBuilder.parse(inputSource); - - final Element jmeterTestPlan = document.getDocumentElement(); - - NodeList childNodes = jmeterTestPlan.getChildNodes(); - for (int i = 0; i < childNodes.getLength(); i++) { - Node node = childNodes.item(i); - - if (node instanceof Element) { - Element ele = (Element) node; - - // jmeterTestPlan的子元素肯定是 - parseHashTree(ele); - } - } - - - DOMSource domSource = new DOMSource(document); - StringWriter writer = new StringWriter(); - StreamResult result = new StreamResult(writer); - TransformerFactory tf = TransformerFactory.newInstance(); - Transformer transformer = tf.newTransformer(); - transformer.transform(domSource, result); - System.out.println("XML IN String format is: \n" + writer.toString()); -// FileUtils.writeStringToFile(new File("/tmp/test-jmeter.jmx"), writer.toString(), StandardCharsets.UTF_8); - } - - private void parseHashTree(Element hashTree) { - if (!valid(hashTree)) { - return; - } - - if (hashTree.getChildNodes().getLength() > 0) { - final NodeList childNodes = hashTree.getChildNodes(); - for (int i = 0; i < childNodes.getLength(); i++) { - Node node = childNodes.item(i); - if (node instanceof Element) { - Element ele = (Element) node; - if (!valid(ele)) { - continue; - } - - if (nodeNameEquals(ele, HASH_TREE_ELEMENT)) { - parseHashTree(ele); - } else if (nodeNameEquals(ele, TEST_PLAN)) { - processTearDownTestPlan(ele); - } else if (nodeNameEquals(ele, CONCURRENCY_THREAD_GROUP)) { - processConcurrencyThreadGroup(ele); - processCheckoutTimer(ele); - processCheckoutBackendListener(ele); - } else if (nodeNameEquals(ele, THREAD_GROUP)) { - processThreadGroup(ele); - processConcurrencyThreadGroup(ele); - processCheckoutTimer(ele); - processCheckoutBackendListener(ele); - } else if (nodeNameEquals(ele, VARIABLE_THROUGHPUT_TIMER)) { - - } else if (nodeNameEquals(ele, BACKEND_LISTENER)) { -// processBackendListener(ele); - } else if (nodeNameEquals(ele, CONFIG_TEST_ELEMENT)) { -// processConfigTestElement(ele); - } else if (nodeNameEquals(ele, DNS_CACHE_MANAGER)) { -// processDnsCacheManager(ele); - } else if (nodeNameEquals(ele, ARGUMENTS)) { -// processArguments(ele); - } - } - } - } - } - - private void processArguments(Element ele) { - /* - - - - BASE_URL_1 - rddev2.fit2cloud.com - = - - - - */ - NodeList childNodes = ele.getChildNodes(); - for (int i = 0; i < childNodes.getLength(); i++) { - Node item = childNodes.item(i); - if (item instanceof Element && nodeNameEquals(item, "collectionProp")) { - removeChildren(item); - Document document = item.getOwnerDocument(); - Element elementProp = document.createElement("elementProp"); - elementProp.setAttribute("name", ""); - elementProp.setAttribute("elementType", ""); - elementProp.appendChild(createStringProp(document, "Argument.name", "")); - elementProp.appendChild(createStringProp(document, "Argument.value", "")); - elementProp.appendChild(createStringProp(document, "Argument.metadata", "=")); - item.appendChild(elementProp); - } - } - - } - - private void processDnsCacheManager(Element ele) { - /* - - - - - baiud.com - 172.16.10.187 - - - true - true - - */ - NodeList childNodes = ele.getChildNodes(); - for (int i = 0, size = childNodes.getLength(); i < size; i++) { - Node item = childNodes.item(i); - if (item instanceof Element && nodeNameEquals(item, "collectionProp") - && StringUtils.equals(((Element) item).getAttribute("name"), "DNSCacheManager.hosts")) { - Node childNode = item.getFirstChild(); - // todo 绑定域名 多个 - while (!(childNode instanceof Element)) { - childNode = childNode.getNextSibling(); - } - Element elementProp = ((Element) childNode); - elementProp.setAttribute("name", "baidu.com"); - elementProp.setAttribute("elementType", "StaticHost"); - removeChildren(elementProp); - elementProp.appendChild(createStringProp(ele.getOwnerDocument(), "StaticHost.Name", "")); - elementProp.appendChild(createStringProp(ele.getOwnerDocument(), "StaticHost.Address", "")); - } - - if (item instanceof Element && nodeNameEquals(item, "boolProp") - && StringUtils.equals(((Element) item).getAttribute("name"), "DNSCacheManager.isCustomResolver")) { - item.getFirstChild().setNodeValue("true"); - } - } - - } - - private void processConfigTestElement(Element ele) { - /* - - - - - - - - - - true - true - 6 - 30000 - - - */ - NodeList childNodes = ele.getChildNodes(); - for (int i = 0, size = childNodes.getLength(); i < size; i++) { - Node item = childNodes.item(i); - if (item instanceof Element && nodeNameEquals(item, STRING_PROP) - && StringUtils.equals(((Element) item).getAttribute("name"), "HTTPSampler.connect_timeout")) { - - item.getFirstChild().setNodeValue("30000"); - } - } - } - - private void processTearDownTestPlan(Element ele) { - /*true*/ - Document document = ele.getOwnerDocument(); - Element tearDownSwitch = createBoolProp(document, "TestPlan.tearDown_on_shutdown", true); - ele.appendChild(tearDownSwitch); - - Node hashTree = ele.getNextSibling(); - while (!(hashTree instanceof Element)) { - hashTree = hashTree.getNextSibling(); - } - /* - - continue - - false - 1 - - 1 - 1 - false - - - true - - */ - Element tearDownElement = document.createElement("PostThreadGroup"); - tearDownElement.setAttribute("guiclass", "PostThreadGroupGui"); - tearDownElement.setAttribute("testclass", "PostThreadGroup"); - tearDownElement.setAttribute("testname", "tearDown Thread Group"); - tearDownElement.setAttribute("enabled", "true"); - tearDownElement.appendChild(createStringProp(document, "ThreadGroup.on_sample_error", "continue")); - tearDownElement.appendChild(createStringProp(document, "ThreadGroup.num_threads", "1")); - tearDownElement.appendChild(createStringProp(document, "ThreadGroup.ramp_time", "1")); - tearDownElement.appendChild(createStringProp(document, "ThreadGroup.duration", "")); - tearDownElement.appendChild(createStringProp(document, "ThreadGroup.delay", "")); - tearDownElement.appendChild(createBoolProp(document, "ThreadGroup.scheduler", false)); - tearDownElement.appendChild(createBoolProp(document, "ThreadGroup.same_user_on_next_iteration", true)); - Element elementProp = document.createElement("elementProp"); - elementProp.setAttribute("name", "ThreadGroup.main_controller"); - elementProp.setAttribute("elementType", "LoopController"); - elementProp.setAttribute("guiclass", "LoopControlPanel"); - elementProp.setAttribute("testclass", "LoopController"); - elementProp.setAttribute("testname", "Loop Controller"); - elementProp.setAttribute("enabled", "true"); - elementProp.appendChild(createBoolProp(document, "LoopController.continue_forever", false)); - elementProp.appendChild(createStringProp(document, "LoopController.loops", "1")); - tearDownElement.appendChild(elementProp); - hashTree.appendChild(tearDownElement); - - Element tearDownHashTree = document.createElement(HASH_TREE_ELEMENT); - /* - - */ - Element onceOnlyController = document.createElement("OnceOnlyController"); - onceOnlyController.setAttribute("guiclass", "OnceOnlyControllerGui"); - onceOnlyController.setAttribute("testclass", "OnceOnlyController"); - onceOnlyController.setAttribute("testname", "Once Only Controller"); - onceOnlyController.setAttribute("enabled", "true"); - tearDownHashTree.appendChild(onceOnlyController); - /* - - - false - true - false - - - - */ - Element onceOnlyHashTree = document.createElement(HASH_TREE_ELEMENT); - Element debugSampler = document.createElement("DebugSampler"); - debugSampler.setAttribute("guiclass", "TestBeanGUI"); - debugSampler.setAttribute("testclass", "DebugSampler"); - debugSampler.setAttribute("testname", "Debug Sampler"); - debugSampler.setAttribute("enabled", "true"); - debugSampler.appendChild(createBoolProp(document, "displayJMeterProperties", false)); - debugSampler.appendChild(createBoolProp(document, "displayJMeterVariables", true)); - debugSampler.appendChild(createBoolProp(document, "displaySystemProperties", false)); - onceOnlyHashTree.appendChild(debugSampler); - // 添加空的 hashTree - onceOnlyHashTree.appendChild(document.createElement(HASH_TREE_ELEMENT)); - tearDownHashTree.appendChild(onceOnlyHashTree); - hashTree.appendChild(tearDownHashTree); - // 添加backend listener - processCheckoutBackendListener(tearDownElement); - } - - private Element createBoolProp(Document document, String name, boolean value) { - Element tearDownSwitch = document.createElement("boolProp"); - tearDownSwitch.setAttribute("name", name); - tearDownSwitch.appendChild(document.createTextNode(String.valueOf(value))); - return tearDownSwitch; - } - - private void processBackendListener(Element backendListener) { - Document document = backendListener.getOwnerDocument(); - // 清空child - removeChildren(backendListener); - backendListener.appendChild(createStringProp(document, "classname", "io.github.rahulsinghai.jmeter.backendlistener.kafka.KafkaBackendClient")); - backendListener.appendChild(createStringProp(document, "QUEUE_SIZE", "5000")); - // elementProp - Element elementProp = document.createElement("elementProp"); - elementProp.setAttribute("name", "arguments"); - elementProp.setAttribute("elementType", "Arguments"); - elementProp.setAttribute("guiclass", "ArgumentsPanel"); - elementProp.setAttribute("testclass", "Arguments"); - elementProp.setAttribute("enabled", "true"); - Element collectionProp = document.createElement("collectionProp"); - collectionProp.setAttribute("name", "Arguments.arguments"); - collectionProp.appendChild(createKafkaProp(document, "kafka.acks", kafkaProperties.getAcks())); - collectionProp.appendChild(createKafkaProp(document, "kafka.bootstrap.servers", kafkaProperties.getBootstrapServers())); - collectionProp.appendChild(createKafkaProp(document, "kafka.topic", kafkaProperties.getTopic())); - collectionProp.appendChild(createKafkaProp(document, "kafka.sample.filter", kafkaProperties.getSampleFilter())); - collectionProp.appendChild(createKafkaProp(document, "kafka.fields", kafkaProperties.getFields())); - collectionProp.appendChild(createKafkaProp(document, "kafka.test.mode", kafkaProperties.getTestMode())); - collectionProp.appendChild(createKafkaProp(document, "kafka.parse.all.req.headers", kafkaProperties.getParseAllReqHeaders())); - collectionProp.appendChild(createKafkaProp(document, "kafka.parse.all.res.headers", kafkaProperties.getParseAllResHeaders())); - collectionProp.appendChild(createKafkaProp(document, "kafka.timestamp", kafkaProperties.getTimestamp())); - collectionProp.appendChild(createKafkaProp(document, "kafka.compression.type", kafkaProperties.getCompressionType())); - collectionProp.appendChild(createKafkaProp(document, "kafka.ssl.enabled", kafkaProperties.getSsl().getEnabled())); - collectionProp.appendChild(createKafkaProp(document, "kafka.ssl.key.password", kafkaProperties.getSsl().getKeyPassword())); - collectionProp.appendChild(createKafkaProp(document, "kafka.ssl.keystore.location", kafkaProperties.getSsl().getKeystoreLocation())); - collectionProp.appendChild(createKafkaProp(document, "kafka.ssl.keystore.password", kafkaProperties.getSsl().getKeystorePassword())); - collectionProp.appendChild(createKafkaProp(document, "kafka.ssl.truststore.location", kafkaProperties.getSsl().getTruststoreLocation())); - collectionProp.appendChild(createKafkaProp(document, "kafka.ssl.truststore.password", kafkaProperties.getSsl().getTruststorePassword())); - collectionProp.appendChild(createKafkaProp(document, "kafka.ssl.enabled.protocols", kafkaProperties.getSsl().getEnabledProtocols())); - collectionProp.appendChild(createKafkaProp(document, "kafka.ssl.keystore.type", kafkaProperties.getSsl().getKeystoreType())); - collectionProp.appendChild(createKafkaProp(document, "kafka.ssl.protocol", kafkaProperties.getSsl().getProtocol())); - collectionProp.appendChild(createKafkaProp(document, "kafka.ssl.provider", kafkaProperties.getSsl().getProvider())); - collectionProp.appendChild(createKafkaProp(document, "kafka.ssl.truststore.type", kafkaProperties.getSsl().getTruststoreType())); - collectionProp.appendChild(createKafkaProp(document, "kafka.batch.size", kafkaProperties.getBatchSize())); - collectionProp.appendChild(createKafkaProp(document, "kafka.client.id", kafkaProperties.getClientId())); - collectionProp.appendChild(createKafkaProp(document, "kafka.connections.max.idle.ms", kafkaProperties.getConnectionsMaxIdleMs())); - // 添加关联关系 test.id test.name - collectionProp.appendChild(createKafkaProp(document, "test.id", "")); - collectionProp.appendChild(createKafkaProp(document, "test.name", "")); - - elementProp.appendChild(collectionProp); - // set elementProp - backendListener.appendChild(elementProp); - } - - private void processCheckoutBackendListener(Element element) { - Document document = element.getOwnerDocument(); - - Node listenerParent = element.getNextSibling(); - while (!(listenerParent instanceof Element)) { - listenerParent = listenerParent.getNextSibling(); - } - - NodeList childNodes = listenerParent.getChildNodes(); - for (int i = 0, l = childNodes.getLength(); i < l; i++) { - Node item = childNodes.item(i); - if (nodeNameEquals(item, BACKEND_LISTENER)) { - // 如果已经存在,不再添加 - return; - } - } - - // add class name - Element backendListener = document.createElement(BACKEND_LISTENER); - backendListener.setAttribute("guiclass", "BackendListenerGui"); - backendListener.setAttribute("testclass", "BackendListener"); - backendListener.setAttribute("testname", "Backend Listener"); - backendListener.setAttribute("enabled", "true"); - listenerParent.appendChild(backendListener); - listenerParent.appendChild(document.createElement(HASH_TREE_ELEMENT)); - } - - private Element createKafkaProp(Document document, String name, String value) { - Element eleProp = document.createElement("elementProp"); - eleProp.setAttribute("name", name); - eleProp.setAttribute("elementType", "Argument"); - eleProp.appendChild(createStringProp(document, "Argument.name", name)); - eleProp.appendChild(createStringProp(document, "Argument.value", value)); - eleProp.appendChild(createStringProp(document, "Argument.metadata", "=")); - return eleProp; - } - - private void processThreadGroup(Element threadGroup) { - // 重命名 tagName - Document document = threadGroup.getOwnerDocument(); - document.renameNode(threadGroup, threadGroup.getNamespaceURI(), CONCURRENCY_THREAD_GROUP); - threadGroup.setAttribute("guiclass", CONCURRENCY_THREAD_GROUP + "Gui"); - threadGroup.setAttribute("testclass", CONCURRENCY_THREAD_GROUP); - /* - - continue - 2 - 12 - 2 - 3 - - 1 - S - */ - removeChildren(threadGroup); - // elementProp - Element elementProp = document.createElement("elementProp"); - elementProp.setAttribute("name", "ThreadGroup.main_controller"); - elementProp.setAttribute("elementType", "com.blazemeter.jmeter.control.VirtualUserController"); - threadGroup.appendChild(elementProp); - - - threadGroup.appendChild(createStringProp(document, "ThreadGroup.on_sample_error", "continue")); - threadGroup.appendChild(createStringProp(document, "TargetLevel", "2")); - threadGroup.appendChild(createStringProp(document, "RampUp", "12")); - threadGroup.appendChild(createStringProp(document, "Steps", "2")); - threadGroup.appendChild(createStringProp(document, "Hold", "12")); - threadGroup.appendChild(createStringProp(document, "LogFilename", "")); - threadGroup.appendChild(createStringProp(document, "Iterations", "1")); - threadGroup.appendChild(createStringProp(document, "Unit", "S")); - } - - private void processCheckoutTimer(Element element) { - /* - - - - 1 - 1 - 13 - - - - */ - Document document = element.getOwnerDocument(); - - - Node timerParent = element.getNextSibling(); - while (!(timerParent instanceof Element)) { - timerParent = timerParent.getNextSibling(); - } - - NodeList childNodes = timerParent.getChildNodes(); - for (int i = 0, l = childNodes.getLength(); i < l; i++) { - Node item = childNodes.item(i); - if (nodeNameEquals(item, VARIABLE_THROUGHPUT_TIMER)) { - // 如果已经存在,不再添加 - return; - } - } - - Element timer = document.createElement(VARIABLE_THROUGHPUT_TIMER); - timer.setAttribute("guiclass", VARIABLE_THROUGHPUT_TIMER + "Gui"); - timer.setAttribute("testclass", VARIABLE_THROUGHPUT_TIMER); - timer.setAttribute("testname", "jp@gc - Throughput Shaping Timer"); - timer.setAttribute("enabled", "true"); - - Element collectionProp = document.createElement("collectionProp"); - collectionProp.setAttribute("name", "load_profile"); - Element childCollectionProp = document.createElement("collectionProp"); - childCollectionProp.setAttribute("name", "140409499"); - childCollectionProp.appendChild(createStringProp(document, "49", "1")); - childCollectionProp.appendChild(createStringProp(document, "49", "1")); - childCollectionProp.appendChild(createStringProp(document, "1570", "10")); - collectionProp.appendChild(childCollectionProp); - timer.appendChild(collectionProp); - timerParent.appendChild(timer); - // 添加一个空的hashTree - timerParent.appendChild(document.createElement(HASH_TREE_ELEMENT)); - } - - private Element createStringProp(Document document, String name, String value) { - Element unit = document.createElement(STRING_PROP); - unit.setAttribute("name", name); - unit.appendChild(document.createTextNode(value)); - return unit; - } - - private void processConcurrencyThreadGroup(Element concurrencyThreadGroup) { - if (concurrencyThreadGroup.getChildNodes().getLength() > 0) { - final NodeList childNodes = concurrencyThreadGroup.getChildNodes(); - for (int i = 0; i < childNodes.getLength(); i++) { - Node node = childNodes.item(i); - if (node instanceof Element) { - Element ele = (Element) node; - if (!valid(ele)) { - continue; - } - - if (nodeNameEquals(ele, STRING_PROP)) { - parseStringProp(ele); - } - } - } - } - } - - private void parseStringProp(Element stringProp) { - if (stringProp.getChildNodes().getLength() > 0) { - stringProp.getFirstChild().setNodeValue("1"); - } - } - - private boolean nodeNameEquals(Node node, String desiredName) { - return desiredName.equals(node.getNodeName()) || desiredName.equals(node.getLocalName()); - } - - private boolean valid(Element ele) { - return StringUtils.isBlank(ele.getAttribute("enabled")) || Boolean.parseBoolean(ele.getAttribute("enabled")); - } - - private void removeChildren(Node node) { - while (node.hasChildNodes()) { - node.removeChild(node.getFirstChild()); - } - } -} diff --git a/backend/src/test/java/io/metersphere/ResultDataParseTest.java b/backend/src/test/java/io/metersphere/ResultDataParseTest.java deleted file mode 100644 index 10f3eeadceb3d4d552de496abc4e9a887f0743f1..0000000000000000000000000000000000000000 --- a/backend/src/test/java/io/metersphere/ResultDataParseTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.metersphere; - -import io.metersphere.report.base.Statistics; -import org.junit.Test; - -import java.lang.reflect.Field; - -public class ResultDataParseTest { - - String[] s = {"1","2","3","4","5","6","7","8","9","10","11","12","13"}; - - public static T setParam(Class clazz, Object[] args) - throws Exception { - if (clazz == null || args == null) { - throw new IllegalArgumentException(); - } - T t = clazz.newInstance(); - Field[] fields = clazz.getDeclaredFields(); - if (fields == null || fields.length > args.length) { - throw new IndexOutOfBoundsException(); - } - for (int i = 0; i < fields.length; i++) { - fields[i].setAccessible(true); - fields[i].set(t, args[i]); - } - return t; - } - - @Test - public void test() throws Exception { - Statistics statistics = setParam(Statistics.class, s); - System.out.println(statistics.toString()); - } - - -} diff --git a/backend/src/test/java/io/metersphere/service/TestCaseTest.java b/backend/src/test/java/io/metersphere/service/TestCaseTest.java deleted file mode 100644 index 5e7975760dead348c1886de8d9ce918db40834ad..0000000000000000000000000000000000000000 --- a/backend/src/test/java/io/metersphere/service/TestCaseTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.metersphere.service; - -import io.metersphere.base.domain.TestCaseNode; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import javax.annotation.Resource; - -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class TestCaseTest { - - - @Resource - TestCaseNodeService testCaseNodeService; - - @Test - public void addNode() { - TestCaseNode node = new TestCaseNode(); - node.setName("node01"); - node.setProjectId("2ade216b-01a6-43d0-b48c-4a3898306096"); - node.setCreateTime(System.currentTimeMillis()); - node.setUpdateTime(System.currentTimeMillis()); - testCaseNodeService.addNode(node); - } - - -} diff --git a/backend/src/test/java/io/metersphere/service/TestResourcePoolServiceTest.java b/backend/src/test/java/io/metersphere/service/TestResourcePoolServiceTest.java deleted file mode 100644 index 28587d695c11e446ef5f98c90e11e523d4247f90..0000000000000000000000000000000000000000 --- a/backend/src/test/java/io/metersphere/service/TestResourcePoolServiceTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.metersphere.service; - -import io.metersphere.controller.request.resourcepool.QueryResourcePoolRequest; -import io.metersphere.dto.TestResourcePoolDTO; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import javax.annotation.Resource; -import java.util.List; - -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class TestResourcePoolServiceTest { - - @Resource - private TestResourcePoolService testResourcePoolService; - - @Test - public void listResourcePools() { - List list = testResourcePoolService.listResourcePools(new QueryResourcePoolRequest()); - System.out.println(list.size()); - } -} \ No newline at end of file