Exemplo n.º 1
0
 @Test
 public void testGetActivity() {
   JavaScriptPreviewPage previewPage = executeSnippet(SNIPPET_ID);
   JsonJavaObject json = previewPage.getJson();
   String activityNodeId = json.getAsString("getActivityNodeUuid");
   Assert.assertNotNull(activityNodeId);
 }
  public ArrayList<String[]> getSuggestedTags(JsonJavaObject data) {
    // ArrayList that will contain the set of classifiers and scores
    ArrayList<String[]> tags = new ArrayList<String[]>();

    // The data is returned as JSON with a root element of 'images'
    JsonJavaArray images = data.getAsArray("images");
    if (images != null) {
      // For each image, there is a set of scores in the JSON
      JsonJavaArray classifiers = images.getAsObject(0).getAsArray("classifiers");

      if (classifiers != null) {
        JsonJavaArray classes = classifiers.getAsObject(0).getAsArray("classes");
        if (classes != null) {
          // From the scores, get the 'name' of the classifier and it's associated 'score'
          for (int i = 0; i < classes.size(); i++) {
            JsonJavaObject jsonObj = classes.getAsObject(i);
            String tagName = jsonObj.getAsString("class");
            double score = jsonObj.getAsDouble("score");

            // Filter out classifiers with a match < 90%
            // if (score > 0.90) {
            // Add the classifier name and score to the ArrayList
            String[] tagInfo = new String[2];
            tagInfo[0] = tagName;
            tagInfo[1] = "" + score;
            tags.add(tagInfo);
            // }
          }
        }
      }
    }
    return tags;
  }
Exemplo n.º 3
0
  @Test
  public void DeleteProfileWithMissingArguments() {
    addSnippetParam("sample.createProfileId", "");

    JavaScriptPreviewPage previewPage = executeSnippet(SNIPPET_ID);
    JsonJavaObject json = previewPage.getJson();
    Assert.assertEquals(400, json.getInt("code"));
  }
  public JsonJavaObject getResponseJson(String action, boolean status, String message) {
    JsonJavaObject returnJSON = new JsonJavaObject();
    returnJSON.put("action", action);
    returnJSON.put("status", Boolean.toString(status));
    returnJSON.put("message", message);

    return returnJSON;
  }
Exemplo n.º 5
0
  @Test
  public void testCreateForumTopic() {
    addSnippetParam("ForumService.forumUuid", forum.getForumUuid());

    JavaScriptPreviewPage previewPage = executeSnippet(SNIPPET_ID);
    JsonJavaObject json = previewPage.getJson();
    Assert.assertNull("Unexpected error detected on page", json.getString("code"));
    assertForumTopicProperties(json);
  }
Exemplo n.º 6
0
  @Test
  public void testGetForumTopicInvalidArg() {
    addSnippetParam("ForumService.topicUuid", "");

    JavaScriptPreviewPage previewPage = executeSnippet(SNIPPET_ID);
    JsonJavaObject json = previewPage.getJson();
    Assert.assertEquals(400, json.getInt("code"));
    Assert.assertEquals("Invalid argument, expected topicUuid.", json.getString("message"));
  }
Exemplo n.º 7
0
  @Test
  public void testCommunityNewSave() {
    JavaScriptPreviewPage previewPage = executeSnippet(SNIPPET_ID);
    JsonJavaObject json = previewPage.getJson();
    Assert.assertNull("Unexpected error detected on page", json.getString("code"));

    community = getCommunity(json.getString("getCommunityUuid"));
    assertCommunityValid(json);
  }
Exemplo n.º 8
0
 @Test
 public void testBaseServiceEndpoint() {
   JavaScriptPreviewPage previewPage = executeSnippet(SNIPPET_ID);
   List jsonList = previewPage.getJsonList();
   Assert.assertEquals(2, jsonList.size());
   JsonJavaObject json = (JsonJavaObject) jsonList.get(0);
   Assert.assertEquals("connections", json.getJsonObject("endpoint").getString("name"));
   json = (JsonJavaObject) jsonList.get(1);
   Assert.assertEquals("connections", json.getJsonObject("endpoint").getString("name"));
 }
Exemplo n.º 9
0
  @Test
  public void testGetForumTopicError() {
    addSnippetParam("ForumService.topicUuid", "Foo");

    JavaScriptPreviewPage previewPage = executeSnippet(SNIPPET_ID);
    JsonJavaObject json = previewPage.getJson();
    Assert.assertEquals(404, json.getInt("code"));
    Assert.assertEquals(
        "No existing forum found. Please contact your system administrator.",
        json.getString("message"));
  }
