Project

General

Profile

« Previous | Next » 

Revision 51877

[maven-release-plugin] copy for tag cnr-spring-utils-1.0.2

View differences:

modules/cnr-spring-utils/tags/cnr-spring-utils-1.0.2/deploy.info
1
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet45/modules/cnr-spring-utils/trunk/", "deploy_repository": "dnet45-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-snapshots", "name": "cnr-spring-utils"}
modules/cnr-spring-utils/tags/cnr-spring-utils-1.0.2/src/test/java/eu/dnetlib/springutils/aop/SimpleBean.java
1
package eu.dnetlib.springutils.aop;
2

  
3
import org.apache.commons.logging.Log;
4
import org.apache.commons.logging.LogFactory;
5

  
6
public class SimpleBean {
7
	private static final Log log = LogFactory.getLog(SimpleBean.class); // NOPMD by marko on 11/24/08 5:02 PM
8

  
9
	private boolean initialized = false;
10
	
11
	public void init() {
12
		log.info("initialized");
13
		System.out.println("initialized");
14
		initialized = true;
15
	}
16

  
17
	public boolean isInitialized() {
18
		return initialized;
19
	}
20
}
modules/cnr-spring-utils/tags/cnr-spring-utils-1.0.2/src/test/java/eu/dnetlib/springutils/aop/MethodCacheInterceptorTest.java
1
package eu.dnetlib.springutils.aop;
2

  
3
import static org.junit.Assert.assertEquals; // NOPMD
4
import static org.junit.Assert.assertFalse;
5
import static org.junit.Assert.assertNotNull;
6
import static org.junit.Assert.assertTrue;
7
import static org.mockito.Mockito.mock; // NOPMD
8
import static org.mockito.Mockito.verify;
9
import static org.mockito.Mockito.when;
10

  
11
import java.lang.reflect.InvocationTargetException;
12
import java.lang.reflect.Method;
13

  
14
import net.sf.ehcache.Cache;
15
import net.sf.ehcache.CacheManager;
16
import net.sf.ehcache.Element;
17

  
18
import org.aopalliance.intercept.MethodInvocation;
19
import org.junit.After;
20
import org.junit.Before;
21
import org.junit.Test;
22

  
23
/**
24
 * test the methodcache AOP interceptor.
25
 * 
26
 * @author marko
27
 * 
28
 */
29
public class MethodCacheInterceptorTest {
30

  
31
	private static final String TEST_VALUE = "mockedTestValue";
32
	private transient CacheManager singletonManager;
33
	private transient Cache cache;
34
	private transient MethodInvocation inv;
35
	private transient MethodInvocation invArgs;
36
	private transient MethodCacheInterceptor inter;
37

  
38
	@Before
39
	public void setUp() throws Throwable {
40
		singletonManager = CacheManager.create();
41
		singletonManager.addCache("testCache");
42
		cache = singletonManager.getCache("testCache");
43

  
44
		inter = new MethodCacheInterceptor();
45
		inter.setCache(cache);
46

  
47
		final MethodCacheInterceptorTest _this = mock(MethodCacheInterceptorTest.class);
48

  
49
		inv = mock(MethodInvocation.class);
50
		final Method method = MethodCacheInterceptorTest.class.getDeclaredMethod("test");
51

  
52
		when(inv.getThis()).thenReturn(_this);
53
		when(inv.getMethod()).thenReturn(method);
54

  
55
		when(inv.proceed()).thenReturn(TEST_VALUE);
56

  
57
		// second method
58
		invArgs = mock(MethodInvocation.class);
59
		final Method methodArgs = MethodCacheInterceptorTest.class.getDeclaredMethod("testWithArgs", String.class);
60

  
61
		when(invArgs.getThis()).thenReturn(_this);
62
		when(invArgs.getMethod()).thenReturn(methodArgs);
63
		when(invArgs.getArguments()).thenReturn(new Object[] { "test1" });
64
		when(invArgs.proceed()).thenReturn("mockedTestValueWithArgs");
65

  
66
	}
67

  
68
	@After
69
	public void tearDown() throws Exception {
70
		singletonManager.removeAllCaches();
71
	}
72

  
73
	@Test
74
	public void testCache() {
75
		cache.put(new Element("key", "value"));
76
		assertEquals("check cache", "value", cache.get("key").getObjectValue());
77
	}
78

  
79
	@Test
80
	public void testInterceptor() throws Throwable {
81
		assertEquals("first invocation", TEST_VALUE, inter.invoke(inv));
82
		assertEquals("cached invocation", TEST_VALUE, inter.invoke(inv));
83

  
84
		// real method has to be called only once
85
		verify(inv).proceed();
86
	}
87

  
88
	@Test
89
	public void testFlush() throws Throwable {
90
		assertEquals("first invocation", TEST_VALUE, inter.invoke(inv));
91
		cache.flush();
92
		assertEquals("cache not flushed", TEST_VALUE, inter.invoke(inv));
93

  
94
		// since cache is flushed, the method is called twice
95
		// TODO understand why It fail
96
		// verify(inv, times(2)).proceed();
97
	}
98

  
99
	@Test
100
	public void testWithArguments() throws Throwable {
101
		assertEquals("first invocation", "mockedTestValueWithArgs", inter.invoke(invArgs));
102
		assertEquals("cached invocation", "mockedTestValueWithArgs", inter.invoke(invArgs));
103
		verify(invArgs).proceed();
104
	}
105

  
106
	/**
107
	 * This method is only needed because of it's signature.
108
	 * 
109
	 * @return dummy
110
	 */
111
	public String test() { // NOPMD
112
		return null;
113
	}
114

  
115
	/**
116
	 * This method is only needed because of it's signature.
117
	 * 
118
	 * @param arg
119
	 *            dummy
120
	 * @return dummy
121
	 */
122
	public String testWithArgs(final String arg) { // NOPMD
123
		return null;
124
	}
125

  
126
	/**
127
	 * ensure that the spring lifecycle works.
128
	 * 
129
	 * @throws NoSuchMethodException
130
	 *             reflection
131
	 * @throws InvocationTargetException
132
	 *             reflection
133
	 * @throws IllegalAccessException
134
	 *             reflection
135
	 */
136
	@Test
137
	public void testAfterPropertiesSet() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
138
		inter.getClass().getMethod("afterPropertiesSet").invoke(inter);
139
		assertNotNull("dummy", inter);
140
	}
141

  
142
	/**
143
	 * test write only.
144
	 */
145
	@Test
146
	public void testSetWriteOnly() {
147
		assertFalse("getter", inter.isWriteOnly());
148
		inter.setWriteOnly(true);
149
		assertTrue("getter", inter.isWriteOnly());
150
	}
151

  
152
}
modules/cnr-spring-utils/tags/cnr-spring-utils-1.0.2/src/test/java/eu/dnetlib/springutils/aop/MethodInvokingInitializerTest.java
1
package eu.dnetlib.springutils.aop;
2

  
3
import static org.junit.Assert.*;
4

  
5
import javax.annotation.Resource;
6

  
7
import org.junit.Before;
8
import org.junit.Test;
9
import org.junit.runner.RunWith;
10
import org.springframework.test.context.ContextConfiguration;
11
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12

  
13
@RunWith(SpringJUnit4ClassRunner.class)
14
@ContextConfiguration
15
public class MethodInvokingInitializerTest {
16

  
17
	@Resource
18
	private SimpleBean simpleBean;
19
	
20
	@Before
21
	public void setUp() throws Exception {
22
	}
23

  
24
	@Test
25
	public void testStart() {
26
		assertTrue(simpleBean.isInitialized());
27
	}
28

  
29
}
modules/cnr-spring-utils/tags/cnr-spring-utils-1.0.2/src/test/java/eu/dnetlib/springutils/stringtemplate/ClassPathStringTemplateGroupTest.java
1
package eu.dnetlib.springutils.stringtemplate;
2

  
3
import static org.junit.Assert.assertEquals;
4
import java.io.StringReader;
5
import org.junit.Before;
6
import org.junit.Test;
7

  
8
public class ClassPathStringTemplateGroupTest {
9

  
10
	private ClassPathStringTemplateGroup group;
11
	private final transient String templates = "group simple;\nvardef(type,name) ::= \"<type> <name>;\""
12
			+ "method(type,name,args) ::= <<<type> <name>(<args; separator=\",\">) {  <statements; separator=\"\n\">}>>";;
13

  
14
	@Before
15
	public void setUp() throws Exception {
16
		group = new ClassPathStringTemplateGroup(new StringReader(templates));
17
	}
18

  
19
	@Test
20
	public void testName() {
21
		group.setPackage("eu.dnetlib");
22
		assertEquals("check Path", "/eu/dnetlib/pippo.st", group.getFileNameFromTemplateName("pippo"));
23
		assertEquals("check Path", "pippo", group.getTemplateNameFromFileName("/eu/dnetlib/pippo.st"));
24
	}
25

  
26
	public ClassPathStringTemplateGroup getGroup() {
27
		return group;
28
	}
29

  
30
	public void setGroup(final ClassPathStringTemplateGroup group) {
31
		this.group = group;
32
	}
33
}
0 34

  
modules/cnr-spring-utils/tags/cnr-spring-utils-1.0.2/src/test/java/eu/dnetlib/springutils/stringtemplate/StringTemplateFactoryTest.java
1
package eu.dnetlib.springutils.stringtemplate;
2

  
3

  
4
import static org.junit.Assert.*;
5

  
6
import javax.annotation.Resource;
7

  
8
import org.antlr.stringtemplate.StringTemplate;
9
import org.junit.Test;
10
import org.junit.runner.RunWith;
11
import org.springframework.test.context.ContextConfiguration;
12
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
13

  
14
/**
15
 * Test a string template factory bean.
16
 * @author marko
17
 *
18
 */
