@Test public void testAclTableEntries() throws Exception { String userTestNamespace = "userTestNsp"; Table acl = UTIL.getConnection().getTable(AccessControlLists.ACL_TABLE_NAME); try { ListMultimap<String, TablePermission> perms = AccessControlLists.getNamespacePermissions(conf, TEST_NAMESPACE); perms = AccessControlLists.getNamespacePermissions(conf, TEST_NAMESPACE); for (Map.Entry<String, TablePermission> entry : perms.entries()) { LOG.debug(entry); } assertEquals(6, perms.size()); // Grant and check state in ACL table grantOnNamespace(UTIL, userTestNamespace, TEST_NAMESPACE, Permission.Action.WRITE); Result result = acl.get(new Get(Bytes.toBytes(userTestNamespace))); assertTrue(result != null); perms = AccessControlLists.getNamespacePermissions(conf, TEST_NAMESPACE); assertEquals(7, perms.size()); List<TablePermission> namespacePerms = perms.get(userTestNamespace); assertTrue(perms.containsKey(userTestNamespace)); assertEquals(1, namespacePerms.size()); assertEquals(TEST_NAMESPACE, namespacePerms.get(0).getNamespace()); assertEquals(null, namespacePerms.get(0).getFamily()); assertEquals(null, namespacePerms.get(0).getQualifier()); assertEquals(1, namespacePerms.get(0).getActions().length); assertEquals(Permission.Action.WRITE, namespacePerms.get(0).getActions()[0]); // Revoke and check state in ACL table revokeFromNamespace(UTIL, userTestNamespace, TEST_NAMESPACE, Permission.Action.WRITE); perms = AccessControlLists.getNamespacePermissions(conf, TEST_NAMESPACE); assertEquals(6, perms.size()); } finally { acl.close(); } }
/** Test for mathematical expression in alignment */ @Test public void testMathematicalExpression() { Collection<? extends Cell> cells = alignment.getCells(); Iterator<? extends Cell> it = cells.iterator(); Cell cell = null; while (it.hasNext()) { Cell temp = it.next(); if (temp.getTransformationIdentifier() .equals("eu.esdihumboldt.cst.functions.numeric.mathexpression")) { cell = temp; break; } } ListMultimap<String, ParameterValue> params = cell.getTransformationParameters(); List<ParameterValue> values = params.get("expression"); // test the amount and the correctness of the parameter assertEquals(1, values.size()); String date = values.get(0).as(String.class); assertEquals("income * age/10", date); // test the amount and the correctness of source properties ListMultimap<String, ? extends Entity> src = cell.getSource(); // all source properties should be named "var" so we test if both lists // have the same size List<? extends Entity> srcCells = src.get("var"); assertEquals(2, src.size()); assertEquals(2, srcCells.size()); // since we have now the right amount of source properties we can now // test the correctness of their names Entity srcCell1 = srcCells.get(0); Entity srcCell2 = srcCells.get(1); String name1 = srcCell1.getDefinition().getDefinition().getDisplayName(); String name2 = srcCell2.getDefinition().getDefinition().getDisplayName(); assertEquals("age", name1); assertEquals("income", name2); }
private void readInjectedDependencies() { File injectedDepFile = new File(getConfigDir(), "injectedDependencies.json"); if (!injectedDepFile.exists()) { FMLLog.getLogger() .log( Level.DEBUG, "File {} not found. No dependencies injected", injectedDepFile.getAbsolutePath()); return; } JsonParser parser = new JsonParser(); JsonElement injectedDeps; try { injectedDeps = parser.parse(new FileReader(injectedDepFile)); for (JsonElement el : injectedDeps.getAsJsonArray()) { JsonObject jo = el.getAsJsonObject(); String modId = jo.get("modId").getAsString(); JsonArray deps = jo.get("deps").getAsJsonArray(); for (JsonElement dep : deps) { JsonObject depObj = dep.getAsJsonObject(); String type = depObj.get("type").getAsString(); if (type.equals("before")) { injectedBefore.put( modId, VersionParser.parseVersionReference(depObj.get("target").getAsString())); } else if (type.equals("after")) { injectedAfter.put( modId, VersionParser.parseVersionReference(depObj.get("target").getAsString())); } else { FMLLog.getLogger().log(Level.ERROR, "Invalid dependency type {}", type); throw new RuntimeException("Unable to parse type"); } } } } catch (Exception e) { FMLLog.getLogger().log(Level.ERROR, "Unable to parse {} - skipping", injectedDepFile); FMLLog.getLogger().throwing(Level.ERROR, e); return; } FMLLog.getLogger() .log( Level.DEBUG, "Loaded {} injected dependencies on modIds: {}", injectedBefore.size(), injectedBefore.keySet()); }
/** test for the inspire identifier function in alignment5 */ @Test public void testIdentifier() { Collection<? extends Cell> cells = alignment5.getCells(); Iterator<? extends Cell> it = cells.iterator(); Cell cell = null; while (it.hasNext()) { Cell temp = it.next(); if (temp.getTransformationIdentifier() .equals("eu.esdihumboldt.cst.functions.inspire.identifier")) { cell = temp; break; } } ListMultimap<String, ParameterValue> params = cell.getTransformationParameters(); List<ParameterValue> country = params.get("countryName"); List<ParameterValue> provider = params.get("providerName"); List<ParameterValue> product = params.get("productName"); List<ParameterValue> version = params.get("version"); List<ParameterValue> versionNilReason = params.get("versionNilReason"); // check if all parameters were set once assertEquals(1, country.size()); assertEquals(1, provider.size()); assertEquals(1, product.size()); assertEquals(1, version.size()); assertEquals(1, versionNilReason.size()); // now test if they have correct values assertEquals("at", country.get(0).getValue()); assertEquals("BEV", provider.get(0).getValue()); assertEquals("humboldt-sample-transformed-data-CadastralParcels", product.get(0).getValue()); assertEquals("", version.get(0).getValue()); assertEquals("unknown", versionNilReason.get(0).getValue()); // check if all parameters were tested assertEquals(5, params.size()); }
/** test for the inspire geographical name function in alignment7 */ @Test public void testGeographicalName2() { Collection<? extends Cell> cells = alignment7.getCells(); Iterator<? extends Cell> it = cells.iterator(); Cell cell = null; while (it.hasNext()) { Cell temp = it.next(); if (temp.getTransformationIdentifier() .equals("eu.esdihumboldt.cst.functions.inspire.geographicalname")) { cell = temp; break; } } ListMultimap<String, ParameterValue> params = cell.getTransformationParameters(); List<ParameterValue> gender = params.get("grammaticalGender"); List<ParameterValue> number = params.get("grammaticalNumber"); List<ParameterValue> lang = params.get("language"); List<ParameterValue> nameStatus = params.get("nameStatus"); List<ParameterValue> nativeness = params.get("nativeness"); List<ParameterValue> ipa = params.get("pronunciationIPA"); List<ParameterValue> sound = params.get("pronunciationSoundLink"); List<ParameterValue> source = params.get("sourceOfName"); List<ParameterValue> script = params.get("script"); List<ParameterValue> text = params.get("text"); List<ParameterValue> trans = params.get("transliterationScheme"); // test if all parameters (except the parameters for the spellings) were // set only once assertEquals(1, gender.size()); assertEquals(1, number.size()); assertEquals(1, lang.size()); assertEquals(1, nameStatus.size()); assertEquals(1, nativeness.size()); assertEquals(1, ipa.size()); // sound shouldn't be available because in older version we couldn't // enter a value assertEquals(0, sound.size()); assertEquals(1, source.size()); // spelling parameters assertEquals(2, script.size()); assertEquals(2, text.size()); assertEquals(2, trans.size()); // now test if they have the correct values assertEquals("", gender.get(0).getValue()); assertEquals("", number.get(0).getValue()); assertEquals("esp", lang.get(0).getValue()); assertEquals("official", nameStatus.get(0).getValue()); assertEquals("endonym", nativeness.get(0).getValue()); assertEquals("", ipa.get(0).getValue()); assertEquals("unknown", source.get(0).getValue()); for (int i = 0; i < text.size(); i++) { String spellText = text.get(i).as(String.class); String spellScript = script.get(i).as(String.class); String spellTrans = trans.get(i).as(String.class); if (i == 0) { assertEquals("identifier", spellText); assertEquals("idScript", spellScript); // no value set, initial value is "null" assertEquals(null, spellTrans); } if (i == 1) { assertEquals("name", spellText); // initial value is "eng", that was removed so we expect an // empty string assertEquals("", spellScript); assertEquals("nameTrans", spellTrans); } } // check if all parameters were tested (size is 13 because "sound" is // not defined in params and there are 2 spellings this time and 1 // spelling has 3 parameters -> +3 parameters) assertEquals(13, params.size()); }
/** test for the inspire geographical name function in alignment6 */ @Test public void testGeographicalName1() { Collection<? extends Cell> cells = alignment6.getCells(); Iterator<? extends Cell> it = cells.iterator(); Cell cell = null; while (it.hasNext()) { Cell temp = it.next(); if (temp.getTransformationIdentifier() .equals("eu.esdihumboldt.cst.functions.inspire.geographicalname")) { cell = temp; break; } } ListMultimap<String, ParameterValue> params = cell.getTransformationParameters(); List<ParameterValue> gender = params.get("grammaticalGender"); List<ParameterValue> number = params.get("grammaticalNumber"); List<ParameterValue> lang = params.get("language"); List<ParameterValue> nameStatus = params.get("nameStatus"); List<ParameterValue> nativeness = params.get("nativeness"); List<ParameterValue> ipa = params.get("pronunciationIPA"); List<ParameterValue> sound = params.get("pronunciationSoundLink"); List<ParameterValue> source = params.get("sourceOfName"); List<ParameterValue> script = params.get("script"); List<ParameterValue> text = params.get("text"); List<ParameterValue> trans = params.get("transliterationScheme"); // test if all parameters were set only once assertEquals(1, gender.size()); assertEquals(1, number.size()); assertEquals(1, lang.size()); assertEquals(1, nameStatus.size()); assertEquals(1, nativeness.size()); assertEquals(1, ipa.size()); // sound shouldn't be available because in older version we couldn't // enter a value assertEquals(0, sound.size()); assertEquals(1, source.size()); assertEquals(1, script.size()); assertEquals(1, text.size()); assertEquals(1, trans.size()); // now test if they have the correct values assertEquals("common", gender.get(0).getValue()); assertEquals("dual", number.get(0).getValue()); assertEquals("deu", lang.get(0).getValue()); assertEquals("historical", nameStatus.get(0).getValue()); assertEquals("exonym", nativeness.get(0).getValue()); assertEquals("IDipa", ipa.get(0).getValue()); assertEquals("source", source.get(0).getValue()); assertEquals("IDscript", script.get(0).getValue()); assertEquals("identifier", text.get(0).getValue()); assertEquals("IDtrans", trans.get(0).getValue()); // check if all parameters were tested (size is 10 because "sound" is // not defined in params) assertEquals(10, params.size()); }
public SuppressionScrap(String fileName) { File fXmlFile = new File(fileName); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = null; try { dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); NodeList nList = doc.getElementsByTagName("suppress"); for (int temp = 0; temp < nList.getLength(); temp++) { Node nNode = nList.item(temp); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; String rule = eElement.getAttribute("checks"); String file = eElement.getAttribute("files"); if (file.indexOf('[') == -1) { if (rule.equals("")) { classSuppressionsByWildRule.put(rule, file); } else { classSuppressionsByRule.put(rule, file); rulesByClass.put(file, rule); } } else { if (rule.equals("")) { pakageSuppressionsByWildRule.put(rule, file); } else { pakageSuppressionsByRule.put(rule, file); rulesByPakage.put(file, rule); } } allSuppressionsByRule.put(rule, file); } } Date date = new Date(); System.out.println("===" + date + " Suppression stats ==="); System.out.println(); System.out.println( "Total Suppression's = " + allSuppressionsByRule.size()); System.out.println( "Total Unique suppression's = " + allSuppressionsByRule.keySet().size()); System.out.println( "Total Packages with wildcard suppression = " + pakageSuppressionsByWildRule.size()); System.out.println( "Total Packages with specific suppression = " + rulesByPakage.keySet().size()); System.out.println( "Total Classes with wildcard suppression = " + classSuppressionsByWildRule.size()); System.out.println( "Total Classes with specific suppression = " + rulesByClass.keySet().size()); System.out.println(); System.out.println("---Suppressed Packages Ordered by Suppression instance count---"); printMostBrokenRule(rulesByPakage); System.out.println(); System.out.println("---Suppressed Classes Ordered by Suppression instance count---"); printMostBrokenRule(rulesByClass); System.out.println(); System.out.println("---Suppression's Ordered by most broken grouped by Package"); printMostBrokenRule(pakageSuppressionsByRule); System.out.println(); System.out.println("---Suppression's Ordered by most broken grouped by Classes"); printMostBrokenRule(classSuppressionsByRule); System.out.println(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
@Override public String toString() { return "current path: \"" + path + "\"; " + msgMap.size() + " messages"; }
public int size() { return msgMap.size(); }
@Override public int concreteSize() { return cells.size(); }
@Override public int size() { return backingMap.size(); }
private Map<FieldName, ? extends ClassificationMap<?>> evaluateRuleSet( ModelManagerEvaluationContext context) { RuleSetModel ruleSetModel = getModel(); RuleSet ruleSet = ruleSetModel.getRuleSet(); List<RuleSelectionMethod> ruleSelectionMethods = ruleSet.getRuleSelectionMethods(); RuleSelectionMethod ruleSelectionMethod; // "If more than one method is included, the first method is used as the default method for // scoring" if (ruleSelectionMethods.size() > 0) { ruleSelectionMethod = ruleSelectionMethods.get(0); } else { throw new InvalidFeatureException(ruleSet); } // Both the ordering of keys and values is significant ListMultimap<String, SimpleRule> firedRules = LinkedListMultimap.create(); List<Rule> rules = ruleSet.getRules(); for (Rule rule : rules) { collectFiredRules(firedRules, rule, context); } RuleClassificationMap result = new RuleClassificationMap(); RuleSelectionMethod.Criterion criterion = ruleSelectionMethod.getCriterion(); Set<String> keys = firedRules.keySet(); for (String key : keys) { List<SimpleRule> keyRules = firedRules.get(key); switch (criterion) { case FIRST_HIT: { SimpleRule winner = keyRules.get(0); // The first value of the first key if (result.getEntity() == null) { result.setEntity(winner); } result.put(key, winner.getConfidence()); } break; case WEIGHTED_SUM: { SimpleRule winner = null; double totalWeight = 0; for (SimpleRule keyRule : keyRules) { if (winner == null || (winner.getWeight() < keyRule.getWeight())) { winner = keyRule; } totalWeight += keyRule.getWeight(); } result.put(winner, key, totalWeight / firedRules.size()); } break; case WEIGHTED_MAX: { SimpleRule winner = null; for (SimpleRule keyRule : keyRules) { if (winner == null || (winner.getWeight() < keyRule.getWeight())) { winner = keyRule; } } result.put(winner, key, winner.getConfidence()); } break; default: throw new UnsupportedFeatureException(ruleSelectionMethod, criterion); } } return TargetUtil.evaluateClassification(result, context); }