use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.
the class AccessControllerTest method setup.
@Before
public void setup() {
String discoveryProviderParticipantId = "";
String routingProviderParticipantId = "";
accessController = new AccessControllerImpl(localCapabilitiesDirectory, localDomainAccessController, new CapabilitiesProvisioning() {
@Override
public Collection<DiscoveryEntry> getDiscoveryEntries() {
return new ArrayList<DiscoveryEntry>();
}
}, discoveryProviderParticipantId, routingProviderParticipantId);
when(messageMock.getType()).thenReturn(Message.VALUE_MESSAGE_TYPE_REQUEST);
when(messageMock.getRecipient()).thenReturn(toParticipantId);
when(messageMock.getSender()).thenReturn(fromParticipantId);
when(messageMock.getCreatorUserId()).thenReturn(DUMMY_USERID);
when(messageMock.getId()).thenReturn("someId");
final DiscoveryEntryWithMetaInfo discoveryEntry = new DiscoveryEntryWithMetaInfo(new Version(47, 11), testDomain, testInterface, toParticipantId, new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + ONE_MINUTE_IN_MS, testPublicKeyId, false);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
CapabilityCallback callback = (CapabilityCallback) invocation.getArguments()[2];
callback.processCapabilityReceived(discoveryEntry);
return null;
}
}).when(localCapabilitiesDirectory).lookup(eq(toParticipantId), any(DiscoveryQos.class), any(CapabilityCallback.class));
}
use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.
the class LocalCapabilitiesDirectoryTest method testLookupByParticipantId_localEntry_DiscoveryEntryWithMetaInfoContainsExpectedIsLocalValue.
@Test
public void testLookupByParticipantId_localEntry_DiscoveryEntryWithMetaInfoContainsExpectedIsLocalValue() {
String participantId = "participantId";
String interfaceName = "interfaceName";
DiscoveryQos discoveryQos = new DiscoveryQos();
discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_THEN_GLOBAL);
// local DiscoveryEntry
String localDomain = "localDomain";
DiscoveryEntry localEntry = new DiscoveryEntry();
localEntry.setDomain(localDomain);
localEntry.setInterfaceName(interfaceName);
localEntry.setParticipantId(participantId);
when(localDiscoveryEntryStoreMock.lookup(eq(participantId), eq(discoveryQos.getCacheMaxAgeMs()))).thenReturn(localEntry);
DiscoveryEntryWithMetaInfo capturedLocalEntry = localCapabilitiesDirectory.lookup(participantId, discoveryQos);
DiscoveryEntryWithMetaInfo localEntryWithMetaInfo = CapabilityUtils.convertToDiscoveryEntryWithMetaInfo(true, localEntry);
assertEquals(localEntryWithMetaInfo, capturedLocalEntry);
}
use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.
the class LocalCapabilitiesDirectoryImpl method lookup.
@Override
public Promise<Lookup2Deferred> lookup(String participantId) {
Lookup2Deferred deferred = new Lookup2Deferred();
DiscoveryEntryWithMetaInfo discoveryEntry = lookup(participantId, DiscoveryQos.NO_FILTER);
deferred.resolve(discoveryEntry);
return new Promise<>(deferred);
}
use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.
the class LocalCapabilitiesDirectoryImpl method lookup.
@Override
@CheckForNull
public DiscoveryEntryWithMetaInfo lookup(String participantId, DiscoveryQos discoveryQos) {
final Future<DiscoveryEntryWithMetaInfo> lookupFuture = new Future<>();
lookup(participantId, discoveryQos, new CapabilityCallback() {
@Override
public void processCapabilityReceived(DiscoveryEntryWithMetaInfo capability) {
lookupFuture.onSuccess(capability);
}
@Override
public void onError(Throwable e) {
lookupFuture.onFailure(new JoynrRuntimeException(e));
}
});
DiscoveryEntryWithMetaInfo retrievedCapabilitiyEntry = null;
try {
retrievedCapabilitiyEntry = lookupFuture.get();
} catch (InterruptedException e1) {
logger.error("interrupted while retrieving capability entry by participant ID", e1);
} catch (ApplicationException e1) {
// should not be reachable since ApplicationExceptions are not used internally
logger.error("ApplicationException while retrieving capability entry by participant ID", e1);
}
return retrievedCapabilitiyEntry;
}
use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.
the class LocalCapabilitiesDirectoryImpl method addEntriesForDomain.
private boolean addEntriesForDomain(Collection<DiscoveryEntryWithMetaInfo> discoveryEntries, Collection<DiscoveryEntryWithMetaInfo> addTo, String domain) {
boolean domainMatched = false;
for (DiscoveryEntryWithMetaInfo discoveryEntry : discoveryEntries) {
if (discoveryEntry.getDomain().equals(domain)) {
addTo.add(discoveryEntry);
domainMatched = true;
}
}
return domainMatched;
}
Aggregations