protected User createAndAssertBasicCreationOfUser(String userId, String name) { // 1. Create a new user object // (Note: it is not strictly required to perform a cast on the user object // to a NodeBacked interface - behind the scenes, the aspectj compiler // will automatically do this for you however, to make life easier for // IDE's this can sometimes prove quite useful to prevent them moaning // at you about compilation issues which theoretically wont exists post // aspectj compilation ....) User user = new User(userId, name); Long userNodeId = ((NodeBacked) user).getNodeId(); assertNull( "Not expecting user to have been persisted in graph and" + "to have been allocated a node id " + "yet as we have not issued an explicit persist call", userNodeId); // 2. Save / Persist it and ensure it is allocated a node id ((NodeBacked) user).persist(); userNodeId = ((NodeBacked) user).getNodeId(); assertNotNull( "Expecting user to have been persisted in graph and " + "allocated a node id now " + "as we have issued an explicit persist call", userNodeId); return user; }
// HACK: reflection private void updateScenarioParameters() { for (ConfigurableObject configObj : this.scenarioParameters.values()) { String beanName = configObj.getId(); Object bean = this.context.getBean(beanName); Class<?> clazz = bean.getClass(); HashMap<String, java.lang.reflect.Field> declaredFields = new HashMap<String, java.lang.reflect.Field>(); do { for (java.lang.reflect.Field field : clazz.getDeclaredFields()) { declaredFields.put(field.getName(), field); } clazz = clazz.getSuperclass(); } while (clazz != null); clazz = bean.getClass(); for (ScenarioParameter parameter : configObj.getParameters()) { String field = this.capitalize(parameter.getField()); Object value = parameter.getValue(); Method[] methods = clazz.getMethods(); for (Method method : methods) { if (method.getName().equals("set" + field)) { try { method.invoke(bean, value); } catch (Exception e) { throw new RuntimeException(e); } ((NodeBacked) bean).persist(); break; } } } } }