}
return result;
}
@Test(enabled=TEST_ENABLED)
public void testFlowPropertyDefinitionNamespace() {
FlowTestingUtils flowTestingUtils = new FlowTestingUtils();
String activityName = "activity";
String namespace;
String flowTypeName = "myflow";
FlowPropertyDefinitionImpl flowLocalProperty = new FlowPropertyDefinitionImpl("foo", Boolean.class).initPropertyScope(flowLocal);
FlowPropertyDefinitionImpl activityLocalProperty = new FlowPropertyDefinitionImpl("foo", Boolean.class).initPropertyScope(activityLocal);
List<String> namespaces;
{
// static test using FlowActivity
FlowActivityImpl flowActivity = newFlowActivity();
flowActivity.setFlowPropertyProviderName(activityName);
flowTestingUtils.addFlowDefinition(flowTypeName, flowActivity);
namespace = flowLocalProperty.getNamespaceKey(null, flowActivity);
assertEquals(namespace, flowTypeName);
namespace = activityLocalProperty.getNamespaceKey(null, flowActivity);
assertEquals(namespace, flowTypeName+"."+activityName);
namespaces = flowLocalProperty.getNamespaceKeySearchList(null, flowActivity);
assertEquals(namespaces.get(0), flowTypeName, "namespaces="+namespaces);
assertEquals(namespaces.get(1), flowTypeName, "namespaces="+namespaces);
assertEquals(namespaces.get(2), null, "namespaces="+namespaces);
assertEquals(namespaces.size(), 3, "namespaces="+namespaces);
namespaces = activityLocalProperty.getNamespaceKeySearchList(null, flowActivity);
int i = 0;
assertEquals(namespaces.get(i++), flowActivity.getFullActivityInstanceNamespace(), "namespaces="+namespaces);
assertEquals(namespaces.get(i++), flowActivity.getFlowPropertyProviderFullName(), "namespaces="+namespaces);
assertEquals(namespaces.get(i++), flowActivity.getFlowPropertyProviderName(), "namespaces="+namespaces);
assertEquals(namespaces.get(i++), flowTypeName, "namespaces="+namespaces);
assertEquals(namespaces.get(i++), null, "namespaces="+namespaces);
assertEquals(namespaces.size(), i, "namespaces="+namespaces);
}
{
// static test for FlowImpl
Flow flow = flowTestingUtils.getFlowDefinitionsManager().getFlowDefinition(flowTypeName);
namespace = flowLocalProperty.getNamespaceKey(null, flow);
assertEquals(namespace, flowTypeName);
namespaces = flowLocalProperty.getNamespaceKeySearchList(null, flow);
assertEquals(namespaces.get(0), flowTypeName, "namespaces="+namespaces);
assertEquals(namespaces.get(1), flowTypeName, "namespaces="+namespaces);
assertEquals(namespaces.get(2), null, "namespaces="+namespaces);
assertEquals(namespaces.size(), 3, "namespaces="+namespaces);
try {
namespaces = activityLocalProperty.getNamespaceKeySearchList(null, flow);
fail("should throw exception");
} catch (IllegalStateException e) {
// expected
}
try {
namespace = activityLocalProperty.getNamespaceKey(null, flow);
fail("should throw exception");
} catch (IllegalStateException e) {
// expected
}
}
// now as part of a running flow
FlowManagement flowManagement = flowTestingUtils.getFlowManagement();
FlowStateImpl flowStateImpl = flowManagement.startFlowState(flowTypeName, true, null, null);
FlowActivityImpl flowActivity = flowStateImpl.getCurrentActivity();
for(FlowPropertyProvider flowPropertyProvider: new FlowPropertyProvider[] {flowActivity, flowStateImpl.getFlow()}) {
namespace = flowLocalProperty.getNamespaceKey(flowStateImpl, flowPropertyProvider);
assertEquals(namespace, flowStateImpl.getLookupKey());