public void testActionContainerCreatedOnlyOncePerRequest() { MutablePicoContainer requestContainer = new DefaultPicoContainer(); requestContainer.registerComponentImplementation(TestService.class); MutablePicoContainer actionsContainer = new DefaultPicoContainer(requestContainer); requestMock .expects(once()) .method("getAttribute") .with(eq(KeyConstants.ACTIONS_CONTAINER)) .will(returnValue(actionsContainer)); requestMock .expects(once()) .method("getAttribute") .with(eq(KeyConstants.ACTIONS_CONTAINER)) .will(returnValue(actionsContainer)); requestMock .expects(once()) .method("setAttribute") .with(eq(KeyConstants.ACTIONS_CONTAINER), isA(MutablePicoContainer.class)); requestMock .expects(once()) .method("getAttribute") .with(eq(KeyConstants.REQUEST_CONTAINER)) .will(returnValue(requestContainer)); requestMock .expects(once()) .method("getAttribute") .with(eq(KeyConstants.ACTIONS_CONTAINER)) .will(returnValue(null)); actionFactory.getAction(request, mapping1, servlet); actionFactory.getAction(request, mapping1, servlet); actionFactory.getAction(request, mapping1, servlet); }
public void testGetActionWhenActionsContainerAlreadyExists() { MutablePicoContainer requestContainer = new DefaultPicoContainer(); requestContainer.registerComponentInstance(TestService.class, service); MutablePicoContainer actionsContainer = new DefaultPicoContainer(requestContainer); requestMock .stubs() .method("getAttribute") .with(eq(KeyConstants.ACTIONS_CONTAINER)) .will(returnValue(actionsContainer)); StrutsTestAction action1 = (StrutsTestAction) actionFactory.getAction(request, mapping1, servlet); StrutsTestAction action2 = (StrutsTestAction) actionFactory.getAction(request, mapping2, servlet); TestAction action3 = (TestAction) actionFactory.getAction(request, mapping1, servlet); TestAction action4 = (TestAction) actionFactory.getAction(request, mapping2, servlet); assertNotNull(action1); assertNotNull(action2); assertNotSame(action1, action2); assertSame(action1, action3); assertSame(action2, action4); assertSame(action1, actionsContainer.getComponentInstance("/myPath1")); assertSame(action2, actionsContainer.getComponentInstance("/myPath2")); assertSame(service, action1.getService()); assertSame(service, action2.getService()); assertNotNull(action1.getServlet()); assertNotNull(action2.getServlet()); assertSame(servlet, action1.getServlet()); assertSame(servlet, action2.getServlet()); }
@Override public void onContextInitialize(final IWorkbenchApplicationContext context) { this.context = context; final ActionFactory actionFactory = new ActionFactory(); final IAction addFolderAction = actionFactory.createAddFolderAction(context); // create menus context.getPopupMenu().addAction(addFolderAction); final List<IComponentNode> componentList3 = new LinkedList<IComponentNode>(); componentList3.add(new ImportantComponentTreeNodeDemo1("IMPORTANT1", "Important")); final FolderNodeDemo folderNode2 = new FolderNodeDemo("MISC", "Misc", componentList3); context.add(folderNode2); }
public void testNoContainerExists() { requestMock .expects(once()) .method("getAttribute") .with(eq(KeyConstants.ACTIONS_CONTAINER)) .will(returnValue(null)); requestMock .expects(once()) .method("getAttribute") .with(eq(KeyConstants.REQUEST_CONTAINER)) .will(returnValue(null)); sessionMock .expects(once()) .method("getAttribute") .with(eq(KeyConstants.SESSION_CONTAINER)) .will(returnValue(null)); servletContextMock .expects(once()) .method("getAttribute") .with(eq(KeyConstants.APPLICATION_CONTAINER)) .will(returnValue(null)); try { actionFactory.getAction(request, mapping1, servlet); fail("PicoInitializationException should have been raised"); } catch (PicoInitializationException e) { // expected } }
public void testApplicationContainerExists() { MutablePicoContainer appContainer = new DefaultPicoContainer(); appContainer.registerComponentInstance(TestService.class, service); requestMock .expects(once()) .method("getAttribute") .with(eq(KeyConstants.ACTIONS_CONTAINER)) .will(returnValue(null)); requestMock .expects(once()) .method("getAttribute") .with(eq(KeyConstants.REQUEST_CONTAINER)) .will(returnValue(null)); sessionMock .expects(once()) .method("getAttribute") .with(eq(KeyConstants.SESSION_CONTAINER)) .will(returnValue(null)); servletContextMock .expects(once()) .method("getAttribute") .with(eq(KeyConstants.APPLICATION_CONTAINER)) .will(returnValue(appContainer)); requestMock .expects(once()) .method("setAttribute") .with(eq(KeyConstants.ACTIONS_CONTAINER), isA(MutablePicoContainer.class)); TestAction action = (TestAction) actionFactory.getAction(request, mapping1, servlet); assertNotNull(action); assertSame(service, action.getService()); }
private void setupMenu() { menu.add(ActionFactory.getMovementFromDeckToWaste(moveController)); menu.add(ActionFactory.getMovementFromFoundationToPile(moveController)); menu.add(ActionFactory.getMovementFromPileToFoundation(moveController)); menu.add(ActionFactory.getMovementFromPileToPile(moveController)); menu.add(ActionFactory.getMovementFromWasteToDeck(moveController)); menu.add(ActionFactory.getMovementFromWasteToFoundation(moveController)); menu.add(ActionFactory.getMovementFromWasteToPile(moveController)); menu.add(ActionFactory.getMovementDiscover(moveController)); }
public List<Action> followUpActions() { if (followUpActions == null) { followUpActions = new ArrayList<Action>(); if (item.getTalkPhraseSource() != null) for (String id : item.getTalkPhraseSource().initialPhraseIds()) followUpActions.add(actionFactory.createSayAction(id, item)); } return followUpActions; }
public void createTouchDownAction() { ParallelAction whenParallelAction = ActionFactory.parallel(); for (Script s : scriptList) { if (s instanceof WhenTouchDownScript) { SequenceAction sequence = createActionSequence(s); whenParallelAction.addAction(sequence); } } look.addAction(whenParallelAction); }
public void createWhenScriptActionSequence(String action) { ParallelAction whenParallelAction = actionFactory.parallel(); for (Script s : scriptList) { if (s instanceof WhenScript && (((WhenScript) s).getAction().equalsIgnoreCase(action))) { SequenceAction sequence = createActionSequence(s); whenParallelAction.addAction(sequence); } } look.setWhenParallelAction(whenParallelAction); look.addAction(whenParallelAction); }
public void createWhenNfcScriptAction(String uid) { ParallelAction whenParallelAction = ActionFactory.parallel(); for (Script s : scriptList) { if (s instanceof WhenNfcScript) { WhenNfcScript whenNfcScript = (WhenNfcScript) s; if (whenNfcScript.isMatchAll() || whenNfcScript.getNfcTag().getNfcTagUid().equals(uid)) { SequenceAction sequence = createActionSequence(s); whenParallelAction.addAction(sequence); } } } // TODO: quick fix for faulty behaviour - nfc action triggers again after touchevents // look.setWhenParallelAction(whenParallelAction); look.addAction(whenParallelAction); }
public void testBadActionType() { MutablePicoContainer actionsContainer = new DefaultPicoContainer(); requestMock .stubs() .method("getAttribute") .with(eq(KeyConstants.ACTIONS_CONTAINER)) .will(returnValue(actionsContainer)); mapping1.setType("/i/made/a/typo"); try { actionFactory.getAction(request, mapping1, servlet); fail("PicoIntrospectionException should have been raised"); } catch (PicoIntrospectionException e) { // expected } }
/** * Returns an instance of the MuAction class denoted by the given ActionParameters and for the * specified MainFrame. If an existing instance corresponding to the same ActionParameters and * MainFrame is found, it is simply returned. If no matching instance could be found, a new * instance is created, added to the internal action instances map (for further use) and returned. * If the action denoted by the specified ActionParameters cannot be found or cannot be * instantiated, <code>null</code> is returned. * * @param actionParameters a descriptor of the action to instantiate with initial properties * @param mainFrame the MainFrame instance the action belongs to * @return a MuAction instance matching the given ActionParameters and MainFrame, <code>null * </code> if the MuAction action denoted by the ActionParameters could not be found or could * not be instantiated. */ public static MuAction getActionInstance(ActionParameters actionParameters, MainFrame mainFrame) { Map<ActionParameters, ActionAndIdPair> mainFrameActions = mainFrameActionsMap.get(mainFrame); if (mainFrameActions == null) { mainFrameActions = new Hashtable<ActionParameters, ActionAndIdPair>(); mainFrameActionsMap.put(mainFrame, mainFrameActions); } // Looks for an existing MuAction instance used by the specified MainFrame if (mainFrameActions.containsKey(actionParameters)) { return mainFrameActions.get(actionParameters).getAction(); } else { String actionId = actionParameters.getActionId(); // Looks for the action's factory ActionFactory actionFactory = actionFactories.get(actionId); if (actionFactory == null) { LOGGER.debug("couldn't initiate action: " + actionId + ", its factory wasn't found"); return null; } Map<String, Object> properties = actionParameters.getInitProperties(); // If no properties hashtable is specified in the action descriptor if (properties == null) { properties = new Hashtable<String, Object>(); } // else clone the hashtable to ensure that it doesn't get modified by action instances. // Since cloning is an expensive operation, this is done only if the hashtable is not empty. else if (!properties.isEmpty()) { Map<String, Object> buffer; buffer = new Hashtable<String, Object>(); buffer.putAll(properties); properties = buffer; } // Instantiate the MuAction class MuAction action = actionFactory.createAction(mainFrame, properties); mainFrameActions.put(actionParameters, new ActionAndIdPair(action, actionId)); // If the action's label has not been set yet, use the action descriptor's if (action.getLabel() == null) { // Retrieve the standard label entry from the dictionary and use it as this action's label String label = ActionProperties.getActionLabel(actionId); // Append '...' to the label if this action invokes a dialog when performed if (action instanceof InvokesDialog) label += "..."; action.setLabel(label); // Looks for a standard label entry in the dictionary and if it is defined, use it as this // action's tooltip String tooltip = ActionProperties.getActionTooltip(actionId); if (tooltip != null) action.setToolTipText(tooltip); } // If the action's accelerators have not been set yet, use the ones from ActionKeymap if (action.getAccelerator() == null) { // Retrieve the standard accelerator (if any) and use it as this action's accelerator KeyStroke accelerator = ActionKeymap.getAccelerator(actionId); if (accelerator != null) action.setAccelerator(accelerator); // Retrieve the standard alternate accelerator (if any) and use it as this action's // alternate accelerator accelerator = ActionKeymap.getAlternateAccelerator(actionId); if (accelerator != null) action.setAlternateAccelerator(accelerator); } // If the action's icon has not been set yet, use the action descriptor's if (action.getIcon() == null) { // Retrieve the standard icon image (if any) and use it as the action's icon ImageIcon icon = ActionProperties.getActionIcon(actionId); if (icon != null) action.setIcon(icon); } return action; } }
private SequenceAction createActionSequence(Script script) { SequenceAction sequence = ActionFactory.sequence(); script.run(this, sequence); return sequence; }