コード例 #1
0
  @Test
  public void testLoadRepresentationsWithIds() {
    ArrayList<String> repIds = null;
    List<Representation> reps = null;
    try {
      // prepare a list of ids
      Model m = papi.loadCompleteModelWithDbId(mockModelId);
      repIds = new ArrayList<String>();
      for (Revision r : m.getRevisions()) {
        Representation oneRep = r.getRepresentations().iterator().next();
        repIds.add(oneRep.getDbId());
      }
      // load list
      reps = papi.loadRepresentations(repIds);
      assertEquals(reps.size(), repIds.size());
      for (Representation rep : reps) {
        assertTrue(repIds.contains(rep.getDbId()));
        assertEquals(rep.getModel().getDbId(), mockModelId);
      }
      // empty list
      reps = papi.loadRepresentations(new ArrayList<String>());
      assertTrue(reps.isEmpty());
    } catch (Exception e) {
      fail(e.getMessage());
    }

    try {
      // non-existent representation id
      repIds.add(wrongRepId);
      reps = papi.loadRepresentations(repIds);
      fail();
    } catch (IllegalArgumentException e) {
      assert (true);
    }

    try {
      // non-existent id
      repIds.add(NonExistentClusterId);
      reps = papi.loadRepresentations(repIds);
      fail();
    } catch (IllegalArgumentException e) {
      assert (true);
    }
    try {
      // wrong input
      repIds.add(AbcId);
      reps = papi.loadRepresentations(repIds);
      fail();
    } catch (IllegalArgumentException e) {
      assert (true);
    }
  }
コード例 #2
0
  @Test
  public void testLoadRepresentationsWithConfig() {
    try {
      // create config according to saved representation
      Representation mockRepresentation = RepresentationFactory.createLightweightRepresentation();

      DbFilterConfig config = new DbFilterConfig();
      config.addFormat(mockRepresentation.getFormat());
      config.addOrigin(mockRepresentation.getModel().getOrigin());
      config.addNotation(mockRepresentation.getNotation());

      // load
      List<Representation> results = papi.loadRepresentations(config);
      Representation rep = results.get(0);
      Revision rev = rep.getRevision();
      Model mod = rep.getModel();
      assertTrue(results.size() > 0);
      assertEquals(rep.getFormat(), (mockRepresentation.getFormat()));
      assertEquals(rep.getNotation(), mockRepresentation.getNotation());
      assertEquals(mod.getOrigin(), mockRepresentation.getModel().getOrigin());
      assertEquals(
          mod.getLatestRevision(),
          rev); // because the mockRepresentation's model has only 1 revision
    } catch (Exception e) {
      fail(e.getMessage());
    }
  }