示例#1
0
  /**
   * Can be used to substitute the predicate of all the triplets with a specific predicate.
   *
   * <p>------------------------------------------------------------------- IMPORTANT: If modified,
   * this documentation must also be modified in the class GActionType.
   * -------------------------------------------------------------------
   *
   * <p>parameters expected:
   *
   * <ul>
   *   <li>old_uri: the URI predicate to replace
   *   <li>new_uri: the new URI predicate
   * </ul>
   *
   * You can use RDFS.SUBCLASSOF to refer to http://www.w3.org/2000/01/rdf-schema#subClassOf
   *
   * @param factory
   * @param action
   * @param g
   * @throws SLIB_Ex_Critic
   */
  private static void predicateSubstitution(URIFactory factory, GAction action, G g)
      throws SLIB_Ex_Critic {

    logger.info("-------------------------------------");
    logger.info(" Predicate Substitution");
    logger.info("-------------------------------------");
    logger.info("Starting " + GActionType.PREDICATE_SUBSTITUTE);

    String old_URI = (String) action.getParameter("old_uri");
    String new_URI = (String) action.getParameter("new_uri");

    if (old_URI == null || new_URI == null) {
      throw new SLIB_Ex_Critic("Error - please specify a parameter old_uri and new_uri");
    }

    if (old_URI.toUpperCase().equals("RDFS.SUBCLASSOF")) {
      old_URI = RDFS.SUBCLASSOF.toString();
    }
    if (new_URI.toUpperCase().equals("RDFS.SUBCLASSOF")) {
      new_URI = RDFS.SUBCLASSOF.toString();
    }

    URI oldURI = factory.getURI(old_URI);
    URI newURI = factory.getURI(new_URI);

    Set<E> oldRel = g.getE(oldURI);
    g.removeE(oldRel);

    for (E e : oldRel) {
      g.addE(e.getSource(), newURI, e.getTarget());
    }

    logger.info(oldRel.size() + " relations modified");
  }
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:config/bootstrap.xml"})
public class PublishServiceTestCase extends TestCase {

  @Autowired
  @Qualifier("system_fact")
  private Properties systemProps;

  @Autowired private PublishService service;
  @Autowired private AGraphDao dao;

  private static final String RAW_STR_1 =
      "<http://www.test.org/devGraph2><http://www.test.org/testClass1><"
          + RDFS.SUBCLASSOF.toString()
          + "><http://www.test.org/testClass2>";
  private static final String RAW_STR_2 =
      "<http://www.test.org/devGraph2><http://www.test.org/testInstance1><?p><http://www.test.org/testClass1>";
  private static final String RAW_STR_TOTAL = RAW_STR_1 + "," + RAW_STR_2;
  private static final String MOCK_UUID = "mark4";
  private String strToPub = "";

  @Before
  public void prepare() {
    this.strToPub =
        RAW_STR_TOTAL.replace(
            "?p", systemProps.getProperty("agraph.server.graph.subscribe.predicate"));
  }

  //	@Test
  //	public void testDoPublishWithoutNotification() throws ServiceException,
  // AGraphDataAccessException, ParameterException {
  //		service.doPublish(strToPub, MOCK_UUID, false, false);
  //
  //		List<String> superClass = this.dao.getImmediateClass(
  //				new IRI("<http://www.test.org/testClass1>", MOCK_UUID),
  //				"http://www.test.org/devGraph2",
  //				MOCK_UUID);
  //		assertNotNull(superClass);
  //		assertEquals(1, superClass.size());
  //		assertEquals("http://www.test.org/testClass2", superClass.get(0));
  //
  //		List<String> subscribers = this.dao.getSubscriberIRI("http://www.test.org/testClass1",
  // MOCK_UUID);
  //		assertNotNull(subscribers);
  //		assertEquals(1, subscribers.size());
  //		assertEquals("http://www.test.org/testInstance1", subscribers.get(0));
  //	}

  @After
  public void cleanup() throws ParameterException, AGraphDataAccessException {
    List<Quad> quads = new ArrayList<Quad>();
    quads.add(new Quad(RAW_STR_1, MOCK_UUID));
    quads.add(
        new Quad(
            RAW_STR_2.replace(
                "?p", systemProps.getProperty("agraph.server.graph.subscribe.predicate")),
            MOCK_UUID));
    this.dao.removeQuads(quads, MOCK_UUID, false);
  }
}