@Override
 protected void onProgressUpdate(String... progress) {
   if (progress != null && progress.length > 0) {
     String msg = TextUtils.join("\n", progress);
     textViewTest.setText(msg);
   } else textViewTest.setText(_action.toString());
 }
  @Test
  public void testUpdate() {
    // Verify behavior: calling update does not send an event
    AnActionEvent event = null; // Using null since I can't figure out how to create one of these
    String name = "myAction";
    Map<String, String> properties = new HashMap<String, String>();
    TestAction testAction = new TestAction(name);
    testAction.update(event);
    assertLogged("");

    // Verify behavior: exception in update logs the exception
    name = "myAction2";
    testAction = new TestAction(name);
    testAction.setThrowOnUpdate(true);
    testAction.update(event);
    assertLogged("sendException(throwOnUpdate, {VSO.Plugin.Property.Name=myAction2})");
  }
Example #3
0
  public void testUnselectAll() throws Exception {
    ActionHelper sah = new ActionHelper();
    sah.setUpAction(action);
    sah.setupClampListBounds();
    ActionForward forward = sah.executeAction("unselectall");

    verifyRhnSetData(sah.getUser().getId(), action.getSetDecl().getLabel(), 0);
    verifyParam(forward.getPath(), "setupdated", "true");
  }
  @Test
  public void testActionPerformed() throws Exception {
    // Verify behavior: calling actionPerformed sends an event
    AnActionEvent event = null; // Using null since I can't figure out how to create one of these
    String name = "myAction";
    Map<String, String> properties = new HashMap<String, String>();
    TestAction testAction = new TestAction(name);
    testAction.actionPerformed(event);
    assertLogged("sendEvent(myAction, {VSO.Plugin.Property.Name=myAction})");

    // Verify behavior: exception in actionPerformed sends the start event and then logs the
    // exception
    name = "myAction2";
    testAction = new TestAction(name);
    testAction.setThrowOnActionPerformed(true);
    testAction.actionPerformed(event);
    assertLogged(
        "sendEvent(myAction2, {VSO.Plugin.Property.Name=myAction2})sendException(throwOnActionPerformed, {VSO.Plugin.Property.Name=myAction2})");
  }
Example #5
0
  public void testUpdateListPipe() throws Exception {
    ActionHelper sah = new ActionHelper();
    sah.setUpAction(action);
    sah.setupClampListBounds();
    sah.getRequest().setRequestURL("foo");
    sah.getRequest()
        .setupAddParameter("items_selected", new String[] {"777|999", "99|555", "666|77656"});
    sah.getRequest().setupAddParameter("newset", (String) null);
    sah.getRequest().setupAddParameter("items_on_page", (String) null);
    sah.executeAction("updatelist");

    // let's go find the data
    verifyRhnSetData(sah.getUser().getId(), action.getSetDecl().getLabel(), 3);
  }
