Commit 975b3656 authored by doc@bgerp.org's avatar doc@bgerp.org

p12134 Code format, cleanup.

parent 924b3c77
......@@ -127,7 +127,7 @@ public class InstallerModule {
boolean result = false;
try {
String fullClassName = "ru.bgcrm.util.distr.call." + callClass;
InstallationCall call = (InstallationCall) Class.forName(fullClassName.toString()).newInstance();
InstallationCall call = (InstallationCall) Class.forName(fullClassName.toString()).getDeclaredConstructor().newInstance();
call.call(setup, zip, param);
result = true;
} catch (Exception ex) {
......
This diff is collapsed.
package ru.bgcrm.dao.expression;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.HashMap;
......@@ -9,116 +11,114 @@ import java.util.Map;
import org.junit.Test;
import ru.bgcrm.dao.expression.Expression;
public class ExpressionTest {
public static class LibraryMain {
public void test1(String param1) {
System.out.println("test1 is called");
}
public void test1(String param1, String param2) {
System.out.println("test1 ext is called");
}
}
@Test
public void testSeveralFunctions() {
Map<String, Object> ctx = new HashMap<>();
ctx.put(null, new LibraryMain());
Expression exp = new Expression(ctx);
exp.executeScript("test1('ddd'); test1('ddd', 'mmm');");
}
public static class TestExpression {
private String value;
public void setValue(String value) {
this.value = value;
}
public List<Integer> getIds() {
return Arrays.asList(new Integer[] { 1, 3, 4 });
}
}
@Test
public void testBooleanExpression() {
Map<String, Object> ctx = new HashMap<>();
ctx.put("t", new TestExpression());
Expression exp = new Expression(ctx);
assertTrue(exp.check("1 =~ t.getIds()"));
assertFalse(exp.check("7 =~ t.getIds()"));
assertEquals("testValue",
exp.executeScript("b = '0'; a = t.getIds(); if (1 =~ a){b = 'testValue'}; return b;"));
}
@Test
public void testReturningValues() {
Map<String, Object> ctx = new HashMap<>();
final TestExpression testExpr = new TestExpression();
ctx.put("t", testExpr);
Expression exp = new Expression(ctx);
exp.executeScript("if (!cu:isEmpty(t.getIds())){t.setValue('testValue')};");
assertEquals("testValue", testExpr.value);
}
@Test
public void testExpressionV3() {
Map<String, Object> ctx = new HashMap<>();
final TestExpression testExpr = new TestExpression();
ctx.put("t", testExpr);
Expression exp = new Expression(ctx);
assertEquals(new Boolean(true), exp.executeScript("return !empty(cu.intersection({1,2}, t.getIds()))"));
}
@Test
public void testExpressionAsScript() {
Map<String, Object> ctx = new HashMap<>();
final TestExpression testExpr = new TestExpression();
ctx.put("t", testExpr);
Expression exp = new Expression(ctx);
assertEquals("ab", exp.getString("'a'.concat('b')"));
}
@Test
public void testNewCall() {
Expression exp = new Expression(new HashMap<>());
assertEquals("value44", exp.getString("new('ru.bgcrm.dao.expression.ExpressionTestClass', 'value44').getValue()"));
}
@Test
public void testIfExpr() {
Map<String, Object> map = new HashMap<String, Object>(1);
map.put("numberFrom", "13333333333");
String expr = "if( numberFrom.length() == 11 ){ numberFrom = numberFrom.substring(1)}; return numberFrom;";
String processed = new Expression(map).getString(expr);
assertEquals("3333333333", processed);
}
@Test
public void testStaticMethodCall() {
String expr =
"var u = ru.bgcrm.util.Utils;"
+ "return u.parseInt('3') + 't';";
String value = new Expression(new HashMap<>()).getString(expr);
assertEquals("3t", value);
}
@Test
public void testConcatenationNull() {
Map<String, Object> map = new HashMap<String, Object>(1);
map.put("a", "t");
String expr = "b = null;" +
"return a + b;";
String value = new Expression(map).getString(expr);
assertEquals("t", value);
}
public static class LibraryMain {
public void test1(String param1) {
System.out.println("test1 is called");
}
public void test1(String param1, String param2) {
System.out.println("test1 ext is called");
}
}
@Test
public void testSeveralFunctions() {
Map<String, Object> ctx = new HashMap<>();
ctx.put(null, new LibraryMain());
Expression exp = new Expression(ctx);
exp.executeScript("test1('ddd'); test1('ddd', 'mmm');");
}
public static class TestExpression {
private String value;
public void setValue(String value) {
this.value = value;
}
public List<Integer> getIds() {
return Arrays.asList(new Integer[] { 1, 3, 4 });
}
}
@Test
public void testBooleanExpression() {
Map<String, Object> ctx = new HashMap<>();
ctx.put("t", new TestExpression());
Expression exp = new Expression(ctx);
assertTrue(exp.check("1 =~ t.getIds()"));
assertFalse(exp.check("7 =~ t.getIds()"));
assertEquals("testValue",
exp.executeScript("b = '0'; a = t.getIds(); if (1 =~ a){b = 'testValue'}; return b;"));
}
@Test
public void testReturningValues() {
Map<String, Object> ctx = new HashMap<>();
final TestExpression testExpr = new TestExpression();
ctx.put("t", testExpr);
Expression exp = new Expression(ctx);
exp.executeScript("if (!cu:isEmpty(t.getIds())){t.setValue('testValue')};");
assertEquals("testValue", testExpr.value);
}
@Test
public void testExpressionV3() {
Map<String, Object> ctx = new HashMap<>();
final TestExpression testExpr = new TestExpression();
ctx.put("t", testExpr);
Expression exp = new Expression(ctx);
assertEquals(true, exp.executeScript("return !empty(cu.intersection({1,2}, t.getIds()))"));
}
@Test
public void testExpressionAsScript() {
Map<String, Object> ctx = new HashMap<>();
final TestExpression testExpr = new TestExpression();
ctx.put("t", testExpr);
Expression exp = new Expression(ctx);
assertEquals("ab", exp.getString("'a'.concat('b')"));
}
@Test
public void testNewCall() {
Expression exp = new Expression(new HashMap<>());
assertEquals("value44", exp.getString("new('ru.bgcrm.dao.expression.ExpressionTestClass', 'value44').getValue()"));
}
@Test
public void testIfExpr() {
Map<String, Object> map = new HashMap<String, Object>(1);
map.put("numberFrom", "13333333333");
String expr = "if( numberFrom.length() == 11 ){ numberFrom = numberFrom.substring(1)}; return numberFrom;";
String processed = new Expression(map).getString(expr);
assertEquals("3333333333", processed);
}
@Test
public void testStaticMethodCall() {
String expr =
"var u = ru.bgcrm.util.Utils;"
+ "return u.parseInt('3') + 't';";
String value = new Expression(new HashMap<>()).getString(expr);
assertEquals("3t", value);
}
@Test
public void testConcatenationNull() {
Map<String, Object> map = new HashMap<String, Object>(1);
map.put("a", "t");
String expr = "b = null;" +
"return a + b;";
String value = new Expression(map).getString(expr);
assertEquals("t", value);
}
}
\ No newline at end of file
package ru.bgcrm.dao.expression;
public class ExpressionTestClass {
private String param;
public ExpressionTestClass(String param) {
this.param = param;
}
public String getValue() {
return param;
}
private String param;
public ExpressionTestClass(String param) {
this.param = param;
}
public String getValue() {
return param;
}
}
package ru.bgcrm.test.bgbilling;
import org.junit.Assert;
import org.junit.Test;
import junit.framework.Assert;
import ru.bgcrm.plugin.bgbilling.proto.model.inet.InetService;
public class InetServiceTest {
......
This diff is collapsed.
......@@ -6,18 +6,16 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import com.beust.jcommander.internal.Lists;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import com.beust.jcommander.internal.Lists;
import ru.bgcrm.model.CommonObjectLink;
import ru.bgcrm.model.Pair;
import ru.bgcrm.model.process.Process;
import ru.bgcrm.model.process.ProcessExecutor;
import ru.bgerp.plugin.blow.model.Board;
import ru.bgerp.plugin.blow.model.Item;
public class BoardTest {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment