}
public void testParse() {
System.out.println("***SessionNameTest: testParse ...");
try {
SessionName sessionName = new SessionName(glob, "jack");
//assertEquals("", "/node/unknown/client/jack", sessionName.getAbsoluteName());
assertEquals("", "client/jack", sessionName.getAbsoluteName());
assertEquals("", (String)null, sessionName.getNodeIdStr());
assertEquals("", "client/jack", sessionName.getRelativeName());
assertEquals("", "jack", sessionName.getLoginName());
assertEquals("", 0L, sessionName.getPublicSessionId());
}
catch (IllegalArgumentException e) {
fail("testParse failed: " + e.toString());
}
try {
SessionName sessionName = new SessionName(glob, "client/jack");
System.out.println("AbsoluteName=" + sessionName.getAbsoluteName() + " RelativeName=" + sessionName.getRelativeName());
assertEquals("", "client/jack", sessionName.getAbsoluteName());
//assertEquals("", "/node/unknown/client/jack", sessionName.getAbsoluteName());
assertEquals("", (String)null, sessionName.getNodeIdStr());
assertEquals("", "client/jack", sessionName.getRelativeName());
assertEquals("", "jack", sessionName.getLoginName());
assertEquals("", 0L, sessionName.getPublicSessionId());
}
catch (IllegalArgumentException e) {
fail("testParse failed: " + e.toString());
}
try {
SessionName sessionName = new SessionName(glob, "client/jack/99");
System.out.println("AbsoluteName=" + sessionName.getAbsoluteName() + " RelativeName=" + sessionName.getRelativeName());
if (SessionName.useSessionMarker())
assertEquals("", "client/jack/session/99", sessionName.getAbsoluteName());
else
assertEquals("", "client/jack/99", sessionName.getAbsoluteName());
assertEquals("", (String)null, sessionName.getNodeIdStr());
if (SessionName.useSessionMarker())
assertEquals("", "client/jack/session/99", sessionName.getRelativeName());
else
assertEquals("", "client/jack/99", sessionName.getRelativeName());
assertEquals("", "jack", sessionName.getLoginName());
assertEquals("", 99L, sessionName.getPublicSessionId());
}
catch (IllegalArgumentException e) {
fail("testParse failed: " + e.toString());
}
try {
SessionName sessionName = new SessionName(glob, "/node/heron/client/jack/session/99");
System.out.println("AbsoluteName=" + sessionName.getAbsoluteName() + " RelativeName=" + sessionName.getRelativeName());
if (SessionName.useSessionMarker())
assertEquals("", "/node/heron/client/jack/session/99", sessionName.getAbsoluteName());
else
assertEquals("", "/node/heron/client/jack/99", sessionName.getAbsoluteName());
assertEquals("", "heron", sessionName.getNodeId().getId());
if (SessionName.useSessionMarker())
assertEquals("", "client/jack/session/99", sessionName.getRelativeName());
else
assertEquals("", "client/jack/99", sessionName.getRelativeName());
assertEquals("", "jack", sessionName.getLoginName());
assertEquals("", 99L, sessionName.getPublicSessionId());
}
catch (IllegalArgumentException e) {
fail("testParse failed: " + e.toString());
}
try { // Test copy constructor ...
SessionName tmp = new SessionName(glob, "client/jack");
SessionName sessionName = new SessionName(glob, tmp, -4L);
System.out.println("AbsoluteName=" + sessionName.getAbsoluteName() + " RelativeName=" + sessionName.getRelativeName());
if (SessionName.useSessionMarker())
assertEquals("", "client/jack/session/-4", sessionName.getAbsoluteName());
else
assertEquals("", "client/jack/-4", sessionName.getAbsoluteName());
assertEquals("", (String)null, sessionName.getNodeIdStr());
if (SessionName.useSessionMarker())
assertEquals("", "client/jack/session/-4", sessionName.getRelativeName());
else
assertEquals("", "client/jack/-4", sessionName.getRelativeName());
assertEquals("", "jack", sessionName.getLoginName());
assertEquals("", -4L, sessionName.getPublicSessionId());
}
catch (IllegalArgumentException e) {
fail("testParse failed: " + e.toString());
}
try { // Test given node ID ...
SessionName tmp = new SessionName(glob, new NodeId("avalon"), "client/jack");
SessionName sessionName = new SessionName(glob, tmp, -4);
System.out.println("AbsoluteName=" + sessionName.getAbsoluteName() + " RelativeName=" + sessionName.getRelativeName());
if (SessionName.useSessionMarker())
assertEquals("Expected /node/avalon/client/jack/session/-4 but was:" + sessionName.getAbsoluteName(), "/node/avalon/client/jack/session/-4", sessionName.getAbsoluteName());
else
assertEquals("Expected /node/avalon/client/jack/-4 but was:" + sessionName.getAbsoluteName(), "/node/avalon/client/jack/-4", sessionName.getAbsoluteName());
assertEquals("", "avalon", sessionName.getNodeId().getId());
if (SessionName.useSessionMarker())
assertEquals("", "client/jack/session/-4", sessionName.getRelativeName());
else
assertEquals("", "client/jack/-4", sessionName.getRelativeName());
assertEquals("", "jack", sessionName.getLoginName());
assertEquals("", -4L, sessionName.getPublicSessionId());
}
catch (IllegalArgumentException e) {
fail("testParse failed: " + e.toString());
}
try { // Test given node ID ...
SessionName tmp = new SessionName(glob, new NodeId("/node/avalon"), "client/jack");
SessionName sessionName = new SessionName(glob, tmp, -4);
System.out.println("AbsoluteName=" + sessionName.getAbsoluteName() + " RelativeName=" + sessionName.getRelativeName());
if (SessionName.useSessionMarker())
assertEquals("", "/node/avalon/client/jack/session/-4", sessionName.getAbsoluteName());
else
assertEquals("", "/node/avalon/client/jack/-4", sessionName.getAbsoluteName());
assertEquals("", "avalon", sessionName.getNodeId().getId());
if (SessionName.useSessionMarker())
assertEquals("", "client/jack/session/-4", sessionName.getRelativeName());
else
assertEquals("", "client/jack/-4", sessionName.getRelativeName());
assertEquals("", "jack", sessionName.getLoginName());
assertEquals("", -4L, sessionName.getPublicSessionId());
}
catch (IllegalArgumentException e) {
fail("testParse failed: " + e.toString());
}
try { // Test given node ID ...
SessionName sessionName = new SessionName(glob, new NodeId("/node/sauron/client/jack/99"), "/node/heron/client/jack/99");
System.out.println("AbsoluteName=" + sessionName.getAbsoluteName() + " RelativeName=" + sessionName.getRelativeName());
if (SessionName.useSessionMarker())
assertEquals("", "/node/sauron/client/jack/session/99", sessionName.getAbsoluteName());
else
assertEquals("", "/node/sauron/client/jack/99", sessionName.getAbsoluteName());
assertEquals("", "sauron", sessionName.getNodeId().getId());
if (SessionName.useSessionMarker())
assertEquals("", "client/jack/session/99", sessionName.getRelativeName());
else
assertEquals("", "client/jack/99", sessionName.getRelativeName());
assertEquals("", "jack", sessionName.getLoginName());
assertEquals("", 99L, sessionName.getPublicSessionId());
}
catch (IllegalArgumentException e) {
fail("testParse failed: " + e.toString());
}
try { // Test given node ID ...
new SessionName(glob, new NodeId("/avalon"), "client/jack");
fail("testParse failed, nodeId is invalid.");
}
catch (IllegalArgumentException e) {
System.out.println("SUCCESS: " + e.toString());
}
try {
new SessionName(glob, null);
fail("testParse failed, null should throw an exception.");
}
catch (IllegalArgumentException e) {
System.out.println("SUCCESS: " + e.toString());
}
try {
new SessionName(glob, "");
fail("testParse failed, \"\" should throw an exception.");
}
catch (IllegalArgumentException e) {
System.out.println("SUCCESS: " + e.toString());
}
try {
new SessionName(glob, "/");
fail("testParse failed, \"/\" should throw an exception.");
}
catch (IllegalArgumentException e) {
System.out.println("SUCCESS: " + e.toString());
}
try {
new SessionName(glob, "//////");
fail("testParse failed, \"//////\" should throw an exception.");
}
catch (IllegalArgumentException e) {
System.out.println("SUCCESS: " + e.toString());
}
try {
// missing clusterNodeId is similar to relative addressing,
// changed 2009-05-21 Marcel to not throw exception anymore
new SessionName(glob, "/node//joe/2");
System.out.println("SUCCESS: \"/node//joe/2\" missing clusterNodeId is similar to relative addressing.");
}
catch (IllegalArgumentException e) {
fail("testParse failed: " + e.toString());
}
try {
// missing clusterNodeId is similar to relative addressing,
// changed 2009-05-21 Marcel to not throw exception anymore
new SessionName(glob, "/node//client/joe/2");
System.out.println("SUCCESS: /node//client/joe/2 missing clusterNodeId is similar to relative addressing.");
}
catch (IllegalArgumentException e) {
fail("testParse failed: " + e.toString());
}