Example #6
0
  public void testUpdateList() throws Exception {
    // TestAction action = new TestAction();
    ActionHelper sah = new ActionHelper();
    sah.setUpAction(action);
    sah.setupClampListBounds();
    sah.getRequest().setRequestURL("foo");
    sah.getRequest().setupAddParameter("items_selected", new String[] {"10", "20", "30"});
    sah.getRequest().setupAddParameter("newset", (String) null);
    sah.getRequest().setupAddParameter("items_on_page", (String) null);
    ActionForward forward = sah.executeAction("updatelist");

    // let's go find the data
    verifyRhnSetData(sah.getUser().getId(), action.getSetDecl().getLabel(), 3);
    verifyParam(forward.getPath(), "setupdated", "true");
  }
  @SuppressWarnings({"unchecked", "unchecked"})
  public void test() throws Exception {
    // request
    setRequestContent("json-1.txt");
    this.request.addHeader("content-type", "application/json");

    // interceptor
    JSONInterceptor interceptor = new JSONInterceptor();
    TestAction action = new TestAction();

    this.invocation.setAction(action);
    this.invocation.getStack().push(action);

    interceptor.intercept(this.invocation);

    // serialize and compare
    List list = action.getList();

    assertNotNull(list);
    assertEquals(list.size(), 10);

    list = action.getCollection();
    assertNotNull(list);
    assertEquals(list.size(), 3);
    assertEquals(list.get(0), "b");
    assertEquals(list.get(1), 1L);
    list = (List) list.get(2);
    assertNotNull(list);
    assertEquals(list.size(), 2);
    assertEquals(list.get(0), 10L);
    assertEquals(list.get(1), 12L);

    list = action.getCollection2();
    assertNotNull(list);
    assertEquals(list.size(), 1);

    // inside a map any primitive is either: String, Long, Boolean or Double
    Map bean = (Map) list.get(0);

    assertNotNull(bean);
    assertTrue((Boolean) bean.get("booleanField"));
    assertEquals(bean.get("charField"), "s");
    assertEquals(bean.get("doubleField"), 10.1);
    assertEquals(bean.get("floatField"), 1.5);
    assertEquals(bean.get("intField"), 10L);
    assertEquals(bean.get("longField"), 100L);
    assertEquals(bean.get("stringField"), "str");

    bean = (Map) bean.get("objectField");
    assertNotNull(bean);
    assertFalse((Boolean) bean.get("booleanField"));
    assertEquals(bean.get("charField"), "\u0000");
    assertEquals(bean.get("doubleField"), 2.2);
    assertEquals(bean.get("floatField"), 1.1);
    assertEquals(bean.get("intField"), 0L);
    assertEquals(bean.get("longField"), 0L);
    assertEquals(bean.get("stringField"), "  ");

    assertEquals(action.getFoo(), "foo");

    Map map = action.getMap();

    assertNotNull(map);
    assertEquals(map.size(), 2);
    assertEquals(map.get("a"), 1L);
    list = (List) map.get("c");
    assertNotNull(list);
    assertEquals(list.size(), 2);
    assertEquals(list.get(0), 1.0);
    assertEquals(list.get(1), 2.0);

    assertEquals(action.getResult(), null);

    Bean bean2 = action.getBean();

    assertNotNull(bean2);
    assertTrue(bean2.isBooleanField());
    assertEquals(bean2.getStringField(), "test");
    assertEquals(bean2.getIntField(), 10);
    assertEquals(bean2.getCharField(), 's');
    assertEquals(bean2.getDoubleField(), 10.1);
    assertEquals(bean2.getByteField(), 3);

    String[] strArray = action.getArray();

    assertNotNull(strArray);
    assertEquals(strArray.length, 2);
    assertEquals(strArray[0], "str0");
    assertEquals(strArray[1], "str1");

    int[] intArray = action.getIntArray();

    assertNotNull(intArray);
    assertEquals(intArray.length, 2);
    assertEquals(intArray[0], 1);
    assertEquals(intArray[1], 2);

    Bean[] beanArray = action.getBeanArray();

    assertNotNull(beanArray);
    assertNotNull(beanArray[0]);
    assertEquals(beanArray[0].getStringField(), "bean1");
    assertNotNull(beanArray[1]);
    assertEquals(beanArray[1].getStringField(), "bean2");

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(action.getDate());

    assertEquals(calendar.get(Calendar.YEAR), 1999);
    assertEquals(calendar.get(Calendar.MONTH), Calendar.DECEMBER);
    assertEquals(calendar.get(Calendar.DAY_OF_MONTH), 31);
    assertEquals(calendar.get(Calendar.HOUR), 11);
    assertEquals(calendar.get(Calendar.MINUTE), 59);
    assertEquals(calendar.get(Calendar.SECOND), 59);

    calendar.setTime(action.getDate2());
    assertEquals(calendar.get(Calendar.YEAR), 1999);
    assertEquals(calendar.get(Calendar.MONTH), Calendar.DECEMBER);
    assertEquals(calendar.get(Calendar.DAY_OF_MONTH), 31);

    // test desrialize=false
    assertNull(action.getFoo2());
  }