Exemplo n.º 10
0
  @Test
  public void testRegisterCustomer() {
    try {
      CustomerJsonBuilder customer = new CustomerJsonBuilder();
      customer
          .setOrgName("Abe Industrial")
          .setPhone("999-999-9999")
          .setOrganizationAddressLine1("5 Technology Park Drive")
          .setOrganizationAddressLine2("")
          .setOrganizationAddressType(CustomerManagementService.AddressType.MAILING)
          .setOrganizationCity("Westford")
          .setOrganizationCountry("United States")
          .setOrganizationPostalCode("01866")
          .setOrganizationState("Massachusetts")
          .setContactFamilyName("Ninty")
          .setContactGivenName("Joe")
          .setContactEmailAddress(getUniqueEmail())
          .setContactNamePrefix("Mr")
          .setContactEmployeeNumber("6A77777")
          .setContactLanguagePreference("EN_US")
          .setContactWorkPhone("800-555-1234")
          .setContactMobilePhone("800-555-2345")
          .setContactHomePhone("800-555-3456")
          .setContactFax("800-555-4567")
          .setContactJobTitle("Director")
          .setContactWebSiteAddress("joeninty.example.com")
          .setContactTimeZone("America/Central")
          .setContactPhoto("")
          .setCustomerAccountNumber("0000123457")
          .setCustomerAccountLocationName("Westford Lab")
          .setCustomerAccountPaymentMethodType(CustomerManagementService.PaymentMethodType.INVOICE)
          .setCustomerAccountCurrencyType("USD")
          .setCustomerIdentifierType(CustomerManagementService.CustomerIdType.IBM_CUSTOMER_NUMBER)
          .setCustomerIdentifierValue("9999999999");

      JsonJavaObject response = getCustomerManagementService().registerCustomer(customer);
      long customerId = response.getAsLong("Long");
      Assert.assertNotNull("Invalid customer id", customerId);
      System.out.println(customerId);
    } catch (BssException be) {
      JsonJavaObject jsonObject = be.getResponseJson();
      System.err.println(jsonObject);
      // be.printStackTrace();
      Assert.fail("Error registering customer because: " + jsonObject);
    } catch (Exception e) {
      e.printStackTrace();
      Assert.fail("Error registering customer caused by: " + e.getMessage());
    }
  }
Exemplo n.º 11
0
 @Test
 @Ignore
 public void testBaseEntity() {
   JavaScriptPreviewPage previewPage = executeSnippet(SNIPPET_ID);
   List jsonList = previewPage.getJsonList();
   for (int i = 0; i < jsonList.size(); i++) {
     JsonJavaObject json = (JsonJavaObject) jsonList.get(i);
     Iterator<String> properties = json.getProperties();
     if (properties.hasNext() && Results[i][1] != null) {
       String property = properties.next();
       Object value = json.get(property);
       Assert.assertEquals(Results[i][0], property);
       Assert.assertEquals(
           "Match failed [" + i + "] name:" + property + " type:" + value.getClass(),
           Results[i][1],
           value);
     }
   }
 }
  public void doResponseWriteJson(JsonJavaObject jsonJavaObject) {
    try {
      PrintWriter out = res.getWriter();
      out.print(jsonToString(jsonJavaObject));
      out.close();

      if (jsonJavaObject.get("status").equals("true"))
        res.setStatus(HttpServletResponse.SC_ACCEPTED);
      else res.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  @Test
  public void testSuspendCustomer() {
    try {
      String customerId = registerCustomer();

      CustomerManagementService customerManagement = getCustomerManagementService();

      JsonEntity jsonEntity = customerManagement.getCustomerById(customerId);
      Assert.assertNotNull("Unable to retrieve customer: " + customerId, jsonEntity);
      Assert.assertEquals(customerId, customerManagement.getCustomerId(jsonEntity.getJsonObject()));

      customerManagement.suspendCustomer(customerId);

      jsonEntity = customerManagement.getCustomerById(customerId);
      Assert.assertNotNull("Unable to retrieve customer: " + customerId, jsonEntity);
      JsonJavaObject rootObject = jsonEntity.getJsonObject();

      JsonJavaObject customerObject = rootObject.getAsObject("Customer");
      System.out.println(customerObject);
      Assert.assertNotNull("No SuspensionDate", customerObject.get("SuspensionDate"));

      customerManagement.unsuspendCustomer(customerId);

      jsonEntity = customerManagement.getCustomerById(customerId);
      Assert.assertNotNull("Unable to retrieve customer: " + customerId, jsonEntity);
      rootObject = jsonEntity.getJsonObject();

      customerObject = rootObject.getAsObject("Customer");
      System.out.println(customerObject);
      Assert.assertNull("SuspensionDate", customerObject.get("SuspensionDate"));
      Assert.assertEquals("ACTIVE", customerObject.get("CustomerState"));

    } catch (BssException be) {
      JsonJavaObject jsonObject = be.getResponseJson();
      System.out.println(jsonObject);
      Assert.fail("Error suspending customer caused by: " + jsonObject);
    } catch (Exception e) {
      e.printStackTrace();
      Assert.fail("Error suspending customer caused by: " + e.getMessage());
    }
  }
Exemplo n.º 14
0
 @Test
 public void testAddMemberToActivity() {
   JavaScriptPreviewPage previewPage = executeSnippet(SNIPPET_ID);
   JsonJavaObject json = previewPage.getJson();
   Assert.assertEquals(json.getAsInt("status"), 201); // created
 }
Exemplo n.º 15
0
 @Test
 public void testGetBookmarksTags() {
   JavaScriptPreviewPage previewPage = executeSnippet(SNIPPET_ID);
   JsonJavaObject json = previewPage.getJson();
   Assert.assertNotNull(json.getString("tagTerm"));
 }
  @Test
  public void testUpdateSubscriberProfile() {
    try {
      registerCustomer();
      String subscriberId = addSubscriber();

      SubscriberManagementService subscriberManagement = getSubscriberManagementService();

      JsonEntity jsonEntity = subscriberManagement.getSubscriberById(subscriberId);
      Assert.assertNotNull("Unable to retrieve subscriber: " + subscriberId, jsonEntity);
      Assert.assertEquals(
          subscriberId, subscriberManagement.getSubscriberId(jsonEntity.getJsonObject()));

      JsonJavaObject rootObject = jsonEntity.getJsonObject();
      Assert.assertNotNull("Unable to retrieve subscriber: " + subscriberId, rootObject);

      System.out.println(rootObject);
      JsonJavaObject subscriberObject = rootObject.getAsObject("Subscriber");
      JsonJavaObject personObject = subscriberObject.getAsObject("Person");
      personObject.putString("GivenName", "Fred");
      personObject.putString("WorkPhone", "800-666-1234");

      subscriberManagement.updateSubscribeProfile(rootObject);

      jsonEntity = subscriberManagement.getSubscriberById(subscriberId);
      Assert.assertNotNull("Unable to retrieve subscriber: " + subscriberId, jsonEntity);
      Assert.assertEquals(
          subscriberId, subscriberManagement.getSubscriberId(jsonEntity.getJsonObject()));

      rootObject = jsonEntity.getJsonObject();
      Assert.assertNotNull("Unable to retrieve subscriber: " + subscriberId, subscriberObject);

      System.out.println(rootObject);
      subscriberObject = rootObject.getAsObject("Subscriber");
      personObject = subscriberObject.getAsObject("Person");
      Assert.assertEquals("Fred", personObject.getAsString("GivenName"));
      Assert.assertEquals("800-666-1234", personObject.getAsString("WorkPhone"));

    } catch (BssException be) {
      JsonJavaObject jsonObject = be.getResponseJson();
      System.out.println(jsonObject);
      Assert.fail("Error updating subscriber profile caused by: " + jsonObject);
    } catch (Exception e) {
      e.printStackTrace();
      Assert.fail("Error updating subscriber profile caused by: " + e.getMessage());
    }
  }
Exemplo n.º 17
0
 @Test
 public void testGetActivityMember() {
   JavaScriptPreviewPage previewPage = executeSnippet(SNIPPET_ID);
   JsonJavaObject json = previewPage.getJson();
   Assert.assertEquals(json.getAsString("getUserId"), id);
 }
Exemplo n.º 18
0
 @Test
 public void testUpdateActivityMember() {
   JavaScriptPreviewPage previewPage = executeSnippet(SNIPPET_ID);
   JsonJavaObject json = previewPage.getJson();
   Assert.assertEquals(json.getAsInt("status"), 200); // OK	
 }