@Test public void shouldFailProcess() throws IOException, ProcessSubtreeException, LexerException, ParserConfigurationException, SAXException, RepositoryException { StatisticsAccessLog acLog = EasyMock.createMock(StatisticsAccessLog.class); ProcessingIndexFeeder feeder = createMock(ProcessingIndexFeeder.class); CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().build(); cacheManager.init(); HazelcastServerNode.ensureHazelcastNode(); FedoraAccessAkubraImpl fa4 = createMockBuilder(FedoraAccessAkubraImpl.class) .withConstructor(KConfiguration.getInstance(), feeder, acLog, cacheManager) .addMockedMethod("getRelsExt") .addMockedMethod("isStreamAvailable") .addMockedMethod("isObjectAvailable") .createMock(); notConsistentNarodniListyRelsExt(fa4); for (int i = 0; i < ImportDataPrepare.NARODNI_LISTY.length; i++) { EasyMock.expect(fa4.isObjectAvailable(ImportDataPrepare.NARODNI_LISTY[i])).andReturn(true).anyTimes(); } SolrAccess solrAccess = EasyMock.createMock(SolrAccess.class); Set<String> keys = ImportDataPrepare.PATHS_MAPPING.keySet(); for (String key : keys) { EasyMock.expect(solrAccess.getPath(key)).andReturn(new ObjectPidsPath[] { ImportDataPrepare.PATHS_MAPPING.get(key) }).anyTimes(); } replay(fa4,feeder, solrAccess); Consistency consistency = new Consistency(); Injector injector = Guice.createInjector(new _Module(fa4, solrAccess)); injector.injectMembers(consistency); List<NotConsistentRelation> notConsitent = consistency.checkConsitency("uuid:b2f18fb0-91f6-11dc-9f72-000d606f5dc6", false); Assert.assertTrue(!notConsitent.isEmpty()); Assert.assertTrue(notConsitent.size() == ImportDataPrepare.NARODNI_LISTY_NOT_EXISTS.length); }
public List<NotConsistentRelation> checkConsitency(String rootPid, boolean repair) throws IOException, ProcessSubtreeException, LexerException, RepositoryException { TreeProcess deep = new TreeProcess(this.fedoraAccess); this.fedoraAccess.processSubtree(rootPid, deep); List<NotConsistentRelation> relations = deep.getRelations(); if (repair) { LOGGER.fine("deleting inconsitencies"); for (NotConsistentRelation nRelation : relations) { List<String> children = nRelation.getChildren(); List<Triple<String, String, String>> objectRelations = fedoraAccess.getInternalAPI().getObject(nRelation.getRootPid()).getRelations(null); for (Triple<String, String, String> t : objectRelations) { if (children.contains(t.getRight())) { fedoraAccess.getInternalAPI().getObject(nRelation.getRootPid()).removeRelation(t.getMiddle(), t.getLeft(), t.getRight()); if (fedoraAccess.getInternalAPI().getObject(nRelation.getRootPid()).relationExists(t.getMiddle(), t.getLeft(), t.getRight())) { throw new RuntimeException("cannot delete relation "); } } } } } return relations; }
Consistency { public List<NotConsistentRelation> checkConsitency(String rootPid, boolean repair) throws IOException, ProcessSubtreeException, LexerException, RepositoryException { TreeProcess deep = new TreeProcess(this.fedoraAccess); this.fedoraAccess.processSubtree(rootPid, deep); List<NotConsistentRelation> relations = deep.getRelations(); if (repair) { LOGGER.fine("deleting inconsitencies"); for (NotConsistentRelation nRelation : relations) { List<String> children = nRelation.getChildren(); List<Triple<String, String, String>> objectRelations = fedoraAccess.getInternalAPI().getObject(nRelation.getRootPid()).getRelations(null); for (Triple<String, String, String> t : objectRelations) { if (children.contains(t.getRight())) { fedoraAccess.getInternalAPI().getObject(nRelation.getRootPid()).removeRelation(t.getMiddle(), t.getLeft(), t.getRight()); if (fedoraAccess.getInternalAPI().getObject(nRelation.getRootPid()).relationExists(t.getMiddle(), t.getLeft(), t.getRight())) { throw new RuntimeException("cannot delete relation "); } } } } } return relations; } }
Consistency { public List<NotConsistentRelation> checkConsitency(String rootPid, boolean repair) throws IOException, ProcessSubtreeException, LexerException, RepositoryException { TreeProcess deep = new TreeProcess(this.fedoraAccess); this.fedoraAccess.processSubtree(rootPid, deep); List<NotConsistentRelation> relations = deep.getRelations(); if (repair) { LOGGER.fine("deleting inconsitencies"); for (NotConsistentRelation nRelation : relations) { List<String> children = nRelation.getChildren(); List<Triple<String, String, String>> objectRelations = fedoraAccess.getInternalAPI().getObject(nRelation.getRootPid()).getRelations(null); for (Triple<String, String, String> t : objectRelations) { if (children.contains(t.getRight())) { fedoraAccess.getInternalAPI().getObject(nRelation.getRootPid()).removeRelation(t.getMiddle(), t.getLeft(), t.getRight()); if (fedoraAccess.getInternalAPI().getObject(nRelation.getRootPid()).relationExists(t.getMiddle(), t.getLeft(), t.getRight())) { throw new RuntimeException("cannot delete relation "); } } } } } return relations; }  }
Consistency { public List<NotConsistentRelation> checkConsitency(String rootPid, boolean repair) throws IOException, ProcessSubtreeException, LexerException, RepositoryException { TreeProcess deep = new TreeProcess(this.fedoraAccess); this.fedoraAccess.processSubtree(rootPid, deep); List<NotConsistentRelation> relations = deep.getRelations(); if (repair) { LOGGER.fine("deleting inconsitencies"); for (NotConsistentRelation nRelation : relations) { List<String> children = nRelation.getChildren(); List<Triple<String, String, String>> objectRelations = fedoraAccess.getInternalAPI().getObject(nRelation.getRootPid()).getRelations(null); for (Triple<String, String, String> t : objectRelations) { if (children.contains(t.getRight())) { fedoraAccess.getInternalAPI().getObject(nRelation.getRootPid()).removeRelation(t.getMiddle(), t.getLeft(), t.getRight()); if (fedoraAccess.getInternalAPI().getObject(nRelation.getRootPid()).relationExists(t.getMiddle(), t.getLeft(), t.getRight())) { throw new RuntimeException("cannot delete relation "); } } } } } return relations; }  List<NotConsistentRelation> checkConsitency(String rootPid, boolean repair); @Process static void process(String pid, Boolean flag); static void main(String[] args); }
Consistency { public List<NotConsistentRelation> checkConsitency(String rootPid, boolean repair) throws IOException, ProcessSubtreeException, LexerException, RepositoryException { TreeProcess deep = new TreeProcess(this.fedoraAccess); this.fedoraAccess.processSubtree(rootPid, deep); List<NotConsistentRelation> relations = deep.getRelations(); if (repair) { LOGGER.fine("deleting inconsitencies"); for (NotConsistentRelation nRelation : relations) { List<String> children = nRelation.getChildren(); List<Triple<String, String, String>> objectRelations = fedoraAccess.getInternalAPI().getObject(nRelation.getRootPid()).getRelations(null); for (Triple<String, String, String> t : objectRelations) { if (children.contains(t.getRight())) { fedoraAccess.getInternalAPI().getObject(nRelation.getRootPid()).removeRelation(t.getMiddle(), t.getLeft(), t.getRight()); if (fedoraAccess.getInternalAPI().getObject(nRelation.getRootPid()).relationExists(t.getMiddle(), t.getLeft(), t.getRight())) { throw new RuntimeException("cannot delete relation "); } } } } } return relations; }  List<NotConsistentRelation> checkConsitency(String rootPid, boolean repair); @Process static void process(String pid, Boolean flag); static void main(String[] args);  }