@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()));
  }
  @Ignore
  @Test
  public void testGetSearchUserGridWidgetDefinitionWithoutAuthentication()
      throws IllegalArgumentException, IllegalAccessException, InvocationTargetException,
          SecurityException, NoSuchMethodException, IOException {
    AbstractLicensableWidget searchUserGridWidget =
        uIService.getWidgetDefinition(SearchUserGridWidgetName);
    SecurityContext securityContext = SecurityContextHolder.getContext();
    securityContext.setAuthentication(null);
    Assert.notNull(searchUserGridWidget);
    Assert.notNull(searchUserGridWidget.getDataURL());

    Assert.isTrue(
        searchUserGridWidget.getActionConfig().getActionConfig().size() == 2,
        "Search user grid widget action config does not have expected # of permissions values");

    Assert.isTrue(
        searchUserGridWidget
                .getActionConfig()
                .getActionConfig()
                .get("widget-actions")
                .get(new Permission("delete-user"))
            == Boolean.FALSE,
        "Search user grid widget action config does not have delete-user permission false");

    Assert.isTrue(
        searchUserGridWidget
                .getActionConfig()
                .getActionConfig()
                .get("widget-actions")
                .get(new Permission("disable-user"))
            == Boolean.FALSE,
        "Search user grid widget action config does not have disable-user permission false");
  }
  @Transactional(readOnly = true)
  @Test
  public void testGetWidgetDefinitionsByCategory() throws IOException, Exception {

    SecurityContext securityContext = SecurityContextHolder.getContext();
    securityContext.setAuthentication(auth);

    MultiMap widgetDefinitionsByCategoryMap = uIService.getWidgetDefinitionsByCategory();
    Assert.notNull(widgetDefinitionsByCategoryMap);
    //			Assert.isTrue(widgetDefinitionsByCategoryMap.size() == 3);
    //			Assert.isTrue(widgetDefinitionsByCategoryMap.values().size() == 4);

    org.junit.Assert.assertTrue(
        "testGetWidgetDefinitionsByCategory() widgetDefinitionsByCategoryMap.size() failed test, "
            + "expected value 3, actually got: "
            + widgetDefinitionsByCategoryMap.size(),
        widgetDefinitionsByCategoryMap.size() == 4);
    org.junit.Assert.assertTrue(
        "testGetWidgetDefinitionsByCategory() widgetDefinitionsByCategoryMap.values().size() failed test, "
            + "expected value 4, actually got: "
            + widgetDefinitionsByCategoryMap.values().size(),
        widgetDefinitionsByCategoryMap.values().size() >= 5);

    securityContext.setAuthentication(null);
  }
 @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);
 }
 @Test
 @Transactional
 @Rollback(true)
 public void testSaveWidget()
     throws JsonParseException, JsonMappingException, JsonProcessingException, IOException {
   LucasObjectMapper om = new LucasObjectMapper();
   String stringActionConfig = om.writeValueAsString(mappedActionConfig);
   MappedActionConfigurable<String, Map<Permission, Boolean>> mac =
       om.readValue(
           stringActionConfig,
           new TypeReference<MappedActionConfigurable<String, Map<Permission, Boolean>>>() {});
   uIService.deleteWidget(widget.getName());
   uIService.saveWidget(widget);
   AbstractLicensableWidget retrivedWidget = uIService.getWidgetByName(widget.getName());
   Assert.notNull(retrivedWidget);
 }
 @Test
 public void testGetPicklineByWaveBarChartWidgetDefinition()
     throws JsonProcessingException, IllegalArgumentException, IllegalAccessException,
         InvocationTargetException, SecurityException, NoSuchMethodException {
   AbstractLicensableWidget picklineByWaveBarChartWidget =
       uIService.getWidgetDefinition(PicklineByWaveBarChartWidgetName);
   Assert.notNull(picklineByWaveBarChartWidget);
 }
  @Test
  @Transactional(readOnly = true)
  public void testGetEventGridWidgetDefinitionWithAuthentication()
      throws IllegalArgumentException, IllegalAccessException, InvocationTargetException,
          SecurityException, NoSuchMethodException, IOException {
    SecurityContext securityContext = SecurityContextHolder.getContext();
    securityContext.setAuthentication(auth);
    AbstractLicensableWidget eventGridWidget = uIService.getWidgetDefinition(EventGridWidgetName);
    Assert.notNull(eventGridWidget);
    Assert.isTrue(
        eventGridWidget.getActionConfig().getActionConfig().size() == 2,
        "Event grid widget action config does not have expected # of permissions values");
    Assert.isTrue(
        eventGridWidget
                .getActionConfig()
                .getActionConfig()
                .get("widget-actions")
                .get(new Permission("create-event"))
            == Boolean.TRUE,
        "Event grid widget action config does not have create-event permission true");
    Assert.isTrue(
        eventGridWidget
                .getActionConfig()
                .getActionConfig()
                .get("widget-actions")
                .get(new Permission("edit-event"))
            == Boolean.TRUE,
        "Event grid widget action config does not have edit-event permission true");

    // Assertions for AutoRefreshConfig
    JSONObject defaultViewConfigJSON = new JSONObject(eventGridWidget.getDefaultViewConfig());
    Assert.isTrue(
        defaultViewConfigJSON.has("autoRefreshConfig"),
        "Could not find property 'AutoRefreshConfig'");

    JSONObject autoRefreshConfigJSON =
        new JSONObject(defaultViewConfigJSON.get("autoRefreshConfig").toString());
    Assert.isTrue(
        autoRefreshConfigJSON.has("globalOverride"), "Could not find property 'globalOverride'");
    Assert.isTrue(autoRefreshConfigJSON.has("enabled"), "Could not find property 'enabled'");
    Assert.isTrue(autoRefreshConfigJSON.has("interval"), "Could not find property 'interval'");

    Assert.isTrue(
        autoRefreshConfigJSON.getBoolean("globalOverride") == false,
        "Incorrect value for property 'globalOverride'");
    Assert.isTrue(
        autoRefreshConfigJSON.getBoolean("enabled") == true,
        "Incorrect value for property 'enabled'");
    Assert.isTrue(
        autoRefreshConfigJSON.getInt("interval") == 120, "Incorrect value for property 'interval'");
  }
  @Test
  public void testGetCanvasesByCategories() throws Exception {

    SecurityContext securityContext = SecurityContextHolder.getContext();
    securityContext.setAuthentication(auth);
    LinkedHashMap<String, List<Canvas>> canvasesByCategory = uIService.getCanvasesByCategories();
    Assert.notNull(canvasesByCategory, "Canvases by category service call returns null");
    Assert.isTrue(
        canvasesByCategory.size() == 2,
        "Canvases by category service call does not return all three types of canvases");
    Assert.isTrue(
        canvasesByCategory.values().size() == 2,
        "Canvases by category service call does not return expected number of canvases (=5)");
    securityContext.setAuthentication(null);
  }
 @Transactional(readOnly = true)
 @Test
 public void testGetUserCreationFormWidgetDefinition()
     throws JsonProcessingException, IllegalArgumentException, IllegalAccessException,
         InvocationTargetException, SecurityException, NoSuchMethodException {
   String listenForListString = "\"listensForList\": [ \"userName\"]";
   AbstractLicensableWidget userCreationFormWidget =
       uIService.getWidgetDefinition(UserCreationFormWidgetName);
   Assert.notNull(userCreationFormWidget);
   Assert.notNull(userCreationFormWidget.getReactToList());
   Assert.notNull(userCreationFormWidget.getBroadcastList());
   String defaultViewConfig = userCreationFormWidget.getDefaultViewConfig();
   Assert.isTrue(
       defaultViewConfig.contains(listenForListString),
       "Default view config does not have the expected listen for list");
 }
  @Test
  @Transactional
  @Rollback(true)
  public void testGetWidgetInstanceListForCanvas() throws Exception {

    List<DefaultWidgetInstance> widgetInstanceList =
        uIService.getWidgetInstanceListForCanvas(3l, JACK_USERNAME);
    for (DefaultWidgetInstance widgetInstance : widgetInstanceList) {

      Map<String, Map<Permission, Boolean>> actionConfigMap =
          widgetInstance.getWidget().getActionConfig().getActionConfig();

      Assert.notNull(actionConfigMap);
    }
    Assert.notNull(widgetInstanceList);
  }
  /**
   * @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");
  }
  @Test
  @Transactional(readOnly = true)
  public void testGetSearchUserGridWidgetDefinitionWithAuthentication()
      throws IllegalArgumentException, IllegalAccessException, InvocationTargetException,
          SecurityException, NoSuchMethodException, IOException {
    String listenForListString = "\"listensForList\":[\"userName\"]";
    SecurityContext securityContext = SecurityContextHolder.getContext();
    securityContext.setAuthentication(auth);
    AbstractLicensableWidget searchUserGridWidget =
        uIService.getWidgetDefinition(SearchUserGridWidgetName);
    Assert.notNull(searchUserGridWidget);
    Assert.isTrue(
        searchUserGridWidget.getActionConfig().getActionConfig().size() == 2,
        "Search user grid widget action config does not have expected # of permissions values");
    Assert.isTrue(
        searchUserGridWidget
                .getActionConfig()
                .getActionConfig()
                .get("widget-actions")
                .get(new Permission("delete-user"))
            == Boolean.TRUE,
        "Search user grid widget action config does not have delete-user permission true");
    Assert.isTrue(
        searchUserGridWidget
                .getActionConfig()
                .getActionConfig()
                .get("widget-actions")
                .get(new Permission("disable-user"))
            == Boolean.TRUE,
        "Search user grid widget action config does not have disable-user permission true");
    Assert.notNull(
        searchUserGridWidget.getReactToList(),
        "Search user grid widget definition does not have react to map");
    Assert.notNull(
        searchUserGridWidget.getBroadcastList(),
        "Search user grid widget definition does not have the broadcast list");
    Assert.isTrue(
        searchUserGridWidget.getBroadcastList().size() == 1,
        "Search user grid widget definition does not have the required broadcast list size");
    String defaultViewConfig = searchUserGridWidget.getDefaultViewConfig();
    Assert.isTrue(
        defaultViewConfig.contains(listenForListString),
        "Default view config does not have the expected listen for list");

    // Assertions for AutoRefreshConfig
    JSONObject defaultViewConfigJSON = new JSONObject(searchUserGridWidget.getDefaultViewConfig());
    Assert.isTrue(
        defaultViewConfigJSON.has("autoRefreshConfig"),
        "Could not find property 'AutoRefreshConfig'");

    JSONObject autoRefreshConfigJSON =
        new JSONObject(defaultViewConfigJSON.get("autoRefreshConfig").toString());
    Assert.isTrue(
        autoRefreshConfigJSON.has("globalOverride"), "Could not find property 'globalOverride'");
    Assert.isTrue(autoRefreshConfigJSON.has("enabled"), "Could not find property 'enabled'");
    Assert.isTrue(autoRefreshConfigJSON.has("interval"), "Could not find property 'interval'");

    Assert.isTrue(
        autoRefreshConfigJSON.getBoolean("globalOverride") == false,
        "Incorrect value for property 'globalOverride'");
    Assert.isTrue(
        autoRefreshConfigJSON.getBoolean("enabled") == true,
        "Incorrect value for property 'enabled'");
    Assert.isTrue(
        autoRefreshConfigJSON.getInt("interval") == 120, "Incorrect value for property 'interval'");
  }