/** * This constructor allows for a String to be passed in order * to create an ObjectId. It will store it as a LocalId and * verify it as such. * * @param id The id of the new LocalId that will be created * @throws IllegalArgumentException when the id provided could not be parsed * into either a GlobalId or a LocalId */ public ObjectId(String id) throws IllegalArgumentException { try { this.objectId = new GlobalId(id); } catch(IllegalArgumentException e1) { // Not a valid globalId, try localId try { this.objectId = new LocalId(id); } catch(IllegalArgumentException e2) { // Not either so throw exception throw new IllegalArgumentException("The provided ObjectId is not valid"); } } }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof GlobalId)) { return false; } GlobalId actual = (GlobalId) o; return this.getDomainName().equals(actual.getDomainName()) && this.getLocalId().equals(actual.getLocalId()); }
/** * This constructor allows for a String to be passed in order * to create an ObjectId. It will store it as a LocalId and * verify it as such. * * @param id The id of the new LocalId that will be created * @throws IllegalArgumentException when the id provided could not be parsed * into either a GlobalId or a LocalId */ public ObjectId(String id) throws IllegalArgumentException { try { this.objectId = new GlobalId(id); } catch(IllegalArgumentException e1) { // Not a valid globalId, try localId try { this.objectId = new LocalId(id); } catch(IllegalArgumentException e2) { // Not either so throw exception throw new IllegalArgumentException("The provided ObjectId is not valid"); } } }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof GlobalId)) { return false; } GlobalId actual = (GlobalId) o; return this.getDomainName().equals(actual.getDomainName()) && this.getLocalId().equals(actual.getLocalId()); }
@Test(expected=IllegalArgumentException.class) public void testGlobalIdException() { new GlobalId("example.com/test:195mg90a39v"); } }
@Test(expected=IllegalArgumentException.class) public void testGlobalIdException() { new GlobalId("example.com/test:195mg90a39v"); } }
@Test public void testGlobalId() throws Exception { DomainName dn = new DomainName("example.com"); LocalId lid = new LocalId("195mg90a39v"); GlobalId g1 = new GlobalId(dn, lid); assertTrue(g1 instanceof GlobalId); GlobalId g2 = new GlobalId("example.com:195mg90a39v"); assertTrue(g2 instanceof GlobalId); GlobalId g3 = new GlobalId("example.com", "195mg90a39v"); assertTrue(g3 instanceof GlobalId); }
@Test public void testGlobalId() throws Exception { DomainName dn = new DomainName("example.com"); LocalId lid = new LocalId("195mg90a39v"); GlobalId g1 = new GlobalId(dn, lid); assertTrue(g1 instanceof GlobalId); GlobalId g2 = new GlobalId("example.com:195mg90a39v"); assertTrue(g2 instanceof GlobalId); GlobalId g3 = new GlobalId("example.com", "195mg90a39v"); assertTrue(g3 instanceof GlobalId); }
@Test public void testGroupId() { DomainName dn1 = new DomainName("example.com"); LocalId l1 = new LocalId("195mg90a39v"); GlobalId gl1 = new GlobalId(dn1, l1); GroupId g1 = new GroupId("example.com:195mg90a39v"); GroupId g2 = new GroupId(gl1); assertEquals(g1.getType(), g2.getType()); assertEquals(g1.getObjectId().toString(), g2.getObjectId().toString()); GroupId g3 = new GroupId("@foo"); assertEquals(Type.custom, g3.getType()); assertEquals("@foo", g3.getObjectId().toString()); GroupId g4 = new GroupId(Type.objectId, "example.com:195mg90a39v"); assertEquals(Type.objectId, g4.getType()); assertEquals("example.com:195mg90a39v", g4.getObjectId().toString()); GroupId g5 = new GroupId(Type.custom, "@foo"); assertEquals(Type.custom, g5.getType()); assertEquals("@foo", g5.getObjectId().toString()); GroupId g6 = new GroupId(Type.all, "something"); assertEquals(Type.all, g6.getType()); assertEquals("@all", g6.getObjectId().toString()); GroupId g7 = new GroupId(Type.self, null); assertEquals(Type.self, g7.getType()); assertEquals("@self", g7.getObjectId().toString()); GroupId g8 = new GroupId(Type.friends, "bar"); assertEquals(Type.friends, g8.getType()); assertEquals("@friends", g8.getObjectId().toString()); }
@Test public void testGroupId() { DomainName dn1 = new DomainName("example.com"); LocalId l1 = new LocalId("195mg90a39v"); GlobalId gl1 = new GlobalId(dn1, l1); GroupId g1 = new GroupId("example.com:195mg90a39v"); GroupId g2 = new GroupId(gl1); assertEquals(g1.getType(), g2.getType()); assertEquals(g1.getObjectId().toString(), g2.getObjectId().toString()); GroupId g3 = new GroupId("@foo"); assertEquals(Type.custom, g3.getType()); assertEquals("@foo", g3.getObjectId().toString()); GroupId g4 = new GroupId(Type.objectId, "example.com:195mg90a39v"); assertEquals(Type.objectId, g4.getType()); assertEquals("example.com:195mg90a39v", g4.getObjectId().toString()); GroupId g5 = new GroupId(Type.custom, "@foo"); assertEquals(Type.custom, g5.getType()); assertEquals("@foo", g5.getObjectId().toString()); GroupId g6 = new GroupId(Type.all, "something"); assertEquals(Type.all, g6.getType()); assertEquals("@all", g6.getObjectId().toString()); GroupId g7 = new GroupId(Type.self, null); assertEquals(Type.self, g7.getType()); assertEquals("@self", g7.getObjectId().toString()); GroupId g8 = new GroupId(Type.friends, "bar"); assertEquals(Type.friends, g8.getType()); assertEquals("@friends", g8.getObjectId().toString()); }
@Test public void testObjectId() throws Exception { LocalId lid = new LocalId("195mg90a39v"); GlobalId gid = new GlobalId("example.com:195mg90a39v"); ObjectId o1 = new ObjectId(lid); assertTrue(o1 instanceof ObjectId); ObjectId o2 = new ObjectId(gid); assertTrue(o2 instanceof ObjectId); ObjectId o3 = new ObjectId("195mg90a39v"); assertTrue(o3 instanceof ObjectId); assertTrue(o3.getObjectId() instanceof LocalId); ObjectId o4 = new ObjectId("example.com:195mg90a39v"); assertTrue(o4 instanceof ObjectId); assertTrue(o4.getObjectId() instanceof GlobalId); }
@Test public void testObjectId() throws Exception { LocalId lid = new LocalId("195mg90a39v"); GlobalId gid = new GlobalId("example.com:195mg90a39v"); ObjectId o1 = new ObjectId(lid); assertTrue(o1 instanceof ObjectId); ObjectId o2 = new ObjectId(gid); assertTrue(o2 instanceof ObjectId); ObjectId o3 = new ObjectId("195mg90a39v"); assertTrue(o3 instanceof ObjectId); assertTrue(o3.getObjectId() instanceof LocalId); ObjectId o4 = new ObjectId("example.com:195mg90a39v"); assertTrue(o4 instanceof ObjectId); assertTrue(o4.getObjectId() instanceof GlobalId); }