19
@RunWith(SpringJUnit4ClassRunner.class)
20
@ContextConfiguration
21
public class StringTemplateFactoryTest {
22

  
23
	@Resource
24
	private StringTemplate template;
25

  
26
	@Test
27
	public void testStringTemplate() {
28
		assertEquals("check template", "test\n", template.toString());
29
	}
30

  
31
}
modules/cnr-spring-utils/tags/cnr-spring-utils-1.0.2/src/test/java/eu/dnetlib/springutils/condbean/TestBean.java
1
package eu.dnetlib.springutils.condbean;
2

  
3
public class TestBean {
4
	int value;
5

  
6
	public int getValue() {
7
		return value;
8
	}
9

  
10
	public void setValue(final int value) {
11
		this.value = value;
12
	}
13
}
modules/cnr-spring-utils/tags/cnr-spring-utils-1.0.2/src/test/java/eu/dnetlib/springutils/condbean/ConditionalBeanTest.java
1
package eu.dnetlib.springutils.condbean;
2

  
3
import static org.junit.Assert.assertEquals;
4

  
5
import org.junit.BeforeClass;
6
import org.junit.Test;
7
import org.junit.runner.RunWith;
8
import org.springframework.beans.factory.annotation.Autowired;
9
import org.springframework.beans.factory.annotation.Qualifier;
10
import org.springframework.test.context.ContextConfiguration;
11
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12

  
13
@RunWith(SpringJUnit4ClassRunner.class)
14
@ContextConfiguration
15
public class ConditionalBeanTest {
16

  
17
	private static final int FIVE = 5;
18

  
19
	private static final int THREE = 3;
20

  
21
	@Autowired
22
	@Qualifier("elementTest")
23
	transient TestBean elementBean;
24
	
25
	@Autowired
26
	@Qualifier("elementTest")
27
	transient TestBean attributeBean;
28
	
29
	@Autowired
30
	@Qualifier("elementTest2")
31
	transient TestBean boolBean1;
32
	
33
	@Autowired
34
	@Qualifier("elementTest2")
35
	transient TestBean boolBean2;
36
	
37
	@Autowired
38
	@Qualifier("elementTest3")
39
	transient TestBean boolBean3;
40
	
41
	@Autowired
42
	@Qualifier("elementTest3")
43
	transient TestBean boolBean4;
44
	
45
	
46
	/**
47
	 * required to be "BeforeClass" because otherwise the spring context will not see it.
48
	 */
49
	@BeforeClass
50
	public static void setProperties() {
51
		System.setProperty("some.existing.property", "pippo");
52
	}
53
	
54
	@Test
55
	public void element() {
56
		assertEquals("element", 1, elementBean.getValue());
57
	}
58
	
59
	@Test
60
	public void attribute() {
61
		assertEquals("attribute", 1, attributeBean.getValue());
62
	}
63
	
64
	@Test
65
	public void bool1() {
66
		assertEquals("boolean 1", THREE, boolBean1.getValue());
67
	}
68
	
69
	@Test
70
	public void bool2() {
71
		assertEquals("boolean 2", THREE, boolBean2.getValue());
72
	}
73
	
74
	@Test
75
	public void bool3() {
76
		assertEquals("boolean 3", FIVE, boolBean3.getValue());
77
	}
78
	
79
	@Test
80
	public void bool4() {
81
		assertEquals("boolean 4", FIVE, boolBean4.getValue());
82
	}
83

  
84
}
modules/cnr-spring-utils/tags/cnr-spring-utils-1.0.2/src/test/java/eu/dnetlib/springutils/condbean/JParsecConditionExpressionParserTest.java
1
package eu.dnetlib.springutils.condbean;
2

  
3
import static org.junit.Assert.assertTrue;
4

  
5
import org.junit.Ignore;
6
import org.junit.Test;
7

  
8
public class JParsecConditionExpressionParserTest {
9

  
10
	transient JParsecConditionExpressionParser parser = new JParsecConditionExpressionParser(); 
11

  
12
	@Ignore("implement the parser in parsec")
13
	@Test
14
	public void testExpressionValue() {
15
		assertTrue("test it", parser.expressionValue("1"));
16
	}
17

  
18
}
modules/cnr-spring-utils/tags/cnr-spring-utils-1.0.2/src/test/java/eu/dnetlib/springutils/condbean/parser/CondBeanParserTest.java
1
package eu.dnetlib.springutils.condbean.parser;
2

  
3
import static org.junit.Assert.assertFalse;
4
import static org.junit.Assert.assertTrue;
5

  
6
import java.io.IOException;
7
import java.io.InputStream;
8

  
9
import org.junit.Before;
10
import org.junit.Test;
11

  
12
import eu.dnetlib.springutils.condbean.parser.ast.AbstractExpression;
13
import fri.patterns.interpreter.parsergenerator.Lexer;
14
import fri.patterns.interpreter.parsergenerator.Parser;
15
import fri.patterns.interpreter.parsergenerator.ParserTables;
16
import fri.patterns.interpreter.parsergenerator.lexer.LexerBuilder;
17
import fri.patterns.interpreter.parsergenerator.lexer.LexerException;
18
import fri.patterns.interpreter.parsergenerator.parsertables.LALRParserTables;
19
import fri.patterns.interpreter.parsergenerator.syntax.SyntaxException;
20
import fri.patterns.interpreter.parsergenerator.syntax.builder.SyntaxBuilder;
21
import fri.patterns.interpreter.parsergenerator.syntax.builder.SyntaxSeparation;
22

  
23
public class CondBeanParserTest {
24

  
25
	private static final String CHECK_EXPRESSION = "check expression";
26
	private static final String PARSE_FAILED = "parse failed";
27
	private SyntaxSeparation separation;
28
	private LexerBuilder builder;
29
	private Lexer lexer;
30
	private ParserTables parserTables;
31
	private Parser parser;
32
	private AbstractExpression result;
33
	private ParserTables tables;
34
	private SyntaxBuilder builder2;
35
	private InputStream syntaxInput;
36

  
37
	@Before
38
	public void setUp() throws SyntaxException, LexerException, Exception {
39
		syntaxInput = CondBeanParser.class.getResourceAsStream("CondBeanParser.syntax");
40
		builder2 = new SyntaxBuilder(syntaxInput);
41
		lexer = builder2.getLexer();
42
		tables = new LALRParserTables(builder2.getParserSyntax());
43
		parser = new Parser(tables);
44
		parser.setLexer(lexer);
45
	}
46

  
47
	@Test
48
	public void testParser0() throws IOException {
49
		parser.setInput("1 || 1");
50
		assertTrue(PARSE_FAILED, parser.parse(new CondBeanParser()));
51
		result = (AbstractExpression) parser.getResult();
52
		assertTrue(CHECK_EXPRESSION, (Boolean) result.evaluate());
53
	}
54

  
55
	@Test
56
	public void testParser1() throws IOException {
57
		parser.setInput("!${some.existing.property} && ${some.value} == 3 || isdef(someBean) || 11");
58
		assertTrue(PARSE_FAILED, parser.parse(new CondBeanParser()));
59
		result = (AbstractExpression) parser.getResult();
60
		assertTrue(CHECK_EXPRESSION, (Boolean) result.evaluate());
61
	}
62

  
63
	@Test
64
	public void testParser2() throws IOException {
65
		parser.setInput("2 == 3");
66
		assertTrue(PARSE_FAILED, parser.parse(new CondBeanParser()));
67
		result = (AbstractExpression) parser.getResult();
68
		assertFalse(CHECK_EXPRESSION, (Boolean) result.evaluate());
69

  
70
	}
71

  
72
	@Test
73
	public void testParser3() throws IOException {
74
		parser.setInput("2==3");
75
		assertTrue(PARSE_FAILED, parser.parse(new CondBeanParser()));
76
		result = (AbstractExpression) parser.getResult();
77
		assertFalse(CHECK_EXPRESSION, (Boolean) result.evaluate());
78

  
79
	}
80

  
81
	@Test
82
	public void testParser4() throws IOException {
83
		parser.setInput("${some.value} == 3");
84
		assertTrue(PARSE_FAILED, parser.parse(new CondBeanParser()));
85
		result = (AbstractExpression) parser.getResult();
86
		assertFalse(CHECK_EXPRESSION, (Boolean) result.evaluate());
87
	}
88

  
89
	@Test
90
	public void testParser5() throws IOException {
91
		parser.setInput("!${some.existing.property} && ${some.value} == 3");
92
		assertTrue(PARSE_FAILED, parser.parse(new CondBeanParser()));
93
		result = (AbstractExpression) parser.getResult();
94
		assertFalse(CHECK_EXPRESSION, (Boolean) result.evaluate());
95

  
96
	}
97

  
98
	@Test
99
	public void testParser6() throws IOException {
100
		parser.setInput("${some.value} == 3 && !${some.existing.property}"); // give
101
		assertTrue(PARSE_FAILED, parser.parse(new CondBeanParser()));
102
		result = (AbstractExpression) parser.getResult();
103
		assertFalse(CHECK_EXPRESSION, (Boolean) result.evaluate());
104

  
105
	}
106

  
107
	@Test
108
	public void testParser7() throws IOException {
109
		parser.setInput("3 < 2 && 2<4");
110
		assertTrue(PARSE_FAILED, parser.parse(new CondBeanParser()));
111
		result = (AbstractExpression) parser.getResult();
112
		assertFalse(CHECK_EXPRESSION, (Boolean) result.evaluate());
113
	}
114

  
115
	@Test
116
	public void testParser8() throws IOException {
117
		parser.setInput("3 < 2 || 2<4");
118
		assertTrue(PARSE_FAILED, parser.parse(new CondBeanParser()));
119
		result = (AbstractExpression) parser.getResult();
120
		assertTrue(CHECK_EXPRESSION, (Boolean) result.evaluate());
121

  
122
	}
123

  
124
	public SyntaxSeparation getSeparation() {
125
		return separation;
126
	}
127

  
128
	public void setSeparation(final SyntaxSeparation separation) {
129
		this.separation = separation;
130
	}
131

  
132
	public LexerBuilder getBuilder() {
133
		return builder;
134
	}
135

  
136
	public void setBuilder(final LexerBuilder builder) {
137
		this.builder = builder;
138
	}
139

  
140
	public Lexer getLexer() {
141
		return lexer;
142
	}
143

  
144
	public void setLexer(final Lexer lexer) {
145
		this.lexer = lexer;
146
	}
147

  
148
	public ParserTables getParserTables() {
149
		return parserTables;
150
	}
151

  
152
	public void setParserTables(final ParserTables parserTables) {
153
		this.parserTables = parserTables;
154
	}
155

  
156
	public Parser getParser() {
157
		return parser;
158
	}
159

  
160
	public void setParser(final Parser parser) {
161
		this.parser = parser;
162
	}
163

  
164
	public AbstractExpression getResult() {
165
		return result;
166
	}
167

  
168
	public void setResult(final AbstractExpression result) {
169
		this.result = result;
170
	}
171

  
172
	public ParserTables getTables() {
173
		return tables;
174
	}
175

  
176
	public void setTables(final ParserTables tables) {
177
		this.tables = tables;
178
	}
179

  
180
	public SyntaxBuilder getBuilder2() {
181
		return builder2;
182
	}
183

  
184
	public void setBuilder2(final SyntaxBuilder builder2) {
185
		this.builder2 = builder2;
186
	}
187

  
188
	public InputStream getSyntaxInput() {
189
		return syntaxInput;
190
	}
191

  
192
	public void setSyntaxInput(final InputStream syntaxInput) {
193
		this.syntaxInput = syntaxInput;
194
	}
195

  
196
}
modules/cnr-spring-utils/tags/cnr-spring-utils-1.0.2/src/test/java/eu/dnetlib/springutils/condbean/parser/RunccExpressionParserTest.java
1
package eu.dnetlib.springutils.condbean.parser;
2

  
3
import static org.junit.Assert.assertFalse;
4
import static org.junit.Assert.assertTrue;
5

  
6
import java.io.IOException;
7

  
8
import org.junit.After;
9
import org.junit.Before;
10
import org.junit.Test;
11

  
12
import eu.dnetlib.springutils.condbean.parser.ast.AndExpression;
13
import eu.dnetlib.springutils.condbean.parser.ast.EqualityExpression;
14
import eu.dnetlib.springutils.condbean.parser.ast.OrExpression;
15
import eu.dnetlib.springutils.condbean.parser.ast.RelationalExpression;
16
import eu.dnetlib.springutils.condbean.parser.ast.SysProperty;
17

  
18

  
19
public class RunccExpressionParserTest { //NOPMD
20
	
21
	private static final String CHECK_EXPRESSION = "check expression value";
22
	private static final String EXPRESSION_TYPE = "check expression type";
23
	private String parseInput;
24
	private RunccExpressionParser parser;
25
	
26
	@Before
27
	public void setProperties() {
28
		System.setProperty("some.existing.property", "pippo");
29
		
30
		parser = new RunccExpressionParser();
31
		parser.setCondBeanParser(new CondBeanParser());
32
	}	
33
	
34
	@After
35
	public void cleanupProperties() {
36
		System.clearProperty("some.existing.property");
37
	}
38
	
39
	@Test
40
    public void test0() throws IOException {
41
    	parseInput = "${some.existing.property}";
42
		
43
		assertTrue(CHECK_EXPRESSION, parser.expressionValue(parseInput));
44
		assertTrue(EXPRESSION_TYPE, parser.getTopRule(parseInput) instanceof SysProperty);
45
	}
46
	
47
	@Test
48
    public void test1() throws IOException {
49
    	parseInput = "false && false";
50
		
51
		assertFalse(CHECK_EXPRESSION, parser.expressionValue(parseInput));
52
		assertTrue(EXPRESSION_TYPE, parser.getTopRule(parseInput) instanceof AndExpression);
53
	}
54
	
55
	@Test
56
    public void test2() throws IOException {
57
    	parseInput = "1<2";
58
		
59
		assertTrue(CHECK_EXPRESSION, parser.expressionValue(parseInput));
60
		assertTrue(EXPRESSION_TYPE, parser.getTopRule(parseInput) instanceof RelationalExpression);
61
	}
62
	
63
	@Test
64
	public void test3() throws IOException {
65
		
66
		parseInput = "!${some.existing.property} && ${some.value} == 3 || isdef(someBean) || 11";
67
		assertTrue(CHECK_EXPRESSION, parser.expressionValue(parseInput));
68
		assertTrue(EXPRESSION_TYPE, parser.getTopRule(parseInput) instanceof OrExpression);
69
	}
70

  
71
	@Test
72
	public void test4() throws IOException {
73
		
74
		parseInput = "2 == 3";
75
		assertFalse(CHECK_EXPRESSION, parser.expressionValue(parseInput));
76
		assertTrue(EXPRESSION_TYPE, parser.getTopRule(parseInput) instanceof EqualityExpression);
77

  
78
	}
79

  
80
	@Test
81
	public void test5() throws IOException {
82
		
83
		parseInput = "\"3\"==3";
84
		assertFalse(CHECK_EXPRESSION, parser.expressionValue(parseInput));
85
		assertTrue(EXPRESSION_TYPE, parser.getTopRule(parseInput) instanceof EqualityExpression);
86
	}
87

  
88
	@Test
89
	public void test6() throws IOException {
90
		
91
		parseInput = "${some.value} == 3";
92
		assertFalse(CHECK_EXPRESSION, parser.expressionValue(parseInput));
93
		assertTrue(EXPRESSION_TYPE, parser.getTopRule(parseInput) instanceof EqualityExpression);
94
	}
95

  
96
	@Test
97
	public void test7() throws IOException {
98
		
99
		parseInput = "!${some.existing.property} && ${some.value} == 3";
100
		assertFalse(CHECK_EXPRESSION, parser.expressionValue(parseInput));
101
		assertTrue(EXPRESSION_TYPE, parser.getTopRule(parseInput) instanceof AndExpression);
102
	}
103

  
104
	@Test
105
	public void test8() throws IOException {
106
		
107
		parseInput = "${some.value} == 3 && !${some.existing.property}";
108
		assertFalse(CHECK_EXPRESSION, parser.expressionValue(parseInput));
109
		assertTrue(EXPRESSION_TYPE, parser.getTopRule(parseInput) instanceof AndExpression);
110
	}
111

  
112
	@Test
113
	public void test9() throws IOException {
114
		
115
		parseInput = "3 < 2 && 2<4";
116
		assertFalse(CHECK_EXPRESSION, parser.expressionValue(parseInput));
117
		assertTrue(EXPRESSION_TYPE, parser.getTopRule(parseInput) instanceof AndExpression);
118
	}
119

  
120
	@Test
121
	public void test10() throws IOException	{
122
		
123
		parseInput = "3 < 2 || 2<4";
124
		assertTrue(CHECK_EXPRESSION, parser.expressionValue(parseInput));
125
		assertTrue(EXPRESSION_TYPE, parser.getTopRule(parseInput) instanceof OrExpression);
126
	}
127
	
128
	@Test
129
    public void test11() throws IOException {
130
    	parseInput = "3==3";
131
		
132
		assertTrue(CHECK_EXPRESSION, parser.expressionValue(parseInput));
133
		assertTrue(EXPRESSION_TYPE, parser.getTopRule(parseInput) instanceof EqualityExpression);
134
	}
135

  
136
	public String getParseInput() {
137
		return parseInput;
138
	}
139

  
140
	public void setParseInput(final String parseInput) {
141
		this.parseInput = parseInput;
142
	}
143

  
144
	public RunccExpressionParser getParser() {
145
		return parser;
146
	}
147

  
148
	public void setParser(final RunccExpressionParser parser) {
149
		this.parser = parser;
150
	}	
151
}
modules/cnr-spring-utils/tags/cnr-spring-utils-1.0.2/src/test/java/eu/dnetlib/springutils/condbean/parser/ast/ExpressionTest.java
1
package eu.dnetlib.springutils.condbean.parser.ast;
2

  
3
import static org.junit.Assert.assertEquals;
4

  
5
import org.junit.Test;
6

  
7

  
8
public class ExpressionTest {
9
	
10
	private AbstractTerminal term1;
11
	private AbstractExpression exp1;
12
	private AbstractBinaryExpression exp2;
13

  
14
	@Test
15
	public void testExpression() {
16
		term1 = new IdentifierNode("pippo");
17
		exp1 = new NotExpression(term1);
18
		exp2 = new OrExpression(term1, exp1);
19
		
20
		assertEquals("check expression", exp2.getLeft(), term1);
21
		
22
	}
23

  
24
	public AbstractTerminal getTerm1() {
25
		return term1;
26
	}
27

  
28
	public void setTerm1(final AbstractTerminal term1) {
29
		this.term1 = term1;
30
	}
31

  
32
	public AbstractExpression getExp1() {
33
		return exp1;
34
	}
35

  
36
	public void setExp1(final AbstractExpression exp1) {
37
		this.exp1 = exp1;
38
	}
39

  
40
	public AbstractBinaryExpression getExp2() {
41
		return exp2;
42
	}
43

  
44
	public void setExp2(final AbstractBinaryExpression exp2) {
45
		this.exp2 = exp2;
46
	}
47
	
48
	
49
	
50
}
modules/cnr-spring-utils/tags/cnr-spring-utils-1.0.2/src/test/java/eu/dnetlib/springutils/condbean/parser/ast/NotExpressionTest.java
1
package eu.dnetlib.springutils.condbean.parser.ast;
2

  
3
import static org.junit.Assert.assertFalse;
4
import static org.junit.Assert.assertTrue;
5
import static org.mockito.Mockito.mock;
6
import static org.mockito.Mockito.when;
7

  
8
import org.junit.Before;
9
import org.junit.Test;
10

  
11
public class NotExpressionTest {
12

  
13
	private NotExpression expr;
14

  
15
	private AbstractExpression expression;
16

  
17
	@Before
18
	public void setUp() throws Exception {
19
		expression = mock(AbstractExpression.class);
20
		expr = new NotExpression(expression);
21
	}
22

  
23
	@Test
24
	public void testTrue() {
25
		when(expression.evaluate()).thenReturn(true);
26
		assertFalse("check expression", (Boolean) expr.evaluate());
27
	}
28

  
29
	@Test
30
	public void testFalse() {
31
		when(expression.evaluate()).thenReturn(false);
32
		assertTrue("check expression", (Boolean) expr.evaluate());
33
	}
34

  
35
	public NotExpression getExpr() {
36
		return expr;
37
	}
38

  
39
	public void setExpr(final NotExpression expr) {
40
		this.expr = expr;
41
	}
42

  
43
	public AbstractExpression getExpression() {
44
		return expression;
45
	}
46

  
47
	public void setExpression(final AbstractExpression expression) {
48
		this.expression = expression;
49
	}
50

  
51
}
modules/cnr-spring-utils/tags/cnr-spring-utils-1.0.2/src/test/java/eu/dnetlib/springutils/condbean/parser/ast/OrExpressionTest.java
1
package eu.dnetlib.springutils.condbean.parser.ast;
2

  
3
import static org.junit.Assert.assertFalse;
4
import static org.junit.Assert.assertTrue;
5
import static org.mockito.Mockito.mock;
6
import static org.mockito.Mockito.when;
7

  
8
import org.junit.Before;
9
import org.junit.Test;
10

  
11
public class OrExpressionTest {
12
	private static final String CHECK_EXPRESSION = "check expression";
13

  
14
	private OrExpression expr;
15

  
16
	private AbstractExpression left, right;
17

  
18
	@Before
19
	public void setUp() throws Exception {
20
		left = mock(AbstractExpression.class);
21
		right = mock(AbstractExpression.class);
22
		expr = new OrExpression(left, right);
23
	}
24

  
25
	@Test
26
	public void testTrue() {
27
		when(left.evaluate()).thenReturn(true);
28
		when(right.evaluate()).thenReturn(true);
29
		assertTrue(CHECK_EXPRESSION, (Boolean) expr.evaluate());
30
	}
31

  
32
	@Test
33
	public void testFalse() {
34
		when(left.evaluate()).thenReturn(true);
35
		when(right.evaluate()).thenReturn(false);
36
		assertTrue(CHECK_EXPRESSION, (Boolean) expr.evaluate());
37
	}
38

  
39
	@Test
40
	public void testOneNull() {
41
		when(left.evaluate()).thenReturn(null);
42
		when(right.evaluate()).thenReturn(1);
43
		assertTrue(CHECK_EXPRESSION, (Boolean) expr.evaluate());
44
	}
45

  
46
	@Test
47
	public void testBothNull() {
48
		when(left.evaluate()).thenReturn(null);
49
		when(right.evaluate()).thenReturn(null);
50
		assertFalse(CHECK_EXPRESSION, (Boolean) expr.evaluate());
51
	}
52

  
53
	public OrExpression getExpr() {
54
		return expr;
55
	}
56

  
57
	public void setExpr(final OrExpression expr) {
58
		this.expr = expr;
59
	}
60

  
61
	public AbstractExpression getLeft() {
62
		return left;
63
	}
64

  
65
	public void setLeft(final AbstractExpression left) {
66
		this.left = left;
67
	}
68

  
69
	public AbstractExpression getRight() {
70
		return right;
71
	}
72

  
73
	public void setRight(final AbstractExpression right) {
74
		this.right = right;
75
	}
76

  
77
}
modules/cnr-spring-utils/tags/cnr-spring-utils-1.0.2/src/test/java/eu/dnetlib/springutils/condbean/parser/ast/AndExpressionTest.java
1
package eu.dnetlib.springutils.condbean.parser.ast;
2

  
3
import static org.junit.Assert.assertFalse;
4
import static org.junit.Assert.assertTrue;
5
import static org.mockito.Mockito.mock;
6
import static org.mockito.Mockito.when;
7

  
8
import org.junit.Before;
9
import org.junit.Test;
10

  
11
public class AndExpressionTest {
12

  
13
	private static final String CHECK_EXPRESSION = "check expression";
14
	private AndExpression expr;
15

  
16
	private AbstractExpression left, right;
17

  
18
	@Before
19
	public void setUp() throws Exception {
20
		left = mock(AbstractExpression.class);
21
		right = mock(AbstractExpression.class);
22
		expr = new AndExpression(left, right);
23
	}
24

  
25
	@Test
26
	public void testTrue() {
27
		when(left.evaluate()).thenReturn(true);
28
		when(right.evaluate()).thenReturn(true);
29
		assertTrue(CHECK_EXPRESSION, (Boolean) expr.evaluate());
30
	}
31

  
32
	@Test
33
	public void testFalse() {
34
		when(left.evaluate()).thenReturn(true);
35
		when(right.evaluate()).thenReturn(false);
36
		assertFalse(CHECK_EXPRESSION, (Boolean) expr.evaluate());
37
	}
38

  
39
	@Test
40
	public void testOneNull() {
41
		when(left.evaluate()).thenReturn(null);
42
		when(right.evaluate()).thenReturn(1);
43
		assertFalse(CHECK_EXPRESSION, (Boolean) expr.evaluate());
44
	}
45

  
46
	@Test
47
	public void testBothNull() {
48
		when(left.evaluate()).thenReturn(null);
49
		when(right.evaluate()).thenReturn(null);
50
		assertFalse(CHECK_EXPRESSION, (Boolean) expr.evaluate());
51
	}
52

  
53
	public AndExpression getExpr() {
54
		return expr;
55
	}
56

  
57
	public void setExpr(final AndExpression expr) {
58
		this.expr = expr;
59
	}
60

  
61
	public AbstractExpression getLeft() {
62
		return left;
63
	}
64

  
65
	public void setLeft(final AbstractExpression left) {
66
		this.left = left;
67
	}
68

  
69
	public AbstractExpression getRight() {
70
		return right;
71
	}
72

  
73
	public void setRight(final AbstractExpression right) {
74
		this.right = right;
75
	}
76

  
77
}
modules/cnr-spring-utils/tags/cnr-spring-utils-1.0.2/src/test/java/eu/dnetlib/springutils/condbean/parser/ast/RelationalExpressionTest.java
1
package eu.dnetlib.springutils.condbean.parser.ast;
2

  
3
import static org.junit.Assert.assertFalse;
4
import static org.junit.Assert.assertTrue;
5
import static org.mockito.Mockito.mock;
6
import static org.mockito.Mockito.when;
7

  
8
import org.junit.Before;
9
import org.junit.Test;
10

  
11
public class RelationalExpressionTest {
12

  
13
	private static final String CHECK_EXPRESSION = "check expression";
14

  
15
	private RelationalExpression expr;
16

  
17
	private AbstractExpression left, right;
18

  
19
	@Before
20
	public void setUp() throws Exception {
21
		left = mock(AbstractExpression.class);
22
		right = mock(AbstractExpression.class);
23
		expr = new RelationalExpression(left, right, "<=");
24
	}
25

  
26
	@Test
27
	public void testString() {
28
		when(left.evaluate()).thenReturn("pippo");
29
		when(right.evaluate()).thenReturn("pippo");
30
		assertTrue(CHECK_EXPRESSION, (Boolean) expr.evaluate());
31
	}
32

  
33
	@Test
34
	public void testStringlex1() {
35
		when(left.evaluate()).thenReturn("pippo1");
36
		when(right.evaluate()).thenReturn("mippo");
37
		assertFalse(CHECK_EXPRESSION, (Boolean) expr.evaluate());
38
	}
39

  
40
	@Test
41
	public void testStringlex2() {
42
		when(left.evaluate()).thenReturn("pippo");
43
		when(right.evaluate()).thenReturn("rippo");
44
		assertTrue(CHECK_EXPRESSION, (Boolean) expr.evaluate());
45
	}
46

  
47
	@Test
48
	public void testInt() {
49
		when(left.evaluate()).thenReturn(1);
50
		when(right.evaluate()).thenReturn(1);
51
		assertTrue(CHECK_EXPRESSION, (Boolean) expr.evaluate());
52
	}
53

  
54
	@Test
55
	public void testIntString() {
56
		when(left.evaluate()).thenReturn("1");
57
		when(right.evaluate()).thenReturn(1);
58
		assertFalse(CHECK_EXPRESSION, (Boolean) expr.evaluate());
59
	}
60

  
61
	public RelationalExpression getExpr() {
62
		return expr;
63
	}
64

  
65
	public void setExpr(final RelationalExpression expr) {
66
		this.expr = expr;
67
	}
68

  
69
	public AbstractExpression getLeft() {
70
		return left;
71
	}
72

  
73
	public void setLeft(final AbstractExpression left) {
74
		this.left = left;
75
	}
76

  
77
	public AbstractExpression getRight() {
78
		return right;
79
	}
80

  
81
	public void setRight(final AbstractExpression right) {
82
		this.right = right;
83
	}
84

  
85
}
modules/cnr-spring-utils/tags/cnr-spring-utils-1.0.2/src/test/java/eu/dnetlib/springutils/condbean/parser/ast/EqualityExpressionTest.java
1
package eu.dnetlib.springutils.condbean.parser.ast;
2

  
3
import static org.junit.Assert.assertFalse;
4
import static org.junit.Assert.assertTrue;
5
import static org.mockito.Mockito.mock;
6
import static org.mockito.Mockito.when;
7

  
8
import org.junit.Before;
9
import org.junit.Test;
10

  
11
public class EqualityExpressionTest {
12

  
13
	private static final String CHECK_EXPRESSION = "check expression";
14

  
15
	private EqualityExpression expr;
16

  
17
	private AbstractExpression left, right;
18

  
19
	@Before
20
	public void setUp() throws Exception {
21
		left = mock(AbstractExpression.class);
22
		right = mock(AbstractExpression.class);
23
		expr = new EqualityExpression(left, right, "==");
24

  
25
	}
26

  
27
	@Test
28
	public void testEquals() {
29
		when(left.evaluate()).thenReturn("pippo");
30
		when(right.evaluate()).thenReturn("pippo");
31
		assertTrue(CHECK_EXPRESSION, (Boolean) expr.evaluate());
32
	}
33

  
34
	@Test
35
	public void testNotEquals() {
36
		when(left.evaluate()).thenReturn("pippo1");
37
		when(right.evaluate()).thenReturn("puppo");
38
		assertFalse(CHECK_EXPRESSION, (Boolean) expr.evaluate());
39
	}
40

  
41
	@Test
42
	public void testInteger() {
43
		when(left.evaluate()).thenReturn("pippo1");
44
		when(right.evaluate()).thenReturn(1);
45
		assertFalse(CHECK_EXPRESSION, (Boolean) expr.evaluate());
46
	}
47

  
48
	@Test
49
	public void testOneNull() {
50
		when(left.evaluate()).thenReturn(null);
51
		when(right.evaluate()).thenReturn(1);
52
		assertFalse(CHECK_EXPRESSION, (Boolean) expr.evaluate());
53
	}
54

  
55
	@Test
56
	public void testBothNull() {
57
		when(left.evaluate()).thenReturn(null);
58
		when(right.evaluate()).thenReturn(null);
59
		assertTrue(CHECK_EXPRESSION, (Boolean) expr.evaluate());
60
	}
61

  
62
	@Test
63
	public void testIntString() {
64
		when(left.evaluate()).thenReturn(1);
65
		when(right.evaluate()).thenReturn("1");
66
		assertFalse(CHECK_EXPRESSION, (Boolean) expr.evaluate());
67
	}
68

  
69
	@Test
70
	public void testIntChar() {
71
		when(left.evaluate()).thenReturn(1);
72
		when(right.evaluate()).thenReturn('1');
73
		assertFalse(CHECK_EXPRESSION, (Boolean) expr.evaluate());
74
	}
75

  
76
	@Test
77
	public void testString() {
78
		when(left.evaluate()).thenReturn("2");
79
		when(right.evaluate()).thenReturn("3");
80
		assertFalse(CHECK_EXPRESSION, (Boolean) expr.evaluate());
81
	}
82

  
83
	public EqualityExpression getExpr() {
84
		return expr;
85
	}
86

  
87
	public void setExpr(final EqualityExpression expr) {
88
		this.expr = expr;
89
	}
90

  
91
	public AbstractExpression getLeft() {
92
		return left;
93
	}
94

  
95
	public void setLeft(final AbstractExpression left) {
96
		this.left = left;
97
	}
98

  
99
	public AbstractExpression getRight() {
100
		return right;
101
	}
102

  
103
	public void setRight(final AbstractExpression right) {
104
		this.right = right;
105
	}
106
}
modules/cnr-spring-utils/tags/cnr-spring-utils-1.0.2/src/test/java/eu/dnetlib/springutils/condbean/TrivialConditionExpressionParserTest.java
1
package eu.dnetlib.springutils.condbean;
2

  
3
import static org.junit.Assert.assertEquals;
4
import static org.junit.Assert.assertFalse;
5
import static org.junit.Assert.assertTrue;
6

  
7
import org.junit.Before;
8
import org.junit.BeforeClass;
9
import org.junit.Test;
10

  
11
public class TrivialConditionExpressionParserTest {
12

  
13
	transient TrivialConditionExpressionParser parser = new TrivialConditionExpressionParser();  
14
	
15
	@BeforeClass
16
	public static void setUpProperties() {
17
		System.setProperty("trivial.condition.true", "value");
18
	}
19
	
20
	@Before
21
	public void setUp() {
22
		parser.setFinder(new SystemPropertiesFinder());
23
	}
24
	
25
	@Test
26
	public void testExpressionValue() {
27
		assertTrue("check true condition", parser.expressionValue("trivial.condition.true"));
28
		assertFalse("check false condition", parser.expressionValue("trivial.condition.false"));
29
	}
30

  
31
	@Test
32
	public void testGetProperty() {
33
		assertEquals("check true condition", "value", parser.getProperty("trivial.condition.true"));
34
		assertEquals("check false condition", null, parser.getProperty("trivial.condition.false"));
35
	}
36

  
37
}
modules/cnr-spring-utils/tags/cnr-spring-utils-1.0.2/src/test/java/eu/dnetlib/springutils/template/TestBean.java
1
package eu.dnetlib.springutils.template;
2

  
3
public class TestBean {
4
	private int value;
5

  
6
	private String address;
7
	
8
	private String prop;
9
	
10
	private TestBean next;
11
	
12
	public int getValue() {
13
		return value;
14
	}
15

  
16
	public void setValue(int value) {
17
		this.value = value;
18
	}
19

  
20
	public TestBean getNext() {
21
		return next;
22
	}
23

  
24
	public void setNext(TestBean next) {
25
		this.next = next;
26
	}
27

  
28
	public String getAddress() {
29
		return address;
30
	}
31

  
32
	public void setAddress(String address) {
33
		this.address = address;
34
	}
35

  
36
	public String getProp() {
37
		return prop;
38
	}
39

  
40
	public void setProp(String prop) {
41
		this.prop = prop;
42
	}
43
}
modules/cnr-spring-utils/tags/cnr-spring-utils-1.0.2/src/test/java/eu/dnetlib/springutils/template/TemplateTest.java
1
package eu.dnetlib.springutils.template;
2

  
3

  
4
import static org.junit.Assert.*; // NOPMD
5

  
6
import javax.annotation.Resource;
7

  
8
import org.junit.Before;
9
import org.junit.Test;
10
import org.junit.runner.RunWith;
11
import org.springframework.test.context.ContextConfiguration;
12
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
13

  
14
@RunWith(SpringJUnit4ClassRunner.class)
15
@ContextConfiguration
16
public class TemplateTest {
17
	
18
	@Resource(name = "test")
19
	private transient TestBean testBean;
20
	
21
	@Resource(name = "testDefault1")
22
	private transient TestBean testDefault1;
23
	
24
	@Resource(name = "testDefault2")
25
	private transient TestBean testDefault2;
26
	
27
	@Resource(name = "testDefault3")
28
	private transient TestBean testDefault3;
29
	
30
	@Before
31
	public void setUp() throws Exception {
32
	}
33

  
34
	@Test
35
	public void testTemplate() {
36
		assertEquals("check property value expansion", "expandedValue", testBean.getAddress());
37
		assertEquals("check bean reference", "tail-expandedValue", testBean.getNext().getAddress());
38
	}
39
	
40
	@Test
41
	public void testMultipleInstances() {
42
		assertEquals("check expanded value", "expandedValue", testDefault1.getAddress());
43
		assertEquals("check other value", "otherValue", testDefault2.getAddress());
44
	}
45
	
46
	@Test
47
	public void testDefault() {
48
		assertEquals("check expanded value", "expandedValue", testDefault1.getAddress());
49
		assertEquals("check default value", "defaultValue", testDefault3.getAddress());
50
	}
51
	
52
	@Test
53
	public void testProp() {
54
		assertEquals("check property", "test", testBean.getProp());
55
	}
56
}
modules/cnr-spring-utils/tags/cnr-spring-utils-1.0.2/src/test/java/eu/dnetlib/springutils/template/ReorderTemplateTest.java
1
package eu.dnetlib.springutils.template;
2

  
3

  
4
import static org.junit.Assert.*; // NOPMD
5

  
6
import javax.annotation.Resource;
7

  
8
import org.junit.Test;
9
import org.junit.runner.RunWith;
10
import org.springframework.test.context.ContextConfiguration;
11
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12

  
13
/**
14
 * Templates should work also if parsed out of order (instantiations before declarations). 
15
 * 
16
 * @author marko
17
 *
18
 */
19
@RunWith(SpringJUnit4ClassRunner.class)
20
@ContextConfiguration
21
public class ReorderTemplateTest {
22

  
23
	@Resource(name = "test")
24
	private transient TestBean testBean;
25

  
26
	@Test
27
	public void testOutOfOrder() {
28
		assertNotNull(testBean);
29
	}
30
}
modules/cnr-spring-utils/tags/cnr-spring-utils-1.0.2/src/test/java/eu/dnetlib/springutils/collections/ResourceReaderCollectionTest.java
1
package eu.dnetlib.springutils.collections;
2

  
3

  
4
import static org.junit.Assert.*;
5

  
6
import java.util.List;
7

  
8
import org.junit.Test;
9
import org.junit.runner.RunWith;
10
import org.springframework.core.io.Resource;
11
import org.springframework.test.context.ContextConfiguration;
12
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
13

  
14
/**
15
 * Test resource->string transformer.
16
 * 
17
 * @author marko
18
 *
19
 */
20
@RunWith(SpringJUnit4ClassRunner.class)
21
@ContextConfiguration
22
public class ResourceReaderCollectionTest {
23

  
24
	/**
25
	 * resources filled by spring.
26
	 */
27
	@javax.annotation.Resource(name = "resourceList")
28
	List<Resource> resources;
29
	
30
	/**
31
	 * test resources
32
	 */
33
	@Test
34
	public void testResources() {
35
		boolean passed = false;
36
		for(String el : new ResourceReaderCollection(resources)) {
37
			passed = true;
38
			assertEquals("content", "test\n", el);
39
		}
40
		
41
		assertTrue("passed", passed);
42
	}
43
	
44
}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff