Пример #1
0
  @Test
  public void isUpdateOperation() throws Exception {
    VmInputs vmInputs = new VmInputs.VmInputsBuilder().withOperation("add").build();
    boolean isUpdate = InputUtils.isUpdateOperation(vmInputs);

    assertFalse(isUpdate);
  }
Пример #2
0
  @Test
  public void getLongInputException() throws RuntimeException {
    exception.expect(RuntimeException.class);
    exception.expectMessage("The input value must be a long number.");

    InputUtils.getLongInput("Still doesn't work in this way", 0);
  }
Пример #3
0
  @Test
  public void getDiskFileNameString() {
    String testDiskFileNameString =
        InputUtils.getDiskFileNameString("someDataStore", "testVM", "Renamed");

    assertEquals("[someDataStore] testVM/Renamed.vmdk", testDiskFileNameString);
  }
 /**
  * A private method to read the connection string parameter from the web.xml file
  *
  * @return the database connection string
  */
 private String getConnectionString() {
   if (InputUtils.isValid(rdf.getContextParam("databaseConnectionString")) == false) {
     throw new RuntimeException(
         "Unable to read the connection string parameter from the web.xml file");
   } else {
     return rdf.getContextParam("databaseConnectionString");
   }
 }
Пример #5
0
  @Test
  public void checkValidOperation() throws Exception {
    exception.expect(RuntimeException.class);
    exception.expectMessage(
        "Invalid operation specified for disk device. The disk device can be only added or removed.");

    VmInputs vmInputs =
        new VmInputs.VmInputsBuilder().withDevice("disk").withOperation("update").build();
    InputUtils.checkValidOperation(vmInputs, "disk");
  }
Пример #6
0
  @Test
  public void validateDiskInputsRemove() throws Exception {
    exception.expect(RuntimeException.class);
    exception.expectMessage("The [] is not a valid disk label.");

    VmInputs vmInputs =
        new VmInputs.VmInputsBuilder()
            .withVirtualMachineName("testVM")
            .withOperation("remove")
            .withDevice("disk")
            .withUpdateValue("")
            .build();
    InputUtils.validateDiskInputs(vmInputs);
  }
Пример #7
0
  @Test
  public void validateDiskInputsAdd() throws Exception {
    exception.expect(RuntimeException.class);
    exception.expectMessage("The disk size must be positive long.");

    VmInputs vmInputs =
        new VmInputs.VmInputsBuilder()
            .withVirtualMachineName("testVM")
            .withOperation("add")
            .withDevice("disk")
            .withLongVmDiskSize("0")
            .withDiskMode("persistent")
            .build();
    InputUtils.validateDiskInputs(vmInputs);
  }
Пример #8
0
  @Test
  public void getUrlStringSuccess() throws Exception {
    HttpInputs httpInputs =
        new HttpInputs.HttpInputsBuilder()
            .withHost("vc6.subdomain.example.com")
            .withPort("443")
            .withProtocol("")
            .withUsername("")
            .withPassword("")
            .withTrustEveryone("false")
            .build();
    String testUrl = InputUtils.getUrlString(httpInputs);

    assertEquals("https://vc6.subdomain.example.com:443/sdk", testUrl);
  }
Пример #9
0
  @Test
  public void getUrlStringException() throws Exception {
    exception.expect(Exception.class);
    exception.expectMessage(
        "Unsupported protocol value: [myProtocol]. Valid values are: https, http.");

    HttpInputs httpInputs =
        new HttpInputs.HttpInputsBuilder()
            .withHost("")
            .withPort("8080")
            .withProtocol("myProtocol")
            .withUsername("")
            .withPassword("")
            .withTrustEveryone("true")
            .build();
    InputUtils.getUrlString(httpInputs);
  }
  /**
   * A method to build a list of Collaboration objects representing a list of collaborations
   * associated with a collaborator
   *
   * @param id the unique identifier of a collaborator
   * @return a CollaborationList object containing a list of Collaboration objects
   */
  public CollaborationList getCollaborationList_org(String org_id, String id) {

    // check on the input parameters
    if (InputUtils.isValidInt(id) == false) {
      throw new IllegalArgumentException("The id parameter cannot be null");
    }

    // declare helper variables
    CollaborationList list = new CollaborationList(id);

    // define other helper variables
    Collaboration collaboration = null;

    // define other helper variables
    String partner = null;
    Integer count = null;
    String firstDate = null;
    String lastDate = null;

    // define the base sql query
    String sqlQuery =
        "SELECT distinct count(*), con.contributorid, min(e.first_date), max(e.first_date) "
            + "FROM contributor con, conevlink c , conevlink c2, orgevlink o, events e "
            + "WHERE o.organisationid = ? " // + org_id + " "
            + "AND c.eventid = O.EVENTID "
            + "AND e.eventid = O.EVENTID "
            + "AND e.eventid = c.EVENTID "
            + "AND c.contributorid != ?" // + id + " "
            + "AND con.contributorid = c.contributorid "
            + "AND c2.contributorid = ? " // + id + " "
            + "AND c2.eventid = c.eventid "
            + "GROUP BY con.contributorid, con.first_name ";

    int[] param = {Integer.parseInt(org_id), Integer.parseInt(id), Integer.parseInt(id)};
    // execute the query
    java.sql.ResultSet resultSet = db.exePreparedStatement(sqlQuery, param);

    try {
      //		 	check to see that data was returned
      if (!resultSet.last()) {
        db.tidyup();
        return null;
      } else resultSet.beforeFirst();

      // loop though the resulset
      while (resultSet.next()) {
        // get the data
        partner = resultSet.getString(2);
        count = resultSet.getInt(1);
        firstDate = resultSet.getDate(3).toString();
        lastDate = resultSet.getDate(4).toString();

        // create the collaboration object
        collaboration = new Collaboration(id, partner, count, firstDate, lastDate);

        // add the collaboration to the list
        list.addCollaboration(collaboration);
      }

    } catch (java.sql.SQLException ex) {
      System.out.println("Exception: " + ex.getMessage());
      resultSet = null;
    }

    db.tidyup();
    // return the list of collaborations
    return list;
  } // end the CollaborationList method
Пример #11
0
  @Test
  public void getSuccessfullyDefaultDelimiter() {
    String testDelimiter = InputUtils.getDefaultDelimiter("", ",");

    assertEquals(",", testDelimiter);
  }
  /**
   * A method to build a collection of collaborator objects representing a network based on an
   * organisation
   *
   * @param id the id of the central organisation
   * @param radius the number of edges required from the central contributor
   * @return the collection of collaborator objects
   */
  @SuppressWarnings("rawtypes")
  public TreeMap<Integer, Collaborator> getRawCollaboratorData_org(String id, int radius) {

    // check the parameters
    if (InputUtils.isValidInt(id) == false) {
      throw new IllegalArgumentException("Error: the id parameter is required");
    }

    if (InputUtils.isValidInt(radius, ExportServlet.MIN_DEGREES, ExportServlet.MAX_DEGREES)
        == false) {
      throw new IllegalArgumentException(
          "Error: the radius parameter must be between "
              + ExportServlet.MIN_DEGREES
              + " and "
              + ExportServlet.MAX_DEGREES);
    }

    // define helper variables
    // collection of collaborators
    java.util.TreeMap<Integer, Collaborator> cId_cObj_map =
        new java.util.TreeMap<Integer, Collaborator>();

    // set of collaborators that we've already processed
    java.util.TreeSet<Integer> foundCollaboratorsSet = new java.util.TreeSet<Integer>();

    // define other helper variables
    String contributor_id = null;
    QuerySolution row = null;
    Collaborator collaborator = null;

    String sql =
        "SELECT DISTINCT b.eventid   "
            + "FROM events a, orgevlink b "
            + "WHERE b.organisationid = ? " // +id
            + "AND a.eventid = b.eventid";

    int[] param = {Integer.parseInt(id)};
    java.sql.ResultSet resultSet = db.exePreparedStatement(sql, param);

    ArrayList<String> eventResults = new ArrayList<String>();

    try {
      //		 	check to see that data was returned
      if (!resultSet.last()) {
        db.tidyup();
        return null;
      } else resultSet.beforeFirst();

      // loop through the resultset
      while (resultSet.next() == true) {
        eventResults.add(resultSet.getString(1));
      }

    } catch (java.sql.SQLException ex) {
      System.out.println("Exception: " + ex.getMessage());
      resultSet = null;
    }

    db.tidyup();

    // helper
    int first = 0;

    // define the query
    String sparqlQuery1 =
        "PREFIX foaf:       <"
            + FOAF.NS
            + "> "
            + "PREFIX ausestage:  <"
            + AuseStage.NS
            + "> "
            + "PREFIX event:      <http://purl.org/NET/c4dm/event.owl#> "
            + "PREFIX dcterms:    <http://purl.org/dc/terms/> "
            + "SELECT DISTINCT ?agent ?givenName ?familyName "
            + "WHERE { ";
    for (String event : eventResults) {
      if (first > 0) {
        sparqlQuery1 += "UNION ";
      }
      first++;

      sparqlQuery1 +=
          "{<ausstage:e:"
              + event
              + "> a                event:Event; "
              + "   event:agent      ?agent. "
              + "	?agent             a                foaf:Person; "
              + "   foaf:givenName   ?givenName; "
              + "   foaf:familyName  ?familyName. "
              + " } ";
    }
    sparqlQuery1 += " } ";

    // execute query
    ResultSet results = rdf.executeSparqlQuery(sparqlQuery1);

    // now we transfer the results to a TreeMap <Integer,
    while (results.hasNext()) {

      row = results.nextSolution();

      contributor_id = AusStageURI.getId(row.get("agent").toString());

      collaborator = new Collaborator(contributor_id);

      cId_cObj_map.put(Integer.parseInt(contributor_id), collaborator);
      foundCollaboratorsSet.add(Integer.parseInt(contributor_id));
    }

    rdf.tidyUp();

    return cId_cObj_map;
  } // end getRawCollaboratorData_org method
Пример #13
0
 @Test
 public void getLongInputDefault() {
   long testLong = InputUtils.getLongInput("", 1024L);
   assertEquals(1024L, testLong);
 }
Пример #14
0
 @Test
 public void getLongInput() {
   long testLong = InputUtils.getLongInput("4096", 1024L);
   assertEquals(4096L, testLong);
 }
Пример #15
0
 @Test
 public void getIntInputDefault() {
   int testInt = InputUtils.getIntInput("", 1024);
   assertEquals(1024, testInt);
 }
Пример #16
0
  @Test
  public void isIntFalse() {
    boolean isUpdate = InputUtils.isInt("2147483648");

    assertFalse(isUpdate);
  }
Пример #17
0
 @Test
 public void getIntInput() {
   int testInt = InputUtils.getIntInput("4096", 1024);
   assertEquals(4096, testInt);
 }
Пример #18
0
  @Test
  public void isIntTrue() {
    boolean isUpdate = InputUtils.isInt("2147483647");

    assertTrue(isUpdate);
  }