@Test public void testReturnsRemotePropertiesOrEmptyProperties() throws Exception { Transaction txn = new Transaction(null, true); Contact contact1 = getContact(false); Contact contact2 = getContact(true); Contact contact3 = getContact(true); List<Contact> contacts = Arrays.asList(contact1, contact2, contact3); Group contactGroup2 = getGroup(CLIENT_ID, MAJOR_VERSION); Group contactGroup3 = getGroup(CLIENT_ID, MAJOR_VERSION); Map<MessageId, BdfDictionary> messageMetadata3 = new LinkedHashMap<>(); MessageId barUpdateId = new MessageId(getRandomId()); messageMetadata3.put(barUpdateId, BdfDictionary.of( new BdfEntry("transportId", "bar"), new BdfEntry("version", 1), new BdfEntry("local", false) )); MessageId localUpdateId = new MessageId(getRandomId()); messageMetadata3.put(localUpdateId, BdfDictionary.of( new BdfEntry("transportId", "foo"), new BdfEntry("version", 1), new BdfEntry("local", true) )); MessageId fooUpdateId = new MessageId(getRandomId()); messageMetadata3.put(fooUpdateId, BdfDictionary.of( new BdfEntry("transportId", "foo"), new BdfEntry("version", 1), new BdfEntry("local", false) )); BdfList fooUpdate = BdfList.of("foo", 1, fooPropertiesDict); context.checking(new Expectations() {{ oneOf(db).startTransaction(true); will(returnValue(txn)); oneOf(db).getContacts(txn); will(returnValue(contacts)); oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, MAJOR_VERSION, contact2); will(returnValue(contactGroup2)); oneOf(clientHelper).getMessageMetadataAsDictionary(txn, contactGroup2.getId()); will(returnValue(Collections.emptyMap())); oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, MAJOR_VERSION, contact3); will(returnValue(contactGroup3)); oneOf(clientHelper).getMessageMetadataAsDictionary(txn, contactGroup3.getId()); will(returnValue(messageMetadata3)); oneOf(clientHelper).getMessageAsList(txn, fooUpdateId); will(returnValue(fooUpdate)); oneOf(clientHelper).parseAndValidateTransportProperties( fooPropertiesDict); will(returnValue(fooProperties)); oneOf(db).commitTransaction(txn); oneOf(db).endTransaction(txn); }}); TransportPropertyManagerImpl t = createInstance(); Map<ContactId, TransportProperties> properties = t.getRemoteProperties(new TransportId("foo")); assertEquals(3, properties.size()); assertEquals(0, properties.get(contact1.getId()).size()); assertEquals(0, properties.get(contact2.getId()).size()); assertEquals(fooProperties, properties.get(contact3.getId())); }
@Override public Map<ContactId, TransportProperties> getRemoteProperties( TransportId t) throws DbException { Map<ContactId, TransportProperties> remote = new HashMap<>(); Transaction txn = db.startTransaction(true); try { for (Contact c : db.getContacts(txn)) remote.put(c.getId(), getRemoteProperties(txn, c, t)); db.commitTransaction(txn); } finally { db.endTransaction(txn); } return remote; }
TransportPropertyManagerImpl implements TransportPropertyManager,
		Client, ContactHook, ClientVersioningHook, IncomingMessageHook { @Override public Map<ContactId, TransportProperties> getRemoteProperties( TransportId t) throws DbException { Map<ContactId, TransportProperties> remote = new HashMap<>(); Transaction txn = db.startTransaction(true); try { for (Contact c : db.getContacts(txn)) remote.put(c.getId(), getRemoteProperties(txn, c, t)); db.commitTransaction(txn); } finally { db.endTransaction(txn); } return remote; } }
TransportPropertyManagerImpl implements TransportPropertyManager,
		Client, ContactHook, ClientVersioningHook, IncomingMessageHook { @Override public Map<ContactId, TransportProperties> getRemoteProperties( TransportId t) throws DbException { Map<ContactId, TransportProperties> remote = new HashMap<>(); Transaction txn = db.startTransaction(true); try { for (Contact c : db.getContacts(txn)) remote.put(c.getId(), getRemoteProperties(txn, c, t)); db.commitTransaction(txn); } finally { db.endTransaction(txn); } return remote; } @Inject  TransportPropertyManagerImpl(DatabaseComponent db,
			ClientHelper clientHelper,
			ClientVersioningManager clientVersioningManager,
			MetadataParser metadataParser,
			ContactGroupFactory contactGroupFactory, Clock clock); }
TransportPropertyManagerImpl implements TransportPropertyManager,
		Client, ContactHook, ClientVersioningHook, IncomingMessageHook { @Override public Map<ContactId, TransportProperties> getRemoteProperties( TransportId t) throws DbException { Map<ContactId, TransportProperties> remote = new HashMap<>(); Transaction txn = db.startTransaction(true); try { for (Contact c : db.getContacts(txn)) remote.put(c.getId(), getRemoteProperties(txn, c, t)); db.commitTransaction(txn); } finally { db.endTransaction(txn); } return remote; } @Inject  TransportPropertyManagerImpl(DatabaseComponent db,
			ClientHelper clientHelper,
			ClientVersioningManager clientVersioningManager,
			MetadataParser metadataParser,
			ContactGroupFactory contactGroupFactory, Clock clock); @Override void createLocalState(Transaction txn); @Override void addingContact(Transaction txn, Contact c); @Override void removingContact(Transaction txn, Contact c); @Override void onClientVisibilityChanging(Transaction txn, Contact c,
			Visibility v); @Override boolean incomingMessage(Transaction txn, Message m, Metadata meta); @Override void addRemoteProperties(Transaction txn, ContactId c,
			Map<TransportId, TransportProperties> props); @Override Map<TransportId, TransportProperties> getLocalProperties(); @Override Map<TransportId, TransportProperties> getLocalProperties(
			Transaction txn); @Override TransportProperties getLocalProperties(TransportId t); @Override Map<ContactId, TransportProperties> getRemoteProperties(
			TransportId t); @Override TransportProperties getRemoteProperties(ContactId c, TransportId t); @Override void mergeLocalProperties(TransportId t, TransportProperties p); }
TransportPropertyManagerImpl implements TransportPropertyManager,
		Client, ContactHook, ClientVersioningHook, IncomingMessageHook { @Override public Map<ContactId, TransportProperties> getRemoteProperties( TransportId t) throws DbException { Map<ContactId, TransportProperties> remote = new HashMap<>(); Transaction txn = db.startTransaction(true); try { for (Contact c : db.getContacts(txn)) remote.put(c.getId(), getRemoteProperties(txn, c, t)); db.commitTransaction(txn); } finally { db.endTransaction(txn); } return remote; } @Inject  TransportPropertyManagerImpl(DatabaseComponent db,
			ClientHelper clientHelper,
			ClientVersioningManager clientVersioningManager,
			MetadataParser metadataParser,
			ContactGroupFactory contactGroupFactory, Clock clock); @Override void createLocalState(Transaction txn); @Override void addingContact(Transaction txn, Contact c); @Override void removingContact(Transaction txn, Contact c); @Override void onClientVisibilityChanging(Transaction txn, Contact c,
			Visibility v); @Override boolean incomingMessage(Transaction txn, Message m, Metadata meta); @Override void addRemoteProperties(Transaction txn, ContactId c,
			Map<TransportId, TransportProperties> props); @Override Map<TransportId, TransportProperties> getLocalProperties(); @Override Map<TransportId, TransportProperties> getLocalProperties(
			Transaction txn); @Override TransportProperties getLocalProperties(TransportId t); @Override Map<ContactId, TransportProperties> getRemoteProperties(
			TransportId t); @Override TransportProperties getRemoteProperties(ContactId c, TransportId t); @Override void mergeLocalProperties(TransportId t, TransportProperties p);  }