test
This commit is contained in:
parent
05832e8df6
commit
803554f335
2
pom.xml
2
pom.xml
|
@ -24,7 +24,7 @@
|
|||
|
||||
<dependency>
|
||||
<groupId>com.loafle.overflow</groupId>
|
||||
<artifactId>crawler_java</artifactId>
|
||||
<artifactId>crawler</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven: org.snmp4j:snmp4j:2.5.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: log4j:log4j:1.2.14" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.loafle.overflow:crawler_java:1.0.0-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.loafle.overflow:crawler:1.0.0-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
|
||||
|
|
|
@ -30,7 +30,7 @@ public class SNMPCrawler extends Crawler {
|
|||
retObj = getByV3(config);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
new Exception("Unknown SNMP protocol : " + targetVer).printStackTrace();
|
||||
}
|
||||
|
||||
return retObj;
|
||||
|
@ -49,8 +49,9 @@ public class SNMPCrawler extends Crawler {
|
|||
String port = (String)config.get("port");
|
||||
String community = (String)config.get("community");
|
||||
String[] oids = (String[])config.get("oids");
|
||||
String method = (String)config.get("method");
|
||||
|
||||
switch ((String)config.get("method")) {
|
||||
switch (method) {
|
||||
case "validate":
|
||||
return snmpV2.validate(ip, port, community);
|
||||
case "get":
|
||||
|
@ -58,12 +59,10 @@ public class SNMPCrawler extends Crawler {
|
|||
case "walk":
|
||||
return snmpV2.walk(ip, port, community, oids[0]);
|
||||
default:
|
||||
return null;
|
||||
new Exception("Unknown SNMP command : " + method).printStackTrace();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("An Exception happend as follows.");
|
||||
System.err.println(e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (snmp != null) {
|
||||
|
@ -102,8 +101,9 @@ public class SNMPCrawler extends Crawler {
|
|||
String privType = (String)config.get("privType");
|
||||
String privPass = (String)config.get("privPass");
|
||||
String[] oids = (String[])config.get("oids");
|
||||
String method = (String)config.get("method");
|
||||
|
||||
switch ((String)config.get("method")) {
|
||||
switch (method) {
|
||||
case "validate":
|
||||
return snmpV3.validate(ip, port, user, authType, authPass, privType, privPass);
|
||||
case "get":
|
||||
|
@ -111,13 +111,11 @@ public class SNMPCrawler extends Crawler {
|
|||
case "walk":
|
||||
return snmpV3.walk(ip, port, user, authType, authPass, privType, privPass, oids[0]);
|
||||
default:
|
||||
return null;
|
||||
new Exception("Unknown SNMP command : " + method).printStackTrace();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("An Exception happend as follows.");
|
||||
System.err.println(e.getMessage());
|
||||
e.printStackTrace();
|
||||
new Exception("An Exception happend : " + e.getMessage()).printStackTrace();
|
||||
} finally {
|
||||
if (snmp != null) {
|
||||
try {
|
||||
|
@ -136,5 +134,4 @@ public class SNMPCrawler extends Crawler {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -46,13 +46,12 @@ public class AppTest {
|
|||
config.put("method", "walk");
|
||||
config.put("oids", new String[]{"1.3.6.1.2.1.25.2.3.1.3"});
|
||||
|
||||
Object res = c.getInternal(config);
|
||||
Object result = c.getInternal(config);
|
||||
|
||||
if(res instanceof Boolean) {
|
||||
System.out.println("validate : " + res);
|
||||
assertEquals(res, true);
|
||||
}else {
|
||||
printResult((Map<String, String>)res);
|
||||
if(result instanceof Boolean) {
|
||||
System.out.println("validate : " + result);
|
||||
}else {
|
||||
printResult((Map<String, String>)result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user