public void ListConfigFromJson() { JObject o = JObject.Parse(@"{ nodesLoader :{ targetIdentifier: 'nodeId', whiteList : ['ciao'], blackList : ['pippo'], contains : ['kola'], notContain :[] } }"); config = o.ToObject <nodesConfigWrapper>().nodesLoader; Console.WriteLine("not contain {0}", config.notContain.Length); NodesSelector sel = new NodesSelector(config); node.NodeId = "paul"; Assert.False(sel.selectNode(node), "Wrong nodeId should fail"); node.NodeId = "ciao"; Assert.True(sel.selectNode(node), "nodeId should pass"); node.NodeId = "pippo"; Assert.False(sel.selectNode(node), "blacklisted nodeId should fail"); node.NodeId = "hey kola"; Assert.True(sel.selectNode(node), "contained nodeId should pass"); Assert.True(config.notContain.Length == 0, "fail to initialize empty array"); Assert.True(config.matchRegEx.Length == 0, "fail to initialize empty array 2"); }
public void RegEx() { config.matchRegEx = new string[] { "^obi", "^OBI" }; NodesSelector sel = new NodesSelector(config); node.BrowseName = "OBI ciao"; Assert.True(sel.selectNode(node), "matchRegEx not working"); node.BrowseName = "ciao"; Assert.False(sel.selectNode(node), "cross check"); }
public void NodeID() { config.targetIdentifier = "NodeId"; config.whiteList = new string[] { "ciao" }; NodesSelector sel = new NodesSelector(config); Assert.False(sel.selectNode(node), "Empty nodeId should fail"); node.NodeId = "paul"; Assert.False(sel.selectNode(node), "Wrong nodeId should fail"); node.NodeId = "ciao"; Assert.True(sel.selectNode(node), "nodeId should pass"); }
public void WhiteListing() { config.whiteList = new string[] { "hola", "pola" }; config.contains = new string[] { "mubo", "jumbo" }; NodesSelector sel = new NodesSelector(config); Assert.False(sel.selectNode(node), "Should fail"); node.BrowseName = "Hola"; Assert.False(sel.selectNode(node), "white list should fail"); node.BrowseName = "pola"; Assert.True(sel.selectNode(node), "whitelist broken "); node.BrowseName = "polajumbo"; Assert.True(sel.selectNode(node), "containslist broken "); }
public void DisplayName() { config.targetIdentifier = "displayName"; config.whiteList = new string[] { "ciao" }; Opc.Ua.Export.LocalizedText[] txt = { new Opc.Ua.Export.LocalizedText() }; txt[0].Value = "bella"; NodesSelector sel = new NodesSelector(config); Assert.False(sel.selectNode(node), "Empty displayName should fail"); node.DisplayName = txt; Assert.False(sel.selectNode(node), "Wrong displayName should fail"); node.DisplayName[0].Value = "ciao"; Assert.True(sel.selectNode(node), "displayName should pass"); }
public void BlackListAndMatchAll() { config.matchRegEx = new string[] { "^" }; NodesSelector sel = new NodesSelector(config); config.notContain = new string[] { "bella", "ciao" }; config.blackList = new string[] { "lea", "giorgio" }; Assert.True(sel.selectNode(node), "Blacklist + matchRegEx all not working"); node.BrowseName = ""; Assert.True(sel.selectNode(node), "Blacklist + matchRegEx all not working 2"); node.BrowseName = "ciao putin"; Assert.False(sel.selectNode(node), "NotContainBlacklist + matchRegEx all not working"); node.BrowseName = "lea"; Assert.False(sel.selectNode(node), "Blacklist + matchRegEx all not working "); }
public void init(JObject config, CancellationTokenSource cts) { _config = config.ToObject <opcPromConfigWrapper>().prometheus; server = new KestrelMetricServer(_config.port); variablesMap = new Dictionary <string, Gauge>(); var db_nodes = _serv.db.getDbNodes(); try{ selector = new NodesSelector(_config.variableFilter); } catch (Exception e) { logger.Error("HTTP server initialization failed: " + e.Message); cts.Cancel(); } if (!cts.IsCancellationRequested) { foreach (var node in db_nodes) { if (selector.selectNode(node.name)) { variablesMap.Add(node.name, createMetric(node.name)); } } variablesMap.Add("opc_server_up", createMetric("opc_server_up", "Describe the status of connection with the opc-server, 0 means TCP connection down.")); setTimer(); try { server.Start(); logger.Info("Prometheus metrics exposed at http://localhost:" + _config.port + "/metrics"); } catch (Exception e) { logger.Error("HTTP server initialization failed: " + e.Message); cts.Cancel(); } } }
public void configurationSkipNoList() { NodesSelector sel = new NodesSelector(config); Assert.True(sel.selectNode(node), "Skip selection on empty list does not work."); }