@Test public final void shouldCreateViewForUrlItem() { MenuItemDefinition menuUrlItemDefinition = MenuItemDefinition.create(PLUGIN_IDENTIFIER, "itemName", "categoryName", ROLE_VISIBLE, true).forUrl("someUrl"); given(menuCrudService.getView(menuUrlItemDefinition)).willReturn(null); given(menuCrudService.createEntity(QcadooViewConstants.MODEL_VIEW)).willAnswer(new Answer<Entity>() { @Override public Entity answer(final InvocationOnMock invocation) throws Throwable { DataDefinition dataDefinition = mock(DataDefinition.class); return new DefaultEntity(dataDefinition); } }); menuService.addView(menuUrlItemDefinition); verify(menuCrudService).save(entityCaptor.capture()); Entity savedView = entityCaptor.getValue(); assertEquals("somePlugin", savedView.getStringField(ViewFields.PLUGIN_IDENTIFIER)); assertEquals("itemName", savedView.getStringField(ViewFields.NAME)); assertNull(savedView.getStringField(ViewFields.VIEW)); assertEquals("someUrl", savedView.getStringField(ViewFields.URL)); }
@Override @Transactional public void addView(final MenuItemDefinition itemDefinition) { Entity menuView = menuCrudService.getView(itemDefinition); if (menuView != null) { return; } boolean hasUrlOrViewExists = itemDefinition.getUrl() != null || viewDefinitionService.viewExists(itemDefinition.getViewPluginIdentifier(), itemDefinition.getViewName()); Preconditions.checkState(hasUrlOrViewExists, String.format("View %s/%s does not exist", itemDefinition.getViewPluginIdentifier(), itemDefinition.getViewName())); menuView = menuCrudService.createEntity(QcadooViewConstants.MODEL_VIEW); menuView.setField(ViewFields.PLUGIN_IDENTIFIER, itemDefinition.getViewPluginIdentifier()); menuView.setField(ViewFields.NAME, itemDefinition.getViewName()); if (itemDefinition.getUrl() == null) { menuView.setField(ViewFields.VIEW, itemDefinition.getViewName()); } else { menuView.setField(ViewFields.URL, itemDefinition.getUrl()); } menuCrudService.save(menuView); }
MenuServiceImpl implements InternalMenuService { @Override @Transactional public void addView(final MenuItemDefinition itemDefinition) { Entity menuView = menuCrudService.getView(itemDefinition); if (menuView != null) { return; } boolean hasUrlOrViewExists = itemDefinition.getUrl() != null || viewDefinitionService.viewExists(itemDefinition.getViewPluginIdentifier(), itemDefinition.getViewName()); Preconditions.checkState(hasUrlOrViewExists, String.format("View %s/%s does not exist", itemDefinition.getViewPluginIdentifier(), itemDefinition.getViewName())); menuView = menuCrudService.createEntity(QcadooViewConstants.MODEL_VIEW); menuView.setField(ViewFields.PLUGIN_IDENTIFIER, itemDefinition.getViewPluginIdentifier()); menuView.setField(ViewFields.NAME, itemDefinition.getViewName()); if (itemDefinition.getUrl() == null) { menuView.setField(ViewFields.VIEW, itemDefinition.getViewName()); } else { menuView.setField(ViewFields.URL, itemDefinition.getUrl()); } menuCrudService.save(menuView); } }
MenuServiceImpl implements InternalMenuService { @Override @Transactional public void addView(final MenuItemDefinition itemDefinition) { Entity menuView = menuCrudService.getView(itemDefinition); if (menuView != null) { return; } boolean hasUrlOrViewExists = itemDefinition.getUrl() != null || viewDefinitionService.viewExists(itemDefinition.getViewPluginIdentifier(), itemDefinition.getViewName()); Preconditions.checkState(hasUrlOrViewExists, String.format("View %s/%s does not exist", itemDefinition.getViewPluginIdentifier(), itemDefinition.getViewName())); menuView = menuCrudService.createEntity(QcadooViewConstants.MODEL_VIEW); menuView.setField(ViewFields.PLUGIN_IDENTIFIER, itemDefinition.getViewPluginIdentifier()); menuView.setField(ViewFields.NAME, itemDefinition.getViewName()); if (itemDefinition.getUrl() == null) { menuView.setField(ViewFields.VIEW, itemDefinition.getViewName()); } else { menuView.setField(ViewFields.URL, itemDefinition.getUrl()); } menuCrudService.save(menuView); }  }
MenuServiceImpl implements InternalMenuService { @Override @Transactional public void addView(final MenuItemDefinition itemDefinition) { Entity menuView = menuCrudService.getView(itemDefinition); if (menuView != null) { return; } boolean hasUrlOrViewExists = itemDefinition.getUrl() != null || viewDefinitionService.viewExists(itemDefinition.getViewPluginIdentifier(), itemDefinition.getViewName()); Preconditions.checkState(hasUrlOrViewExists, String.format("View %s/%s does not exist", itemDefinition.getViewPluginIdentifier(), itemDefinition.getViewName())); menuView = menuCrudService.createEntity(QcadooViewConstants.MODEL_VIEW); menuView.setField(ViewFields.PLUGIN_IDENTIFIER, itemDefinition.getViewPluginIdentifier()); menuView.setField(ViewFields.NAME, itemDefinition.getViewName()); if (itemDefinition.getUrl() == null) { menuView.setField(ViewFields.VIEW, itemDefinition.getViewName()); } else { menuView.setField(ViewFields.URL, itemDefinition.getUrl()); } menuCrudService.save(menuView); }  @Override @Transactional(readOnly = true) @Monitorable MenuDefinition getMenu(final Locale locale); @Override @Transactional void addView(final MenuItemDefinition itemDefinition); @Override @Transactional void removeView(final MenuItemDefinition itemDefinition); @Override @Transactional void createCategory(final MenuCategoryDefinition menuCategoryDefinition); @Override @Transactional void removeCategory(final MenuCategoryDefinition menuCategoryDefinition); @Override @Transactional void createItem(final MenuItemDefinition itemDefinition); @Override @Transactional void removeItem(final MenuItemDefinition itemDefinition); }
MenuServiceImpl implements InternalMenuService { @Override @Transactional public void addView(final MenuItemDefinition itemDefinition) { Entity menuView = menuCrudService.getView(itemDefinition); if (menuView != null) { return; } boolean hasUrlOrViewExists = itemDefinition.getUrl() != null || viewDefinitionService.viewExists(itemDefinition.getViewPluginIdentifier(), itemDefinition.getViewName()); Preconditions.checkState(hasUrlOrViewExists, String.format("View %s/%s does not exist", itemDefinition.getViewPluginIdentifier(), itemDefinition.getViewName())); menuView = menuCrudService.createEntity(QcadooViewConstants.MODEL_VIEW); menuView.setField(ViewFields.PLUGIN_IDENTIFIER, itemDefinition.getViewPluginIdentifier()); menuView.setField(ViewFields.NAME, itemDefinition.getViewName()); if (itemDefinition.getUrl() == null) { menuView.setField(ViewFields.VIEW, itemDefinition.getViewName()); } else { menuView.setField(ViewFields.URL, itemDefinition.getUrl()); } menuCrudService.save(menuView); }  @Override @Transactional(readOnly = true) @Monitorable MenuDefinition getMenu(final Locale locale); @Override @Transactional void addView(final MenuItemDefinition itemDefinition); @Override @Transactional void removeView(final MenuItemDefinition itemDefinition); @Override @Transactional void createCategory(final MenuCategoryDefinition menuCategoryDefinition); @Override @Transactional void removeCategory(final MenuCategoryDefinition menuCategoryDefinition); @Override @Transactional void createItem(final MenuItemDefinition itemDefinition); @Override @Transactional void removeItem(final MenuItemDefinition itemDefinition);  }