@Transactional @Rollback(true) @Test public void testUpdateWidgetInstance() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException, IOException { ObjectMapper objectMapper = new ObjectMapper(); DefaultWidgetInstance defaultWidgetInstance = prepareData(objectMapper); Map<String, String> responsMap = uIService.createOrUpdateWidgetInstance(defaultWidgetInstance); Assert.isTrue( responsMap.get("widgetInstanceAction").equals("update"), "The response action should have been 'updated'"); Canvas retrievedPerishableCanvas = uIService.getCanvasByName("Perishable Goods Canvas"); List<DefaultWidgetInstance> retrievedDefaultWidgetInstances = retrievedPerishableCanvas.getWidgetInstanceList(); DefaultWidgetInstance retrievedRefaultWidgetInstance = retrievedDefaultWidgetInstances.get(0); Assert.isTrue( objectMapper .writeValueAsString(actualViewConfig) .equals(retrievedRefaultWidgetInstance.getActualViewConfig())); }
@Test @Transactional public void testHydratedCanvas() throws Exception { final Canvas canvas = this.uIService.getHydratedCanvas(300L); Assert.notNull(canvas, "Canvas Doesn't Exist for CanvasId 300"); final List<DefaultWidgetInstance> defaultWidgetInstances = canvas.getWidgetInstanceList(); Assert.notNull(defaultWidgetInstances, "DefaultWidgetInstance List for CanvasId 6 is Null"); }
@Test @Transactional public void testGetCanvasById() throws Exception { final Canvas canvas = this.uIService.getCanvasById(1L); Assert.notNull(canvas, "Canvas Doesn't Exist for CanvasId 1"); final List<DefaultWidgetInstance> defaultWidgetInstances = canvas.getWidgetInstanceList(); Assert.notNull(defaultWidgetInstances, "DefaultWidgetInstance List for CanvasId 5 is Null"); }
/** * @Author Adarsh kumar * * <p>testExistingCanvasAndDeletion() provide the functionality of deletion of the existing canvas * based on the canvasId or canvasName in this test already existing canvas is used for deletion * test by the uiService * * @throws Exception */ @Test @Rollback(value = true) @Transactional public void testExistingCanvasAndDeletion() throws Exception { /* FETCHING CANVAS FROM DATABASE FOR ENSURING NEW CANVAS IS EXISTING INTO DB */ Canvas canvasPersisted = this.uIService.getCanvasById(1L); Assert.notNull( canvasPersisted, "Canvas Doesn't Exist for CanvasId " + canvasPersisted.getCanvasId()); /* DELETING THE CANVAS FROM DATABASE BASED ON ID OR NAME */ final Boolean result = this.uIService.deleteCanvasById(canvasPersisted.getCanvasId()); Assert.isTrue(result, "Canvas Isn't deleted from database"); }
private DefaultWidgetInstance prepareData(ObjectMapper objectMapper) throws JsonProcessingException { AbstractLicensableWidget widget = new UserProductivityWidget(); widget.setId(1l); widget.setName("user-productivity-widget"); Canvas perishableCanvas = new Canvas(); perishableCanvas.setName("Perishable Goods Canvas"); perishableCanvas.setShortName("shortName"); perishableCanvas.setCanvasType(CanvasType.PRIVATE); perishableCanvas.setCanvasId(1l); DefaultWidgetInstance defaultWidgetInstance = new DefaultWidgetInstance(); defaultWidgetInstance.setActualViewConfig(objectMapper.writeValueAsString(actualViewConfig)); defaultWidgetInstance.setCanvas(perishableCanvas); defaultWidgetInstance.setWidgetinstanceId(1l); defaultWidgetInstance.setWidget(widget); return defaultWidgetInstance; }
@Test @Transactional @Rollback(true) public void testCreateCanvas() throws Exception { uIService.saveWidget(widget); canvas = new Canvas("testCanvas"); canvas.setCanvasType(CanvasType.PRIVATE); canvas.setCanvasLayout(uIService.getCanvasLayoutById(1L)); canvas.setShortName("testCanvas"); canvas.setCreatedByUserName("createdByUserName"); canvas.setCreatedDateTime(new Date()); canvas.setWidgetInstanceList(widgetInstanceList); uIService.saveCanvas(canvas); Canvas retrivedCanvas = uIService.getCanvasByName(canvas.getName()); Assert.notNull(retrivedCanvas); }
/** * @Author Adarsh kumar * * <p>testCanvasPersistedAndDeletion() provide the functionality of deletion of the canvas based * on the canvasId or canvasName in this test case new canvas is inserted and then deleted by the * uiService for testing. * * @throws Exception */ @Test @Rollback(value = true) @Transactional public void testCanvasPersistedAndDeletion() throws Exception { /* CREATING NEW CANVAS FOR TESTING PURPOSE */ this.uIService.saveWidget(widget); final Canvas canvasNew = new Canvas("testCanvas"); canvasNew.setCanvasType(CanvasType.PRIVATE); canvasNew.setCanvasLayout(uIService.getCanvasLayoutById(1L)); canvasNew.setShortName("testCanvas"); canvasNew.setCreatedByUserName("createdByUserName"); canvasNew.setCreatedDateTime(new Date()); canvasNew.setWidgetInstanceList(widgetInstanceList); final Long canvasId = this.uIService.saveCanvas(canvasNew); Assert.notNull(canvasId, "Canvas Isn't Persisted into database " + canvasId); /* DELETING THE CANVAS FROM DATABASE BASED ON ID */ final Boolean result = this.uIService.deleteCanvasById(canvasNew.getCanvasId()); Assert.isTrue(result, "Canvas Isn't deleted from database"); }
@Before public void setup() throws Exception { user = new User(); user.setUserId(1L); user.setUserName(USERNAME); user.setHashedPassword(HASHED_PASSWORD); canvas = new Canvas("testCanvas1"); List<String> listensFor = new ArrayList<String>(); listensFor.add("Area"); listensFor.add("Shift"); listensFor.add("Picker"); List<Integer> anchorList = new ArrayList<Integer>(); anchorList.add(2); anchorList.add(3); List<Map<String, String>> options = new ArrayList<Map<String, String>>(); Map<String, String> optionsMap1 = new HashMap<String, String>(); optionsMap1.put("legend", "horizontal"); optionsMap1.put("value", "h"); Map<String, String> optionsMap2 = new HashMap<String, String>(); optionsMap2.put("legend", "vertical"); optionsMap2.put("value", "v"); options.add(optionsMap1); options.add(optionsMap2); widgetOrientation = new WidgetOrientation(options, "h"); defaultViewConfig = new DefaultViewConfig(anchorList, 2L, 2L, 2L, widgetOrientation); actualViewConfig = new ActualViewConfig(anchorList, 2L, 2L, 2L, listensFor); p1 = new Permission("create-assignment"); p2 = new Permission("view-report-productivity"); p3 = new Permission("configure-location"); p4 = new Permission("create-canvas"); p5 = new Permission("delete-canvas"); p6 = new Permission("authenticated-user"); p7 = new Permission("pickingwidget2-widget-access"); Map<String, Map<Permission, Boolean>> mappedActionConfigurableMap = new HashMap<String, Map<Permission, Boolean>>(); mappedActionConfig = new PermissionMappedActionConfig(mappedActionConfigurableMap); mappedActionConfigurableMap.put( "widget-access", new HashMap<Permission, Boolean>() { { put(p7, Boolean.FALSE); } }); mappedActionConfigurableMap.put( "widget-actions", new HashMap<Permission, Boolean>() { { put(p1, Boolean.FALSE); put(p2, Boolean.FALSE); put(p3, Boolean.FALSE); put(p4, Boolean.FALSE); put(p5, Boolean.FALSE); put(p6, Boolean.FALSE); } }); ObjectMapper objectMapper = new ObjectMapper(); widget = new UserCreationFormWidget( "Picking Widget2", "pick2", Enum.valueOf(WidgetType.class, "GRID"), objectMapper.writeValueAsString(defaultViewConfig)); widget.setActionConfig(mappedActionConfig); widget.setActive(true); widget.setCategory("Administration"); ; widgetInstance = new DefaultWidgetInstance( objectMapper.writeValueAsString(actualViewConfig), canvas, widget); widgetInstanceList = new ArrayList<DefaultWidgetInstance>(); widgetInstanceList.add(widgetInstance); canvas.setWidgetInstanceList(widgetInstanceList); auth = new UsernamePasswordAuthenticationToken(user, null, Arrays.asList(grantedAuthoritiesArr)); }