com.ecfeed.core.model.ModelHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ecfeed.junit Show documentation
Show all versions of ecfeed.junit Show documentation
An open library used to connect to the ecFeed service. It can be also used as a standalone testing tool. It is integrated with Junit5 and generates a stream of test cases using a selected algorithm (e.g. Cartesian, N-Wise). There are no limitations associated with the off-line version but the user cannot access the on-line computation servers and the model database.
The newest version!
/*******************************************************************************
*
* Copyright (c) 2016 ecFeed AS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
*******************************************************************************/
package com.ecfeed.core.model;
import com.ecfeed.core.utils.ExceptionHelper;
import com.ecfeed.core.utils.RegexHelper;
public class ModelHelper {
public static String getSimpleName(String qualifiedName) {
int lastDotIndex = qualifiedName.lastIndexOf('.');
if (lastDotIndex == -1) {
return qualifiedName;
}
return qualifiedName.substring(lastDotIndex + 1);
}
public static String getQualifiedName(String packageName, String localName) {
return packageName + "." + localName;
}
public static String getPackageName(String qualifiedName) {
int lastDotIndex = qualifiedName.lastIndexOf('.');
return (lastDotIndex == -1)? "" : qualifiedName.substring(0, lastDotIndex);
}
public static boolean isValidTestCaseName(String name) {
return name.matches(RegexHelper.REGEX_TEST_CASE_NODE_NAME);
}
public static boolean isValidConstraintName(String name) {
return name.matches(RegexHelper.REGEX_CONSTRAINT_NODE_NAME);
}
public static boolean validateTestCaseName(String name){
return name.matches(RegexHelper.REGEX_TEST_CASE_NODE_NAME);
}
public static String convertParameterToSimplifiedString(AbstractParameterNode parameter) {
String result = parameter.toString();
String type = parameter.getType();
result.replace(type, ModelHelper.getSimpleName(type));
return result;
}
public static RootNode findRoot(AbstractNode startNode) {
AbstractNode node = startNode;
for (int cnt = 0; ; cnt++) {
if (cnt >= 1000) {
ExceptionHelper.reportRuntimeException("Model too deep or recursive. Cannot find root.");
}
AbstractNode parent = node.getParent();
if (parent == null) {
if (node instanceof RootNode) {
return (RootNode)node;
}
return null;
}
node = parent;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy