use of org.olat.course.run.userview.UserCourseEnvironment in project OpenOLAT by OpenOLAT.
the class ConditionTest method getUserDemoCourseEnvironment.
private UserCourseEnvironment getUserDemoCourseEnvironment() {
Identity author = JunitTestHelper.createAndPersistIdentityAsUser("junit_auth-" + UUID.randomUUID().toString());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("condition");
Roles roles = new Roles(false, false, false, false, false, false, false);
RepositoryEntry re = JunitTestHelper.deployDemoCourse(author);
ICourse course = CourseFactory.loadCourse(re);
IdentityEnvironment identityEnv = new IdentityEnvironment(id, roles);
UserCourseEnvironment uce = new UserCourseEnvironmentImpl(identityEnv, course.getCourseEnvironment());
return uce;
}
use of org.olat.course.run.userview.UserCourseEnvironment in project OpenOLAT by OpenOLAT.
the class ConditionTest method simpleExpresion.
@Test
public void simpleExpresion() throws Exception {
UserCourseEnvironment uce = getUserDemoCourseEnvironment();
ConditionInterpreter interpreter = new ConditionInterpreter(uce);
String condition = "now >= date(\"03.07.2012 08:26\")";
boolean result = interpreter.evaluateCondition(condition);
Assert.assertTrue(result);
Collection<Object> tokens = interpreter.getParsedTokens(condition);
Assert.assertNotNull(tokens);
Assert.assertFalse(tokens.isEmpty());
}
use of org.olat.course.run.userview.UserCourseEnvironment in project OpenOLAT by OpenOLAT.
the class ConditionTest method syntaxProposal.
@Test
public void syntaxProposal() throws Exception {
UserCourseEnvironment uce = getUserDemoCourseEnvironment();
ConditionInterpreter interpreter = new ConditionInterpreter(uce);
String condition = "inLearningGroup(\"16872486<Rule1Group1>\")";
boolean result = interpreter.evaluateCondition(condition);
Assert.assertFalse(result);
Collection<Object> tokens = interpreter.getParsedTokens(condition);
Assert.assertNotNull(tokens);
Assert.assertFalse(tokens.isEmpty());
for (Object token : tokens) {
System.out.println(token.getClass().getName());
}
}
use of org.olat.course.run.userview.UserCourseEnvironment in project OpenOLAT by OpenOLAT.
the class ConditionTest method testHasNotPropertyFunction.
@Test
public void testHasNotPropertyFunction() throws Exception {
UserCourseEnvironment uce = getUserDemoCourseEnvironment();
ConditionInterpreter interpreter = new ConditionInterpreter(uce);
String condition = "hasNotUserProperty(\"firstName\", \"firstcondition\")";
boolean result = interpreter.evaluateCondition(condition);
Assert.assertFalse(condition, result);
condition = "hasNotUserProperty(\"firstName\", \"\")";
result = interpreter.evaluateCondition(condition);
Assert.assertFalse(condition, result);
condition = "hasNotUserProperty(\"firstName\")";
result = interpreter.evaluateCondition(condition);
Assert.assertFalse(condition, result);
condition = "hasNotUserProperty(\"firstName\", \"firstcondition\", \"firstcondition\")";
result = interpreter.evaluateCondition(condition);
Assert.assertFalse(condition, result);
condition = "hasNotUserProperty(\"firstName\", \"someThing\")";
result = interpreter.evaluateCondition(condition);
Assert.assertTrue(condition, result);
condition = "hasNotUserProperty(\"firstName\", \"firstconditiongugus\")";
result = interpreter.evaluateCondition(condition);
Assert.assertTrue(condition, result);
condition = "hasNotUserProperty(\"firstName\", \"gugusfirstcondition\")";
result = interpreter.evaluateCondition(condition);
Assert.assertTrue(condition, result);
condition = "hasNotUserProperty(\"lastName\", \"firstcondition\")";
result = interpreter.evaluateCondition(condition);
Assert.assertTrue(condition, result);
}
use of org.olat.course.run.userview.UserCourseEnvironment in project OpenOLAT by OpenOLAT.
the class ConditionTest method testHasPropertyFunction.
@Test
public void testHasPropertyFunction() throws Exception {
UserCourseEnvironment uce = getUserDemoCourseEnvironment();
ConditionInterpreter interpreter = new ConditionInterpreter(uce);
String condition = "hasUserProperty(\"firstName\", \"firstcondition\")";
boolean result = interpreter.evaluateCondition(condition);
Assert.assertTrue(condition, result);
condition = "hasUserProperty(\"firstName\", \"\")";
result = interpreter.evaluateCondition(condition);
Assert.assertFalse(condition, result);
condition = "hasUserProperty(\"firstName\", \"firstcondition \")";
result = interpreter.evaluateCondition(condition);
Assert.assertFalse(condition, result);
condition = "hasUserProperty(\"firstName\", \" firstcondition\")";
result = interpreter.evaluateCondition(condition);
Assert.assertFalse(condition, result);
condition = "hasUserProperty(\"firstName\")";
result = interpreter.evaluateCondition(condition);
Assert.assertFalse(condition, result);
condition = "hasUserProperty(\"firstName\", \"firstcondition\", \"firstcondition\")";
result = interpreter.evaluateCondition(condition);
Assert.assertFalse(condition, result);
condition = "hasUserProperty(\"firstName\", \"someThing\")";
result = interpreter.evaluateCondition(condition);
Assert.assertFalse(condition, result);
condition = "hasUserProperty(\"firstName\", \"firstconditiongugus\")";
result = interpreter.evaluateCondition(condition);
Assert.assertFalse(condition, result);
condition = "hasUserProperty(\"firstName\", \"gugusfirstcondition\")";
result = interpreter.evaluateCondition(condition);
Assert.assertFalse(condition, result);
condition = "hasUserProperty(\"lastName\", \"firstcondition\")";
result = interpreter.evaluateCondition(condition);
Assert.assertFalse(condition, result);
}
Aggregations